Skip to:
Content

BuddyPress.org


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

Notices Admin List: Handle status change action links.

  • Add support for activating, deactivating and deleting site wide notices via action links on the notices list.
  • Use notice- and action-specific nonces for status change links.
  • Change success/error parameters to allow more specific feedback messages.
  • Reformat the code that creates the status change action links.
  • Prepend the currently active notice with the tag "Active:".
File:
1 edited

Legend:

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

    r11869 r11870  
    115115         */
    116116        public function admin_load() {
     117                $redirect_to = false;
     118
     119                // Catch new notice saves.
    117120                if ( ! empty( $_POST['bp_notice']['send'] ) ) {
    118121
     
    125128
    126129                        if ( messages_send_notice( $notice['subject'], $notice['content'] ) ) {
    127                                 $redirect_to = add_query_arg( 'success', 1, $this->url );
     130                                $redirect_to = add_query_arg( 'success', 'create', $this->url );
    128131
    129132                        // Notice could not be sent.
    130133                        } else {
    131                                 $redirect_to = add_query_arg( 'error', 1, $this->url );
     134                                $redirect_to = add_query_arg( 'error', 'create', $this->url );
    132135                        }
    133 
     136                }
     137
     138                // Catch activation/deactivation/delete requests
     139                if ( ! empty( $_GET['notice_id'] ) && ! empty( $_GET['notice_action'] ) ) {
     140                        $notice_id = absint( $_GET['notice_id'] );
     141
     142                        check_admin_referer( 'messages-' . $_GET['notice_action'] . '-notice-' . $notice_id );
     143
     144                        $success = false;
     145                        switch ( $_GET['notice_action'] ) {
     146                                case 'activate':
     147                                        $notice = new BP_Messages_Notice( $notice_id );
     148                                        $success = $notice->activate();
     149                                        break;
     150                                case 'deactivate':
     151                                        $notice = new BP_Messages_Notice( $notice_id );
     152                                        $success = $notice->deactivate();
     153                                        break;
     154                                case 'delete':
     155                                        $notice = new BP_Messages_Notice( $notice_id );
     156                                        $success = $notice->delete();
     157                                        break;                 
     158                        }
     159                        if ( $success ) {
     160                                $redirect_to = add_query_arg( 'success', 'update', $this->url );
     161
     162                        // Notice could not be updated.
     163                        } else {
     164                                $redirect_to = add_query_arg( 'error', 'update', $this->url );
     165                        }
     166
     167                }
     168
     169                if ( $redirect_to ) {
    134170                        wp_safe_redirect( $redirect_to );
    135171                        exit();
     
    191227                                        <p>
    192228                                                <?php
    193                                                 if ( isset( $_GET['error'] ) ) :
    194                                                         esc_html_e( 'Notice was not created. Please try again.', 'buddypress' );
    195                                                 else :
    196                                                         esc_html_e( 'Notice successfully created.', 'buddypress' );
    197                                                 endif;
     229                                                if ( isset( $_GET['error'] ) ) {
     230                                                        if ( 'create' === $_GET['error'] ) {
     231                                                                esc_html_e( 'Notice was not created. Please try again.', 'buddypress' );
     232                                                        } else {
     233                                                                esc_html_e( 'Notice was not updated. Please try again.', 'buddypress' );                                                       
     234                                                        }
     235                                                 } else {
     236                                                        if ( 'create' === $_GET['success'] ) {
     237                                                                esc_html_e( 'Notice successfully created.', 'buddypress' );
     238                                                        } else {
     239                                                                esc_html_e( 'Notice successfully updated.', 'buddypress' );
     240                                                        }
     241                                                }
    198242                                                ?>
    199243                                        </p>
Note: See TracChangeset for help on using the changeset viewer.