diff --git a/src/MasterSite.php b/src/MasterSite.php index b126f0d3e2..11aa29720b 100644 --- a/src/MasterSite.php +++ b/src/MasterSite.php @@ -587,27 +587,16 @@ function ($item) { } ); - $donate_menu_default[] = [ - 'link' => planet4_get_option('donate_button', '#'), - 'title' => planet4_get_option('donate_text', __('Donate', 'planet4-master-theme')), - ]; - - // Donate button menu dropdown. - // If no Donate menu is defined, we use the old settings from Planet 4 > Donate. - $donate_menu_items = $donate_menu_default; - // Check if the menu has been created. if (has_nav_menu('donate-menu')) { $donate_menu = new TimberMenu('donate-menu'); // Check if it has at least 1 item added into the menu. if (! empty($donate_menu->get_items())) { - $donate_menu_items = $donate_menu->get_items(); + $context['donate_menu_items'] = $donate_menu->get_items(); } } - $context['donate_menu_default'] = $donate_menu_default; - $context['donate_menu_items'] = $donate_menu_items; $languages = function_exists('icl_get_languages') ? icl_get_languages() : []; $context['site_languages'] = $languages; @@ -651,8 +640,6 @@ function ($item) { $context['p4_visitor_type'] = 'guest'; } - $context['donatelink'] = $options['donate_button'] ?? '#'; - $context['donatetext'] = $options['donate_text'] ?? __('Donate', 'planet4-master-theme'); $context['website_navbar_title'] = $options['website_navigation_title'] ?? __('International (English)', 'planet4-master-theme'); diff --git a/src/Migrations/M018MigrateDonateButtonSetting.php b/src/Migrations/M018MigrateDonateButtonSetting.php new file mode 100644 index 0000000000..7e1ad6df8a --- /dev/null +++ b/src/Migrations/M018MigrateDonateButtonSetting.php @@ -0,0 +1,69 @@ +prepare($sql, array($donate_menu_slug)); + $results = $wpdb->get_results($prepared_sql); + + if (count($results)) { + return; + } + + $term = wp_insert_term( + 'Donate Menu', + 'nav_menu', + [ + 'slug' => $donate_menu_slug, + ], + ); + + if (is_wp_error($term) || !isset($term['term_id'])) { + return; + } + + $term_id = $term['term_id']; + + $options = get_option($option_key); + + wp_update_nav_menu_item( + $term_id, + 0, + [ + 'menu-item-title' => $options['donate_text'], + 'menu-item-url' => $options['donate_button'], + 'menu-item-status' => 'publish', + 'menu-item-type' => 'custom', + ], + ); + + $nav_menu_locations = get_theme_mod('nav_menu_locations'); + $nav_menu_locations[$donate_menu_slug] = (int) $term['term_id']; + set_theme_mod('nav_menu_locations', $nav_menu_locations); + + unset($options['donate_text']); + unset($options['donate_button']); + update_option($option_key, $options); + } +} diff --git a/src/Migrator.php b/src/Migrator.php index c853e5830c..fa83364f4a 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -19,6 +19,7 @@ use P4\MasterTheme\Migrations\M015RemoveListingPagesBackgroundImage; use P4\MasterTheme\Migrations\M016CreateDefaultActionType; use P4\MasterTheme\Migrations\M017NewIAToggle; +use P4\MasterTheme\Migrations\M018MigrateDonateButtonSetting; /** * Run any new migration scripts and record results in the log. @@ -55,6 +56,7 @@ public static function migrate(): void M015RemoveListingPagesBackgroundImage::class, M016CreateDefaultActionType::class, M017NewIAToggle::class, + M018MigrateDonateButtonSetting::class, ]; // Loop migrations and run those that haven't run yet. diff --git a/src/Settings.php b/src/Settings.php index dc495a374c..25737f10c2 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -99,28 +99,6 @@ public function __construct() ], ], ], - 'planet4_settings_donate_button' => [ - 'title' => 'Donate button', - 'fields' => [ - [ - 'name' => __('Donate button link', 'planet4-master-theme-backend'), - 'id' => 'donate_button', - 'type' => 'text', - 'attributes' => [ - 'type' => 'text', - ], - ], - - [ - 'name' => __('Donate button text', 'planet4-master-theme-backend'), - 'id' => 'donate_text', - 'type' => 'text', - 'attributes' => [ - 'type' => 'text', - ], - ], - ], - ], 'planet4_settings_defaults_content' => [ 'title' => 'Defaults content', 'fields' => [ diff --git a/templates/burger-menu.twig b/templates/burger-menu.twig index 85ed3fc596..5ba1e821a4 100644 --- a/templates/burger-menu.twig +++ b/templates/burger-menu.twig @@ -49,11 +49,11 @@