bp_delete_term( int $term_id, string $taxonomy = '' )

Deletes a BP Term.


Parameters Parameters

$term_id

(int) (Required) The BP Term ID. Required.

$taxonomy

(string) (Optional) The BP Taxonomy Name. Required.

Default value: ''


Top ↑

Return Return

(bool|WP_Error) True on success, WP_Error on failure.


Source Source

File: bp-core/bp-core-taxonomy.php

function bp_delete_term( $term_id = 0, $taxonomy = '' ) {
	if ( ! $term_id || ! $taxonomy ) {
		return new WP_Error( 'missing_arguments', __( 'Sorry, the term ID and the taxonomy are required arguments.', 'buddypress' ) );
	}

	$site_id = bp_get_taxonomy_term_site_id( $taxonomy );

	$switched = false;
	if ( $site_id !== get_current_blog_id() ) {
		switch_to_blog( $site_id );
		bp_register_taxonomies();
		$switched = true;
	}

	/**
	 * Fires before a BP Term is deleted from the database.
	 *
	 * @since 7.0.0
	 *
	 * @param int    $term_id  The BP Term ID.
	 * @param string $taxonomy The BP Taxonomy Name.
	 */
	do_action( 'bp_before_delete_term', $term_id, $taxonomy );

	$deleted = wp_delete_term( $term_id, $taxonomy );

	if ( $switched ) {
		restore_current_blog();
	}

	if ( is_wp_error( $deleted ) ) {
		return $deleted;
	}

	if ( false === $deleted ) {
		return new WP_Error( 'inexistant_term', __( 'Sorry, the term does not exist.', 'buddypress' ) );
	}

	if ( 0 === $deleted ) {
		return new WP_Error( 'default_term', __( 'Sorry, the default term cannot be deleted.', 'buddypress' ) );
	}

	/**
	 * Fires once a BP Term has been deleted from the database.
	 *
	 * @since 7.0.0
	 *
	 * @param boolean $deleted True.
	 * @param int     $term_id  The deleted BP Term ID.
	 * @param string  $taxonomy The BP Taxonomy Name of the deleted BP Term ID.
	 */
	do_action( 'bp_delete_term', $deleted, $term_id, $taxonomy );

	return $deleted;
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.