-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-rest-api-wordpress.php
More file actions
114 lines (90 loc) · 3.52 KB
/
class-rest-api-wordpress.php
File metadata and controls
114 lines (90 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Plugin Name: REST API WP/Woo
* Plugin URI: #
* Description:
* Version: 0.0.5
* Author: Andrei Leca
* Author URI:
* Text Domain: WordPress
* License: MIT
*/
namespace Hmd\Rest_Api_WordPress;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Rest_Api_Wordpress' ) ) :
class Rest_Api_WordPress {
private static $instance;
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Rest_Api_WordPress ) ) {
self::$instance = new Rest_Api_WordPress;
self::$instance->constants();
self::$instance->includes();
}
return self::$instance;
}
/**
* Constants
*/
public function constants() {
$upload = wp_get_upload_dir();
// Plugin version
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_VERSION' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_VERSION', '0.0.5' );
}
// Plugin file
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_FILE' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_FILE', __FILE__ );
}
// Plugin basename
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_BASENAME' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_BASENAME', plugin_basename( REST_API_WORDPRESS_PLUGIN_FILE ) );
}
// Plugin directory path
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_DIR_PATH' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_DIR_PATH', trailingslashit( plugin_dir_path( REST_API_WORDPRESS_PLUGIN_FILE ) ) );
}
// Plugin directory classes
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_CLASSES' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_CLASSES', trailingslashit( REST_API_WORDPRESS_PLUGIN_DIR_PATH . 'classes' ) );
}
// Plugin directory URL
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_DIR_URL' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_DIR_URL', trailingslashit( plugin_dir_url( REST_API_WORDPRESS_PLUGIN_FILE ) ) );
}
// Upload folder for contents
if ( ! defined( 'WPR_REST_API_WORDPRESS_PLUGIN_UPLOAD_DIR_PATH' ) ) {
define( 'WPR_REST_API_WORDPRESS_PLUGIN_UPLOAD_DIR_PATH', trailingslashit( $upload['basedir'] . '/rest_api_imgs' ) );
}
// Upload folder url for contents
if ( ! defined( 'WPR_REST_API_WORDPRESS_PLUGIN_UPLOAD_DIR_URL' ) ) {
define( 'WPR_REST_API_WORDPRESS_PLUGIN_UPLOAD_DIR_URL', trailingslashit( $upload['baseurl'] . '/rest_api_imgs' ) );
}
// Plugin token registration new user routes
// NOTE: PLEASE CHANGE THIS TOKEN 'MySuperSecretToken'
if ( ! defined( 'REST_API_WORDPRESS_PLUGIN_TOKEN' ) ) {
define( 'REST_API_WORDPRESS_PLUGIN_TOKEN', 'MySuperSecretToken' );
}
}
/**
* It includes the files that are required for the plugin to work.
*/
public function includes() {
if ( file_exists( REST_API_WORDPRESS_PLUGIN_DIR_PATH . 'vendor/autoload.php' ) ) {
require_once( REST_API_WORDPRESS_PLUGIN_DIR_PATH . 'vendor/autoload.php' );
}
require_once( REST_API_WORDPRESS_PLUGIN_DIR_PATH . 'inc/class-update-cart.php' );
require_once( REST_API_WORDPRESS_PLUGIN_CLASSES . 'woocommerce/class-rest-api-woocommerce.php' );
require_once( REST_API_WORDPRESS_PLUGIN_CLASSES . 'woocommerce/class-wpr-wc-api-order.php' );
require_once( REST_API_WORDPRESS_PLUGIN_CLASSES . 'wordpress/class-rest-api-wordpresswp.php' );
require_once( REST_API_WORDPRESS_PLUGIN_CLASSES . 'auth/class-user-role-api.php' );
\User_Role_Api::instance();
\Rest_Api_WooCommerce::instance();
\Rest_Api_WordpressWP::instance();
\WPR_WC_API_Order::instance();
}
}
endif;
add_action( 'plugins_loaded', array( Rest_Api_WordPress::class, 'instance' ), 100 );