bp_messages_action_edit_notice

Handle editing of sitewide notices.

Description

(boolean) bp_messages_action_edit_notice(); 

Returns (boolean)


Usage

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

Defined (1)

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

/bp-messages/bp-messages-actions.php  
  1. function bp_messages_action_edit_notice() { 
  2. global $notice_id; 
  3.  
  4. // Bail if not viewing a single notice URL. 
  5. if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || ! bp_action_variable( 1 ) ) { 
  6. return false; 
  7.  
  8. // Get action variables. 
  9. $action = bp_action_variable( 0 ); // deactivate|activate|delete. 
  10. $notice_id = bp_action_variable( 1 ); // 1|2|3|etc... 
  11.  
  12. // Bail if notice ID is not numeric. 
  13. if ( ! is_numeric( $notice_id ) ) { 
  14. return; 
  15.  
  16. // Define local variables. 
  17. $redirect_to = ''; 
  18. $feedback = ''; 
  19. $success = false; 
  20.  
  21. // Get the notice from database. 
  22. $notice = new BP_Messages_Notice( $notice_id ); 
  23.  
  24. // Take action. 
  25. switch ( $action ) { 
  26.  
  27. // Deactivate. 
  28. case 'deactivate' : 
  29. $success = $notice->deactivate(); 
  30. $feedback = true === $success 
  31. ? __( 'Notice deactivated successfully.', buddypress ) 
  32. : __( 'There was a problem deactivating that notice.', buddypress ); 
  33. break; 
  34.  
  35. // Activate. 
  36. case 'activate' : 
  37. $success = $notice->activate(); 
  38. $feedback = true === $success 
  39. ? __( 'Notice activated successfully.', buddypress ) 
  40. : __( 'There was a problem activating that notice.', buddypress ); 
  41. break; 
  42.  
  43. // Delete. 
  44. case 'delete' : 
  45. $success = $notice->delete(); 
  46. $feedback = true === $success 
  47. ? __( 'Notice deleted successfully.', buddypress ) 
  48. : __( 'There was a problem deleting that notice.', buddypress ); 
  49. break; 
  50.  
  51. // Feedback. 
  52. if ( ! empty( $feedback ) ) { 
  53.  
  54. // Determine message type. 
  55. $type = ( true === $success ) 
  56. ? 'success' 
  57. : error; 
  58.  
  59. // Add feedback message. 
  60. bp_core_add_message( $feedback, $type ); 
  61.  
  62. // Redirect. 
  63. $redirect_to = trailingslashit( $member_notices . 'notices' ); 
  64.  
  65. bp_core_redirect( $redirect_to );