functions.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * Blank Canvas functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  6. *
  7. * @package WordPress
  8. * @subpackage Blank Canvas
  9. * @since 1.0
  10. */
  11. if ( ! function_exists( 'blank_canvas_setup' ) ) :
  12. /**
  13. * Sets up theme defaults and registers support for various WordPress features.
  14. *
  15. * Note that this function is hooked into the after_setup_theme hook, which
  16. * runs before the init hook. The init hook is too late for some features, such
  17. * as indicating support for post thumbnails.
  18. */
  19. function blank_canvas_setup() {
  20. // Add support for editor styles.
  21. add_theme_support( 'editor-styles' );
  22. // Enqueue editor styles.
  23. add_editor_style( 'variables.css' );
  24. // Editor color palette.
  25. $colors_theme_mod = get_theme_mod( 'custom_colors_active' );
  26. $primary = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-primary' ) ) ) ? '#000000' : get_theme_mod( 'seedlet_--global--color-primary' );
  27. $secondary = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-secondary' ) ) ) ? '#007cba' : get_theme_mod( 'seedlet_--global--color-secondary' );
  28. $foreground = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-foreground' ) ) ) ? '#333333' : get_theme_mod( 'seedlet_--global--color-foreground' );
  29. $tertiary = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-tertiary' ) ) ) ? '#FAFAFA' : get_theme_mod( 'seedlet_--global--color-tertiary' );
  30. $background = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-background' ) ) ) ? '#FFFFFF' : get_theme_mod( 'seedlet_--global--color-background' );
  31. add_theme_support(
  32. 'editor-color-palette',
  33. array(
  34. array(
  35. 'name' => __( 'Primary', 'blank-canvas' ),
  36. 'slug' => 'primary',
  37. 'color' => $primary,
  38. ),
  39. array(
  40. 'name' => __( 'Secondary', 'blank-canvas' ),
  41. 'slug' => 'secondary',
  42. 'color' => $secondary,
  43. ),
  44. array(
  45. 'name' => __( 'Foreground', 'blank-canvas' ),
  46. 'slug' => 'foreground',
  47. 'color' => $foreground,
  48. ),
  49. array(
  50. 'name' => __( 'Tertiary', 'blank-canvas' ),
  51. 'slug' => 'tertiary',
  52. 'color' => $tertiary,
  53. ),
  54. array(
  55. 'name' => __( 'Background', 'blank-canvas' ),
  56. 'slug' => 'background',
  57. 'color' => $background,
  58. ),
  59. )
  60. );
  61. }
  62. endif;
  63. add_action( 'after_setup_theme', 'blank_canvas_setup', 11 );
  64. /**
  65. * Filter the colors for Blank Canvas
  66. */
  67. function blank_canvas_colors() {
  68. return array(
  69. array( '--global--color-background', '#FFFFFF', __( 'Background Color', 'blank-canvas' ) ),
  70. array( '--global--color-foreground', '#333333', __( 'Foreground Color', 'blank-canvas' ) ),
  71. array( '--global--color-primary', '#000000', __( 'Primary Color', 'blank-canvas' ) ),
  72. array( '--global--color-secondary', '#007cba', __( 'Secondary Color', 'blank-canvas' ) ),
  73. array( '--global--color-tertiary', '#FAFAFA', __( 'Tertiary Color', 'blank-canvas' ) ),
  74. );
  75. }
  76. add_filter( 'seedlet_colors', 'blank_canvas_colors' );
  77. /**
  78. * Remove Seedlet theme features.
  79. */
  80. function blank_canvas_remove_parent_theme_features() {
  81. // Theme Support.
  82. remove_theme_support( 'custom-header' );
  83. }
  84. add_action( 'after_setup_theme', 'blank_canvas_remove_parent_theme_features', 11 );
  85. /**
  86. * Dequeue Seedlet scripts.
  87. */
  88. function blank_canvas_dequeue_parent_scripts() {
  89. if ( false === get_theme_mod( 'show_site_header', false ) ) {
  90. // Naviation assets.
  91. wp_dequeue_script( 'seedlet-primary-navigation-script' );
  92. wp_dequeue_style( 'seedlet-style-navigation' );
  93. }
  94. }
  95. add_action( 'wp_enqueue_scripts', 'blank_canvas_dequeue_parent_scripts', 11 );
  96. /**
  97. * Remove unused custmizer settings.
  98. */
  99. function blank_canvas_remove_customizer_settings( $wp_customize ) {
  100. // Remove Jetpack's Author Bio setting.
  101. if ( function_exists( 'jetpack_author_bio' ) ) {
  102. $wp_customize->remove_control( 'jetpack_content_author_bio_title' );
  103. $wp_customize->remove_control( 'jetpack_content_author_bio' );
  104. }
  105. // Remove Seedlet's header and footer hide options,
  106. // since they're already hidden by default.
  107. $wp_customize->remove_control( 'hide_site_header' );
  108. $wp_customize->remove_control( 'hide_site_footer' );
  109. }
  110. add_action( 'customize_register', 'blank_canvas_remove_customizer_settings', 11 );
  111. /**
  112. * Add custmizer settings.
  113. */
  114. function blank_canvas_add_customizer_settings( $wp_customize ) {
  115. // Cast the widgets panel as an object.
  116. $customizer_widgets_panel = (object) $wp_customize->get_panel( 'widgets' );
  117. $content_options_link = "wp.customize.control('show_site_header').focus(); return false;";
  118. // Add a Customizer message about the site title & tagline options.
  119. // translators: %s is an action which opens the "Content Options" section of customizer
  120. $wp_customize->get_section( 'title_tagline' )->description = sprintf( __( 'The site logo, title, and tagline will only appear on all posts and pages if the "Site header and top menu" option is enabled in the <a href="#" onClick="%s">Content Options</a> section.', 'blank-canvas' ), $content_options_link );
  121. $wp_customize->get_section( 'menu_locations' )->description = __( 'This theme will only display Menus if they are enabled in the Content Options section.', 'blank-canvas' );
  122. $wp_customize->get_panel( 'nav_menus' )->description = __( 'This theme will only display Menus if they are enabled in the Content Options section.', 'blank-canvas' );
  123. $customizer_widgets_panel->description = __( 'This theme will only display Widgets if they are enabled in the Content Options section.', 'blank-canvas' );
  124. }
  125. add_action( 'customize_register', 'blank_canvas_add_customizer_settings', 11 );
  126. /**
  127. * Remove Meta Footer Items.
  128. */
  129. if ( ! function_exists( 'seedlet_entry_meta_footer' ) ) :
  130. /**
  131. * Prints HTML with meta information for the categories, tags and comments.
  132. */
  133. function seedlet_entry_meta_footer() {
  134. // Edit post link.
  135. edit_post_link(
  136. sprintf(
  137. wp_kses(
  138. /* translators: %s: Name of current post. Only visible to screen readers. */
  139. __( 'Edit <span class="screen-reader-text">%s</span>', 'blank-canvas' ),
  140. array(
  141. 'span' => array(
  142. 'class' => array(),
  143. ),
  144. )
  145. ),
  146. get_the_title()
  147. ),
  148. '<span class="edit-link">' . seedlet_get_icon_svg( 'edit', 16 ),
  149. '</span>'
  150. );
  151. }
  152. endif;
  153. /**
  154. * Enqueue scripts and styles.
  155. */
  156. function blank_canvas_enqueue() {
  157. wp_enqueue_style( 'blank-canvas-styles', get_stylesheet_uri() );
  158. }
  159. add_action( 'wp_enqueue_scripts', 'blank_canvas_enqueue', 11 );
  160. /**
  161. * Block Patterns.
  162. */
  163. require get_stylesheet_directory() . '/inc/block-patterns.php';
  164. /**
  165. * Customizer additions.
  166. */
  167. require get_stylesheet_directory() . '/inc/customizer.php';
  168. /**
  169. * Adds custom classes to the array of body classes.
  170. *
  171. * @param array $classes Classes for the body element.
  172. * @return array
  173. */
  174. function blank_canvas_body_classes( $classes ) {
  175. if ( false === get_theme_mod( 'show_post_and_page_titles', false ) ) {
  176. $classes[] = 'hide-post-and-page-titles';
  177. }
  178. if ( false === get_theme_mod( 'show_site_footer', false ) ) {
  179. $classes[] = 'hide-site-footer';
  180. }
  181. if ( false === get_theme_mod( 'show_comments', false ) ) {
  182. $classes[] = 'hide-comments';
  183. }
  184. return $classes;
  185. }
  186. add_filter( 'body_class', 'blank_canvas_body_classes' );