Changeset 4525 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
- Timestamp:
- 12/13/2016 08:45:19 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
r4404 r4525 1 1 <?php 2 3 use WordCamp\Mentors_Dashboard; 2 4 3 5 if ( ! class_exists( 'WordCamp_Admin' ) ) : … … 37 39 // Scripts and CSS 38 40 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); 39 add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ), 99 );40 41 add_action( 'admin_print_styles', array( $this, 'admin_styles' ) ); 41 42 … … 179 180 $post_value = wcpt_key_to_str( $key, 'wcpt_' ); 180 181 $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 } 181 187 182 188 switch ( $value ) { … … 381 387 'Safety Wrangler Name' => 'text', 382 388 'Safety Wrangler E-mail Address' => 'text', 389 'Mentor WordPress.org User Name' => 'text', 383 390 'Mentor Name' => 'text', 384 391 'Mentor E-mail Address' => 'text', … … 461 468 'Safety Wrangler Name' => 'text', 462 469 'Safety Wrangler E-mail Address' => 'text', 470 'Mentor WordPress.org User Name' => 'text', 463 471 'Mentor Name' => 'text', 464 472 'Mentor E-mail Address' => 'text', … … 484 492 */ 485 493 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 } 507 527 } 508 528 … … 905 925 906 926 /** 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 /** 907 948 * Add our custom admin notice keys to the redirect URL. 908 949 * … … 1083 1124 foreach ( $meta_keys as $key => $value ) : 1084 1125 $object_name = wcpt_key_to_str( $key, 'wcpt_' ); 1126 $readonly = ( WordCamp_Admin::is_protected_field( $key ) ) ? ' readonly="readonly"' : ''; 1085 1127 ?> 1086 1128 … … 1090 1132 <p> 1091 1133 <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; ?> /> 1093 1135 </p> 1094 1136 … … 1108 1150 case 'text' : ?> 1109 1151 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; ?> /> 1111 1153 1112 1154 <?php break; … … 1120 1162 ?> 1121 1163 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; ?> /> 1123 1165 1124 1166 <?php break; 1125 1167 case 'textarea' : ?> 1126 1168 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> 1128 1170 1129 1171 <?php break;
Note: See TracChangeset
for help on using the changeset viewer.