Making WordPress.org

Ticket #1794: 1794.1.diff

File 1794.1.diff, 4.3 KB (added by hlashbrooke, 7 years ago)

Adding new metabox view file

  • wordcamp.org/public_html/wp-content/plugins/wc-post-types/css/admin.css

    diff --git wordcamp.org/public_html/wp-content/plugins/wc-post-types/css/admin.css wordcamp.org/public_html/wp-content/plugins/wc-post-types/css/admin.css
    index b5657e8..4909af1 100644
     
    4040                        display: table-caption;
    4141                        font-weight: bold;
    4242                }
     43.wcbsponsor-note {
     44        margin-bottom: 1em;
     45}
     46.wcbsponsor-note-meta {
     47        font-weight: 800;
     48}
     49 No newline at end of file
  • new file wordcamp.org/public_html/wp-content/plugins/wc-post-types/views/sponsors/metabox-notes.php

    diff --git wordcamp.org/public_html/wp-content/plugins/wc-post-types/views/sponsors/metabox-notes.php wordcamp.org/public_html/wp-content/plugins/wc-post-types/views/sponsors/metabox-notes.php
    new file mode 100644
    index 0000000..818fef0
    - +  
     1<?php if ( empty ( $existing_notes ) ) : ?>
     2
     3        <?php _e( 'There are no notes yet.', 'wordcamporg' ); ?>
     4
     5<?php else : ?>
     6
     7        <?php foreach ( $existing_notes as $note ) : ?>
     8                <div class="wcbsponsor-note">
     9                        <span class="wcbsponsor-note-meta">
     10                                <?php echo esc_html( date( 'Y-m-d', $note['timestamp'] ) ); ?>
     11                                <?php echo esc_html( get_the_author_meta( 'nickname', $note['author_id'] ) ); ?>:
     12                        </span>
     13
     14                        <?php echo esc_html( $note['message'] ); ?>
     15                </div>
     16        <?php endforeach; ?>
     17
     18<?php endif; ?>
     19
     20<div>
     21        <h3>
     22                <label for="wcbsponsor_new_note">
     23                        <?php _e( 'Add a Note', 'wordcamporg' ); ?>
     24                </label>
     25
     26                <?php if ( current_user_can( 'manage_network' ) ) : ?>
     27                        <p class="description">(visible to organizers)</p>
     28                <?php endif; ?>
     29        </h3>
     30
     31        <textarea id="wcbsponsor_new_note" name="wcbsponsor_new_note" class="large-text"></textarea>
     32
     33        <?php submit_button(
     34                esc_html__( 'Add Note', 'wordcamporg' ),
     35                'secondary',
     36                'wcbsponsor_add_note'
     37        ); ?>
     38</div>
  • wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    diff --git wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php
    index 4fd6e51..91671c9 100644
    class WordCamp_Post_Types_Plugin { 
    15141514                add_meta_box( 'sponsor-info',      __( 'Sponsor Info',      'wordcamporg'  ), array( $this, 'metabox_sponsor_info'      ), 'wcb_sponsor',   'normal' );
    15151515                add_meta_box( 'sponsor-agreement', __( 'Sponsor Agreement', 'wordcamporg'  ), array( $this, 'metabox_sponsor_agreement' ), 'wcb_sponsor',   'side'   );
    15161516                add_meta_box( 'invoice-sponsor',   __( 'Invoice Sponsor',   'wordcamporg'  ), array( $this, 'metabox_invoice_sponsor'   ), 'wcb_sponsor',   'side'   );
     1517                add_meta_box( 'sponsor-notes',     __( 'Sponsor Notes',         'wordcamporg'  ), array( $this, 'metabox_sponsor_notes'   ),   'wcb_sponsor',   'side'   );
    15171518        }
    15181519
    15191520        /**
    class WordCamp_Post_Types_Plugin { 
    18061807                require_once( __DIR__ . '/views/sponsors/metabox-invoice-sponsor.php' );
    18071808        }
    18081809
     1810        function metabox_sponsor_notes( $post ) {
     1811                $existing_notes = get_post_meta( $post->ID, '_wcbsponsor_notes', true );
     1812                require_once( __DIR__ . '/views/sponsors/metabox-notes.php' );
     1813        }
     1814
    18091815        /**
    18101816         * Fired when a post is saved, makes sure additional metadata is also updated.
    18111817         */
    class WordCamp_Post_Types_Plugin { 
    19821988                                        update_post_meta( $post_id, $meta_key, $value );
    19831989                                }
    19841990                        }
     1991
     1992                        $this->validate_and_save_sponsor_notes( $post, $_POST['wcbsponsor_new_note'] );
    19851993                }
    19861994        }
    19871995
    19881996        /**
     1997         * Validate and save expense data
     1998         *
     1999         * @param WP_Post $post
     2000         * @param array    $expenses
     2001         */
     2002        function validate_and_save_sponsor_notes( $post, $new_note_message ) {
     2003
     2004                $new_note_message = sanitize_text_field( wp_unslash( $new_note_message ) );
     2005
     2006                if ( empty( $new_note_message ) ) {
     2007                        return;
     2008                }
     2009
     2010                $notes = get_post_meta( $post->ID, '_wcbsponsor_notes', true );
     2011                if ( ! is_array( $notes ) ) {
     2012                        $notes = array();
     2013                }
     2014
     2015                $new_note = array(
     2016                        'timestamp' => time(),
     2017                        'author_id' => get_current_user_id(),
     2018                        'message'   => $new_note_message
     2019                );
     2020
     2021                $notes[] = $new_note;
     2022
     2023                update_post_meta( $post->ID, '_wcbsponsor_notes', $notes );
     2024
     2025        }
     2026
     2027        /**
    19892028         * Registers the custom post types, runs during init.
    19902029         */
    19912030        function register_post_types() {