functions.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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.0.1
  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. // Note, the is_IE global variable is defined by WordPress and is used
  98. // to detect if the current browser is internet explorer.
  99. global $is_IE;
  100. if ( $is_IE ) {
  101. $editor_stylesheet_path = './assets/css/ie-editor.css';
  102. }
  103. // Enqueue editor styles.
  104. add_editor_style(
  105. array(
  106. seedlet_fonts_url(),
  107. $editor_stylesheet_path,
  108. ) );
  109. // Add custom editor font sizes.
  110. add_theme_support(
  111. 'editor-font-sizes',
  112. array(
  113. array(
  114. 'name' => __( 'Tiny', 'seedlet' ),
  115. 'shortName' => __( 'XS', 'seedlet' ),
  116. 'size' => 14,
  117. 'slug' => 'tiny',
  118. ),
  119. array(
  120. 'name' => __( 'Small', 'seedlet' ),
  121. 'shortName' => __( 'S', 'seedlet' ),
  122. 'size' => 16,
  123. 'slug' => 'small',
  124. ),
  125. array(
  126. 'name' => __( 'Normal', 'seedlet' ),
  127. 'shortName' => __( 'M', 'seedlet' ),
  128. 'size' => 18,
  129. 'slug' => 'normal',
  130. ),
  131. array(
  132. 'name' => __( 'Large', 'seedlet' ),
  133. 'shortName' => __( 'L', 'seedlet' ),
  134. 'size' => 24,
  135. 'slug' => 'large',
  136. ),
  137. array(
  138. 'name' => __( 'Huge', 'seedlet' ),
  139. 'shortName' => __( 'XL', 'seedlet' ),
  140. 'size' => 28,
  141. 'slug' => 'huge',
  142. ),
  143. )
  144. );
  145. // Editor color palette.
  146. $colors_theme_mod = get_theme_mod( 'custom_colors_active' );
  147. $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' );
  148. $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' );
  149. $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' );
  150. $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' );
  151. $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' );
  152. add_theme_support(
  153. 'editor-color-palette',
  154. array(
  155. array(
  156. 'name' => __( 'Primary', 'seedlet' ),
  157. 'slug' => 'primary',
  158. 'color' => $primary
  159. ),
  160. array(
  161. 'name' => __( 'Secondary', 'seedlet' ),
  162. 'slug' => 'secondary',
  163. 'color' => $secondary
  164. ),
  165. array(
  166. 'name' => __( 'Foreground', 'seedlet' ),
  167. 'slug' => 'foreground',
  168. 'color' => $foreground
  169. ),
  170. array(
  171. 'name' => __( 'Tertiary', 'seedlet' ),
  172. 'slug' => 'tertiary',
  173. 'color' => $tertiary
  174. ),
  175. array(
  176. 'name' => __( 'Background', 'seedlet' ),
  177. 'slug' => 'background',
  178. 'color' => $background
  179. ),
  180. )
  181. );
  182. $gradient_color_a = $secondary;
  183. $gradient_color_b = $tertiary;
  184. add_theme_support(
  185. 'editor-gradient-presets',
  186. array(
  187. array(
  188. 'name' => __( 'Diagonal', 'seedlet' ),
  189. 'gradient' => 'linear-gradient(to bottom right, ' . $gradient_color_a . ' 49.9%, ' . $gradient_color_b . ' 50%)',
  190. 'slug' => 'hard-diagonal',
  191. ),
  192. array(
  193. 'name' => __( 'Diagonal inverted', 'seedlet' ),
  194. 'gradient' => 'linear-gradient(to top left, ' . $gradient_color_a . ' 49.9%, ' . $gradient_color_b . ' 50%)',
  195. 'slug' => 'hard-diagonal-inverted',
  196. ),
  197. array(
  198. 'name' => __( 'Horizontal', 'seedlet' ),
  199. 'gradient' => 'linear-gradient(to bottom, ' . $gradient_color_a . ' 50%, ' . $gradient_color_b . ' 50%)',
  200. 'slug' => 'hard-horizontal',
  201. ),
  202. array(
  203. 'name' => __( 'Horizontal inverted', 'seedlet' ),
  204. 'gradient' => 'linear-gradient(to top, ' . $gradient_color_a . ' 50%, ' . $gradient_color_b . ' 50%)',
  205. 'slug' => 'hard-horizontal-inverted',
  206. ),
  207. array(
  208. 'name' => __( 'Diagonal gradient', 'seedlet' ),
  209. 'gradient' => 'linear-gradient(to bottom right, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  210. 'slug' => 'diagonal',
  211. ),
  212. array(
  213. 'name' => __( 'Diagonal inverted gradient', 'seedlet' ),
  214. 'gradient' => 'linear-gradient(to top left, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  215. 'slug' => 'diagonal-inverted',
  216. ),
  217. array(
  218. 'name' => __( 'Horizontal gradient', 'seedlet' ),
  219. 'gradient' => 'linear-gradient(to bottom, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  220. 'slug' => 'horizontal',
  221. ),
  222. array(
  223. 'name' => __( 'Horizontal inverted gradient', 'seedlet' ),
  224. 'gradient' => 'linear-gradient(to top, ' . $gradient_color_a . ', ' . $gradient_color_b . ')',
  225. 'slug' => 'horizontal-inverted',
  226. ),
  227. array(
  228. 'name' => __( 'Stripe', 'seedlet' ),
  229. 'gradient' => 'linear-gradient(to bottom, transparent 20%, ' . $gradient_color_a . ' 20%, ' . $gradient_color_a . ' 80%, transparent 80%)',
  230. 'slug' => 'stripe',
  231. ),
  232. )
  233. );
  234. // Add support for responsive embedded content.
  235. add_theme_support( 'responsive-embeds' );
  236. // Add support for custom line height controls.
  237. add_theme_support( 'custom-line-height' );
  238. // Add support for experimental link color control.
  239. add_theme_support( 'experimental-link-color' );
  240. // Add support for experimental cover block spacing.
  241. add_theme_support( 'experimental-custom-spacing' );
  242. // Add support for custom units.
  243. add_theme_support( 'custom-units' );
  244. // Add support for WordPress.com Global Styles.
  245. add_theme_support(
  246. 'jetpack-global-styles',
  247. [
  248. 'enable_theme_default' => true,
  249. ]
  250. );
  251. }
  252. endif;
  253. add_action( 'after_setup_theme', 'seedlet_setup' );
  254. /**
  255. * Add Google webfonts, if necessary
  256. *
  257. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  258. */
  259. function seedlet_fonts_url() {
  260. $fonts_url = '';
  261. /* Translators: If there are characters in your language that are not
  262. * supported by Fira Sans, translate this to 'off'. Do not translate
  263. * into your own language.
  264. */
  265. $fira_sans = esc_html_x( 'on', 'Fira Sans: on or off', 'seedlet' );
  266. /* Translators: If there are characters in your language that are not
  267. * supported by Playfair Display, translate this to 'off'. Do not translate
  268. * into your own language.
  269. */
  270. $playfair_display = esc_html_x( 'on', 'Playfair Display: on or off', 'seedlet' );
  271. if ( 'off' !== $fira_sans || 'off' !== $playfair_display ) {
  272. $font_families = array();
  273. if ( 'off' !== $fira_sans ) {
  274. $font_families[] = 'Fira Sans:ital,wght@0,400;0,500;1,400';
  275. }
  276. if ( 'off' !== $playfair_display ) {
  277. $font_families[] = 'Playfair Display:ital,wght@0,400;0,700;1,400';
  278. }
  279. $query_args = array(
  280. 'family' => urlencode( implode( '|', $font_families ) ),
  281. 'subset' => urlencode( 'latin,latin-ext' ),
  282. );
  283. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  284. }
  285. return esc_url_raw( $fonts_url );
  286. }
  287. /**
  288. * Register widget area.
  289. *
  290. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  291. */
  292. function seedlet_widgets_init() {
  293. register_sidebar(
  294. array(
  295. 'name' => __( 'Footer', 'seedlet' ),
  296. 'id' => 'sidebar-1',
  297. 'description' => __( 'Add widgets here to appear in your footer.', 'seedlet' ),
  298. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  299. 'after_widget' => '</section>',
  300. 'before_title' => '<h2 class="widget-title">',
  301. 'after_title' => '</h2>',
  302. )
  303. );
  304. }
  305. add_action( 'widgets_init', 'seedlet_widgets_init' );
  306. /**
  307. * Set the content width in pixels, based on the theme's design and stylesheet.
  308. *
  309. * Priority 0 to make it available to lower priority callbacks.
  310. *
  311. * @global int $content_width Content width.
  312. */
  313. function seedlet_content_width() {
  314. // This variable is intended to be overruled from themes.
  315. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  316. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  317. $GLOBALS['content_width'] = apply_filters( 'seedlet_content_width', 750 );
  318. }
  319. add_action( 'after_setup_theme', 'seedlet_content_width', 0 );
  320. /**
  321. * Enqueue scripts and styles.
  322. */
  323. function seedlet_scripts() {
  324. // Enqueue Google fonts
  325. wp_enqueue_style( 'seedlet-fonts', seedlet_fonts_url(), array(), null );
  326. // Theme styles
  327. wp_enqueue_style( 'seedlet-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
  328. // RTL styles
  329. wp_style_add_data( 'seedlet-style', 'rtl', 'replace' );
  330. // Print styles
  331. wp_enqueue_style( 'seedlet-print-style', get_template_directory_uri() . '/assets/css/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
  332. // Threaded comment reply styles
  333. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  334. wp_enqueue_script( 'comment-reply' );
  335. }
  336. // Main navigation scripts
  337. wp_enqueue_script( 'seedlet-primary-navigation-script', get_template_directory_uri() . '/assets/js/primary-navigation.js', array(), wp_get_theme()->get( 'Version' ), true );
  338. // Note, the is_IE global variable is defined by WordPress and is used
  339. // to detect if the current browser is internet explorer.
  340. global $is_IE;
  341. if ( $is_IE ) {
  342. // If IE 11 or below, use a ponyfill to add CSS Variable support
  343. wp_register_script( 'css-vars-ponyfill', get_stylesheet_directory_uri() . '/assets/js/css-vars-ponyfill2.js' );
  344. wp_enqueue_script( 'ie11-fix',
  345. get_stylesheet_directory_uri() . '/assets/js/ie11-fix.js',
  346. array( 'css-vars-ponyfill' ),
  347. '1.0'
  348. );
  349. }
  350. }
  351. add_action( 'wp_enqueue_scripts', 'seedlet_scripts' );
  352. /**
  353. * Fix skip link focus in IE11.
  354. *
  355. * This does not enqueue the script because it is tiny and because it is only for IE11,
  356. * thus it does not warrant having an entire dedicated blocking script being loaded.
  357. *
  358. * @link https://git.io/vWdr2
  359. */
  360. function seedlet_skip_link_focus_fix() {
  361. // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
  362. ?>
  363. <script>
  364. /(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);
  365. </script>
  366. <?php
  367. }
  368. add_action( 'wp_print_footer_scripts', 'seedlet_skip_link_focus_fix' );
  369. /**
  370. * SVG Icons class.
  371. */
  372. require get_template_directory() . '/classes/class-seedlet-svg-icons.php';
  373. /**
  374. * Custom colors class.
  375. */
  376. if ( ! class_exists( 'Colors_Manager' ) ) { // Check for presence of wpcom color manager to avoid duplicate color customization functionality.
  377. require get_template_directory() . '/classes/class-seedlet-custom-colors.php';
  378. }
  379. /**
  380. * Enhance the theme by hooking into WordPress.
  381. */
  382. require get_template_directory() . '/inc/template-functions.php';
  383. /**
  384. * SVG Icons related functions.
  385. */
  386. require get_template_directory() . '/inc/icon-functions.php';
  387. /**
  388. * Custom template tags for the theme.
  389. */
  390. require get_template_directory() . '/inc/template-tags.php';
  391. /**
  392. * Customizer additions.
  393. */
  394. require get_template_directory() . '/inc/customizer.php';
  395. /**
  396. * Block Patterns.
  397. */
  398. require get_template_directory() . '/inc/block-patterns.php';
  399. /**
  400. * Block Styles.
  401. */
  402. require get_template_directory() . '/inc/block-styles.php';
  403. /**
  404. * Load WooCommerce compatibility file.
  405. */
  406. if ( class_exists( 'WooCommerce' ) ) {
  407. require get_template_directory() . '/inc/woocommerce.php';
  408. }