0

Is there a way to install and activate a child-theme from zip file like we do with TGM-Plugin-Activation which helping us to suggest or force user to install and activate a plugin.

So my idea is that i want to create a plugin with a form to choose child themes and then when the user choose one it will install and activate it.

Thank you.

EDIT

I have a plugin who create an option page with this kind of forms. enter image description here

Then I retrieve variables like this:

function getHeader($theme)
{
global $Header;
global $biblio_options;
$biblio_settings = get_option('biblio_options', $biblio_options);
$theme = $biblio_settings['themechoice'];
if ($theme == 'thmone' || $theme == null)
    {
    $Header = get_header();
    }

....

when client choose for exemple theme 1 then i changed the header and it's style and everything works fine.

But now I like to have the same with child theme so when user choose theme 1 on the plugin it will install a child-theme1 from a zip file who will be on the plugin folder then activate it.

Thank you for your help.

6
  • Maybe something in here could help wpgear.org/#updaters
    – jgraup
    Nov 24, 2016 at 18:56
  • @jgraup I guess you didn't get what I mean, I'm not looking for themes update, i look for switching between not yet installed child theme and their parent theme. Nov 24, 2016 at 20:54
  • No, I understood. I just think maybe these updaters might have code that could help you. You would just need to do some leg work to find out how.
    – jgraup
    Nov 24, 2016 at 21:02
  • Have you looked at codex.wordpress.org/Filesystem_API or wordpress.stackexchange.com/a/42212?
    – jgraup
    Nov 24, 2016 at 21:18
  • @jgraup I was looking into these updaters but it doesn't work till now, I will make an Edit then I will see these Filesystem. Nov 24, 2016 at 21:22

1 Answer 1

1

Yes, you can activate the child-theme dynamically. To do that follow the steps

  1. Move the unzipped child-theme to the themes folder
  2. Find the name of the child theme(I guess you already have that)
  3. Then Update the options table by update_option('stylesheet', 'NAME OF THE CHILD THEME')

NOTE: You need to be sure that the active theme and child theme is compatible with each other.

10
  • How do you go about unzipping zip files to folders without name conflicts in WordPress?
    – jgraup
    Nov 24, 2016 at 19:58
  • I did not give him any clue in which process, he will do the whole thing but said in short how he can achieve that. However using wp_get_themes() function can be found all themes data on the site then after checking the installed themes names and files if those does not conflict with the new theme then desired theme can be installed. Nov 24, 2016 at 20:02
  • Seems like the hardest part of the problem. I hope someone can give the answer
    – jgraup
    Nov 24, 2016 at 20:04
  • @MDSultanNasirUddin I just tried to create a child theme manually and try to use the function update_option to switch between themes, but what happened is wordpress create a copy of my child theme which is an error (an empty child theme juste with the same name used on update_function) Nov 24, 2016 at 20:57
  • @jgraup And like you said the whole probleme now is how to trigger an installation and activation of the child theme juste from a submit button. Nov 24, 2016 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.