PluginProbe
Extendify / 3.2.0
Extendify v3.2.0
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 / Schemas / NavigationLink.php

NavigationLink.php in Extendify 3.2.0, at app/QuickEdit/Schemas/NavigationLink.php

51 lines 1.4 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\Schemas;
4
5 defined('ABSPATH') || die('No direct access.');
6
7 // Nav links inside a core/navigation with a `ref` attribute live in a
8 // wp_navigation post, not post_content; not yet supported. Inline
9 // core/navigation-link children of an inline core/navigation work normally.
10 class NavigationLink implements Schema
11 {
12 public function fields(): array
13 {
14 return [
15 [
16 'key' => 'label',
17 'control' => 'text',
18 'label' => __('Label', 'extendify-local'),
19 ],
20 [
21 'key' => 'url',
22 'control' => 'link',
23 'label' => __('Destination', 'extendify-local'),
24 ],
25 ];
26 }
27
28 public function apply(array $block, string $fieldKey, $value): array
29 {
30 $attrs = $block['attrs'] ?? [];
31 switch ($fieldKey) {
32 case 'label':
33 $label = is_string($value) ? wp_strip_all_tags($value) : '';
34 $attrs['label'] = $label;
35 break;
36 case 'url':
37 $url = is_string($value) ? esc_url_raw($value) : '';
38 if ($url === '') {
39 unset($attrs['url']);
40 } else {
41 $attrs['url'] = $url;
42 }
43 break;
44 default:
45 return $block;
46 }
47 $block['attrs'] = $attrs;
48 return $block;
49 }
50 }
51