Site logo

[Resolved] Import GP export file though One Click Demo Import

Home Forums Support [Resolved] Import GP export file though One Click Demo Import

Home Forums Support Import GP export file though One Click Demo Import

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1768814
    George

    Kind of a developer question.

    I am using the One Click Demo Import plugin to try and import theme settings for exporting to another site. I am also exporting an array containing the GP export JSON file exported from Customizer -> GeneratePress. I am exposing the array with the following code:

    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' );

    The import_json array contains the JSON file that I then need to process. The above plugin has an ocdi/after_import hook that runs after the import settings. In there, I need to be able to run some code to import the JSON file into the GeneratePress settings of the destination file where the plugin is also installed.

    Can you provide the function that GP uses to import the JSON file so I can update the hook?

    #1770585
    Tom
    Lead Developer
    Lead Developer

    Hi George,

    You can find the import functionality we use in the import-export/functions/functions.php file of GP Premium on line 225.

    There isn’t a function you can use, but it should shed some light on what’s needed in your own custom function 🙂

    #1771478
    George

    I suppose the public static functions get_modules(), get_theme_mods() and get_settings() are publicly accessible for me to use? For updating the settings should I replace, for example, self::get_modules() with $this->get_modules()?

    #1771554
    Tom
    Lead Developer
    Lead Developer

    I would personally just build your own functions using the same method we used in the plugin. That way you know it’s never going to break if we end up changing something. The functionality itself is simply enough to copy/paste into your own little helper class.

    #1771591
    George

    Yeah, struggling as it is with the code, not as savvy as you but I don’t want you to teach me PHP in 5 minutes, I guess! So you are saying that I should create my own function and use that function in the hooks provided by the plugin?

    #1776289
    Tom
    Lead Developer
    Lead Developer

    Personally I would just “clone” the function in the theme and adjust it to your specific needs. That way you aren’t re-inventing the wheel, most of the groundwork is there, it just needs to be tweaked a little.

    #1776560
    George

    Hey Tom, I think I made it work!

    Something I noticed, even though, personally I don’t need it. When you have the Site Library setting activated in the GP settings for the source site, the import doesn’t migrate that setting to the destination one. I think that’s because there is no site library related content included in the exported JSON file. Not sure if it’s intentional.

    #1780409
    Tom
    Lead Developer
    Lead Developer

    Hey George,

    Just to make sure, are you saying that the option to enable/disable the Site Library module doesn’t get imported? So the site imported to doesn’t have that module active?

    If so, sounds like a bug. I’ll take a look 🙂

    Thanks!

    #1780510
    George

    Correct, Tom.

    Thanks!

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