Make WordPress Core

Ticket #37516: theme-feature-37516.diff

File theme-feature-37516.diff, 4.6 KB (added by tellyworth, 7 years ago)

Adds a new custom-title-tagline theme feature that allows themes to explicitly support this going forward. No retrofit or change for themes that don't support that feature.

  • src/wp-includes/class-wp-customize-manager.php

     
    44544454                        'section'    => 'title_tagline',
    44554455                ) );
    44564456
     4457                // Theme feature for enabling and disabling the site title
     4458                if ( current_theme_supports( 'custom-title-tagline', 'display-title' ) ) {
     4459                        $this->add_setting( 'header_display_title', array(
     4460                                'default'    => get_option( 'header_display_title' ) || get_option( 'blogname' ),
     4461                                'type'       => 'option',
     4462                                'capability' => 'manage_options',
     4463                                'transport'         => 'postMessage',
     4464                                'sanitize_callback' => 'absint',
     4465
     4466
     4467                        ) );
     4468
     4469                        $this->add_control( 'header_display_title', array(
     4470                                'label'    => __( 'Display Site Title' ),
     4471                                'section'  => 'title_tagline',
     4472                                'settings' => 'header_display_title',
     4473                                'type'     => 'checkbox',
     4474                        ) );
     4475                }
     4476
     4477                // Theme feature for enabling and disabling the site tagline
     4478                if ( current_theme_supports( 'custom-title-tagline', 'display-tagline' ) ) {
     4479                        $this->add_setting( 'header_display_tagline', array(
     4480                                'default'    => get_option( 'header_display_tagline' ) || get_option( 'blogdescrption' ),
     4481                                'type'       => 'option',
     4482                                'capability' => 'manage_options',
     4483                                'transport'         => 'postMessage',
     4484                                'sanitize_callback' => 'absint',
     4485                        ) );
     4486
     4487                        $this->add_control( 'header_display_tagline', array(
     4488                                'label'    => __( 'Display Site Tagline' ),
     4489                                'section'  => 'title_tagline',
     4490                                'settings' => 'header_display_tagline',
     4491                                'type'     => 'checkbox',
     4492                        ) );
     4493                }
     4494
    44574495                // Add a setting to hide header text if the theme doesn't support custom headers.
    4458                 if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) {
     4496                if ( ! current_theme_supports( 'custom-header', 'header-text' ) && ! current_theme_supports( 'custom-title-tagline' ) ) {
    44594497                        $this->add_setting( 'header_text', array(
    44604498                                'theme_supports'    => array( 'custom-logo', 'header-text' ),
    44614499                                'default'           => 1,
  • src/wp-includes/general-template.php

     
    42534253
    42544254        return $settings;
    42554255}
     4256
     4257if ( 0 )  {
     4258/**
     4259 * TEMPORARY - this needs a better solution
     4260 * Used to demonstrate https://core.trac.wordpress.org/ticket/37516 only
     4261 * apply_filters( 'bloginfo', $output, $show );
     4262 */
     4263function filter_bloginfo_header_text( $output, $show ) {
     4264        if ( 'name' === $show )
     4265                return ( get_option( 'header_text_title') ? $output : '' );
     4266        elseif ( 'description' === $show )
     4267                return ( get_option( 'header_text_tagline' ) ? $output : '' );
     4268
     4269
     4270        return $output;
     4271}
     4272
     4273function add_filter_bloginfo_header_text( $header_name ) {
     4274        add_filter( 'bloginfo', 'filter_bloginfo_header_text', 10, 2 );
     4275}
     4276
     4277add_action( 'get_header', 'add_filter_bloginfo_header_text' );
     4278
     4279function filter_register_blogname_partials( WP_Customize_Manager $wp_customize ) {
     4280
     4281    if ( ! isset( $wp_customize->selective_refresh ) ) {
     4282        return;
     4283    }
     4284
     4285    $wp_customize->selective_refresh->add_partial( 'header_text_title', array(
     4286        'selector' => '.site-title a',
     4287        'settings' => array( 'blogname', 'header_text_title' ),
     4288        'render_callback' => function() {
     4289            return filter_bloginfo_header_text( get_bloginfo( 'name' ), 'name' );
     4290        },
     4291    ) );
     4292
     4293    $wp_customize->selective_refresh->add_partial( 'header_text_tagline', array(
     4294        'selector' => '.site-description',
     4295        'settings' => array( 'blogdescription', 'header_text_tagline' ),
     4296        'render_callback' => function() {
     4297                return filter_bloginfo_header_text( get_bloginfo( 'description' ), 'description' );
     4298        }
     4299    ) );
     4300}
     4301add_action( 'customize_register', 'filter_register_blogname_partials' );
     4302
     4303}
     4304 No newline at end of file
  • src/wp-includes/theme.php

     
    24192419
    24202420                                return false;
    24212421                        }
     2422
     2423                        break;
     2424
     2425                case 'custom-title-tagline' :
     2426                        if ( ! is_array( $args ) )
     2427                                $args = array( 0 => array() );
     2428
     2429                        $defaults = array(
     2430                                'display-title'          => true,
     2431                                'display-tagline'        => true,
     2432                        );
     2433
     2434                        $args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults );
     2435
     2436                        break;
     2437
    24222438        }
    24232439
    24242440        $_wp_theme_features[ $feature ] = $args;
     
    31513167                clean_post_cache( $post_id );
    31523168        }
    31533169}
     3170