| @@ -4,59 +4,76 @@ | ||
| 4 | 4 | Description: A collection of blocks for the Gutenberg block editor, developed by Qode Interactive. |
| 5 | 5 | Author: Qode Interactive |
| 6 | 6 | Author URI: https://qodeinteractive.com/ |
| 7 | 7 | Plugin URI: https://qodeinteractive.com/qi-blocks-for-gutenberg/ |
| 8 | -Version: 1.0 | |
| 9 | -Requires at least: 5.8 | |
| 10 | -Requires PHP: 7.0 | |
| 8 | +Version: 1.5.3 | |
| 9 | +Requires at least: 6.3 | |
| 10 | +Requires PHP: 7.4 | |
| 11 | 11 | Text Domain: qi-blocks |
| 12 | 12 | */ |
| 13 | + | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + // Exit if accessed directly. | |
| 16 | + exit; | |
| 17 | +} | |
| 18 | + | |
| 13 | 19 | if ( ! class_exists( 'Qi_Blocks' ) ) { |
| 14 | 20 | class Qi_Blocks { |
| 15 | 21 | private static $instance; |
| 16 | 22 | |
| 17 | 23 | public function __construct() { |
| 18 | - // Set the main plugins constants | |
| 24 | + // Set the main plugins constants. | |
| 19 | 25 | define( 'QI_BLOCKS_PLUGIN_BASE_FILE', plugin_basename( __FILE__ ) ); |
| 20 | 26 | define( 'QI_BLOCKS_PLUGIN_LANGUAGES_PATH', plugin_dir_path( __FILE__ ) . '/languages/' ); |
| 21 | 27 | |
| 22 | - // Include required files | |
| 23 | - require_once dirname( __FILE__ ) . '/constants.php'; | |
| 28 | + // Include required files. | |
| 29 | + require_once __DIR__ . '/constants.php'; | |
| 24 | 30 | |
| 25 | - // Check if Gutenberg editor exists | |
| 31 | + // Check if Gutenberg editor exists. | |
| 26 | 32 | if ( class_exists( 'WP_Block_Type' ) ) { |
| 27 | 33 | require_once QI_BLOCKS_ABS_PATH . '/helpers/helper.php'; |
| 34 | + require_once QI_BLOCKS_INC_PATH . '/deprecated/helper.php'; | |
| 28 | 35 | |
| 29 | - // Make plugin available for translation | |
| 30 | - add_action( 'plugins_loaded', array( $this, 'load_plugin_text_domain' ) ); | |
| 36 | + // Make plugin available for translation. | |
| 37 | + add_action( 'init', array( $this, 'load_plugin_text_domain' ) ); | |
| 31 | 38 | |
| 32 | - // Add plugin's body classes | |
| 39 | + // Add plugin's body classes. | |
| 33 | 40 | add_filter( 'body_class', array( $this, 'add_body_classes' ) ); |
| 34 | 41 | |
| 35 | - // Allow SVG MIME Type in Media Upload | |
| 42 | + // Allow SVG MIME Type in Media Upload. | |
| 36 | 43 | add_filter( 'upload_mimes', array( $this, 'allow_svg_media_files' ) ); |
| 44 | + add_filter( 'wp_handle_upload_prefilter', array( $this, 'handle_svg_wp_media_upload' ) ); | |
| 37 | 45 | add_filter( 'wp_check_filetype_and_ext', array( $this, 'check_svg_upload' ), 10, 4 ); |
| 38 | 46 | |
| 39 | - // Enqueue plugin's assets | |
| 47 | + // Enqueue plugin's assets. | |
| 48 | + add_action( 'init', array( $this, 'register_assets' ) ); | |
| 40 | 49 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 41 | 50 | add_action( 'wp_enqueue_scripts', array( $this, 'localize_js_scripts' ) ); |
| 42 | 51 | |
| 43 | - // Register plugin's editor assets | |
| 52 | + // Loads core block assets only when they are rendered on the page - WordPress 5.8. | |
| 53 | + add_filter( 'should_load_separate_core_block_assets', '__return_true' ); | |
| 54 | + | |
| 55 | + // Register plugin's editor assets. | |
| 44 | 56 | add_action( 'init', array( $this, 'register_editor_assets' ) ); |
| 45 | 57 | |
| 46 | - // Enqueue plugin's editor assets | |
| 47 | - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) ); | |
| 48 | - add_action( 'enqueue_block_editor_assets', array( $this, 'localize_editor_js_scripts' ) ); | |
| 58 | + // Enqueue plugin's editor assets. The main editor script is registered and | |
| 59 | + // localized in register_editor_assets() (on `init`), so it only needs enqueuing here. | |
| 60 | + add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) ); | |
| 49 | 61 | |
| 50 | - // Set plugin's blocks style dependency | |
| 62 | + // Load editor CSS inside the block canvas iframe (WP 6.3+ / block themes). | |
| 63 | + add_action( 'enqueue_block_assets', array( $this, 'enqueue_editor_canvas_assets' ) ); | |
| 64 | + | |
| 65 | + // Set plugin's blocks style dependency. | |
| 51 | 66 | add_filter( 'qi_blocks_filter_block_style_dependency', array( $this, 'set_block_style_dependency' ) ); |
| 52 | 67 | |
| 53 | - // Include plugin's modules | |
| 54 | - $this->include_modules(); | |
| 68 | + // Include plugin's modules. | |
| 69 | + add_action( 'after_setup_theme', array( $this, 'include_modules' ), 5 ); | |
| 55 | 70 | } |
| 56 | 71 | } |
| 57 | 72 | |
| 58 | 73 | /** |
| 74 | + * Instance of module class | |
| 75 | + * | |
| 59 | 76 | * @return Qi_Blocks |
| 60 | 77 | */ |
| 61 | 78 | public static function get_instance() { |
| 62 | 79 | if ( is_null( self::$instance ) ) { |
| @@ -65,14 +82,14 @@ | ||
| 65 | 82 | |
| 66 | 83 | return self::$instance; |
| 67 | 84 | } |
| 68 | 85 | |
| 69 | - function load_plugin_text_domain() { | |
| 70 | - // Make plugin available for translation | |
| 86 | + public function load_plugin_text_domain() { | |
| 87 | + // Make plugin available for translation. | |
| 71 | 88 | load_plugin_textdomain( 'qi-blocks', false, QI_BLOCKS_REL_PATH . '/languages' ); |
| 72 | 89 | } |
| 73 | 90 | |
| 74 | - function add_body_classes( $classes ) { | |
| 91 | + public function add_body_classes( $classes ) { | |
| 75 | 92 | $classes[] = 'qi-blocks-' . QI_BLOCKS_VERSION; |
| 76 | 93 | |
| 77 | 94 | if ( wp_is_mobile() ) { |
| 78 | 95 | $classes[] = 'qodef-gutenberg--touch'; |
| @@ -82,9 +99,9 @@ | ||
| 82 | 99 | |
| 83 | 100 | return $classes; |
| 84 | 101 | } |
| 85 | 102 | |
| 86 | - function allow_svg_media_files( $mimes ) { | |
| 103 | + public function allow_svg_media_files( $mimes ) { | |
| 87 | 104 | $mimes['svg'] = 'image/svg+xml'; |
| 88 | 105 | $mimes['svgz'] = 'image/svg+xml'; |
| 89 | 106 | |
| 90 | 107 | return $mimes; |
| @@ -89,10 +106,51 @@ | ||
| 89 | 106 | |
| 90 | 107 | return $mimes; |
| 91 | 108 | } |
| 92 | 109 | |
| 93 | - function check_svg_upload( $checked, $file, $filename, $mimes ) { | |
| 110 | + /* | |
| 111 | + * @param array $file { | |
| 112 | + * Reference to a single element from `$_FILES`. | |
| 113 | + * | |
| 114 | + * @type string $name The original name of the file on the client machine. | |
| 115 | + * @type string $type The mime type of the file, if the browser provided this information. | |
| 116 | + * @type string $tmp_name The temporary filename of the file in which the uploaded file was stored on the server. | |
| 117 | + * @type int $size The size, in bytes, of the uploaded file. | |
| 118 | + * @type int $error The error code associated with this file upload. | |
| 119 | + * } | |
| 120 | + */ | |
| 121 | + public function handle_svg_wp_media_upload( $file ) { | |
| 94 | 122 | |
| 123 | + if ( ! empty( $file ) && isset( $file['type'] ) && 'image/svg+xml' === $file['type'] ) { | |
| 124 | + // Load the svg file. | |
| 125 | + $get_svg_content = @file_get_contents( $file['tmp_name'] ); | |
| 126 | + | |
| 127 | + if ( ! empty( $get_svg_content ) ) { | |
| 128 | + | |
| 129 | + if ( class_exists( 'enshrined\svgSanitize\Sanitizer' ) ) { | |
| 130 | + // Create a new sanitizer instance. | |
| 131 | + $sanitizer = new enshrined\svgSanitize\Sanitizer(); | |
| 132 | + | |
| 133 | + // Pass it to the sanitizer and get it back clean. | |
| 134 | + $clean_svg_content = $sanitizer->sanitize( $get_svg_content ); | |
| 135 | + | |
| 136 | + if ( empty( $clean_svg_content ) ) { | |
| 137 | + $clean_svg_content = ''; | |
| 138 | + } | |
| 139 | + | |
| 140 | + // Update clean SVG/XML data. | |
| 141 | + @file_put_contents( $file['tmp_name'], $clean_svg_content ); | |
| 142 | + } | |
| 143 | + } else { | |
| 144 | + $file['error'] = esc_html__( 'Please upload a valid SVG file.', 'qi-blocks' ); | |
| 145 | + } | |
| 146 | + } | |
| 147 | + | |
| 148 | + return $file; | |
| 149 | + } | |
| 150 | + | |
| 151 | + public function check_svg_upload( $checked, $file, $filename, $mimes ) { | |
| 152 | + | |
| 95 | 153 | if ( ! $checked['type'] ) { |
| 96 | 154 | |
| 97 | 155 | $check_filetype = wp_check_filetype( $filename, $mimes ); |
| 98 | 156 | $ext = $check_filetype['ext']; |
| @@ -98,10 +156,11 @@ | ||
| 98 | 156 | $ext = $check_filetype['ext']; |
| 99 | 157 | $type = $check_filetype['type']; |
| 100 | 158 | $proper_filename = $filename; |
| 101 | 159 | |
| 102 | - if ( $type && 0 === strpos( $type, 'image/' ) && $ext !== 'svg' ) { | |
| 103 | - $ext = $type = false; | |
| 160 | + if ( $type && 0 === strpos( $type, 'image/' ) && 'svg' !== $ext ) { | |
| 161 | + $ext = false; | |
| 162 | + $type = false; | |
| 104 | 163 | } |
| 105 | 164 | |
| 106 | 165 | $checked = compact( 'ext', 'type', 'proper_filename' ); |
| 107 | 166 | } |
| @@ -108,68 +167,188 @@ | ||
| 108 | 167 | |
| 109 | 168 | return $checked; |
| 110 | 169 | } |
| 111 | 170 | |
| 112 | - function enqueue_assets() { | |
| 171 | + public function register_assets() { | |
| 113 | 172 | |
| 114 | - // Enqueue plugin's 3rd party scripts | |
| 173 | + // Register CSS grid styles. | |
| 174 | + wp_register_style( 'qi-blocks-grid', QI_BLOCKS_ASSETS_URL_PATH . '/dist/grid.css', array(), QI_BLOCKS_VERSION ); | |
| 175 | + | |
| 176 | + // Register CSS styles. | |
| 177 | + wp_register_style( 'qi-blocks-main', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main.css', array(), QI_BLOCKS_VERSION ); | |
| 178 | + | |
| 179 | + // Register JS scripts. | |
| 180 | + wp_register_script( 'qi-blocks-main', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main.js', array( 'jquery' ), QI_BLOCKS_VERSION, true ); | |
| 181 | + } | |
| 182 | + | |
| 183 | + public function enqueue_assets() { | |
| 184 | + if ( ! function_exists( 'qi_blocks_should_load_frontend_assets' ) || ! qi_blocks_should_load_frontend_assets() ) { | |
| 185 | + return; | |
| 186 | + } | |
| 187 | + | |
| 188 | + $this->register_3rd_party_assets(); | |
| 115 | 189 | $this->enqueue_3rd_party_assets(); |
| 116 | 190 | |
| 117 | - // Enqueue CSS grid styles | |
| 118 | - wp_enqueue_style( 'qi-blocks-grid', QI_BLOCKS_ASSETS_URL_PATH . '/dist/grid.css' ); | |
| 191 | + if ( function_exists( 'qi_blocks_page_needs_swiper' ) && qi_blocks_page_needs_swiper() ) { | |
| 192 | + wp_enqueue_style( 'swiper' ); | |
| 193 | + wp_enqueue_script( 'swiper' ); | |
| 119 | 194 | |
| 120 | - // Enqueue CSS styles | |
| 121 | - wp_enqueue_style( 'qi-blocks-main', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main.css' ); | |
| 195 | + $wp_scripts = wp_scripts(); | |
| 122 | 196 | |
| 123 | - // Enqueue JS scripts | |
| 124 | - wp_enqueue_script( 'qi-blocks-main', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main.js', array( 'jquery' ), false, true ); | |
| 197 | + if ( isset( $wp_scripts->registered['qi-blocks-main'] ) && ! in_array( 'swiper', $wp_scripts->registered['qi-blocks-main']->deps, true ) ) { | |
| 198 | + $wp_scripts->registered['qi-blocks-main']->deps[] = 'swiper'; | |
| 199 | + } | |
| 200 | + } | |
| 201 | + | |
| 202 | + // Enqueue CSS grid styles. | |
| 203 | + wp_enqueue_style( 'qi-blocks-grid' ); | |
| 204 | + | |
| 205 | + // Enqueue CSS styles. | |
| 206 | + wp_enqueue_style( 'qi-blocks-main' ); | |
| 207 | + | |
| 208 | + // Enqueue JS scripts. | |
| 209 | + wp_enqueue_script( 'qi-blocks-main' ); | |
| 125 | 210 | } |
| 126 | 211 | |
| 127 | - function register_editor_assets() { | |
| 212 | + public function register_editor_assets() { | |
| 213 | + $this->register_3rd_party_assets(); | |
| 128 | 214 | |
| 129 | - // Enqueue plugin's 3rd party scripts | |
| 130 | - $this->enqueue_3rd_party_assets(); | |
| 215 | + // Register CSS grid styles. | |
| 216 | + wp_register_style( 'qi-blocks-grid-editor', QI_BLOCKS_ASSETS_URL_PATH . '/dist/grid-editor.css', array( 'qi-blocks-main' ), QI_BLOCKS_VERSION ); | |
| 131 | 217 | |
| 132 | - // Register CSS grid styles | |
| 133 | - wp_register_style( 'qi-blocks-grid-editor', QI_BLOCKS_ASSETS_URL_PATH . '/dist/grid-editor.css', array( 'qi-blocks-main' ) ); | |
| 218 | + // Register CSS styles. | |
| 219 | + wp_register_style( 'qi-blocks-main', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main.css', array(), QI_BLOCKS_VERSION ); | |
| 220 | + wp_register_style( 'qi-blocks-main-editor', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main-editor.css', array( 'qi-blocks-main' ), QI_BLOCKS_VERSION ); | |
| 134 | 221 | |
| 135 | - // Register CSS styles | |
| 136 | - wp_register_style( 'qi-blocks-main', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main.css' ); | |
| 137 | - wp_register_style( 'qi-blocks-main-editor', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main-editor.css', array( 'qi-blocks-main' ) ); | |
| 222 | + // Register the main editor JS script early (on `init`) so that the per-block | |
| 223 | + // editor scripts - which declare `qi-blocks-main-editor` as a dependency at | |
| 224 | + // registration time - resolve against a real, registered handle. Registering it | |
| 225 | + // here (instead of only inside enqueue_editor_assets) guarantees the handle and its | |
| 226 | + // localized `qiBlocksEditor` data are available whenever the script is loaded, | |
| 227 | + // either directly or pulled in as a block editor_script dependency. | |
| 228 | + $script_dependency = apply_filters( | |
| 229 | + 'qi_blocks_filter_main_editor_dependencies', | |
| 230 | + array( | |
| 231 | + 'wp-blocks', | |
| 232 | + 'wp-element', | |
| 233 | + 'wp-block-editor', | |
| 234 | + 'wp-plugins', | |
| 235 | + 'wp-i18n', | |
| 236 | + 'wp-api-fetch', | |
| 237 | + 'wp-api', | |
| 238 | + 'wp-data', | |
| 239 | + 'wp-html-entities', | |
| 240 | + 'wp-date', | |
| 241 | + 'wp-autop', | |
| 242 | + ) | |
| 243 | + ); | |
| 244 | + | |
| 245 | + wp_register_script( 'qi-blocks-main-editor', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main-editor.js', $script_dependency, QI_BLOCKS_VERSION, true ); | |
| 246 | + | |
| 247 | + // Enqueue localization data for our blocks. | |
| 248 | + if ( function_exists( 'wp_set_script_translations' ) ) { | |
| 249 | + wp_set_script_translations( 'qi-blocks-main-editor', 'qi-blocks' ); | |
| 250 | + } | |
| 251 | + | |
| 252 | + // Attach the localized variables to the now-registered handle. WordPress prints the | |
| 253 | + // localized data whenever the script is output, so this works regardless of whether | |
| 254 | + // the script is enqueued directly or as a block editor_script dependency. | |
| 255 | + $this->localize_editor_js_scripts(); | |
| 138 | 256 | } |
| 139 | 257 | |
| 140 | - function enqueue_editor_assets() { | |
| 258 | + public function enqueue_editor_assets() { | |
| 259 | + $this->enqueue_3rd_party_assets(); | |
| 141 | 260 | |
| 142 | - // Enqueue CSS grid styles | |
| 261 | + // Enqueue CSS grid styles. | |
| 143 | 262 | wp_enqueue_style( 'qi-blocks-grid-editor' ); |
| 144 | 263 | |
| 145 | - // Enqueue CSS styles | |
| 264 | + // Enqueue CSS styles. | |
| 146 | 265 | wp_enqueue_style( 'qi-blocks-main' ); |
| 147 | 266 | wp_enqueue_style( 'qi-blocks-main-editor' ); |
| 148 | 267 | |
| 149 | - // Enqueue JS scripts | |
| 150 | - wp_enqueue_script( 'qi-blocks-main-editor', QI_BLOCKS_ASSETS_URL_PATH . '/dist/main-editor.js', array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-editor', 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-api-fetch', 'wp-api', 'wp-data', 'wp-html-entities', 'wp-date', 'wp-autop' ), false, true ); | |
| 268 | + // Enqueue JS scripts (already registered and localized in register_editor_assets). | |
| 269 | + wp_enqueue_script( 'qi-blocks-main-editor' ); | |
| 270 | + } | |
| 151 | 271 | |
| 152 | - // Enqueue localization data for our blocks | |
| 153 | - if ( function_exists( 'wp_set_script_translations' ) ) { | |
| 154 | - wp_set_script_translations( 'qi-blocks-main-editor', 'qi-blocks' ); | |
| 272 | + public function enqueue_editor_canvas_assets() { | |
| 273 | + if ( ! is_admin() ) { | |
| 274 | + return; | |
| 155 | 275 | } |
| 276 | + | |
| 277 | + wp_enqueue_style( 'qi-blocks-main' ); | |
| 278 | + wp_enqueue_style( 'qi-blocks-grid-editor' ); | |
| 279 | + wp_enqueue_style( 'qi-blocks-main-editor' ); | |
| 280 | + | |
| 281 | + /* | |
| 282 | + * WordPress 6.3+/7.0 renders the editor content inside the canvas iframe and only | |
| 283 | + * loads assets enqueued on `enqueue_block_assets` there - editor scripts (and their | |
| 284 | + * `qiBlocksEditor` localization) stay in the parent document. While collecting the | |
| 285 | + * iframe assets, core sets `should_load_block_editor_scripts_and_styles` to false, | |
| 286 | + * which is how we detect the iframe pass. In that pass we expose the qiBlocksEditor | |
| 287 | + * variables so any block markup/script running inside the iframe can read them. | |
| 288 | + * | |
| 289 | + * We intentionally skip this on the parent editor page: there the full qiBlocksEditor | |
| 290 | + * object (including the runtime methods added by main-editor.js) already exists, and | |
| 291 | + * re-declaring it would wipe those methods. | |
| 292 | + */ | |
| 293 | + $is_iframe_canvas_pass = ! apply_filters( 'should_load_block_editor_scripts_and_styles', true ); | |
| 294 | + | |
| 295 | + if ( $is_iframe_canvas_pass ) { | |
| 296 | + if ( ! wp_script_is( 'qi-blocks-editor-canvas-vars', 'registered' ) ) { | |
| 297 | + // Source-less handle used only to carry the localized variables into the iframe. | |
| 298 | + wp_register_script( 'qi-blocks-editor-canvas-vars', false, array(), QI_BLOCKS_VERSION, false ); | |
| 299 | + } | |
| 300 | + | |
| 301 | + wp_enqueue_script( 'qi-blocks-editor-canvas-vars' ); | |
| 302 | + | |
| 303 | + wp_localize_script( | |
| 304 | + 'qi-blocks-editor-canvas-vars', | |
| 305 | + 'qiBlocksEditor', | |
| 306 | + array( | |
| 307 | + 'vars' => $this->get_localize_editor_js_variables(), | |
| 308 | + ) | |
| 309 | + ); | |
| 310 | + | |
| 311 | + /* | |
| 312 | + * Lightweight iframe bundle exposing the dependency-free runtime helpers | |
| 313 | + * (qodefGetCurrentBlockElement, qodefSetEditorLinkBehavior) on the same | |
| 314 | + * qiBlocksEditor object so other scripts running inside the iframe can use them. | |
| 315 | + * It depends on the vars handle so `var qiBlocksEditor = { vars }` is printed | |
| 316 | + * first and the bundle only augments it (it never overwrites existing members). | |
| 317 | + */ | |
| 318 | + if ( ! wp_script_is( 'qi-blocks-editor-canvas', 'registered' ) ) { | |
| 319 | + wp_register_script( | |
| 320 | + 'qi-blocks-editor-canvas', | |
| 321 | + QI_BLOCKS_ASSETS_URL_PATH . '/dist/editor-canvas.js', | |
| 322 | + array( 'qi-blocks-editor-canvas-vars' ), | |
| 323 | + QI_BLOCKS_VERSION, | |
| 324 | + true | |
| 325 | + ); | |
| 326 | + } | |
| 327 | + | |
| 328 | + wp_enqueue_script( 'qi-blocks-editor-canvas' ); | |
| 329 | + } | |
| 156 | 330 | } |
| 157 | 331 | |
| 158 | - function enqueue_3rd_party_assets() { | |
| 332 | + public function register_3rd_party_assets() { | |
| 333 | + // Hook to include additional 3rd party scripts. | |
| 334 | + do_action( 'qi_blocks_action_additional_3rd_party_scripts' ); | |
| 159 | 335 | |
| 160 | - // Hook to include additional 3rd party scripts | |
| 161 | - do_action( 'qi_blocks_action_additional_3rd_party_scripts' ); | |
| 336 | + if ( ! wp_style_is( 'animate', 'registered' ) ) { | |
| 337 | + wp_register_style( 'animate', QI_BLOCKS_ASSETS_URL_PATH . '/css/plugins/animate/animate.min.css', array(), '4.1.1' ); | |
| 338 | + } | |
| 162 | 339 | |
| 163 | - // Register and enqueue animate styles | |
| 164 | - wp_register_style( 'animate', QI_BLOCKS_ASSETS_URL_PATH . '/css/plugins/animate/animate.min.css' ); | |
| 340 | + if ( ! wp_script_is( 'fslightbox', 'registered' ) ) { | |
| 341 | + wp_register_script( 'fslightbox', QI_BLOCKS_ASSETS_URL_PATH . '/js/plugins/fslightbox/fslightbox.min.js', array( 'jquery' ), '3.4.1', true ); | |
| 342 | + } | |
| 343 | + } | |
| 344 | + | |
| 345 | + public function enqueue_3rd_party_assets() { | |
| 346 | + $this->register_3rd_party_assets(); | |
| 165 | 347 | wp_enqueue_style( 'animate' ); |
| 166 | - | |
| 167 | - // Register lightbox scripts | |
| 168 | - wp_register_script( 'fslightbox', QI_BLOCKS_ASSETS_URL_PATH . '/js/plugins/fslightbox/fslightbox.min.js', array( 'jquery' ), false, true ); | |
| 169 | 348 | } |
| 170 | 349 | |
| 171 | - function set_block_style_dependency( $style_dependency ) { | |
| 350 | + public function set_block_style_dependency( $style_dependency ) { | |
| 172 | 351 | $style_dependency[] = 'animate'; |
| 173 | 352 | $style_dependency[] = 'qi-blocks-main'; |
| 174 | 353 | |
| 175 | 354 | if ( is_admin() ) { |
| @@ -179,9 +358,13 @@ | ||
| 179 | 358 | |
| 180 | 359 | return $style_dependency; |
| 181 | 360 | } |
| 182 | 361 | |
| 183 | - function localize_js_scripts() { | |
| 362 | + public function localize_js_scripts() { | |
| 363 | + if ( ! wp_script_is( 'qi-blocks-main', 'enqueued' ) ) { | |
| 364 | + return; | |
| 365 | + } | |
| 366 | + | |
| 184 | 367 | $global = apply_filters( |
| 185 | 368 | 'qi_blocks_filter_localize_main_js', |
| 186 | 369 | array( |
| 187 | 370 | 'arrowLeftIcon' => '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 34.2 32.3" xml:space="preserve" style="stroke-width: 2;"><line x1="0.5" y1="16" x2="33.5" y2="16"/><line x1="0.3" y1="16.5" x2="16.2" y2="0.7"/><line x1="0" y1="15.4" x2="16.2" y2="31.6"/></svg>', |
| @@ -198,14 +381,14 @@ | ||
| 198 | 381 | ) |
| 199 | 382 | ); |
| 200 | 383 | } |
| 201 | 384 | |
| 202 | - function localize_editor_js_scripts() { | |
| 203 | - $global = apply_filters( | |
| 385 | + public function get_localize_editor_js_variables() { | |
| 386 | + return apply_filters( | |
| 204 | 387 | 'qi_blocks_filter_localize_main_editor_js', |
| 205 | 388 | array( |
| 206 | 389 | 'siteURL' => esc_url( get_home_url( '/' ) ), |
| 207 | - 'dateFormat' => esc_attr( get_option( 'date_format' ) ), // TBR! | |
| 390 | + 'dateFormat' => esc_attr( get_option( 'date_format' ) ), | |
| 208 | 391 | 'defaultTitleLabel' => esc_html__( 'Example Title Text', 'qi-blocks' ), |
| 209 | 392 | 'defaultSubtitleLabel' => esc_html__( 'Example Subtitle Text', 'qi-blocks' ), |
| 210 | 393 | 'defaultContentLabel' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent et eros eu felis.', 'qi-blocks' ), |
| 211 | 394 | 'defaultContentLong' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempus nisl vitae magna pulvinar laoreet. Nullam erat ipsum, mattis nec mollis ac, accumsan a enim. Nunc at euismod arcu. Aliquam ullamcorper eros justo, vel mollis neque facilisis vel. Proin augue tortor, condimentum id sapien a, tempus venenatis massa. Aliquam egestas eget diam sed sagittis. Vivamus consectetur purus vel felis molestie sollicitudin. Vivamus sit amet enim nisl. Cras vitae varius metus, a hendrerit ex. Sed in mi dolor. Proin pretium nibh non volutpat efficitur.', 'qi-blocks' ), |
| @@ -225,20 +408,22 @@ | ||
| 225 | 408 | 'authorIcon' => '<svg class="qodef-e-info-item-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 15.9 15.9" xml:space="preserve"><path d="M2.5,2.5C4,1,5.8,0.2,7.9,0.2c2.1,0,3.9,0.8,5.5,2.3c1.5,1.5,2.3,3.3,2.3,5.5c0,2.1-0.8,3.9-2.3,5.5c-1.5,1.5-3.3,2.3-5.5,2.3c-2.1,0-3.9-0.8-5.5-2.3C1,11.9,0.2,10,0.2,7.9C0.2,5.8,1,4,2.5,2.5z M12.9,2.9c-1.4-1.4-3.1-2.1-5-2.1c-2,0-3.6,0.7-5,2.1C1.5,4.3,0.9,6,0.9,7.9c0,1.7,0.6,3.2,1.7,4.5c1-0.4,2.1-0.8,3.3-1.2c0.1,0,0.1-0.2,0.1-0.4c0-0.4,0-0.7-0.1-0.9C5.7,9.7,5.6,9.3,5.5,8.8C5.3,8.5,5.1,8.1,5,7.6c-0.1-0.4-0.1-0.7,0-1V6.5c0.1-0.2,0-0.7-0.1-1.4C4.8,4.5,5,3.8,5.5,3.2c0.5-0.6,1.2-1,2.2-1h0.7c1,0,1.7,0.4,2.2,1c0.5,0.6,0.7,1.3,0.6,1.9c-0.1,0.7-0.2,1.2-0.1,1.4c0,0,0,0,0,0.1c0.1,0.2,0.1,0.6,0,1c-0.1,0.5-0.3,0.9-0.5,1.2c-0.1,0.5-0.2,0.9-0.3,1.2c-0.1,0.3-0.2,0.6-0.2,0.9c0,0.2,0,0.4,0.1,0.4c1.2,0.4,2.4,0.8,3.5,1.2c1.1-1.3,1.7-2.8,1.7-4.5C15,6,14.3,4.3,12.9,2.9z"/></svg>', |
| 226 | 409 | 'dateIcon' => '<svg class="qodef-e-info-item-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 14.6 14.6" xml:space="preserve"><path d="M10.9,1.3V0.2h-0.6v1.2H4.3V0.2H3.7v1.2H0.2v13.1h14.3V1.3H10.9z M10.9,1.9v1.2h-0.6V1.9H10.9z M4.3,1.9v1.2H3.7V1.9H4.3z M13.8,13.8H0.8V4.9h13.1V13.8z"/></svg>', |
| 227 | 410 | ) |
| 228 | 411 | ); |
| 412 | + } | |
| 229 | 413 | |
| 414 | + public function localize_editor_js_scripts() { | |
| 230 | 415 | wp_localize_script( |
| 231 | 416 | 'qi-blocks-main-editor', |
| 232 | 417 | 'qiBlocksEditor', |
| 233 | 418 | array( |
| 234 | - 'vars' => $global, | |
| 419 | + 'vars' => $this->get_localize_editor_js_variables(), | |
| 235 | 420 | ) |
| 236 | 421 | ); |
| 237 | 422 | } |
| 238 | 423 | |
| 239 | - function include_modules() { | |
| 240 | - // Hook to include additional element before modules inclusion | |
| 424 | + public function include_modules() { | |
| 425 | + // Hook to include additional element before modules inclusion. | |
| 241 | 426 | do_action( 'qi_blocks_action_before_include_modules' ); |
| 242 | 427 | |
| 243 | 428 | foreach ( glob( QI_BLOCKS_INC_PATH . '/*/include.php' ) as $module ) { |
| 244 | 429 | include_once $module; |
| @@ -243,9 +428,9 @@ | ||
| 243 | 428 | foreach ( glob( QI_BLOCKS_INC_PATH . '/*/include.php' ) as $module ) { |
| 244 | 429 | include_once $module; |
| 245 | 430 | } |
| 246 | 431 | |
| 247 | - // Hook to include additional element after modules inclusion | |
| 432 | + // Hook to include additional element after modules inclusion. | |
| 248 | 433 | do_action( 'qi_blocks_action_after_include_modules' ); |
| 249 | 434 | } |
| 250 | 435 | } |
| 251 | 436 | |
| @@ -258,9 +443,9 @@ | ||
| 258 | 443 | */ |
| 259 | 444 | function qi_blocks_activation_trigger() { |
| 260 | 445 | set_transient( QI_BLOCKS_ACTIVATED_TRANSIENT, 1 ); |
| 261 | 446 | |
| 262 | - // Hook to add additional code on plugin activation | |
| 447 | + // Hook to add additional code on plugin activation. | |
| 263 | 448 | do_action( 'qi_blocks_action_on_activation' ); |
| 264 | 449 | } |
| 265 | 450 | |
| 266 | 451 | register_activation_hook( __FILE__, 'qi_blocks_activation_trigger' ); |
| @@ -271,9 +456,9 @@ | ||
| 271 | 456 | * Function that trigger hooks on plugin deactivation |
| 272 | 457 | */ |
| 273 | 458 | function qi_blocks_deactivation_trigger() { |
| 274 | 459 | |
| 275 | - // Hook to add additional code on plugin deactivation | |
| 460 | + // Hook to add additional code on plugin deactivation. | |
| 276 | 461 | do_action( 'qi_blocks_action_on_deactivation' ); |
| 277 | 462 | } |
| 278 | 463 | |
| 279 | 464 | register_deactivation_hook( __FILE__, 'qi_blocks_deactivation_trigger' ); |