fastlinemedia / customizer-export-import

Adds a settings export/import section to the WordPress customizer.
43 stars 13 forks source link

Can this be automated on theme activation? #4

Open bghouse opened 8 years ago

bghouse commented 8 years ago

Is there a way that an export file with default settings could be set to automatically import on theme activation? Kind of a "setup defaults" for a new theme?

ghost commented 8 years ago

+1, this could be a real time saver for sure.

fastlinemedia commented 8 years ago

Would the export file live somewhere in the theme?

bghouse commented 8 years ago

Yes, that was what I was thinking. Maybe a wait to add the path into the theme's function files or something.. I use Devon's Customizer Library which is awesome, and have moved all my theme settings into the customizer now. But the one thing it doesnt do is set defaults into the database on activation. I understand why, however it means that my code for various advanced features that checks to see if an option is set doesnt work because technically they aren't set yet. So being able to have an import file with the basic settings is so much easier for my clients. And if there is a way to automate it - even better :-)

fastlinemedia commented 8 years ago

Cool. I think this might be better served with a function that you can pop into your functions.php file. I'll whip something up for you next week.

bghouse commented 8 years ago

Oh yeah, that would be amazing and just perfect with a function in the theme :-)

fastlinemedia commented 8 years ago

Here's a modified version of the plugin's import function that should work in your theme's functions.php file upon activation. Let me know if you have any questions...

https://gist.github.com/fastlinemedia/9a8070b9a636e38b510f

bghouse commented 8 years ago

Thank you - just a quick question. Do I still need to have the plugin itself installed and activated?

bghouse commented 8 years ago

oops - one more question. What happens if the user activates the theme, makes changes, deactivates and then re-activates. Will it wipe out the changes? Is there some sort of way to tell? Or am I completely overthinking this - lol

bghouse commented 8 years ago

I just tried this in the theme and it didn't work all the way. I was expecting that after the theme activation I could look at the front end of the site and see the changes, but I dont. If I access the Theme Customizer, I can see the defaults set in there - but it's not visible on the front end unless I change something and save it. So it's like it's still not completely initialized.

Also, I have a logo image with a default as one of my options. When I import the file using the plugin, it sets the default. If I use this automated function, it doesnt.

fastlinemedia commented 8 years ago

I updated the gist so it now checks to see if the options have already been imported.

As for it not working all of the way, is your theme doing any CSS caching? If so, you'll need to modify the gist to clear that out. It's only setting the theme mods and options, nothing else.

As for images, this function doesn't currently support them. I would need to create a whole new class based on the customizer plugin for that and I don't have time at the moment.

This is separate from the plugin, so it doesn't need to be activated for this to work.

bghouse commented 8 years ago

Thank you! I'll try this again and see if I can sort it out