Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to hide user's fields from REST API #384

Open
djoo opened this issue Jul 15, 2021 · 2 comments
Open

Unable to hide user's fields from REST API #384

djoo opened this issue Jul 15, 2021 · 2 comments

Comments

@djoo
Copy link

djoo commented Jul 15, 2021

I want to hide ACF fields on my users.

For exemple on this https://domain.com/wp-json/acf/v3/users/279/

I did enabled the filter in functions.php :

add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );

The toggle Show in REST API? is visible in field settings but set to No by default. Despite that, all fields are still included in the API. Turning it on and back off does not remove them either.

Any idea ?

it's really important because it's confidential informations

@djoo djoo changed the title Unable to hide field from REST API Unable to hide user's fields from REST API Jul 15, 2021
@djoo
Copy link
Author

djoo commented Jul 15, 2021

Found a way, if it can help


add_filter( 'rest_endpoints', 'disable_custom_colivys_rest_endpoints' );
function disable_custom_colivys_rest_endpoints( $endpoints ) {
	

    $routes = array( 
        '/wp/v2/users', 
        '/wp/v2/users/(?P<id>[\d]+)',
        '/acf/v3/users',
        '/acf/v3/users/(?P<id>[\\d]+)/?(?P<field>[\\w\\-\\_]+)?',
     );

    foreach ( $routes as $route ) {
        if ( empty( $endpoints[ $route ] ) ) {
            continue;
        }

        foreach ( $endpoints[ $route ] as $i => $handlers ) {
            if ( is_array( $handlers ) && isset( $handlers['methods'] ) &&
                'GET' === $handlers['methods'] ) {
                unset( $endpoints[ $route ][ $i ] );
            }
        }
    }

	return $endpoints;
}

@brownsugar
Copy link

You can use Disable REST API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants