| @@ -1,0 +1,90 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Theme Tools: Site Logo. | |
| 4 | + * | |
| 5 | + * @see https://jetpack.com/support/site-logo/ | |
| 6 | + * | |
| 7 | + * This feature will only be activated for themes that declare their support. | |
| 8 | + * This can be done by adding code similar to the following during the | |
| 9 | + * 'after_setup_theme' action: | |
| 10 | + * | |
| 11 | + * $args = array( | |
| 12 | + * 'header-text' => array( | |
| 13 | + * 'site-title', | |
| 14 | + * 'site-description', | |
| 15 | + * ), | |
| 16 | + * 'size' => 'medium', | |
| 17 | + * ); | |
| 18 | + * add_theme_support( 'site-logo', $args ); | |
| 19 | + * | |
| 20 | + * @package automattic/jetpack | |
| 21 | + */ | |
| 22 | + | |
| 23 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 24 | + exit( 0 ); | |
| 25 | +} | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * Activate the Site Logo plugin. | |
| 29 | + * | |
| 30 | + * @uses current_theme_supports() | |
| 31 | + * @since 3.2.0 | |
| 32 | + * @since 9.9.0 Uses Core site_logo option format universally. | |
| 33 | + */ | |
| 34 | +function site_logo_init() { | |
| 35 | + // Only load our code if our theme declares support, and the standalone plugin is not activated. | |
| 36 | + if ( current_theme_supports( 'site-logo' ) && ! class_exists( 'Site_Logo', false ) ) { | |
| 37 | + _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/' ); | |
| 38 | + // Load our class for namespacing. | |
| 39 | + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { | |
| 40 | + // wpcom handles the image sizes differently. | |
| 41 | + require_once WPMU_PLUGIN_DIR . '/site-logo/inc/class-site-logo.php'; | |
| 42 | + } else { | |
| 43 | + require __DIR__ . '/site-logo/inc/class-site-logo.php'; | |
| 44 | + } | |
| 45 | + | |
| 46 | + // Load template tags. | |
| 47 | + require __DIR__ . '/site-logo/inc/functions.php'; | |
| 48 | + | |
| 49 | + // Load backwards-compatible template tags. | |
| 50 | + require __DIR__ . '/site-logo/inc/compat.php'; | |
| 51 | + } | |
| 52 | +} | |
| 53 | +add_action( 'init', 'site_logo_init' ); | |
| 54 | + | |
| 55 | +/** | |
| 56 | + * When switching from a legacy theme that uses `site-logo` to a theme that uses `custom-logo`, | |
| 57 | + * update the theme's custom logo if it doesn't already have one. | |
| 58 | + * | |
| 59 | + * @return void | |
| 60 | + */ | |
| 61 | +function jetpack_update_custom_logo_from_site_logo() { | |
| 62 | + $site_logo = get_option( 'site_logo' ); | |
| 63 | + | |
| 64 | + if ( current_theme_supports( 'custom-logo' ) && ! get_theme_mod( 'custom_logo' ) && $site_logo ) { | |
| 65 | + set_theme_mod( 'custom_logo', $site_logo ); | |
| 66 | + } | |
| 67 | +} | |
| 68 | +add_action( 'after_switch_theme', 'jetpack_update_custom_logo_from_site_logo', 10, 0 ); | |
| 69 | + | |
| 70 | +/** | |
| 71 | + * Transforms the legacy site_logo array, when present, into an attachment ID. | |
| 72 | + * | |
| 73 | + * The attachment ID is the format used for the site_logo option by the Site Logo block, | |
| 74 | + * and the updated Jetpack site-logo feature. | |
| 75 | + * | |
| 76 | + * @since 9.9.0 | |
| 77 | + * | |
| 78 | + * @param int|array|WP_Error $site_logo Option. | |
| 79 | + * @return int|WP_Error | |
| 80 | + */ | |
| 81 | +function jetpack_site_logo_block_compat( $site_logo ) { | |
| 82 | + if ( is_array( $site_logo ) && isset( $site_logo['id'] ) ) { | |
| 83 | + remove_filter( 'option_site_logo', 'jetpack_site_logo_block_compat', 1 ); | |
| 84 | + update_option( 'site_logo', $site_logo['id'] ); | |
| 85 | + return $site_logo['id']; | |
| 86 | + } | |
| 87 | + | |
| 88 | + return $site_logo; | |
| 89 | +} | |
| 90 | +add_filter( 'option_site_logo', 'jetpack_site_logo_block_compat', 1 ); | |