Making WordPress.org

Ticket #1794: 1794.diff

File 1794.diff, 2.9 KB (added by hlashbrooke, 7 years ago)

Adds 'Sponsor Notes' metabox to wcb_sponsor CPT

  • 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
  • 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() {