-
-
Notifications
You must be signed in to change notification settings - Fork 3
Filters
Note! A lot of functionality on this plugin is hooked into the plugins_loaded
action. For this reason your theme functions aren't loaded yet! Please create a plugin (or must-use plugin) to use most of these filters.
view_admin_as_role_defaults_meta
view_admin_as_superior_admins
view_admin_as_full_access_capabilities
view_admin_as_view_expiration
view_admin_as_validate_view_data_{TYPE}
view_admin_as_handle_ajax_{KEY}
view_admin_as_update_view_{KEY}
view_admin_as_user_has_cap_priority
view_admin_as_get_capabilities
view_admin_as_add_capabilities
view_admin_as_script_localization
view_admin_as_error_page_options
view_admin_as_default_global_settings_{ID}
view_admin_as_allowed_global_settings_{ID}
view_admin_as_default_user_settings_{ID}
view_admin_as_allowed_user_settings_{ID}
view_admin_as_toolbar_classes
view_admin_as_freeze_locale
view_admin_as_user_query_limit
vaa_admin_bar_priority
vaa_admin_bar_view_titles
vaa_admin_bar_title
vaa_admin_bar_view_title_{TYPE}
vaa_admin_bar_view_title_user_show_roles
vaa_admin_bar_caps_do_title_submenu
view_admin_as_{TYPE}_ajax_search
Since 1.4
Change the meta_keys to use for role defaults.
@param array $meta Default metadata
@return array $meta
By default it uses the following meta keys:
%%
stands for a wildcard which could be anything.
admin_color » The admin color
rich_editing » Enable/Disable rich editing
metaboxhidden_%% » Hidden metaboxes
meta-box-order_%% » Metabox order and locations
closedpostboxes_%% » Hidden post boxes
edit_%%_per_page » Amount of items per page in edit.php pages
manage%%columnshidden » Hidden columns in edit.php pages
screen_layout_%% » Screen layout (number of columns)
The following meta keys are forbidden:
%%
stands for the table prefix
vaa-view-admin-as » Meta value for this plugin
%%capabilities » The user’s capabilities
%%user_level » The user’s user level
session_tokens » The user’s session tokens
nickname » The user’s nickname
first_name » The user’s first name
last_name » The user’s last name
description » The user’s description
Examples:
add_filter( 'view_admin_as_role_defaults_meta', 'my_vaa_meta_filter' );
function my_vaa_meta_filter( $metakeys ) {
// Adding a new meta key:
$metakeys['new_meta_key'] = true; // Or anything that parses to true
// Removing a new meta key
unset( $metakeys['rich_editing'] );
// Always return the metakeys!!
return $metakeys;
}
Since: 1.5.2
Give admins the capability to view and edit other admins
@param array
@return array requires a returned array of user ID's
Note: Super admins only!
All returned user ID's will be validated with is_super_admin()
Examples:
add_filter( 'view_admin_as_superior_admins', 'my_superior_admins' );
function my_superior_admins() {
// Give user ID 2 superior access
return 2;
// Give user ID's 2 and 4 superior access
return array( 2, 4 );
}
Example 2: https://developer.wordpress.org/reference/functions/get_user_by/
add_filter( 'view_admin_as_superior_admins', 'my_superior_admins' );
function my_superior_admins() {
// Get your user object
$user = get_user_by( 'email', 'test@your.domain' );
if ( isset( $user->ID ) ) {
// Return your user ID
return $user->ID;
}
}
The best way to do this is by creating a new file in the /wp-content/mu-plugins/
directory. There you can create a new file vaa-superior-admin.php
where you add this code.
The mu-plugins
are "Must Use plugins" that are loaded at the beginning of WP (even before all other plugins). Also, they cannot be edited anywhere in the WP UI.
Gist snippet example: https://gist.github.com/JoryHogeveen/256292fc4bf87d69c0ba5ca473a61eee
Since: 1.8
Filter the capabilities required to gain full access to this plugin.
Default: edit_users
& delete_plugins
@param array $caps The default capabilities.
@param \WP_User $user The user that is being validated.
@return array
- Single site only!
-
is_super_admin()
is always checked!
Since: 1.6.2
Change expiration time for view meta
@param int $viewExpiration 86400 (1 day in seconds)
@return int
- You can set it to
1
to always clear everything after login -
0
will be overwritten!
Since: 1.6.2
Since: 1.7 Added first NULL parameter and third $key parameter.
Validate the data for a view type. (See view_admin_as_view_types
)
Hook is required!
@param null $null Ensures a validation filter is required.
@param mixed $value Unvalidated view data.
@param string $key The data key.
@return mixed validated view data for type
Since: 1.7
Ajax return filters.
@param null $null Null.
@param mixed $value View data value.
@param string $key View data key.
@return bool|array {
In case of array. Uses wp_json_return() structure.
@type bool $success Send JSON success or error?
@type array $data {
Optional extra data to send with the JSON return.
In case of a view the page normally refreshes.
@type string $redirect (URL) Redirect the user? (Only works on success).
@type string $display Options: notice A notice type in the admin bar
popup A popup/overlay with content
@type string $type Options: success Ureka! (green) - Default when $success is true
error Send an error (red) - Default when $success is false
message Just a message (blue)
warning Send a warning (orange)
@type string $text The text to show
@type array $list Show multiple messages (Popup only)
@type string $textarea Textarea content (Popup only)
}
}
Since: 1.7
See view_admin_as_handle_ajax_{KEY}
This is the filter triggered for registerd view types.
Since: 1.7.2
The priority value of the VAA user_has_cap
filter.
Runs as last for caps views and as first for all other views.
@param int $priority
@return int
Since: 1.5
Get all capabilities (also checks for other known plugins)
@param array $capabilities
@return array $capabilities
(previously: _vaa_add_capabilities
)
NOTE: ONLY add capabilities used by this plugin!
Since: 1.5
Since: 1.6.3 Changed to view_admin_as_add_capabilities
Add capabilities to the list of this plugin's capabilities
@param array $capabilities
@return array $capabilities
Since: 1.7
Add data to the VAA script localization
@param array $array Empty array (Will be overwritten with VAA core data so use unique keys).
@return array
Since: 1.6.2
Add or remove options to the die handler pages
@param array $options {
Required array of arrays.
@type array {
@type string $text The text to show.
@type string $url The link.
}
}
@return array
Since: 1.7
Set the default global settings.
ID is not set for core settings: view_admin_as_default_global_settings
@param array
@return array
Since: 1.7
Set the allowed global settings.
ID is not set for core settings: view_admin_as_allowed_global_settings
@param array {
Settings array (key = setting name).
@type array Array of allowed values.
}
@return array
Since: 1.7
Set the default settings for users.
ID is not set for core settings: view_admin_as_default_user_settings
@param array
@return array
Since: 1.7
Set the allowed settings for users.
ID is not set for core settings: view_admin_as_allowed_user_settings
@param array {
Settings array (key = setting name).
@type array Array of allowed values.
}
@return array
Since: 1.6
Add classes to the VAA toolbar menu (front only)
@param array $array Empty array.
@return array
Since: 1.7.5
Force own locale on view. Overwrites the user setting.
@param bool $freeze_locale The user setting.
@return bool
Since: 1.8
Change the limit for querying users.
@param int $limit Default: 100.
@return int
Since: 1.7.4
Set the priority in which the adminbar root node is added.
@param int $priority
@param string $parent The main VAA node parent.
@return int
Since: 1.7.5
Filter the title to show when a view is applied.
@param array $title The current title(s).
@param array $view The view data.
@return array
Since: 1.6
Since: 1.7.5 Renamed from vaa_admin_bar_viewing_as_title
.
Filter the title to show when a view is applied.
This filter is hooked after the initial parsing of view titles. See vaa_admin_bar_view_titles
.
@param string $title The current title.
@param array $view The view data.
@return string
Since: 1.8
Change the display title for view type nodes..
@param string $title The default view title. (Example: WP_User->display_name for the user view type)
@param mixed $view The view type value. (Example: WP_User for the user view type).
@return array
Since: 1.8
Add the user roles to the user title?
Only available if users are not grouped under their roles.
@param bool $true True by default.
@param \WP_User $user The user object.
@return bool
Since: 1.7.5
Whether the capability manager should be loaded as a submenu from the title element or as a separate node below the title.
Default: true
Useful if you have a plugin that adds another sub-node below the capability title.
@param bool $do_title_submenu
@return bool
Since: 1.8.1
Force AJAX search for view types at all times.
Note: Currently only available for user views (view_admin_as_user_ajax_search
)
Default: false
@param bool $do_title_submenu
@return bool
Since: 1.6.2
Deprecated since: 1.8
Add basic view types for automated use in JS and view data validation
@param array of strings (view types)
@return array of strings (view types)
- Menu items require the class
vaa-{TYPE}-item
(through theadd_node()
meta key) - Menu items require the
rel
attribute for the view data to be send (string or numeric) - Menu items require the
href
attribute (the node needs to be an<a>
element). - See:
VAA_API::get_vaa_action_link()
- See:
VAA_View_Admin_As_Admin_Bar::do_view_title()