Skip to content

Commit

Permalink
Added composer.json and REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq1988 committed Oct 30, 2019
1 parent 62fc9ed commit 247f546
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 22 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# Matches multiple files with brace expansion notation
# Set default charset
Expand Down
1 change: 1 addition & 0 deletions assets/js/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/frontend.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/style.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions assets/js/vendors.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions assets/js/vendors.js.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!
* Vue.js v2.6.10
* (c) 2014-2019 Evan You
* Released under the MIT License.
*/

/*!
* vue-router v3.1.3
* (c) 2019 Evan You
* @license MIT
*/
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "tareq1988/vue-wp-starter",
"description": "A WordPress Vue.js starter plugin",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Tareq Hasan",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4": {
"App\\": "includes/"
}
}
}
File renamed without changes.
40 changes: 40 additions & 0 deletions includes/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace App;

use WP_REST_Controller;

/**
* REST_API Handler
*/
class Api extends WP_REST_Controller {

/**
* [__construct description]
*/
public function __construct() {
$this->includes();

add_action( 'rest_api_init', [ $this, 'register_routes' ] );
}

/**
* Include the controller classes
*
* @return void
*/
private function includes() {
if ( !class_exists( __NAMESPACE__ . '\Api\Example' ) ) {
require_once __DIR__ . '/Api/Example.php';
}
}

/**
* Register the API routes
*
* @return void
*/
public function register_routes() {
(new Api\Example())->register_routes();
}

}
75 changes: 75 additions & 0 deletions includes/Api/Example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
namespace App\Api;

use WP_REST_Controller;

/**
* REST_API Handler
*/
class Example extends WP_REST_Controller {

/**
* [__construct description]
*/
public function __construct() {
$this->namespace = 'myapp/v1';
$this->rest_base = 'test';
}

/**
* Register the routes
*
* @return void
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
)
)
);
}

/**
* Retrieves a collection of items.
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
$items = [
'foo' => 'bar'
];

$response = rest_ensure_response( $items );

return $response;
}

/**
* Checks if a given request has access to read the items.
*
* @param WP_REST_Request $request Full details about the request.
*
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
*/
public function get_items_permissions_check( $request ) {
return true;
}

/**
* Retrieves the query params for the items collection.
*
* @return array Collection parameters.
*/
public function get_collection_params() {
return [];
}
}
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions includes/class-rest-api.php

This file was deleted.

15 changes: 5 additions & 10 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,21 @@ public function deactivate() {
*/
public function includes() {

require_once BASEPLUGIN_INCLUDES . '/class-assets.php';
require_once BASEPLUGIN_INCLUDES . '/Assets.php';

if ( $this->is_request( 'admin' ) ) {
require_once BASEPLUGIN_INCLUDES . '/class-admin.php';
require_once BASEPLUGIN_INCLUDES . '/Admin.php';
}

if ( $this->is_request( 'frontend' ) ) {
require_once BASEPLUGIN_INCLUDES . '/class-frontend.php';
require_once BASEPLUGIN_INCLUDES . '/Frontend.php';
}

if ( $this->is_request( 'ajax' ) ) {
// require_once BASEPLUGIN_INCLUDES . '/class-ajax.php';
}

if ( $this->is_request( 'rest' ) ) {
require_once BASEPLUGIN_INCLUDES . '/class-rest-api.php';
}
require_once BASEPLUGIN_INCLUDES . '/Api.php';
}

/**
Expand Down Expand Up @@ -227,10 +225,7 @@ public function init_classes() {
// $this->container['ajax'] = new App\Ajax();
}

if ( $this->is_request( 'rest' ) ) {
$this->container['rest'] = new App\REST_API();
}

$this->container['api'] = new App\Api();
$this->container['assets'] = new App\Assets();
}

Expand Down

0 comments on commit 247f546

Please sign in to comment.