is_block_editor() ) {
return;
}
$build_url = plugin_dir_url( __FILE__ ) . 'build/';
$vendor_url = $build_url . 'tailwindcss-in-browser.js';
$wasm_url = '';
$wasm_files = glob( __DIR__ . '/build/lightningcss_node-*.wasm' );
if ( is_array( $wasm_files ) && ! empty( $wasm_files ) ) {
$wasm_url = $build_url . basename( $wasm_files[0] );
}
// Build the @theme CSS block from the user-configured theme settings
// (Advanced Addons → Tailwind Theme). Falls back to defaults if unconfigured.
$theme_css = '';
if ( class_exists( \AdvancedAddons\Tailwind_Theme_Settings::class ) ) {
$theme_css = \AdvancedAddons\Tailwind_Theme_Settings::get_theme_css();
}
/**
* Filter the custom Tailwind CSS v4 configuration passed to the in-browser compiler.
*
* Use this to override or extend the default theme variables.
* Return the full CSS configuration; the default is merged/replaced by your return value.
*
* @param string $config_css The CSS configuration string (contains default theme variables).
*/
$config_css = apply_filters( 'advanced_addons_tailwind_config_css', $theme_css );
echo '' . "\n";
if ( '' !== $wasm_url ) {
echo '' . "\n";
}
echo '' . "\n";
}
);
function advanced_addons_fe_script() {
global $post;
if ( ! $post instanceof WP_Post ) {
return;
}
$post_id = $post->ID;
$tw_css = get_post_meta( $post_id, '_tailwind_css', true );
wp_register_style( 'wp-addon-tw-style', false, array(), defined( 'ADVANCED_ADDONS_VERSION' ) ? ADVANCED_ADDONS_VERSION : '4.0.0' );
wp_enqueue_style( 'wp-addon-tw-style' );
if ( is_string( $tw_css ) && '' !== trim( $tw_css ) ) {
$safe_css = class_exists( '\AdvancedAddons\Security' )
? \AdvancedAddons\Security::sanitize_css( $tw_css )
: wp_strip_all_tags( $tw_css );
wp_add_inline_style( 'wp-addon-tw-style', $safe_css );
}
}
add_action( 'wp_enqueue_scripts', 'advanced_addons_fe_script', 20 );
function advanced_addons_post_meta() {
$types = array( 'post', 'page', 'wp_block' );
foreach ( $types as $type ) {
register_post_meta(
$type,
'_tailwind_css',
array(
'single' => true,
'type' => 'string',
'show_in_rest' => true,
'auth_callback' => function ( $allowed, $meta_key, $post_id ) {
return current_user_can( 'edit_post', $post_id );
},
)
);
register_post_meta(
$type,
'_tailwind_css_source_hash',
array(
'single' => true,
'type' => 'string',
'show_in_rest' => true,
'auth_callback' => function ( $allowed, $meta_key, $post_id ) {
return current_user_can( 'edit_post', $post_id );
},
)
);
}
}
add_action( 'init', 'advanced_addons_post_meta' );