BP_Messages_Notices_Admin::admin_load()

Catch save/update requests or load the screen.

Description

Source

File: bp-messages/classes/class-bp-messages-notices-admin.php

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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 = wp_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 ) );
}

Changelog

Changelog
Version Description
BuddyPress 3.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.