[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/classes/ -> class-bp-messages-notices-list-table.php (source)

   1  <?php
   2  /**
   3   * BuddyPress messages admin site-wide notices list table class.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Messages
   7   * @since 3.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  // Include WP's list table class.
  14  if ( ! class_exists( 'WP_List_Table' ) ) {
  15      require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  16  }
  17  
  18  class BP_Messages_Notices_List_Table extends WP_List_Table {
  19      
  20      /**
  21       * Constructor
  22       *
  23       * @since 3.0.0
  24       */
  25  	public function __construct( $args = array() ) {
  26          parent::__construct(
  27              array(
  28                  'plural'   => 'notices',
  29                  'singular' => 'notice',
  30                  'ajax'     => true,
  31                  'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
  32              )
  33          );
  34      }
  35  
  36      /**
  37       * Checks the current user's permissions
  38       *
  39       * @since 3.0.0
  40       */
  41  	public function ajax_user_can() {
  42          return bp_current_user_can( 'bp_moderate' );
  43      }
  44  
  45      /**
  46       * Set up items for display in the list table.
  47       *
  48       * Handles filtering of data, sorting, pagination, and any other data
  49       * manipulation required prior to rendering.
  50       *
  51       * @since 3.0.0
  52       */
  53  	public function prepare_items() {
  54          $page     = $this->get_pagenum();
  55          $per_page = $this->get_items_per_page( 'bp_notices_per_page' );
  56  
  57          $this->items = BP_Messages_Notice::get_notices( array(
  58              'pag_num'  => $per_page,
  59              'pag_page' => $page
  60          ) );
  61  
  62          $this->set_pagination_args( array(
  63              'total_items' => BP_Messages_Notice::get_total_notice_count(),
  64              'per_page' => $per_page,
  65          ) );
  66      }
  67  
  68      /**
  69       * Get a list of columns. The format is:
  70       * 'internal-name' => 'Title'
  71       *
  72       * @since 3.0.0
  73       *
  74       * @return array
  75       */
  76  	public function get_columns() {
  77          return apply_filters( 'bp_notices_list_table_get_columns', array(
  78              'subject'   => _x( 'Subject', 'Admin Notices column header', 'buddypress' ),
  79              'message'   => _x( 'Content', 'Admin Notices column header', 'buddypress' ),
  80              'date_sent' => _x( 'Created', 'Admin Notices column header', 'buddypress' ),
  81          ) );
  82      }
  83  
  84      /**
  85       * Generates content for a single row of the table
  86       *
  87       * @since 3.0.0
  88       *
  89       * @param object $item The current item
  90       */
  91  	public function single_row( $item ) {
  92          $class = '';
  93  
  94          if ( ! empty( $item->is_active ) ) {
  95              $class = ' class="notice-active"';
  96          }
  97  
  98          echo "<tr{$class}>";
  99          $this->single_row_columns( $item );
 100          echo '</tr>';
 101      }
 102  
 103      /**
 104       * Generates content for the "subject" column.
 105       *
 106       * @since 3.0.0
 107       *
 108       * @param object $item The current item
 109       */
 110  	public function column_subject( $item ) {
 111          $actions = array(
 112              'activate_deactivate' => sprintf( '<a href="%s" data-bp-notice-id="%d" data-bp-action="activate">%s</a>', 
 113                  esc_url( wp_nonce_url( add_query_arg( array(
 114                      'page'          => 'bp-notices',
 115                      'notice_action' => 'activate',
 116                      'notice_id'     => $item->id
 117                  ), bp_get_admin_url( 'users.php' ) ), 'messages-activate-notice-' . $item->id ) ),
 118                  (int) $item->id,
 119                  esc_html__( 'Activate Notice', 'buddypress' ) ),
 120              'delete' => sprintf( '<a href="%s" data-bp-notice-id="%d" data-bp-action="delete">%s</a>', 
 121                  esc_url( wp_nonce_url( add_query_arg( array(
 122                      'page'          => 'bp-notices',
 123                      'notice_action' => 'delete',
 124                      'notice_id'     => $item->id
 125                  ), bp_get_admin_url( 'users.php' ) ), 'messages-delete-notice-' . $item->id ) ),
 126                  (int) $item->id,
 127                  esc_html__( 'Delete Notice', 'buddypress' ) )
 128          );
 129  
 130          if ( ! empty( $item->is_active ) ) {
 131              $item->subject = sprintf( _x( 'Active: %s', 'Tag prepended to active site-wide notice titles on WP Admin notices list table', 'buddypress' ), $item->subject );
 132              $actions['activate_deactivate'] = sprintf( '<a href="%s" data-bp-notice-id="%d" data-bp-action="deactivate">%s</a>', 
 133                  esc_url( wp_nonce_url( add_query_arg( array(
 134                      'page'          => 'bp-notices',
 135                      'notice_action' => 'deactivate',
 136                      'notice_id'     => $item->id
 137                  ), bp_get_admin_url( 'users.php' ) ), 'messages-deactivate-notice-' . $item->id ) ),
 138                  (int) $item->id,
 139                  esc_html__( 'Deactivate Notice', 'buddypress' ) );
 140          }
 141  
 142          echo '<strong>' . apply_filters( 'bp_get_message_notice_subject', $item->subject ) . '</strong> ' . $this->row_actions( $actions );
 143      }
 144  
 145      /**
 146       * Generates content for the "message" column.
 147       *
 148       * @since 3.0.0
 149       *
 150       * @param object $item The current item
 151       */
 152  	public function column_message( $item ) {
 153          echo apply_filters( 'bp_get_message_notice_text', $item->message );
 154      }
 155  
 156      /**
 157       * Generates content for the "date_sent" column.
 158       *
 159       * @since 3.0.0
 160       *
 161       * @param object $item The current item
 162       */
 163  	public function column_date_sent( $item ) {
 164          echo apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime( $item->date_sent ) ) );
 165      }
 166  }


Generated: Mon Feb 24 01:01:31 2020 Cross-referenced by PHPXref 0.7.1