Snippet Category Security Enhancements

Disable REST API for Non-Admins

add_filter('rest_authentication_errors', function($result) {
    if (!empty($result)) {
        return $result;
    }
    if (!is_user_logged_in()) {
        return new WP_Error('rest_not_logged_in', 'API is not available for anonymous users.', array('status' => 401));
    }
    return $result;
});

Prevent User Enumeration

if (!is_admin()) {
    // block WP enum scans
    if (preg_match('/(wp-comments-post)/', $_SERVER['REQUEST_URI']) === 0 && !empty($_REQUEST['author'])) {
        wp_redirect(home_url());
        exit;
    }
}

Disable XML-RPC Pingback

add_filter( 'xmlrpc_methods', function( $methods ) {
   unset( $methods['pingback.ping'] );
   return $methods;
});