/** * Register the routes for the objects of the controller. * * @since 0.2.0 */ public function register_routes() { $namespace = util::get_namespace(); register_rest_route($namespace, '/products', array('methods' => \WP_REST_Server::READABLE, 'callback' => array($this, 'get_items'), 'permission_callback' => array($this, 'get_items_permissions_check'), 'args' => array('plugin' => array('default' => 'edd', 'sanitize_callback' => array($this, 'strip_tags'))))); register_rest_route($namespace, '/products/price/(?P<id>[\\d]+)', array('methods' => \WP_REST_Server::READABLE, 'callback' => array($this, 'get_price'), 'permission_callback' => array($this, 'get_items_permissions_check'), 'args' => array('plugin' => array('default' => 'edd', 'sanitize_callback' => array($this, 'strip_tags'))))); register_rest_route($namespace, '/products/plugins', array('methods' => \WP_REST_Server::READABLE, 'callback' => array($this, 'get_plugins'), 'permission_callback' => array($this, 'get_items_permissions_check'), 'args' => array('context' => array('default' => 'select-options')))); }
/** * Load the REST API * * @uses "rest_api_init" */ public static function boot_rest_api() { if (!did_action('ingot_rest_api_booted')) { $group = new groups(); $group->register_routes(); $variant = new variant(); $variant->register_routes(); $settings = new \ingot\testing\api\rest\settings(); $settings->register_routes(); $products = new products(); $products->register_routes(); $session = new \ingot\testing\api\rest\session(); $session->register_routes(); /** * Runs after the Ingot REST API is booted up * * @since 0.2.0 * * @param string $namespace Namespace of API */ do_action('ingot_rest_api_booted', util::get_namespace()); } }
/** * Test that this route is registered properly * * @since 0.2.0 * * @group rest * @group settings_rest * @group group_rest * @group tracking_rest * @group session_rest * @group variant_rest */ public function test_register_route() { $routes = $this->server->get_routes(); $this->assertArrayHasKey('/' . \ingot\testing\api\rest\util::get_namespace() . '/' . $this->route_name, $routes, get_class($this)); $this->assertArrayHasKey($this->namespaced_route, $routes, get_class($this)); }
/** * Make namespace for routes * * @since 0.0.8 * * @access protected * * @return string */ protected function make_namespace() { return util::get_namespace(); }