-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Ticket/19958 #10798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Ticket/19958 #10798
Changes from all commits
3372656
713b4bb
fc4fcce
593c421
967dda4
e8c263f
692cbe4
3cef0e1
b6bfb35
71b25bd
c5208b4
e7ae7b2
dbc3b1c
c5aa4f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,14 @@ | |
| if ( ! is_utf8_charset() ) { | ||
| add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); | ||
| } | ||
| /** This filter is documented in wp-includes/class-wp-query.php:1057 */ | ||
| $post_types_allowed_on_home_page = apply_filters( 'post_types_allowed_on_home_page', array_keys( get_post_types( array( 'show_in_home_page_list' => true ) ) ) ); | ||
| $args = array( | ||
| 'post_type' => $post_types_allowed_on_home_page, | ||
| 'post_status' => 'publish', | ||
| 'fields' => 'ids', | ||
| ); | ||
| $allowed_pages = new WP_Query( $args ); | ||
| ?> | ||
|
|
||
| <?php if ( ! get_pages() ) : ?> | ||
|
|
@@ -76,51 +84,89 @@ | |
| if ( 'posts' !== get_option( 'show_on_front' ) ) : | ||
| update_option( 'show_on_front', 'posts' ); | ||
| endif; | ||
| endif; | ||
|
|
||
| else : | ||
| if ( 'page' === get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { | ||
| update_option( 'show_on_front', 'posts' ); | ||
| } | ||
| if ( 'page' === get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { | ||
| update_option( 'show_on_front', 'posts' ); | ||
| } | ||
|
|
||
| $your_homepage_displays_title = __( 'Your homepage displays' ); | ||
| ?> | ||
| $your_homepage_displays_title = __( 'Your homepage displays' ); | ||
| ?> | ||
| <table class="form-table" role="presentation"> | ||
| <tr> | ||
| <th scope="row"><?php echo $your_homepage_displays_title; ?></th> | ||
| <td id="front-static-pages"><fieldset> | ||
| <legend class="screen-reader-text"><span><?php echo $your_homepage_displays_title; ?></span></legend> | ||
| <p><label> | ||
| <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> /> | ||
| <?php _e( 'Your latest posts' ); ?> | ||
| <?php | ||
| $allowed_archives_on_home_page = $post_types_allowed_on_home_page; | ||
| unset( $allowed_archives_on_home_page['page'] ); | ||
| if( 1 === count( $allowed_archives_on_home_page ) ) { | ||
|
Check failure on line 104 in src/wp-admin/options-reading.php
|
||
| _e( sprintf( 'Your latest %s', get_post_type_object( $allowed_archives_on_home_page[0] )->labels->name ) ); | ||
| ?><input name="show_on_front" type="hidden" value="<?php echo esc_attr( $allowed_archives_on_home_page[0] ); ?>" /> <?php | ||
| } else { | ||
| $output = "<select name='show_on_front' id='homepage_types'>\n"; | ||
| $output .= sprintf( '<option value="page" %s>A static page (select below)</option>', selected( -1, strtolower( get_option( 'show_on_front' ) ), false ) ) ; | ||
| foreach ( $allowed_archives_on_home_page as $post_type ){ | ||
| $post_type = ( 'posts' === $post_type ) ? 'post' : $post_type; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oof
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code came from the old code, so I kept it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, its just ugly hence "oof". fine to keep. |
||
| $output .= sprintf( '<option value="%s" %s>%s</option>', | ||
| $post_type, | ||
| selected( $post_type, strtolower( get_option( 'show_on_front' ) ),false ), | ||
| sprintf( __( 'Your latest %s' ), get_post_type_object( $post_type )->labels->name ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we always assume
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the code, it looks like it is always set. src/wp-includes/class-wp-post-type.php:567
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for confirming. |
||
| ) ; | ||
| } | ||
| $output .= "</select>\n"; | ||
|
|
||
| echo $output; | ||
| } | ||
| ?> | ||
| </label> | ||
| </p> | ||
| <?php if ( empty( $allowed_pages->posts ) ) : ?> | ||
| <p> <?php | ||
| $content_type_links = array(); | ||
| foreach ( $post_types_allowed_on_home_page as $type ){ | ||
| $content_type_links[] = sprintf( '<a href="%s">%s</a>', | ||
| 'edit.php?post_type=' . $type, ucfirst( $type ) ); | ||
| } | ||
| printf( | ||
| /* translators: %s: URL to Pages screen. */ | ||
| __( 'No selectable pages found! Add/Publish at least one of these content types %s' ), | ||
| implode( ', ', $content_type_links ) | ||
| ); | ||
| ?> | ||
| </p> | ||
| <?php else : ?> | ||
| <p><label> | ||
| <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> | ||
| <?php | ||
| printf( | ||
| /* translators: %s: URL to Pages screen. */ | ||
| __( 'A <a href="%s">static page</a> (select below)' ), | ||
| 'edit.php?post_type=page' | ||
| ); | ||
| ?> | ||
| </label> | ||
| </p> | ||
| <ul> | ||
| <ul class="staticPages"> | ||
| <li><label for="page_on_front"> | ||
| <?php | ||
|
|
||
| $output = "<select name='page_on_front' >\n"; | ||
| foreach ( $post_types_allowed_on_home_page as $post_type ){ | ||
| $post_type = ( 'posts' === $post_type ) ? 'post' : $post_type; | ||
| $output .= sprintf( '<optgroup label="%s">', get_post_type_object( $post_type )->labels->name ); | ||
| $args = array( | ||
| 'post_type' => $post_type, | ||
| 'post_status' => 'publish', | ||
| ); | ||
| $cpt_posts = new WP_Query( $args ); | ||
| foreach ( $cpt_posts->posts as $cpt_post ) { | ||
| $output .= sprintf( '<option value="%s" %s>%s</option>', | ||
| $cpt_post->ID, | ||
| selected( $cpt_post->ID, get_option( 'page_on_front' ),false ), | ||
| $cpt_post->post_name ) ; | ||
| } | ||
| $output .= '</optgroup>'; | ||
| } | ||
| $output .= "</select>\n"; | ||
|
|
||
|
|
||
| printf( | ||
| /* translators: %s: Select field to choose the front page. */ | ||
| __( 'Homepage: %s' ), | ||
| wp_dropdown_pages( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we use |
||
| array( | ||
| 'name' => 'page_on_front', | ||
| 'echo' => 0, | ||
| 'show_option_none' => __( '— Select —' ), | ||
| 'option_none_value' => '0', | ||
| 'selected' => get_option( 'page_on_front' ), | ||
| ) | ||
| ) | ||
| ); | ||
| __( 'Homepage: %s' ), $output ); | ||
| ?> | ||
| </label></li> | ||
| <li><label for="page_for_posts"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -823,3 +823,67 @@ | |
| */ | ||
| return apply_filters( 'twentytwenty_get_elements_array', $elements ); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //add_filter( 'post_types_allowed_on_home_page', 'rsadfd_post_types_allowed_on_home_page'); | ||
| function rsadfd_post_types_allowed_on_home_page( $posts ){ | ||
|
|
||
| $posts[] = 'book'; | ||
| return $posts; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Register a custom post type called "book". | ||
| * | ||
| * @see get_post_type_labels() for label keys. | ||
| */ | ||
| function wpdocs_codex_book_init() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this section for testing?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes I need to remove it |
||
| $labels = array( | ||
| 'name' => _x( 'Books', 'Post type general name', 'textdomain' ), | ||
| 'singular_name' => _x( 'Book', 'Post type singular name', 'textdomain' ), | ||
| 'menu_name' => _x( 'Books', 'Admin Menu text', 'textdomain' ), | ||
| 'name_admin_bar' => _x( 'Book', 'Add New on Toolbar', 'textdomain' ), | ||
| 'add_new' => __( 'Add New', 'textdomain' ), | ||
| 'add_new_item' => __( 'Add New Book', 'textdomain' ), | ||
| 'new_item' => __( 'New Book', 'textdomain' ), | ||
| 'edit_item' => __( 'Edit Book', 'textdomain' ), | ||
| 'view_item' => __( 'View Book', 'textdomain' ), | ||
| 'all_items' => __( 'All Books', 'textdomain' ), | ||
| 'search_items' => __( 'Search Books', 'textdomain' ), | ||
| 'parent_item_colon' => __( 'Parent Books:', 'textdomain' ), | ||
| 'not_found' => __( 'No books found.', 'textdomain' ), | ||
| 'not_found_in_trash' => __( 'No books found in Trash.', 'textdomain' ), | ||
| 'featured_image' => _x( 'Book Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'textdomain' ), | ||
| 'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'textdomain' ), | ||
| 'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'textdomain' ), | ||
| 'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'textdomain' ), | ||
| 'archives' => _x( 'Book archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'textdomain' ), | ||
| 'insert_into_item' => _x( 'Insert into book', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'textdomain' ), | ||
| 'uploaded_to_this_item' => _x( 'Uploaded to this book', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'textdomain' ), | ||
| 'filter_items_list' => _x( 'Filter books list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'textdomain' ), | ||
| 'items_list_navigation' => _x( 'Books list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'textdomain' ), | ||
| 'items_list' => _x( 'Books list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'textdomain' ), | ||
| ); | ||
|
|
||
| $args = array( | ||
| 'labels' => $labels, | ||
| 'public' => true, | ||
| 'publicly_queryable' => true, | ||
| 'show_ui' => true, | ||
| 'show_in_menu' => true, | ||
| 'query_var' => true, | ||
| 'rewrite' => array( 'slug' => 'book' ), | ||
| 'capability_type' => 'post', | ||
| 'has_archive' => true, | ||
| 'hierarchical' => false, | ||
| 'menu_position' => null, | ||
| 'show_in_home_page_list'=> true, | ||
| 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), | ||
| ); | ||
|
|
||
| register_post_type( 'book', $args ); | ||
| } | ||
|
|
||
| add_action( 'init', 'wpdocs_codex_book_init' ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,52 @@ | |
| endif; | ||
| add_action( 'init', 'twentytwentyfive_register_block_bindings' ); | ||
|
|
||
| /** | ||
| * Registers the 'books' custom post type. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks lioke testing code that can be removed |
||
| * | ||
| * @since Twenty Twenty-Five 1.0 | ||
| * | ||
| * @return void | ||
| */ | ||
| function twentytwentyfive_register_books_post_type() { | ||
| $labels = array( | ||
| 'name' => _x( 'Books', 'post type general name', 'twentytwentyfive' ), | ||
| 'singular_name' => _x( 'Book', 'post type singular name', 'twentytwentyfive' ), | ||
| 'menu_name' => _x( 'Books', 'admin menu', 'twentytwentyfive' ), | ||
| 'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'twentytwentyfive' ), | ||
| 'add_new' => _x( 'Add New', 'book', 'twentytwentyfive' ), | ||
| 'add_new_item' => __( 'Add New Book', 'twentytwentyfive' ), | ||
| 'new_item' => __( 'New Book', 'twentytwentyfive' ), | ||
| 'edit_item' => __( 'Edit Book', 'twentytwentyfive' ), | ||
| 'view_item' => __( 'View Book', 'twentytwentyfive' ), | ||
| 'all_items' => __( 'All Books', 'twentytwentyfive' ), | ||
| 'search_items' => __( 'Search Books', 'twentytwentyfive' ), | ||
| 'parent_item_colon' => __( 'Parent Books:', 'twentytwentyfive' ), | ||
| 'not_found' => __( 'No books found.', 'twentytwentyfive' ), | ||
| 'not_found_in_trash' => __( 'No books found in Trash.', 'twentytwentyfive' ), | ||
| ); | ||
|
|
||
| $args = array( | ||
| 'labels' => $labels, | ||
| 'public' => true, | ||
| 'publicly_queryable' => true, | ||
| 'show_ui' => true, | ||
| 'show_in_menu' => true, | ||
| 'query_var' => true, | ||
| 'rewrite' => array( 'slug' => 'book' ), | ||
| 'capability_type' => 'post', | ||
| 'has_archive' => true, | ||
| 'hierarchical' => false, | ||
| 'menu_position' => null, | ||
| 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), | ||
| 'show_in_rest' => true, | ||
| 'show_in_home_page_list' => true, | ||
| ); | ||
|
|
||
| register_post_type( 'book', $args ); | ||
| } | ||
| add_action( 'init', 'twentytwentyfive_register_books_post_type' ); | ||
|
|
||
| if ( ! function_exists( 'twentytwentyfive_format_binding' ) ) : | ||
| /** | ||
| * Callback function for the post format name block binding source. | ||
|
|
@@ -156,4 +202,6 @@ | |
| return get_post_format_string( $post_format_slug ); | ||
| } | ||
| } | ||
| endif; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1044,6 +1044,28 @@ public function parse_query( $query = '' ) { | |
| $this->is_home = true; | ||
| } | ||
|
|
||
| // this block control what is CPT is used for the home page archive list | ||
| if ( $this->is_home && 'page' !== get_option( 'show_on_front' ) && empty( $query_vars['post_type'] ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An inline comment explaining why this is being added here would be helpful (not obvious to me)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
| /** | ||
| * Filters the CPT that can be displayed as home page achivle list. | ||
| * | ||
| * Only 'post' is set as default. | ||
| * | ||
| * @since 7.0.0 | ||
| * | ||
| * @param string[] $search_columns Array of post-types. | ||
| */ | ||
| $post_types_allowed_on_home_page = apply_filters( 'post_types_allowed_on_home_page', array_keys( get_post_types( array( 'show_in_home_page_list' => true ) ) ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filters get documented once, other instances include a reference ( // This filter is documented in ...)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| $front_page_post_type = get_option( 'show_on_front' ); | ||
| if ( 'posts' === $front_page_post_type ) { | ||
| $front_page_post_type = 'post'; | ||
| } | ||
|
|
||
| if ( in_array( $front_page_post_type, $post_types_allowed_on_home_page, true ) ) { | ||
| $query_vars['post_type'] = $front_page_post_type; | ||
| } | ||
| } | ||
|
|
||
| // Correct `is_*` for 'page_on_front' and 'page_for_posts'. | ||
| if ( $this->is_home && 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { | ||
| $_query = wp_parse_args( $this->query ); | ||
|
|
@@ -4470,8 +4492,11 @@ public function is_comment_feed() { | |
| * @return bool Whether the query is for the front page of the site. | ||
| */ | ||
| public function is_front_page() { | ||
| /** This filter is documented in wp-includes/class-wp-query.php:1057 */ | ||
| $post_types_allowed_on_home_page = apply_filters( 'post_types_allowed_on_home_page', array_keys( get_post_types( array( 'show_in_home_page_list' => true ) ) ) ); | ||
|
|
||
| // Most likely case. | ||
| if ( 'posts' === get_option( 'show_on_front' ) && $this->is_home() ) { | ||
| if ( in_array( get_option( 'show_on_front' ), $post_types_allowed_on_home_page, true ) && $this->is_home() ) { | ||
| return true; | ||
| } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) | ||
| && $this->is_page( get_option( 'page_on_front' ) ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are pages specifically excluded?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a list of CPT that can be used as a home archive. This can not be pages
Pages shouldn't be set, but I'm protecting the settings here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, got it. maybe add an inline comment to clarify. confused me when reviewing the code.