functions.php 5.8 KB

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