Skip to content

Commit

Permalink
fix: imported option "theme_mods_trinity-core" will be updated after …
Browse files Browse the repository at this point in the history
…final import
  • Loading branch information
lgersman committed Feb 2, 2023
1 parent d040821 commit 14b1865
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use cm4all\wp\impex\Impex;
use cm4all\wp\impex\ImpexImport;
use cm4all\wp\impex\ImpexTransformationContext;

require_once(ABSPATH . 'wp-admin/includes/plugin.php');

Expand All @@ -19,5 +20,35 @@

$profile->events(ImpexImport::EVENT_IMPORT_END)->addListener(
'reset ninja forms mainentance mode',
fn () => method_exists('WPN_Helper', 'set_forms_maintenance_mode') && \WPN_Helper::set_forms_maintenance_mode(0)
);
function (ImpexTransformationContext $transformationContext, array $imported) {
if(method_exists('WPN_Helper', 'set_forms_maintenance_mode')) {
\WPN_Helper::set_forms_maintenance_mode(0);
}

// remap old import ids to new ids in option "theme_mods_trinity-core"
if(in_array('theme_mods_trinity-core', $imported['options'])) {
$theme_mods_trinity_core = \get_option('theme_mods_trinity-core');
// remap custom logo if set
$custom_logo = $theme_mods_trinity_core['custom_logo'];
if($custom_logo!==-1 && ($imported['posts'][$custom_logo] ?? false)) {
$theme_mods_trinity_core['custom_logo'] = $imported['posts'][$custom_logo];
}
// remap custom_css_post_id if set
$custom_css_post_id = $theme_mods_trinity_core['custom_css_post_id'];
if($custom_css_post_id!==-1 && ($imported['posts'][$custom_css_post_id] ?? false)) {
$theme_mods_trinity_core['custom_css_post_id'] = $imported['posts'][$custom_css_post_id];
}
// remap nav_menu_locations if set
$nav_menu_locations = $theme_mods_trinity_core['nav_menu_locations'] ?? null;
if($theme_mods_trinity_core['nav_menu_locations'] !== false) {
foreach ($nav_menu_locations as $nav_menu_name => $old_nav_menu_term_id) {
if(array_key_exists($old_nav_menu_term_id, $imported['terms'])) {
$nav_menu_locations[$nav_menu_name] = $imported['terms'][$old_nav_menu_term_id];
}
}
}

\update_option('theme_mods_trinity-core', $theme_mods_trinity_core);
}
},
);

0 comments on commit 14b1865

Please sign in to comment.