| 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 |
|