Merge pull request #23981 from woocommerce/update/init-blocks-package
Init the blocks package
This commit is contained in:
commit
da766789f6
|
@ -9,7 +9,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"composer/installers": "1.6.0",
|
"composer/installers": "1.6.0",
|
||||||
"woocommerce/woocommerce-rest-api": "dev-test/jetpack-autoloader",
|
"woocommerce/woocommerce-rest-api": "dev-test/jetpack-autoloader",
|
||||||
"woocommerce/woocommerce-blocks": "dev-add/build-config",
|
"woocommerce/woocommerce-blocks": "dev-build/2.2.0-dev",
|
||||||
"automattic/jetpack-autoloader": "^1"
|
"automattic/jetpack-autoloader": "^1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "b26e3ab11a27accf12e540dc6cb540a4",
|
"content-hash": "bd3583eea7bbf9c0401e52371ae1baf9",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "automattic/jetpack-autoloader",
|
"name": "automattic/jetpack-autoloader",
|
||||||
|
@ -164,19 +164,20 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "woocommerce/woocommerce-blocks",
|
"name": "woocommerce/woocommerce-blocks",
|
||||||
"version": "dev-add/build-config",
|
"version": "dev-build/2.2.0-dev",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/woocommerce/woocommerce-gutenberg-products-block.git",
|
"url": "https://github.com/woocommerce/woocommerce-gutenberg-products-block.git",
|
||||||
"reference": "be2a243d0e999af6f4318f7b242cdac2565d36d8"
|
"reference": "64fdbe613ee66d5444696428567f3b683b1a2b06"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/woocommerce/woocommerce-gutenberg-products-block/zipball/be2a243d0e999af6f4318f7b242cdac2565d36d8",
|
"url": "https://api.github.com/repos/woocommerce/woocommerce-gutenberg-products-block/zipball/64fdbe613ee66d5444696428567f3b683b1a2b06",
|
||||||
"reference": "be2a243d0e999af6f4318f7b242cdac2565d36d8",
|
"reference": "64fdbe613ee66d5444696428567f3b683b1a2b06",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
"automattic/jetpack-autoloader": "^1",
|
||||||
"composer/installers": "1.6.0"
|
"composer/installers": "1.6.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
@ -184,9 +185,15 @@
|
||||||
"woocommerce/woocommerce-sniffs": "0.0.6"
|
"woocommerce/woocommerce-sniffs": "0.0.6"
|
||||||
},
|
},
|
||||||
"type": "wordpress-plugin",
|
"type": "wordpress-plugin",
|
||||||
|
"extra": {
|
||||||
|
"scripts-description": {
|
||||||
|
"phpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer",
|
||||||
|
"phpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier"
|
||||||
|
}
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"WooCommerce\\Blocks\\": "src/"
|
"Automattic\\WooCommerce\\Blocks\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
@ -195,7 +202,7 @@
|
||||||
],
|
],
|
||||||
"description": "Feature plugin for the WooCommerce Gutenberg Products block",
|
"description": "Feature plugin for the WooCommerce Gutenberg Products block",
|
||||||
"homepage": "https://woocommerce.com/",
|
"homepage": "https://woocommerce.com/",
|
||||||
"time": "2019-06-20T14:53:51+00:00"
|
"time": "2019-06-21T18:08:00+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "woocommerce/woocommerce-rest-api",
|
"name": "woocommerce/woocommerce-rest-api",
|
||||||
|
@ -203,12 +210,12 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/woocommerce/woocommerce-rest-api.git",
|
"url": "https://github.com/woocommerce/woocommerce-rest-api.git",
|
||||||
"reference": "46453550e8d7468f6a1f46b47fefd2fdc482c801"
|
"reference": "2943708bb12f70b845f32e5f26893436a926a1ee"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/woocommerce/woocommerce-rest-api/zipball/46453550e8d7468f6a1f46b47fefd2fdc482c801",
|
"url": "https://api.github.com/repos/woocommerce/woocommerce-rest-api/zipball/2943708bb12f70b845f32e5f26893436a926a1ee",
|
||||||
"reference": "46453550e8d7468f6a1f46b47fefd2fdc482c801",
|
"reference": "2943708bb12f70b845f32e5f26893436a926a1ee",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -236,7 +243,7 @@
|
||||||
],
|
],
|
||||||
"description": "The WooCommerce core REST API.",
|
"description": "The WooCommerce core REST API.",
|
||||||
"homepage": "https://github.com/woocommerce/woocommerce-rest-api",
|
"homepage": "https://github.com/woocommerce/woocommerce-rest-api",
|
||||||
"time": "2019-06-21T09:40:39+00:00"
|
"time": "2019-06-21T13:57:26+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* WooCommerce API class loader.
|
* WC-API endpoint handler.
|
||||||
*
|
*
|
||||||
* This handles APIs in WooCommerce. These include:
|
* This handles API related functionality in WooCommerce.
|
||||||
* - wc-api endpoint - Commonly used by Payment gateways for callbacks.
|
* - wc-api endpoint - Commonly used by Payment gateways for callbacks.
|
||||||
* - Legacy REST API - Deprecated in 2.6.0. @see class-wc-legacy-api.php
|
* - Legacy REST API - Deprecated in 2.6.0. @see class-wc-legacy-api.php
|
||||||
* - WP REST API - The main REST API in WooCommerce which is built on top of the WP REST API.
|
* - WP REST API - The main REST API in WooCommerce which is built on top of the WP REST API.
|
||||||
|
@ -24,33 +24,23 @@ class WC_API extends WC_Legacy_API {
|
||||||
public function init() {
|
public function init() {
|
||||||
parent::init();
|
parent::init();
|
||||||
add_action( 'init', array( $this, 'add_endpoint' ), 0 );
|
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_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
|
||||||
add_action( 'parse_request', array( $this, 'handle_api_requests' ), 0 );
|
add_action( 'parse_request', array( $this, 'handle_api_requests' ), 0 );
|
||||||
add_action( 'rest_api_init', array( $this, 'register_wp_admin_settings' ) );
|
add_action( 'rest_api_init', array( $this, 'register_wp_admin_settings' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Call the Server class from the Rest API package.
|
|
||||||
*
|
|
||||||
* @see \Automattic\WooCommerce\RestApi\Server
|
|
||||||
*/
|
|
||||||
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.
|
* Get the version of the REST API package being ran.
|
||||||
*
|
*
|
||||||
* @since 3.7.0
|
* @since 3.7.0
|
||||||
* @return int|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function get_rest_api_package_version() {
|
public function get_rest_api_package_version() {
|
||||||
|
if ( ! $this->is_rest_api_loaded() ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return \Automattic\WooCommerce\RestApi\Package::get_version();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of the REST API package being ran.
|
* Get the version of the REST API package being ran.
|
||||||
|
@ -59,7 +49,10 @@ class WC_API extends WC_Legacy_API {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_rest_api_package_path() {
|
public function get_rest_api_package_path() {
|
||||||
return '';
|
if ( ! $this->is_rest_api_loaded() ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return \Automattic\WooCommerce\RestApi\Package::get_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +62,7 @@ class WC_API extends WC_Legacy_API {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function is_rest_api_loaded() {
|
protected function is_rest_api_loaded() {
|
||||||
return class_exists( '\Automattic\WooCommerce\RestApi\Server', false );
|
return class_exists( '\Automattic\WooCommerce\RestApi\Package', false );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +75,7 @@ class WC_API extends WC_Legacy_API {
|
||||||
*/
|
*/
|
||||||
public function get_endpoint_data( $endpoint, $params = array() ) {
|
public function get_endpoint_data( $endpoint, $params = array() ) {
|
||||||
if ( ! $this->is_rest_api_loaded() ) {
|
if ( ! $this->is_rest_api_loaded() ) {
|
||||||
$this->rest_api_init();
|
return new WP_Error( 'rest_api_unavailable', __( 'The Rest API is unavailable.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
$request = new \WP_REST_Request( 'GET', $endpoint );
|
$request = new \WP_REST_Request( 'GET', $endpoint );
|
||||||
if ( $params ) {
|
if ( $params ) {
|
||||||
|
|
|
@ -180,6 +180,7 @@ final class WooCommerce {
|
||||||
register_shutdown_function( array( $this, 'log_errors' ) );
|
register_shutdown_function( array( $this, 'log_errors' ) );
|
||||||
|
|
||||||
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), -1 );
|
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), -1 );
|
||||||
|
add_action( 'plugins_loaded', array( $this, 'init_packages' ) );
|
||||||
add_action( 'after_setup_theme', array( $this, 'setup_environment' ) );
|
add_action( 'after_setup_theme', array( $this, 'setup_environment' ) );
|
||||||
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
|
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
|
||||||
add_action( 'init', array( $this, 'init' ), 0 );
|
add_action( 'init', array( $this, 'init' ), 0 );
|
||||||
|
@ -191,6 +192,21 @@ final class WooCommerce {
|
||||||
add_action( 'deactivated_plugin', array( $this, 'deactivated_plugin' ) );
|
add_action( 'deactivated_plugin', array( $this, 'deactivated_plugin' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load any WooCommerce packages.
|
||||||
|
*
|
||||||
|
* Most packages will have their own init routines, so this is used early once plugins are loaded.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*/
|
||||||
|
public function init_packages() {
|
||||||
|
if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
\Automattic\WooCommerce\Blocks\Package::init();
|
||||||
|
\Automattic\WooCommerce\RestApi\Package::init();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures fatal errors are logged so they can be picked up in the status report.
|
* Ensures fatal errors are logged so they can be picked up in the status report.
|
||||||
*
|
*
|
||||||
|
|
|
@ -271,6 +271,13 @@ class WC_Legacy_API {
|
||||||
$this->server->serve_request();
|
$this->server->serve_request();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rest API Init.
|
||||||
|
*
|
||||||
|
* @deprecated since 3.7.0 - REST API clases autoload.
|
||||||
|
*/
|
||||||
|
public function rest_api_init() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include REST API classes.
|
* Include REST API classes.
|
||||||
*
|
*
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
"license": "GPL-3.0+",
|
"license": "GPL-3.0+",
|
||||||
"main": "Gruntfile.js",
|
"main": "Gruntfile.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "npm install && composer install --no-dev",
|
|
||||||
"build": "grunt",
|
"build": "grunt",
|
||||||
"build-watch": "grunt watch",
|
"build-watch": "grunt watch",
|
||||||
"lint:js": "eslint assets/js --ext=js",
|
"lint:js": "eslint assets/js --ext=js",
|
||||||
|
|
Loading…
Reference in New Issue