bp_dtheme_ajax_close_notice

Close and keep closed site wide notices from an admin in the sidebar, via a POST request.

Description

bp_dtheme_ajax_close_notice(); 

Usage

  1. if ( !function_exists( 'bp_dtheme_ajax_close_notice' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-themes/bp-default/_inc/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_dtheme_ajax_close_notice(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-themes/bp-default/_inc/ajax.php  
  1. function bp_dtheme_ajax_close_notice() { 
  2. // Bail if not a POST action 
  3. if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 
  4. return; 
  5.  
  6. $nonce_check = isset( $_POST['nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'bp_messages_close_notice' ); 
  7.  
  8. if ( ! $nonce_check || ! isset( $_POST['notice_id'] ) ) { 
  9. echo "-1<div id='message' class=error><p>" . __( 'There was a problem closing the notice.', buddypress ) . '</p></div>'; 
  10.  
  11. } else { 
  12. $user_id = get_current_user_id(); 
  13. $notice_ids = bp_get_user_meta( $user_id, 'closed_notices', true ); 
  14. $notice_ids[] = (int) $_POST['notice_id']; 
  15.  
  16. bp_update_user_meta( $user_id, 'closed_notices', $notice_ids ); 
  17.  
  18. exit;