Update with latest changes from block-library
This commit is contained in:
parent
bf4d1d815d
commit
fdefe5feac
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
* NOTE: DO NOT edit this file in WooCommerce core, this is generated from woocommerce-gutenberg-products-block.
|
||||
*
|
||||
* @package WooCommerce\Blocks
|
||||
* @version 3.6.0
|
||||
* @version 1.3.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* NOTE: DO NOT edit this file in WooCommerce core, this is generated from woocommerce-gutenberg-products-block.
|
||||
*
|
||||
* @package WooCommerce\Blocks
|
||||
* @version 3.6.0
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -16,6 +16,35 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
*/
|
||||
class WC_Block_Library {
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
*
|
||||
* @var WC_Block_Library instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Get class instance
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( function_exists( 'register_block_type' ) ) {
|
||||
add_action( 'init', array( 'WC_Block_Library', 'register_blocks' ) );
|
||||
add_action( 'init', array( 'WC_Block_Library', 'register_assets' ) );
|
||||
add_filter( 'block_categories', array( 'WC_Block_Library', 'add_block_category' ) );
|
||||
add_action( 'admin_print_footer_scripts', array( 'WC_Block_Library', 'print_script_settings' ), 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file modified time as a cache buster if we're in dev mode.
|
||||
*
|
||||
|
@ -33,12 +62,12 @@ class WC_Block_Library {
|
|||
/**
|
||||
* Registers a script according to `wp_register_script`, additionally loading the translations for the file.
|
||||
*
|
||||
* @since 3.6.0
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $handle Name of the script. Should be unique.
|
||||
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
|
||||
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
|
||||
* @param bool $has_i18n Optional. Whether to add a script translation call to this file. Default 'false'.
|
||||
* @param bool $has_i18n Optional. Whether to add a script translation call to this file. Default 'true'.
|
||||
*/
|
||||
protected static function register_script( $handle, $src, $deps = array(), $has_i18n = true ) {
|
||||
$filename = str_replace( plugins_url( '/', WC_PLUGIN_FILE ), '', $src );
|
||||
|
@ -52,7 +81,7 @@ class WC_Block_Library {
|
|||
/**
|
||||
* Registers a style according to `wp_register_style`.
|
||||
*
|
||||
* @since 4.1.0
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $handle Name of the stylesheet. Should be unique.
|
||||
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
||||
|
@ -68,6 +97,8 @@ class WC_Block_Library {
|
|||
|
||||
/**
|
||||
* Register block scripts & styles.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static function register_assets() {
|
||||
self::register_style( 'wc-block-editor', WC()->plugin_url() . '/assets/css/blocks/editor.css', array( 'wp-edit-blocks' ) );
|
||||
|
@ -102,6 +133,8 @@ class WC_Block_Library {
|
|||
|
||||
/**
|
||||
* Register blocks, hooking up assets and render functions as needed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static function register_blocks() {
|
||||
require_once dirname( __FILE__ ) . '/class-wc-block-featured-product.php';
|
||||
|
@ -176,6 +209,8 @@ class WC_Block_Library {
|
|||
/**
|
||||
* Adds a WooCommerce category to the block inserter.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $categories Array of categories.
|
||||
* @return array Array of block categories.
|
||||
*/
|
||||
|
@ -193,7 +228,12 @@ class WC_Block_Library {
|
|||
}
|
||||
|
||||
/**
|
||||
* Output the wcSettings global before printing any script tags.
|
||||
* Output useful globals before printing any script tags.
|
||||
*
|
||||
* These are used by @woocommerce/components & the block library to set up defaults
|
||||
* based on user-controlled settings from WordPress.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static function print_script_settings() {
|
||||
global $wp_locale;
|
||||
|
@ -223,6 +263,8 @@ class WC_Block_Library {
|
|||
'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
|
||||
),
|
||||
);
|
||||
// NOTE: wcSettings is not used directly, it's only for @woocommerce/components.
|
||||
$settings = apply_filters( 'woocommerce_components_settings', $settings );
|
||||
|
||||
// Global settings used in each block.
|
||||
$block_settings = array(
|
||||
|
@ -238,17 +280,11 @@ class WC_Block_Library {
|
|||
);
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php // Use the wcSettings from wc-admin if already present. ?>
|
||||
var wcSettings = wcSettings || <?php echo wp_json_encode( $settings ); ?>;
|
||||
var wc_product_block_data = <?php echo wp_json_encode( $block_settings ); ?>;
|
||||
var wcSettings = wcSettings || JSON.parse( decodeURIComponent( '<?php echo rawurlencode( wp_json_encode( $settings ) ); ?>' ) );
|
||||
var wc_product_block_data = JSON.parse( decodeURIComponent( '<?php echo rawurlencode( wp_json_encode( $block_settings ) ); ?>' ) );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( function_exists( 'register_block_type' ) ) {
|
||||
add_action( 'init', array( 'WC_Block_Library', 'register_blocks' ) );
|
||||
add_action( 'init', array( 'WC_Block_Library', 'register_assets' ) );
|
||||
add_filter( 'block_categories', array( 'WC_Block_Library', 'add_block_category' ) );
|
||||
add_action( 'admin_print_footer_scripts', array( 'WC_Block_Library', 'print_script_settings' ), 1 );
|
||||
}
|
||||
WC_Block_Library::get_instance();
|
||||
|
|
Loading…
Reference in New Issue