WordPress.org

Make WordPress Core

Ticket #19958: CustomPostTypeAsHomePages.2.patch

File CustomPostTypeAsHomePages.2.patch, 4.5 KB (added by pbearne, 20 months ago)

incomplete patch after tonight work

  • wp-admin/includes/nav-menu.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        <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> 
    118118        <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> 
    119119</ul> 
    120120<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 
  • wp-includes/post.php

     
    35963596} 
    35973597 
    35983598/** 
     3599 * Checks for value is in the hierarchical_post_types 
     3600 * 
     3601 *@return bool  
     3602 */ 
     3603function filter_hierarchical_post_types($post_types){ 
     3604        $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); 
     3605        return in_array( $post_types, $hierarchical_post_types ); 
     3606} 
     3607 
     3608 
     3609/** 
    35993610 * Retrieve a list of pages. 
    36003611 * 
    36013612 * The defaults that can be overridden are the following: 'child_of', 
     
    36283639        $number = (int) $number; 
    36293640        $offset = (int) $offset; 
    36303641 
    3631         // Make sure the post type is hierarchical 
     3642        // Make sure we have a valid post type 
     3643        if ( !is_array( $post_type ) ) 
     3644                $post_type = explode( ',', $post_type ); 
     3645        if ( array_diff( $post_type, get_post_types() ) ) 
     3646                return $pages; 
     3647        // Make sure the all post types are hierarchical 
    36323648        $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); 
    3633         if ( !in_array( $post_type, $hierarchical_post_types ) ) 
     3649        // remove any elemnts not in $hierarchical_post_types  
     3650        $post_type = array_filter($post_type, "filter_hierarchical_post_types"); 
     3651        //then check one last time to make sure 
     3652        if ( !$post_type ) 
    36343653                return $pages; 
    36353654 
    36363655        // Make sure we have a valid post status 
     
    37333752        if ( $parent >= 0 ) 
    37343753                $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); 
    37353754 
     3755        // Check if post_type is an array so that Custom Page types can be added to dropdowns and lists 
     3756        if ( 1 == count( $post_type ) ) {        
     3757                $where_post_type = $wpdb->prepare("post_type = %s"  , array_shift( $post_type ) ); 
     3758        } else{ 
     3759                $post_type = implode( "', '", $post_type ); 
     3760                $where_post_type = "post_type IN ('$post_type')"; 
     3761        } 
     3762 
    37363763        if ( 1 == count( $post_status ) ) { 
    3737                 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $post_type, array_shift( $post_status ) ); 
     3764                $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) ); 
    37383765        } else { 
    37393766                $post_status = implode( "', '", $post_status ); 
    3740                 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $post_type ); 
     3767                $where_post_type .= "AND post_status IN ('$post_status')" ; 
    37413768        } 
    37423769 
    37433770        $orderby_array = array();