Tribe__Admin__Notices::register( string $slug, callable|string $callback, array $arguments = array(), callable|null $active_callback = null )
Register a Notice and attach a callback to the required action to display it correctly
Contents
Parameters
- $slug
-
(string) (Required) Slug to save the notice
- $callback
-
(callable|string) (Required) A callable Method/Function to actually display the notice
- $arguments
-
(array) (Optional) Arguments to Setup a notice
Default value: array()
- $active_callback
-
(callable|null) (Optional) An optional callback that should return bool values to indicate whether the notice should display or not.
Default value: null
Return
(stdClass)
Source
File: src/Tribe/Admin/Notices.php
public function register( $slug, $callback, $arguments = array(), $active_callback = null ) {
// Prevent weird stuff here
$slug = sanitize_title_with_dashes( $slug );
$defaults = array(
'callback' => null,
'content' => null,
'action' => 'admin_notices',
'priority' => 10,
'expire' => false,
'dismiss' => false,
'type' => 'error',
'is_rendered' => false,
'wrap' => false,
);
$defaults['callback'] = array( $this, 'render_' . $slug );
$defaults['content'] = $callback;
if ( is_callable( $active_callback ) ) {
$defaults['active_callback'] = $active_callback;
}
// Merge Arguments
$notice = (object) wp_parse_args( $arguments, $defaults );
// Enforce this one
$notice->slug = $slug;
// Clean these
$notice->priority = absint( $notice->priority );
$notice->expire = (bool) $notice->expire;
$notice->dismiss = (bool) $notice->dismiss;
// Set the Notice on the array of notices
$this->notices[ $slug ] = $notice;
// Return the notice Object because it might be modified
return $notice;
}
Changelog
| Version | Description |
|---|---|
| 4.3 | Introduced. |