functions.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <?php
  2. /**
  3. * Seedlet functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Seedlet
  8. * @since 1.1.0
  9. */
  10. /**
  11. * seedlet only works in WordPress 4.7 or later.
  12. */
  13. if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
  14. require get_template_directory() . '/inc/back-compat.php';
  15. return;
  16. }
  17. if ( ! function_exists( 'seedlet_setup' ) ) :
  18. /**
  19. * Sets up theme defaults and registers support for various WordPress features.
  20. *
  21. * Note that this function is hooked into the after_setup_theme hook, which
  22. * runs before the init hook. The init hook is too late for some features, such
  23. * as indicating support for post thumbnails.
  24. */
  25. function seedlet_setup() {
  26. /*
  27. * Make theme available for translation.
  28. * Translations can be filed in the /languages/ directory.
  29. * If you're building a theme based on seedlet, use a find and replace
  30. * to change 'seedlet' to the name of your theme in all the template files.
  31. */
  32. load_theme_textdomain( 'seedlet', get_template_directory() . '/languages' );
  33. // Add default posts and comments RSS feed links to head.
  34. add_theme_support( 'automatic-feed-links' );
  35. /*
  36. * Let WordPress manage the document title.
  37. * By adding theme support, we declare that this theme does not use a
  38. * hard-coded <title> tag in the document head, and expect WordPress to
  39. * provide it for us.
  40. */
  41. add_theme_support( 'title-tag' );
  42. /*
  43. * Enable support for Post Thumbnails on posts and pages.
  44. *
  45. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  46. */
  47. add_theme_support( 'post-thumbnails' );
  48. set_post_thumbnail_size( 1568, 9999 );
  49. // This theme uses wp_nav_menu() in two locations.
  50. register_nav_menus(
  51. array(
  52. 'primary' => __( 'Primary Navigation', 'seedlet' ),
  53. 'footer' => __( 'Footer Navigation', 'seedlet' ),
  54. 'social' => __( 'Social Links Navigation', 'seedlet' ),
  55. )
  56. );
  57. /*
  58. * Switch default core markup for search form, comment form, and comments
  59. * to output valid HTML5.
  60. */
  61. add_theme_support(
  62. 'html5',
  63. array(
  64. 'search-form',
  65. 'comment-form',
  66. 'comment-list',
  67. 'gallery',
  68. 'caption',
  69. 'style',
  70. 'script',
  71. 'navigation-widgets',
  72. )
  73. );
  74. /**
  75. * Add support for core custom logo.
  76. *
  77. * @link https://codex.wordpress.org/Theme_Logo
  78. */
  79. add_theme_support(
  80. 'custom-logo',
  81. array(
  82. 'height' => 240,
  83. 'width' => 240,
  84. 'flex-width' => false,
  85. 'flex-height' => false,
  86. )
  87. );
  88. // Add theme support for selective refresh for widgets.
  89. add_theme_support( 'customize-selective-refresh-widgets' );
  90. // Add support for Block Styles.
  91. add_theme_support( 'wp-block-styles' );
  92. // Add support for full and wide align images.
  93. add_theme_support( 'align-wide' );
  94. // Add support for editor styles.
  95. add_theme_support( 'editor-styles' );
  96. $editor_stylesheet_path = './assets/css/style-editor.css';
  97. // Enqueue editor styles.
  98. add_editor_style(
  99. array(
  100. seedlet_fonts_url(),
  101. './assets/css/style-editor.css',
  102. )
  103. );
  104. // Add custom editor font sizes.
  105. add_theme_support(
  106. 'editor-font-sizes',
  107. array(
  108. array(
  109. 'name' => __( 'Tiny', 'seedlet' ),
  110. 'shortName' => __( 'XS', 'seedlet' ),
  111. 'size' => 14,
  112. 'slug' => 'tiny',
  113. ),
  114. array(
  115. 'name' => __( 'Small', 'seedlet' ),
  116. 'shortName' => __( 'S', 'seedlet' ),
  117. 'size' => 16,
  118. 'slug' => 'small',
  119. ),
  120. array(
  121. 'name' => __( 'Normal', 'seedlet' ),
  122. 'shortName' => __( 'M', 'seedlet' ),
  123. 'size' => 18,
  124. 'slug' => 'normal',
  125. ),
  126. array(
  127. 'name' => __( 'Large', 'seedlet' ),
  128. 'shortName' => __( 'L', 'seedlet' ),
  129. 'size' => 24,
  130. 'slug' => 'large',
  131. ),
  132. array(
  133. 'name' => __( 'Huge', 'seedlet' ),
  134. 'shortName' => __( 'XL', 'seedlet' ),
  135. 'size' => 28,
  136. 'slug' => 'huge',
  137. ),
  138. )
  139. );
  140. // Editor color palette.
  141. $colors_theme_mod = get_theme_mod( 'custom_colors_active' );
  142. $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' );
  143. $secondary = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-secondary' ) ) ) ? '#3C8067' : get_theme_mod( 'seedlet_--global--color-secondary' );
  144. $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' );
  145. $tertiary = ( ! empty( $colors_theme_mod ) && 'default' === $colors_theme_mod || empty( get_theme_mod( 'seedlet_--global--color-tertiary' ) ) ) ? '#FAFBF6' : get_theme_mod( 'seedlet_--global--color-tertiary' );
  146. $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' );
  147. add_theme_support(
  148. 'editor-color-palette',
  149. array(
  150. array(
  151. 'name' => __( 'Primary', 'seedlet' ),
  152. 'slug' => 'primary',
  153. 'color' => $primary,
  154. ),
  155. array(
  156. 'name' => __( 'Secondary', 'seedlet' ),
  157. 'slug' => 'secondary',
  158. 'color' => $secondary,
  159. ),
  160. array(
  161. 'name' => __( 'Foreground', 'seedlet' ),
  162. 'slug' => 'foreground',
  163. 'color' => $foreground,
  164. ),
  165. array(
  166. 'name' => __( 'Tertiary', 'seedlet' ),
  167. 'slug' => 'tertiary',
  168. 'color' => $tertiary,
  169. ),
  170. array(
  171. 'name' => __( 'Background', 'seedlet' ),
  172. 'slug' => 'background',
  173. 'color' => $background,
  174. ),
  175. )
  176. );
  177. $gradient_color_a = $secondary;
  178. $gradient_color_b = $tertiary;
  179. add_theme_support(
  180. 'editor-gradient-presets',
  181. array(
  182. array(
  183. 'name' => __( 'Diagonal', 'seedlet' ),
  184. 'gradient' => 'linear-gradient(to bottom right, ' . $gradient_color_a . ' 49.9%, ' . $gradient_color_b . ' 50%)',
  185. 'slug' => 'hard-diagonal',
  186. ),
  187. array(
  188. 'name' => __( 'Diagonal inverted', 'seedlet' ),
  189. 'gradient' => 'linear-gradient(to top left, ' . $gradient_color_a . ' 49.9%, ' . $gradient_color_b . ' 50%)',
  190. 'slug' => 'hard-diagonal-inverted',
  191. ),
  192. array(
  193. 'name' => __( 'Horizontal', 'seedlet' ),
  194. 'gradient' => 'linear-gradient(to bottom, ' . $gradient_color_a . ' 50%, ' . $gradient_color_b . ' 50%)',
  195. 'slug' => 'hard-horizontal',
  196. ),
  197. array(
  198. 'name' => __( 'Horizontal inverted', 'seedlet' ),
  199. 'gradient' => 'linear-gradient(to top, ' . $gradient_color_a . ' 50%, ' . $gradient_color_b . ' 50%)',
  200. 'slug' => 'hard-horizontal-inverted',
  201. ),
  202. array(
  203. 'name' => __( 'Diagonal gradient', 'seedlet' ),
  204. 'gradient' => 'linear-gradient(to bottom right, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  205. 'slug' => 'diagonal',
  206. ),
  207. array(
  208. 'name' => __( 'Diagonal inverted gradient', 'seedlet' ),
  209. 'gradient' => 'linear-gradient(to top left, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  210. 'slug' => 'diagonal-inverted',
  211. ),
  212. array(
  213. 'name' => __( 'Horizontal gradient', 'seedlet' ),
  214. 'gradient' => 'linear-gradient(to bottom, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  215. 'slug' => 'horizontal',
  216. ),
  217. array(
  218. 'name' => __( 'Horizontal inverted gradient', 'seedlet' ),
  219. 'gradient' => 'linear-gradient(to top, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  220. 'slug' => 'horizontal-inverted',
  221. ),
  222. array(
  223. 'name' => __( 'Stripe', 'seedlet' ),
  224. 'gradient' => 'linear-gradient(to bottom, transparent 20%, ' . $gradient_color_a . ' 20%, ' . $gradient_color_a . ' 80%, transparent 80%)',
  225. 'slug' => 'stripe',
  226. ),
  227. )
  228. );
  229. // Add support for responsive embedded content.
  230. add_theme_support( 'responsive-embeds' );
  231. // Add support for custom line height controls.
  232. add_theme_support( 'custom-line-height' );
  233. // Add support for experimental link color control.
  234. add_theme_support( 'experimental-link-color' );
  235. // Add support for experimental cover block spacing.
  236. add_theme_support( 'custom-spacing' );
  237. // Add support for custom units.
  238. add_theme_support( 'custom-units' );
  239. // Add support for WordPress.com Global Styles.
  240. add_theme_support(
  241. 'jetpack-global-styles',
  242. array(
  243. 'enable_theme_default' => true,
  244. )
  245. );
  246. }
  247. endif;
  248. add_action( 'after_setup_theme', 'seedlet_setup' );
  249. /**
  250. * Add Google webfonts, if necessary
  251. *
  252. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  253. */
  254. function seedlet_fonts_url() {
  255. $fonts_url = '';
  256. /* Translators: If there are characters in your language that are not
  257. * supported by Fira Sans, translate this to 'off'. Do not translate
  258. * into your own language.
  259. */
  260. $fira_sans = esc_html_x( 'on', 'Fira Sans: on or off', 'seedlet' );
  261. /* Translators: If there are characters in your language that are not
  262. * supported by Playfair Display, translate this to 'off'. Do not translate
  263. * into your own language.
  264. */
  265. $playfair_display = esc_html_x( 'on', 'Playfair Display: on or off', 'seedlet' );
  266. if ( 'off' !== $fira_sans || 'off' !== $playfair_display ) {
  267. $font_families = array();
  268. if ( 'off' !== $fira_sans ) {
  269. $font_families[] = 'Fira Sans:ital,wght@0,400;0,500;1,400';
  270. }
  271. if ( 'off' !== $playfair_display ) {
  272. $font_families[] = 'Playfair Display:ital,wght@0,400;0,700;1,400';
  273. }
  274. $query_args = array(
  275. 'family' => urlencode( implode( '|', $font_families ) ),
  276. 'subset' => urlencode( 'latin,latin-ext' ),
  277. );
  278. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  279. }
  280. return esc_url_raw( $fonts_url );
  281. }
  282. /**
  283. * Register widget area.
  284. *
  285. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  286. */
  287. function seedlet_widgets_init() {
  288. register_sidebar(
  289. array(
  290. 'name' => __( 'Footer', 'seedlet' ),
  291. 'id' => 'sidebar-1',
  292. 'description' => __( 'Add widgets here to appear in your footer.', 'seedlet' ),
  293. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  294. 'after_widget' => '</section>',
  295. 'before_title' => '<h2 class="widget-title">',
  296. 'after_title' => '</h2>',
  297. )
  298. );
  299. }
  300. add_action( 'widgets_init', 'seedlet_widgets_init' );
  301. /**
  302. * Set the content width in pixels, based on the theme's design and stylesheet.
  303. *
  304. * Priority 0 to make it available to lower priority callbacks.
  305. *
  306. * @global int $content_width Content width.
  307. */
  308. function seedlet_content_width() {
  309. // This variable is intended to be overruled from themes.
  310. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  311. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  312. $GLOBALS['content_width'] = apply_filters( 'seedlet_content_width', 620 );
  313. }
  314. add_action( 'after_setup_theme', 'seedlet_content_width', 0 );
  315. /**
  316. * Enqueue scripts and styles.
  317. */
  318. function seedlet_scripts() {
  319. // Enqueue Google fonts
  320. wp_enqueue_style( 'seedlet-fonts', seedlet_fonts_url(), array(), null );
  321. // Theme styles
  322. wp_enqueue_style( 'seedlet-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
  323. // Navigation styles
  324. wp_enqueue_style( 'seedlet-style-navigation', get_template_directory_uri() . '/assets/css/style-navigation.css', array(), wp_get_theme()->get( 'Version' ) );
  325. // RTL styles
  326. wp_style_add_data( 'seedlet-style', 'rtl', 'replace' );
  327. wp_style_add_data( 'seedlet-style-navigation', 'rtl', 'replace' );
  328. // Print styles
  329. wp_enqueue_style( 'seedlet-print-style', get_template_directory_uri() . '/assets/css/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
  330. // Threaded comment reply styles
  331. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  332. wp_enqueue_script( 'comment-reply' );
  333. }
  334. // Main navigation scripts
  335. wp_enqueue_script( 'seedlet-primary-navigation-script', get_template_directory_uri() . '/assets/js/primary-navigation.js', array(), wp_get_theme()->get( 'Version' ), true );
  336. // Note, the is_IE global variable is defined by WordPress and is used
  337. // to detect if the current browser is internet explorer.
  338. global $is_IE;
  339. if ( $is_IE ) {
  340. // If IE 11 or below, use a ponyfill to add CSS Variable support
  341. wp_register_script( 'css-vars-ponyfill', get_template_directory_uri() . '/assets/js/css-vars-ponyfill2.js' );
  342. wp_enqueue_script(
  343. 'ie11-fix',
  344. get_template_directory_uri() . '/assets/js/ie11-fix.js',
  345. array( 'css-vars-ponyfill' ),
  346. '1.0'
  347. );
  348. }
  349. }
  350. add_action( 'wp_enqueue_scripts', 'seedlet_scripts' );
  351. /**
  352. * Fix skip link focus in IE11.
  353. *
  354. * This does not enqueue the script because it is tiny and because it is only for IE11,
  355. * thus it does not warrant having an entire dedicated blocking script being loaded.
  356. *
  357. * @link https://git.io/vWdr2
  358. */
  359. function seedlet_skip_link_focus_fix() {
  360. // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
  361. ?>
  362. <script>
  363. /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
  364. </script>
  365. <?php
  366. }
  367. add_action( 'wp_print_footer_scripts', 'seedlet_skip_link_focus_fix' );
  368. if ( ! function_exists( 'seedlet_author_bio' ) ) {
  369. /**
  370. * Implements the Jetpack Author bio
  371. */
  372. function seedlet_author_bio() {
  373. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  374. if ( ! is_singular( 'attachment' ) ) {
  375. get_template_part( 'template-parts/post/author-bio' );
  376. }
  377. } else {
  378. jetpack_author_bio();
  379. }
  380. }
  381. }
  382. /**
  383. * SVG Icons class.
  384. */
  385. require get_template_directory() . '/classes/class-seedlet-svg-icons.php';
  386. /**
  387. * Custom colors class.
  388. */
  389. if ( ! class_exists( 'Colors_Manager' ) ) { // Check for presence of wpcom color manager to avoid duplicate color customization functionality.
  390. require get_template_directory() . '/classes/class-seedlet-custom-colors.php';
  391. }
  392. /**
  393. * Enhance the theme by hooking into WordPress.
  394. */
  395. require get_template_directory() . '/inc/template-functions.php';
  396. /**
  397. * SVG Icons related functions.
  398. */
  399. require get_template_directory() . '/inc/icon-functions.php';
  400. /**
  401. * Custom template tags for the theme.
  402. */
  403. require get_template_directory() . '/inc/template-tags.php';
  404. /**
  405. * Customizer additions.
  406. */
  407. require get_template_directory() . '/inc/customizer.php';
  408. /**
  409. * Block Patterns.
  410. */
  411. require get_template_directory() . '/inc/block-patterns.php';
  412. /**
  413. * Block Styles.
  414. */
  415. require get_template_directory() . '/inc/block-styles.php';
  416. /**
  417. * Load WooCommerce compatibility file.
  418. */
  419. if ( class_exists( 'WooCommerce' ) ) {
  420. require get_template_directory() . '/inc/woocommerce.php';
  421. }
  422. /**
  423. * Load Jetpack compatibility file.
  424. */
  425. require get_template_directory() . '/inc/jetpack.php';