PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 11.1
Jetpack – WP Security, Backup, Speed, & Growth v11.1
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / theme-tools / site-logo.php
site-logo.php
81 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 require __DIR__ . '/site-logo/inc/class-site-logo.php';
35
36 // Load template tags.
37 require __DIR__ . '/site-logo/inc/functions.php';
38
39 // Load backwards-compatible template tags.
40 require __DIR__ . '/site-logo/inc/compat.php';
41 }
42 }
43 add_action( 'init', 'site_logo_init' );
44
45 /**
46 * When switching from a legacy theme that uses `site-logo` to a theme that uses `custom-logo`,
47 * update the theme's custom logo if it doesn't already have one.
48 *
49 * @return void
50 */
51 function jetpack_update_custom_logo_from_site_logo() {
52 $site_logo = get_option( 'site_logo' );
53
54 if ( current_theme_supports( 'custom-logo' ) && ! get_theme_mod( 'custom_logo' ) && $site_logo ) {
55 set_theme_mod( 'custom_logo', $site_logo );
56 }
57 }
58 add_action( 'after_switch_theme', 'jetpack_update_custom_logo_from_site_logo', 10, 0 );
59
60 /**
61 * Transforms the legacy site_logo array, when present, into an attachment ID.
62 *
63 * The attachment ID is the format used for the site_logo option by the Site Logo block,
64 * and the updated Jetpack site-logo feature.
65 *
66 * @since 9.9.0
67 *
68 * @param int|array $site_logo Option.
69 * @return int
70 */
71 function jetpack_site_logo_block_compat( $site_logo ) {
72 if ( isset( $site_logo['id'] ) ) {
73 remove_filter( 'option_site_logo', 'jetpack_site_logo_block_compat', 1 );
74 update_option( 'site_logo', $site_logo['id'] );
75 return $site_logo['id'];
76 }
77
78 return $site_logo;
79 }
80 add_filter( 'option_site_logo', 'jetpack_site_logo_block_compat', 1 );
81