functions.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. /**
  3. * Varia functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package WordPress
  8. * @subpackage Varia
  9. * @since 1.0.0
  10. */
  11. /**
  12. * Varia only works in WordPress 4.7 or later.
  13. */
  14. if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
  15. require get_template_directory() . '/inc/back-compat.php';
  16. return;
  17. }
  18. if ( ! function_exists( 'varia_setup' ) ) :
  19. /**
  20. * Sets up theme defaults and registers support for various WordPress features.
  21. *
  22. * Note that this function is hooked into the after_setup_theme hook, which
  23. * runs before the init hook. The init hook is too late for some features, such
  24. * as indicating support for post thumbnails.
  25. */
  26. function varia_setup() {
  27. /*
  28. * Make theme available for translation.
  29. * Translations can be filed in the /languages/ directory.
  30. * If you're building a theme based on Varia, use a find and replace
  31. * to change 'varia' to the name of your theme in all the template files.
  32. */
  33. load_theme_textdomain( 'varia', get_template_directory() . '/languages' );
  34. // Add default posts and comments RSS feed links to head.
  35. add_theme_support( 'automatic-feed-links' );
  36. /*
  37. * Let WordPress manage the document title.
  38. * By adding theme support, we declare that this theme does not use a
  39. * hard-coded <title> tag in the document head, and expect WordPress to
  40. * provide it for us.
  41. */
  42. add_theme_support( 'title-tag' );
  43. /*
  44. * Enable support for Post Thumbnails on posts and pages.
  45. *
  46. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  47. */
  48. add_theme_support( 'post-thumbnails', array( 'post' ) );
  49. set_post_thumbnail_size( 1568, 9999 );
  50. // This theme uses wp_nav_menu() in two locations.
  51. register_nav_menus(
  52. array(
  53. 'menu-1' => __( 'Primary', 'varia' ),
  54. 'menu-2' => __( 'Footer Menu', 'varia' ),
  55. 'social' => __( 'Social Links Menu', 'varia' ),
  56. )
  57. );
  58. /*
  59. * Switch default core markup for search form, comment form, and comments
  60. * to output valid HTML5.
  61. */
  62. add_theme_support(
  63. 'html5',
  64. array(
  65. 'search-form',
  66. 'comment-form',
  67. 'comment-list',
  68. 'gallery',
  69. 'caption',
  70. )
  71. );
  72. /**
  73. * Add support for core custom logo.
  74. *
  75. * @link https://codex.wordpress.org/Theme_Logo
  76. */
  77. add_theme_support(
  78. 'custom-logo',
  79. array(
  80. 'height' => 96,
  81. 'width' => 100,
  82. 'flex-width' => true,
  83. 'flex-height' => false,
  84. 'header-text' => array( 'site-title', 'site-description' ),
  85. )
  86. );
  87. // Add theme support for selective refresh for widgets.
  88. add_theme_support( 'customize-selective-refresh-widgets' );
  89. // Add support for Block Styles.
  90. add_theme_support( 'wp-block-styles' );
  91. // Add support for full and wide align images.
  92. add_theme_support( 'align-wide' );
  93. // Add support for editor styles.
  94. add_theme_support( 'editor-styles' );
  95. // Enqueue editor styles.
  96. add_editor_style( 'style-editor.css' );
  97. // add_editor_style( 'child-theme-alt-style.css' ); // this will get loaded in a child theme
  98. // Add custom editor font sizes.
  99. add_theme_support(
  100. 'editor-font-sizes',
  101. array(
  102. array(
  103. 'name' => __( 'Small', 'varia' ),
  104. 'shortName' => __( 'S', 'varia' ),
  105. 'size' => 15,
  106. 'slug' => 'small',
  107. ),
  108. array(
  109. 'name' => __( 'Normal', 'varia' ),
  110. 'shortName' => __( 'M', 'varia' ),
  111. 'size' => 18,
  112. 'slug' => 'normal',
  113. ),
  114. array(
  115. 'name' => __( 'Large', 'varia' ),
  116. 'shortName' => __( 'L', 'varia' ),
  117. 'size' => 25.92,
  118. 'slug' => 'large',
  119. ),
  120. array(
  121. 'name' => __( 'Huge', 'varia' ),
  122. 'shortName' => __( 'XL', 'varia' ),
  123. 'size' => 31.105,
  124. 'slug' => 'huge',
  125. ),
  126. )
  127. );
  128. // $default_hue = varia_get_default_hue();
  129. // $saturation = varia_get_default_saturation();
  130. // $lightness = varia_get_default_lightness();
  131. // $lightness_hover = varia_get_default_lightness_hover();
  132. // Editor color palette.
  133. add_theme_support(
  134. 'editor-color-palette',
  135. array(
  136. array(
  137. 'name' => __( 'Primary', 'varia' ),
  138. 'slug' => 'primary',
  139. 'color' => '#0000FF', // varia_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? $default_hue : get_theme_mod( 'primary_color_hue', $default_hue ), $saturation, $lightness ),
  140. ),
  141. array(
  142. 'name' => __( 'Secondary', 'varia' ),
  143. 'slug' => 'secondary',
  144. 'color' => '#FF0000', // varia_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? $default_hue : get_theme_mod( 'primary_color_hue', $default_hue ), $saturation, $lightness_hover ),
  145. ),
  146. array(
  147. 'name' => __( 'Dark Gray', 'varia' ),
  148. 'slug' => 'foreground-dark',
  149. 'color' => '#111111',
  150. ),
  151. array(
  152. 'name' => __( 'Gray', 'varia' ),
  153. 'slug' => 'foreground',
  154. 'color' => '#444444',
  155. ),
  156. array(
  157. 'name' => __( 'Light Gray', 'varia' ),
  158. 'slug' => 'foreground-light',
  159. 'color' => '#767676',
  160. ),
  161. array(
  162. 'name' => __( 'Lighter Gray', 'varia' ),
  163. 'slug' => 'background-dark',
  164. 'color' => '#DDDDDD',
  165. ),
  166. array(
  167. 'name' => __( 'Subtle Gray', 'varia' ),
  168. 'slug' => 'background-light',
  169. 'color' => '#FAFAFA',
  170. ),
  171. array(
  172. 'name' => __( 'White', 'varia' ),
  173. 'slug' => 'background',
  174. 'color' => '#FFFFFF',
  175. ),
  176. )
  177. );
  178. // Add support for responsive embedded content.
  179. add_theme_support( 'responsive-embeds' );
  180. // Add support for Global Styles.
  181. add_theme_support(
  182. 'jetpack-global-styles',
  183. [
  184. 'enable_theme_default' => true,
  185. ]
  186. );
  187. }
  188. endif;
  189. add_action( 'after_setup_theme', 'varia_setup' );
  190. /**
  191. * Register widget area.
  192. *
  193. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  194. */
  195. function varia_widgets_init() {
  196. register_sidebar(
  197. array(
  198. 'name' => __( 'Footer', 'varia' ),
  199. 'id' => 'sidebar-1',
  200. 'description' => __( 'Add widgets here to appear in your footer.', 'varia' ),
  201. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  202. 'after_widget' => '</section>',
  203. 'before_title' => '<h2 class="widget-title">',
  204. 'after_title' => '</h2>',
  205. )
  206. );
  207. }
  208. add_action( 'widgets_init', 'varia_widgets_init' );
  209. /**
  210. * Set the content width in pixels, based on the theme's design and stylesheet.
  211. *
  212. * Priority 0 to make it available to lower priority callbacks.
  213. *
  214. * @global int $content_width Content width.
  215. */
  216. function varia_content_width() {
  217. // This variable is intended to be overruled from themes.
  218. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  219. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  220. $GLOBALS['content_width'] = apply_filters( 'varia_content_width', 750 );
  221. }
  222. add_action( 'after_setup_theme', 'varia_content_width', 0 );
  223. /**
  224. * Enqueue scripts and styles.
  225. */
  226. function varia_scripts() {
  227. // Theme styles
  228. wp_enqueue_style( 'varia-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  229. // RTL styles
  230. wp_style_add_data( 'varia-style', 'rtl', 'replace' );
  231. // Print styles
  232. wp_enqueue_style( 'varia-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
  233. // Threaded comment reply styles
  234. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  235. wp_enqueue_script( 'comment-reply' );
  236. }
  237. }
  238. add_action( 'wp_enqueue_scripts', 'varia_scripts' );
  239. /**
  240. * Fix skip link focus in IE11.
  241. *
  242. * This does not enqueue the script because it is tiny and because it is only for IE11,
  243. * thus it does not warrant having an entire dedicated blocking script being loaded.
  244. *
  245. * @link https://git.io/vWdr2
  246. */
  247. function varia_skip_link_focus_fix() {
  248. // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
  249. ?>
  250. <script>
  251. /(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);
  252. </script>
  253. <?php
  254. }
  255. add_action( 'wp_print_footer_scripts', 'varia_skip_link_focus_fix' );
  256. /**
  257. * Enqueue block editor content-width styles.
  258. * - These need to be enqueued separately to include the selectors
  259. * that live outside of `.editor-styles-wrapper`
  260. *
  261. */
  262. function varia_editor_content_width() {
  263. wp_enqueue_style( 'varia-editor-content-width-style', get_theme_file_uri( '/style-editor-content-width.css' ), false, wp_get_theme()->get( 'Version' ), 'all' );
  264. }
  265. add_action( 'enqueue_block_editor_assets', 'varia_editor_content_width' );
  266. /**
  267. * SVG Icons class.
  268. */
  269. require get_template_directory() . '/classes/class-varia-svg-icons.php';
  270. /**
  271. * Custom Comment Walker template.
  272. */
  273. require get_template_directory() . '/classes/class-varia-walker-comment.php';
  274. /**
  275. * Enhance the theme by hooking into WordPress.
  276. */
  277. require get_template_directory() . '/inc/template-functions.php';
  278. /**
  279. * SVG Icons related functions.
  280. */
  281. require get_template_directory() . '/inc/icon-functions.php';
  282. /**
  283. * Custom template tags for the theme.
  284. */
  285. require get_template_directory() . '/inc/template-tags.php';