Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/wp-admin/includes/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@
<script>
jQuery( function($) {
var section = $('#front-static-pages'),
staticPage = section.find('input:radio[value="page"]'),
selects = section.find('select'),
selects = section.find('.staticPages select'),
homepage_types = section.find('select#homepage_types')

Check failure on line 119 in src/wp-admin/includes/options.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Tabs must be used to indent lines; spaces are not allowed
check_disabled = function(){
selects.prop( 'disabled', ! staticPage.prop('checked') );
selects.prop( 'disabled', homepage_types.val() !== "page" );
};
check_disabled();
section.find( 'input:radio' ).on( 'change', check_disabled );
homepage_types.on( 'change', check_disabled );
} );
</script>
<?php
Expand Down
107 changes: 85 additions & 22 deletions src/wp-admin/options-reading.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,37 @@
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 fillter overrides which post type are show in the dropdown
*
* @uses get_post_types
*
* @param array $args
* @return $args
*
*/
$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'

Check failure on line 83 in src/wp-admin/options-reading.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

There should be a comma after the last array item in a multi-line array.
);
$allowed_pages = new WP_Query( $args );
?>

<?php if ( ! get_pages() ) : ?>
<input name="show_on_front" type="hidden" value="posts" />
<table class="form-table" role="presentation">
<?php
if ( 'posts' !== get_option( 'show_on_front' ) ) :
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' ) ) {

Check failure on line 98 in src/wp-admin/options-reading.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Line indented incorrectly; expected 0 tabs, found 1
update_option( 'show_on_front', 'posts' );
}

Check failure on line 100 in src/wp-admin/options-reading.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Line indented incorrectly; expected 0 tabs, found 1

$your_homepage_displays_title = __( 'Your homepage displays' );
?>
Expand All @@ -90,37 +107,83 @@
<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 = array( 'posts') + $post_types_allowed_on_home_page;
unset( $allowed_archives_on_home_page['page'] );
if( 1 === count( $allowed_archives_on_home_page ) ) {
_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;
$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 )
) ;
}
$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' ) ); ?> />
<!-- <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'
);
// 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(
array(
'name' => 'page_on_front',
'echo' => 0,
'show_option_none' => __( '&mdash; Select &mdash;' ),
'option_none_value' => '0',
'selected' => get_option( 'page_on_front' ),
)
)
);
__( 'Homepage: %s' ), $output );
?>
</label></li>
<li><label for="page_for_posts">
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
'show_on_front',
'page_on_front',
'page_for_posts',
'show_archive_on_front',
'blog_public',
),
'writing' => array(
Expand Down
64 changes: 64 additions & 0 deletions src/wp-content/themes/twentytwenty/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){

Check failure on line 830 in src/wp-content/themes/twentytwenty/functions.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space before opening brace; found 0

$posts[] = 'book';
return $posts;

Check failure on line 833 in src/wp-content/themes/twentytwenty/functions.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Tabs must be used to indent lines; spaces are not allowed
}


/**
* Register a custom post type called "book".
*
* @see get_post_type_labels() for label keys.
*/
function wpdocs_codex_book_init() {
$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,

Check failure on line 882 in src/wp-content/themes/twentytwenty/functions.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space before "=>"; 0 found
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
);

register_post_type( 'book', $args );
}

add_action( 'init', 'wpdocs_codex_book_init' );
48 changes: 48 additions & 0 deletions src/wp-content/themes/twentytwentyfive/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,52 @@
endif;
add_action( 'init', 'twentytwentyfive_register_block_bindings' );

/**
* Registers the 'books' custom post type.
*
* @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.
Expand All @@ -156,4 +202,6 @@
return get_post_format_string( $post_format_slug );
}
}
endif;

Check failure on line 205 in src/wp-content/themes/twentytwentyfive/functions.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 blank line at end of file; 3 found


4 changes: 3 additions & 1 deletion src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4470,8 +4470,10 @@ public function is_comment_feed() {
* @return bool Whether the query is for the front page of the site.
*/
public function is_front_page() {
$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' ) )
Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'show_in_rest' => true,
'rest_base' => 'posts',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'show_in_home_page_list'=> null,

Check failure on line 55 in src/wp-includes/post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space before "=>"; 0 found
)
);

Expand Down Expand Up @@ -86,6 +87,7 @@
'show_in_rest' => true,
'rest_base' => 'pages',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'show_in_home_page_list'=> true,

Check failure on line 90 in src/wp-includes/post.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space before "=>"; 0 found
)
);

Expand Down Expand Up @@ -3966,8 +3968,8 @@
*/
function _reset_front_page_settings_for_post( $post_id ) {
$post = get_post( $post_id );

if ( 'page' === $post->post_type ) {
$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 ) ) ) );
if ( in_array( $post->post_type, $post_types_allowed_on_home_page, true ) ) {
/*
* If the page is defined in option page_on_front or post_for_posts,
* adjust the corresponding options.
Expand Down
Loading