PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
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 0.7.0 All 126 releases
extendify / app / QuickEdit / Services / IdentityTagger.php

IdentityTagger.php in Extendify 3.1.5, at app/QuickEdit/Services/IdentityTagger.php

52 lines 1.6 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\Services;
4
5 defined('ABSPATH') || die('No direct access.');
6
7 // Routes Quick Edit clicks on site-title/tagline/logo to SiteIdentityModal
8 // instead of the BlockTextEditor (those values live in wp_options).
9 class IdentityTagger
10 {
11 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility
12 const ATTR = 'data-extendify-quick-edit-identity';
13
14 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility
15 const KIND_BY_BLOCK = [
16 'core/site-title' => 'title',
17 'core/site-tagline' => 'tagline',
18 'core/site-logo' => 'logo',
19 ];
20
21 public static function init()
22 {
23 add_filter('render_block', [self::class, 'tag'], 12, 2);
24 }
25
26 public static function tag($html, $block)
27 {
28 if (is_admin() || !is_string($html) || $html === '') {
29 return $html;
30 }
31 // Don't bloat anonymous-viewer HTML with markers they can't act on.
32 if (!is_user_logged_in() || !current_user_can('manage_options')) {
33 return $html;
34 }
35 $name = $block['blockName'] ?? '';
36 $kind = self::KIND_BY_BLOCK[$name] ?? null;
37 if (!$kind) {
38 return $html;
39 }
40 $tp = new \WP_HTML_Tag_Processor($html);
41 if (!$tp->next_tag()) {
42 return $html;
43 }
44 // Some pipelines re-fire render_block; avoid double-tagging.
45 if ($tp->get_attribute(self::ATTR) !== null) {
46 return $html;
47 }
48 $tp->set_attribute(self::ATTR, $kind);
49 return $tp->get_updated_html();
50 }
51 }
52