init.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Blocks Initializer |
| 4 | * |
| 5 | * Enqueue CSS/JS of all the blocks. |
| 6 | * |
| 7 | * @since 1.0.0 |
| 8 | * @package CGB |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | if (! defined('ABSPATH')) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | if (! defined('SUPERBBLOCKS_VERSION')) { |
| 17 | exit; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Enqueue Gutenberg block assets for both frontend + backend. |
| 22 | * |
| 23 | * Assets enqueued: |
| 24 | * 1. blocks.style.build.css - Frontend + Backend. |
| 25 | * 2. blocks.build.js - Backend. |
| 26 | * 3. blocks.editor.build.css - Backend. |
| 27 | * |
| 28 | * @uses {wp-blocks} for block type registration & related functions. |
| 29 | * @uses {wp-element} for WP Element abstraction — structure of blocks. |
| 30 | * @uses {wp-i18n} to internationalize the block's text. |
| 31 | * @uses {wp-editor} for WP editor styles. |
| 32 | * @since 1.0.0 |
| 33 | */ |
| 34 | function superb_blocks_cgb_block_assets() |
| 35 | { // phpcs:ignore |
| 36 | // Register block styles for both frontend + backend. |
| 37 | wp_register_style( |
| 38 | 'superb_blocks-cgb-style-css', // Handle. |
| 39 | plugins_url('dist/blocks.style.build.css', dirname(__FILE__)), // Block style CSS. |
| 40 | is_admin() ? array( 'wp-editor' ) : null, // Dependency to include the CSS after it. |
| 41 | SUPERBBLOCKS_VERSION // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time. |
| 42 | ); |
| 43 | |
| 44 | wp_register_style( |
| 45 | 'superb_blocks-cgb-fontawesome-css', // Handle. |
| 46 | plugins_url('lib/fontawesome/css/all.min.css', dirname(__FILE__)), // Block style CSS. |
| 47 | is_admin() ? array( 'wp-editor' ) : null, // Dependency to include the CSS after it. |
| 48 | SUPERBBLOCKS_VERSION // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time. |
| 49 | ); |
| 50 | |
| 51 | // Register block editor script for backend. |
| 52 | wp_register_script( |
| 53 | 'superb_blocks-cgb-block-js', // Handle. |
| 54 | plugins_url('dist/blocks.build.js', dirname(__FILE__)), // Block.build.js: We register the block here. Built with Webpack. |
| 55 | array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above. |
| 56 | SUPERBBLOCKS_VERSION, // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time. |
| 57 | true // Enqueue the script in the footer. |
| 58 | ); |
| 59 | |
| 60 | // Register block editor styles for backend. |
| 61 | wp_register_style( |
| 62 | 'superb_blocks-cgb-block-editor-css', // Handle. |
| 63 | plugins_url('dist/blocks.editor.build.css', dirname(__FILE__)), // Block editor CSS. |
| 64 | array( 'wp-edit-blocks' ), // Dependency to include the CSS after it. |
| 65 | SUPERBBLOCKS_VERSION // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time. |
| 66 | ); |
| 67 | |
| 68 | // WP Localized globals. Use dynamic PHP stuff in JavaScript via `cgbGlobal` object. |
| 69 | /*wp_localize_script( |
| 70 | 'superb_blocks-cgb-block-js', |
| 71 | 'cgbGlobal', // Array containing dynamic data for a JS Global. |
| 72 | [ |
| 73 | 'pluginDirPath' => plugin_dir_path(__DIR__), |
| 74 | 'pluginDirUrl' => plugin_dir_url(__DIR__), |
| 75 | // Add more data here that you want to access from `cgbGlobal` object. |
| 76 | ] |
| 77 | );*/ |
| 78 | |
| 79 | /** |
| 80 | * Register Gutenberg block on server-side. |
| 81 | * |
| 82 | * Register the block on server-side to ensure that the block |
| 83 | * scripts and styles for both frontend and backend are |
| 84 | * enqueued when the editor loads. |
| 85 | * |
| 86 | * @link https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type#enqueuing-block-scripts |
| 87 | * @since 1.16.0 |
| 88 | */ |
| 89 | register_block_type( |
| 90 | 'superb-blocks/superb-blocks', |
| 91 | array( |
| 92 | // Enqueue blocks.style.build.css on both frontend & backend. |
| 93 | 'style' => array('superb_blocks-cgb-fontawesome-css','superb_blocks-cgb-style-css'), |
| 94 | // Enqueue blocks.build.js in the editor only. |
| 95 | 'editor_script' => 'superb_blocks-cgb-block-js', |
| 96 | // Enqueue blocks.editor.build.css in the editor only. |
| 97 | 'editor_style' => 'superb_blocks-cgb-block-editor-css', |
| 98 | ) |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | // Hook: Block assets. |
| 103 | add_action('init', 'superb_blocks_cgb_block_assets'); |
| 104 | |
| 105 | add_action('admin_init', 'superb_blocks_spbThemesNotification', 9); |
| 106 | function superb_blocks_spbThemesNotification() |
| 107 | { |
| 108 | $notifications = include(plugin_dir_path(__FILE__).'/admin_notification/Autoload.php'); |
| 109 | $options = array("delay"=> "+3 days"); |
| 110 | $notifications->Add("superb_blocks_admin_notification", "Unlock All Features with Superb Blocks Premium", " |
| 111 | |
| 112 | Take advantage of the up to <span style='font-weight:bold;'>45% discount</span> and unlock all features for Superb Blocks Premium. |
| 113 | The discount is only available for a limited time. |
| 114 | |
| 115 | <div> |
| 116 | <a style='margin-bottom:15px;' class='button button-large button-secondary' target='_blank' href='https://superbthemes.com/plugins/superb-blocks/'>Read more</a> <a style='margin-bottom:15px;' class='button button-large button-primary' target='_blank' href='https://superbthemes.com/plugins/superb-blocks/'>Buy now</a> |
| 117 | </div> |
| 118 | |
| 119 | ", "info", $options); |
| 120 | $notifications->Boot(); |
| 121 | } |
| 122 |