Support » Plugin: One Click Demo Import » before_widget_import_action returns wrong selected_index

  • Resolved Chris Baldelomar

    (@cbaldelomar)


    The following code returns the wrong selected index. This leaves the developer without the ability to determine which import selection the user has chosen.

    
    /**
     * Execute the action: 'pt-ocdi/before_widgets_import'.
     *
     * @param array $selected_import_files Actual selected import files (content, widgets, customizer, redux).
     * @param array $import_files          The filtered import files defined in <code>pt-ocdi/import_files</code> filter.
     * @param int   $selected_index        Selected index of import.
     */
    public function before_widget_import_action( $selected_import_files, $import_files, $selected_index ) {
    	print_r( $import_files );
    	echo "<br />============<br />";
    	print_r( $selected_index );
    	echo "<br />============<br />";
    	print_r( $import_files[ $selected_index ] );
    	die();
    	$this->do_import_action( 'pt-ocdi/before_widgets_import', $import_files[ $selected_index ] );
    }
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor capuderg

    (@capuderg)

    Hi,

    I’ve just tested this and the $selected_index is correct.

    I choose the third import out of 4 and the returned index was 2, which is correct since the indexes go 0,1,2,3.

    What was your scenario?

    How many predefined demo imports does you theme have? Are all predefined demo imports configured correctly (do they all display on the plugin page)?

    Take care!

    I have two. When I select the first or second, it returned 1 for both.

    Plugin Contributor capuderg

    (@capuderg)

    Hmmm… that’s strange.

    Could you maybe send me the theme zip file so I can debug it? (my email is: same username as here at gmail com)

    Take care!

    If I add this piece of code to my theme files:

    
    delete_transient( 'ocdi_importer_data' );
    

    I get the correct $selected_import value.

    Or, if I comment out this line in OneClickDemoImport.php Line 213:

    
    // Is this a new AJAX call to continue the previous import?
    // $use_existing_importer_data = $this->use_existing_importer_data();
    

    Then I also get the correct $selected_import value.

    This hack temporarily solves my problem:

    function wporg_current_screen( $current_screen ) {
    	if ( 'appearance_page_pt-one-click-demo-import' == $current_screen->base ) {
    		delete_transient( 'ocdi_importer_data' );
    	}
    }
    add_action( 'current_screen', 'wporg_current_screen' );
    Plugin Contributor capuderg

    (@capuderg)

    Hi Chris,

    the transient is used for holding data between each AJAX call, if the demo import takes more then 25 seconds (which it does in most of the cases). Deleting it, might have other consequences…

    The transient should be deleted after each completed demo import, so I don’t know, why yours is not deleting after completion.

    Do all your demo imports complete (you see a success or error message)? Or do they end up in some server side error messages?

    This transient also continues the import, if it comes to a server side error, so you just select the same import again and it continues from the point it failed before.

    Take care!

    Yes, so far, with the hack, my theme import is working as expected. The transient is being deleted when the “appearance_page_pt-one-click-demo-import” is loaded, before the demo import begins.

    So this action hook below returns the correct $selected_import value in your environment?

    function wporg_ocdi_before_widgets_import( $selected_import ) {
    	print_r($selected_import);
    }
    add_action( 'pt-ocdi/before_widgets_import', 'wporg_ocdi_before_widgets_import' );

    By the way, thanks for such a great plugin. You guys also make great themes.

    Plugin Contributor capuderg

    (@capuderg)

    Hi Chris,

    thanks for the kind words 🙂 If you like our plugin, please review it here, I would really appreciate it.

    This selected index/transient issue is really strange, since if this would not work for other people, the plugin would be importing incorrect demo imports and theme authors and users would definitely report something to us. Also we are using this plugin for a good year now in our themes and we never had this issue reported.

    To answer you questions, yes, the index is always correct in my tests.

    Take care!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘before_widget_import_action returns wrong selected_index’ is closed to new replies.