Filter
uncanny-automator
uap_option_get_all_wss_roles
Filters all wholesale sales roles before they are retrieved from the WordPress database.
add_filter( 'uap_option_get_all_wss_roles', $callback, 10, 1 );
Description
Filters the roles available for Wholesale Suite integration within the User Access Control plugin. Developers can use this hook to modify, add, or remove specific roles from the options list, controlling which user roles can be associated with Wholesale Suite features. This filter fires during the retrieval of Wholesale Suite role options.
Usage
add_filter( 'uap_option_get_all_wss_roles', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is not used by the `uap_option_get_all_wss_roles` filter hook.
Return Value
The filtered value.
Examples
// Example: Add a custom role to the list of Wholesale Suite roles that can be selected.
add_filter( 'uap_option_get_all_wss_roles', function( $option ) {
// Check if the 'options' key exists and is an array.
if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
// Add a new custom role. Replace 'My Custom Role Slug' and 'My Custom Role Label'
// with your actual custom role slug and display label.
$option['options']['my_custom_role_slug'] = 'My Custom Role Label';
}
return $option;
}, 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/wholesale-suite/helpers/wholesale-suite-helpers.php:52
public function get_all_wss_roles( $label = null, $option_code = 'CUSTOMER_ROLES', $is_any = false, $is_all = false, $custom_value = false ) {
if ( ! $label ) {
/* translators: WordPress role */
$label = esc_attr__( 'Role', 'uncanny-automator' );
}
$roles = array();
if ( true === $is_any ) {
$roles['-1'] = esc_attr__( 'Any role', 'uncanny-automator' );
}
if ( true === $is_all ) {
$roles['-1'] = esc_attr__( 'All roles', 'uncanny-automator' );
}
$wwp_wholesale_role = WWP_Wholesale_Roles::getInstance();
$wss_roles = $wwp_wholesale_role->getAllRegisteredWholesaleRoles();
foreach ( $wss_roles as $role_name => $role_info ) {
$roles[ $role_name ] = $role_info['roleName'];
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $roles,
'supports_custom_value' => $custom_value,
);
return apply_filters( 'uap_option_get_all_wss_roles', $option );
}