PluginProbe
Flipbox / trunk
Flipbox vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.4.0
flipbox / includes / helpers.php

helpers.php in Flipbox trunk, at includes/helpers.php

117 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Load google fonts.
5 */
6
7 // Exit if accessed directly.
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 class Flipbox_Helper
13 {
14
15 private static $instance;
16
17 /**
18 * Registers the plugin.
19 */
20 public static function register()
21 {
22 if (null === self::$instance) {
23 self::$instance = new self;
24 }
25 return self::$instance;
26 }
27
28 /**
29 * The Constructor.
30 */
31 public function __construct()
32 {
33 add_action('admin_enqueue_scripts', array($this, 'enqueues'));
34 }
35
36 /**
37 * Load fonts.
38 *
39 * @access public
40 */
41 public function enqueues($hook)
42 {
43 /**
44 * Only for Admin Add/Edit Pages
45 */
46 $query_string = isset($_SERVER['QUERY_STRING']) ? sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])) : '';
47
48 // strpos() instead of str_contains(): str_contains() is PHP 8.0+ and fatals below it.
49 if ($hook == 'post-new.php' || $hook == 'post.php' || $hook == 'site-editor.php' || ($hook == 'themes.php' && !empty($query_string) && strpos($query_string, 'gutenberg-edit-site') !== false)) {
50 $controls_asset_path = EB_FLIPBOX_BLOCKS_ADMIN_PATH . '/dist/modules.asset.php';
51 if (!file_exists($controls_asset_path)) {
52 return;
53 }
54
55 // `include`, not `include_once`: include_once returns bool true rather than the
56 // array when the file has already been included, which then fatals on PHP 8
57 // at array_merge(null).
58 $controls_dependencies = include $controls_asset_path;
59 if (!is_array($controls_dependencies) || !isset($controls_dependencies['dependencies'])) {
60 return;
61 }
62
63 wp_register_script(
64 "eb-flipbox-blocks-controls-util",
65 EB_FLIPBOX_BLOCKS_ADMIN_URL . '/dist/modules.js',
66 array_merge($controls_dependencies['dependencies']),
67 $controls_dependencies['version'],
68 true
69 );
70
71 wp_localize_script('eb-flipbox-blocks-controls-util', 'EssentialBlocksLocalize', array(
72 'eb_wp_version' => (float) get_bloginfo('version'),
73 'rest_rootURL' => get_rest_url(),
74 'fontAwesome' => "true"
75 ));
76
77 if ($hook == 'post-new.php' || $hook == 'post.php') {
78 wp_localize_script('eb-flipbox-blocks-controls-util', 'eb_conditional_localize', array(
79 'editor_type' => 'edit-post'
80 ));
81 } else if ($hook == 'site-editor.php') {
82 wp_localize_script('eb-flipbox-blocks-controls-util', 'eb_conditional_localize', array(
83 'editor_type' => 'edit-site'
84 ));
85 }
86
87 wp_register_style(
88 'essential-blocks-iconpicker-css',
89 EB_FLIPBOX_BLOCKS_ADMIN_URL . 'dist/style-modules.css',
90 [],
91 EB_FLIPBOX_BLOCKS_VERSION,
92 'all'
93 );
94
95 wp_enqueue_style(
96 'essential-blocks-editor-css',
97 EB_FLIPBOX_BLOCKS_ADMIN_URL . '/dist/modules.css',
98 array('essential-blocks-iconpicker-css','fontawesome-frontend-css'),
99 $controls_dependencies['version'],
100 'all'
101 );
102 }
103 }
104 public static function get_block_register_path($blockname, $blockPath)
105 {
106 // version_compare(), never a float cast: (float) "5.10" is 5.1 and (float) "7.0.3"
107 // silently drops the patch, so any x.10+ release would take the wrong branch.
108 // '< 5.7' is the exact equivalent of the previous '<= 5.6' float test.
109 if (version_compare(get_bloginfo('version'), '5.7', '<')) {
110 return $blockname;
111 } else {
112 return $blockPath;
113 }
114 }
115 }
116 Flipbox_Helper::register();
117