Support » Networking WordPress » Enable a theme in PHP

  • For a multisite i need to automically activate a package specific theme for automatically created subsites. this would be the command in WP-CLI
    https://developer.wordpress.org/cli/commands/theme/enable/

    How do i do this in php? if there’s no function for this, can it be done directly in the DB?

    Next step would be to activate the theme, this i will do directly in database changing options “template” and “stylesheet”

Viewing 3 replies - 1 through 3 (of 3 total)
  • https://codex.wordpress.org/Function_Reference/switch_theme
    I think this link is helpful for you..

    I didn’t write it correctly in the post. and the link you send is not site/multisite specific.

    I need to ENABLE a theme, that is not network-wide activated, on a specific site(id).

    Means: the available themes are not being activated network-wide. each subsite gets a specific theme enabled, and then activated as current theme.

    activate as current theme i know how to do (via database)

    i dont know how to enable the theme on the site

    Hi, this should do it:

    
    $blog_id = 3; // id of the blog to enable the theme for
    $theme = 'twentyseventeen'; // the theme stylesheet
    $allowed_themes = get_blog_option( $blog_id, 'allowedthemes' );
    if ( !$allowed_themes ) {
        $allowed_themes = array( $theme => true );
    } else {
        $allowed_themes[$theme] = true;
    }
    update_blog_option( $blog_id, 'allowedthemes', $allowed_themes ); 
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Enable a theme in PHP’ is closed to new replies.