Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin that installs a folder of themes and other plugins into the WP site during plugin activation.

I would like to place script into the plugin which will activate one of the themes that the plugin installs.

Can someone post a quick example of script that registers and activates a known theme via a plugin's activation script?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

switch_theme() should work:

function myplugin_activate() {
  switch_theme('default', 'default');
}

register_activation_hook( __FILE__, 'myplugin_activate' );
share|improve this answer
    
@OTP: Thanks. Checking it out now. –  Scott B Mar 25 '11 at 4:38
    
@OTP: The plugin actually copies the theme from one of its payload folders over into the themes directory during the plugin activation. Would there be any issues with the timing of the switch_theme() statement in relation to when the theme transfer is completed? ie, would it fail if the plugin has not yet transferred the theme fully into the theme's folder? –  Scott B Mar 25 '11 at 4:40
    
no, unless you're copying the files in the background with ajax and you don't wait for the response –  onetrickpony Mar 25 '11 at 11:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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