cptui_admin_notices

Return a notice based on conditions.

Description

(bool|string) cptui_admin_notices( (string) $action = '', (string) $object_type = '', (constant) $success = true, (string) $custom = '' ); 

Returns (bool|string)

false on no message, else HTML div with our notice message.

Parameters (4)

0. $action — Optional. (string) => ''
The type of action that occurred. Optional. Default empty string.
1. $object_type — Optional. (string) => ''
Whether it's from a post type or taxonomy. Optional. Default empty string.
2. $success — Optional. (constant) => true
Whether the action succeeded or not. Optional. Default true.
3. $custom — Optional. (string) => ''
Custom message if necessary. Optional. Default empty string.

Usage

  1. if ( !function_exists( 'cptui_admin_notices' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/custom-post-type-ui.php'; 
  3.  
  4. // The type of action that occurred. Optional. Default empty string. 
  5. $action = ''; 
  6.  
  7. // Whether it's from a post type or taxonomy. Optional. Default empty string. 
  8. $object_type = ''; 
  9.  
  10. // Whether the action succeeded or not. Optional. Default true. 
  11. $success = true; 
  12.  
  13. // Custom message if necessary. Optional. Default empty string. 
  14. $custom = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = cptui_admin_notices($action, $object_type, $success, $custom); 
  18.  

Defined (1)

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

/custom-post-type-ui.php  
  1. function cptui_admin_notices( $action = '', $object_type = '', $success = true, $custom = '' ) { 
  2.  
  3. $class = array(); 
  4. $class[] = ( $success ) ? 'updated' : error; 
  5. $class[] = 'notice is-dismissible'; 
  6. $object_type = esc_attr( $object_type ); 
  7.  
  8. $messagewrapstart = '<div id="message" class="' . implode( ' ', $class ) . '"><p>'; 
  9. $message = ''; 
  10.  
  11. $messagewrapend = '</p></div>'; 
  12.  
  13. if ( 'add' == $action ) { 
  14. if ( $success ) { 
  15. $message .= sprintf( __( '%s has been successfully added', 'custom-post-type-ui' ), $object_type ); 
  16. } else { 
  17. $message .= sprintf( __( '%s has failed to be added', 'custom-post-type-ui' ), $object_type ); 
  18. } elseif ( 'update' == $action ) { 
  19. if ( $success ) { 
  20. $message .= sprintf( __( '%s has been successfully updated', 'custom-post-type-ui' ), $object_type ); 
  21. } else { 
  22. $message .= sprintf( __( '%s has failed to be updated', 'custom-post-type-ui' ), $object_type ); 
  23. } elseif ( 'delete' == $action ) { 
  24. if ( $success ) { 
  25. $message .= sprintf( __( '%s has been successfully deleted', 'custom-post-type-ui' ), $object_type ); 
  26. } else { 
  27. $message .= sprintf( __( '%s has failed to be deleted', 'custom-post-type-ui' ), $object_type ); 
  28. } elseif ( 'import' == $action ) { 
  29. if ( $success ) { 
  30. $message .= sprintf( __( '%s has been successfully imported', 'custom-post-type-ui' ), $object_type ); 
  31. } else { 
  32. $message .= sprintf( __( '%s has failed to be imported', 'custom-post-type-ui' ), $object_type ); 
  33. } elseif ( error == $action ) { 
  34. if ( ! empty( $custom ) ) { 
  35. $message = $custom; 
  36.  
  37. if ( $message ) { 
  38.  
  39. /** 
  40. * Filters the custom admin notice for CPTUI. 
  41. * @since 1.0.0 
  42. * @param string $value Complete HTML output for notice. 
  43. * @param string $action Action whose message is being generated. 
  44. * @param string $message The message to be displayed. 
  45. * @param string $messagewrapstart Beginning wrap HTML. 
  46. * @param string $messagewrapend Ending wrap HTML. 
  47. */ 
  48. return apply_filters( 'cptui_admin_notice', $messagewrapstart . $message . $messagewrapend, $action, $message, $messagewrapstart, $messagewrapend ); 
  49.  
  50. return false;