get_post_type_object example

private $parent_base;

    /** * Constructor. * * @since 5.0.0 * * @param string $parent_post_type Post type of the parent. */
    public function __construct( $parent_post_type ) {
        $this->parent_post_type = $parent_post_type;
        $post_type_object       = get_post_type_object( $parent_post_type );
        $parent_controller      = $post_type_object->get_rest_controller();

        if ( ! $parent_controller ) {
            $parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
        }

        $this->parent_controller    = $parent_controller;
        $this->revisions_controller = new WP_REST_Revisions_Controller( $parent_post_type );
        $this->rest_base            = 'autosaves';
        $this->parent_base          = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
        $this->namespace            = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
    }
if ( '' === $original_title ) {
                    /* translators: %d: ID of a post. */
                    $original_title = sprintf( __( '#%d (no title)' )$original_object->ID );
                }
            }
        } elseif ( 'taxonomy' === $item->type && ! empty( $item->object_id ) ) {
            $original_term_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
            if ( ! is_wp_error( $original_term_title ) ) {
                $original_title = $original_term_title;
            }
        } elseif ( 'post_type_archive' === $item->type ) {
            $original_object = get_post_type_object( $item->object );
            if ( $original_object ) {
                $original_title = $original_object->labels->archives;
            }
        }
        $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) );
        return $original_title;
    }

    /** * Get type label. * * @since 4.7.0 * * @param object $item Nav menu item. * @return string The type label. */
protected $allow_batch = array( 'v1' => true );

    /** * Constructor. * * @since 4.7.0 * * @param string $post_type Post type. */
    public function __construct( $post_type ) {
        $this->post_type = $post_type;
        $obj             = get_post_type_object( $post_type );
        $this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
        $this->namespace = ! empty( $obj->rest_namespace ) ? $obj->rest_namespace : 'wp/v2';

        $this->meta = new WP_REST_Post_Meta_Fields( $this->post_type );
    }

    /** * Registers the routes for posts. * * @since 4.7.0 * * @see register_rest_route() */
