bp_core_add_message

Add a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.

Description

bp_core_add_message( (string) $message, (string) $type = '' ); 

Parameters (2)

0. $message (string)
Feedback message to be displayed.
1. $type — Optional. (string) => ''
Message type. updated,, success., error, warning. Default: success..

Usage

  1. if ( !function_exists( 'bp_core_add_message' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // Feedback message to be displayed. 
  5. $message = ''; 
  6.  
  7. // Message type. 'updated', 'success', 'error', 'warning'. 
  8. // Default: 'success'. 
  9. $type = ''; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_core_add_message($message, $type); 
  13.  

Defined (1)

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

/bp-core/bp-core-functions.php  
  1. function bp_core_add_message( $message, $type = '' ) { 
  2.  
  3. // Success is the default. 
  4. if ( empty( $type ) ) { 
  5. $type = 'success'; 
  6.  
  7. // Send the values to the cookie for page reload display. 
  8. @setcookie( 'bp-message', $message, time() + 60 * 60 * 24, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 
  9. @setcookie( 'bp-message-type', $type, time() + 60 * 60 * 24, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 
  10.  
  11. // Get BuddyPress. 
  12. $bp =buddypress); 
  13.  
  14. /** 
  15. * Send the values to the $bp global so we can still output messages 
  16. * without a page reload 
  17. */ 
  18. $bp->template_message = $message; 
  19. $bp->template_message_type = $type;