Home » Resolved : “register_rest_route was called incorrectly”

Resolved : “register_rest_route was called incorrectly”

PHP Notice: register_rest_route was called incorrectly. The REST API route definition for relevanssi/v1/search 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.

PHP error after WordPress 5.5 update

My wordpress custom api plugin : “register_rest_route was called incorrectly.” error on WordPress 5.5 RC2 & namespace must not start or end with a slash.

I’m getting the following error in the wp-admin area after updating to WordPress 5.5 (note: I have wp_debug turned ON): register route in wordpress.

Notice: register_rest_route was called incorrectly. The REST API route definition for mc4wp/v1/form 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 /public_html/wp-includes/functions.php on line 5225

Notice : register_rest_route was called incorrectly . The REST API route definition for test/productsis missing a permission_callbackrequired argument . For REST API routes that are public, use __return_trueas the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

Notice : register_rest_route was called incorrectly . The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read howtest/products/(?P[\d]+)permission_callback__return_trueDebug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

Read Also:  Laravel Auth Middleware Example Tutorial From Scratch

Notice : register_rest_route was called incorrectly . The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225 Notice : register_rest_route was called incorrectlytest/products/(?P[\d]+)/variationspermission_callback__return_true

rest_api_init not working
. The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225 Notice : register_rest_route was called incorrectly . The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPresstest/products/(?P[\d]+)/variations/(?P[\d]+)permission_callback__return_true

test/products/categoriespermission_callback__return_truefor more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

Notice : register_rest_route was called incorrectly . The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225 Notice : register_rest_route was called incorrectlytest/products/categories/(?P[\d]+)permission_callback__return_true

Read Also:  Create Custom helper Functions in Laravel

. The REST API route definition for test/products/tagsis missing a permission_callbackrequired argument . For REST API routes that are public, use __return_trueas the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

Notice : register_rest_route was called incorrectly . The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPresstest/products/tags/(?P[\d]+)permission_callback__return_truefor more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

Notice : register_rest_route was called incorrectly . The REST API route definition for test/products/reviewsis missing a permission_callbackrequired argument . For REST API routes that are public, use __return_trueas the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

Notice : register_rest_route was called incorrectly. The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPress for more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225 Notice : register_rest_route was called incorrectly . The REST API route definition for is missing a required argument . For REST API routes that are public, use as the permission callback. Read how to debug WordPresstest/products/reviews/(?P[\d]+)permission_callback__return_true

Read Also:  How to write SQL Sub Query in PHP with MySQLi

public-woo/v1/settingspermission_callback__return_truefor more information. (This message was added in version 5.5.0.) In /Users/test/www/wordpress/wp-includes/functions.php on line 5225

REST API ERRORS

I just updated the Gist to add the permission_callback.

'permission_callback' => '__return_true',

Also Read: FIX 500 internal server error

rest-api-endpoint.php
here simple example for register_rest_route post method.

<?php 
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


class WP_YOUR_CLASS_NAME_Rest_Controller extends WP_REST_Controller {
 
    public function callHooks(){
      add_action( 'rest_api_init', array($this,'registerApiEndpoints') );
    }
    
    function registerApiEndpoints() {
        register_rest_route( 'public-woo/v3', '/settings', array(
            'methods' => 'POST',
            'callback' => array($this,'resetApiAllOptions'),
			'permission_callback' => '__return_true', //I just updated the Gist to add the permission_callback.
        ) );
      
    }
    
    public function resetApiAllOptions(){
            global $wpdb;
           
          $resultsData = array(
            "error"   => 0,
            "message" => "Sorry, you are not allowed to edit this resource.",
            "code" => "woocommerce_rest_cannot_edit"
          );
         return json_encode($resultsData);	
    }
}

How to Fix Common WooCommerce REST API Issues?

woocommerce_rest_cannot_view, Sorry, you cannot list resources, 401 or “error_message”: “Sorry, you cannot list resources.” using WooCommerce API

{
  "code": "woocommerce_rest_cannot_view",
  "message": "Sorry, you cannot list resources.",
  "data": {
    "status": 401
  }
}

In register_rest_route authentication, Please review the documentation here: woocommerce rest api docs


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  registration and signin form in php and mysql with validation
  2. Read Also:  Laravel 6 Define Table Names in Model
  3. Read Also:  Ajax Live Data Search using Jquery PHP MySql
  4. Read Also:  MySQL WHERE Clause with AND, OR, IN, NOT IN
  5. Read Also:  how to install PHP Accelerator in Xampp
  6. Read Also:  Laravel 6 Ajax post data Example
  7. Read Also:  Convert and Loop through JSON with PHP and JavaScript Arrays/Objects | json to array php
  8. Read Also:  registration and signin form in php and mysql with validation
  9. Read Also:  Laravel 6 Define Table Names in Model
  10. Read Also:  Ajax Live Data Search using Jquery PHP MySql

Leave a Comment

Your email address will not be published. Required fields are marked *