Make WordPress Core

Ticket #19627: frontpage.patch

File frontpage.patch, 13.4 KB (added by marius2012, 8 years ago)
  • wp-admin/options-reading.php

     
    111111        </label>
    112112        </p>
    113113<ul>
    114         <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>
     114        <li><label for="page_on_front"><?php printf( __( 'Front page: %s' ), wp_dropdown_pages( array( 'include_templates'=>true,  'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label></li>
    115115        <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>
    116116</ul>
    117117<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
  • wp-includes/canonical.php

     
    162162                } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) {
    163163                        if ( $redirect_url = get_permalink(get_query_var('page_id')) )
    164164                                $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
    165                 } elseif ( is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && ! $redirect_url ) {
     165                } elseif ( is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && is_numeric(get_option('page_on_front')) && ! $redirect_url ) {
    166166                        $redirect_url = home_url('/');
    167167                } elseif ( is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts')  && ! $redirect_url ) {
    168168                        if ( $redirect_url = get_permalink(get_option('page_for_posts')) )
  • wp-includes/class-wp-customize-control.php

     
    483483                                                'show_option_none'  => __( '&mdash; Select &mdash;' ),
    484484                                                'option_none_value' => '0',
    485485                                                'selected'          => $this->value(),
     486                                                'include_templates' => ( $this->id == 'page_on_front' )
    486487                                        )
    487488                                );
    488489
  • wp-includes/formatting.php

     
    33793379                case 'large_size_h':
    33803380                case 'mailserver_port':
    33813381                case 'comment_max_links':
    3382                 case 'page_on_front':
    33833382                case 'page_for_posts':
    33843383                case 'rss_excerpt_length':
    33853384                case 'default_category':
     
    33933392                        $value = absint( $value );
    33943393                        break;
    33953394
     3395                case 'page_on_front':
     3396                case 'old_page_on_front':
     3397                        if( is_numeric( $value ) ) {
     3398                                $value = absint( $value );
     3399                        } else {
     3400                                if( locate_template( $value ) == '' ) {
     3401                                        $value = 0;
     3402                                }
     3403                        }
     3404                        break;
     3405
    33963406                case 'posts_per_page':
    33973407                case 'posts_per_rss':
    33983408                        $value = (int) $value;
  • wp-includes/link-template.php

     
    319319function get_page_link( $post = false, $leavename = false, $sample = false ) {
    320320        $post = get_post( $post );
    321321
    322         if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) )
     322        if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) && is_numeric(get_option('page_on_front')) )
    323323                $link = home_url('/');
    324324        else
    325325                $link = _get_page_link( $post, $leavename, $sample );
     
    639639                $feed = get_default_feed();
    640640
    641641        if ( '' != get_option('permalink_structure') ) {
    642                 if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
     642                if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') && is_numeric(get_option('page_on_front')) )
    643643                        $url = _get_page_link( $post_id );
    644644                else
    645645                        $url = get_permalink($post_id);
     
    33343334        if ( ! empty( $post_id ) ) {
    33353335                $post_type = get_post_type_object( $post->post_type );
    33363336
    3337                 if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) {
     3337                if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) && is_numeric(get_option('page_on_front')) ) {
    33383338                        $shortlink = home_url( '/' );
    33393339                } elseif ( $post_type->public ) {
    33403340                        $shortlink = home_url( '?p=' . $post_id );
  • wp-includes/post-template.php

     
    905905        } else {
    906906                if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    907907                        $url = add_query_arg( 'page', $i, get_permalink() );
    908                 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
     908                elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID && is_numeric(get_option('page_on_front')) )
    909909                        $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
    910910                else
    911911                        $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
     
    10191019                'show_option_none' => '', 'show_option_no_change' => '',
    10201020                'option_none_value' => '',
    10211021                'value_field' => 'ID',
     1022                'include_templates'=>false
    10221023        );
    10231024
    10241025        $r = wp_parse_args( $args, $defaults );
    10251026
    10261027        $pages = get_pages( $r );
     1028
     1029        if ( $r['include_templates'] ) {
     1030                $templates = get_page_templates();
     1031        }else{
     1032                $templates = array();
     1033        }
     1034
    10271035        $output = '';
    10281036        // Back-compat with old system where both id and name were based on $name argument
    10291037        if ( empty( $r['id'] ) ) {
     
    10301038                $r['id'] = $r['name'];
    10311039        }
    10321040
    1033         if ( ! empty( $pages ) ) {
     1041        if ( ! empty( $pages ) || ! empty( $templates )) {
    10341042                $output = "<select name='" . esc_attr( $r['name'] ) . "' id='" . esc_attr( $r['id'] ) . "'>\n";
     1043
    10351044                if ( $r['show_option_no_change'] ) {
    10361045                        $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
    10371046                }
     
    10381047                if ( $r['show_option_none'] ) {
    10391048                        $output .= "\t<option value=\"" . esc_attr( $r['option_none_value'] ) . '">' . $r['show_option_none'] . "</option>\n";
    10401049                }
    1041                 $output .= walk_page_dropdown_tree( $pages, $r['depth'], $r );
     1050                if( ! empty( $pages )) {
     1051                        if ( $r['include_templates'] ) {
     1052                                $output .= "<optgroup label=\"" . __('Pages') . "\" >";
     1053                        }
     1054                        $output .= walk_page_dropdown_tree( $pages, $r['depth'], $r );
     1055                        if ( $r['include_templates'] ) {
     1056                                $output .= "</optgroup>";
     1057                        }
     1058                }
     1059                if( ! empty( $templates ) && $r['include_templates'] ) {
     1060                        $output .= "<optgroup label=\"" . __('Templates') . "\" >";
     1061                        foreach ( $templates as $template_name=>$template_file ){
     1062                                $output .= "\t<option value=\"" . esc_attr( $template_file ) . "\"";
     1063                                if ( $template_file == $args['selected'] )
     1064                                        $output .= ' selected="selected"';
     1065                                $output .= '>';
     1066                                $output .= esc_html( $template_name ) ;
     1067                                $output .= "</option>\n";
     1068                        }
     1069                        $output .= "</optgroup>";
     1070                }
    10421071                $output .= "</select>\n";
    10431072        }
    10441073
     
    12281257                        } else {
    12291258                                $list_args['exclude'] = '';
    12301259                        }
    1231                         $list_args['exclude'] .= get_option('page_on_front');
     1260                        if( is_numeric(get_option('page_on_front')) ){
     1261                                $list_args['exclude'] .= get_option('page_on_front');
     1262                        }
    12321263                }
    12331264        }
    12341265
  • wp-includes/query.php

     
    17511751                        $this->is_home = true;
    17521752
    17531753                // Correct is_* for page_on_front and page_for_posts
    1754                 if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) {
     1754                if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') && is_numeric(get_option('page_on_front')) ) {
    17551755                        $_query = wp_parse_args($this->query);
    17561756                        // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.
    17571757                        if ( isset($_query['pagename']) && '' == $_query['pagename'] )
     
    17591759                        if ( empty($_query) || !array_diff( array_keys($_query), array('preview', 'page', 'paged', 'cpage') ) ) {
    17601760                                $this->is_page = true;
    17611761                                $this->is_home = false;
    1762                                 $qv['page_id'] = get_option('page_on_front');
     1762                                if(is_numeric(get_option('page_on_front'))) {
     1763                                        $qv['page_id'] = get_option('page_on_front');
     1764                                }
    17631765                                // Correct <!--nextpage--> for page_on_front
    17641766                                if ( !empty($qv['paged']) ) {
    17651767                                        $qv['page'] = $qv['paged'];
     
    24942496                if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 )
    24952497                        $q['comments_per_page'] = get_option('comments_per_page');
    24962498
    2497                 if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
     2499                if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') && is_numeric(get_option('page_on_front'))) {
    24982500                        $this->is_page = true;
    24992501                        $this->is_home = false;
    25002502                        $q['page_id'] = get_option('page_on_front');
     
    43164318                // most likely case
    43174319                if ( 'posts' == get_option( 'show_on_front') && $this->is_home() )
    43184320                        return true;
    4319                 elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) )
     4321                elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && ( $this->is_page( get_option( 'page_on_front' ) ) || locate_template( get_option( 'page_on_front' ) ) != '' ) )
    43204322                        return true;
    43214323                else
    43224324                        return false;
  • wp-includes/rewrite.php

     
    14761476                        $commentmatch = $match . $commentregex;
    14771477                        $commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index($num_toks + 1);
    14781478
    1479                         if ( get_option('page_on_front') ) {
     1479                        if ( get_option('page_on_front')  && is_numeric(get_option('page_on_front')) ) {
    14801480                                //create query for Root /comment-page-xx
    14811481                                $rootcommentmatch = $match . $commentregex;
    14821482                                $rootcommentquery = $index . '?' . $query . '&page_id=' . get_option('page_on_front') . '&cpage=' . $this->preg_index($num_toks + 1);
     
    15061506                        //only on pages with comments add ../comment-page-xx/
    15071507                        if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
    15081508                                $rewrite = array_merge($rewrite, array($commentmatch => $commentquery));
    1509                         } elseif ( EP_ROOT & $ep_mask && get_option('page_on_front') ) {
     1509                        } elseif ( EP_ROOT & $ep_mask && get_option('page_on_front') && is_numeric(get_option('page_on_front')) ) {
    15101510                                $rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery));
    15111511                        }
    15121512                        //do endpoints
  • wp-includes/template.php

     
    286286 */
    287287function get_front_page_template() {
    288288        $templates = array('front-page.php');
    289 
     289        if( get_option( "show_on_front" ) == "page" && ! is_numeric( get_option( "page_on_front" ) ) ){
     290                if( locate_template( get_option( "page_on_front" ) ) != '' ) {
     291                        $templates = array( get_option("page_on_front") );
     292                }
     293        }
    290294        return get_query_template( 'front_page', $templates );
    291295}
    292296
  • wp-includes/theme.php

     
    19521952                        remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
    19531953                        update_option( 'theme_switched_via_customizer', false );
    19541954                }
     1955                $value_frontpage = get_theme_support( 'custom-frontpage' ) ;
     1956                $template_frontpage = isset( $value_frontpage[0] ) ? $value_frontpage[0] : '';
    19551957
     1958                if( ! empty ( $template_frontpage ) ){
     1959                        update_option( 'old_page_on_front' , get_option( 'page_on_front' ) );
     1960                        update_option( 'old_show_on_front' , get_option( 'show_on_front' ) );
     1961                        update_option( 'page_on_front' , $template_frontpage . '.php' );
     1962                        update_option( 'show_on_front' , 'page' );
     1963                }else{
     1964                        $old_frontpage = get_option( 'old_page_on_front' );
     1965                        $old_show_on_front = get_option( 'old_show_on_front' );
     1966                        if( $old_frontpage !== false  &&   $old_show_on_front !== false  ){
     1967                                update_option( 'page_on_front',$old_frontpage );
     1968                                update_option( 'show_on_front',$old_show_on_front );
     1969                        }
     1970                }
    19561971                if ( $old_theme->exists() ) {
    19571972                        /**
    19581973                         * Fires on the first WP load after a theme switch if the old theme still exists.