Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mlbd/b748ee08ea3995ad2f233b99cc819451 to your computer and use it in GitHub Desktop.
Save mlbd/b748ee08ea3995ad2f233b99cc819451 to your computer and use it in GitHub Desktop.
/**
*
* Import Class
* A helper class for support CS to OCDI
*
*/
if ( !class_exists( 'OCDI_Plugin' ) )
return;
class CS_Import_OCDI {
public $title;
public function __construct($title = 'Codestart Framework data uploaded') {
$this->title = $title;
add_action('pt-ocdi/after_content_import_execution', array($this, 'cs_import_init'), 3, 99 );
}
public function cs_decode_string( $string ) {
return unserialize( $string );
}
public function cs_import_init( $selected_import_files, $import_files, $selected_index ) {
if ( !class_exists( 'CSFramework' ) ) {
return;
}
$downloader = new OCDI\Downloader();
if( ! empty( $import_files[$selected_index]['local_import_cs'] ) ) {
foreach( $import_files[$selected_index]['local_import_cs'] as $index => $import ) {
$file_path = $import['file_path'];
$file_raw = OCDI\Helpers::data_from_file( $file_path );
update_option( $import['option_name'], cs_decode_string( $file_raw, true ) );
}
}
$ocdi = OCDI\OneClickDemoImport::get_instance();
$log_path = $ocdi->get_log_file_path();
OCDI\Helpers::append_to_file( $this->title, $log_path );
}
}
$cs_init = new CS_Import_OCDI();
@mlbd
Copy link
Author

mlbd commented Apr 25, 2018

if( !function_exists('prefix_demo_import_func') ) {
	function prefix_demo_import_func() {
		return array(
			array(
				'import_file_name'           => 'Prefix Demo Data',
				'local_import_file'            => trailingslashit( get_template_directory() ) . 'inc/demo-data/content.xml',
				'local_import_widget_file'     => trailingslashit( get_template_directory() ) . 'inc/demo-data/widgets.wie',
				'local_import_cs'           => array(
			        array(
			          'file_path'   => trailingslashit( get_template_directory() ) . 'inc/demo-data/demo.txt',
			          'option_name' => '_cs_options',
			        ),
			     ),
				'import_notice' => __( '<p><sub style="color: red;font-size: 2em;vertical-align: middle;top: 2px;position: relative;margin-right: 5px;">*</sub>Import process might take several minutes depending on your server configuration. Please wait till it shows confirmation message.</p><p></p>', 'textdomain' ),
			),
		);
	}
}
add_filter( 'pt-ocdi/import_files', 'prefix_demo_import_func' );

@pavliukpetro
Copy link

Hello. I tried these files but it wasn't working for me. Tell me, please, where should I put the code?

@mlbd
Copy link
Author

mlbd commented Nov 28, 2019

@pavlyukpetr you just need to put both of them in your theme functions.php or any other fucntions file you want to

@WPsmart
Copy link

WPsmart commented Apr 2, 2020

Hi

I try this method, but Ideta import not working, but log file shows it's uploaded?

i change file path (fake path) and test, but fake URL also show as Framework data uploaded in a log file

any suggestions for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment