WordPress.org

Making WordPress.org

Changeset 1302


Ignore:
Timestamp:
02/24/2015 07:58:53 PM (7 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.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors
Files:
1 added
4 edited

Legend:

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

    r623 r1302  
    1313
    1414require_once( __DIR__ . '/classes/multi-event-sponsors.php' );
     15require_once( __DIR__ . '/classes/mes-region.php' );
    1516require_once( __DIR__ . '/classes/mes-sponsor.php' );
    1617require_once( __DIR__ . '/classes/mes-sponsorship-level.php' );
    1718
    1819$GLOBALS['multi_event_sponsors']  = new Multi_Event_Sponsors();
     20$GLOBALS['mes_sponsor']           = new MES_Region();
    1921$GLOBALS['mes_sponsor']           = new MES_Sponsor();
    2022$GLOBALS['mes_sponsorship_level'] = new MES_Sponsorship_Level();
  • 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    }
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsorship-level.php

    r716 r1302  
    1616    public function __construct() {
    1717        add_action( 'init',                                   array( $this, 'create_post_type' ) );
    18         add_action( 'add_meta_boxes_' . self::POST_TYPE_SLUG, array( $this, 'remove_meta_boxes' ) );
    1918        add_action( 'admin_init',                             array( $this, 'add_meta_boxes' ) );
    2019        add_action( 'save_post',                              array( $this, 'save_post' ), 10, 2 );
    2120        add_filter( 'the_content',                            array( $this, 'add_header_footer_text' ) );
     21
     22        // todo readjust whitepsace after this commit
    2223    }
    2324
     
    5859            'query_var'       => true,
    5960            'supports'        => array( 'title', 'editor', 'author', 'excerpt', 'revisions' ),
    60             'taxonomies'      => array( MES_Sponsor::REGIONS_SLUG ),
     61            'taxonomies'      => array( MES_Region::TAXONOMY_SLUG ),
    6162        );
    6263
    6364        register_post_type( self::POST_TYPE_SLUG, $post_type_params );
    64     }
    65 
    66     /**
    67      * Remove the taxonomy meta boxes, since we don't assign them directly.
    68      *
    69      * @param WP_Post $post
    70      */
    71     public function remove_meta_boxes( $post ) {
    72         remove_meta_box( 'mes-regionsdiv', null, 'side' );
    7365    }
    7466
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/multi-event-sponsors.php

    r845 r1302  
    4141    public function shortcode_multi_event_sponsors( $parameters ) {
    4242        $sponsors           = $this->reindex_array_by_object_id( get_posts( array( 'post_type' => MES_Sponsor::POST_TYPE_SLUG, 'numberposts' => -1 ) ) );
    43         $regions            = $this->reindex_array_by_object_id( get_terms( MES_Sponsor::REGIONS_SLUG, array( 'hide_empty' => false ) ) );
     43        $regions            = $this->reindex_array_by_object_id( get_terms( MES_Region::TAXONOMY_SLUG, array( 'hide_empty' => false ) ) );
    4444        $sponsorship_levels = $this->reindex_array_by_object_id( get_posts( array( 'post_type' => MES_Sponsorship_Level::POST_TYPE_SLUG, 'numberposts' => -1 ) ) );
    4545        $grouped_sponsors   = $this->group_sponsors_by_region_and_level( $sponsors );
     
    5555     * This makes for efficient direct access when the ID is known.
    5656     *
    57      * @param $array
    58      * @return mixed
     57     * @param array $old_array
     58     * @return array
    5959     */
    6060    protected function reindex_array_by_object_id( $old_array ) {
     
    124124     */
    125125    protected function uksort_regions( $region_a_id, $region_b_id ) {
    126         $region_a = get_term( $region_a_id, MES_Sponsor::REGIONS_SLUG );
    127         $region_b = get_term( $region_b_id, MES_Sponsor::REGIONS_SLUG );
     126        $region_a = get_term( $region_a_id, MES_Region::TAXONOMY_SLUG );
     127        $region_b = get_term( $region_b_id, MES_Region::TAXONOMY_SLUG );
    128128
    129129        if ( $region_a->name == $region_b->name ) {
Note: See TracChangeset for help on using the changeset viewer.