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