Example #1
0
 /**
  * Imports uploaded mods and calls WordPress core customize_save actions so
  * themes that hook into them can act before mods are saved to the database.
  *
  * @since 0.1
  * @since 0.3 Added $wp_customize param and importing of options.
  * @access private
  * @param object $wp_customize An instance of WP_Customize_Manager.
  * @return void
  */
 private static function _import($wp_customize)
 {
     // Make sure we have a valid nonce.
     if (!wp_verify_nonce($_REQUEST['cei-import'], 'cei-importing')) {
         return;
     }
     // Make sure WordPress upload support is loaded.
     if (!function_exists('wp_handle_upload')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     // Load the export/import option class.
     require_once CEI_PLUGIN_DIR . 'classes/class-cei-option.php';
     // Setup global vars.
     global $wp_customize;
     global $cei_error;
     // Setup internal vars.
     $cei_error = false;
     $template = get_template();
     $overrides = array('test_form' => FALSE, 'mimes' => array('dat' => 'text/dat'));
     $file = wp_handle_upload($_FILES['cei-import-file'], $overrides);
     // Make sure we have an uploaded file.
     if (isset($file['error'])) {
         $cei_error = $file['error'];
         return;
     }
     if (!file_exists($file['file'])) {
         $cei_error = __('Error importing settings! Please try again.', 'customizer-export-import');
         return;
     }
     // Get the upload data.
     $raw = file_get_contents($file['file']);
     $data = @unserialize($raw);
     // Remove the uploaded file.
     unlink($file['file']);
     // Data checks.
     if ('array' != gettype($data)) {
         $cei_error = __('Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import');
         return;
     }
     if (!isset($data['template']) || !isset($data['mods'])) {
         $cei_error = __('Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import');
         return;
     }
     if ($data['template'] != $template) {
         $cei_error = __('Error importing settings! The settings you uploaded are not for the current theme.', 'customizer-export-import');
         return;
     }
     // Import images.
     if (isset($_REQUEST['cei-import-images'])) {
         $data['mods'] = self::_import_images($data['mods']);
     }
     // Import custom options.
     if (isset($data['options'])) {
         foreach ($data['options'] as $option_key => $option_value) {
             $option = new CEI_Option($wp_customize, $option_key, array('default' => '', 'type' => 'option', 'capability' => 'edit_theme_options'));
             $option->import($option_value);
         }
     }
     // Call the customize_save action.
     do_action('customize_save', $wp_customize);
     // Loop through the mods.
     foreach ($data['mods'] as $key => $val) {
         // Call the customize_save_ dynamic action.
         do_action('customize_save_' . $key, $wp_customize);
         // Save the mod.
         set_theme_mod($key, $val);
     }
     // Call the customize_save_after action.
     do_action('customize_save_after', $wp_customize);
 }
Example #2
0
 /**
  * Imports uploaded mods and calls WordPress core customize_save actions so
  * themes that hook into them can act before mods are saved to the database.
  *
  * @since 0.1
  * @since 0.3 Added $wp_customize param and importing of options.
  * @access private
  * @param object $wp_customize An instance of WP_Customize_Manager.
  * @return void
  */
 private static function _import($wp_customize)
 {
     if (!wp_verify_nonce($_REQUEST['cei-import'], 'cei-importing')) {
         return;
     }
     require_once CEI_PLUGIN_DIR . 'classes/class-cei-option.php';
     global $wp_customize;
     global $cei_error;
     $cei_error = false;
     $template = get_template();
     $raw = file_get_contents($_FILES['cei-import-file']['tmp_name']);
     $data = @unserialize($raw);
     // Data checks.
     if ('array' != gettype($data)) {
         $cei_error = __('Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import');
         return;
     }
     if (!isset($data['template']) || !isset($data['mods'])) {
         $cei_error = __('Error importing settings! Please check that you uploaded a customizer export file.', 'customizer-export-import');
         return;
     }
     if ($data['template'] != $template) {
         $cei_error = __('Error importing settings! The settings you uploaded are not for the current theme.', 'customizer-export-import');
         return;
     }
     // Import images.
     if (isset($_REQUEST['cei-import-images'])) {
         $data['mods'] = self::_import_images($data['mods']);
     }
     // Import custom options.
     if (isset($data['options'])) {
         foreach ($data['options'] as $option_key => $option_value) {
             $option = new CEI_Option($wp_customize, $option_key, array('default' => '', 'type' => 'option', 'capability' => 'edit_theme_options'));
             $option->import($option_value);
         }
     }
     // Call the customize_save action.
     do_action('customize_save', $wp_customize);
     // Loop through the mods.
     foreach ($data['mods'] as $key => $val) {
         // Call the customize_save_ dynamic action.
         do_action('customize_save_' . $key, $wp_customize);
         // Save the mod.
         set_theme_mod($key, $val);
     }
     // Call the customize_save_after action.
     do_action('customize_save_after', $wp_customize);
 }