[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Opt-outs List Table class. 4 * 5 * @package BuddyPress 6 * @subpackage CoreAdminClasses 7 * @since 8.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * List table class for nonmember opt-outs admin page. 15 * 16 * @since 8.0.0 17 */ 18 class BP_Optouts_List_Table extends WP_Users_List_Table { 19 20 /** 21 * Opt-out count. 22 * 23 * @since 8.0.0 24 * 25 * @var int 26 */ 27 public $total_items = 0; 28 29 /** 30 * Constructor. 31 * 32 * @since 8.0.0 33 */ 34 public function __construct() { 35 // Define singular and plural labels, as well as whether we support AJAX. 36 parent::__construct( 37 array( 38 'ajax' => false, 39 'plural' => 'optouts', 40 'singular' => 'optout', 41 'screen' => get_current_screen()->id, 42 ) 43 ); 44 } 45 46 /** 47 * Set up items for display in the list table. 48 * 49 * Handles filtering of data, sorting, pagination, and any other data 50 * manipulation required prior to rendering. 51 * 52 * @since 8.0.0 53 */ 54 public function prepare_items() { 55 global $usersearch; 56 57 $search = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 58 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 59 $paged = $this->get_pagenum(); 60 61 $args = array( 62 'search_terms' => $search, 63 'order_by' => 'date_modified', 64 'sort_order' => 'DESC', 65 'page' => $paged, 66 'per_page' => $per_page, 67 ); 68 69 if ( isset( $_REQUEST['orderby'] ) ) { 70 $args['order_by'] = $_REQUEST['orderby']; 71 } 72 73 if ( isset( $_REQUEST['order'] ) ) { 74 $args['sort_order'] = $_REQUEST['order']; 75 } 76 77 $this->items = bp_get_optouts( $args ); 78 $optouts_class = new BP_Optout(); 79 $this->total_items = $optouts_class->get_total_count( $args ); 80 81 $this->set_pagination_args( 82 array( 83 'total_items' => $this->total_items, 84 'per_page' => $per_page, 85 ) 86 ); 87 } 88 89 /** 90 * Gets the name of the default primary column. 91 * 92 * @since 10.1.0 93 * 94 * @return string Name of the default primary column, in this case, 'email_address'. 95 */ 96 protected function get_default_primary_column_name() { 97 return 'email_address'; 98 } 99 100 /** 101 * Get the list of views available on this table. 102 * 103 * @since 8.0.0 104 */ 105 public function views() { 106 if ( is_multisite() && bp_core_do_network_admin() ) { 107 $tools_parent = 'admin.php'; 108 } else { 109 $tools_parent = 'tools.php'; 110 } 111 112 $url_base = add_query_arg( 113 array( 114 'page' => 'bp-optouts', 115 ), 116 bp_get_admin_url( $tools_parent ) 117 ); 118 ?> 119 120 <h2 class="screen-reader-text"> 121 <?php 122 /* translators: accessibility text */ 123 esc_html_e( 'Filter opt-outs list', 'buddypress' ); 124 ?> 125 </h2> 126 <ul class="subsubsub"> 127 <?php 128 /** 129 * Fires inside listing of views so plugins can add their own. 130 * 131 * @since 8.0.0 132 * 133 * @param string $url_base Current URL base for view. 134 * @param array $active_filters Current filters being requested. 135 */ 136 do_action( 'bp_optouts_list_table_get_views', $url_base, $this->active_filters ); ?> 137 </ul> 138 <?php 139 } 140 141 /** 142 * Get rid of the extra nav. 143 * 144 * WP_Users_List_Table will add an extra nav to change user's role. 145 * As we're dealing with opt-outs, we don't need this. 146 * 147 * @since 8.0.0 148 * 149 * @param array $which Current table nav item. 150 */ 151 public function extra_tablenav( $which ) { 152 return; 153 } 154 155 /** 156 * Specific opt-out columns. 157 * 158 * @since 8.0.0 159 * 160 * @return array 161 */ 162 public function get_columns() { 163 /** 164 * Filters the nonmember opt-outs columns. 165 * 166 * @since 8.0.0 167 * 168 * @param array $value Array of columns to display. 169 */ 170 return apply_filters( 171 'bp_optouts_list_columns', 172 array( 173 'cb' => '<input type="checkbox" />', 174 'email_address' => __( 'Email Address Hash', 'buddypress' ), 175 'username' => __( 'Email Sender', 'buddypress' ), 176 'user_registered' => __( 'Email Sender Registered', 'buddypress' ), 177 'email_type' => __( 'Email Type', 'buddypress' ), 178 'email_type_description' => __( 'Email Description', 'buddypress' ), 179 'optout_date_modified' => __( 'Date Modified', 'buddypress' ), 180 ) 181 ); 182 } 183 184 /** 185 * Specific bulk actions for opt-outs. 186 * 187 * @since 8.0.0 188 */ 189 public function get_bulk_actions() { 190 if ( current_user_can( 'delete_users' ) ) { 191 $actions['delete'] = _x( 'Delete', 'Optout database record action', 'buddypress' ); 192 } 193 194 return $actions; 195 } 196 197 /** 198 * The text shown when no items are found. 199 * 200 * Nice job, clean sheet! 201 * 202 * @since 8.0.0 203 */ 204 public function no_items() { 205 esc_html_e( 'No opt-outs found.', 'buddypress' ); 206 } 207 208 /** 209 * The columns opt-outs can be reordered by. 210 * 211 * @since 8.0.0 212 */ 213 public function get_sortable_columns() { 214 return array( 215 'username' => 'user_id', 216 'email_type' => 'email_type', 217 'optout_date_modified' => 'date_modified', 218 ); 219 } 220 221 /** 222 * Display opt-out rows. 223 * 224 * @since 8.0.0 225 */ 226 public function display_rows() { 227 $style = ''; 228 foreach ( $this->items as $optout ) { 229 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 230 echo "\n\t" . $this->single_row( $optout, $style ); 231 } 232 } 233 234 /** 235 * Display an opt-out row. 236 * 237 * @since 8.0.0 238 * 239 * @see WP_List_Table::single_row() for explanation of params. 240 * 241 * @param BP_Optout $optout BP_Optout object. 242 * @param string $style Styles for the row. 243 * @param string $role Role to be assigned to user. 244 * @param int $numposts Number of posts. 245 * @return void 246 */ 247 public function single_row( $optout = null, $style = '', $role = '', $numposts = 0 ) { 248 echo '<tr' . $style . ' id="optout-' . intval( $optout->id ) . '">'; 249 echo $this->single_row_columns( $optout ); 250 echo '</tr>'; 251 } 252 253 /** 254 * Markup for the checkbox used to select items for bulk actions. 255 * 256 * @since 8.0.0 257 * 258 * @param BP_Optout $optout BP_Optout object. 259 */ 260 public function column_cb( $optout = null ) { 261 ?> 262 <label class="screen-reader-text" for="optout_<?php echo intval( $optout->id ); ?>"> 263 <?php 264 /* translators: %d: accessibility text. */ 265 printf( esc_html__( 'Select opt-out request: %d', 'buddypress' ), intval( $optout->id ) ); 266 ?> 267 </label> 268 <input type="checkbox" id="optout_<?php echo intval( $optout->id ) ?>" name="optout_ids[]" value="<?php echo esc_attr( $optout->id ) ?>" /> 269 <?php 270 } 271 272 /** 273 * Markup for the checkbox used to select items for bulk actions. 274 * 275 * @since 8.0.0 276 * 277 * @param BP_Optout $optout BP_Optout object. 278 */ 279 public function column_email_address( $optout = null ) { 280 echo esc_html( $optout->email_address ); 281 282 $actions = array(); 283 284 if ( is_network_admin() ) { 285 $form_url = network_admin_url( 'admin.php' ); 286 } else { 287 $form_url = bp_get_admin_url( 'tools.php' ); 288 } 289 290 // Delete link. 291 $delete_link = add_query_arg( 292 array( 293 'page' => 'bp-optouts', 294 'optout_id' => $optout->id, 295 'action' => 'delete', 296 ), 297 $form_url 298 ); 299 $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Delete', 'buddypress' ) ); 300 301 /** 302 * Filters the row actions for each opt-out in list. 303 * 304 * @since 8.0.0 305 * 306 * @param array $actions Array of actions and corresponding links. 307 * @param object $optout The BP_Optout. 308 */ 309 $actions = apply_filters( 'bp_optouts_management_row_actions', $actions, $optout ); 310 311 echo $this->row_actions( $actions ); 312 } 313 314 /** 315 * The inviter/site member who sent the email that prompted the opt-out. 316 * 317 * @since 8.0.0 318 * 319 * @param BP_Optout $optout BP_Optout object. 320 */ 321 public function column_username( $optout = null ) { 322 $avatar = get_avatar( $optout->user_id, 32 ); 323 $inviter = get_user_by( 'id', $optout->user_id ); 324 if ( ! $inviter ) { 325 return; 326 } 327 $user_link = bp_core_get_user_domain( $optout->user_id ); 328 echo $avatar . sprintf( '<strong><a href="%1$s" class="edit">%2$s</a></strong><br/>', esc_url( $user_link ), esc_html( $inviter->user_login ) ); 329 } 330 331 /** 332 * Display registration date of user whose communication prompted opt-out. 333 * 334 * @since 8.0.0 335 * 336 * @param BP_Optout $optout BP_Optout object. 337 */ 338 public function column_user_registered( $optout = null ) { 339 $inviter = get_user_by( 'id', $optout->user_id ); 340 if ( ! $inviter ) { 341 return; 342 } 343 echo esc_html( mysql2date( 'Y/m/d g:i:s a', $inviter->user_registered ) ); 344 } 345 346 /** 347 * Display type of email that prompted opt-out. 348 * 349 * @since 8.0.0 350 * 351 * @param BP_Optout $optout BP_Optout object. 352 */ 353 public function column_email_type( $optout = null ) { 354 echo esc_html( $optout->email_type ); 355 } 356 357 /** 358 * Display description of bp-email-type that prompted opt-out. 359 * 360 * @since 8.0.0 361 * 362 * @param BP_Optout $optout BP_Optout object. 363 */ 364 public function column_email_type_description( $optout = null ) { 365 $type_term = get_term_by( 'slug', $optout->email_type, 'bp-email-type' ); 366 if ( $type_term ) { 367 echo esc_html( $type_term->description ); 368 } 369 370 } 371 372 /** 373 * Display opt-out date. 374 * 375 * @since 8.0.0 376 * 377 * @param BP_Optout $optout BP_Optout object. 378 */ 379 public function column_optout_date_modified( $optout = null ) { 380 echo esc_html( mysql2date( 'Y/m/d g:i:s a', $optout->date_modified ) ); 381 } 382 383 /** 384 * Allow plugins to add custom columns. 385 * 386 * @since 8.0.0 387 * 388 * @param BP_Optout $optout BP_Optout object. 389 * @param string $column_name The column name. 390 * @return string 391 */ 392 function column_default( $optout = null, $column_name = '' ) { 393 394 /** 395 * Filters the single site custom columns for plugins. 396 * 397 * @since 8.0.0 398 * 399 * @param string $column_name The column name. 400 * @param BP_Optout $optout BP_Optout object. 401 */ 402 return apply_filters( 'bp_optouts_management_custom_column', '', $column_name, $optout ); 403 } 404 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |