| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.13 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Admin; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Media |
| 20 |
{ |
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
if (!is_admin()) |
| 24 |
{ |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
add_action('enqueue_block_editor_assets', [$this, 'block_editor_only_assets']); |
| 29 |
|
| 30 |
add_action('enqueue_block_assets', [$this, 'enqueue_block_assets']); |
| 31 |
|
| 32 |
add_filter('block_editor_settings_all', [$this, 'filterBlockEditorSettings'], 10, 2); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Disable template mode for FireBox campaigns. |
| 37 |
* |
| 38 |
* @param array $settings |
| 39 |
* @param mixed $editor_context |
| 40 |
* |
| 41 |
* @return array |
| 42 |
*/ |
| 43 |
public function filterBlockEditorSettings($settings, $editor_context) |
| 44 |
{ |
| 45 |
if (!is_admin() || !is_array($settings)) |
| 46 |
{ |
| 47 |
return $settings; |
| 48 |
} |
| 49 |
|
| 50 |
if ( |
| 51 |
!is_object($editor_context) || |
| 52 |
!property_exists($editor_context, 'post') || |
| 53 |
!is_object($editor_context->post) || |
| 54 |
!property_exists($editor_context->post, 'post_type') || |
| 55 |
$editor_context->post->post_type !== 'firebox' |
| 56 |
) |
| 57 |
{ |
| 58 |
return $settings; |
| 59 |
} |
| 60 |
|
| 61 |
$settings['supportsTemplateMode'] = false; |
| 62 |
|
| 63 |
return $settings; |
| 64 |
} |
| 65 |
|
| 66 |
public function block_editor_only_assets() |
| 67 |
{ |
| 68 |
if (!is_admin()) |
| 69 |
{ |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
// Enqueue block editor script only in Gutenberg editor |
| 74 |
if (function_exists('get_current_screen')) |
| 75 |
{ |
| 76 |
$screen = get_current_screen(); |
| 77 |
if ($screen->is_block_editor) |
| 78 |
{ |
| 79 |
wp_enqueue_script( |
| 80 |
'firebox-gutenberg-store', |
| 81 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/gutenberg_store.js', |
| 82 |
['wp-data'], |
| 83 |
FBOX_VERSION, |
| 84 |
true |
| 85 |
); |
| 86 |
|
| 87 |
// Required for ProOnlyButton hover icon swap (closed/open lock) across plans. |
| 88 |
wp_enqueue_style( |
| 89 |
'firebox-editor-free', |
| 90 |
FBOX_MEDIA_ADMIN_URL . 'css/editor-free.css', |
| 91 |
[], |
| 92 |
FBOX_VERSION |
| 93 |
); |
| 94 |
|
| 95 |
if ($this->shouldLoadFreeUpgradeModalsScript()) |
| 96 |
{ |
| 97 |
wp_enqueue_script( |
| 98 |
'firebox-plugins-free-modals', |
| 99 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/plugins/free-modals.js', |
| 100 |
[], |
| 101 |
FBOX_VERSION, |
| 102 |
true |
| 103 |
); |
| 104 |
} |
| 105 |
|
| 106 |
if (FBOX_LICENSE_TYPE === 'lite') |
| 107 |
{ |
| 108 |
wp_enqueue_script('firebox-blocks-free', FBOX_MEDIA_ADMIN_URL . 'js/blocks/blocks-free.js', [], FBOX_VERSION, true); |
| 109 |
} |
| 110 |
else if (FBOX_LICENSE_TYPE === 'pro') |
| 111 |
{ |
| 112 |
wp_enqueue_script('firebox-blocks-pro', FBOX_MEDIA_ADMIN_URL . 'js/blocks/blocks-pro.js', [], FBOX_VERSION, true); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Loads Gutenberg editor assets |
| 120 |
* |
| 121 |
* @return void |
| 122 |
*/ |
| 123 |
public function enqueue_block_assets() |
| 124 |
{ |
| 125 |
if (!is_admin()) |
| 126 |
{ |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
// Enqueue block editor script only in Gutenberg editor |
| 131 |
if (function_exists('get_current_screen')) |
| 132 |
{ |
| 133 |
$screen = get_current_screen(); |
| 134 |
if ($screen->is_block_editor) |
| 135 |
{ |
| 136 |
wp_enqueue_code_editor(['type' => 'text/css']); |
| 137 |
wp_enqueue_code_editor(['type' => 'javascript']); |
| 138 |
|
| 139 |
// Add the block editor styling for our blocks |
| 140 |
wp_enqueue_style( |
| 141 |
'firebox-blocks-editor-styles', |
| 142 |
FBOX_MEDIA_ADMIN_URL . 'css/admin/blocks.css', |
| 143 |
[], |
| 144 |
FBOX_VERSION |
| 145 |
); |
| 146 |
|
| 147 |
// Add the FireBox block editor script only to FireBox post type |
| 148 |
if (get_post_type() === 'firebox') |
| 149 |
{ |
| 150 |
wp_enqueue_script( |
| 151 |
'firebox-gutenberg-store', |
| 152 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/gutenberg_store.js', |
| 153 |
['wp-data'], |
| 154 |
FBOX_VERSION, |
| 155 |
true |
| 156 |
); |
| 157 |
|
| 158 |
// FireBox main CSS file |
| 159 |
wp_enqueue_style( |
| 160 |
'firebox', |
| 161 |
FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css', |
| 162 |
[], |
| 163 |
FBOX_VERSION |
| 164 |
); |
| 165 |
|
| 166 |
wp_enqueue_style( |
| 167 |
'firebox-animations', |
| 168 |
FBOX_MEDIA_PUBLIC_URL . 'css/vendor/animate.min.css', |
| 169 |
[], |
| 170 |
FBOX_VERSION |
| 171 |
); |
| 172 |
|
| 173 |
wp_enqueue_style( |
| 174 |
'firebox-block-editor', |
| 175 |
FBOX_MEDIA_ADMIN_URL . 'css/block-editor.css', |
| 176 |
[], |
| 177 |
FBOX_VERSION |
| 178 |
); |
| 179 |
|
| 180 |
// Load the Phone Number widget styles on this hook so WordPress injects |
| 181 |
// them into the editor iframe canvas (enqueue_block_editor_assets does not). |
| 182 |
\FPFramework\Base\Widgets\PhoneNumber::register_assets(); |
| 183 |
wp_enqueue_style('fpframework-widget'); |
| 184 |
wp_enqueue_style('fpframework-phonenumber-widget'); |
| 185 |
|
| 186 |
wp_enqueue_script( |
| 187 |
'firebox-editor', |
| 188 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/editor.js', |
| 189 |
['wp-edit-post'], |
| 190 |
FBOX_VERSION, |
| 191 |
false |
| 192 |
); |
| 193 |
|
| 194 |
wp_enqueue_script( |
| 195 |
'firebox-slotfills-general', |
| 196 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/slotfills/general.js', |
| 197 |
[], |
| 198 |
FBOX_VERSION, |
| 199 |
true |
| 200 |
); |
| 201 |
|
| 202 |
// Required for ProOnlyButton hover icon swap (closed/open lock) across plans. |
| 203 |
wp_enqueue_style( |
| 204 |
'firebox-editor-free', |
| 205 |
FBOX_MEDIA_ADMIN_URL . 'css/editor-free.css', |
| 206 |
[], |
| 207 |
FBOX_VERSION |
| 208 |
); |
| 209 |
|
| 210 |
if ($this->shouldLoadFreeUpgradeModalsScript()) |
| 211 |
{ |
| 212 |
wp_enqueue_script( |
| 213 |
'firebox-plugins-free-modals', |
| 214 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/plugins/free-modals.js', |
| 215 |
[], |
| 216 |
FBOX_VERSION, |
| 217 |
true |
| 218 |
); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
if (FBOX_LICENSE_TYPE === 'lite') |
| 223 |
{ |
| 224 |
wp_enqueue_script( |
| 225 |
'firebox-slotfills-free', |
| 226 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/slotfills/free.js', |
| 227 |
[], |
| 228 |
FBOX_VERSION, |
| 229 |
true |
| 230 |
); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
$integrations_registry = \FireBox\Core\Helpers\Integrations::getFormEditorIntegrationsRegistry(); |
| 240 |
$integration_connections = []; |
| 241 |
foreach ($integrations_registry as $integration) |
| 242 |
{ |
| 243 |
if (!is_array($integration) || empty($integration['slug'])) |
| 244 |
{ |
| 245 |
continue; |
| 246 |
} |
| 247 |
|
| 248 |
$integration_connections[$integration['slug']] = !empty($integration['connected']); |
| 249 |
} |
| 250 |
|
| 251 |
$data = [ |
| 252 |
'google_fonts' => \FPFramework\Libs\GoogleFonts::getFonts(), |
| 253 |
'google_fonts_names' => \FPFramework\Libs\GoogleFonts::getFontsNames(), |
| 254 |
'icons' => \FireBox\Core\Libs\Icons::getAll(), |
| 255 |
'turnstile_site_key' => \FireBox\Core\Helpers\Captcha\Turnstile::getSiteKey(), |
| 256 |
'has_turnstile_secret_key' => (string) \FireBox\Core\Helpers\Captcha\Turnstile::getSecretKey() !== '', |
| 257 |
'hcaptcha_site_key' => \FireBox\Core\Helpers\Captcha\HCaptcha::getSiteKey(), |
| 258 |
'has_hcaptcha_secret_key' => (string) \FireBox\Core\Helpers\Captcha\HCaptcha::getSecretKey() !== '', |
| 259 |
'settings_url' => admin_url('admin.php?page=firebox-settings'), |
| 260 |
'integrations_registry' => $integrations_registry, |
| 261 |
'integration_connections' => $integration_connections, |
| 262 |
'license_type' => defined('FBOX_LICENSE_TYPE') ? FBOX_LICENSE_TYPE : '', |
| 263 |
'license_plan' => defined('FBOX_LICENSE_PLAN') ? FBOX_LICENSE_PLAN : '', |
| 264 |
'media_url' => FBOX_MEDIA_URL, |
| 265 |
|
| 266 |
]; |
| 267 |
|
| 268 |
wp_register_script('firebox-block-editor-script', false); |
| 269 |
wp_enqueue_script('firebox-block-editor-script'); |
| 270 |
wp_localize_script('firebox-block-editor-script', 'fbox_block_editor_object', $data); |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
private function shouldLoadFreeUpgradeModalsScript() |
| 276 |
{ |
| 277 |
$license_type = defined('FBOX_LICENSE_TYPE') ? strtolower(trim((string) FBOX_LICENSE_TYPE)) : ''; |
| 278 |
$license_plan = defined('FBOX_LICENSE_PLAN') ? strtolower(trim((string) FBOX_LICENSE_PLAN)) : ''; |
| 279 |
|
| 280 |
return $license_type === 'lite' || in_array($license_plan, ['free', 'basic'], true); |
| 281 |
} |
| 282 |
} |
| 283 |
|