Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"core": "WordPress/WordPress#6.7.1",
"core": "WordPress/WordPress#6.8",
"phpVersion": "7.4",
"plugins": [ "." ]
}
12 changes: 6 additions & 6 deletions src/Block/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ function register() {
$block_path = dirname( plugin_dir_path( __FILE__ ), 2 ) . '/build/block';
$block_json_path = "$block_path/block.json";

register_site_status_test( $block_json_path );

if ( ! file_exists( $block_json_path ) ) {
return;
}

add_action(
'init',
function () use ( $block_json_path ) {
register_site_status_test( $block_json_path );

if ( ! file_exists( $block_json_path ) ) {
return;
}

$metadata = parse_block_json( $block_json_path );
register_block_type(
$block_json_path,
Expand Down
39 changes: 28 additions & 11 deletions src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,36 @@ function main() {
}

function register_scripts() {
// Common configuration data for both admin and frontend.
$json_data = wp_json_encode(
array(
'rootUrl' => root_url() . '/iframe/',
)
);

// Helper function to register and enqueue the configuration script.
$register_config_script = function() use ( $json_data ) {
// Enqueue script for global configuration.
wp_register_script( SCRIPT_HANDLE_CONFIG, '', array(), automattic_chatrix_version(), true );
wp_enqueue_script( SCRIPT_HANDLE_CONFIG );
wp_add_inline_script( SCRIPT_HANDLE_CONFIG, 'window.' . CONFIG_VARIABLE . " = $json_data;" );
};

// Admin scripts - needed for Gutenberg editor.
add_action(
'wp_enqueue_scripts',
function () {
$json_data = wp_json_encode(
array(
'rootUrl' => root_url() . '/iframe/',
)
);
'admin_enqueue_scripts',
function () use ( $register_config_script ) {
// Register and enqueue configuration script in admin area.
$register_config_script();
}
);

// Enqueue script for global configuration.
wp_register_script( SCRIPT_HANDLE_CONFIG, '', array(), automattic_chatrix_version(), true );
wp_enqueue_script( SCRIPT_HANDLE_CONFIG );
wp_add_inline_script( SCRIPT_HANDLE_CONFIG, 'window.' . CONFIG_VARIABLE . " = $json_data;" );
// Frontend scripts.
add_action(
'wp_enqueue_scripts',
function () use ( $register_config_script ) {
// Register and enqueue configuration script.
$register_config_script();

// Note we don't enqueue the SCRIPT_HANDLE_APP script yet. It will be enqueued whenever SCRIPT_HANDLE_APP
// is specified as a dependency of another script.
Expand Down