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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Administration API: WP_Site_Logo class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
* @since 4.5.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class used to implement site logo functionality.
|
|
|
|
*
|
|
|
|
* @since 4.5.0
|
|
|
|
*/
|
|
|
|
class WP_Site_Logo {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current logo settings stored in theme mod.
|
|
|
|
*
|
|
|
|
* @since 4.5.0
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
add_action( 'wp_head', array( $this, 'head_text_styles' ) );
|
|
|
|
add_action( 'delete_attachment', array( $this, 'delete_attachment_data' ) );
|
|
|
|
add_filter( 'image_size_names_choose', array( $this, 'media_manager_image_sizes' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-03 02:04:25 -05:00
|
|
|
* Hides header text on the front end if necessary.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
*
|
|
|
|
* @since 4.5.0
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function head_text_styles() {
|
|
|
|
// Bail if our theme supports custom headers.
|
|
|
|
if ( current_theme_supports( 'custom-header' ) || get_theme_mod( 'site_logo_header_text', true ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-03 02:04:25 -05:00
|
|
|
// Is Display Header Text unchecked? If so, hide the header text.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
?>
|
|
|
|
<!-- Site Logo: hide header text -->
|
|
|
|
<style type="text/css">
|
|
|
|
<?php echo sanitize_html_class( $this->header_text_classes() ); ?> {
|
|
|
|
position: absolute;
|
|
|
|
clip: rect(1px, 1px, 1px, 1px);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-03 02:04:25 -05:00
|
|
|
* Resets the site logo if the current logo is deleted in the media manager.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
*
|
|
|
|
* @since 4.5.0
|
|
|
|
* @access public
|
|
|
|
*
|
2016-03-03 02:04:25 -05:00
|
|
|
* @param int $post_id Post ID.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
*/
|
|
|
|
public function delete_attachment_data( $post_id ) {
|
|
|
|
$site_logo_id = get_theme_mod( 'site_logo' );
|
|
|
|
|
|
|
|
if ( $site_logo_id && $site_logo_id == $post_id ) {
|
|
|
|
remove_theme_mod( 'site_logo' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-03 02:04:25 -05:00
|
|
|
* Makes custom image sizes available to the media manager.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
*
|
|
|
|
* @since 4.5.0
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param array $sizes Image sizes.
|
|
|
|
* @return array All default and registered custom image sizes.
|
|
|
|
*/
|
|
|
|
public function media_manager_image_sizes( $sizes ) {
|
|
|
|
|
|
|
|
// Get an array of all registered image sizes.
|
|
|
|
$intermediate = get_intermediate_image_sizes();
|
|
|
|
|
2016-03-03 02:04:25 -05:00
|
|
|
// Is there anything fun to work with?
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
if ( is_array( $intermediate ) && ! empty( $intermediate ) ) {
|
|
|
|
foreach ( $intermediate as $key => $size ) {
|
|
|
|
|
|
|
|
// If the size isn't already in the $sizes array, add it.
|
|
|
|
if ( ! array_key_exists( $size, $sizes ) ) {
|
|
|
|
$sizes[ $size ] = $size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sizes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-03 02:04:25 -05:00
|
|
|
* Retrieves the header text classes.
|
|
|
|
*
|
|
|
|
* If not defined in add_theme_support(), defaults from Underscores will be used.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
*
|
|
|
|
* @since 4.5.0
|
|
|
|
* @access protected
|
|
|
|
*
|
2016-03-03 02:04:25 -05:00
|
|
|
* @return string String of classes to hide.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
*/
|
|
|
|
protected function header_text_classes() {
|
|
|
|
$args = get_theme_support( 'site-logo' );
|
|
|
|
|
|
|
|
if ( isset( $args[0]['header-text'] ) ) {
|
|
|
|
// Use any classes defined in add_theme_support().
|
|
|
|
$classes = $args[0]['header-text'];
|
|
|
|
} else {
|
|
|
|
// Otherwise, use these defaults, which will work with any Underscores-based theme.
|
|
|
|
$classes = array(
|
|
|
|
'site-title',
|
|
|
|
'site-description',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-03 02:04:25 -05:00
|
|
|
// If there's an array of classes, reduce them to a string for output.
|
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.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
|
|
|
if ( is_array( $classes ) ) {
|
|
|
|
$classes = array_map( 'sanitize_html_class', $classes );
|
|
|
|
$classes = (string) '.' . implode( ', .', $classes );
|
|
|
|
} else {
|
|
|
|
$classes = (string) '.' . $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WP_Site_Logo instance.
|
|
|
|
*
|
|
|
|
* @global WP_Site_Logo $wp_site_logo
|
|
|
|
*/
|
|
|
|
$GLOBALS['wp_site_logo'] = new WP_Site_Logo;
|