ulgm_rest_api_allow_display_name_update
Filters whether the display name can be updated via the REST API.
add_filter( 'ulgm_rest_api_allow_display_name_update', $callback, 10, 1 );
Description
This filter allows developers to control whether display name updates are permitted via the REST API. By default, it returns `false`, preventing display name changes. Return `true` to enable display name updates, but note that this relies on the `ulgm_rest_api_display_name_order` filter for determining the actual display name composition.
Usage
add_filter( 'ulgm_rest_api_allow_display_name_update', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Allow display name updates via the REST API.
*
* By default, this filter returns false, preventing display name updates.
* Returning true will enable this functionality.
*
* @param bool $allow_update Whether to allow display name updates.
* @return bool True to allow updates, false otherwise.
*/
add_filter( 'ulgm_rest_api_allow_display_name_update', function( $allow_update ) {
// This example enables display name updates if the user has the 'edit_users' capability.
// You can replace this with your own custom logic, for example, checking user roles,
// specific user IDs, or custom meta data.
if ( current_user_can( 'edit_users' ) ) {
return true;
}
return $allow_update; // Return the default value if the condition isn't met.
}, 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/classes/helpers/rest-api-end-points.php:2025
);
// make sure email value is provided.
if ( ! empty( $email ) ) {
$args['user_email'] = $email;
}
if ( true === apply_filters( 'ulgm_rest_api_allow_display_name_update', false ) ) {
$display_name_order = apply_filters(
'ulgm_rest_api_display_name_order',
array( $first_name, $last_name ),
$first_name,
$last_name
);