Making WordPress.org


Ignore:
Timestamp:
02/24/2015 07:58:53 PM (10 years ago)
Author:
iandunn
Message:

Multi Event Sponsors: Refactor the Regions taxonomy into its own class.

There was arguably already enough code to warrant putting it in its own file, and I'm going to be adding more soon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsor.php

    r715 r1302  
    1414class MES_Sponsor {
    1515    const POST_TYPE_SLUG     = 'mes';
    16     const REGIONS_SLUG       = 'mes-regions';
    1716   
    1817    /**
     
    2120    public function __construct() {
    2221        add_action( 'init',                                   array( $this, 'create_post_type' ) );
    23         add_action( 'init',                                   array( $this, 'create_taxonomies' ) );
    24         add_action( 'add_meta_boxes_' . self::POST_TYPE_SLUG, array( $this, 'remove_meta_boxes' ) );
    2522        add_action( 'admin_init',                             array( $this, 'add_meta_boxes' ) );
    2623        add_action( 'save_post',                              array( $this, 'save_post' ), 10, 2 );
    27         add_action( 'wcpt_metabox_value',                     array( $this, 'wcpt_region_dropdown_render' ), 10, 3 );
    28         add_action( 'wcpt_metabox_save',                      array( $this, 'wcpt_region_dropdown_save' ), 10, 3 );
    2924        add_filter( 'the_content',                            array( $this, 'add_header_footer_text' ) );
     25
     26        // todo readjust whitespace after this commit
    3027    }
    3128
     
    6562            'query_var'       => true,
    6663            'supports'        => array( 'title', 'editor', 'author', 'excerpt', 'revisions', 'thumbnail' ),
    67             'taxonomies'      => array( self::REGIONS_SLUG ),
     64            'taxonomies'      => array( MES_Region::TAXONOMY_SLUG ),
    6865        );
    6966
    7067        register_post_type( self::POST_TYPE_SLUG, $post_type_params );
    71     }
    72 
    73     /**
    74      * Registers the category taxonomy
    75      */
    76     public function create_taxonomies() {
    77         $region_params = array(
    78             'label'                 => __( 'Region', 'wordcamporg' ),
    79             'labels'                => array(
    80                 'name'          => __( 'Regions', 'wordcamporg' ),
    81                 'singular_name' => __( 'Region', 'wordcamporg' )
    82             ),
    83             'hierarchical'          => true,
    84             'rewrite'               => array( 'slug' => self::REGIONS_SLUG ),
    85         );
    86 
    87         if ( ! taxonomy_exists( self::REGIONS_SLUG ) ) {
    88             register_taxonomy( self::REGIONS_SLUG, self::POST_TYPE_SLUG, $region_params );
    89         }
    9068    }
    9169
     
    9876            __( 'Regional Sponsorships', 'wordcamporg' ),
    9977            array( $this, 'markup_meta_boxes' ),
    100             self::POST_TYPE_SLUG,
     78            MES_Sponsor::POST_TYPE_SLUG,
    10179            'normal',
    10280            'default'
     
    10785            __( 'Contact Information', 'wordcamporg' ),
    10886            array( $this, 'markup_meta_boxes' ),
    109             self::POST_TYPE_SLUG,
     87            MES_Sponsor::POST_TYPE_SLUG,
    11088            'normal',
    11189            'default'
     
    11492
    11593    /**
    116      * Remove the taxonomy meta boxes, since we don't assign them directly.
    117      *
    118      * @param WP_Post $post
    119      */
    120     public function remove_meta_boxes( $post ) {
    121         remove_meta_box( 'mes-regionsdiv', null, 'side' );
    122     }
    123 
    124     /**
    12594     * Builds the markup for all meta boxes
    12695     *
     
    133102        switch ( $box['id'] ) {
    134103            case 'mes_regional_sponsorships':
    135                 $regions               = get_terms( self::REGIONS_SLUG, array( 'hide_empty' => false ) );
     104                $regions               = get_terms( MES_Region::TAXONOMY_SLUG, array( 'hide_empty' => false ) );
    136105                $sponsorship_levels    = get_posts( array( 'post_type' => MES_Sponsorship_Level::POST_TYPE_SLUG, 'numberposts' => -1 ) );
    137106                $regional_sponsorships = $this->populate_default_regional_sponsorships( get_post_meta( $post->ID, 'mes_regional_sponsorships', true ), $regions );
     
    227196        } else {
    228197            delete_post_meta( $post_id, 'mes_email_address' );
    229         }
    230     }
    231 
    232     /**
    233      * Render the dropdown element with regions for the WordCamp Post Type plugin
    234      *
    235      * @param string $key
    236      * @param string $value
    237      * @param string $field_name
    238      */
    239     public function wcpt_region_dropdown_render( $key, $value, $field_name ) {
    240         if ( 'Multi-Event Sponsor Region' != $key ) {
    241             return;
    242         }
    243 
    244         global $post;
    245 
    246         $regions         = get_terms( self::REGIONS_SLUG, array( 'hide_empty' => false ) );
    247         $selected_region = get_post_meta( $post->ID, $key, true );
    248 
    249         require( dirname( __DIR__ ) . '/views/template-region-dropdown.php' );
    250     }
    251 
    252     /**
    253      * Save the dropdown element with regions for the WordCamp Post Type plugin
    254      *
    255      * @param string $key
    256      * @param string $value
    257      * @param int    $post_id
    258      */
    259     public function wcpt_region_dropdown_save( $key, $value, $post_id ) {
    260         if ( 'Multi-Event Sponsor Region' != $key ) {
    261             return;
    262         }
    263 
    264         $post_key = wcpt_key_to_str( $key, 'wcpt_' );
    265         if ( isset( $_POST[ $post_key ] ) ) {
    266             update_post_meta( $post_id, $key, absint( $_POST[ $post_key ] ) );
    267198        }
    268199    }
Note: See TracChangeset for help on using the changeset viewer.