File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/Interactivity.tar
class-wc-interactivity-store.php 0000644 00000002022 15154715352 0013023 0 ustar 00 <?php
/**
* Manages the initial state of the Interactivity API store in the server and
* its serialization so it can be restored in the browser upon hydration.
*
* It's a private class, exposed by other functions, like `wc_store`.
*
* @access private
*/
class WC_Interactivity_Store {
/**
* Store.
*
* @var array
*/
private static $store = array();
/**
* Get store data.
*
* @return array
*/
static function get_data() {
return self::$store;
}
/**
* Merge data.
*
* @param array $data The data that will be merged with the exsisting store.
*/
static function merge_data( $data ) {
self::$store = array_replace_recursive( self::$store, $data );
}
/**
* Reset the store data.
*/
static function reset() {
self::$store = array();
}
/**
* Render the store data.
*/
static function render() {
if ( empty( self::$store ) ) {
return;
}
echo sprintf(
'<script id="wc-interactivity-store-data" type="application/json">%s</script>',
wp_json_encode( self::$store )
);
}
}
load.php 0000644 00000000177 15154715352 0006211 0 ustar 00 <?php
require __DIR__ . '/class-wc-interactivity-store.php';
require __DIR__ . '/store.php';
require __DIR__ . '/scripts.php';
scripts.php 0000644 00000003264 15154715352 0006761 0 ustar 00 <?php
/**
* Move interactive scripts to the footer. This is a temporary measure to make
* it work with `wc_store` and it should be replaced with deferred scripts or
* modules.
*/
function woocommerce_interactivity_move_interactive_scripts_to_the_footer() {
// Move the @woocommerce/interactivity package to the footer.
wp_script_add_data( 'wc-interactivity', 'group', 1 );
// Move all the view scripts of the interactive blocks to the footer.
$registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
foreach ( array_values( $registered_blocks ) as $block ) {
if ( isset( $block->supports['interactivity'] ) && $block->supports['interactivity'] ) {
foreach ( $block->view_script_handles as $handle ) {
wp_script_add_data( $handle, 'group', 1 );
}
}
}
}
add_action( 'wp_enqueue_scripts', 'woocommerce_interactivity_move_interactive_scripts_to_the_footer', 11 );
/**
* Register the Interactivity API runtime and make it available to be enqueued
* as a dependency in interactive blocks.
*/
function woocommerce_interactivity_register_runtime() {
$plugin_path = \Automattic\WooCommerce\Blocks\Package::get_path();
$plugin_url = plugin_dir_url( $plugin_path . '/index.php' );
$file = 'build/wc-interactivity.js';
$file_path = $plugin_path . $file;
$file_url = $plugin_url . $file;
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( $file_path ) ) {
$version = filemtime( $file_path );
} else {
$version = \Automattic\WooCommerce\Blocks\Package::get_version();
}
wp_register_script(
'wc-interactivity',
$file_url,
array(),
$version,
true
);
}
add_action( 'wp_enqueue_scripts', 'woocommerce_interactivity_register_runtime' );
store.php 0000644 00000000715 15154715352 0006424 0 ustar 00 <?php
/**
* Merge data with the exsisting store.
*
* @param array $data Data that will be merged with the exsisting store.
*
* @return $data The current store data.
*/
function wc_store( $data = null ) {
if ( $data ) {
WC_Interactivity_Store::merge_data( $data );
}
return WC_Interactivity_Store::get_data();
}
/**
* Render the Interactivity API store in the frontend.
*/
add_action( 'wp_footer', array( 'WC_Interactivity_Store', 'render' ), 8 );