Skip to content

Instantly share code, notes, and snippets.

@wp-kitten
Created March 20, 2015 12:06
Show Gist options
  • Save wp-kitten/79233437569b637ece19 to your computer and use it in GitHub Desktop.
Save wp-kitten/79233437569b637ece19 to your computer and use it in GitHub Desktop.
Prevents a WodPress Core Theme from being activated.
<?php
/*
* Prevents a WodPress Core Theme from being activated.
*
* As a Theme Framework, it provides all the help and functionality child themes need, but child themes
* should be activated instead.
*
* This should go into the Core Theme's functions.php file
*/
if(! class_exists('CORE-THEME-MAIN-CLASS-NAME')) {
add_action('after_switch_theme', '_core_prevent_activation', 10, 2);
function _core_prevent_activation($oldThemeName, $oldTheme)
{
add_action('admin_notices', '_core_do_not_activate');
function _core_do_not_activate()
{
echo '<div class="update-nag">';
_e('Theme not activated: the Core Theme is a Theme Framework. Activate the child theme instead!<br/>
For now, the previous theme was reactivated.', 'text-domain');
echo '</div>';
}
// Revert to the previous used theme
switch_theme($oldTheme->stylesheet);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment