[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/messages/ -> classes.php (source)

   1  <?php
   2  /**
   3   * Mesages classes
   4   *
   5   * @since 1.0.0
   6   */
   7  
   8  // Exit if accessed directly.
   9  defined( 'ABSPATH' ) || exit;
  10  
  11  if ( is_admin() && current_user_can( 'activate_plugins' ) ) :
  12  
  13      class BP_Nouveau_Notices_List_Table extends WP_List_Table {
  14  		public function __construct( $args = array() ) {
  15              parent::__construct(
  16                  array(
  17                      'plural'   => 'notices',
  18                      'singular' => 'notice',
  19                      'ajax'     => true,
  20                      'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
  21                  )
  22              );
  23          }
  24  
  25  		public function ajax_user_can() {
  26              return bp_current_user_can( 'bp_moderate' );
  27          }
  28  
  29  		public function prepare_items() {
  30              $page     = $this->get_pagenum();
  31              $per_page = $this->get_items_per_page( 'bp_nouveau_notices_per_page' );
  32  
  33              $this->items = BP_Messages_Notice::get_notices( array(
  34                  'pag_num'  => $per_page,
  35                  'pag_page' => $page
  36              ) );
  37  
  38              $this->set_pagination_args( array(
  39                  'total_items' => BP_Messages_Notice::get_total_notice_count(),
  40                  'per_page' => $per_page,
  41              ) );
  42          }
  43  
  44  		public function get_columns() {
  45              return apply_filters( 'bp_nouveau_notices_list_table_get_columns', array(
  46                  'subject'   => _x( 'Subject', 'Admin Notices column header', 'buddypress' ),
  47                  'message'   => _x( 'Content', 'Admin Notices column header', 'buddypress' ),
  48                  'date_sent' => _x( 'Created', 'Admin Notices column header', 'buddypress' ),
  49              ) );
  50          }
  51  
  52  		public function single_row( $item ) {
  53              $class = '';
  54  
  55              if ( ! empty( $item->is_active ) ) {
  56                  $class = ' class="notice-active"';
  57              }
  58  
  59              echo "<tr{$class}>";
  60              $this->single_row_columns( $item );
  61              echo '</tr>';
  62          }
  63  
  64  		public function column_subject( $item ) {
  65              $actions = array(
  66                  'activate_deactivate' => '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
  67                      'page' => 'bp-notices',
  68                      'activate' => $item->id
  69                  ), bp_get_admin_url( 'users.php' ) ) ), 'messages_activate_notice' ) . '" data-bp-notice-id="' . $item->id . '" data-bp-action="activate">' . esc_html__( 'Activate Notice', 'buddypress' ) . '</a>',
  70                  'delete' => '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
  71                      'page' => 'bp-notices',
  72                      'delete' => $item->id
  73                  ), bp_get_admin_url( 'users.php' ) ) ), 'messages_delete_thread' ) . '" data-bp-notice-id="' . $item->id . '" data-bp-action="delete">' . esc_html__( 'Delete Notice', 'buddypress' ) . '</a>',
  74              );
  75  
  76              if ( ! empty( $item->is_active ) ) {
  77                  $actions['activate_deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
  78                      'page' => 'bp-notices',
  79                      'deactivate' => $item->id
  80                  ), bp_get_admin_url( 'users.php' ) ) ), 'messages_deactivate_notice' ) . '" data-bp-notice-id="' . $item->id . '" data-bp-action="deactivate">' . esc_html__( 'Deactivate Notice', 'buddypress' ) . '</a>';
  81              }
  82  
  83              echo '<strong>' . apply_filters( 'bp_get_message_notice_subject', $item->subject ) . '</strong> ' . $this->row_actions( $actions );
  84          }
  85  
  86  		public function column_message( $item ) {
  87              echo apply_filters( 'bp_get_message_notice_text', $item->message );
  88          }
  89  
  90  		public function column_date_sent( $item ) {
  91              echo apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime( $item->date_sent ) ) );
  92          }
  93      }
  94  endif;
  95  
  96  
  97  class BP_Nouveau_Admin_Notices {
  98  
  99  	public static function register_notices_admin() {
 100          if ( ! is_admin() || ! bp_is_active( 'messages' ) ) {
 101              return;
 102          }
 103  
 104          $bp = buddypress();
 105  
 106          if ( empty( $bp->messages->admin ) ) {
 107              $bp->messages->admin = new self;
 108          }
 109  
 110          return $bp->messages->admin;
 111      }
 112  
 113      /**
 114       * Constructor method.
 115       *
 116       * @since 2.0.0
 117       */
 118  	public function __construct() {
 119          $this->setup_globals();
 120          $this->setup_actions();
 121      }
 122  
 123  	protected function setup_globals() {
 124          $this->screen_id = '';
 125          $this->url       = add_query_arg( array( 'page' => 'bp-notices' ), bp_get_admin_url( 'users.php' ) );
 126      }
 127  
 128  	protected function setup_actions() {
 129          add_action( bp_core_admin_hook(), array( $this, 'admin_menu' ) );
 130      }
 131  
 132  	public function admin_menu() {
 133          // Bail if current user cannot moderate community.
 134          if ( ! bp_current_user_can( 'bp_moderate' ) || ! bp_is_active( 'messages' ) ) {
 135              return false;
 136          }
 137  
 138          $this->screen_id = add_users_page(
 139              _x( 'All Member Notices', 'Notices admin page title', 'buddypress' ),
 140              _x( 'All Member Notices', 'Admin Users menu', 'buddypress' ),
 141              'manage_options',
 142              'bp-notices',
 143              array( $this, 'admin_index' )
 144          );
 145  
 146          add_action( 'load-' . $this->screen_id, array( $this, 'admin_load' ) );
 147      }
 148  
 149  	public function admin_load() {
 150          if ( ! empty( $_POST['bp_notice']['send'] ) ) {
 151              $notice = wp_parse_args( $_POST['bp_notice'], array(
 152                  'subject' => '',
 153                  'content' => ''
 154              ) );
 155  
 156              if ( messages_send_notice( $notice['subject'], $notice['content'] ) ) {
 157                  $redirect_to = add_query_arg( 'success', 1, $this->url );
 158  
 159              // Notice could not be sent.
 160              } else {
 161                  $redirect_to = add_query_arg( 'error', 1, $this->url );
 162              }
 163  
 164              wp_safe_redirect( $redirect_to );
 165              exit();
 166          }
 167  
 168          $this->list_table = new BP_Nouveau_Notices_List_Table( array( 'screen' => get_current_screen()->id ) );
 169      }
 170  
 171  	public function admin_index() {
 172          $this->list_table->prepare_items();
 173          ?>
 174          <div class="wrap">
 175              <?php if ( version_compare( $GLOBALS['wp_version'], '4.8', '>=' ) ) : ?>
 176  
 177                  <h1 class="wp-heading-inline"><?php echo esc_html_x( 'All Member Notices', 'Notices admin page title', 'buddypress' ); ?></h1>
 178  
 179                      <a id="add_notice" class="page-title-action" href="#"><?php esc_html_e( 'Add New Notice', 'buddypress' ); ?></a>
 180  
 181                  <hr class="wp-header-end">
 182  
 183              <?php else : ?>
 184  
 185                  <h1>
 186                      <?php echo esc_html_x( 'All Member Notices', 'Notices admin page title', 'buddypress' ); ?>
 187                      <a id="add_notice" class="add-new-h2" href="#"><?php esc_html_e( 'Add New Notice', 'buddypress' ); ?></a>
 188                  </h1>
 189  
 190              <?php endif; ?>
 191  
 192              <form action=<?php echo esc_url( $this->url ); ?> method="post">
 193                  <table class="widefat">
 194                      <tr>
 195                          <td><label for="bp_notice_subject"><?php esc_html_e( 'Subject', 'buddypress' ); ?></label></td>
 196                          <td><input type="text" class="widefat" id="bp_notice_subject" name="bp_notice[subject]"/></td>
 197                      </tr>
 198                      <tr>
 199                          <td><label for="bp_notice_content"><?php esc_html_e( 'Content', 'buddypress' ); ?></label></td>
 200                          <td><textarea class="widefat" id="bp_notice_content" name="bp_notice[content]"></textarea></td>
 201                      </tr>
 202                      <tr class="submit">
 203                          <td>&nbsp;</td>
 204                          <td style="float:right">
 205                              <input type="reset" value="<?php esc_attr_e( 'Cancel Notice', 'buddypress' ); ?>" class="button-secondary">
 206                              <input type="submit" value="<?php esc_attr_e( 'Save Notice', 'buddypress' ); ?>" name="bp_notice[send]" class="button-primary">
 207                          </td>
 208                      </tr>
 209                  </table>
 210              <form>
 211  
 212              <?php if ( isset( $_GET['success'] ) || isset( $_GET['error'] ) ) : ?>
 213  
 214                  <div id="message" class="<?php echo isset( $_GET['success'] ) ? 'updated' : 'error'; ?>">
 215  
 216                      <p>
 217                          <?php
 218                          if ( isset( $_GET['error'] ) ) :
 219                              esc_html_e( 'Notice was not created. Please try again.', 'buddypress' );
 220                          else :
 221                              esc_html_e( 'Notice successfully created.', 'buddypress' );
 222                          endif;
 223                          ?>
 224                      </p>
 225  
 226                  </div>
 227  
 228              <?php endif; ?>
 229  
 230              <?php $this->list_table->display(); ?>
 231  
 232          </div>
 233          <?php
 234      }
 235  }
 236  add_action( 'bp_init', array( 'BP_Nouveau_Admin_Notices', 'register_notices_admin' ) );


Generated: Wed Feb 28 01:00:55 2018 Cross-referenced by PHPXref 0.7.1