Making WordPress.org

Changeset 1305


Ignore:
Timestamp:
02/24/2015 11:21:48 PM (11 years ago)
Author:
iandunn
Message:

Multi Event Sponsors: Collect camera kit wrangler address for each region.

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

Legend:

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

    r1302 r1305  
    1616    public function __construct() {
    1717        add_action( 'init',               array( $this, 'create_taxonomy' ) );
     18        add_action( self::TAXONOMY_SLUG . '_add_form_fields',  array( $this, 'markup_meta_fields' ) );
     19        add_action( self::TAXONOMY_SLUG . '_edit_form_fields', array( $this, 'markup_meta_fields' ) );
     20        add_action( 'create_' . self::TAXONOMY_SLUG,           array( $this, 'save_meta_fields' ) );
     21        add_action( 'edited_' . self::TAXONOMY_SLUG,           array( $this, 'save_meta_fields' ) );
    1822        add_action( 'add_meta_boxes' ,    array( $this, 'remove_meta_box' ),             10, 2 );
    1923        add_action( 'wcpt_metabox_value', array( $this, 'wcpt_region_dropdown_render' ), 10, 3 );
    2024        add_action( 'wcpt_metabox_save',  array( $this, 'wcpt_region_dropdown_save' ),   10, 3 );
     25
     26        // todo readjust whitespace after this commit
    2127    }
    2228
     
    3743        if ( ! taxonomy_exists( self::TAXONOMY_SLUG ) ) {
    3844            register_taxonomy( self::TAXONOMY_SLUG, MES_Sponsor::POST_TYPE_SLUG, $region_params );
     45        }
     46    }
     47
     48    /**
     49     * Markup the UI for adding and editing meta fields
     50     */
     51    public function markup_meta_fields() {
     52        $camera_wranglers      = get_option( 'mes_region_camera_wranglers', array() );
     53        $camera_wrangler_email = '';
     54        $region_id             = empty( $_GET['tag_ID'] ) ? false : absint( $_GET['tag_ID'] );
     55
     56        if ( $region_id && ! empty( $camera_wranglers[ $region_id ] ) ) {
     57            $camera_wrangler_email = $camera_wranglers[ $_GET['tag_ID'] ];
     58        }
     59
     60        require_once( dirname( __DIR__ ) . '/views/taxonomy-meta-region.php' );
     61    }
     62
     63    /**
     64     * Save meta fields when Region terms are added and edited
     65     *
     66     * @todo Currently there's no way to alert the user if data validation failed and their changes weren't saved,
     67     *       but #10142 might introduce one.
     68     *
     69     * @param int $term_id
     70     */
     71    public function save_meta_fields( $term_id ) {
     72        global $wp_list_table;
     73        $taxonomy = get_taxonomy( self::TAXONOMY_SLUG );
     74
     75        if ( is_a( $wp_list_table, 'WP_Terms_List_Table' ) && 'editedtag' == $wp_list_table->current_action() ) {
     76            $nonce_value  = $_POST['mes_edit_region_meta_nonce'];
     77            $nonce_action = "mes_edit_region_{$term_id}_meta";
     78        } else {
     79            $nonce_value  = $_POST['mes_add_region_meta_nonce'];
     80            $nonce_action = 'mes_add_region_meta';
     81        }
     82
     83        if ( ! current_user_can( $taxonomy->cap->edit_terms ) || ! wp_verify_nonce( $nonce_value, $nonce_action ) ) {
     84            return;
     85        }
     86
     87        $camera_wrangler_email = $_POST['camera-wrangler-email'];
     88
     89        if ( is_email( $camera_wrangler_email ) ) {
     90            $camera_wranglers             = get_option( 'mes_region_camera_wranglers', array() );
     91            $camera_wranglers[ $term_id ] = $camera_wrangler_email;
     92
     93            update_option( 'mes_region_camera_wranglers', $camera_wranglers );
    3994        }
    4095    }
Note: See TracChangeset for help on using the changeset viewer.