• I improved the code that remove endpoints because wasn’t removing the various sub rest api.
    This is the code modified that I am using:

        public function remove_endpoints( $endpoints ) {
            $endpoints_to_remove = array(
                'media',
                'types',
                'statuses',
                'taxonomies',
                'tags',
                'users',
                'comments',
                'settings',
                'themes',
                'blocks',
                'oembed',
                'posts',
                'pages',
                'block-renderer',
                'search',
                'categories'
            );
    
            foreach ( $endpoints_to_remove as $endpoint ) {
                $base_endpoint = "/wp/v2/{$endpoint}";
                foreach ( $endpoints as $maybe_endpoint => $object ) {
                    if ( strpos( $maybe_endpoint, $base_endpoint ) !== false ) {
                        unset( $endpoints[ $maybe_endpoint ] );
                    }
                }       
            }
    
            return $endpoints;
        }
    
    

    In that way all the foreach are not required because search by the name and it is more fast.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Better code to remove endpoints’ is closed to new replies.