/** * Checks if a given request has access to read fallbacks. * * @since 6.3.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
    public function get_item_permissions_check( $request ) {

        $post_type = get_post_type_object( $this->post_type );

        // Getting fallbacks requires creating and reading `wp_navigation` posts.         if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( 'edit_theme_options' ) || ! current_user_can( 'edit_posts' ) ) {
            return new WP_Error(
                'rest_cannot_create',
                __( 'Sorry, you are not allowed to create Navigation Menus as this user.' ),
                array( 'status' => rest_authorization_required_code() )
            );
        }

        if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) {
            
$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
            }
        }

        if ( $thumbnail_support ) {
            $featured_image_id                   = get_post_meta( $post->ID, '_thumbnail_id', true );
            $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
        }
    }

    if ( $post ) {
        $post_type_object = get_post_type_object( $post->post_type );
    } else {
        $post_type_object = get_post_type_object( 'post' );
    }

    $strings = array(
        // Generic.         'mediaFrameDefaultTitle'      => __( 'Media' ),
        'url'                         => __( 'URL' ),
        'addMedia'                    => __( 'Add media' ),
        'search'                      => __( 'Search' ),
        'select'                      => __( 'Select' ),
        
$_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group.
$types   = (array) get_post_types(
    array(
        'show_ui'      => true,
        '_builtin'     => false,
        'show_in_menu' => true,
    )
);
$builtin = array( 'post', 'page' );
foreach ( array_merge( $builtin$types ) as $ptype ) {
    $ptype_obj = get_post_type_object( $ptype );
    // Check if it should be a submenu.     if ( true !== $ptype_obj->show_in_menu ) {
        continue;
    }
    $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first.     $ptype_for_id        = sanitize_html_class( $ptype );

    $menu_icon = 'dashicons-admin-post';
    if ( is_string( $ptype_obj->menu_icon ) ) {
        // Special handling for data:image/svg+xml and Dashicons.         if ( str_starts_with( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || str_starts_with( $ptype_obj->menu_icon, 'dashicons-' ) ) {
            
// If there is a post.     if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
        $title = single_post_title( '', false );
    }

    // If there's a post type archive.     if ( is_post_type_archive() ) {
        $post_type = get_query_var( 'post_type' );
        if ( is_array( $post_type ) ) {
            $post_type = reset( $post_type );
        }
        $post_type_object = get_post_type_object( $post_type );
        if ( ! $post_type_object->has_archive ) {
            $title = post_type_archive_title( '', false );
        }
    }

    // If there's a category or tag.     if ( is_category() || is_tag() ) {
        $title = single_term_title( '', false );
    }

    // If there's a taxonomy.
'supportsLayout'            => wp_theme_has_theme_json(),
    'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
);

// Add additional back-compat patterns registered by `current_screen` et al. $custom_settings['__experimentalAdditionalBlockPatterns']          = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
$custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );

$editor_settings = get_block_editor_settings( $custom_settings$block_editor_context );

if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) {
    $post_type = get_post_type_object( $_GET['postType'] );
    if ( ! $post_type ) {
        wp_die( __( 'Invalid post type.' ) );
    }
}

$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
$active_theme            = get_stylesheet();

$navigation_rest_route = rest_get_route_for_post_type_items(
    'wp_navigation'
);


function get_editable_user_ids( $user_id$exclude_zeros = true, $post_type = 'post' ) {
    _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

    global $wpdb;

    if ( ! $user = get_userdata( $user_id ) )
        return array();
    $post_type_obj = get_post_type_object($post_type);

    if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
        if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros )
            return array($user->ID);
        else
            return array();
    }

    if ( !is_multisite() )
        $level_key = $wpdb->get_blog_prefix() . 'user_level';
    else
        

    $filename = apply_filters( 'export_wp_filename', $wp_filename$sitename$date );

    header( 'Content-Description: File Transfer' );
    header( 'Content-Disposition: attachment; filename=' . $filename );
    header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );

    if ( 'all' !== $args['content'] && post_type_exists( $args['content'] ) ) {
        $ptype = get_post_type_object( $args['content'] );
        if ( ! $ptype->can_export ) {
            $args['content'] = 'post';
        }

        $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
    } else {
        $post_types = get_post_types( array( 'can_export' => true ) );
        $esses      = array_fill( 0, count( $post_types ), '%s' );

        // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare         $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types );
    }
    if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) {
        return;
    }

    // Don't show for users who can't access the customizer or when in the admin.     if ( ! current_user_can( 'customize' ) || is_admin() ) {
        return;
    }

    // Don't show if the user cannot edit a given customize_changeset post currently being previewed.     if ( is_customize_preview() && $wp_customize->changeset_post_id()
        && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() )
    ) {
        return;
    }

    $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    if ( is_customize_preview() && $wp_customize->changeset_uuid() ) {
        $current_url = remove_query_arg( 'customize_changeset_uuid', $current_url );
    }

    $customize_url = add_query_arg( 'url', urlencode( $current_url )wp_customize_url() );
    if ( is_customize_preview() ) {
        
if ( 'revision' === $post->post_type ) {
                $caps[] = 'do_not_allow';
                break;
            }

            if ( ( get_option( 'page_for_posts' ) == $post->ID ) || ( get_option( 'page_on_front' ) == $post->ID ) ) {
                $caps[] = 'manage_options';
                break;
            }

            $post_type = get_post_type_object( $post->post_type );
            if ( ! $post_type ) {
                /* translators: 1: Post type, 2: Capability name. */
                $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' );

                _doing_it_wrong(
                    __FUNCTION__,
                    sprintf(
                        $message,
                        '<code>' . $post->post_type . '</code>',
                        '<code>' . $cap . '</code>'
                    ),
                    


if ( $admin_title === $title ) {
    /* translators: Admin screen title. %s: Admin screen name. */
    $admin_title = sprintf( __( '%s &#8212; WordPress' )$title );
} else {
    $screen_title = $title;

    if ( 'post' === $current_screen->base && 'add' !== $current_screen->action ) {
        $post_title = get_the_title();
        if ( ! empty( $post_title ) ) {
            $post_type_obj = get_post_type_object( $typenow );
            $screen_title  = sprintf(
                /* translators: Editor admin screen title. 1: "Edit item" text for the post type, 2: Post title. */
                __( '%1$s &#8220;%2$s&#8221;' ),
                $post_type_obj->labels->edit_item,
                $post_title
            );
        }
    }

    /* translators: Admin screen title. 1: Admin screen name, 2: Network or site name. */
    $admin_title = sprintf( __( '%1$s &lsaquo; %2$s &#8212; WordPress' )$screen_title$admin_title );
}
if ( $auto_draft_page_options ) {
                        $dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
                    }
                }

                echo $dropdown;
                ?> <?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?> <button type="button" class="button-link add-new-toggle"> <?php                         /* translators: %s: Add New Page label. */
                        printf( __( '+ %s' )get_post_type_object( 'page' )->labels->add_new_item );
                        ?> </button> <div class="new-content-item"> <label for="create-input-<?php echo esc_attr( $this->id ); ?>"><span class="screen-reader-text"> <?php                             /* translators: Hidden accessibility text. */
                            _e( 'New page title' );
                            ?> </span></label> <input type="text" id="create-input-<?php echo esc_attr( $this->id ); ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title&hellip;' ); ?>"> <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button> </div>
private $parent_base;

    /** * Constructor. * * @since 4.7.0 * * @param string $parent_post_type Post type of the parent. */
    public function __construct( $parent_post_type ) {
        $this->parent_post_type = $parent_post_type;
        $post_type_object       = get_post_type_object( $parent_post_type );
        $parent_controller      = $post_type_object->get_rest_controller();

        if ( ! $parent_controller ) {
            $parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
        }

        $this->parent_controller = $parent_controller;
        $this->rest_base         = 'revisions';
        $this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
        $this->namespace         = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
    }

    
Home | Imprint | This part of the site doesn't use cookies.