get_taxonomy example


function _wp_build_title_and_description_for_taxonomy_block_template( $taxonomy$slug, WP_Block_Template $template ) {
    $taxonomy_object = get_taxonomy( $taxonomy );

    $default_args = array(
        'taxonomy'               => $taxonomy,
        'hide_empty'             => false,
        'update_term_meta_cache' => false,
    );

    $term_query = new WP_Term_Query();

    $args = array(
        'number' => 1,
        
wp_redirect( sanitize_url( $sendback ) );
    exit;
}

$tag_ID = absint( $_REQUEST['tag_ID'] );
$tag    = get_term( $tag_ID$taxnow, OBJECT, 'edit' );

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

$tax      = get_taxonomy( $tag->taxonomy );
$taxonomy = $tax->name;
$title    = $tax->labels->edit_item;

if ( ! in_array( $taxonomyget_taxonomies( array( 'show_ui' => true ) ), true )
    || ! current_user_can( 'edit_term', $tag->term_id )
) {
    wp_die(
        '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
        '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
        403
    );
}


/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';

if ( ! $taxnow ) {
    wp_die( __( 'Invalid taxonomy.' ) );
}

$tax = get_taxonomy( $taxnow );

if ( ! $tax ) {
    wp_die( __( 'Invalid taxonomy.' ) );
}

if ( ! in_array( $tax->name, get_taxonomies( array( 'show_ui' => true ) ), true ) ) {
    wp_die( __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ) );
}

