-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add class to update customizer fields from old versions
- Loading branch information
1 parent
0d0c2a6
commit 81ca3ac
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* | ||
* | ||
* @package ColetivoWP_Update_Customizer | ||
* @author Matheus Gimenez <contato@matheusgimenez.com.br> | ||
* @license GPL-2.0+ | ||
* @copyright 2017 Matheus Gimenez | ||
* | ||
* @wordpress-plugin | ||
* Description: ColetivoWP_Update_Customizer | ||
* Version: 0.1 | ||
* Author: Matheus Gimenez | ||
* Text Domain: custom-roles | ||
* License: GPL-2.0+ | ||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | ||
* Domain Path: /languages | ||
*/ | ||
|
||
// If this file is called directly, abort. | ||
if ( ! defined( 'ABSPATH' ) ) exit; | ||
|
||
class ColetivoWP_Update_Customizer { | ||
/** | ||
/** | ||
* Init Plugin class | ||
*/ | ||
public function __construct() { | ||
add_action( 'admin_init', array( $this, 'update_theme_mod') ); | ||
} | ||
/** | ||
* Change "onepress" to "coletivo" in customizer fields | ||
* @return type | ||
*/ | ||
public function update_theme_mod() { | ||
if ( 'true' === get_option( 'tema_coletivo_updated_customizer', false ) ) { | ||
return; | ||
} | ||
$customizer_fields = get_option( 'theme_mods_tema-coletivo'); | ||
foreach ( $customizer_fields as $key => $value ) { | ||
if ( false === strpos( $key, 'onepress' ) ) { | ||
continue; | ||
} | ||
$new_key = str_replace( 'onepress', 'coletivo', $key ); | ||
$customizer_fields[ $new_key ] = $value; | ||
unset( $customizer_fields[ $key ] ); | ||
} | ||
update_option( 'theme_mods_tema-coletivo', $customizer_fields ); | ||
update_option( 'tema_coletivo_updated_customizer', 'true' ); | ||
} | ||
} | ||
new ColetivoWP_Update_Customizer(); |