Closed nicolas92 closed 7 years ago
Hi nicolas92, you're welcome!
There isn't a filter for that but one could be added here if you wanted to submit a pull request.
I can certainly added it but it might be a few weeks before getting to an update for this plugin.
Hello, thank you very much for your answer, but it is not necessary, I just realized that it import the settings, so I do not need to do this.
I have a question, I hope you will be able to help me.
I created a free theme with several demos to present the theme, I created a one click demo import, so I took the import function of your plugin:
function import_customizer_options( $import_file_path ) {
// Setup global vars.
global $wp_customize;
// Setup internal vars.
$template = get_template();
// Make sure we have an import file.
if ( ! file_exists( $import_file_path ) ) {
return new WP_Error(
'missing_cutomizer_import_file',
sprintf(
esc_html__( 'The customizer import file is missing! File path: %s', 'demo-import' ),
$import_file_path
)
);
}
// Get the upload data.
$raw = file_get_contents( $import_file_path );
// Make sure we got the data.
if ( is_wp_error( $raw ) ) {
return $raw;
}
$data = unserialize( $raw );
// Data checks.
if ( ! is_array( $data ) && ( ! isset( $data['template'] ) || ! isset( $data['mods'] ) ) ) {
return new WP_Error(
'customizer_import_data_error',
esc_html__( 'The customizer import file is not in a correct format. Please make sure to use the correct customizer import file.', 'demo-import' )
);
}
if ( $data['template'] !== $template ) {
return new WP_Error(
'customizer_import_wrong_theme',
esc_html__( 'The customizer import file is not suitable for current theme. You can only import customizer settings for the same theme or a child theme.', 'demo-import' )
);
}
// Import images.
$data['mods'] = self::import_customizer_images( $data['mods'] );
// Import custom options.
if ( isset( $data['options'] ) ) {
// Require modified customizer options class.
if ( ! class_exists( 'WP_Customize_Setting' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-customize-setting.php';
}
require ODI_PATH . '/includes/class/class-customizer-option.php';
foreach ( $data['options'] as $option_key => $option_value ) {
$option = new ODI_Customizer_Option( $wp_customize, $option_key, array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$option->import( $option_value );
}
}
// Loop through the mods.
foreach ( $data['mods'] as $key => $val ) {
// Save the mod.
set_theme_mod( $key, $val );
}
}
But I have a small problem, I would import the dat file exported with your plugin from a github url, so "https://raw.githubusercontent.com/site/sample-data/master/options.dat", the problem Is that it does not work, if I import the file locally (since my plugin), it works perfectly but not with the github url, I'm sure it must be very easy to solve but I have not found how make.
For the xml file for the content and json for the widgets, it works very well from the github url, there is only the dat file of the options of the customizer that I can not seem to recover.
Can you help me?
Thank you a lot :)
Hi @fastlinemedia, any idea? Thank you.
Apologies for the delay. The issue is that function is expecting a file path, not a URL.
You'll need to rework the if ( ! file_exists( $import_file_path ) ) {
check and possibly the $raw = file_get_contents( $import_file_path );
call as file_get_contents
doesn't always work with URLs.
Hello, I solved the problem, I put the file locally and it works very well. Thank you very much :)
Great!
Hello, I have a question. First of all, thanks for this plugin, it is great :) I would like to know if it is possible not to export in the dat file some option "get_theme_mod"? I created a tab in the wordpress admin that has nothing to do with the customizer so I would not like it to be exported to the dat file.
Can you tell me if there is a filter to do this?
Thank you very much.