init(); // Initialize Dashboard UI (admin only). if ( is_admin() ) { require_once __DIR__ . '/inc/class-blocklayouts-dashboard.php'; } /** * Enqueue editor assets. * * @since 0.1.0 */ function blocklayouts_enqueue_editor_assets() { $asset_file = include BLOCKLAYOUTS_PLUGIN_PATH . 'build/index.asset.php'; $license = License::get_instance(); // Ensure asset file is valid array with expected keys. if ( ! is_array( $asset_file ) ) { $asset_file = array( 'dependencies' => array(), 'version' => BLOCKLAYOUTS_VERSION, ); } $asset_file = wp_parse_args( $asset_file, array( 'dependencies' => array(), 'version' => BLOCKLAYOUTS_VERSION, ) ); wp_enqueue_style( 'blocklayouts-core-extensions-editor-styles', BLOCKLAYOUTS_PLUGIN_URL . 'build/index.css', array(), BLOCKLAYOUTS_VERSION ); wp_enqueue_script( 'blocklayouts-library-editor', BLOCKLAYOUTS_PLUGIN_URL . 'build/index.js', $asset_file['dependencies'], $asset_file['version'], false ); wp_set_script_translations( 'blocklayouts-library-editor', 'blocklayouts' ); $config = array( 'license' => $license->get_license_config(), 'instance_name' => $license->get_instance_name(), 'version' => BLOCKLAYOUTS_VERSION, 'api' => array( 'nonce' => wp_create_nonce( 'wp_rest' ), 'root' => esc_url_raw( rest_url() ), ), ); wp_localize_script( 'blocklayouts-library-editor', 'blocklayouts_config', $config ); } add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\blocklayouts_enqueue_editor_assets' ); /** * Enqueue CSS & JavaScript files. * * @since 0.1.0 */ function blocklayouts_enqueue_css_and_js() { if ( is_admin() ) { return; } wp_enqueue_style( 'blocklayouts-main-styles', BLOCKLAYOUTS_PLUGIN_URL . 'assets/css/blocklayouts.css', array(), BLOCKLAYOUTS_VERSION ); // JS. wp_register_script( 'blocklayouts-main-scripts', BLOCKLAYOUTS_PLUGIN_URL . 'assets/js/blocklayouts.min.js', array(), BLOCKLAYOUTS_VERSION, true ); wp_enqueue_script( 'blocklayouts-main-scripts' ); } add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\blocklayouts_enqueue_css_and_js' ); /** * Plugin deactivation hook */ function blocklayouts_deactivate() { // Clean up scheduled events. wp_clear_scheduled_hook( 'blocklayouts_validate_license' ); } register_deactivation_hook( __FILE__, __NAMESPACE__ . '\blocklayouts_deactivate' );