wp_update_term example

$alias = get_term_by( 'slug', $args['alias_of']$taxonomy );
        if ( ! empty( $alias->term_group ) ) {
            // The alias we want is already in a group, so let's use that one.             $term_group = $alias->term_group;
        } elseif ( ! empty( $alias->term_id ) ) {
            /* * The alias is not in a group, so we create a new one * and add the alias to it. */
            $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1;

            wp_update_term(
                $alias->term_id,
                $taxonomy,
                array(
                    'term_group' => $term_group,
                )
            );
        }
    }

    /* * Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy, * unless a unique slug has been explicitly provided. */


    if ( empty( $parent )
        || ! term_exists( $parent$catarr['taxonomy'] )
        || ( $catarr['cat_ID'] && term_is_ancestor_of( $catarr['cat_ID']$parent$catarr['taxonomy'] ) ) ) {
        $parent = 0;
    }

    $args = compact( 'name', 'slug', 'parent', 'description' );

    if ( $update ) {
        $catarr['cat_ID'] = wp_update_term( $catarr['cat_ID']$catarr['taxonomy']$args );
    } else {
        $catarr['cat_ID'] = wp_insert_term( $catarr['cat_name']$catarr['taxonomy']$args );
    }

    if ( is_wp_error( $catarr['cat_ID'] ) ) {
        if ( $wp_error ) {
            return $catarr['cat_ID'];
        } else {
            return 0;
        }
    }
    
$term_data['parent'] = $content_struct['parent'];
        }

        if ( isset( $content_struct['description'] ) ) {
            $term_data['description'] = $content_struct['description'];
        }

        if ( isset( $content_struct['slug'] ) ) {
            $term_data['slug'] = $content_struct['slug'];
        }

        $term = wp_update_term( $term_id$taxonomy['name']$term_data );

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

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

        // Update term meta.         if ( isset( $content_struct['custom_fields'] ) ) {
            
$id = (int) $_POST['tax_ID'];

    if ( ! current_user_can( 'edit_term', $id ) ) {
        wp_die( -1 );
    }

    $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) );

    $tag                  = get_term( $id$taxonomy );
    $_POST['description'] = $tag->description;

    $updated = wp_update_term( $id$taxonomy$_POST );

    if ( $updated && ! is_wp_error( $updated ) ) {
        $tag = get_term( $updated['term_id']$taxonomy );
        if ( ! $tag || is_wp_error( $tag ) ) {
            if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
                wp_die( $tag->get_error_message() );
            }
            wp_die( __( 'Item not updated.' ) );
        }
    } else {
        if ( is_wp_error( $updated ) && $updated->get_error_message() ) {
            
'rest_term_invalid',
                    __( 'Parent term does not exist.' ),
                    array( 'status' => 400 )
                );
            }
        }

        $prepared_term = $this->prepare_item_for_database( $request );

        // Only update the term if we have something to update.         if ( ! empty( $prepared_term ) ) {
            $update = wp_update_term( $term->term_id, $term->taxonomy, wp_slash( (array) $prepared_term ) );

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

        $term = get_term( $term->term_id, $this->taxonomy );

        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
        do_action( "rest_insert_{$this->taxonomy}", $term$request, false );

        
do_action( 'wp_create_nav_menu', $_menu['term_id']$menu_data );

        return (int) $_menu['term_id'];
    }

    if ( ! $_menu || ! isset( $_menu->term_id ) ) {
        return 0;
    }

    $menu_id = (int) $_menu->term_id;

    $update_response = wp_update_term( $menu_id, 'nav_menu', $args );

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

    $menu_id = (int) $update_response['term_id'];

    /** * Fires after a navigation menu has been successfully updated. * * @since 3.0.0 * * @param int $menu_id ID of the updated menu. * @param array $menu_data An array of menu data. */
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
                '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
                403
            );
        }

        $tag = get_term( $tag_ID$taxonomy );
        if ( ! $tag ) {
            wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ) );
        }

        $ret = wp_update_term( $tag_ID$taxonomy$_POST );

        if ( $ret && ! is_wp_error( $ret ) ) {
            $location = add_query_arg( 'message', 3, $referer );
        } else {
            $location = add_query_arg(
                array(
                    'error'   => true,
                    'message' => 5,
                ),
                $referer
            );
        }
Home | Imprint | This part of the site doesn't use cookies.