mercredi 15 juin 2016

How and where to instantiate a custom class that extends the WP_REST_Controller

I have a plugin that I created and I want to use the WP rest api controller pattern in order to extend the api.

<?php
/**
* Plugin Name: ...
* Plugin URI: h...
* Description: A simple plugin ...
* Version: 0.1
* Author: Kamran ...
* Author ....
* License: GPL2

function myplugin_register_endpoints(){

   require_once 'server/controllers/my_ctrl.php';
   $items=new items();
   $items->register_routes();

}

add_action('rest_api_init','myplugin_register_endpoints'); . .

I created a class a folder called server/controllers and inside it my_ctrl.php file with a class that extends WP_REST_Controller that looks like this

// server/controllers/my_ctrl.php

class items extends WP_REST_Controller {

    /**
    * Register the routes for the objects of the controller.
    */
     public function register_routes() {
       .....
     }

}

However I am receiving the following error in sublime xdebuge call stack. I am not sure how to solve this issue?



via Chebli Mohamed

1 commentaire:

  1. Looking for woocommerce Rest API Integration for your online store? Hire our developers & programmers for your custom API and extensions. +91-9806724185 or Contact@expresstechsoftwares.com

    RépondreSupprimer