| @@ -11,28 +11,8 @@ | ||
| 11 | 11 | */ |
| 12 | 12 | class SiteNavigationController |
| 13 | 13 | { |
| 14 | 14 | /** |
| 15 | - * Initialize the controller to add filters and actions. | |
| 16 | - * | |
| 17 | - * @return void | |
| 18 | - */ | |
| 19 | - public static function init() | |
| 20 | - { | |
| 21 | - \add_filter('render_block', function ($block_content, $block) { | |
| 22 | - if ($block['blockName'] === 'core/navigation' && array_key_exists('ref', $block['attrs'])) { | |
| 23 | - // Add the id of the menu to the menu itself | |
| 24 | - $block_content = str_replace( | |
| 25 | - '<nav', | |
| 26 | - '<nav data-extendify-menu-id="' . $block['attrs']['ref'] . '"', | |
| 27 | - $block_content | |
| 28 | - ); | |
| 29 | - } | |
| 30 | - return $block_content; | |
| 31 | - }, 10, 2); | |
| 32 | - } | |
| 33 | - | |
| 34 | - /** | |
| 35 | 15 | * Get a list of published navigation items from the site. |
| 36 | 16 | * |
| 37 | 17 | * @param \WP_REST_Request $request The REST API request |
| 38 | 18 | * @return \WP_REST_Response. |
| @@ -52,48 +32,6 @@ | ||
| 52 | 32 | "name" => $item->post_title, |
| 53 | 33 | "content" => $item->post_content |
| 54 | 34 | ]; |
| 55 | 35 | }, $navigation), 200); |
| 56 | - } | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * Render the navigation menu content based on the provided menu ID. | |
| 60 | - * | |
| 61 | - * @param \WP_REST_Request $request The REST API request | |
| 62 | - * @return string The rendered navigation menu content. | |
| 63 | - */ | |
| 64 | - public static function renderNavigationMenu($request) | |
| 65 | - { | |
| 66 | - if (!$request->get_param('content')) { | |
| 67 | - return ''; | |
| 68 | - } | |
| 69 | - | |
| 70 | - add_filter('render_block_core/navigation', function ($content, $block) { | |
| 71 | - if (empty($block['attrs']['extendifyMenuId'])) { | |
| 72 | - return $content; | |
| 73 | - } | |
| 74 | - $menu_id = $block['attrs']['extendifyMenuId']; | |
| 75 | - | |
| 76 | - return str_replace( | |
| 77 | - 'data-extendify-menu-id=""', | |
| 78 | - 'data-extendify-menu-id="' . esc_attr($menu_id) . '"', | |
| 79 | - $content | |
| 80 | - ); | |
| 81 | - }, 10, 2); | |
| 82 | - | |
| 83 | - | |
| 84 | - $nav_block = [ | |
| 85 | - "blockName" => "core/navigation", | |
| 86 | - "attrs" => [ | |
| 87 | - "icon" => "menu", | |
| 88 | - "overlayBackgroundColor" => "background", | |
| 89 | - "overlayTextColor" => "foreground", | |
| 90 | - "extendifyMenuId" => 5, | |
| 91 | - ], | |
| 92 | - "innerBlocks" => parse_blocks($request->get_param('content')), | |
| 93 | - "innerHTML" => "", | |
| 94 | - "innerContent" => [] | |
| 95 | - ]; | |
| 96 | - | |
| 97 | - return render_block($nav_block); | |
| 98 | 36 | } |
| 99 | 37 | } |