PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / QuickEdit / Frontend.php

Frontend.php in Extendify 3.1.4, at app/QuickEdit/Frontend.php

177 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Extendify\QuickEdit;
4
5 defined('ABSPATH') || die('No direct access.');
6
7 use Extendify\Config;
8 use Extendify\PartnerData;
9 use Extendify\QuickEdit\Controllers\SaveController;
10 use Extendify\QuickEdit\Controllers\SiteIdentityController;
11 use Extendify\QuickEdit\Controllers\WCProductController;
12 use Extendify\QuickEdit\Controllers\WPFormsController;
13 use Extendify\QuickEdit\Controllers\WPNavigationController;
14 use Extendify\QuickEdit\Schemas\Registry;
15 use Extendify\QuickEdit\Services\IdentityTagger;
16 use Extendify\QuickEdit\Services\MediaTextTagger;
17 use Extendify\QuickEdit\Services\NavRefTagger;
18 use Extendify\QuickEdit\Services\TranslatedContext;
19 use Extendify\QuickEdit\Services\WCProductTagger;
20 use Extendify\QuickEdit\Services\WPFormsTagger;
21
22 class Frontend
23 {
24 public function __construct()
25 {
26 Registry::init();
27 SaveController::init();
28 SiteIdentityController::init();
29 WCProductController::init();
30 WPNavigationController::init();
31 WPFormsController::init();
32 IdentityTagger::init();
33 WCProductTagger::init();
34 NavRefTagger::init();
35 WPFormsTagger::init();
36 MediaTextTagger::init();
37
38 // TagBlocks + TagTemplateParts are initialized by Agent\Admin.
39 add_action('wp_enqueue_scripts', [$this, 'enqueue']);
40 add_action('admin_bar_menu', [$this, 'registerAdminBar'], 100);
41 }
42
43 /**
44 * Whether inline Quick Edit surfaces are enabled for this install —
45 * the showQuickEdit partner flag or the matching preview opt-in.
46 *
47 * @return boolean
48 */
49 public static function quickEditEnabled(): bool
50 {
51 return (bool) (PartnerData::setting('showQuickEdit') || Config::preview('quick-edit'));
52 }
53
54 public function registerAdminBar($bar)
55 {
56 if (is_admin() || !is_user_logged_in() || !current_user_can(Config::$requiredCapability)) {
57 return;
58 }
59 if (!self::quickEditEnabled()) {
60 return;
61 }
62 $bar->add_node([
63 'id' => 'extendify-quick-edit-toggle',
64 'title' => '<span class="extendify-quick-edit-toggle-pill" aria-hidden="true">'
65 . '<span class="extendify-quick-edit-toggle-thumb"></span></span>'
66 . '<span class="extendify-quick-edit-toggle-label">'
67 . esc_html__('Quick Edit', 'extendify-local')
68 . '</span>',
69 'href' => '#',
70 'meta' => [
71 'role' => 'switch',
72 'aria-label' => esc_attr__('Quick Edit', 'extendify-local'),
73 ],
74 ]);
75 }
76
77 public function enqueue()
78 {
79 // The Customizer preview iframe is a front-end render (is_admin() false),
80 // so QE would otherwise enqueue and mount inside it — bail before then.
81 if (!current_user_can(Config::$requiredCapability) || is_admin() || is_customize_preview()) {
82 return;
83 }
84
85 $version = constant('EXTENDIFY_DEVMODE') ? (string) time() : Config::$version;
86 $manifest = Config::$assetManifest;
87 $assetMeta = $manifest['extendify-quick-edit.php'] ?? null;
88 $jsFile = $manifest['extendify-quick-edit.js'] ?? null;
89 $cssFile = $manifest['extendify-quick-edit.css'] ?? null;
90 if (!$assetMeta || !$jsFile) {
91 return;
92 }
93 $assetPath = EXTENDIFY_PATH . 'public/build/' . $assetMeta;
94 $asset = file_exists($assetPath)
95 ? require $assetPath
96 : ['dependencies' => [], 'version' => $version];
97
98 $jsHandle = 'extendify-quick-edit';
99 // wp-format-library isn't auto-detected — we access wp.formatLibrary
100 // at runtime to avoid invalid build-module/* handles.
101 $deps = array_merge(
102 $asset['dependencies'] ?? [],
103 ['wp-format-library']
104 );
105 wp_enqueue_script(
106 $jsHandle,
107 EXTENDIFY_BASE_URL . 'public/build/' . $jsFile,
108 $deps,
109 $asset['version'] ?? $version,
110 true
111 );
112 wp_set_script_translations($jsHandle, 'extendify-local', EXTENDIFY_PATH . 'languages/js');
113
114 if ($cssFile) {
115 wp_enqueue_style(
116 $jsHandle,
117 EXTENDIFY_BASE_URL . 'public/build/' . $cssFile,
118 [],
119 $asset['version'] ?? $version
120 );
121 }
122
123 // Required for BlockEditor canvas + toolbar styling.
124 wp_enqueue_style('wp-components');
125 wp_enqueue_style('wp-block-editor');
126 wp_enqueue_style('wp-block-library');
127 wp_enqueue_style('wp-format-library');
128 wp_enqueue_media();
129
130 global $post;
131 $sourceForCurrentPost = ($post instanceof \WP_Post)
132 ? ['kind' => 'post', 'id' => $post->ID]
133 : null;
134
135 $context = ['currentSource' => $sourceForCurrentPost];
136 if (function_exists('get_woocommerce_currency_symbol')) {
137 // WC returns HTML entities for some currencies (e.g. ₹ as
138 // `&#8377;`); the price modal renders it as React text, so
139 // decode before shipping.
140 $context['currencySymbol'] = html_entity_decode(
141 get_woocommerce_currency_symbol(),
142 ENT_QUOTES,
143 'UTF-8'
144 );
145 }
146
147 // EXTENDIFY_QUICK_EDIT_DEBUG (wp-config constant) or ?qe-debug=1 turns
148 // on selector-layer console traces — used to repro the "second block
149 // selected" report without shipping logs in prod builds.
150 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
151 $debug = (defined('EXTENDIFY_QUICK_EDIT_DEBUG') && constant('EXTENDIFY_QUICK_EDIT_DEBUG'))
152 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
153 || (isset($_GET['qe-debug']) && $_GET['qe-debug'] === '1');
154
155 // QE off (showQuickEdit) keeps the selector bundle loaded for Ask AI
156 // but suppresses every inline-edit surface: no auto-on post-Launch
157 // (the agent's Select button is the entry point then) and the
158 // hover/keyboard pills gate on quickEditEnabled.
159 $quickEditEnabled = self::quickEditEnabled();
160
161 wp_add_inline_script(
162 $jsHandle,
163 'window.extQuickEditData = ' . wp_json_encode([
164 'restRoot' => esc_url_raw(rest_url('extendify/v1')),
165 'nonce' => wp_create_nonce('wp_rest'),
166 'schemas' => Registry::describe(),
167 'context' => $context,
168 'translatedContext' => TranslatedContext::detect(),
169 'quickEditEnabled' => $quickEditEnabled,
170 'defaultOn' => ((bool) constant('EXTENDIFY_DEVMODE') || Config::$launchCompleted) && $quickEditEnabled,
171 'debug' => $debug,
172 ]) . ';',
173 'before'
174 );
175 }
176 }
177