Init the API and add to status report
This commit is contained in:
parent
7a61883c30
commit
5b105d0c7f
|
@ -76,6 +76,21 @@ $untested_plugins = $plugin_updates->get_untested_plugins( WC()->version, 'min
|
|||
<td class="help"><?php echo wc_help_tip( esc_html__( 'The version of WooCommerce installed on your site.', 'woocommerce' ) ); /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?></td>
|
||||
<td><?php echo esc_html( $environment['version'] ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-export-label="REST API Version"><?php esc_html_e( 'WooCommerce REST API package', 'woocommerce' ); ?>:</td>
|
||||
<td class="help"><?php echo wc_help_tip( esc_html__( 'The WooCommerce REST API package running on your site.', 'woocommerce' ) ); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$version = wc()->api->get_rest_api_package_version();
|
||||
|
||||
if ( ! is_null( $version ) ) {
|
||||
echo '<mark class="yes"><span class="dashicons dashicons-yes"></span> ' . esc_html( $version ) . ' <code class="private">' . esc_html( wc()->api->get_rest_api_package_path() ) . '</code></mark> ';
|
||||
} else {
|
||||
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . esc_html__( 'Unable to detect the REST API package.', 'woocommerce' ) . '</mark>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-export-label="Log Directory Writable"><?php esc_html_e( 'Log directory writable', 'woocommerce' ); ?>:</td>
|
||||
<td class="help"><?php echo wc_help_tip( esc_html__( 'Several WooCommerce extensions can write logs which makes debugging problems easier. The directory must be writable for this to happen.', 'woocommerce' ) ); /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?></td>
|
||||
|
|
|
@ -19,32 +19,57 @@ defined( 'ABSPATH' ) || exit;
|
|||
class WC_API extends WC_Legacy_API {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 2.0
|
||||
* Init the API by setting up action and filter hooks.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->wc_api_init();
|
||||
$this->rest_api_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the WC API by adding endpoints for those requests.
|
||||
*/
|
||||
private function wc_api_init() {
|
||||
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
|
||||
public function init() {
|
||||
parent::init();
|
||||
add_action( 'init', array( $this, 'add_endpoint' ), 0 );
|
||||
add_action( 'init', array( $this, 'rest_api_init' ) );
|
||||
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
|
||||
add_action( 'parse_request', array( $this, 'handle_api_requests' ), 0 );
|
||||
add_action( 'rest_api_init', array( $this, 'register_wp_admin_settings' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init WP REST API by hooking into `rest_api_init`.
|
||||
* Call the Server class from the Rest API package.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @see \Automattic\WooCommerce\RestApi\Server
|
||||
*/
|
||||
private function rest_api_init() {
|
||||
add_action( 'rest_api_init', array( $this, 'rest_api_includes' ), 5 );
|
||||
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 );
|
||||
public function rest_api_init() {
|
||||
if ( $this->is_rest_api_loaded() || version_compare( PHP_VERSION, '5.6.0', '<' ) ) {
|
||||
return;
|
||||
}
|
||||
\Automattic\WooCommerce\RestApi\Server::instance()->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the REST API package being ran.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_rest_api_package_version() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the REST API package being ran.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_rest_api_package_path() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the rest API classes were already loaded.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @return boolean
|
||||
*/
|
||||
protected function is_rest_api_loaded() {
|
||||
return class_exists( '\Automattic\WooCommerce\RestApi\Server', false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,24 +138,6 @@ class WC_API extends WC_Legacy_API {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Include REST API classes.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function rest_api_includes() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function register_rest_routes() {
|
||||
// Register settings to the REST API.
|
||||
$this->register_wp_admin_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register WC settings from WP-API to the REST API.
|
||||
*
|
||||
|
|
|
@ -270,4 +270,21 @@ class WC_Legacy_API {
|
|||
// Fire off the request.
|
||||
$this->server->serve_request();
|
||||
}
|
||||
|
||||
/**
|
||||
* Include REST API classes.
|
||||
*
|
||||
* @deprecated since 3.7.0 - REST API clases autoload.
|
||||
*/
|
||||
public function rest_api_includes() {
|
||||
$this->rest_api_init();
|
||||
}
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*
|
||||
* @deprecated since 3.7.0 - Not used.
|
||||
*/
|
||||
public function register_rest_routes() {
|
||||
$this->register_wp_admin_settings();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue