Ticket #19958: CustomPostTypeAsHomePages.ui.refreeh.2.patch
File CustomPostTypeAsHomePages.ui.refreeh.2.patch, 11.7 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/options.php
112 112 jQuery(document).ready(function($){ 113 113 var section = $('#front-static-pages'), 114 114 staticPage = section.find('input:radio[value="page"]'), 115 selects = section.find('select'), 115 selects = section.find('.staticPages select'), 116 homepage_types = section.find('select#homepage_types') 116 117 check_disabled = function(){ 117 118 selects.prop( 'disabled', ! staticPage.prop('checked') ); 119 homepage_types.prop( 'disabled', staticPage.prop('checked') ); 118 120 }; 119 121 check_disabled(); 120 122 section.find( 'input:radio' ).change( check_disabled ); -
src/wp-admin/options-reading.php
67 67 } 68 68 ?> 69 69 70 <?php if ( ! get_pages() ) : ?> 71 <input name="show_on_front" type="hidden" value="posts" /> 72 <table class="form-table" role="presentation"> 73 <?php 74 if ( 'posts' != get_option( 'show_on_front' ) ) : 75 update_option( 'show_on_front', 'posts' ); 76 endif; 70 <?php 77 71 78 else : 72 /** 73 * this fillter overrides which post type are show in the dropdown 74 * 75 * @uses get_post_types 76 * 77 * @param array $args 78 * @return $args 79 * 80 */ 81 $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 ) ) ) ); 82 $args = array( 83 'post_type' => $post_types_allowed_on_home_page, 84 'post_status' => 'publish', 85 'fields' => 'ids' 86 ); 87 $allowed_pages = new WP_Query( $args ); 88 89 //if ( empty( $allowed_pages->posts ) ) : ?> 90 <!--<input name="show_on_front" type="hidden" value="posts" />--> 91 <!--<table class="form-table" role="presentation">--> 92 <!-- <tr>--> 93 <!-- <th scope="row">--><?php //_e( 'Your homepage displays' ); ?><!--</th>--> 94 <!-- <td>--><?php 95 // $content_type_links = array(); 96 // foreach ($post_types_allowed_on_home_page as $type ){ 97 // $content_type_links[] = sprintf('<a href="%s">%s</a>', 98 // 'edit.php?post_type=' . $type, ucfirst( $type ) ); 99 // } 100 // printf( 101 // /* translators: %s: URL to Pages screen. */ 102 // __( 'No selectable pages found! Add at least one of these content types %s' ), 103 // implode( ', ', $content_type_links ) 104 // ); 105 // ?> 106 <!-- </td>--> 107 <!-- --><?php 108 // if ( 'posts' !== get_option( 'show_on_front' ) ) : 109 // update_option( 'show_on_front', 'posts' ); 110 // endif; 111 // 112 //else : 79 113 if ( 'page' === get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { 80 114 update_option( 'show_on_front', 'posts' ); 81 115 } 82 ?>116 ?> 83 117 <table class="form-table" role="presentation"> 84 118 <tr> 85 119 <th scope="row"><?php _e( 'Your homepage displays' ); ?></th> 86 120 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Your homepage displays' ); ?></span></legend> 87 121 <p><label> 88 <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> /> 89 <?php _e( 'Your latest posts' ); ?> 122 <input name="show_on_front" type="radio" value="posts" class="tog" <?php 123 $allowed_archives_on_home_page = array( 'posts') + $post_types_allowed_on_home_page; 124 unset( $allowed_archives_on_home_page['page'] ); 125 checked( in_array( get_option( 'show_on_front' ), $allowed_archives_on_home_page, true ) ); ?> /> 126 <?php 127 if( 1 === count( $allowed_archives_on_home_page ) ) { 128 _e( 'Your latest posts' ); 129 } else { 130 $output = "<select name='show_archive_on_front' id='homepage_types'>\n"; 131 foreach ( $allowed_archives_on_home_page as $post_type ){ 132 $post_type = ( 'posts' === $post_type ) ? 'post' : $post_type; 133 $output .= sprintf( '<option %s>%s</option>', $post_type, get_post_type_object( $post_type )->labels->name ) ; 134 } 135 $output .= "</select>\n"; 136 137 printf( __( 'Your latest %s' ), $output ); 138 } 139 ?> 90 140 </label> 91 141 </p> 142 <?php if ( empty( $allowed_pages->posts ) ) : ?> 143 <p> <?php 144 $content_type_links = array(); 145 foreach ($post_types_allowed_on_home_page as $type ){ 146 $content_type_links[] = sprintf('<a href="%s">%s</a>', 147 'edit.php?post_type=' . $type, ucfirst( $type ) ); 148 } 149 printf( 150 /* translators: %s: URL to Pages screen. */ 151 __( 'No selectable pages found! Add/Publish at least one of these content types %s' ), 152 implode( ', ', $content_type_links ) 153 ); 154 ?> 155 </p> 156 <?php else : ?> 92 157 <p><label> 93 158 <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> 94 159 <?php … … 100 165 ?> 101 166 </label> 102 167 </p> 103 <ul >168 <ul class="staticPages"> 104 169 <li><label for="page_on_front"> 105 170 <?php 171 172 $output = "<select name='page_on_front' >\n"; 173 foreach ( $post_types_allowed_on_home_page as $post_type ){ 174 $post_type = ( 'posts' === $post_type ) ? 'post' : $post_type; 175 $output .= sprintf( '<optgroup label="%s">', get_post_type_object( $post_type )->labels->name ); 176 $args = array( 177 'post_type' => $post_type, 178 'post_status' => 'publish', 179 ); 180 $cpt_posts = new WP_Query( $args ); 181 foreach ( $cpt_posts->posts as $cpt_post ) { 182 $output .= sprintf( '<option %s>%s</option>', $cpt_post->ID, $cpt_post->post_name ) ; 183 } 184 $output .= '</optgroup>'; 185 } 186 $output .= "</select>\n"; 187 188 106 189 printf( 107 190 /* translators: %s: Select field to choose the front page. */ 108 __( 'Homepage: %s' ), 109 wp_dropdown_pages( 110 array( 111 'name' => 'page_on_front', 112 'echo' => 0, 113 'show_option_none' => __( '— Select —' ), 114 'option_none_value' => '0', 115 'selected' => get_option( 'page_on_front' ), 116 ) 117 ) 118 ); 191 __( 'Homepage: %s' ), $output ); 119 192 ?> 120 193 </label></li> 121 194 <li><label for="page_for_posts"> -
src/wp-admin/options.php
137 137 'show_on_front', 138 138 'page_on_front', 139 139 'page_for_posts', 140 'show_archive_on_front', 140 141 'blog_public', 141 142 ), 142 143 'writing' => array( -
src/wp-content/themes/twentytwenty/functions.php
754 754 */ 755 755 return apply_filters( 'twentytwenty_get_elements_array', $elements ); 756 756 } 757 758 759 760 //add_filter( 'post_types_allowed_on_home_page', 'rsadfd_post_types_allowed_on_home_page'); 761 function rsadfd_post_types_allowed_on_home_page( $posts ){ 762 763 $posts[] = 'book'; 764 return $posts; 765 } 766 767 768 /** 769 * Register a custom post type called "book". 770 * 771 * @see get_post_type_labels() for label keys. 772 */ 773 function wpdocs_codex_book_init() { 774 $labels = array( 775 'name' => _x( 'Books', 'Post type general name', 'textdomain' ), 776 'singular_name' => _x( 'Book', 'Post type singular name', 'textdomain' ), 777 'menu_name' => _x( 'Books', 'Admin Menu text', 'textdomain' ), 778 'name_admin_bar' => _x( 'Book', 'Add New on Toolbar', 'textdomain' ), 779 'add_new' => __( 'Add New', 'textdomain' ), 780 'add_new_item' => __( 'Add New Book', 'textdomain' ), 781 'new_item' => __( 'New Book', 'textdomain' ), 782 'edit_item' => __( 'Edit Book', 'textdomain' ), 783 'view_item' => __( 'View Book', 'textdomain' ), 784 'all_items' => __( 'All Books', 'textdomain' ), 785 'search_items' => __( 'Search Books', 'textdomain' ), 786 'parent_item_colon' => __( 'Parent Books:', 'textdomain' ), 787 'not_found' => __( 'No books found.', 'textdomain' ), 788 'not_found_in_trash' => __( 'No books found in Trash.', 'textdomain' ), 789 'featured_image' => _x( 'Book Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'textdomain' ), 790 'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'textdomain' ), 791 'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'textdomain' ), 792 'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'textdomain' ), 793 'archives' => _x( 'Book archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'textdomain' ), 794 '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' ), 795 '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' ), 796 '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' ), 797 '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' ), 798 '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' ), 799 ); 800 801 $args = array( 802 'labels' => $labels, 803 'public' => true, 804 'publicly_queryable' => true, 805 'show_ui' => true, 806 'show_in_menu' => true, 807 'query_var' => true, 808 'rewrite' => array( 'slug' => 'book' ), 809 'capability_type' => 'post', 810 'has_archive' => true, 811 'hierarchical' => false, 812 'menu_position' => null, 813 'show_in_home_page_list'=> true, 814 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), 815 ); 816 817 register_post_type( 'book', $args ); 818 } 819 820 add_action( 'init', 'wpdocs_codex_book_init' ); -
src/wp-includes/post.php
39 39 'show_in_rest' => true, 40 40 'rest_base' => 'posts', 41 41 'rest_controller_class' => 'WP_REST_Posts_Controller', 42 'show_in_home_page_list'=> null, 42 43 ) 43 44 ); 44 45 … … 64 65 'show_in_rest' => true, 65 66 'rest_base' => 'pages', 66 67 'rest_controller_class' => 'WP_REST_Posts_Controller', 68 'show_in_home_page_list'=> true, 67 69 ) 68 70 ); 69 71 … … 3132 3134 */ 3133 3135 function _reset_front_page_settings_for_post( $post_id ) { 3134 3136 $post = get_post( $post_id ); 3135 3136 if ( 'page' === $post->post_type) {3137 $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 ) ) ) ); 3138 if ( in_array( $post->post_type, $post_types_allowed_on_home_page, true ) ) { 3137 3139 /* 3138 3140 * If the page is defined in option page_on_front or post_for_posts, 3139 3141 * adjust the corresponding options.