• Hi,

    I want to activate a theme programmatically that I have uploaded via ftp.

    Method 1: If I ‘activate’ the new theme as suggested in many posts simply by changing the ‘current_theme’, ‘template’ and ‘stylesheet’ options of the wp-options table using mysql the new theme becomes the active theme however posts are not being displayed.

    Method 2: If I activate the theme manually from within the admin area the posts do display. Checking the wp-options table after this manual activation shows that tens of new entries specific to the new theme have also been added to the wp-options table.

    Therefore method 1 is clearly inadequate as it doesnt trigger the initialisation/configuration of the theme proper. I need to achieve the result of manual activation as in method 2 but programatically.

    Please bear in mind I need to do this for many websites and so the solution needs to be scripted to automate. Any solution is acceptable and doesnt need to worry about being upgrade proof etc.

    I have taken a look at the switch_theme hook and a few solutions based on it but none of them work for me and simply result in the same as method 1. I am unsure as to how and where best to insert or modify core or theme code to achieve manual activation.

    The solution should run in linux as either bash, php, mysql, wp api calls or a hybrid – whatever is needed. Once I have a single working solution I can create the scripts for all other domains easily.

    Please respond if you have the slightest input – I am pulling my hair out trying to get this working.

    Many thanks,

    big_s

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    If you trace through the manual activation link, you will see all that really happens is the function switch_theme() is called. This is where the switch_theme action is triggered. All this function really does is set the same three options set in your method 1, but there’s a few if ands or buts involved which make it more robust than just changing options.

    I don’t see where these other options you observed are being set. It may be a theme dependent thing? Many themes run a setup. At least with the default theme, the setup is run at runtime on the ‘after_setup_theme’ action. This is part of loading the WP environment, not part of the switch theme process.

    I’m not sure any of this is any help, but you never know when a stray comment will trigger a new thought, so I though I’d reply on the off chance of triggering something. I know there’s a fair chance you already know all this.

    Thread Starter big_s

    (@big_s)

    Hi,

    Thanks for the reply. I am actually a noob to wordpress core and functions so any advice is welcome.

    After some more rooting around based on your tips I found the following in a file called theme-settings.php (obvious really!) that is included as
    require_once(TEMPLATEPATH . "/theme-settings.php");
    within functions.php of the new theme:

    <?php
    // Add default settings and show Theme Settings page after activation
    /*-----------------------------------------------------------------------------------*/
    
    if (is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {
    	add_action('admin_head','solostream_option_setup');
    	header( 'Location: '.admin_url().'themes.php?page=theme-settings.php' );
    }
    
    function solostream_option_setup(){
    
    	//Update EMPTY options
    	$solostream_array = array();
    	add_option('solostream_options',$solostream_array);
    	$template = get_option('solostream_template');
    	$saved_options = get_option('solostream_options');
    	foreach($template as $option) {
    		if($option['type'] != 'header'){
    			$id = $option['id'];
    			$std = $option['std'];
    			if(empty($saved_options)) {
    				update_option($id,$std);
    				$solostream_array[$id] = $std;
    			}
    			else { //Store the old values over again.
    				$solostream_array[$id] = $saved_options[$id];
    			}
    		}
    	}
    	update_option('solostream_options',$solostream_array);
    }
    
    ...

    As you can see its a Solostream theme. So the question now is how and where from do I call this solostream_option_setup() function? Hopefully that should do it 🙂

    Thread Starter big_s

    (@big_s)

    Hi,

    Anyone got any ideas on this? Just need to know how and where to call this function solostream_option_setup() above. Can I append it to a file somewhere and then remove after function has been called or can I write a separate php file to call it or…

    Thanks,

    big_s.

    Moderator bcworkz

    (@bcworkz)

    Sorry for the slow response, I’m pretty regular, but not very frequent.

    It appears the theme adds a ‘activated’ url parameter to the admin panel menu so when it is first picked this setup is run and the admin is redirected to the theme settings. I’m guessing that everything is in order from just switching themes. The options should appear once an admin accesses the theme settings panel.

    You shouldn’t have to do anything special beyond switch_theme(), as that is all that happens when a theme is manually activated. For everything else that might happen, the theme should handle on it’s own, though it’s not always obvious how this is done.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Programmatic Activation Of Theme Not Working’ is closed to new replies.