- This topic has 8 replies, 2 voices, and was last updated 4 years, 10 months ago by
George.
-
AuthorPosts
-
May 7, 2021 at 5:29 am #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_jsonarray contains the JSON file that I then need to process. The above plugin has anocdi/after_importhook 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?
May 8, 2021 at 10:29 am #1770585Tom
Lead DeveloperLead DeveloperHi George,
You can find the import functionality we use in the
import-export/functions/functions.phpfile 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 🙂
May 9, 2021 at 9:17 am #1771478George
I suppose the public static functions
get_modules(),get_theme_mods()andget_settings()are publicly accessible for me to use? For updating the settings should I replace, for example,self::get_modules()with$this->get_modules()?May 9, 2021 at 10:20 am #1771554Tom
Lead DeveloperLead DeveloperI 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.
May 9, 2021 at 10:57 am #1771591George
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?
May 12, 2021 at 9:54 am #1776289Tom
Lead DeveloperLead DeveloperPersonally 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.
May 12, 2021 at 4:33 pm #1776560George
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.
May 14, 2021 at 7:50 am #1780409Tom
Lead DeveloperLead DeveloperHey 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!
May 14, 2021 at 9:06 am #1780510George
Correct, Tom.
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.