functions.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. * Remove Seedlet theme features.
  66. */
  67. function blank_canvas_remove_parent_theme_features() {
  68. // Theme Support.
  69. remove_theme_support( 'custom-header' );
  70. remove_theme_support( 'customize-selective-refresh-widgets' );
  71. }
  72. add_action( 'after_setup_theme', 'blank_canvas_remove_parent_theme_features', 11 );
  73. /**
  74. * Dequeue Seedlet scripts.
  75. */
  76. function blank_canvas_dequeue_parent_scripts() {
  77. if ( false === get_theme_mod( 'show_site_header', false ) ) {
  78. // Naviation assets.
  79. wp_dequeue_script( 'seedlet-primary-navigation-script' );
  80. wp_dequeue_style( 'seedlet-style-navigation' );
  81. }
  82. }
  83. add_action( 'wp_enqueue_scripts', 'blank_canvas_dequeue_parent_scripts', 11 );
  84. /**
  85. * Remove unused custmizer settings.
  86. */
  87. function blank_canvas_remove_customizer_settings( $wp_customize ) {
  88. // Remove Jetpack's Author Bio setting.
  89. if ( function_exists( 'jetpack_author_bio' ) ) {
  90. $wp_customize->remove_control( 'jetpack_content_author_bio_title' );
  91. $wp_customize->remove_control( 'jetpack_content_author_bio' );
  92. }
  93. // Remove Seedlet's header and footer hide options,
  94. // since they're already hidden by default.
  95. $wp_customize->remove_control( 'hide_site_header' );
  96. $wp_customize->remove_control( 'hide_site_footer' );
  97. }
  98. add_action( 'customize_register', 'blank_canvas_remove_customizer_settings', 11 );
  99. /**
  100. * Add custmizer settings.
  101. */
  102. function blank_canvas_add_customizer_settings( $wp_customize ) {
  103. // Add a Customizer message about the site title & tagline options.
  104. $wp_customize->get_section( 'title_tagline' )->description = __( 'The site logo, title, and tagline will only appear on single posts and pages if the “Site header and top menu" option is enabled in the Content Options section.', 'blank-canvas' );
  105. $wp_customize->get_section( 'menu_locations' )->description = __( 'This theme will only display Menus if they are enabled in the Content Options section.', 'blank-canvas' );
  106. $wp_customize->get_panel( 'nav_menus' )->description = __( 'This theme will only display Menus if they are enabled in the Content Options section.', 'blank-canvas' );
  107. $wp_customize->get_panel( 'widgets' )->description = __( 'This theme will only display Widgets if they are enabled in the Content Options section.', 'blank-canvas' );
  108. }
  109. add_action( 'customize_register', 'blank_canvas_add_customizer_settings', 11 );
  110. /**
  111. * Remove Meta Footer Items.
  112. */
  113. if ( ! function_exists( 'seedlet_entry_meta_footer' ) ) :
  114. /**
  115. * Prints HTML with meta information for the categories, tags and comments.
  116. */
  117. function seedlet_entry_meta_footer() {
  118. // Edit post link.
  119. edit_post_link(
  120. sprintf(
  121. wp_kses(
  122. /* translators: %s: Name of current post. Only visible to screen readers. */
  123. __( 'Edit <span class="screen-reader-text">%s</span>', 'blank-canvas' ),
  124. array(
  125. 'span' => array(
  126. 'class' => array(),
  127. ),
  128. )
  129. ),
  130. get_the_title()
  131. ),
  132. '<span class="edit-link">' . seedlet_get_icon_svg( 'edit', 16 ),
  133. '</span>'
  134. );
  135. }
  136. endif;
  137. /**
  138. * Enqueue scripts and styles.
  139. */
  140. function blank_canvas_enqueue() {
  141. wp_enqueue_style( 'blank-canvas-styles', get_stylesheet_uri() );
  142. }
  143. add_action( 'wp_enqueue_scripts', 'blank_canvas_enqueue', 11 );
  144. /**
  145. * Block Patterns.
  146. */
  147. require get_stylesheet_directory() . '/inc/block-patterns.php';
  148. /**
  149. * Enqueue CSS for Customizer message.
  150. */
  151. function blank_canvas_customizer_enqueue() {
  152. wp_enqueue_style( 'blank-canvas-customizer-style', get_stylesheet_directory_uri() . '/assets/customizer.css', array(), wp_get_theme()->get( 'Version' ) );
  153. }
  154. add_action( 'customize_controls_enqueue_scripts', 'blank_canvas_customizer_enqueue' );
  155. /**
  156. * Customizer additions.
  157. */
  158. require get_stylesheet_directory() . '/inc/customizer.php';