is_post_type_viewable example

$data['has_archive'] = $post_type->has_archive;
        }

        if ( rest_is_field_included( 'visibility', $fields ) ) {
            $data['visibility'] = array(
                'show_in_nav_menus' => (bool) $post_type->show_in_nav_menus,
                'show_ui'           => (bool) $post_type->show_ui,
            );
        }

        if ( rest_is_field_included( 'viewable', $fields ) ) {
            $data['viewable'] = is_post_type_viewable( $post_type );
        }

        if ( rest_is_field_included( 'labels', $fields ) ) {
            $data['labels'] = $post_type->labels;
        }

        if ( rest_is_field_included( 'name', $fields ) ) {
            $data['name'] = $post_type->label;
        }

        if ( rest_is_field_included( 'slug', $fields ) ) {
            
$post             = get_post( $post );
    $force_plain_link = wp_force_plain_post_permalink( $post );
    $parent_id        = $post->post_parent;
    $parent           = $parent_id ? get_post( $parent_id ) : false;
    $parent_valid     = true; // Default for no parent.     if (
        $parent_id &&
        (
            $post->post_parent === $post->ID ||
            ! $parent ||
            ! is_post_type_viewable( get_post_type( $parent ) )
        )
    ) {
        // Post is either its own parent or parent post unavailable.         $parent_valid = false;
    }

    if ( $force_plain_link || ! $parent_valid ) {
        $link = false;
    } elseif ( $wp_rewrite->using_permalinks() && $parent ) {
        if ( 'page' === $parent->post_type ) {
            $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.
'order'           => 'DESC',
        'post_type'       => 'post',
        'year'            => get_query_var( 'year' ),
        'monthnum'        => get_query_var( 'monthnum' ),
        'day'             => get_query_var( 'day' ),
        'w'               => get_query_var( 'w' ),
    );

    $parsed_args = wp_parse_args( $args$defaults );

    $post_type_object = get_post_type_object( $parsed_args['post_type'] );
    if ( ! is_post_type_viewable( $post_type_object ) ) {
        return;
    }

    $parsed_args['post_type'] = $post_type_object->name;

    if ( '' === $parsed_args['type'] ) {
        $parsed_args['type'] = 'monthly';
    }

    if ( ! empty( $parsed_args['limit'] ) ) {
        $parsed_args['limit'] = absint( $parsed_args['limit'] );
        
if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
                $actions['delete'] = sprintf(
                    '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
                    get_delete_post_link( $post->ID, '', true ),
                    /* translators: %s: Post title. */
                    esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' )$title ) ),
                    __( 'Delete Permanently' )
                );
            }
        }

        if ( is_post_type_viewable( $post_type_object ) ) {
            if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
                if ( $can_edit_post ) {
                    $preview_link    = get_preview_post_link( $post );
                    $actions['view'] = sprintf(
                        '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
                        esc_url( $preview_link ),
                        /* translators: %s: Post title. */
                        esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' )$title ) ),
                        __( 'Preview' )
                    );
                }
            }
/** * Adds the necessary rewrite rules for the post type. * * @since 4.6.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * @global WP $wp Current WordPress environment instance. */
    public function add_rewrite_rules() {
        global $wp_rewrite$wp;

        if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
            $wp->add_query_var( $this->query_var );
        }

        if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
            if ( $this->hierarchical ) {
                add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
            } else {
                add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
            }

            if ( $this->has_archive ) {
                

                ?> <input <?php echo $private_style; ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Draft' ); ?>" class="button" /> <span class="spinner"></span> <?php } elseif ( 'pending' === $post->post_status && $can_publish ) { ?> <input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save as Pending' ); ?>" class="button" /> <span class="spinner"></span> <?php } ?> </div> <?php         if ( is_post_type_viewable( $post_type_object ) ) :
            ?> <div id="preview-action"> <?php                 $preview_link = esc_url( get_preview_post_link( $post ) );
                if ( 'publish' === $post->post_status ) {
                    $preview_button_text = __( 'Preview Changes' );
                } else {
                    $preview_button_text = __( 'Preview' );
                }

                $preview_button = sprintf(
                    

function is_post_publicly_viewable( $post = null ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return false;
    }

    $post_type   = get_post_type( $post );
    $post_status = get_post_status( $post );

    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}

