Support » Plugin: One Click Demo Import » Add new option to import custom json file

  • Resolved George

    (@quantum_leap)


    I was wondering if there is a way to add an extra option to import an external JSON theme file and include it in the one-click import process. Something like this:

    function ocdi_import_files() {
      return [
        [
          'import_file_name'           => 'Demo Import 1',
          'import_file_url'            => get_stylesheet_directory_uri() . '/demo-data/demo-content.xml',
          'import_widget_file_url'     => get_stylesheet_directory_uri() . '/demo-data/widget-content.wie',
          'import_customizer_file_url' => get_stylesheet_directory_uri() . '/demo-data/customizer-content.dat',
          'import_preview_image_url'   => get_stylesheet_directory_uri() . '/screenshot.png',
          'preview_url'                => 'http://test.test/',
          'import_json'               => array(
    				array(
    					'file_url'    => trailingslashit( get_stylesheet_directory_uri() ) . '/demo-data/gp-export.json',
    					'option_name' => 'GP_option_name',
    				),
    			),
        ],
      ];
    }
    add_filter( 'ocdi/import_files', 'ocdi_import_files' );

    Would that be possible? Also, would it be possible to add the extra JSON import to the manual demo file import list?

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

    (@capuderg)

    Hi George,

    the code example above would work and the added files would be available in some of the plugin’s action and filter hooks (docs). This example would probably be the best fit. But you would still need to hook into them, get the file from the selected import array (same array as you define in the above code, so you would have the ‘import_json’ array key at your disposal) and import/process the file the way you want it.

    Having a new file upload for the manual import would not work, since the plugin will not know where to put it and what it is for.

    Have a nice day!

    Thread Starter George

    (@quantum_leap)

    Ok, are you saying that the best fit for me is to use the ocdi_after_import hook to hook into the array I exposed in the previous code?

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi George,

    yes, that’s it. Just a note, the hook name is ocdi/after_import.

    You can use and modify the code example provided in the section titled: “How to handle different after import custom code executions depending on which predefined demo was imported?” on this page: https://ocdi.com/advanced-integration-guide

    Have a nice day!

    Thread Starter George

    (@quantum_leap)

    For my import_json array is there any use for the option_name key, or I can just declare the file_url one?

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi George,

    under the import_json array you can define whatever you want. You will be using that array structure in the hook anyway, so use whatever works best for you.

    Take care!

    Thread Starter George

    (@quantum_leap)

    I made it work, thanks for your help!

    Plugin Author Gregor Capuder

    (@capuderg)

    Hi George,

    that’s awesome! I’m glad I could help. 🙂

    Have a nice day!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.