[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-optouts-list-table.php (source)

   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       * Get the list of views available on this table.
  91       *
  92       * @since 8.0.0
  93       */
  94  	public function views() {
  95          if ( is_multisite() && bp_core_do_network_admin() ) {
  96              $tools_parent = 'admin.php';
  97          } else {
  98              $tools_parent = 'tools.php';
  99          }
 100  
 101          $url_base = add_query_arg(
 102              array(
 103                  'page' => 'bp-optouts',
 104              ),
 105              bp_get_admin_url( $tools_parent )
 106          );
 107          ?>
 108  
 109          <h2 class="screen-reader-text">
 110              <?php
 111                  /* translators: accessibility text */
 112                  esc_html_e( 'Filter opt-outs list', 'buddypress' );
 113              ?>
 114          </h2>
 115          <ul class="subsubsub">
 116              <?php
 117              /**
 118               * Fires inside listing of views so plugins can add their own.
 119               *
 120               * @since 8.0.0
 121               *
 122               * @param string $url_base       Current URL base for view.
 123               * @param array  $active_filters Current filters being requested.
 124               */
 125              do_action( 'bp_optouts_list_table_get_views', $url_base, $this->active_filters ); ?>
 126          </ul>
 127      <?php
 128      }
 129  
 130      /**
 131       * Get rid of the extra nav.
 132       *
 133       * WP_Users_List_Table will add an extra nav to change user's role.
 134       * As we're dealing with opt-outs, we don't need this.
 135       *
 136       * @since 8.0.0
 137       *
 138       * @param array $which Current table nav item.
 139       */
 140  	public function extra_tablenav( $which ) {
 141          return;
 142      }
 143  
 144      /**
 145       * Specific opt-out columns.
 146       *
 147       * @since 8.0.0
 148       *
 149       * @return array
 150       */
 151  	public function get_columns() {
 152          /**
 153           * Filters the nonmember opt-outs columns.
 154           *
 155           * @since 8.0.0
 156           *
 157           * @param array $value Array of columns to display.
 158           */
 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          );
 171      }
 172  
 173      /**
 174       * Specific bulk actions for opt-outs.
 175       *
 176       * @since 8.0.0
 177       */
 178  	public function get_bulk_actions() {
 179          if ( current_user_can( 'delete_users' ) ) {
 180              $actions['delete'] = _x( 'Delete', 'Optout database record action', 'buddypress' );
 181          }
 182  
 183          return $actions;
 184      }
 185  
 186      /**
 187       * The text shown when no items are found.
 188       *
 189       * Nice job, clean sheet!
 190       *
 191       * @since 8.0.0
 192       */
 193  	public function no_items() {
 194          esc_html_e( 'No opt-outs found.', 'buddypress' );
 195      }
 196  
 197      /**
 198       * The columns opt-outs can be reordered by.
 199       *
 200       * @since 8.0.0
 201       */
 202  	public function get_sortable_columns() {
 203          return array(
 204              'username'             => 'user_id',
 205              'email_type'           => 'email_type',
 206              'optout_date_modified' => 'date_modified',
 207          );
 208      }
 209  
 210      /**
 211       * Display opt-out rows.
 212       *
 213       * @since 8.0.0
 214       */
 215  	public function display_rows() {
 216          $style = '';
 217          foreach ( $this->items as $optout ) {
 218              $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
 219              echo "\n\t" . $this->single_row( $optout, $style );
 220          }
 221      }
 222  
 223      /**
 224       * Display an opt-out row.
 225       *
 226       * @since 8.0.0
 227       *
 228       * @see WP_List_Table::single_row() for explanation of params.
 229       *
 230       * @param BP_Optout $optout   BP_Optout object.
 231       * @param string    $style    Styles for the row.
 232       * @param string    $role     Role to be assigned to user.
 233       * @param int       $numposts Number of posts.
 234       * @return void
 235       */
 236  	public function single_row( $optout = null, $style = '', $role = '', $numposts = 0 ) {
 237          echo '<tr' . $style . ' id="optout-' . intval( $optout->id ) . '">';
 238          echo $this->single_row_columns( $optout );
 239          echo '</tr>';
 240      }
 241  
 242      /**
 243       * Markup for the checkbox used to select items for bulk actions.
 244       *
 245       * @since 8.0.0
 246       *
 247       * @param BP_Optout $optout BP_Optout object.
 248       */
 249  	public function column_cb( $optout = null ) {
 250      ?>
 251          <label class="screen-reader-text" for="optout_<?php echo intval( $optout->id ); ?>">
 252              <?php
 253                  /* translators: %d: accessibility text. */
 254                  printf( esc_html__( 'Select opt-out request: %d', 'buddypress' ), intval( $optout->id ) );
 255              ?>
 256          </label>
 257          <input type="checkbox" id="optout_<?php echo intval( $optout->id ) ?>" name="optout_ids[]" value="<?php echo esc_attr( $optout->id ) ?>" />
 258          <?php
 259      }
 260  
 261      /**
 262       * Markup for the checkbox used to select items for bulk actions.
 263       *
 264       * @since 8.0.0
 265       *
 266       * @param BP_Optout $optout BP_Optout object.
 267       */
 268  	public function column_email_address( $optout = null ) {
 269          echo esc_html( $optout->email_address );
 270  
 271          $actions = array();
 272  
 273          if ( is_network_admin() ) {
 274              $form_url = network_admin_url( 'admin.php' );
 275          } else {
 276              $form_url = bp_get_admin_url( 'tools.php' );
 277          }
 278  
 279          // Delete link.
 280          $delete_link = add_query_arg(
 281              array(
 282                  'page'      => 'bp-optouts',
 283                  'optout_id' => $optout->id,
 284                  'action'    => 'delete',
 285              ),
 286              $form_url
 287          );
 288          $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Delete', 'buddypress' ) );
 289  
 290          /**
 291           * Filters the row actions for each opt-out in list.
 292           *
 293           * @since 8.0.0
 294           *
 295           * @param array  $actions Array of actions and corresponding links.
 296           * @param object $optout  The BP_Optout.
 297           */
 298          $actions = apply_filters( 'bp_optouts_management_row_actions', $actions, $optout );
 299  
 300          echo $this->row_actions( $actions );
 301      }
 302  
 303      /**
 304       * The inviter/site member who sent the email that prompted the opt-out.
 305       *
 306       * @since 8.0.0
 307       *
 308       * @param BP_Optout $optout BP_Optout object.
 309       */
 310  	public function column_username( $optout = null ) {
 311          $avatar = get_avatar( $optout->user_id, 32 );
 312          $inviter = get_user_by( 'id', $optout->user_id );
 313          if ( ! $inviter ) {
 314              return;
 315          }
 316          $user_link = bp_core_get_user_domain( $optout->user_id );
 317          echo $avatar . sprintf( '<strong><a href="%1$s" class="edit">%2$s</a></strong><br/>', esc_url( $user_link ), esc_html( $inviter->user_login ) );
 318      }
 319  
 320      /**
 321       * Display registration date of user whose communication prompted opt-out.
 322       *
 323       * @since 8.0.0
 324       *
 325       * @param BP_Optout $optout BP_Optout object.
 326       */
 327  	public function column_user_registered( $optout = null ) {
 328          $inviter = get_user_by( 'id', $optout->user_id );
 329          if ( ! $inviter ) {
 330              return;
 331          }
 332          echo esc_html( mysql2date( 'Y/m/d g:i:s a', $inviter->user_registered  ) );
 333      }
 334  
 335      /**
 336       * Display type of email that prompted opt-out.
 337       *
 338       * @since 8.0.0
 339       *
 340       * @param BP_Optout $optout BP_Optout object.
 341       */
 342  	public function column_email_type( $optout = null ) {
 343          echo esc_html( $optout->email_type );
 344      }
 345  
 346      /**
 347       * Display description of bp-email-type 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_description( $optout = null ) {
 354          $type_term = get_term_by( 'slug', $optout->email_type, 'bp-email-type' );
 355          if ( $type_term ) {
 356              echo esc_html( $type_term->description );
 357          }
 358  
 359      }
 360  
 361      /**
 362       * Display opt-out date.
 363       *
 364       * @since 8.0.0
 365       *
 366       * @param BP_Optout $optout BP_Optout object.
 367       */
 368  	public function column_optout_date_modified( $optout = null ) {
 369          echo esc_html( mysql2date( 'Y/m/d g:i:s a', $optout->date_modified ) );
 370      }
 371  
 372      /**
 373       * Allow plugins to add custom columns.
 374       *
 375       * @since 8.0.0
 376       *
 377       * @param BP_Optout $optout      BP_Optout object.
 378       * @param string    $column_name The column name.
 379       * @return string
 380       */
 381  	function column_default( $optout = null, $column_name = '' ) {
 382  
 383          /**
 384           * Filters the single site custom columns for plugins.
 385           *
 386           * @since 8.0.0
 387           *
 388           * @param string    $column_name The column name.
 389           * @param BP_Optout $optout      BP_Optout object.
 390           */
 391          return apply_filters( 'bp_optouts_management_custom_column', '', $column_name, $optout );
 392      }
 393  }


Generated: Wed Oct 20 01:01:02 2021 Cross-referenced by PHPXref 0.7.1