wpcom.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. // Set theme colors for third party services.
  17. if ( ! isset( $themecolors ) ) {
  18. $themecolors = array(
  19. 'bg' => 'ffffff',
  20. 'border' => '767676',
  21. 'text' => '111111',
  22. 'link' => '0073aa',
  23. 'url' => '0073aa',
  24. );
  25. }
  26. }
  27. add_action( 'after_setup_theme', 'varia_wpcom_setup' );
  28. /**
  29. * Add setting for hiding page title on the homepage.
  30. */
  31. function varia_wpcom_customize_update( $wp_customize ) {
  32. $wp_customize->add_setting( 'hide_front_page_title', array(
  33. 'default' => false,
  34. 'type' => 'theme_mod',
  35. 'transport' => 'postMessage',
  36. 'sanitize_callback' => 'varia_sanitize_checkbox',
  37. ) );
  38. $wp_customize->add_control( 'hide_front_page_title', array(
  39. 'label' => esc_html__( 'Hide Homepage Title', 'varia' ),
  40. 'description' => esc_html__( 'Check to hide the page title, if your homepage is set to display a static page.', 'varia' ),
  41. 'section' => 'static_front_page',
  42. 'priority' => 10,
  43. 'type' => 'checkbox',
  44. 'settings' => 'hide_front_page_title',
  45. ) );
  46. $wp_customize->add_setting( 'color_a11y_warning' );
  47. $wp_customize->add_control( 'color_a11y_warning', array(
  48. 'id' => 'id',
  49. 'label' => esc_html__( 'Color Accessibility Warning', 'varia' ),
  50. 'description' => sprintf(
  51. __( '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' ),
  52. esc_url( 'https://a11yproject.com/posts/what-is-color-contrast/' )
  53. ),
  54. 'section' => 'colors_manager_tool',
  55. 'priority' => 10,
  56. 'type' => 'hidden',
  57. ) );
  58. }
  59. add_action( 'customize_register', 'varia_wpcom_customize_update' );
  60. /**
  61. * Sanitize the checkbox.
  62. *
  63. * @param boolean $input.
  64. *
  65. * @return boolean true if is 1 or '1', false if anything else
  66. */
  67. function varia_sanitize_checkbox( $input ) {
  68. if ( 1 == $input ) {
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. }
  74. /**
  75. * Bind JS handlers to instantly live-preview changes.
  76. */
  77. function varia_wpcom_customize_preview_js() {
  78. wp_enqueue_script( 'varia_wpcom_customize_preview', get_theme_file_uri( '/inc/customize-preview-wpcom.js' ), array( 'customize-preview' ), '1.0', true );
  79. }
  80. add_action( 'customize_preview_init', 'varia_wpcom_customize_preview_js' );
  81. /**
  82. * Enqueue our WP.com styles for front-end.
  83. * Loads after style.css so we can add overrides.
  84. */
  85. function varia_wpcom_scripts() {
  86. wp_enqueue_style( 'varia-wpcom-style', get_template_directory_uri() . '/inc/style-wpcom.css', array( 'varia-style' ), '20181218' );
  87. }
  88. add_action( 'wp_enqueue_scripts', 'varia_wpcom_scripts' );
  89. /**
  90. * Adds custom classes to the array of body classes.
  91. *
  92. * @param array $classes Classes for the body element.
  93. * @return array
  94. */
  95. function varia_wpcom_body_classes( $classes ) {
  96. $hide = get_theme_mod( 'hide_front_page_title', false );
  97. if ( true === $hide ) {
  98. $classes[] = 'hide-homepage-title';
  99. }
  100. $credit_option = get_option( 'footercredit' );
  101. if ( 'hidden' == $credit_option ) {
  102. $classes[] = 'hide-footer-credit';
  103. }
  104. return $classes;
  105. }
  106. add_filter( 'body_class', 'varia_wpcom_body_classes' );
  107. /**
  108. * Adds custom classes to the admin body classes.
  109. *
  110. * @param string $classes Classes for the body element.
  111. * @return string
  112. */
  113. function varia_wpcom_admin_body_classes( $classes ) {
  114. global $post;
  115. $is_block_editor_screen = ( function_exists( 'get_current_screen' ) && get_current_screen() && get_current_screen()->is_block_editor() );
  116. $hide = get_theme_mod( 'hide_front_page_title', false );
  117. $front_page = (int) get_option( 'page_on_front' );
  118. if ( $is_block_editor_screen && $front_page === $post->ID && true === $hide ) {
  119. $classes .= ' hide-homepage-title';
  120. }
  121. return $classes;
  122. }
  123. add_filter( 'admin_body_class', 'varia_wpcom_admin_body_classes' );
  124. /**
  125. * Enqueue our WP.com styles for the block editor.
  126. */
  127. function varia_wpcom_editor_scripts() {
  128. wp_enqueue_style( 'varia-wpcom-editor-style', get_template_directory_uri() . '/inc/style-editor-wpcom.css', array(), '20190906' );
  129. }
  130. add_action( 'enqueue_block_editor_assets', 'varia_wpcom_editor_scripts' );
  131. /**
  132. * Enqueue CSS and JS for customizer pane.
  133. */
  134. function varia_enqueue_message_scripts() {
  135. wp_enqueue_script( 'varia-customize-message-wpcom-script', get_template_directory_uri() . '/inc/customize-message-wpcom.js', array( 'customize-controls' ), wp_get_theme()->get( 'Version' ) );
  136. wp_enqueue_style( 'varia-customize-message-wpcom-style', get_template_directory_uri() . '/inc/customize-message-wpcom.css', array(), wp_get_theme()->get( 'Version' ) );
  137. }
  138. add_action( 'customize_controls_enqueue_scripts', 'varia_enqueue_message_scripts' );