Changeset 8085 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
- Timestamp:
- 01/16/2019 03:36:24 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
r8084 r8085 23 23 * Initialize WCPT Admin 24 24 */ 25 function __construct() {25 public function __construct() { 26 26 27 27 parent::__construct(); 28 28 29 // Add some general styling to the admin area 29 // Add some general styling to the admin area. 30 30 add_action( 'wcpt_admin_head', array( $this, 'admin_head' ) ); 31 31 32 // Scripts and CSS 32 // Scripts and CSS. 33 33 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); 34 34 35 // Post status transitions 35 // Post status transitions. 36 36 add_action( 'transition_post_status', array( $this, 'trigger_schedule_actions' ), 10, 3 ); 37 37 add_action( 'wcpt_approved_for_pre_planning', array( $this, 'add_organizer_to_central' ), 10 ); … … 41 41 42 42 add_filter( 43 'wp_insert_post_data', array( 43 'wp_insert_post_data', 44 array( 44 45 $this, 45 46 'require_complete_meta_to_publish_wordcamp', 46 ), 11, 2 47 ); // after enforce_post_status 48 49 // Cron jobs 47 ), 48 11, 49 2 50 ); // after enforce_post_status. 51 52 // Cron jobs. 50 53 add_action( 'plugins_loaded', array( $this, 'schedule_cron_jobs' ), 11 ); 51 54 add_action( 'wcpt_close_wordcamps_after_event', array( $this, 'close_wordcamps_after_event' ) ); … … 55 58 56 59 /** 57 * metabox ()58 *59 60 * Add the metabox 60 61 * 61 62 * @uses add_meta_box 62 63 */ 63 function metabox() {64 public function metabox() { 64 65 add_meta_box( 65 66 'wcpt_information', … … 104 105 * @return string 105 106 */ 106 static function get_event_label() {107 public static function get_event_label() { 107 108 return WordCamp_Application::get_event_label(); 108 109 } … … 113 114 * @return string 114 115 */ 115 static function get_event_type() {116 public static function get_event_type() { 116 117 return WordCamp_Application::get_event_type(); 117 118 } … … 120 121 * Check if a field is readonly. 121 122 * 122 * @param $key123 * @param string $key 123 124 * 124 125 * @return bool 125 126 */ 126 function _is_protected_field( $key ) {127 public function _is_protected_field( $key ) { 127 128 return self::is_protected_field( $key ); 128 129 } 129 130 131 /** 132 * Update mentor username. 133 * 134 * @param int $post_id 135 */ 130 136 public function update_mentor( $post_id ) { 131 137 if ( $this->get_event_type() !== get_post_type() ) { … … 133 139 } 134 140 135 // If the Mentor username changed, update the site 141 // If the Mentor username changed, update the site. 142 //phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified in `metabox_save` in class-event-admin.php. 136 143 $mentor_username = $_POST[ wcpt_key_to_str( 'Mentor WordPress.org User Name', 'wcpt_' ) ]; 137 if ( $mentor_username !== get_post_meta( $post_id, 'Mentor WordPress.org User Name', true )) {144 if ( get_post_meta( $post_id, 'Mentor WordPress.org User Name', true ) !== $mentor_username ) { 138 145 $this->add_mentor( get_post( $post_id ), $mentor_username ); 139 146 } … … 146 153 * These are used for the maps on Central, stats, etc. 147 154 * 148 * @param int $post_id Post id 149 * @param array $original_meta_values Original meta values before save 155 * @param int $post_id Post id. 156 * @param array $original_meta_values Original meta values before save. 150 157 */ 151 158 public function update_venue_address( $post_id, $original_meta_values ) { … … 154 161 } 155 162 156 // If the venue address was changed, update its coordinates 163 // If the venue address was changed, update its coordinates. 164 //phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified in `metabox_save` in class-event-admin.php. 157 165 $new_address = $_POST[ wcpt_key_to_str( 'Physical Address', 'wcpt_' ) ]; 158 166 if ( $new_address === $original_meta_values['Physical Address'][0] ) { … … 160 168 } 161 169 162 $request_url = add_query_arg( array( 163 'address' => rawurlencode( $new_address ), 164 ), 'https://maps.googleapis.com/maps/api/geocode/json' ); 170 $request_url = add_query_arg( 171 array( 172 'address' => rawurlencode( $new_address ), 173 ), 174 'https://maps.googleapis.com/maps/api/geocode/json' 175 ); 165 176 166 177 $key = apply_filters( 'wordcamp_google_maps_api_key', '', 'server' ); 167 178 168 179 if ( $key ) { 169 $request_url = add_query_arg( array( 170 'key' => $key, 171 ), $request_url ); 180 $request_url = add_query_arg( 181 array( 'key' => $key ), 182 $request_url 183 ); 172 184 } 173 185 … … 175 187 $body = json_decode( wp_remote_retrieve_body( $response ) ); 176 188 177 // Don't delete the existing (and probably good) values if the request failed 189 // Don't delete the existing (and probably good) values if the request failed. 178 190 if ( is_wp_error( $response ) || empty( $body->results[0]->address_components ) ) { 179 191 Logger\log( 'geocoding_failure', compact( 'request_url', 'response' ) ); … … 198 210 * @see https://developers.google.com/maps/documentation/geocoding/intro#Types API response schema 199 211 * 200 * @param $response212 * @param array $response 201 213 * 202 214 * @return array … … 225 237 226 238 case 'country': 227 $country_code = $component->short_name; // This is not guaranteed to be ISO 3166-1 alpha-2, but should match in most cases 239 $country_code = $component->short_name; // This is not guaranteed to be ISO 3166-1 alpha-2, but should match in most cases. 228 240 $country_name = $component->long_name; 229 241 break; … … 272 284 * @return array 273 285 */ 274 static function meta_keys( $meta_group = '' ) {286 public static function meta_keys( $meta_group = '' ) { 275 287 /* 276 288 * Warning: These keys are used for both the input field label and the postmeta key, so if you want to … … 289 301 'Organizer Name' => 'text', 290 302 'WordPress.org Username' => 'text', 291 'Email Address' => 'text', // Note: This is the lead organizer's e-mail address, which is different than the "E-mail Address" field 303 'Email Address' => 'text', // Note: This is the lead organizer's e-mail address, which is different than the "E-mail Address" field. 292 304 'Telephone' => 'text', 293 305 'Mailing Address' => 'textarea', … … 342 354 343 355 case 'contributor': 344 // These fields names need to be unique, hence the 'Contributor' prefix on each one 356 // These fields names need to be unique, hence the 'Contributor' prefix on each one. 345 357 $retval = array( 346 358 'Contributor Day' => 'checkbox', … … 361 373 'URL' => 'wc-url', 362 374 'E-mail Address' => 'text', 363 // Note: This is the address for the entire organizing team, which is different than the "Email Address" field 375 // Note: This is the address for the entire organizing team, which is different than the "Email Address" field. 364 376 'Twitter' => 'text', 365 377 'WordCamp Hashtag' => 'text', … … 457 469 * @return array 458 470 */ 459 static function get_venue_address_meta_keys() {471 public static function get_venue_address_meta_keys() { 460 472 return array( 461 473 '_venue_coordinates', … … 472 484 * Adds jQuery UI 473 485 */ 474 function admin_scripts() {475 476 // Edit WordCamp screen 486 public function admin_scripts() { 487 488 // Edit WordCamp screen. 477 489 if ( WCPT_POST_TYPE_ID === get_post_type() ) { 478 490 479 // Default data 491 // Default data. 480 492 $data = array( 481 493 'Mentors' => array( … … 487 499 ); 488 500 489 // Only include mentor data if the Mentor username field is editable 501 // Only include mentor data if the Mentor username field is editable. 490 502 if ( current_user_can( 'wordcamp_manage_mentors' ) ) { 491 503 $data['Mentors']['data'] = Mentors_Dashboard\get_all_mentor_data(); … … 501 513 502 514 /** 503 * admin_head ()504 *505 515 * Add some general styling to the admin area 506 516 */ 507 function admin_head() {508 if ( ! empty( $_GET['post_type'] ) && $_GET['post_type'] == WCPT_POST_TYPE_ID) : ?>517 public function admin_head() { 518 if ( ! empty( $_GET['post_type'] ) && WCPT_POST_TYPE_ID == $_GET['post_type'] ) : ?> 509 519 510 520 .column-title { width: 40%; } … … 516 526 517 527 /** 518 * user_profile_update ()519 *520 528 * Responsible for showing additional profile options and settings 521 529 * 522 530 * @todo Everything 523 531 */ 524 function user_profile_update( $user_id ) {532 public function user_profile_update( $user_id ) { 525 533 if ( ! wcpt_has_access() ) { 526 534 return false; … … 529 537 530 538 /** 531 * user_profile_wordcamp ()532 *533 539 * Responsible for saving additional profile options and settings 534 540 * 535 541 * @todo Everything 536 542 */ 537 function user_profile_wordcamp( $profileuser ) {543 public function user_profile_wordcamp( $profileuser ) { 538 544 if ( ! wcpt_has_access() ) { 539 545 return false; … … 541 547 ?> 542 548 543 <h3><?php _e( 'WordCamps', 'wcpt' ); ?></h3>549 <h3><?php esc_html_e( 'WordCamps', 'wcpt' ); ?></h3> 544 550 545 551 <table class="form-table"> 546 552 <tr valign="top"> 547 <th scope="row"><?php _e( 'WordCamps', 'wcpt' ); ?></th>553 <th scope="row"><?php esc_html_e( 'WordCamps', 'wcpt' ); ?></th> 548 554 549 555 <td> … … 556 562 557 563 /** 558 * column_headers ()559 *560 564 * Manage the column headers 561 565 * 562 566 * @param array $columns 567 * 563 568 * @return array $columns 564 569 */ 565 function column_headers( $columns ) {570 public function column_headers( $columns ) { 566 571 $columns = array( 567 572 'cb' => '<input type="checkbox" />', … … 577 582 578 583 /** 579 * column_data ( $column, $post_id )580 *581 584 * Print extra columns 582 585 * … … 584 587 * @param int $post_id 585 588 */ 586 function column_data( $column, $post_id ) {587 if ( $_GET['post_type'] !== WCPT_POST_TYPE_ID) {589 public function column_data( $column, $post_id ) { 590 if ( WCPT_POST_TYPE_ID !== $_GET['post_type'] ) { 588 591 return $column; 589 592 } … … 591 594 switch ( $column ) { 592 595 case 'wcpt_location': 593 echo wcpt_get_wordcamp_location() ? wcpt_get_wordcamp_location() : __( 'No Location', 'wcpt');596 echo esc_html( wcpt_get_wordcamp_location() ? wcpt_get_wordcamp_location() : __( 'No Location', 'wcpt' ) ); 594 597 break; 595 598 596 599 case 'wcpt_date': 597 // Has a start date 598 if ( $start = wcpt_get_wordcamp_start_date() ) { 599 600 // Has an end date 601 if ( $end = wcpt_get_wordcamp_end_date() ) { 600 // Has a start date. 601 $start = wcpt_get_wordcamp_start_date(); 602 if ( $start ) { 603 604 // Has an end date. 605 $end = wcpt_get_wordcamp_end_date(); 606 if ( $end ) { 602 607 $string_date = sprintf( __( 'Start: %1$s<br />End: %2$s', 'wcpt' ), $start, $end ); 603 608 604 // No end date 609 // No end date. 605 610 } else { 606 611 $string_date = sprintf( __( 'Start: %1$s', 'wcpt' ), $start ); 607 612 } 608 613 609 // No date 614 // No date. 610 615 } else { 611 616 $string_date = __( 'No Date', 'wcpt' ); 612 617 } 613 618 614 echo $string_date;619 echo wp_kses( $string_date, array( 'br' => array() ) ); 615 620 break; 616 621 617 622 case 'wcpt_organizer': 618 echo wcpt_get_wordcamp_organizer_name() ? wcpt_get_wordcamp_organizer_name() : __( 'No Organizer', 'wcpt');623 echo esc_html( wcpt_get_wordcamp_organizer_name() ? wcpt_get_wordcamp_organizer_name() : __( 'No Organizer', 'wcpt' ) ); 619 624 break; 620 625 621 626 case 'wcpt_venue': 622 echo wcpt_get_wordcamp_venue_name() ? wcpt_get_wordcamp_venue_name() : __( 'No Venue', 'wcpt');627 echo esc_html( wcpt_get_wordcamp_venue_name() ? wcpt_get_wordcamp_venue_name() : __( 'No Venue', 'wcpt' ) ); 623 628 break; 624 629 } … … 626 631 627 632 /** 628 * post_row_actions ( $actions, $post )629 *630 633 * Remove the quick-edit action link and display the description under 631 634 * … … 634 637 * @return array $actions 635 638 */ 636 function post_row_actions( $actions, $post ) {639 public function post_row_actions( $actions, $post ) { 637 640 if ( WCPT_POST_TYPE_ID == $post->post_type ) { 638 641 unset( $actions['inline hide-if-no-js'] ); … … 640 643 $wc = array(); 641 644 642 if ( $wc_location = wcpt_get_wordcamp_location() ) { 645 $wc_location = wcpt_get_wordcamp_location(); 646 if ( $wc_location ) { 643 647 $wc['location'] = $wc_location; 644 648 } 645 649 646 if ( $wc_url = make_clickable( wcpt_get_wordcamp_url() ) ) { 650 $wc_url = make_clickable( wcpt_get_wordcamp_url() ); 651 if ( $wc_url ) { 647 652 $wc['url'] = $wc_url; 648 653 } 649 654 650 echo implode( ' - ', (array) $wc);655 echo wp_kses( implode( ' - ', (array) $wc ), wp_kses_allowed_html() ); 651 656 } 652 657 … … 672 677 if ( 'wcpt-pre-planning' == $new_status ) { 673 678 do_action( 'wcpt_approved_for_pre_planning', $post ); 674 } elseif ( $old_status == 'wcpt-needs-schedule' && $new_status == 'wcpt-scheduled') {679 } elseif ( 'wcpt-needs-schedule' == $old_status && 'wcpt-scheduled' == $new_status ) { 675 680 do_action( 'wcpt_added_to_final_schedule', $post ); 676 681 } … … 689 694 */ 690 695 public function add_organizer_to_central( $post ) { 696 697 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- WordCamp status can be moved to pre-planning status only from the admin edit screen where nonce is already verified. 691 698 $lead_organizer = get_user_by( 'login', $_POST['wcpt_wordpress_org_username'] ); 692 699 … … 767 774 */ 768 775 public function enforce_post_status( $post_data, $post_data_raw ) { 769 if ( $post_data['post_type'] != WCPT_POST_TYPE_ID || empty( $_POST['post_ID'] ) ) {776 if ( WCPT_POST_TYPE_ID != $post_data['post_type'] || empty( $post_data_raw['ID'] ) ) { 770 777 return $post_data; 771 778 } 772 779 773 $post = get_post( $ _POST['post_ID'] );780 $post = get_post( $post_data_raw['post_ID'] ); 774 781 if ( ! $post ) { 775 782 return $post_data; … … 814 821 $required_scheduled_fields = $this->get_required_fields( 'scheduled' ); 815 822 816 // Check pending posts 817 if ( 'wcpt-needs-site' == $post_data['post_status'] && absint( $ _POST['post_ID'] ) > $min_site_id ) {823 // Check pending posts. 824 if ( 'wcpt-needs-site' == $post_data['post_status'] && absint( $post_data_raw['ID'] ) > $min_site_id ) { 818 825 foreach ( $required_needs_site_fields as $field ) { 826 827 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce check would have done in `metabox_save`. 819 828 $value = $_POST[ wcpt_key_to_str( $field, 'wcpt_' ) ]; 820 829 … … 827 836 } 828 837 829 // Check published posts 830 if ( 'wcpt-scheduled' == $post_data['post_status'] && isset( $ _POST['post_ID'] ) && absint( $_POST['post_ID'] ) > $min_site_id ) {838 // Check published posts. 839 if ( 'wcpt-scheduled' == $post_data['post_status'] && isset( $post_data_raw['ID'] ) && absint( $post_data_raw['ID'] ) > $min_site_id ) { 831 840 foreach ( $required_scheduled_fields as $field ) { 841 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce check would have done in `metabox_save`. 832 842 $value = $_POST[ wcpt_key_to_str( $field, 'wcpt_' ) ]; 833 843 … … 846 856 * Get a list of fields required to move to a certain post status 847 857 * 848 * @param string $status 'needs-site' | 'scheduled' | 'any' 858 * @param string $status 'needs-site' | 'scheduled' | 'any'. 849 859 * 850 860 * @return array … … 854 864 855 865 $scheduled = array( 856 // WordCamp 866 // WordCamp. 857 867 'Start Date (YYYY-mm-dd)', 858 868 'Location', … … 862 872 'Multi-Event Sponsor Region', 863 873 864 // Organizing Team 874 // Organizing Team. 865 875 'Organizer Name', 866 876 'WordPress.org Username', … … 873 883 'Budget Wrangler E-mail Address', 874 884 875 // Venue 876 'Physical Address', // used to build stats 885 // Venue. 886 'Physical Address', // used to build stats. 877 887 ); 878 888 … … 895 905 } 896 906 907 /** 908 * TODO: Add description. 909 * 910 * @return array 911 */ 897 912 public static function get_protected_fields() { 898 913 $protected_fields = array(); … … 900 915 if ( ! current_user_can( 'wordcamp_manage_mentors' ) ) { 901 916 $protected_fields = array_merge( 902 $protected_fields, array( 917 $protected_fields, 918 array( 903 919 'Mentor WordPress.org User Name', 904 920 'Mentor Name', … … 910 926 if ( ! current_user_can( 'wordcamp_wrangle_wordcamps' ) ) { 911 927 $protected_fields = array_merge( 912 $protected_fields, array( 928 $protected_fields, 929 array( 913 930 'Multi-Event Sponsor Region', 914 931 ) … … 941 958 942 959 $screen = get_current_screen(); 943 944 960 945 961 if ( empty( $post->post_type ) || $this->get_event_type() != $post->post_type || 'post' !== $screen->base ) { … … 1056 1072 } 1057 1073 } 1058 endif; // class_exists check 1074 endif; // class_exists check. 1059 1075 1060 1076 /** … … 1066 1082 } 1067 1083 1084 /** 1085 * Displays organizer metabox 1086 */ 1068 1087 function wcpt_organizer_metabox() { 1069 1088 $meta_keys = $GLOBALS['wordcamp_admin']->meta_keys( 'organizer' ); … … 1071 1090 } 1072 1091 1092 /** 1093 * Displays venue metabox 1094 */ 1073 1095 function wcpt_venue_metabox() { 1074 1096 $meta_keys = $GLOBALS['wordcamp_admin']->meta_keys( 'venue' ); … … 1076 1098 } 1077 1099 1100 /** 1101 * Displays contributor metabox 1102 */ 1078 1103 function wcpt_contributor_metabox() { 1079 1104 $meta_keys = $GLOBALS['wordcamp_admin']->meta_keys( 'contributor' ); … … 1082 1107 1083 1108 /** 1084 * wcpt_metabox ()1085 *1086 1109 * The metabox that holds all of the additional information 1087 1110 * … … 1095 1118 $required_fields = WordCamp_Admin::get_required_fields( 'any' ); 1096 1119 1097 // @todo When you refactor meta_keys() to support changing labels -- see note in meta_keys() -- also make it support these notes 1120 // @todo When you refactor meta_keys() to support changing labels -- see note in meta_keys() -- also make it support these notes. 1098 1121 $messages = array( 1099 1122 'Telephone' => 'Required for shipping.', 1100 1123 'Mailing Address' => 'Shipping address.', 1101 'Physical Address' => 'Please include the city, state/province and country.', // So it can be geocoded correctly for the map 1124 'Physical Address' => 'Please include the city, state/province and country.', // So it can be geocoded correctly for the map. 1102 1125 'Global Sponsorship Grant Amount' => 'No commas, thousands separators or currency symbols. Ex. 1234.56', 1103 1126 'Global Sponsorship Grant' => 'Deprecated.',
Note: See TracChangeset
for help on using the changeset viewer.