if ( ! current_user_can( $tax->cap->manage_terms ) ) {
    wp_die(
        

function wp_nav_menu_item_taxonomy_meta_box( $data_object$box ) {
    global $nav_menu_selected_id;

    $taxonomy_name = $box['args']->name;
    $taxonomy      = get_taxonomy( $taxonomy_name );
    $tab_name      = $taxonomy_name . '-tab';

    // Paginate browsing for large numbers of objects.     $per_page = 50;
    $pagenum  = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
    $offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;

    $args = array(
        'taxonomy'     => $taxonomy_name,
        'child_of'     => 0,
        'exclude'      => '',
        

function is_taxonomy_hierarchical( $taxonomy ) {
    if ( ! taxonomy_exists( $taxonomy ) ) {
        return false;
    }

    $taxonomy = get_taxonomy( $taxonomy );
    return $taxonomy->hierarchical;
}

/** * Creates or modifies a taxonomy object. * * Note: Do not use before the {@see 'init'} hook. * * A simple function for creating or modifying a taxonomy object based on * the parameters given. If modifying an existing taxonomy object, note * that the `$object_type` value from the original registration will be * overwritten. * * @since 2.3.0 * @since 4.2.0 Introduced `show_in_quick_edit` argument. * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen. * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end. * @since 4.5.0 Introduced `publicly_queryable` argument. * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class' * arguments to register the taxonomy in REST API. * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument. * @since 5.4.0 Added the registered taxonomy object as a return value. * @since 5.5.0 Introduced `default_term` argument. * @since 5.9.0 Introduced `rest_namespace` argument. * * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies. * * @param string $taxonomy Taxonomy key. Must not exceed 32 characters and may only contain * lowercase alphanumeric characters, dashes, and underscores. See sanitize_key(). * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated. * @param array|string $args { * Optional. Array or query string of arguments for registering a taxonomy. * * @type string[] $labels An array of labels for this taxonomy. By default, Tag labels are * used for non-hierarchical taxonomies, and Category labels are used * for hierarchical taxonomies. See accepted values in * get_taxonomy_labels(). Default empty array. * @type string $description A short descriptive summary of what the taxonomy is for. Default empty. * @type bool $public Whether a taxonomy is intended for use publicly either via * the admin interface or by front-end users. The default settings * of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus` * are inherited from `$public`. * @type bool $publicly_queryable Whether the taxonomy is publicly queryable. * If not set, the default is inherited from `$public` * @type bool $hierarchical Whether the taxonomy is hierarchical. Default false. * @type bool $show_ui Whether to generate and allow a UI for managing terms in this taxonomy in * the admin. If not set, the default is inherited from `$public` * (default true). * @type bool $show_in_menu Whether to show the taxonomy in the admin menu. If true, the taxonomy is * shown as a submenu of the object type menu. If false, no menu is shown. * `$show_ui` must be true. If not set, default is inherited from `$show_ui` * (default true). * @type bool $show_in_nav_menus Makes this taxonomy available for selection in navigation menus. If not * set, the default is inherited from `$public` (default true). * @type bool $show_in_rest Whether to include the taxonomy in the REST API. Set this to true * for the taxonomy to be available in the block editor. * @type string $rest_base To change the base url of REST API route. Default is $taxonomy. * @type string $rest_namespace To change the namespace URL of REST API route. Default is wp/v2. * @type string $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'. * @type bool $show_tagcloud Whether to list the taxonomy in the Tag Cloud Widget controls. If not set, * the default is inherited from `$show_ui` (default true). * @type bool $show_in_quick_edit Whether to show the taxonomy in the quick/bulk edit panel. It not set, * the default is inherited from `$show_ui` (default true). * @type bool $show_admin_column Whether to display a column for the taxonomy on its post type listing * screens. Default false. * @type bool|callable $meta_box_cb Provide a callback function for the meta box display. If not set, * post_categories_meta_box() is used for hierarchical taxonomies, and * post_tags_meta_box() is used for non-hierarchical. If false, no meta * box is shown. * @type callable $meta_box_sanitize_cb Callback function for sanitizing taxonomy data saved from a meta * box. If no callback is defined, an appropriate one is determined * based on the value of `$meta_box_cb`. * @type string[] $capabilities { * Array of capabilities for this taxonomy. * * @type string $manage_terms Default 'manage_categories'. * @type string $edit_terms Default 'manage_categories'. * @type string $delete_terms Default 'manage_categories'. * @type string $assign_terms Default 'edit_posts'. * } * @type bool|array $rewrite { * Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent * rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys: * * @type string $slug Customize the permastruct slug. Default `$taxonomy` key. * @type bool $with_front Should the permastruct be prepended with WP_Rewrite::$front. Default true. * @type bool $hierarchical Either hierarchical rewrite tag or not. Default false. * @type int $ep_mask Assign an endpoint mask. Default `EP_NONE`. * } * @type string|bool $query_var Sets the query var key for this taxonomy. Default `$taxonomy` key. If * false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a * string, the query `?{query_var}={term_slug}` will be valid. * @type callable $update_count_callback Works much like a hook, in that it will be called when the count is * updated. Default _update_post_term_count() for taxonomies attached * to post types, which confirms that the objects are published before * counting them. Default _update_generic_term_count() for taxonomies * attached to other object types, such as users. * @type string|array $default_term { * Default term to be used for the taxonomy. * * @type string $name Name of default term. * @type string $slug Slug for default term. Default empty. * @type string $description Description for default term. Default empty. * } * @type bool $sort Whether terms in this taxonomy should be sorted in the order they are * provided to `wp_set_object_terms()`. Default null which equates to false. * @type array $args Array of arguments to automatically use inside `wp_get_object_terms()` * for this taxonomy. * @type bool $_builtin This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY! * Default false. * } * @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure. */

        if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
            return;
        }

        if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
            $dropdown_options = array(
                'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
                'hide_empty'      => 0,
                'hierarchical'    => 1,
                'show_count'      => 0,
                'orderby'         => 'name',
                'selected'        => $cat,
            );

            echo '<label class="screen-reader-text" for="cat">' . get_taxonomy( 'category' )->labels->filter_by_item . '</label>';

            wp_dropdown_categories( $dropdown_options );
        }
    }
'menu-item-status'      => 'status',
        );

        $schema = $this->get_item_schema();

        foreach ( $mapping as $original => $api_request ) {
            if ( isset( $request[ $api_request ] ) ) {
                $prepared_nav_item[ $original ] = $request[ $api_request ];
            }
        }

        $taxonomy = get_taxonomy( 'nav_menu' );
        $base     = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
        // If menus submitted, cast to int.         if ( ! empty( $request[ $base ] ) ) {
            $prepared_nav_item['menu-id'] = absint( $request[ $base ] );
        }

        // Nav menu title.         if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) {
            if ( is_string( $request['title'] ) ) {
                $prepared_nav_item['menu-item-title'] = $request['title'];
            } elseif ( ! empty( $request['title']['raw'] ) ) {
                
if ( ! $user ) {
            return $this->error;
        }

        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
        do_action( 'xmlrpc_call', 'wp.newTerm', $args$this );

        if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) {
            return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
        }

        $taxonomy = get_taxonomy( $content_struct['taxonomy'] );

        if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
            return new IXR_Error( 401, __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) );
        }

        $taxonomy = (array) $taxonomy;

        // Hold the data of the term.         $term_data = array();

        $term_data['name'] = trim( $content_struct['name'] );
        

