-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANET-7047: Migrate Donate button setting to a menu (#2076)
* Ref: https://jira.greenpeace.org/browse/PLANET-7047 Migrate Donate button settings - Create a new term if not exists - Remove donate button settings page - Unset donate settings from planet4_options - Remove default donate settings within the context - Update desktop and mobile templates --------- Co-authored-by: Dan Tovbein <[email protected]>
- Loading branch information
1 parent
889c572
commit 0547c5e
Showing
5 changed files
with
74 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace P4\MasterTheme\Migrations; | ||
|
||
use P4\MasterTheme\MigrationRecord; | ||
use P4\MasterTheme\MigrationScript; | ||
|
||
/** | ||
* Migrate Donate button setting to a menu. | ||
*/ | ||
class M018MigrateDonateButtonSetting extends MigrationScript | ||
{ | ||
/** | ||
* Perform the actual migration. | ||
* | ||
* @param MigrationRecord $record Information on the execution, can be used to add logs. | ||
* phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter -- interface implementation | ||
*/ | ||
protected static function execute(MigrationRecord $record): void | ||
{ | ||
global $wpdb; | ||
|
||
$donate_menu_slug = 'donate-menu'; | ||
$option_key = 'planet4_options'; | ||
|
||
$sql = 'SELECT t.term_id FROM wp_terms AS t WHERE t.slug="%s"'; | ||
$prepared_sql = $wpdb->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters