Нема описа

site-logo.php 2.3KB

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