wpcom.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. }
  47. add_action( 'customize_register', 'varia_wpcom_customize_update' );
  48. /**
  49. * Sanitize the checkbox.
  50. *
  51. * @param boolean $input.
  52. *
  53. * @return boolean true if is 1 or '1', false if anything else
  54. */
  55. function varia_sanitize_checkbox( $input ) {
  56. if ( 1 == $input ) {
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. }
  62. /**
  63. * Bind JS handlers to instantly live-preview changes.
  64. */
  65. function varia_wpcom_customize_preview_js() {
  66. wp_enqueue_script( 'varia_wpcom_customize_preview', get_theme_file_uri( '/inc/customize-preview-wpcom.js' ), array( 'customize-preview' ), '1.0', true );
  67. }
  68. add_action( 'customize_preview_init', 'varia_wpcom_customize_preview_js' );
  69. /**
  70. * Enqueue our WP.com styles for front-end.
  71. * Loads after style.css so we can add overrides.
  72. */
  73. function varia_wpcom_scripts() {
  74. wp_enqueue_style( 'varia-wpcom-style', get_template_directory_uri() . '/inc/style-wpcom.css', array( 'varia-style' ), '20181218' );
  75. }
  76. add_action( 'wp_enqueue_scripts', 'varia_wpcom_scripts' );
  77. /**
  78. * Adds custom classes to the array of body classes.
  79. *
  80. * @param array $classes Classes for the body element.
  81. * @return array
  82. */
  83. function varia_wpcom_body_classes( $classes ) {
  84. $hide = get_theme_mod( 'hide_front_page_title', false );
  85. if ( true === $hide ) {
  86. $classes[] = 'hide-homepage-title';
  87. }
  88. $credit_option = get_option( 'footercredit' );
  89. if ( 'hidden' == $credit_option ) {
  90. $classes[] = 'hide-footer-credit';
  91. }
  92. return $classes;
  93. }
  94. add_filter( 'body_class', 'varia_wpcom_body_classes' );
  95. /**
  96. * Adds custom classes to the admin body classes.
  97. *
  98. * @param string $classes Classes for the body element.
  99. * @return string
  100. */
  101. function varia_wpcom_admin_body_classes( $classes ) {
  102. global $post;
  103. $is_block_editor_screen = ( function_exists( 'get_current_screen' ) && get_current_screen() && get_current_screen()->is_block_editor() );
  104. $hide = get_theme_mod( 'hide_front_page_title', false );
  105. $front_page = (int) get_option( 'page_on_front' );
  106. if ( $is_block_editor_screen && $front_page === $post->ID && true === $hide ) {
  107. $classes .= ' hide-homepage-title';
  108. }
  109. return $classes;
  110. }
  111. add_filter( 'admin_body_class', 'varia_wpcom_admin_body_classes' );
  112. /**
  113. * Enqueue our WP.com styles for the block editor.
  114. */
  115. function varia_wpcom_editor_scripts() {
  116. wp_enqueue_style( 'varia-wpcom-editor-style', get_template_directory_uri() . '/inc/style-editor-wpcom.css', array(), '20190906' );
  117. }
  118. add_action( 'enqueue_block_editor_assets', 'varia_wpcom_editor_scripts' );