TABLE_BUILDER_BLOCK_PLUGIN_URL, 'screen' => $hook, 'api_url' => TABLE_BUILDER_BLOCK_PLUGIN_URL . 'api/', 'root_url' => esc_url(home_url('/')), 'version' => TABLE_BUILDER_BLOCK_PLUGIN_VERSION, 'generalSettingsUrl' => admin_url('options-general.php'), 'activeTheme' => wp_get_theme()->get('Name'), 'assetUrl' => TABLE_BUILDER_BLOCK_PLUGIN_URL . 'assets/images/', ) ); } /** * Enqueue block editor assets. * * @return void * @since 1.0.0 */ public function blocks_editor_scripts() { $assets = [ 'components' => TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/tablebuilder/components.asset.php', 'helper' => TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/tablebuilder/helper.asset.php', 'global' => TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/tablebuilder/global.asset.php', ]; foreach ($assets as $handle => $asset_path) { $this->enqueue_assets($asset_path, "table_builder-block-editor-{$handle}", "{$handle}.js"); } } private function enqueue_assets($asset_file, $handle, $script_file) { $this->get_filesystem(); global $wp_filesystem; if (!isset($wp_filesystem) || !$wp_filesystem->exists($asset_file)) { return; } // Check if asset file exists if ($wp_filesystem->exists($asset_file)) { $asset_data = include $asset_file; // Ensure asset data is valid if (!empty($asset_data['dependencies']) && is_array($asset_data['dependencies']) && isset($asset_data['version'])) { wp_enqueue_script( $handle, TABLE_BUILDER_BLOCK_PLUGIN_URL . "build/tablebuilder/{$script_file}", $asset_data['dependencies'], $asset_data['version'], true ); } } } /** * Converts custom properties to CSS rules for global presets. * * @param array $custom_properties The array of custom CSS properties. * @return string The generated CSS rules. */ public function convert_custom_properties($custom_properties) { if (empty($custom_properties)) { return ''; } $css = array_map(function ($key, $value) { return "--table-builder-global-{$key}: {$value};"; }, array_keys($custom_properties), $custom_properties); return "body {" . implode(' ', $css) . "}"; } /** * Print device script in the header for responsive behavior. */ public function print_device_script_for_window() { if (!is_admin()) { $devices = Utils::get_device_list(); wp_add_inline_script('wp-block-editor', 'var breakpoints = ' . wp_json_encode($devices) . ';', 'before'); } } }