wpcom.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * WordPress.com-specific functions and definitions.
  4. *
  5. * This file is centrally included from `wp-content/mu-plugins/wpcom-theme-compat.php`.
  6. *
  7. * @package Varia
  8. */
  9. /**
  10. * Adds support for wp.com-specific theme functions.
  11. *
  12. * @global array $themecolors
  13. */
  14. function varia_wpcom_setup() {
  15. global $themecolors;
  16. // Disable automatically generated color palettes.
  17. add_theme_support(
  18. 'wpcom-colors',
  19. array(
  20. 'only-featured-palettes' => true,
  21. )
  22. );
  23. // Set theme colors for third party services.
  24. if ( ! isset( $themecolors ) ) {
  25. $themecolors = array(
  26. 'bg' => 'ffffff',
  27. 'border' => '767676',
  28. 'text' => '111111',
  29. 'link' => '0073aa',
  30. 'url' => '0073aa',
  31. );
  32. }
  33. }
  34. add_action( 'after_setup_theme', 'varia_wpcom_setup' );
  35. /**
  36. * Add setting for hiding page title on the homepage.
  37. */
  38. function varia_wpcom_customize_update( $wp_customize ) {
  39. $wp_customize->add_setting(
  40. 'hide_front_page_title',
  41. array(
  42. 'default' => false,
  43. 'type' => 'theme_mod',
  44. 'transport' => 'postMessage',
  45. 'sanitize_callback' => 'varia_sanitize_checkbox',
  46. )
  47. );
  48. $wp_customize->add_control(
  49. 'hide_front_page_title',
  50. array(
  51. 'label' => esc_html__( 'Hide Homepage Title', 'varia' ),
  52. 'description' => esc_html__( 'Check to hide the page title, if your homepage is set to display a static page.', 'varia' ),
  53. 'section' => 'static_front_page',
  54. 'priority' => 10,
  55. 'type' => 'checkbox',
  56. 'settings' => 'hide_front_page_title',
  57. )
  58. );
  59. $wp_customize->add_setting( 'color_a11y_warning' );
  60. $wp_customize->add_control(
  61. 'color_a11y_warning',
  62. array(
  63. 'id' => 'id',
  64. 'label' => esc_html__( 'Color Accessibility Warning', 'varia' ),
  65. 'description' => sprintf(
  66. __( 'In order to ensure people can read your site, try to maintain a strong contrast ratio between the colors you choose here. <a href="%s" target="_blank">Learn more about color contrast</a>.', 'varia' ),
  67. esc_url( 'https://a11yproject.com/posts/what-is-color-contrast/' )
  68. ),
  69. 'section' => 'colors_manager_tool',
  70. 'priority' => 10,
  71. 'type' => 'hidden',
  72. )
  73. );
  74. }
  75. add_action( 'customize_register', 'varia_wpcom_customize_update' );
  76. /**
  77. * Bind JS handlers to instantly live-preview changes.
  78. */
  79. function varia_wpcom_customize_preview_js() {
  80. wp_enqueue_script( 'varia_wpcom_customize_preview', get_theme_file_uri( '/inc/customize-preview-wpcom.js' ), array( 'customize-preview' ), '1.0', true );
  81. }
  82. add_action( 'customize_preview_init', 'varia_wpcom_customize_preview_js' );
  83. /**
  84. * Enqueue our WP.com styles for front-end.
  85. * Loads after style.css so we can add overrides.
  86. */
  87. function varia_wpcom_scripts() {
  88. wp_enqueue_style( 'varia-wpcom-style', get_template_directory_uri() . '/inc/style-wpcom.css', array( 'varia-style' ), '20181218' );
  89. }
  90. add_action( 'wp_enqueue_scripts', 'varia_wpcom_scripts' );
  91. /**
  92. * Adds custom classes to the array of body classes.
  93. *
  94. * @param array $classes Classes for the body element.
  95. * @return array
  96. */
  97. function varia_wpcom_body_classes( $classes ) {
  98. $hide = get_theme_mod( 'hide_front_page_title', false );
  99. if ( true === $hide ) {
  100. $classes[] = 'hide-homepage-title';
  101. }
  102. $hide_site_header = get_theme_mod( 'hide_site_header', false );
  103. if ( true === $hide_site_header ) {
  104. $classes[] = 'hide-homepage-header';
  105. }
  106. $hide_site_footer = get_theme_mod( 'hide_site_footer', false );
  107. if ( true === $hide_site_footer ) {
  108. $classes[] = 'hide-homepage-footer';
  109. }
  110. $credit_option = get_option( 'footercredit' );
  111. if ( 'hidden' == $credit_option ) {
  112. $classes[] = 'hide-footer-credit';
  113. }
  114. return $classes;
  115. }
  116. add_filter( 'body_class', 'varia_wpcom_body_classes' );
  117. /**
  118. * Adds custom classes to the admin body classes.
  119. *
  120. * @param string $classes Classes for the body element.
  121. * @return string
  122. */
  123. function varia_wpcom_admin_body_classes( $classes ) {
  124. global $post;
  125. $is_block_editor_screen = ( function_exists( 'get_current_screen' ) && get_current_screen() && get_current_screen()->is_block_editor() );
  126. $hide = get_theme_mod( 'hide_front_page_title', false );
  127. $front_page = (int) get_option( 'page_on_front' );
  128. if ( $is_block_editor_screen && $front_page === $post->ID && true === $hide ) {
  129. $classes .= ' hide-homepage-title';
  130. }
  131. return $classes;
  132. }
  133. add_filter( 'admin_body_class', 'varia_wpcom_admin_body_classes' );
  134. /**
  135. * Enqueue our WP.com styles for the block editor.
  136. */
  137. function varia_wpcom_editor_scripts() {
  138. wp_enqueue_style( 'varia-wpcom-editor-style', get_template_directory_uri() . '/inc/style-editor-wpcom.css', array(), '20190906' );
  139. }
  140. add_action( 'enqueue_block_editor_assets', 'varia_wpcom_editor_scripts' );
  141. /**
  142. * Enqueue CSS for customizer a11y warning.
  143. */
  144. function varia_wpcom_enqueue_message_scripts() {
  145. wp_enqueue_style( 'varia-customize-message-wpcom-style', get_template_directory_uri() . '/inc/customize-message-wpcom.css', array(), wp_get_theme()->get( 'Version' ) );
  146. }
  147. add_action( 'customize_controls_enqueue_scripts', 'varia_wpcom_enqueue_message_scripts' );