Ticket #8448: 8448.3-advices.patch
File 8448.3-advices.patch, 20.8 KB (added by , 4 years ago) |
---|
-
src/bp-core/admin/bp-core-admin-optouts.php
diff --git src/bp-core/admin/bp-core-admin-optouts.php src/bp-core/admin/bp-core-admin-optouts.php index a80b188e4..5df6047d0 100644
function bp_core_optouts_admin_load() { 55 55 // The per_page screen option. 56 56 add_screen_option( 'per_page', array( 'label' => _x( 'Nonmember opt-outs', 'Nonmember opt-outs per page (screen options)', 'buddypress' ) ) ); 57 57 58 get_current_screen()->add_help_tab( array( 59 'id' => 'bp-optouts-overview', 60 'title' => __( 'Overview', 'buddypress' ), 61 'content' => 62 '<p>' . __( 'This is the administration screen for nonmember opt-outs on your site.', 'buddypress' ) . '</p>' . 63 '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' . 64 '<p>' . __( 'You can reorder the list of opt-outs by clicking on the Email Address, User Who Contacted, Email Type or Date Modified column headers.', 'buddypress' ) . '</p>' . 65 '<p>' . __( 'Using the search form, you can search for an opt-out to a specific email address.', 'buddypress' ) . '</p>' 66 ) ); 67 68 get_current_screen()->add_help_tab( array( 69 'id' => 'bp-optouts-actions', 70 'title' => __( 'Actions', 'buddypress' ), 71 'content' => 72 '<p>' . __( 'Hovering over a row in the opt-outs list will display action links that allow you to manage the opt-out. You can perform the following actions:', 'buddypress' ) . '</p>' . 73 '<ul><li>' . __( '"Delete" allows you to delete the record of an opt-out. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' . 74 '<p>' . __( 'Bulk actions allow you to perform these actions for the selected rows.', 'buddypress' ) . '</p>' 75 ) ); 58 // Current screen. 59 $current_screen = get_current_screen(); 60 61 $current_screen->add_help_tab( 62 array( 63 'id' => 'bp-optouts-overview', 64 'title' => __( 'Overview', 'buddypress' ), 65 'content' => 66 '<p>' . __( 'This is the administration screen for nonmember opt-outs on your site.', 'buddypress' ) . '</p>' . 67 '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' . 68 '<p>' . __( 'You can reorder the list of opt-outs by clicking on the Email Address, User Who Contacted, Email Type or Date Modified column headers.', 'buddypress' ) . '</p>' . 69 '<p>' . __( 'Using the search form, you can search for an opt-out to a specific email address.', 'buddypress' ) . '</p>', 70 ) 71 ); 72 73 $current_screen->add_help_tab( 74 array( 75 'id' => 'bp-optouts-actions', 76 'title' => __( 'Actions', 'buddypress' ), 77 'content' => 78 '<p>' . __( 'Hovering over a row in the opt-outs list will display action links that allow you to manage the opt-out. You can perform the following actions:', 'buddypress' ) . '</p>' . 79 '<ul><li>' . __( '"Delete" allows you to delete the record of an opt-out. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' . 80 '<p>' . __( 'Bulk actions allow you to perform these actions for the selected rows.', 'buddypress' ) . '</p>', 81 ) 82 ); 76 83 77 84 // Help panel - sidebar links. 78 get_current_screen()->set_help_sidebar(85 $current_screen->set_help_sidebar( 79 86 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 80 87 '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 81 88 ); 82 89 83 90 // Add accessible hidden headings and text for the Pending Users screen. 84 get_current_screen()->set_screen_reader_content( array( 85 /* translators: accessibility text */ 86 'heading_views' => __( 'Filter opt-outs list', 'buddypress' ), 87 /* translators: accessibility text */ 88 'heading_pagination' => __( 'Opt-out list navigation', 'buddypress' ), 89 /* translators: accessibility text */ 90 'heading_list' => __( 'Opt-outs list', 'buddypress' ), 91 ) ); 91 $current_screen->set_screen_reader_content( 92 array( 93 /* translators: accessibility text */ 94 'heading_views' => __( 'Filter opt-outs list', 'buddypress' ), 95 /* translators: accessibility text */ 96 'heading_pagination' => __( 'Opt-out list navigation', 'buddypress' ), 97 /* translators: accessibility text */ 98 'heading_list' => __( 'Opt-outs list', 'buddypress' ), 99 ) 100 ); 92 101 93 102 } else { 94 103 if ( empty( $_REQUEST['optout_ids' ] ) ) { … … function bp_core_optouts_admin() { 233 242 234 243 <?php endif; ?> 235 244 236 <p><?php echo $notice['message']; ?></p>245 <p><?php echo esc_html( $notice['message'] ); ?></p> 237 246 </div> 238 247 239 248 <?php endif; … … function bp_core_optouts_admin_index() { 299 308 'action2', 300 309 '_wpnonce', 301 310 'optout_ids' 302 ), $_SERVER['REQUEST_URI'] 311 ), 312 $_SERVER['REQUEST_URI'] 303 313 ); 304 314 305 315 ?> … … function bp_core_optouts_admin_index() { 309 319 310 320 <?php 311 321 if ( $usersearch ) { 312 printf( '<span class="subtitle">' . __( 'Opt-outs with an email address matching “%s”', 'buddypress' ) . '</span>', esc_html( $usersearch ) ); 322 $num_results = (int) $bp_optouts_list_table->total_items; 323 printf( '<span class="subtitle">' . esc_html( _n( 'Opt-out with an email address matching “%s”', 'Opt-outs with an email address matching “%s”', $num_results, 'buddypress' ) ) . '</span>', esc_html( $usersearch ) ); 313 324 } 314 325 ?> 315 <p class="description"><?php _e( 'This table shows opt-out requests from people who are not members of this site, but have been contacted via communication from this site, and wish to receive no further communications.', 'buddypress' ); ?></p>326 <p class="description"><?php esc_html_e( 'This table shows opt-out requests from people who are not members of this site, but have been contacted via communication from this site, and wish to receive no further communications.', 'buddypress' ); ?></p> 316 327 317 328 <hr class="wp-header-end"> 318 329 … … function bp_core_optouts_admin_index() { 321 332 322 333 <form id="bp-optouts-search-form" action="<?php echo esc_url( $search_form_url ) ;?>"> 323 334 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" /> 324 <?php $bp_optouts_list_table->search_box( __( 'Search for a specific email address', 'buddypress' ), 'bp-optouts' ); ?>335 <?php $bp_optouts_list_table->search_box( esc_html__( 'Search for a specific email address', 'buddypress' ), 'bp-optouts' ); ?> 325 336 </form> 326 337 327 338 <form id="bp-optouts-form" action="<?php echo esc_url( $form_url );?>" method="post"> -
src/bp-core/bp-core-functions.php
diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php index 88e4b651b..e56c7453f 100644
function bp_get_widget_max_count_limit( $widget_class = '' ) { 4247 4247 * prompted the user to opt-out. 4248 4248 * @type string $date_modified Optional. Specify a time, else now will be used. 4249 4249 * } 4250 * @return false |int False on failure, ID of new (or existing) opt-out if successful.4250 * @return false|int False on failure, ID of new (or existing) opt-out if successful. 4251 4251 */ 4252 4252 function bp_add_optout( $args = array() ) { 4253 4253 $optout = new BP_Optout(); 4254 $r = bp_parse_args( $args, array( 4255 'email_address' => '', 4256 'user_id' => 0, 4257 'email_type' => '', 4258 'date_modified' => bp_core_current_time(), 4259 ), 'add_optout' ); 4254 $r = bp_parse_args( 4255 $args, array( 4256 'email_address' => '', 4257 'user_id' => 0, 4258 'email_type' => '', 4259 'date_modified' => bp_core_current_time(), 4260 ), 4261 'add_optout' 4262 ); 4260 4263 4261 4264 // Opt-outs must have an email address. 4262 4265 if ( empty( $r['email_address'] ) ) { … … function bp_add_optout( $args = array() ) { 4264 4267 } 4265 4268 4266 4269 // Avoid creating duplicate opt-outs. 4267 $optout_id = $optout->optout_exists( array( 4268 'email_address' => $r['email_address'], 4269 'user_id' => $r['user_id'], 4270 'email_type' => $r['email_type'], 4271 ) ); 4270 $optout_id = $optout->optout_exists( 4271 array( 4272 'email_address' => $r['email_address'], 4273 'user_id' => $r['user_id'], 4274 'email_type' => $r['email_type'], 4275 ) 4276 ); 4272 4277 4273 4278 if ( ! $optout_id ) { 4274 4279 // Set up the new opt-out. … … function bp_add_optout( $args = array() ) { 4289 4294 * @since 8.0.0 4290 4295 * 4291 4296 * @see BP_Optout::get() for a description of parameters and return values. 4297 * 4298 * @param array $args See {@link BP_Optout::get()}. 4299 * @return array See {@link BP_Optout::get()}. 4292 4300 */ 4293 4301 function bp_get_optouts( $args = array() ) { 4294 4302 $optout_class = new BP_Optout(); … … function bp_get_optouts( $args = array() ) { 4301 4309 * @since 8.0.0 4302 4310 * 4303 4311 * @param int $id ID of the optout to delete. 4312 * @return bool True on success, false on failure. 4304 4313 */ 4305 4314 function bp_delete_optout_by_id( $id = 0 ) { 4306 4315 $optout_class = new BP_Optout(); -
src/bp-core/classes/class-bp-optout.php
diff --git src/bp-core/classes/class-bp-optout.php src/bp-core/classes/class-bp-optout.php index 6d7725c34..b9a4822a6 100644
class BP_Optout { 282 282 283 283 // id. 284 284 if ( false !== $args['id'] ) { 285 $id_in = implode( ',', wp_parse_id_list( $args['id'] ) );285 $id_in = implode( ',', wp_parse_id_list( $args['id'] ) ); 286 286 $where_conditions['id'] = "id IN ({$id_in})"; 287 287 } 288 288 … … class BP_Optout { 323 323 $et_clean[] = $wpdb->prepare( '%s', sanitize_key( $et ) ); 324 324 } 325 325 326 $et_in = implode( ',', $et_clean );326 $et_in = implode( ',', $et_clean ); 327 327 $where_conditions['email_type'] = "email_type IN ({$et_in})"; 328 328 } 329 329 … … class BP_Optout { 463 463 // id. 464 464 if ( ! empty( $args['id'] ) ) { 465 465 $where_clauses['data']['id'] = absint( $args['id'] ); 466 $where_clauses['format'][] = '%d';466 $where_clauses['format'][] = '%d'; 467 467 } 468 468 469 469 // email_address. 470 470 if ( ! empty( $args['email_address'] ) ) { 471 471 $where_clauses['data']['email_address_hash'] = $args['email_address']; 472 $where_clauses['format'][] = '%s';472 $where_clauses['format'][] = '%s'; 473 473 } 474 474 475 475 // user_id. 476 476 if ( ! empty( $args['user_id'] ) ) { 477 477 $where_clauses['data']['user_id'] = absint( $args['user_id'] ); 478 $where_clauses['format'][] = '%d';478 $where_clauses['format'][] = '%d'; 479 479 } 480 480 481 481 // email_type. 482 482 if ( ! empty( $args['email_type'] ) ) { 483 483 $where_clauses['data']['email_type'] = $args['email_type']; 484 $where_clauses['format'][] = '%s';484 $where_clauses['format'][] = '%s'; 485 485 } 486 486 487 487 return $where_clauses; … … class BP_Optout { 530 530 $optouts_table_name = BP_Optout::get_table_name(); 531 531 532 532 // Parse the arguments. 533 $r = bp_parse_args( $args, array( 534 'id' => false, 535 'email_address' => false, 536 'user_id' => false, 537 'email_type' => false, 538 'search_terms' => '', 539 'order_by' => false, 540 'sort_order' => false, 541 'page' => false, 542 'per_page' => false, 543 'fields' => 'all', 544 ), 'bp_optout_get' ); 533 $r = bp_parse_args( 534 $args, 535 array( 536 'id' => false, 537 'email_address' => false, 538 'user_id' => false, 539 'email_type' => false, 540 'search_terms' => '', 541 'order_by' => false, 542 'sort_order' => false, 543 'page' => false, 544 'per_page' => false, 545 'fields' => 'all', 546 ), 547 'bp_optout_get' 548 ); 545 549 546 550 $sql = array( 547 551 'select' => "SELECT", … … class BP_Optout { 561 565 } 562 566 563 567 // WHERE. 564 $sql['where'] = self::get_where_sql( array( 565 'id' => $r['id'], 566 'email_address' => $r['email_address'], 567 'user_id' => $r['user_id'], 568 'email_type' => $r['email_type'], 569 'search_terms' => $r['search_terms'], 570 ) ); 568 $sql['where'] = self::get_where_sql( 569 array( 570 'id' => $r['id'], 571 'email_address' => $r['email_address'], 572 'user_id' => $r['user_id'], 573 'email_type' => $r['email_type'], 574 'search_terms' => $r['search_terms'], 575 ) 576 ); 571 577 572 578 // ORDER BY. 573 $sql['orderby'] = self::get_order_by_sql( array( 574 'order_by' => $r['order_by'], 575 'sort_order' => $r['sort_order'] 576 ) ); 579 $sql['orderby'] = self::get_order_by_sql( 580 array( 581 'order_by' => $r['order_by'], 582 'sort_order' => $r['sort_order'] 583 ) 584 ); 577 585 578 586 // LIMIT %d, %d. 579 $sql['pagination'] = self::get_paged_sql( array( 580 'page' => $r['page'], 581 'per_page' => $r['per_page'], 582 ) ); 587 $sql['pagination'] = self::get_paged_sql( 588 array( 589 'page' => $r['page'], 590 'per_page' => $r['per_page'], 591 ) 592 ); 583 593 584 594 $paged_optouts_sql = "{$sql['select']} {$sql['fields']} {$sql['from']} {$sql['where']} {$sql['orderby']} {$sql['pagination']}"; 585 595 … … class BP_Optout { 643 653 $optouts_table_name = BP_Optout::get_table_name(); 644 654 645 655 // Parse the arguments. 646 $r = bp_parse_args( $args, array( 647 'id' => false, 648 'email_address' => false, 649 'user_id' => false, 650 'email_type' => false, 651 'search_terms' => '', 652 'order_by' => false, 653 'sort_order' => false, 654 'page' => false, 655 'per_page' => false, 656 'fields' => 'all', 657 ), 'bp_optout_get_total_count' ); 656 $r = bp_parse_args( 657 $args, 658 array( 659 'id' => false, 660 'email_address' => false, 661 'user_id' => false, 662 'email_type' => false, 663 'search_terms' => '', 664 'order_by' => false, 665 'sort_order' => false, 666 'page' => false, 667 'per_page' => false, 668 'fields' => 'all', 669 ), 670 'bp_optout_get_total_count' 671 ); 658 672 659 673 // Build the query 660 674 $select_sql = "SELECT COUNT(*)"; … … class BP_Optout { 700 714 $retval = self::_update( $update['data'], $where['data'], $update['format'], $where['format'] ); 701 715 702 716 // Clear matching items from the cache. 703 $cache_args = $where_args;717 $cache_args = $where_args; 704 718 $cache_args['fields'] = 'ids'; 705 $maybe_cached_ids = self::get( $cache_args );719 $maybe_cached_ids = self::get( $cache_args ); 706 720 foreach ( $maybe_cached_ids as $invite_id ) { 707 721 wp_cache_delete( $invite_id, 'bp_optouts' ); 708 722 } … … class BP_Optout { 747 761 do_action( 'bp_optout_before_delete', $args ); 748 762 749 763 // Clear matching items from the cache. 750 $cache_args = $args;764 $cache_args = $args; 751 765 $cache_args['fields'] = 'ids'; 752 $maybe_cached_ids = self::get( $cache_args );766 $maybe_cached_ids = self::get( $cache_args ); 753 767 foreach ( $maybe_cached_ids as $invite_id ) { 754 768 wp_cache_delete( $invite_id, 'bp_optouts' ); 755 769 } … … class BP_Optout { 783 797 $exists = false; 784 798 785 799 $args['fields'] = 'ids'; 786 $optouts = BP_Optout::get( $args );800 $optouts = BP_Optout::get( $args ); 787 801 if ( $optouts ) { 788 802 $exists = current( $optouts ); 789 803 } 804 790 805 return $exists; 791 806 } 792 807 … … class BP_Optout { 806 821 'id' => $id, 807 822 ) ); 808 823 } 809 810 824 } -
src/bp-core/classes/class-bp-optouts-list-table.php
diff --git src/bp-core/classes/class-bp-optouts-list-table.php src/bp-core/classes/class-bp-optouts-list-table.php index 7615583d8..5201c9172 100644
class BP_Optouts_List_Table extends WP_Users_List_Table { 33 33 */ 34 34 public function __construct() { 35 35 // Define singular and plural labels, as well as whether we support AJAX. 36 parent::__construct( array( 37 'ajax' => false, 38 'plural' => 'optouts', 39 'singular' => 'optout', 40 'screen' => get_current_screen()->id, 41 ) ); 36 parent::__construct( 37 array( 38 'ajax' => false, 39 'plural' => 'optouts', 40 'singular' => 'optout', 41 'screen' => get_current_screen()->id, 42 ) 43 ); 42 44 } 43 45 44 46 /** … … class BP_Optouts_List_Table extends WP_Users_List_Table { 57 59 $paged = $this->get_pagenum(); 58 60 59 61 $args = array( 60 'search_terms' 61 'order_by' 62 'sort_order' 63 'page' 64 'per_page' 62 'search_terms' => $search, 63 'order_by' => 'date_modified', 64 'sort_order' => 'DESC', 65 'page' => $paged, 66 'per_page' => $per_page, 65 67 ); 66 68 67 69 if ( isset( $_REQUEST['orderby'] ) ) { … … class BP_Optouts_List_Table extends WP_Users_List_Table { 76 78 $optouts_class = new BP_Optout(); 77 79 $this->total_items = $optouts_class->get_total_count( $args ); 78 80 79 $this->set_pagination_args( array( 80 'total_items' => $this->total_items, 81 'per_page' => $per_page, 82 ) ); 81 $this->set_pagination_args( 82 array( 83 'total_items' => $this->total_items, 84 'per_page' => $per_page, 85 ) 86 ); 83 87 } 84 88 85 89 /** … … class BP_Optouts_List_Table extends WP_Users_List_Table { 102 106 ); 103 107 ?> 104 108 105 <h2 class="screen-reader-text"><?php 106 /* translators: accessibility text */ 107 _e( 'Filter opt-outs list', 'buddypress' ); 108 ?></h2> 109 <h2 class="screen-reader-text"> 110 <?php 111 /* translators: accessibility text */ 112 esc_html_e( 'Filter opt-outs list', 'buddypress' ); 113 ?> 114 </h2> 109 115 <ul class="subsubsub"> 110 116 <?php 111 117 /** … … class BP_Optouts_List_Table extends WP_Users_List_Table { 150 156 * 151 157 * @param array $value Array of columns to display. 152 158 */ 153 return apply_filters( 'bp_optouts_list_columns', array( 154 'cb' => '<input type="checkbox" />', 155 'email_address' => __( 'Email Address Hash', 'buddypress' ), 156 'username' => __( 'Email Sender', 'buddypress' ), 157 'user_registered' => __( 'Email Sender Registered', 'buddypress' ), 158 'email_type' => __( 'Email Type', 'buddypress' ), 159 'email_type_description' => __( 'Email Description', 'buddypress' ), 160 'optout_date_modified' => __( 'Date Modified', 'buddypress' ), 161 ) ); 159 return apply_filters( 160 'bp_optouts_list_columns', 161 array( 162 'cb' => '<input type="checkbox" />', 163 'email_address' => __( 'Email Address Hash', 'buddypress' ), 164 'username' => __( 'Email Sender', 'buddypress' ), 165 'user_registered' => __( 'Email Sender Registered', 'buddypress' ), 166 'email_type' => __( 'Email Type', 'buddypress' ), 167 'email_type_description' => __( 'Email Description', 'buddypress' ), 168 'optout_date_modified' => __( 'Date Modified', 'buddypress' ), 169 ) 170 ); 162 171 } 163 172 164 173 /** … … class BP_Optouts_List_Table extends WP_Users_List_Table { 192 201 */ 193 202 public function get_sortable_columns() { 194 203 return array( 195 'email_address' 196 'username' 197 'email_type' 198 'optout_date_modified' 204 'email_address' => 'email_address_hash', 205 'username' => 'user_id', 206 'email_type' => 'email_type', 207 'optout_date_modified' => 'date_modified', 199 208 ); 200 209 } 201 210 … … class BP_Optouts_List_Table extends WP_Users_List_Table { 226 235 * @return void 227 236 */ 228 237 public function single_row( $optout = null, $style = '', $role = '', $numposts = 0 ) { 229 echo '<tr' . $style . ' id="optout-' . esc_attr( $optout->id ) . '">';238 echo '<tr' . $style . ' id="optout-' . intval( $optout->id ) . '">'; 230 239 echo $this->single_row_columns( $optout ); 231 240 echo '</tr>'; 232 241 } … … class BP_Optouts_List_Table extends WP_Users_List_Table { 240 249 */ 241 250 public function column_cb( $optout = null ) { 242 251 ?> 243 <label class="screen-reader-text" for="optout_<?php echo intval( $optout->id ); ?>"><?php 244 /* translators: accessibility text */ 245 printf( esc_html__( 'Select opt-out request: %s', 'buddypress' ), $optout->id ); 246 ?></label> 252 <label class="screen-reader-text" for="optout_<?php echo intval( $optout->id ); ?>"> 253 <?php 254 /* translators: %d: accessibility text. */ 255 printf( esc_html__( 'Select opt-out request: %d', 'buddypress' ), intval( $optout->id ) ); 256 ?> 257 </label> 247 258 <input type="checkbox" id="optout_<?php echo intval( $optout->id ) ?>" name="optout_ids[]" value="<?php echo esc_attr( $optout->id ) ?>" /> 248 259 <?php 249 260 } … … class BP_Optouts_List_Table extends WP_Users_List_Table { 275 286 ), 276 287 $form_url 277 288 ); 278 $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), __( 'Delete', 'buddypress' ) );289 $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Delete', 'buddypress' ) ); 279 290 280 291 /** 281 292 * Filters the row actions for each opt-out in list. … … class BP_Optouts_List_Table extends WP_Users_List_Table { 304 315 return; 305 316 } 306 317 $user_link = bp_core_get_user_domain( $optout->user_id ); 307 echo $avatar . sprintf( '<strong><a href="%1$s" class="edit">%2$s</a></strong><br/>', esc_url( $user_link ), $inviter->user_login);318 echo $avatar . sprintf( '<strong><a href="%1$s" class="edit">%2$s</a></strong><br/>', esc_url( $user_link ), esc_html( $inviter->user_login ) ); 308 319 } 309 320 310 321 /**