unregister_taxonomy

函式
unregister_taxonomy ( $taxonomy )
引數
  • (string) $taxonomy Taxonomy name.
    Required:
返回值
  • (true|WP_Error) True on success, WP_Error on failure or if the taxonomy doesn't exist.
定義位置
相關方法
register_taxonomyunregister_meta_keyis_taxonomyget_taxonomyunregister_setting
引入
4.5.0
棄用
-

unregister_taxonomy: 在WordPress中取消註冊一個先前註冊的分類法: 這個函式從已註冊的分類法列表中刪除該分類法,並從資料庫中刪除所有相關術語。

取消註冊一個分類法。

不能用於取消註冊內建分類法。

function unregister_taxonomy( $taxonomy ) {
	if ( ! taxonomy_exists( $taxonomy ) ) {
		return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
	}

	$taxonomy_object = get_taxonomy( $taxonomy );

	// Do not allow unregistering internal taxonomies.
	if ( $taxonomy_object->_builtin ) {
		return new WP_Error( 'invalid_taxonomy', __( 'Unregistering a built-in taxonomy is not allowed.' ) );
	}

	global $wp_taxonomies;

	$taxonomy_object->remove_rewrite_rules();
	$taxonomy_object->remove_hooks();

	// Remove the taxonomy.
	unset( $wp_taxonomies[ $taxonomy ] );

	/**
	 * Fires after a taxonomy is unregistered.
	 *
	 * @since 4.5.0
	 *
	 * @param string $taxonomy Taxonomy name.
	 */
	do_action( 'unregistered_taxonomy', $taxonomy );

	return true;
}

常見問題

FAQs
檢視更多 >