init.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ElementsKit_Lite\Libs\Template_Library; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | /** |
| 8 | * Class Init |
| 9 | * |
| 10 | * Initializes the Template Library of the ElementsKit Lite plugin. |
| 11 | */ |
| 12 | class Init{ |
| 13 | /** |
| 14 | * Initializes the Init class. |
| 15 | * |
| 16 | * Includes necessary files. |
| 17 | */ |
| 18 | public function __construct(){ |
| 19 | add_action('activate_gutenkit-blocks-addon/gutenkit-blocks-addon.php', array($this, 'load_gutenkit_plugin'), 9999); |
| 20 | add_action('enqueue_block_editor_assets', array($this, 'library_enqueue_block_editor_assets')); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Retrieves the URL of the Template Library. |
| 25 | * |
| 26 | * @return string The URL of the Template Library. |
| 27 | * @since 3.1.4 |
| 28 | */ |
| 29 | public static function get_url() { |
| 30 | return \ElementsKit_Lite::lib_url() . 'template-library/'; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Retrieves the directory of the Template Library. |
| 35 | * |
| 36 | * @return string The directory of the Template Library. |
| 37 | * @since 3.1.4 |
| 38 | */ |
| 39 | public static function get_dir() { |
| 40 | return \ElementsKit_Lite::lib_dir() . 'template-library/'; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Loads the GutenKit plugin. |
| 45 | * @since 3.1.4 |
| 46 | * Deletes the 'gutenkit_do_activation_redirect' option. |
| 47 | */ |
| 48 | public function load_gutenkit_plugin() { |
| 49 | delete_option('gutenkit_do_activation_redirect'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Enqueue scripts and styles for the template library in the admin area. |
| 54 | * |
| 55 | * @param string $screen The current admin screen. |
| 56 | * @since 3.1.4 |
| 57 | */ |
| 58 | public function library_enqueue_block_editor_assets() { |
| 59 | // Enqueue block editor only JavaScript and CSS. |
| 60 | $file_path = self::get_dir() . 'assets/library/editor-template-library.asset.php'; |
| 61 | if (file_exists($file_path)) { |
| 62 | $editor_template_library = include $file_path; |
| 63 | wp_enqueue_script( |
| 64 | 'gutenkit-editor-template-library', |
| 65 | self::get_url() . 'assets/library/editor-template-library.js', |
| 66 | $editor_template_library['dependencies'], |
| 67 | $editor_template_library['version'], |
| 68 | [ |
| 69 | 'in_footer' => true, |
| 70 | ] |
| 71 | ); |
| 72 | |
| 73 | wp_enqueue_style( |
| 74 | 'gutenkit-editor-template-library', |
| 75 | self::get_url() . 'assets/library/editor-template-library.css', |
| 76 | array(), |
| 77 | $editor_template_library['version'] |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 |