Постоянно активируйте тему WordPress
Можно ли навсегда активировать тему, чтобы ее нельзя было отключить или изменить?
Что-то похожее на:
define( 'WP_DEFAULT_THEME', 'apollo' );
1
1 answers
Вот одна идея:
/**
* 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 );
}
}
Где вам нужно изменить название темы sticky в соответствии с вашими потребностями. Возможно, вам придется проверить это дальше.
Еще одна вещь, которую нужно попробовать, - это удалить switch_themes
возможность для всех пользователей!
Например, мы можем отфильтровать эту возможность на лету с помощью:
/**
* 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;
});
Таким образом, проверка current_user_can( 'switch_themes' )
во время активации темы в themes.php
возвращает false.
0
Author: birgire, 2015-03-07 03:06:01