PluginProbe
Toggle Content / trunk
Toggle Content 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.2.6 1.2.8 1.3.0
toggle-content / includes / helpers.php

helpers.php in Toggle Content trunk, at includes/helpers.php

136 lines 4.5 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 Toggle_Content_Helper
13 {
14
15
16 private static $instance;
17
18 /**
19 * Registers the plugin.
20 */
21 public static function register()
22 {
23 if (null === self::$instance) {
24 self::$instance = new self;
25 }
26 return self::$instance;
27 }
28
29 /**
30 * The Constructor.
31 */
32 public function __construct()
33 {
34 add_action('admin_enqueue_scripts', array($this, 'enqueues'));
35 }
36
37 /**
38 * Load fonts.
39 *
40 * @access public
41 */
42 public function enqueues()
43 {
44 global $pagenow;
45
46 /**
47 * Only for admin add/edit pages/posts
48 */
49 $query_string = isset($_SERVER['QUERY_STRING'])
50 ? sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING']))
51 : '';
52
53 if ($pagenow == 'post-new.php' || $pagenow == 'post.php' || $pagenow == 'site-editor.php' || ($pagenow == 'themes.php' && !empty($query_string) && str_contains($query_string, 'gutenberg-edit-site'))) {
54
55 $controls_asset_path = TOGGLE_CONTENT_ADMIN_PATH . '/dist/modules.asset.php';
56 if (!file_exists($controls_asset_path)) {
57 return;
58 }
59
60 // `require`, not `include_once`: a second `*_once` include returns bool,
61 // which would make the array offsets below fatal on PHP 8.
62 $controls_dependencies = require $controls_asset_path;
63 if (!is_array($controls_dependencies)) {
64 $controls_dependencies = array();
65 }
66 $controls_deps = isset($controls_dependencies['dependencies']) && is_array($controls_dependencies['dependencies'])
67 ? $controls_dependencies['dependencies']
68 : array();
69 $controls_version = isset($controls_dependencies['version'])
70 ? $controls_dependencies['version']
71 : TOGGLE_CONTENT_VERSION;
72
73 wp_register_script(
74 "toggle-content-controls-util",
75 TOGGLE_CONTENT_ADMIN_URL . 'dist/modules.js',
76 $controls_deps,
77 $controls_version,
78 true
79 );
80
81 /**
82 * Keys consumed by the bundled controls (dist/modules.js).
83 *
84 * `responsiveBreakpoints` is read by StyleComponent to wrap the editor
85 * preview styles in media queries. When it is missing the queries become
86 * `max-width: undefinedpx`, which is invalid CSS, so the whole tablet and
87 * mobile block is dropped and responsive settings look like they do
88 * nothing in the editor.
89 *
90 * The values must match the breakpoints the style-handler hardcodes when
91 * it builds the frontend stylesheet, otherwise the editor preview and the
92 * frontend disagree about where a breakpoint starts.
93 */
94 wp_localize_script('toggle-content-controls-util', 'EssentialBlocksLocalize', array(
95 'eb_wp_version' => (float) get_bloginfo('version'),
96 'rest_rootURL' => get_rest_url(),
97 'fontAwesome' => "true",
98 'googleFont' => "true",
99 'responsiveBreakpoints' => array(
100 'tablet' => 1024,
101 'mobile' => 767,
102 ),
103 ));
104
105 if ($pagenow == 'post-new.php' || $pagenow == 'post.php') {
106 wp_localize_script('toggle-content-controls-util', 'eb_conditional_localize', array(
107 'editor_type' => 'edit-post'
108 ));
109 } else if ($pagenow == 'site-editor.php' || $pagenow == 'themes.php') {
110 wp_localize_script('toggle-content-controls-util', 'eb_conditional_localize', array(
111 'editor_type' => 'edit-site'
112 ));
113 }
114
115 wp_enqueue_style(
116 'toggle-content-editor-css',
117 TOGGLE_CONTENT_ADMIN_URL . 'dist/modules.css',
118 array(),
119 $controls_version,
120 'all'
121 );
122 }
123 }
124
125 public static function get_block_register_path($blockname, $blockPath)
126 {
127 // Unreachable below WP 6.0 (declared floor); kept as a defensive fallback.
128 if ((float) get_bloginfo('version') <= 5.6) {
129 return $blockname;
130 } else {
131 return $blockPath;
132 }
133 }
134 }
135 Toggle_Content_Helper::register();
136