Created
June 18, 2017 17:25
-
-
Save jessengatai/eb4069b5e1ae2aa7735645e0e073fdd7 to your computer and use it in GitHub Desktop.
A function to help migrate old and outdated theme settings after a theme update
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
<?php | |
/** | |
* This function handles updating old settings that are now outdated and should | |
* only fire on theme updates and activations. | |
* | |
* @since Crush 3.0.7 | |
*/ | |
function jnt_migrate_settings() { | |
/** | |
* CRUSH 3.0.7 <-- theme version purely for reference | |
* | |
* Sidebar_autoheight was a checkbox, but now it's a select and named | |
* slightly differently. If the user HAD it turned on, lets update | |
* the new setting for them and remove the old outdated setting. This | |
* will save them having to do it themselves in the customizer. | |
*/ | |
// first check to make sure the old settings still exists | |
if( isset( get_theme_mod('sidebar_autoheight') ) ) { | |
// the autoheight was on | |
if( get_theme_mod('sidebar_autoheight')==1) { | |
set_theme_mod( 'sidebar_height', 'stretch' ); | |
// the autoheight was off | |
} else { | |
set_theme_mod( 'sidebar_height', 'off' ) { | |
} | |
// delete the old setting and prevent any of this from firing again | |
remove_theme_mod( 'sidebar_autoheight' ); | |
} | |
// now simply keep adding settings that need updating each theme update. | |
} | |
// we want to fire the above function only after a theme activation or update | |
add_action('after_switch_theme','jnt_migrate_settings'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment