compat
3 years ago
content-options
2 years ago
js
6 years ago
responsive-videos
3 years ago
site-logo
3 years ago
social-menu
2 years ago
content-options.php
4 years ago
devicepx.php
5 years ago
featured-content.php
3 years ago
infinite-scroll.php
4 years ago
random-redirect.php
3 years ago
responsive-videos.php
3 years ago
site-breadcrumbs.php
3 years ago
site-logo.php
4 years ago
social-links.php
3 years ago
social-menu.php
4 years ago
site-logo.php
86 lines
| 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 | /** |
| 24 | * Activate the Site Logo plugin. |
| 25 | * |
| 26 | * @uses current_theme_supports() |
| 27 | * @since 3.2.0 |
| 28 | * @since 9.9.0 Uses Core site_logo option format universally. |
| 29 | */ |
| 30 | function site_logo_init() { |
| 31 | // Only load our code if our theme declares support, and the standalone plugin is not activated. |
| 32 | if ( current_theme_supports( 'site-logo' ) && ! class_exists( 'Site_Logo', false ) ) { |
| 33 | // Load our class for namespacing. |
| 34 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 35 | // wpcom handles the image sizes differently. |
| 36 | require_once WPMU_PLUGIN_DIR . '/site-logo/inc/class-site-logo.php'; |
| 37 | } else { |
| 38 | require __DIR__ . '/site-logo/inc/class-site-logo.php'; |
| 39 | } |
| 40 | |
| 41 | // Load template tags. |
| 42 | require __DIR__ . '/site-logo/inc/functions.php'; |
| 43 | |
| 44 | // Load backwards-compatible template tags. |
| 45 | require __DIR__ . '/site-logo/inc/compat.php'; |
| 46 | } |
| 47 | } |
| 48 | add_action( 'init', 'site_logo_init' ); |
| 49 | |
| 50 | /** |
| 51 | * When switching from a legacy theme that uses `site-logo` to a theme that uses `custom-logo`, |
| 52 | * update the theme's custom logo if it doesn't already have one. |
| 53 | * |
| 54 | * @return void |
| 55 | */ |
| 56 | function jetpack_update_custom_logo_from_site_logo() { |
| 57 | $site_logo = get_option( 'site_logo' ); |
| 58 | |
| 59 | if ( current_theme_supports( 'custom-logo' ) && ! get_theme_mod( 'custom_logo' ) && $site_logo ) { |
| 60 | set_theme_mod( 'custom_logo', $site_logo ); |
| 61 | } |
| 62 | } |
| 63 | add_action( 'after_switch_theme', 'jetpack_update_custom_logo_from_site_logo', 10, 0 ); |
| 64 | |
| 65 | /** |
| 66 | * Transforms the legacy site_logo array, when present, into an attachment ID. |
| 67 | * |
| 68 | * The attachment ID is the format used for the site_logo option by the Site Logo block, |
| 69 | * and the updated Jetpack site-logo feature. |
| 70 | * |
| 71 | * @since 9.9.0 |
| 72 | * |
| 73 | * @param int|array $site_logo Option. |
| 74 | * @return int |
| 75 | */ |
| 76 | function jetpack_site_logo_block_compat( $site_logo ) { |
| 77 | if ( isset( $site_logo['id'] ) ) { |
| 78 | remove_filter( 'option_site_logo', 'jetpack_site_logo_block_compat', 1 ); |
| 79 | update_option( 'site_logo', $site_logo['id'] ); |
| 80 | return $site_logo['id']; |
| 81 | } |
| 82 | |
| 83 | return $site_logo; |
| 84 | } |
| 85 | add_filter( 'option_site_logo', 'jetpack_site_logo_block_compat', 1 ); |
| 86 |