[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Opt-outs management. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 8.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Set up the Opt-outs admin page. 15 * 16 * Loaded before the page is rendered, this function does all initial 17 * setup, including: processing form requests, registering contextual 18 * help, and setting up screen options. 19 * 20 * @since 8.0.0 21 * 22 * @global $bp_optouts_list_table 23 */ 24 function bp_core_optouts_admin_load() { 25 global $bp_optouts_list_table; 26 27 // Build redirection URL. 28 $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids' ), $_SERVER['REQUEST_URI'] ); 29 $doaction = bp_admin_list_table_current_bulk_action(); 30 31 /** 32 * Fires at the start of the nonmember opt-outs admin load. 33 * 34 * @since 8.0.0 35 * 36 * @param string $doaction Current bulk action being processed. 37 * @param array $_REQUEST Current $_REQUEST global. 38 */ 39 do_action( 'bp_optouts_admin_load', $doaction, $_REQUEST ); 40 41 /** 42 * Filters the allowed actions for use in the nonmember opt-outs admin page. 43 * 44 * @since 8.0.0 45 * 46 * @param array $value Array of allowed actions to use. 47 */ 48 $allowed_actions = apply_filters( 'bp_optouts_admin_allowed_actions', array( 'do_delete', 'do_resend' ) ); 49 50 if ( ! in_array( $doaction, $allowed_actions ) || ( -1 == $doaction ) ) { 51 52 require_once( ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php' ); 53 $bp_optouts_list_table = new BP_Optouts_List_Table(); 54 55 // The per_page screen option. 56 add_screen_option( 'per_page', array( 'label' => _x( 'Nonmember opt-outs', 'Nonmember opt-outs per page (screen options)', 'buddypress' ) ) ); 57 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 Sender, 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 ); 83 84 // Help panel - sidebar links. 85 $current_screen->set_help_sidebar( 86 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 87 '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 88 ); 89 90 // Add accessible hidden headings and text for the Pending Users screen. 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 ); 101 102 } else { 103 if ( empty( $_REQUEST['optout_ids' ] ) ) { 104 return; 105 } 106 $optout_ids = wp_parse_id_list( $_REQUEST['optout_ids' ] ); 107 108 // Handle optout deletion. 109 if ( 'do_delete' == $doaction ) { 110 111 // Nonce check. 112 check_admin_referer( 'optouts_delete' ); 113 114 $success = 0; 115 foreach ( $optout_ids as $optout_id ) { 116 if ( bp_delete_optout_by_id( $optout_id ) ) { 117 $success++; 118 } 119 } 120 121 $query_arg = array( 'updated' => 'deleted' ); 122 123 if ( ! empty( $success ) ) { 124 $query_arg['deleted'] = $success; 125 } 126 127 $notdeleted = count( $optout_ids ) - $success; 128 if ( $notdeleted > 0 ) { 129 $query_arg['notdeleted'] = $notdeleted; 130 } 131 132 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 133 134 bp_core_redirect( $redirect_to ); 135 136 // Plugins can update other stuff from here. 137 } else { 138 139 /** 140 * Fires at end of opt-outs admin load 141 * if doaction does not match any actions. 142 * 143 * @since 2.0.0 144 * 145 * @param string $doaction Current bulk action being processed. 146 * @param array $_REQUEST Current $_REQUEST global. 147 * @param string $redirect Determined redirect url to send user to. 148 */ 149 do_action( 'bp_core_admin_update_optouts', $doaction, $_REQUEST, $redirect_to ); 150 151 bp_core_redirect( $redirect_to ); 152 } 153 } 154 } 155 add_action( "load-tools_page_bp-optouts", 'bp_core_optouts_admin_load' ); 156 157 /** 158 * Get admin notice when viewing the optouts management page. 159 * 160 * @since 8.0.0 161 * 162 * @return array 163 */ 164 function bp_core_get_optouts_notice() { 165 166 // Setup empty notice for return value. 167 $notice = array(); 168 169 // Updates. 170 if ( ! empty( $_REQUEST['updated'] ) && 'deleted' === $_REQUEST['updated'] ) { 171 $notice = array( 172 'class' => 'updated', 173 'message' => '' 174 ); 175 176 if ( ! empty( $_REQUEST['deleted'] ) ) { 177 $deleted = absint( $_REQUEST['deleted'] ); 178 $notice['message'] .= sprintf( 179 _nx( 180 /* translators: %s: number of deleted optouts */ 181 '%s opt-out successfully deleted!', '%s opt-outs successfully deleted!', 182 $deleted, 183 'nonmembers opt-out deleted', 184 'buddypress' 185 ), 186 number_format_i18n( absint( $_REQUEST['deleted'] ) ) 187 ); 188 } 189 190 if ( ! empty( $_REQUEST['notdeleted'] ) ) { 191 $notdeleted = absint( $_REQUEST['notdeleted'] ); 192 $notice['message'] .= sprintf( 193 _nx( 194 /* translators: %s: number of optouts that failed to be deleted */ 195 '%s opt-out was not deleted.', '%s opt-outs were not deleted.', 196 $notdeleted, 197 'nonmembers opt-out not deleted', 198 'buddypress' 199 ), 200 number_format_i18n( $notdeleted ) 201 ); 202 203 if ( empty( $_REQUEST['deleted'] ) ) { 204 $notice['class'] = 'error'; 205 } 206 } 207 } 208 209 // Errors. 210 if ( ! empty( $_REQUEST['error'] ) && 'do_delete' === $_REQUEST['error'] ) { 211 $notice = array( 212 'class' => 'error', 213 'message' => esc_html__( 'There was a problem deleting opt-outs. Please try again.', 'buddypress' ), 214 ); 215 } 216 217 return $notice; 218 } 219 220 /** 221 * Opt-outs admin page router. 222 * 223 * Depending on the context, display 224 * - the list of optouts, 225 * - or the delete confirmation screen, 226 * 227 * Also prepare the admin notices. 228 * 229 * @since 8.0.0 230 */ 231 function bp_core_optouts_admin() { 232 $doaction = bp_admin_list_table_current_bulk_action(); 233 234 // Prepare notices for admin. 235 $notice = bp_core_get_optouts_notice(); 236 237 // Display notices. 238 if ( ! empty( $notice ) ) : 239 if ( 'updated' === $notice['class'] ) : ?> 240 241 <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?> notice is-dismissible"> 242 243 <?php else: ?> 244 245 <div class="<?php echo esc_attr( $notice['class'] ); ?> notice is-dismissible"> 246 247 <?php endif; ?> 248 249 <p><?php echo esc_html( $notice['message'] ); ?></p> 250 </div> 251 252 <?php endif; 253 254 // Show the proper screen. 255 switch ( $doaction ) { 256 case 'delete' : 257 bp_core_optouts_admin_manage( $doaction ); 258 break; 259 260 default: 261 bp_core_optouts_admin_index(); 262 break; 263 } 264 } 265 266 /** 267 * This is the list of optouts. 268 * 269 * @since 8.0.0 270 * 271 * @global $plugin_page 272 * @global $bp_optouts_list_table 273 */ 274 function bp_core_optouts_admin_index() { 275 global $plugin_page, $bp_optouts_list_table; 276 277 $usersearch = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; 278 279 // Prepare the group items for display. 280 $bp_optouts_list_table->prepare_items(); 281 282 if ( is_network_admin() ) { 283 $form_url = network_admin_url( 'admin.php' ); 284 } else { 285 $form_url = bp_get_admin_url( 'tools.php' ); 286 } 287 288 $form_url = add_query_arg( 289 array( 290 'page' => 'bp-optouts', 291 ), 292 $form_url 293 ); 294 295 $search_form_url = remove_query_arg( 296 array( 297 'action', 298 'deleted', 299 'notdeleted', 300 'error', 301 'updated', 302 'delete', 303 'activate', 304 'activated', 305 'notactivated', 306 'resend', 307 'resent', 308 'notresent', 309 'do_delete', 310 'do_activate', 311 'do_resend', 312 'action2', 313 '_wpnonce', 314 'optout_ids' 315 ), 316 $_SERVER['REQUEST_URI'] 317 ); 318 319 bp_core_admin_tabbed_screen_header( __( 'BuddyPress tools', 'buddypress' ), __( 'Manage Opt-outs', 'buddypress' ), 'tools' ); 320 ?> 321 322 <div class="buddypress-body"> 323 <?php 324 if ( $usersearch ) { 325 $num_results = (int) $bp_optouts_list_table->total_items; 326 printf( 327 '<p><span class="subtitle">%s</span></p>', 328 sprintf( 329 esc_html( 330 /* translators: %s: the searched email. */ 331 _n( 'Opt-out with an email address matching “%s”', 'Opt-outs with an email address matching “%s”', $num_results, 'buddypress' ) 332 ), 333 esc_html( $usersearch ) 334 ) 335 ); 336 } 337 ?> 338 <p><?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> 339 340 <?php // Display each opt-out on its own row. ?> 341 <?php $bp_optouts_list_table->views(); ?> 342 343 <form id="bp-optouts-search-form" action="<?php echo esc_url( $search_form_url ) ;?>"> 344 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" /> 345 <?php $bp_optouts_list_table->search_box( esc_html__( 'Search for a specific email address', 'buddypress' ), 'bp-optouts' ); ?> 346 </form> 347 348 <form id="bp-optouts-form" action="<?php echo esc_url( $form_url );?>" method="post"> 349 <?php $bp_optouts_list_table->display(); ?> 350 </form> 351 </div> 352 <?php 353 } 354 355 /** 356 * This is the confirmation screen for actions. 357 * 358 * @since 8.0.0 359 * 360 * @param string $action Delete or resend optout. 361 * 362 * @return null|false 363 */ 364 function bp_core_optouts_admin_manage( $action = '' ) { 365 $capability = bp_core_do_network_admin() ? 'manage_network_options' : 'manage_options'; 366 if ( ! current_user_can( $capability ) || empty( $action ) ) { 367 die( '-1' ); 368 } 369 370 // Get the IDs from the URL. 371 $ids = false; 372 if ( ! empty( $_POST['optout_ids'] ) ) { 373 $ids = wp_parse_id_list( $_POST['optout_ids'] ); 374 } elseif ( ! empty( $_GET['optout_id'] ) ) { 375 $ids = absint( $_GET['optout_id'] ); 376 } 377 378 if ( empty( $ids ) ) { 379 return false; 380 } 381 382 // Query for matching optouts, and filter out bad IDs. 383 $args = array( 384 'id' => $ids, 385 ); 386 $optouts = bp_get_optouts( $args ); 387 $optout_ids = wp_list_pluck( $optouts, 'id' ); 388 389 // Check optout IDs and set up strings. 390 switch ( $action ) { 391 case 'delete' : 392 if ( 0 === count( $optouts ) ) { 393 $helper_text = __( 'No opt-out requests were found.', 'buddypress' ); 394 } else { 395 $helper_text = _n( 'You are about to delete the following opt-out request:', 'You are about to delete the following opt-out requests:', count( $optouts ), 'buddypress' ); 396 } 397 break; 398 } 399 400 // These arguments are added to all URLs. 401 $url_args = array( 'page' => 'bp-optouts' ); 402 403 // These arguments are only added when performing an action. 404 $action_args = array( 405 'action' => 'do_' . $action, 406 'optout_ids' => implode( ',', $optout_ids ) 407 ); 408 409 if ( is_network_admin() ) { 410 $base_url = network_admin_url( 'admin.php' ); 411 } else { 412 $base_url = bp_get_admin_url( 'tools.php' ); 413 } 414 415 $cancel_url = add_query_arg( $url_args, $base_url ); 416 $action_url = wp_nonce_url( 417 add_query_arg( 418 array_merge( $url_args, $action_args ), 419 $base_url 420 ), 421 'optouts_' . $action 422 ); 423 424 bp_core_admin_tabbed_screen_header( __( 'BuddyPress tools', 'buddypress' ), __( 'Manage Opt-outs', 'buddypress' ), 'tools' ); 425 ?> 426 427 <div class="buddypress-body"> 428 429 <p><?php echo esc_html( $helper_text ); ?></p> 430 431 <ol class="bp-optouts-list"> 432 <?php foreach ( $optouts as $optout ) : ?> 433 434 <li> 435 <strong><?php echo esc_html( $optout->email_address ) ?></strong> 436 <p class="description"> 437 <?php 438 $last_modified = mysql2date( 'Y/m/d g:i:s a', $optout->date_modified ); 439 /* translators: %s: modification date */ 440 printf( esc_html__( 'Date modified: %s', 'buddypress'), $last_modified ); 441 ?> 442 </p> 443 </li> 444 445 <?php endforeach; ?> 446 </ol> 447 448 <?php if ( 'delete' === $action && count( $optouts ) ) : ?> 449 450 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p> 451 452 <?php endif ; ?> 453 454 <?php if ( count( $optouts ) ) : ?> 455 456 <a class="button-primary" href="<?php echo esc_url( $action_url ); ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a> 457 458 <?php endif; ?> 459 460 <a class="button" href="<?php echo esc_url( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a> 461 </div> 462 463 <?php 464 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |