Skip to:
Content

BuddyPress.org

Changeset 11868


Ignore:
Timestamp:
02/28/2018 07:25:21 PM (9 years ago)
Author:
dcavins
Message:

Move Notices Admin from Nouveau to Messages component.

As part of Nouveau template development, a nice interface
for managing site-wide notifications was created. This commit
moves that interface into BuddyPress proper so it is available
for use with any template.

Props imath, hnla, djpaul, dcavins.

Location:
trunk/src
Files:
2 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/classes/class-bp-messages-component.php

    r11578 r11868  
    7373                if ( bp_is_active( $this->id, 'star' ) ) {
    7474                        $includes[] = 'star';
     75                }
     76                if ( is_admin() ) {
     77                        $includes[] = 'admin';
    7578                }
    7679
  • trunk/src/bp-messages/classes/class-bp-messages-notices-admin.php

    r11867 r11868  
    11<?php
    22/**
    3  * Mesages classes
     3 * BuddyPress messages component Site-wide Notices admin screen.
    44 *
    5  * @since 1.0.0
     5 *
     6 * @package BuddyPress
     7 * @subpackage Messages
     8 * @since 3.0.0
    69 */
    710
     
    912defined( 'ABSPATH' ) || exit;
    1013
    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 
     14class BP_Messages_Notices_Admin {
     15
     16        /**
     17         * The ID returned by `add_users_page()`.
     18         *
     19         * @since 3.0.0
     20         * @var string
     21         */
     22        public $screen_id = '';
     23
     24        /**
     25         * The URL of the admin screen.
     26         *
     27         * @since 3.0.0
     28         * @var string
     29         */
     30        public $url = '';
     31
     32        /**
     33         * The current instance of the BP_Messages_Notices_List_Table class.
     34         *
     35         * @since 3.0.0
     36         * @var object
     37         */
     38        public $list_table = '';
     39       
     40
     41        /**
     42     * Create a new instance or access the current instance of this class.
     43     *
     44     * @since 3.0.0
     45     */
    9946        public static function register_notices_admin() {
    100                 if ( ! is_admin() || ! bp_is_active( 'messages' ) ) {
     47
     48                if ( ! is_admin() || ! bp_is_active( 'messages' ) || ! bp_current_user_can( 'bp_moderate' ) ) {
    10149                        return;
    10250                }
     
    11462         * Constructor method.
    11563         *
    116          * @since 2.0.0
     64         * @since 3.0.0
    11765         */
    11866        public function __construct() {
     
    12169        }
    12270
     71        /**
     72         * Populate the classs variables.
     73         *
     74         * @since 3.0.0
     75         */
    12376        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 
     77                $this->url = add_query_arg( array( 'page' => 'bp-notices' ), bp_get_admin_url( 'users.php' ) );
     78        }
     79
     80        /**
     81         * Add action hooks.
     82         *
     83         * @since 3.0.0
     84         */
    12885        protected function setup_actions() {
    12986                add_action( bp_core_admin_hook(), array( $this, 'admin_menu' ) );
    13087        }
    13188
     89        /**
     90         * Add the 'All Member Notices' admin menu item.
     91         *
     92         * @since 3.0.0
     93         */
    13294        public function admin_menu() {
    13395                // Bail if current user cannot moderate community.
     
    147109        }
    148110
     111        /**
     112         * Catch save/update requests or load the screen.
     113         *
     114         * @since 3.0.0
     115         */
    149116        public function admin_load() {
    150117                if ( ! empty( $_POST['bp_notice']['send'] ) ) {
     
    166133                }
    167134
    168                 $this->list_table = new BP_Nouveau_Notices_List_Table( array( 'screen' => get_current_screen()->id ) );
    169         }
    170 
     135                $this->list_table = new BP_Messages_Notices_List_Table( array( 'screen' => get_current_screen()->id ) );
     136        }
     137
     138        /**
     139         * Generate content for the bp-notices admin screen.
     140         *
     141         * @since 3.0.0
     142         */
    171143        public function admin_index() {
    172144                $this->list_table->prepare_items();
     
    234206        }
    235207}
    236 add_action( 'bp_init', array( 'BP_Nouveau_Admin_Notices', 'register_notices_admin' ) );
  • trunk/src/bp-templates/bp-nouveau/includes/messages/loader.php

    r11855 r11868  
    4242         */
    4343        protected function includes() {
    44                 require $this->dir . 'classes.php';
    4544                require $this->dir . 'functions.php';
    4645                require $this->dir . 'template-tags.php';
Note: See TracChangeset for help on using the changeset viewer.