leoloso / block-metadata

WordPress plugin to extract all metadata from all Gutenberg blocks inside of a post
GNU General Public License v2.0
12 stars 3 forks source link

Incompatibility with WP 5.9 #6

Open tadekrzewuski-lc opened 3 days ago

tadekrzewuski-lc commented 3 days ago

After upgrading WP to 5.9 I get an error:

Notice: register_rest_route was called incorrectly. The REST API route definition for block-metadata/v1/data/(?P\d+) is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/web/wp/wp-includes/functions.php on line 5777

Notice: register_rest_route was called incorrectly. The REST API route definition for block-metadata/v1/metadata/(?P\d+) is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/web/wp/wp-includes/functions.php on line 5777

After WP 5.5 every register_rest_route is required to have a permission_callback.

Can we add it in RESTHooks.php? 🙏

class RESTHooks {

    /**
     * Register the REST hooks
     */
    public static function init() {
        /**
         * Define REST endpoints
         */
        \add_action('rest_api_init', function () {
            // Endpoint: /wp-json/block-metadata/v1/data/{POST_ID}
            \register_rest_route(RESTUtils::get_namespace(), 'data/(?P<post_id>\d+)', [
                'methods'    => 'GET',
                'callback' => [RESTEndpoints::class, 'get_post_blocks'],
                'permission_callback' => '__return_true'
            ]);
        });
        \add_action('rest_api_init', function () {
            // Endpoint: /wp-json/block-metadata/v1/metadata/{POST_ID}
            \register_rest_route(RESTUtils::get_namespace(), 'metadata/(?P<post_id>\d+)', [
                'methods'    => 'GET',
                'callback' => [RESTEndpoints::class, 'get_post_block_meta'],
                'permission_callback' => '__return_true'
            ]);
        });
    }
}

I can prepare a PR if needed.

leoloso commented 2 days ago

I'm not maintaining this project anymore, as Gato GraphQL has superseded it.

I can switch ownership of this repo to you...