init.php
86 lines
| 1 | <?php |
| 2 | namespace WP_Social\Lib\Template_Library; |
| 3 | |
| 4 | use WP_Social\Plugin; |
| 5 | |
| 6 | defined( 'ABSPATH' ) || exit; |
| 7 | |
| 8 | /** |
| 9 | * Class Init |
| 10 | * |
| 11 | * Initializes the Template Library of the WP Social plugin. |
| 12 | */ |
| 13 | class Init { |
| 14 | /** |
| 15 | * Initializes the Init class. |
| 16 | * |
| 17 | * Includes necessary files. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | add_action('activate_gutenkit-blocks-addon/gutenkit-blocks-addon.php', array( $this, 'load_gutenkit_plugin' ), 9999); |
| 21 | add_action( 'admin_enqueue_scripts', array( $this, 'library_admin_enqueue_scripts' ) ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Retrieves the URL of the Template Library. |
| 26 | * |
| 27 | * @return string The URL of the Template Library. |
| 28 | * @since 3.0.3 |
| 29 | */ |
| 30 | public static function get_url() { |
| 31 | return Plugin::instance()->lib_url() . 'template-library/'; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Retrieves the directory of the Template Library. |
| 36 | * |
| 37 | * @return string The directory of the Template Library. |
| 38 | * @since 3.0.3 |
| 39 | */ |
| 40 | public static function get_dir() { |
| 41 | return Plugin::instance()->lib_dir() . 'template-library/'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Loads the GutenKit plugin. |
| 46 | * @since 3.0.3 |
| 47 | * Deletes the 'gutenkit_do_activation_redirect' option. |
| 48 | */ |
| 49 | public function load_gutenkit_plugin() { |
| 50 | delete_option( 'gutenkit_do_activation_redirect' ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Enqueue scripts and styles for the template library in the admin area. |
| 55 | * |
| 56 | * @param string $screen The current admin screen. |
| 57 | * @since 3.0.3 |
| 58 | */ |
| 59 | public function library_admin_enqueue_scripts($screen) { |
| 60 | // Enqueue block editor only JavaScript and CSS. |
| 61 | $editor_template_library = include self::get_dir() . 'assets/library/editor-template-library.asset.php'; |
| 62 | if ( $screen === 'post.php' || $screen === 'post-new.php' || $screen === 'site-editor.php' ) { |
| 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 | true |
| 69 | ); |
| 70 | |
| 71 | wp_enqueue_style( |
| 72 | 'gutenkit-editor-template-library', |
| 73 | self::get_url() . 'assets/library/editor-template-library.css', |
| 74 | array(), |
| 75 | $editor_template_library['version'] |
| 76 | ); |
| 77 | |
| 78 | // Google Roboto Font |
| 79 | wp_enqueue_style( |
| 80 | 'gutenkit-google-fonts', |
| 81 | 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap' |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 |