• Resolved wpuser10

    (@wpuser10)


    Hello,

    After updated the plugin to the latest version observed problem that widgets are not imported to custom sidebars.

    Before importing widgets using “pt-ocdi/before_widgets_import” I am adding custom sidebars, settings different options and importing Revolution Slider this way:

    function custom_theme_ocdi_import_start( $selected_import ) {
    
    	if ( 'Main demo' === $selected_import['import_file_name'] ) {
    
    		/*add custom sidebars*/
    		$custom_sidebar[] = 'sidebar1';
    		$custom_sidebar[] = 'sidebar2';
    		$custom_sidebar[] = 'sidebar3';
    		$custom_sidebar[] = 'sidebar4';
    
    		update_option( 'custom_sidebar', $custom_sidebar );
    
    		/*import revolution slider before importing xml*/
    		if ( is_plugin_active( 'revslider/revslider.php' ) ) {
    
    			$absolute_path = __FILE__;
    			$path_to_file = explode( 'wp-content', $absolute_path );
    			$path_to_wp = $path_to_file[0];
    
    			require_once( $path_to_wp.'/wp-load.php' );
    			require_once( $path_to_wp.'/wp-includes/functions.php');
    			require_once(ABSPATH . 'wp-admin/includes/file.php');
    
    			echo ' Import Files loaded';
    			echo ' Import Slider'; 
    
    			$slider_array = array(get_template_directory()."/dummy-data/revslider.zip");
    			$slider = new RevSlider();
    
    			foreach($slider_array as $filepath){
    				$slider->importSliderFromPost(true,true,$filepath);
    			}
    
    			echo ' Slider processed';
    		}
    	}
    
    }
    
    add_action( 'pt-ocdi/before_widgets_import', 'custom_theme_ocdi_import_start' );

    Sidebars are correctly added but the problem is that widgets are not imported. No errors reported. Widgets are imported correctly to static sidebars like default sidebar or footer sidebar. After run the import second time widgets are imported. Observed the issue only in the latest version, before update it worked fine. Did you observe it also?

    Thanks!

    https://www.ads-software.com/plugins/one-click-demo-import/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    our custom sidebars are importing just fine, also there were no other reports of any similar issues from other users (theme authors).

    I would say that something is wrong with sidebar creation, since that is the only thing that could be the reason for widgets not to import ( the widgets can’t import because the sidebars do not exist ).

    What does the log files say about the widget import? Could you please send me the two log files (the failed log and the second successful one). There should be some info on what is going on…

    Take care!

    Thread Starter wpuser10

    (@wpuser10)

    There was no errors during the import, importing ended as successful each time. Could please you write where can I find the logs you mentioned?

    Could the reason be that importing Revolution Slider is taking some time and perhaps slowing down the final exacution of action? Sidebars were imported, but widgets were not imported, so it sounds like sidebars were created too late.

    Thanks!

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    the logs should be in the Media section in admin dashboard (you have to view the attachment, to see the actual log file).

    I don’t see how the sidebars are not creating in the correct time, since they are created before the widgets import. Why don’t you create the custom sidebars in the theme (in functions.php), maybe try that?

    I agree that this is the main problem (sidebars are created too late, but I don’t know why, are you sure that updating the “custom_sidebar” option is the only thing needed to create these custom sidebars?):

    > Sidebars were imported, but widgets were not imported, so it sounds like sidebars were created too late.

    Take care!

    Thread Starter wpuser10

    (@wpuser10)

    The sidebars I am adding are intentionally dynamic (it’s possible to add/remove them from settings). There are also static sidebars (registered in functions.php) like footer, sidebar and importing to them works fine.

    Yes, updating “custom_sidebar” is adding the sidebars correctly (I checked it).

    I observed the issue also after I moved the code to import “Revolution Slider” from “import_start” action to “pt-ocdi/before_widgets_import” action. I will move it back to “import_start” and let you know if it helps.

    The only problem with “import_start” is that is not possible there to select the import with code like in your FAQ:

    if ( 'Demo Import 1' === $selected_import['import_file_name'] ) {
            echo "This will be displayed only on after import if user selects Demo Import 1";
    
            // Set logo in customizer
            set_theme_mod( 'logo_img', get_template_directory_uri() . '/assets/images/logo1.png' );
        }

    Do you maybe have solution for this?

    Thanks!

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    let me know how it goes, when you add the Revolution slider import to the “import_start” action.

    The “import_start” is an action hook of the new content importer that is used in this plugin and this plugin does not have immediate access to it, so it also does not have access to the selected import parameter, like the “pt-ocdi/before_widget_import” has, so right now, there is nothing we can do about it. But I will probably add a custom action hook in the next version of the plugin, which we can control, maybe something like this: ‘pt-ocdi/before_import’ (I’ve added it on my todo list).

    Take care!

    Thread Starter wpuser10

    (@wpuser10)

    Tried different methods and unfortunatelly nothing worked.

    Double checked this code below and it works correct (add custom sidebars).

    /*add custom sidebars*/
    $custom_sidebar[] = 'sidebar1';
    $custom_sidebar[] = 'sidebar2';
    $custom_sidebar[] = 'sidebar3';
    $custom_sidebar[] = 'sidebar4';
    
    update_option( 'custom_sidebar', $custom_sidebar );

    It also works correct when it is inside ‘pt-ocdi/before_import’.
    The problem is that it’s adding sidebars too late or it needs to reload a page before importing the widgets. Not sure why. Is it possible to echo time after importing the sidebars and time just before importing the widgets from wie file to investigate it more?

    • This reply was modified 8 years, 5 months ago by wpuser10.
    • This reply was modified 8 years, 5 months ago by wpuser10.
    • This reply was modified 8 years, 5 months ago by wpuser10.
    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    whatever you echo out in the ‘pt-ocdi/before_widgets_import’ action, will be added to the log file, so just echo out the time. To echo out the time of the widgets import, you will have to edit the code in inc/class-ocdi-main.php in the import_widgets method. You can output the time to the log file, if you append the time text to this code:

    
    // Add this message to log file.
    $log_added = OCDI_Helpers::append_to_file(
    	$message,
    	$this->log_file_path,
    	esc_html__( 'Importing widgets' , 'pt-ocdi' )
    );
    

    like this:

    
    // Add this message to log file.
    $log_added = OCDI_Helpers::append_to_file(
    	$message . $the_current_time_string_goes_here,
    	$this->log_file_path,
    	esc_html__( 'Importing widgets' , 'pt-ocdi' )
    );
    

    But the execution of these two things should be always in the order of the before widgets import action hook firing first.

    Take care!

    Thread Starter wpuser10

    (@wpuser10)

    Thank you, I implemented and compared the times and it looks the order is correct, but I still didn’t resolve the problem.

    When first time click on “Import Demo Data” then I got in the log file for example:

    sidebar1 : Sidebar does not exist in theme (moving widget to Inactive)

    After importing I can see the sidebars, but empty. When click on “Import Demo Data” second time then sidebars are with imported widgets (correct).

    Do you have any other suggestions what could be wrong? I am using just very basic system for creating custom widgets, which is working fine in general.

    • This reply was modified 8 years, 5 months ago by wpuser10.
    Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    I really don’t know, what the actual problem is. Clearly the problem is the timing of the custom sidebars creation.

    You just confirmed that the custom sidebars registration code executes before the widgets import, which would mean that everything should work, but it doesn’t.

    The import is done via AJAX calls… maybe the issue of creating the custom sidebars is connected to that? But I really doubt it, since you only call update_option. Or is there another hook that has to be fired, to actually register the custom sidebars?

    We register the custom sidebars in our theme, so we never register them “dynamically”.

    I’m sorry, that I can’t be of more help to you.

    Take care!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Problem with importing widgets to custom sidebars’ is closed to new replies.