最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Programmatically install and activate child-theme

programmeradmin1浏览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.

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.

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.

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.

Share Improve this question edited Nov 24, 2016 at 21:32 Carl Willis asked Nov 24, 2016 at 17:19 Carl WillisCarl Willis 3051 gold badge2 silver badges11 bronze badges 6
  • Maybe something in here could help wpgear/#updaters – jgraup Commented 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. – Carl Willis Commented 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 Commented Nov 24, 2016 at 21:02
  • Have you looked at codex.wordpress/Filesystem_API or wordpress.stackexchange/a/42212? – jgraup Commented 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. – Carl Willis Commented Nov 24, 2016 at 21:22
 |  Show 1 more comment

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论