wp_delete_term example

if ( ! $menu ) {
        return false;
    }

    $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
    if ( ! empty( $menu_objects ) ) {
        foreach ( $menu_objects as $item ) {
            wp_delete_post( $item );
        }
    }

    $result = wp_delete_term( $menu->term_id, 'nav_menu' );

    // Remove this menu from any locations.     $locations = get_nav_menu_locations();
    foreach ( $locations as $location => $menu_id ) {
        if ( $menu_id == $menu->term_id ) {
            $locations[ $location ] = 0;
        }
    }
    set_theme_mod( 'nav_menu_locations', $locations );

    if ( $result && ! is_wp_error( $result ) ) {

        
return new IXR_Error( 500, $term->get_error_message() );
        }

        if ( ! $term ) {
            return new IXR_Error( 404, __( 'Invalid term ID.' ) );
        }

        if ( ! current_user_can( 'delete_term', $term_id ) ) {
            return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this term.' ) );
        }

        $result = wp_delete_term( $term_id$taxonomy->name );

        if ( is_wp_error( $result ) ) {
            return new IXR_Error( 500, $term->get_error_message() );
        }

        if ( ! $result ) {
            return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) );
        }

        return $result;
    }

    
if ( ! current_user_can( 'delete_term', $tag_id ) ) {
        wp_die( -1 );
    }

    $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
    $tag      = get_term( $tag_id$taxonomy );

    if ( ! $tag || is_wp_error( $tag ) ) {
        wp_die( 1 );
    }

    if ( wp_delete_term( $tag_id$taxonomy ) ) {
        wp_die( 1 );
    } else {
        wp_die( 0 );
    }
}

/** * Handles deleting a link via AJAX. * * @since 3.1.0 */
'rest_trash_not_supported',
                /* translators: %s: force=true */
                sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ),
                array( 'status' => 501 )
            );
        }

        $request->set_param( 'context', 'view' );

        $previous = $this->prepare_item_for_response( $term$request );

        $retval = wp_delete_term( $term->term_id, $term->taxonomy );

        if ( ! $retval ) {
            return new WP_Error(
                'rest_cannot_delete',
                __( 'The term cannot be deleted.' ),
                array( 'status' => 500 )
            );
        }

        $response = new WP_REST_Response();
        $response->set_data(
            

        }
        if ( $meta_keys ) {
            $meta_keys = implode( "', '", $meta_keys );
            $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
        }
    }

    if ( $wp_current_db_version < 22422 ) {
        $term = get_term_by( 'slug', 'post-format-standard', 'post_format' );
        if ( $term ) {
            wp_delete_term( $term->term_id, 'post_format' );
        }
    }
}

/** * Execute changes made in WordPress 3.7. * * @ignore * @since 3.7.0 * * @global int $wp_current_db_version The old (current) database version. */
$tag_ID = (int) $_REQUEST['tag_ID'];
        check_admin_referer( 'delete-tag_' . $tag_ID );

        if ( ! current_user_can( 'delete_term', $tag_ID ) ) {
            wp_die(
                '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
                '<p>' . __( 'Sorry, you are not allowed to delete this item.' ) . '</p>',
                403
            );
        }

        wp_delete_term( $tag_ID$taxonomy );

        $location = add_query_arg( 'message', 2, $referer );

        // When deleting a term, prevent the action from redirecting back to a term that no longer exists.         $location = remove_query_arg( array( 'tag_ID', 'action' )$location );

        break;

    case 'bulk-delete':
        check_admin_referer( 'bulk-tags' );

        
/** * Deletes one existing category. * * @since 2.0.0 * * @param int $cat_id Category term ID. * @return bool|int|WP_Error Returns true if completes delete action; false if term doesn't exist; * Zero on attempted deletion of default Category; WP_Error object is * also a possibility. */
function wp_delete_category( $cat_id ) {
    return wp_delete_term( $cat_id, 'category' );
}

/** * Retrieves the terms associated with the given object(s), in the supplied taxonomies. * * @since 2.3.0 * @since 4.2.0 Added support for 'taxonomy', 'parent', and 'term_taxonomy_id' values of `$orderby`. * Introduced `$parent` argument. * @since 4.4.0 Introduced `$meta_query` and `$update_term_meta_cache` arguments. When `$fields` is 'all' or * 'all_with_object_id', an array of `WP_Term` objects will be returned. * @since 4.7.0 Refactored to use WP_Term_Query, and to support any WP_Term_Query arguments. * @since 6.3.0 Passing `update_term_meta_cache` argument value false by default resulting in get_terms() to not * prime the term meta cache. * * @param int|int[] $object_ids The ID(s) of the object(s) to retrieve. * @param string|string[] $taxonomies The taxonomy names to retrieve terms from. * @param array|string $args See WP_Term_Query::__construct() for supported arguments. * @return WP_Term[]|int[]|string[]|string|WP_Error Array of terms, a count thereof as a numeric string, * or WP_Error if any of the taxonomies do not exist. * See WP_Term_Query::get_terms() for more information. */
Home | Imprint | This part of the site doesn't use cookies.