我的一个插件中有这个:
/**
* Prevents deletion of term
*
* Applies filter "atf_locks_term_delete_cap" to allow other plugins to filter the capability.
*
* @uses Adv_Term_Fields_Locks::get_prevent_msg()
*
* @access public
*
* @since 0.1.0
*
* @param int $term_id Term ID.
* @param string $taxonomy Taxonomy Name.
*
* @return mixed int $term_id If current user can delete the term or term is not locked.
* wp_die() On AJAX calls: If current user can\'t delete term or user is not detected.
*/
public function maybe_prevent_term_delete( $term_id, $taxonomy )
{
// If no lock, return term ID
if ( ! $lock = get_term_meta( $term_id, $this->meta_key, true ) ) {
return $term_id;
};
$cap = apply_filters( "atf_locks_term_delete_cap", "manage_others_term_locks" );
$user_can_delete = $this->_user_can( $cap, $term_id, $taxonomy, $lock );
if ( ! $user_can_delete ) :
if ( defined(\'DOING_AJAX\') && DOING_AJAX ) {
wp_die( -1 );
} else {
$_msg = $this->get_prevent_msg( $action = \'delete\' );
wp_die( $_msg, 403 );
};
endif;
return $term_id;
}
这就是所谓的:
add_action( \'pre_delete_term\', array( $this, \'maybe_prevent_term_delete\' ), 99, 2 );
这个
pre_delete_filter
在删除任何术语之前调用。为了防止删除,您可以挂接到类似于我在上面的类方法中所做的操作。
问题是,WP不允许自定义响应。因为这是一个ajax调用,所以它只查找“1”、“0”或“-1”。
退房wp_ajax_delete_tag()
在里面/wp-admin/includes/ajax-actions.php
看看我指的是什么。