messages->admin ) ) { $bp->messages->admin = new self; } return $bp->messages->admin; } /** * Constructor. * * @since 3.0.0 */ public function __construct() { $this->setup_globals(); $this->setup_actions(); } /** * Populate the classs variables. * * @since 3.0.0 */ protected function setup_globals() { $this->url = add_query_arg( array( 'page' => 'bp-notices' ), bp_get_admin_url( 'users.php' ) ); } /** * Add action hooks. * * @since 3.0.0 */ protected function setup_actions() { add_action( bp_core_admin_hook(), array( $this, 'admin_menu' ) ); } /** * Add the 'Site Notices' admin menu item. * * @since 3.0.0 */ public function admin_menu() { // Bail if current user cannot moderate community. if ( ! bp_current_user_can( 'bp_moderate' ) || ! bp_is_active( 'messages' ) ) { return false; } $this->screen_id = add_users_page( _x( 'Site Notices', 'Notices admin page title', 'buddypress' ), _x( 'Site Notices', 'Admin Users menu', 'buddypress' ), 'manage_options', 'bp-notices', array( $this, 'admin_index' ) ); add_action( 'load-' . $this->screen_id, array( $this, 'admin_load' ) ); } /** * Catch save/update requests or load the screen. * * @since 3.0.0 */ public function admin_load() { $redirect_to = false; // Catch new notice saves. if ( ! empty( $_POST['bp_notice']['send'] ) ) { check_admin_referer( 'new-notice', 'ns-nonce' ); $notice = bp_parse_args( $_POST['bp_notice'], array( 'subject' => '', 'content' => '', ) ); if ( messages_send_notice( $notice['subject'], $notice['content'] ) ) { $redirect_to = add_query_arg( 'success', 'create', $this->url ); // Notice could not be sent. } else { $redirect_to = add_query_arg( 'error', 'create', $this->url ); } } // Catch activation/deactivation/delete requests if ( ! empty( $_GET['notice_id'] ) && ! empty( $_GET['notice_action'] ) ) { $notice_id = absint( $_GET['notice_id'] ); check_admin_referer( 'messages-' . $_GET['notice_action'] . '-notice-' . $notice_id ); $success = false; switch ( $_GET['notice_action'] ) { case 'activate': $notice = new BP_Messages_Notice( $notice_id ); $success = $notice->activate(); break; case 'deactivate': $notice = new BP_Messages_Notice( $notice_id ); $success = $notice->deactivate(); break; case 'delete': $notice = new BP_Messages_Notice( $notice_id ); $success = $notice->delete(); break; } if ( $success ) { $redirect_to = add_query_arg( 'success', 'update', $this->url ); // Notice could not be updated. } else { $redirect_to = add_query_arg( 'error', 'update', $this->url ); } } if ( $redirect_to ) { wp_safe_redirect( $redirect_to ); exit(); } $this->list_table = new BP_Messages_Notices_List_Table( array( 'screen' => get_current_screen()->id ) ); } /** * Generate content for the bp-notices admin screen. * * @since 3.0.0 */ public function admin_index() { $this->list_table->prepare_items(); ?>


list_table->display(); ?>