WordPress.org

Make WordPress Core

Ticket #19958: CustomPostTypeAsHomePages.3.patch

File CustomPostTypeAsHomePages.3.patch, 8.1 KB (added by pbearne, 5 years ago)

Current dev version (not working)

  • .

  • wp-admin/includes/nav-menu.php

    Property changes on: .
    ___________________________________________________________________
    Added: svn:ignore
    ## -0,0 +1,2 ##
    +wordpress
    +wp-config.php
     
    724724                                $args['walker'] = $walker;
    725725
    726726                                // if we're dealing with pages, let's put a checkbox for the front page at the top of the list
    727                                 if ( 'page' == $post_type_name ) {
     727                                // do we have a custom homepage? if not inject a Home page link into the pages list
     728                                //what page type is it add the front_or_home = true to the set page
     729                               
     730                                // check we don't have a custom home page and if so get the post type
     731                                $post_type_show_on_front = 'page' == get_option('show_on_front') ? get_post_type((int) get_option( 'page_on_front' )) : 'page';
     732       
     733                                if ( $post_type_show_on_front == $post_type_name ) {
    728734                                        $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0;
    729735                                        if ( ! empty( $front_page ) ) {
    730736                                                $front_page_obj = get_post( $front_page );
  • wp-admin/options-reading.php

     
    114114        </label>
    115115        </p>
    116116<ul>
    117         <li><label for="page_on_front"><?php printf( __( 'Front page: %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' ) ) ) ); ?></label></li>
     117        <?php
     118        // this is in the wwrong place here for code and test need to be moved - not sure where
     119       
     120        /**
     121        * this fillter adds all the post types that have 'show_in_home_page_list' => true set
     122        * to the 'post_type' array in the past in $args array
     123        *
     124        * @uses get_post_types
     125        *
     126        * @param array $args
     127        * @return $args
     128        *
     129        */
     130        function filter_register_post_type_add_to_front_or_home_list($args) {
     131        // do we have any custom post types to add in to the list
     132        //var $custom_post_types_for_homePage   = null;
     133        $custom_post_types_for_homePage = get_post_types(array('show_in_home_page_list' => true, ));
     134                foreach ($custom_post_types_for_homePage as $custom_post_type) {
     135                        if(array_key_exists('post_type', $args) && in_array('page',$args ) ){
     136                                if(is_array($args['post_type'])){
     137                                        $args['post_type'] = array_merge( $args['post_type'], array($custom_post_type ));
     138                                }else{
     139                                        $args['post_type'] = array($args['post_type'] ,$custom_post_type );
     140                                }
     141                        }else{
     142                                $args['post_type'] = array('page', $custom_post_type );
     143                        }
     144                }
     145                //print_r($args);
     146        return $args;
     147        }
     148        // add via filter for now
     149        add_filter('options-front-page' , 'filter_register_post_type_add_to_front_or_home_list');
     150        ?>
     151        <li><label for="page_on_front"><?php printf( __( 'Front page: %s' ), wp_dropdown_pages( apply_filters('options-front-page',array( 'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) ) ); ?></label></li>
    118152        <li><label for="page_for_posts"><?php printf( __( 'Posts page: %s' ), wp_dropdown_pages( array( 'name' => 'page_for_posts', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) ) ) ); ?></label></li>
    119153</ul>
    120154<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
  • wp-content/themes

  • wp-includes/link-template.php

    Property changes on: wp-content/themes
    ___________________________________________________________________
    Added: svn:ignore
    ## -0,0 +1 ##
    +twentytwelveTesting
     
    103103        if ( empty($post->ID) )
    104104                return false;
    105105
    106         if ( $post->post_type == 'page' )
     106        // check we don't have a custom home page and if so get the post type
     107        $post_type_show_on_front = 'page' == get_option('show_on_front') ? get_post_type((int) get_option( 'page_on_front' )) : 'page';
     108
     109        if ( $post->post_type == $post_type_show_on_front )
    107110                return get_page_link($post->ID, $leavename, $sample);
    108111        elseif ( $post->post_type == 'attachment' )
    109112                return get_attachment_link( $post->ID, $leavename );
  • wp-includes/post.php

     
    12261226                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
    12271227                'can_export' => true,
    12281228                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
    1229                 'delete_with_user' => null,
     1229                'delete_with_user' => null,'show_in_home_page_list'=> null,
    12301230        );
    12311231        $args = wp_parse_args($args, $defaults);
    12321232        $args = (object) $args;
     
    12671267
    12681268        if ( null === $args->map_meta_cap )
    12691269                $args->map_meta_cap = false;
     1270        // where to show this custom page type as an option for the home page
     1271        if ( null === $args->show_in_home_page_list )
     1272                $args->show_in_home_page_list = false;
    12701273
    12711274        $args->cap = get_post_type_capabilities( $args );
    12721275        unset($args->capabilities);
     
    13101313
    13111314                if ( $args->hierarchical )
    13121315                        add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
     1316                        // check for if it can shown as home
    13131317                else
    13141318                        add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
    13151319
     
    36063610}
    36073611
    36083612/**
     3613 * Checks for value is in the hierarchical_post_types
     3614 *
     3615 *@return bool
     3616 */
     3617function filter_hierarchical_post_types($post_types){
     3618        $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
     3619        return in_array( $post_types, $hierarchical_post_types );
     3620}
     3621
     3622
     3623/**
    36093624 * Retrieve a list of pages.
    36103625 *
    36113626 * The defaults that can be overridden are the following: 'child_of',
     
    36383653        $number = (int) $number;
    36393654        $offset = (int) $offset;
    36403655
    3641         // Make sure the post type is hierarchical
     3656        // Make sure we have a valid post type
     3657        if ( !is_array( $post_type ) )
     3658                $post_type = explode( ',', $post_type );
     3659        if ( array_diff( $post_type, get_post_types() ) )
     3660                return $pages;
     3661        // Make sure the all post types are hierarchical
    36423662        $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
    3643         if ( !in_array( $post_type, $hierarchical_post_types ) )
     3663        // remove any elemnts not in $hierarchical_post_types
     3664        $post_type = array_filter($post_type, "filter_hierarchical_post_types");
     3665        //then check one last time to make sure
     3666        if ( !$post_type )
    36443667                return $pages;
    36453668
    36463669        // Make sure we have a valid post status
     
    37463769        if ( $parent >= 0 )
    37473770                $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
    37483771
     3772        // Check if post_type is an array so that Custom Page types can be added to dropdowns and lists
     3773        if ( 1 == count( $post_type ) ) {       
     3774                $where_post_type = $wpdb->prepare("post_type = %s"  , array_shift( $post_type ) );
     3775        } else{
     3776                $post_type = implode( "', '", $post_type );
     3777                $where_post_type = "post_type IN ('$post_type')";
     3778        }
     3779
    37493780        if ( 1 == count( $post_status ) ) {
    3750                 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $post_type, array_shift( $post_status ) );
     3781                $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) );
    37513782        } else {
    37523783                $post_status = implode( "', '", $post_status );
    3753                 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $post_type );
     3784                $where_post_type .= "AND post_status IN ('$post_status')" ;
    37543785        }
    37553786
    37563787        $orderby_array = array();