2019-11-15 23:26:29 +01:00
< ? php
2022-06-16 14:01:47 +02:00
/**
* Theme Tools : Site Logo .
*
2019-11-15 23:26:29 +01:00
* @ see https :// jetpack . com / support / site - logo /
*
* This feature will only be activated for themes that declare their support .
* This can be done by adding code similar to the following during the
* 'after_setup_theme' action :
*
* $args = array (
2022-06-16 14:01:47 +02:00
* 'header-text' => array (
* 'site-title' ,
* 'site-description' ,
* ),
* 'size' => 'medium' ,
2019-11-15 23:26:29 +01:00
* );
* add_theme_support ( 'site-logo' , $args );
*
2022-06-16 14:01:47 +02:00
* @ package automattic / jetpack
2019-11-15 23:26:29 +01:00
*/
/**
* Activate the Site Logo plugin .
*
* @ uses current_theme_supports ()
2021-07-23 11:58:50 +02:00
* @ since 3.2 . 0
* @ since 9.9 . 0 Uses Core site_logo option format universally .
2019-11-15 23:26:29 +01:00
*/
function site_logo_init () {
// Only load our code if our theme declares support, and the standalone plugin is not activated.
if ( current_theme_supports ( 'site-logo' ) && ! class_exists ( 'Site_Logo' , false ) ) {
2025-02-28 08:42:11 +01:00
_deprecated_hook ( 'site-logo' , '13.4' , 'custom-logo' , 'Jetpack no longer supports site-logo feature. Add custom-logo support to your theme instead: https://developer.wordpress.org/themes/functionality/custom-logo/' );
2019-11-15 23:26:29 +01:00
// Load our class for namespacing.
2022-12-15 17:41:53 +01:00
if ( defined ( 'IS_WPCOM' ) && IS_WPCOM ) {
// wpcom handles the image sizes differently.
require_once WPMU_PLUGIN_DIR . '/site-logo/inc/class-site-logo.php' ;
} else {
require __DIR__ . '/site-logo/inc/class-site-logo.php' ;
}
2019-11-15 23:26:29 +01:00
// Load template tags.
2022-06-16 14:01:47 +02:00
require __DIR__ . '/site-logo/inc/functions.php' ;
2019-11-15 23:26:29 +01:00
// Load backwards-compatible template tags.
2022-06-16 14:01:47 +02:00
require __DIR__ . '/site-logo/inc/compat.php' ;
2019-11-15 23:26:29 +01:00
}
}
add_action ( 'init' , 'site_logo_init' );
2021-07-23 11:58:50 +02:00
/**
* When switching from a legacy theme that uses `site-logo` to a theme that uses `custom-logo` ,
* update the theme 's custom logo if it doesn' t already have one .
*
* @ return void
*/
function jetpack_update_custom_logo_from_site_logo () {
$site_logo = get_option ( 'site_logo' );
if ( current_theme_supports ( 'custom-logo' ) && ! get_theme_mod ( 'custom_logo' ) && $site_logo ) {
set_theme_mod ( 'custom_logo' , $site_logo );
}
}
add_action ( 'after_switch_theme' , 'jetpack_update_custom_logo_from_site_logo' , 10 , 0 );
/**
* Transforms the legacy site_logo array , when present , into an attachment ID .
*
* The attachment ID is the format used for the site_logo option by the Site Logo block ,
* and the updated Jetpack site - logo feature .
*
* @ since 9.9 . 0
*
2025-06-09 09:58:01 +02:00
* @ param int | array | WP_Error $site_logo Option .
* @ return int | WP_Error
2021-07-23 11:58:50 +02:00
*/
function jetpack_site_logo_block_compat ( $site_logo ) {
2025-06-09 09:58:01 +02:00
if ( is_array ( $site_logo ) && isset ( $site_logo [ 'id' ] ) ) {
2021-07-23 11:58:50 +02:00
remove_filter ( 'option_site_logo' , 'jetpack_site_logo_block_compat' , 1 );
update_option ( 'site_logo' , $site_logo [ 'id' ] );
return $site_logo [ 'id' ];
}
return $site_logo ;
}
add_filter ( 'option_site_logo' , 'jetpack_site_logo_block_compat' , 1 );