1 | <?php |
||
19 | class WC_API extends WC_Legacy_API { |
||
20 | |||
21 | /** |
||
22 | * Init the API by setting up action and filter hooks. |
||
23 | */ |
||
24 | public function init() { |
||
25 | parent::init(); |
||
26 | add_action( 'init', array( $this, 'add_endpoint' ), 0 ); |
||
27 | add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 ); |
||
28 | add_action( 'parse_request', array( $this, 'handle_api_requests' ), 0 ); |
||
29 | add_action( 'rest_api_init', array( $this, 'register_wp_admin_settings' ) ); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Get the version of the REST API package being ran. |
||
34 | * |
||
35 | * @since 3.7.0 |
||
36 | * @return string|null |
||
37 | */ |
||
38 | 1 | public function get_rest_api_package_version() { |
|
39 | 1 | if ( ! $this->is_rest_api_loaded() ) { |
|
40 | return null; |
||
41 | } |
||
42 | 1 | return \Automattic\WooCommerce\RestApi\Package::get_version(); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Get the version of the REST API package being ran. |
||
47 | * |
||
48 | * @since 3.7.0 |
||
49 | * @return string |
||
50 | */ |
||
51 | 1 | public function get_rest_api_package_path() { |
|
52 | 1 | if ( ! $this->is_rest_api_loaded() ) { |
|
53 | return null; |
||
54 | } |
||
55 | 1 | return \Automattic\WooCommerce\RestApi\Package::get_path(); |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Return if the rest API classes were already loaded. |
||
60 | * |
||
61 | * @since 3.7.0 |
||
62 | * @return boolean |
||
63 | */ |
||
64 | 2 | protected function is_rest_api_loaded() { |
|
67 | |||
68 | /** |
||
69 | * Get data from a WooCommerce API endpoint. |
||
70 | * |
||
71 | * @since 3.7.0 |
||
72 | * @param string $endpoint Endpoint. |
||
73 | * @param array $params Params to passwith request. |
||
74 | * @return array|\WP_Error |
||
75 | */ |
||
76 | 1 | public function get_endpoint_data( $endpoint, $params = array() ) { |
|
89 | |||
90 | /** |
||
91 | * Add new query vars. |
||
92 | * |
||
93 | * @since 2.0 |
||
94 | * @param array $vars Query vars. |
||
95 | * @return string[] |
||
96 | */ |
||
97 | public function add_query_vars( $vars ) { |
||
102 | |||
103 | /** |
||
104 | * WC API for payment gateway IPNs, etc. |
||
105 | * |
||
106 | * @since 2.0 |
||
107 | */ |
||
108 | 2 | public static function add_endpoint() { |
|
112 | |||
113 | /** |
||
114 | * API request - Trigger any API requests. |
||
115 | * |
||
116 | * @since 2.0 |
||
117 | * @version 2.4 |
||
118 | */ |
||
119 | public function handle_api_requests() { |
||
155 | |||
156 | /** |
||
157 | * Register WC settings from WP-API to the REST API. |
||
158 | * |
||
159 | * @since 3.0.0 |
||
160 | */ |
||
161 | 1 | public function register_wp_admin_settings() { |
|
172 | } |
||
173 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.