Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
add_action( 'delete_term_taxonomy', 'wpse_70758_del_tax', 10, 1 );
add_action( 'edit_term_taxonomies', 'wpse_70758_del_child_tax', 10, 1 );
$undeletable = array( 'категория_один', 'категория_два' ); // <<<<<<<<<< сюда вписывать категории, которые нельзя удалить (category slugs)
function wpse_70758_del_tax( $tt_id )
{
global $undeletable;
$term = get_term_by( 'id', $tt_id, 'category' );
if( in_array( $term->slug, $undeletable ) )
wp_die( 'Required category, can not be delete.' );
}
function wpse_70758_del_child_tax( $arr_ids )
{
global $undeletable;
foreach( $arr_ids as $id )
{
$term = get_term_by( 'id', $id, 'category' );
$parent = get_term_by( 'id', $term->parent, 'category' );
if( in_array( $parent->slug, $undeletable ) )
wp_die( 'Required category, can not be delete.' );
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question