Make WordPress Core


Ignore:
Timestamp:
02/24/2016 10:09:54 PM (9 years ago)
Author:
obenland
Message:

Customize: Introduce Logo support for themes.

Allows a common theme feature to have a common implementation provided by core and available in a consistent location for users.
See https://make.wordpress.org/core/2016/02/24/theme-logo-support/

Props kwight, enejb, jeherve, bhubbard, samhotchkiss, zinigor, eliorivero, adamsilverstein, melchoyce, ryan, mikeschroder, westonruter, pento, karmatosed, celloexpressions, obenland.
See #33755.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r36687 r36698  
    218218        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' );
    219219        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php' );
     220        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-logo-control.php' );
    220221        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' );
    221222        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' );
     
    829830            'activeControls' => array(),
    830831            'nonce' => $this->get_nonces(),
     832            'l10n' => array(
     833                'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
     834            ),
    831835            '_dirty' => array_keys( $this->unsanitized_post_values() ),
    832836        );
     
    18581862        $this->register_control_type( 'WP_Customize_Cropped_Image_Control' );
    18591863        $this->register_control_type( 'WP_Customize_Site_Icon_Control' );
     1864        $this->register_control_type( 'WP_Customize_Site_Logo_Control' );
    18601865        $this->register_control_type( 'WP_Customize_Theme_Control' );
    18611866
     
    19321937            'section'    => 'title_tagline',
    19331938        ) );
     1939
     1940        // Add a setting to hide header text if the theme isn't supporting the feature itself.
     1941        // @todo
     1942        if ( ! current_theme_supports( 'custom-header' ) ) {
     1943            $this->add_setting( 'header_text', array(
     1944                'default'           => 1,
     1945                'sanitize_callback' => 'absint',
     1946                'transport'         => 'postMessage',
     1947            ) );
     1948
     1949            $this->add_control( 'header_text', array(
     1950                'label'    => __( 'Display Site Title and Tagline' ),
     1951                'section'  => 'title_tagline',
     1952                'settings' => 'header_text',
     1953                'type'     => 'checkbox',
     1954            ) );
     1955        }
    19341956
    19351957        $this->add_setting( 'site_icon', array(
     
    19521974        ) ) );
    19531975
     1976        $this->add_setting( 'site_logo', array(
     1977            'theme_supports' => array( 'site-logo' ),
     1978            'transport'      => 'postMessage',
     1979        ) );
     1980
     1981        $this->add_control( new WP_Customize_Site_Logo_Control( $this, 'site_logo', array(
     1982            'label'    => __( 'Logo' ),
     1983            'section'  => 'title_tagline',
     1984            'priority' => 0,
     1985        ) ) );
     1986
     1987        if ( isset( $this->selective_refresh ) ) {
     1988            $this->selective_refresh->add_partial( 'site_logo', array(
     1989                'settings'            => array( 'site_logo' ),
     1990                'selector'            => '.site-logo-link',
     1991                'render_callback'     => array( $this, '_render_site_logo_partial' ),
     1992                'container_inclusive' => true,
     1993            ) );
     1994        }
     1995
    19541996        /* Colors */
    19551997
     
    21802222
    21812223        return $color;
     2224    }
     2225
     2226    /**
     2227     * Callback for rendering the site logo, used in the site_logo partial.
     2228     *
     2229     * This method exists because the partial object and context data are passed
     2230     * into a partial's render_callback so we cannot use get_the_site_logo() as
     2231     * the render_callback directly since it expects a blog ID as the first
     2232     * argument. When WP no longer supports PHP 5.3, this method can be removed
     2233     * in favor of an anonymous function.
     2234     *
     2235     * @see WP_Customize_Manager::register_controls()
     2236     *
     2237     * @since 4.5.0
     2238     * @access private
     2239     *
     2240     * @return string Site logo.
     2241     */
     2242    public function _render_site_logo_partial() {
     2243        return get_the_site_logo();
    21822244    }
    21832245}
Note: See TracChangeset for help on using the changeset viewer.