1

It it possible to permanently activate a theme so that it cannot be disabled or changed?

Something similar to:

define( 'WP_DEFAULT_THEME', 'apollo' );
  • the context is not very clear, even if it is possible anyone with FTP access will be able to change it. – Mark Kaplun Mar 6 '15 at 17:01
  • Have you tried removing all the other themes? – Tom J Nowell Mar 6 '15 at 18:35
0

Here's one idea:

/**
 * Reactivate the sticky theme, if someone activates another theme.
 */

add_action( 'switch_theme', 'wpse_permanent_theme' );

function wpse_permanent_theme( $new_name )
{
    $sticky_theme_name = 'twentyfifteen';  // Modify this to your needs!

    // Get the sticky theme info, to check if it exists (named):    
    $sticky_theme = wp_get_theme( $sticky_theme_name );

    // Reactivate the sticky theme:   
    if( $sticky_theme->get( 'Name' ) && $sticky_theme_name !== $new_name )
    {
        remove_action( current_action(), __FUNCTION__ );
        switch_theme( $sticky_theme_name );
    }
}  

where you have to modify the sticky theme name to your needs. You may need to test this further.

Another thing to try out would be to remove the switch_themes capability for all users!

For example, we can filter out this capability on the fly with:

/**
 *  Remove the 'switch_themes' capability for all users.
 */

add_filter('user_has_cap', function( $allcaps )
{
    if( isset( $allcaps['switch_themes']  ) )
        unset( $allcaps['switch_themes'] );
    return $allcaps;
});

so the current_user_can( 'switch_themes' ) check during a theme activation in themes.php returns false.

  • thanks @SörenWrede for the edit, I'm playing with the twentyfifteen and the twentyeleven themes, as you can see ;-) – birgire Mar 6 '15 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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