WordPress.org

Make WordPress Core

Ticket #19627: 19627-patch1.diff

File 19627-patch1.diff, 5.3 KB (added by Master Jake, 6 years ago)
  • trunk/wp-includes/theme.php

     
    171171 *
    172172 * The style.css file must contain theme name, theme URI, and description. The
    173173 * data can also contain author URI, author, template (parent template),
    174  * version, status, and finally tags. Some of these are not used by WordPress
    175  * administration panels, but are used by theme directory web sites which list
    176  * the theme.
     174 * version, status, tags, and a recommended display type for the front page
     175 * (static or posts). Some of these are not used by WordPress administration
     176 * panels, but are used by theme directory web sites which list the theme.
    177177 *
    178178 * @since 1.5.0
    179179 *
     
    190190                'Version' => 'Version',
    191191                'Template' => 'Template',
    192192                'Status' => 'Status',
    193                 'Tags' => 'Tags'
     193                'Tags' => 'Tags',
     194                'FrontPage' => 'Front Page'
    194195                );
    195196
    196197        $themes_allowed_tags = array(
     
    207208                'em' => array(),
    208209                'strong' => array()
    209210        );
     211       
     212        $themes_allowed_front_page = array(
     213                'posts',
     214                'static',
     215                'null' // default - means neither posts nor static holds more weight
     216        );
    210217
    211218        $theme_data = get_file_data( $theme_file, $default_headers, 'theme' );
    212219
     
    242249                        $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], esc_attr__( 'Visit author homepage' ), $theme_data['AuthorName'] );
    243250                }
    244251        }
     252       
     253        if ( ! in_array( strtolower( $theme_data['FrontPage'] ), $themes_allowed_front_page ) ) {
     254                $theme_data['FrontPage'] = 'null';
     255        }
    245256
    246257        return $theme_data;
    247258}
     
    437448                        'Tags' => $theme_data['Tags'],
    438449                        'Theme Root' => $theme_root,
    439450                        'Theme Root URI' => str_replace( WP_CONTENT_DIR, content_url(), $theme_root ),
     451                        'Front Page' => $theme_data['FrontPage']
    440452                );
    441453        }
    442454
     
    12471259 * @param string $stylesheet Stylesheet name.
    12481260 */
    12491261function switch_theme($template, $stylesheet) {
    1250         global $wp_theme_directories, $sidebars_widgets;
     1262        global $wp_theme_directories, $sidebars_widgets, $wp_recommended_front_page;
    12511263
    12521264        if ( is_array( $sidebars_widgets ) )
    12531265                set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
     
    12691281                $default_theme_mods = (array) get_option( "mods_$theme" );
    12701282                add_option( "theme_mods_$stylesheet", $default_theme_mods );
    12711283        }
     1284       
     1285        $current_theme_options = get_theme( $theme );
     1286        if ( 'null' !== $current_theme_options['Front Page'] ) {
     1287                $wp_recommended_front_page = $current_theme_options['Front Page'];
     1288        }
    12721289
    12731290        update_option( 'theme_switched', $old_theme );
    12741291        do_action( 'switch_theme', $theme );
  • trunk/wp-admin/themes.php

     
    1818        if ( 'activate' == $_GET['action'] ) {
    1919                check_admin_referer('switch-theme_' . $_GET['template']);
    2020                switch_theme($_GET['template'], $_GET['stylesheet']);
    21                 wp_redirect( admin_url('themes.php?activated=true') );
     21               
     22                // After switch_theme, the recommended front page global is available.
     23                global $wp_recommended_front_page;
     24                $front_page_query = ( isset( $wp_recommended_front_page ) ) ? '&frontpage=' . urlencode( $wp_recommended_front_page ) : '';
     25               
     26                wp_redirect( admin_url('themes.php?activated=true' . $front_page_query) );
    2227                exit;
    2328        } elseif ( 'delete' == $_GET['action'] ) {
    2429                check_admin_referer('delete-theme_' . $_GET['template']);
     
    7782
    7883<?php if ( ! validate_current_theme() ) : ?>
    7984<div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
    80 <?php elseif ( isset($_GET['activated']) ) :
    81                 if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
    82 <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
    83                 } else { ?>
    84 <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
    85                 }
    86         elseif ( isset($_GET['deleted']) ) : ?>
     85<?php elseif ( isset($_GET['activated']) ) : ?>
     86<div id="message2" class="updated"><p>
     87<?php
     88if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) {
     89        $theme_msg2_out = sprintf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) );
     90} else {
     91        $theme_msg2_out = sprintf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) );
     92}
     93
     94if ( 'static' == $_GET['frontpage'] && current_user_can('manage_options') ) {
     95        $theme_msg2_out .= sprintf( __( ' This theme works best with a static front page. Please visit the <a href="%s">reading settings</a> screen to configure your front page preferences.' ), get_admin_url( null, 'options-reading.php' ) );
     96}
     97
     98echo $theme_msg2_out;
     99unset( $theme_msg2_out );
     100?>             
     101</p></div>
     102<?php elseif ( isset($_GET['deleted']) ) : ?>
    87103<div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
    88104<?php endif; ?>
    89105