/** * Retrieves an array of the latest posts, or posts matching the given criteria. * * For more information on the accepted arguments, see the * {@link https://developer.wordpress.org/reference/classes/wp_query/ * WP_Query} documentation in the Developer Handbook. * * The `$ignore_sticky_posts` and `$no_found_rows` arguments are ignored by * this function and both are set to `true`. * * The defaults are as follows: * * @since 1.2.0 * * @see WP_Query * @see WP_Query::parse_query() * * @param array $args { * Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments. * * @type int $numberposts Total number of posts to retrieve. Is an alias of `$posts_per_page` * in WP_Query. Accepts -1 for all. Default 5. * @type int|string $category Category ID or comma-separated list of IDs (this or any children). * Is an alias of `$cat` in WP_Query. Default 0. * @type int[] $include An array of post IDs to retrieve, sticky posts will be included. * Is an alias of `$post__in` in WP_Query. Default empty array. * @type int[] $exclude An array of post IDs not to retrieve. Default empty array. * @type bool $suppress_filters Whether to suppress filters. Default true. * } * @return WP_Post[]|int[] Array of post objects or post IDs. */

    public function get_item( $request ) {
        $post = $this->get_post( $request['id'] );
        if ( is_wp_error( $post ) ) {
            return $post;
        }

        $data     = $this->prepare_item_for_response( $post$request );
        $response = rest_ensure_response( $data );

        if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
            $response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) );
        }

        return $response;
    }

    /** * Checks if a given request has access to create a post. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. */
$preview_post_link_html   = '';
$scheduled_post_link_html = '';
$view_post_link_html      = '';

$preview_page_link_html   = '';
$scheduled_page_link_html = '';
$view_page_link_html      = '';

$preview_url = get_preview_post_link( $post );

$viewable = is_post_type_viewable( $post_type_object );

if ( $viewable ) {

    // Preview post link.     $preview_post_link_html = sprintf(
        ' <a target="_blank" href="%1$s">%2$s</a>',
        esc_url( $preview_url ),
        __( 'Preview post' )
    );

    // Scheduled post preview link.
function build_query_vars_from_query_block( $block$page ) {
    $query = array(
        'post_type'    => 'post',
        'order'        => 'DESC',
        'orderby'      => 'date',
        'post__not_in' => array(),
    );

    if ( isset( $block->context['query'] ) ) {
        if ( ! empty( $block->context['query']['postType'] ) ) {
            $post_type_param = $block->context['query']['postType'];
            if ( is_post_type_viewable( $post_type_param ) ) {
                $query['post_type'] = $post_type_param;
            }
        }
        if ( isset( $block->context['query']['sticky'] ) && ! empty( $block->context['query']['sticky'] ) ) {
            $sticky = get_option( 'sticky_posts' );
            if ( 'only' === $block->context['query']['sticky'] ) {
                /* * Passing an empty array to post__in will return have_posts() as true (and all posts will be returned). * Logic should be used before hand to determine if WP_Query should be used in the event that the array * being passed to post__in is empty. * * @see https://core.trac.wordpress.org/ticket/28099 */

        $this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );

        foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
            if ( is_post_type_viewable( $t ) && $t->query_var ) {
                $post_type_query_vars[ $t->query_var ] = $post_type;
            }
        }

        foreach ( $this->public_query_vars as $wpvar ) {
            if ( isset( $this->extra_query_vars[ $wpvar ] ) ) {
                $this->query_vars[ $wpvar ] = $this->extra_query_vars[ $wpvar ];
            } elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] ) {
                wp_die( __( 'A variable mismatch has been detected.' )__( 'Sorry, you are not allowed to view this item.' ), 400 );
            } elseif ( isset( $_POST[ $wpvar ] ) ) {
                $this->query_vars[ $wpvar ] = $_POST[ $wpvar ];
            }
Home | Imprint | This part of the site doesn't use cookies.