Making WordPress.org


Ignore:
Timestamp:
12/13/2016 08:45:19 PM (9 years ago)
Author:
coreymckrill
Message:

Mentor Dashboard: Use dotorg usernames to id mentors instead of email

  • Adds the Mentor WordPress.org User Name field to wcpt.
  • Introduces "protected" fields in wcpt, which will be marked as readonly unless current user has specific caps. Used to make all mentor fields in the wcpt edit screen readonly unless current user can manage the network.
  • Adds a dropdown pick list of current mentors next to Mentor WordPress.org User Name that will fill in username, name, and email when a mentor is chosen. This only appears if current user has the right caps.
  • Adds a field in the Mentor Dashboard for managing the list of current mentors based on their dotorg usernames.
  • Uses dotorg username to determine which camps a mentor currently has, with their dotorg account email address as a backup.
  • All camps that don't have a value for Mentor WordPress.org User Name or whose value doesn't match a current mentor will appear in the "Active Camps that don't have a mentor" list.
  • Enqueues existing admin.js script for wcpt instead of printing it in the footer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r4404 r4525  
    11<?php
     2
     3use WordCamp\Mentors_Dashboard;
    24
    35if ( ! class_exists( 'WordCamp_Admin' ) ) :
     
    3739        // Scripts and CSS
    3840        add_action( 'admin_enqueue_scripts',                          array( $this, 'admin_scripts' ) );
    39         add_action( 'admin_print_scripts',                            array( $this, 'admin_print_scripts' ), 99 );
    4041        add_action( 'admin_print_styles',                             array( $this, 'admin_styles' ) );
    4142
     
    179180            $post_value   = wcpt_key_to_str( $key, 'wcpt_' );
    180181            $values[ $key ] = isset( $_POST[ $post_value ] ) ? esc_attr( $_POST[ $post_value ] ) : '';
     182
     183            // Don't update protected fields
     184            if ( self::is_protected_field( $key ) ) {
     185                continue;
     186            }
    181187
    182188            switch ( $value ) {
     
    381387                    'Safety Wrangler Name'                           => 'text',
    382388                    'Safety Wrangler E-mail Address'                 => 'text',
     389                    'Mentor WordPress.org User Name'                 => 'text',
    383390                    'Mentor Name'                                    => 'text',
    384391                    'Mentor E-mail Address'                          => 'text',
     
    461468                    'Safety Wrangler Name'                           => 'text',
    462469                    'Safety Wrangler E-mail Address'                 => 'text',
     470                    'Mentor WordPress.org User Name'                 => 'text',
    463471                    'Mentor Name'                                    => 'text',
    464472                    'Mentor E-mail Address'                          => 'text',
     
    484492     */
    485493    function admin_scripts() {
    486         if ( get_post_type() == WCPT_POST_TYPE_ID )
    487             wp_enqueue_script( 'jquery-ui-datepicker' );
    488     }
    489 
    490     /**
    491      * Print our scripts for the Edit WordCamp screen
    492      *
    493      * If this file grows larger, it'd make sense to switch to using wp_enqueue_script().
    494      */
    495     function admin_print_scripts() {
    496         if ( WCPT_POST_TYPE_ID !== get_post_type() ) {
    497             return;
    498         }
    499 
    500         ?>
    501 
    502         <script>
    503             <?php require_once( dirname( __DIR__ ) . '/javascript/wcpt-wordcamp/admin.js' ); ?>
    504         </script>
    505 
    506         <?php
     494        wp_register_script(
     495            'wcpt-admin',
     496            WCPT_URL . 'javascript/wcpt-wordcamp/admin.js',
     497            array( 'jquery', 'jquery-ui-datepicker' ),
     498            WCPT_VERSION,
     499            true
     500        );
     501
     502        // Edit WordCamp screen
     503        if ( WCPT_POST_TYPE_ID === get_post_type() ) {
     504            wp_enqueue_script( 'wcpt-admin' );
     505
     506            // Default data
     507            $data = array(
     508                'Mentors' => array(
     509                    'l10n' => array(
     510                        'selectLabel' => esc_html__( 'Available mentors', 'wordcamporg' ),
     511                        'confirm'     => esc_html__( 'Update Mentor field contents?', 'wordcamporg' ),
     512                    ),
     513                )
     514            );
     515
     516            // Only include mentor data if the Mentor username field is editable
     517            if ( current_user_can( 'manage_network' ) ) {
     518                $data['Mentors']['data'] = Mentors_Dashboard\get_all_mentor_data();
     519            }
     520
     521            wp_localize_script(
     522                'wcpt-admin',
     523                'wordCampPostType',
     524                $data
     525            );
     526        }
    507527    }
    508528
     
    905925
    906926    /**
     927     * Check if a field should be readonly, based on the current user's caps.
     928     *
     929     * @param string $field_name The field to check.
     930     *
     931     * @return bool
     932     */
     933    public static function is_protected_field( $field_name ) {
     934        $protected_fields = array();
     935
     936        if ( ! current_user_can( 'manage_network' ) ) {
     937            $protected_fields += array(
     938                'Mentor WordPress.org User Name',
     939                'Mentor Name',
     940                'Mentor E-mail Address',
     941            );
     942        }
     943
     944        return in_array( $field_name, $protected_fields );
     945    }
     946
     947    /**
    907948     * Add our custom admin notice keys to the redirect URL.
    908949     *
     
    10831124    foreach ( $meta_keys as $key => $value ) :
    10841125        $object_name = wcpt_key_to_str( $key, 'wcpt_' );
     1126        $readonly = ( WordCamp_Admin::is_protected_field( $key ) ) ? ' readonly="readonly"' : '';
    10851127    ?>
    10861128
     
    10901132                <p>
    10911133                    <strong><?php echo $key; ?></strong>:
    1092                     <input type="checkbox" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>" <?php checked( get_post_meta( $post_id, $key, true ) ); ?> />
     1134                    <input type="checkbox" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>" <?php checked( get_post_meta( $post_id, $key, true ) ); ?><?php echo $readonly; ?> />
    10931135                </p>
    10941136
     
    11081150                        case 'text' : ?>
    11091151
    1110                             <input type="text" size="36" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>" value="<?php echo esc_attr( get_post_meta( $post_id, $key, true ) ); ?>" />
     1152                            <input type="text" size="36" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>" value="<?php echo esc_attr( get_post_meta( $post_id, $key, true ) ); ?>"<?php echo $readonly; ?> />
    11111153
    11121154                        <?php break;
     
    11201162                            ?>
    11211163
    1122                             <input type="text" size="36" class="date-field" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>" value="<?php echo $date; ?>" />
     1164                            <input type="text" size="36" class="date-field" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>" value="<?php echo $date; ?>"<?php echo $readonly; ?> />
    11231165
    11241166                        <?php break;
    11251167                        case 'textarea' : ?>
    11261168
    1127                             <textarea rows="4" cols="23" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>"><?php echo esc_attr( get_post_meta( $post_id, $key, true ) ); ?></textarea>
     1169                            <textarea rows="4" cols="23" name="<?php echo $object_name; ?>" id="<?php echo $object_name; ?>"<?php echo $readonly; ?>><?php echo esc_attr( get_post_meta( $post_id, $key, true ) ); ?></textarea>
    11281170
    11291171                        <?php break;
Note: See TracChangeset for help on using the changeset viewer.