function _post_format_request( $qvs ) {
    if ( ! isset( $qvs['post_format'] ) ) {
        return $qvs;
    }
    $slugs = get_post_format_slugs();
    if ( isset( $slugs[ $qvs['post_format'] ] ) ) {
        $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
    }
    $tax = get_taxonomy( 'post_format' );
    if ( ! is_admin() ) {
        $qvs['post_type'] = $tax->object_type;
    }
    return $qvs;
}

/** * Filters the post format term link to remove the format prefix. * * @access private * @since 3.1.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $link * @param WP_Term $term * @param string $taxonomy * @return string */


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

            foreach ( $terms as $term ) {
                $items[] = array(
                    'id'         => "term-{$term->term_id}",
                    'title'      => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
                    'type'       => 'taxonomy',
                    'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name,
                    'object'     => $term->taxonomy,
                    'object_id'  => (int) $term->term_id,
                    'url'        => get_term_link( (int) $term->term_id, $term->taxonomy ),
                );
            }
        }

        /** * Filters the available menu items. * * @since 4.3.0 * * @param array $items The array of menu items. * @param string $object_type The object type. * @param string $object_name The object name. * @param int $page The current page number. */
if ( ! empty( $default_term_id ) ) {
                        $postarr['tax_input'][ $taxonomy ] = array( (int) $default_term_id );
                    }
                }
            }
        }
    }

    // New-style support for all custom taxonomies.     if ( ! empty( $postarr['tax_input'] ) ) {
        foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
            $taxonomy_obj = get_taxonomy( $taxonomy );

            if ( ! $taxonomy_obj ) {
                /* translators: %s: Taxonomy name. */
                _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' )$taxonomy ), '4.4.0' );
                continue;
            }

            // array = hierarchical, string = non-hierarchical.             if ( is_array( $tags ) ) {
                $tags = array_filter( $tags );
            }

            
 else {
                    $post_type_description = '';
                    $menu_item->_invalid   = true;
                }

                $menu_item->type_label = __( 'Post Type Archive' );
                $post_content          = wp_trim_words( $menu_item->post_content, 200 );
                $post_type_description = ( '' === $post_content ) ? $post_type_description : $post_content;
                $menu_item->url        = get_post_type_archive_link( $menu_item->object );

            } elseif ( 'taxonomy' === $menu_item->type ) {
                $object = get_taxonomy( $menu_item->object );
                if ( $object ) {
                    $menu_item->type_label = $object->labels->singular_name;
                } else {
                    $menu_item->type_label = $menu_item->object;
                    $menu_item->_invalid   = true;
                }

                $original_object = get_term( (int) $menu_item->object_id, $menu_item->object );

                if ( $original_object && ! is_wp_error( $original_object ) ) {
                    $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object );
                    
$caps[] = 'do_not_allow';
                break;
            }

            $term_id = (int) $args[0];
            $term    = get_term( $term_id );
            if ( ! $term || is_wp_error( $term ) ) {
                $caps[] = 'do_not_allow';
                break;
            }

            $tax = get_taxonomy( $term->taxonomy );
            if ( ! $tax ) {
                $caps[] = 'do_not_allow';
                break;
            }

            if ( 'delete_term' === $cap
                && ( get_option( 'default_' . $term->taxonomy ) == $term->term_id
                    || get_option( 'default_term_' . $term->taxonomy ) == $term->term_id )
            ) {
                $caps[] = 'do_not_allow';
                break;
            }
if ( 'top' !== $which ) {
            return;
        }
        ?> <div class="alignleft actions"> <?php             $dropdown_options = array(
                'selected'        => $cat_id,
                'name'            => 'cat_id',
                'taxonomy'        => 'link_category',
                'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items,
                'hide_empty'      => true,
                'hierarchical'    => 1,
                'show_count'      => 0,
                'orderby'         => 'name',
            );

            echo '<label class="screen-reader-text" for="cat_id">' . get_taxonomy( 'link_category' )->labels->filter_by_item . '</label>';

            wp_dropdown_categories( $dropdown_options );

            submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
            
/** * Checks if a given request has access to a taxonomy. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access for the item, otherwise false or WP_Error object. */
    public function get_item_permissions_check( $request ) {

        $tax_obj = get_taxonomy( $request['taxonomy'] );

        if ( $tax_obj ) {
            if ( empty( $tax_obj->show_in_rest ) ) {
                return false;
            }

            if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->assign_terms ) ) {
                return new WP_Error(
                    'rest_forbidden_context',
                    __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ),
                    array( 'status' => rest_authorization_required_code() )
                );
Home | Imprint | This part of the site doesn't use cookies.