Skip to content

Instantly share code, notes, and snippets.

@BoweFrankema
Created October 13, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BoweFrankema/de6db7889885c7aec04a to your computer and use it in GitHub Desktop.
Save BoweFrankema/de6db7889885c7aec04a to your computer and use it in GitHub Desktop.
starter-settings.php
<?php
function wefoster_import_starter_settings() {
$screen = get_current_screen();
if (strpos($screen->id, "acf-options-starter-kits") == true) {
// Check to see if the settings have already been imported.
$starterkit = get_field( "choose_a_starter_kit", 'option' );
$template = get_template();
$imported = get_option( $template . '_' . $starterkit . '_customizer_import', false );
// Get the path to the customizer export file.
$path = WEFOSTER_PLUS_PLUGIN_DIR . 'starter-kits/settings/' . $starterkit . '.dat';
// Return if the file doesn't exist.
if ( ! file_exists( $path ) ) {
return;
}
// Get the settings data.
$data = @unserialize( file_get_contents( $path ) );
// Return if something is wrong with the data.
if ( 'array' != gettype( $data ) || ! isset( $data['mods'] ) ) {
return;
}
// Import options.
if ( isset( $data['options'] ) ) {
foreach ( $data['options'] as $option_key => $option_value ) {
update_option( $option_key, $option_value );
}
}
// Import mods.
foreach ( $data['mods'] as $key => $val ) {
set_theme_mod( $key, $val );
}
}
}
add_action('acf/save_post', 'wefoster_import_starter_settings', 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment