functions.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. if ( ! function_exists( 'dw_setup' ) ):
  3. function dw_setup() {
  4. require( get_template_directory() . '/inc/utils.php' );
  5. require( get_template_directory() . '/inc/template.php' );
  6. require( get_template_directory() . '/inc/tweaks.php' );
  7. if ( ! isset( $content_width ) ) $content_width = 1310;
  8. add_theme_support( 'title-tag' );
  9. add_theme_support( 'wp-block-styles' );
  10. add_theme_support( 'automatic-feed-links' );
  11. add_theme_support( 'responsive-embeds' );
  12. add_theme_support( 'menus' );
  13. add_theme_support( 'post-thumbnails' );
  14. add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );
  15. add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'video', 'audio', 'quote', 'link', 'status', 'chat' ) );
  16. set_post_thumbnail_size( 150, 150, true );
  17. add_image_size( 'post-large', 770, 577, true );
  18. add_image_size( 'studio', 400, 300, true );
  19. add_filter( 'big_image_size_threshold', '__return_false' );
  20. add_theme_support( 'align-wide' );
  21. // Load the front-end stylesheet into the block editor so editor typography/sizing
  22. // matches the front end (was missing — only a 2-line editor.css was enqueued).
  23. add_theme_support( 'editor-styles' );
  24. add_editor_style( array( 'v4-style.min.css', 'css/editor.css' ) );
  25. remove_action( 'init', 'wp_sitemaps_get_server' );
  26. // added this to remove depreciation warning in v6.4.1 b/c front page doesn't have wp_header
  27. remove_action( 'wp_footer', 'the_block_template_skip_link' );
  28. // see changes @ https://core.trac.wordpress.org/changeset/56932
  29. }
  30. endif;
  31. add_action( 'after_setup_theme', 'dw_setup' );
  32. if ( ! function_exists( 'dw_plugs' ) ):
  33. function dw_plugs() {
  34. require( get_template_directory() . '/inc/smtp.php');
  35. //echo wp_mail( 'david@davidawindham.com', 'WP Mail Test', 'Mail is working' );
  36. if (!class_exists('dw_crumbs')) {
  37. //include_once(TEMPLATEPATH.'/inc/crumbs.php');
  38. }
  39. }
  40. endif;
  41. add_action( 'after_setup_theme', 'dw_plugs' );
  42. // Keep login sessions alive for a year (default is 2 days, 14 with "Remember Me").
  43. // There's no WP constant for this — it's the auth_cookie_expiration filter, so it
  44. // can't live in wp-config.php. Lower YEAR_IN_SECONDS if you want a shorter session.
  45. function dw_login_session( $length, $user_id, $remember ) {
  46. return YEAR_IN_SECONDS;
  47. }
  48. add_filter( 'auth_cookie_expiration', 'dw_login_session', 10, 3 );
  49. function dw_remove_block_library_css(){
  50. wp_dequeue_style( 'wp-block-library' );
  51. }
  52. //add_action( 'wp_enqueue_scripts', 'dw_remove_block_library_css' );
  53. add_action( 'wp_enqueue_scripts', 'dw_scripts' );
  54. function dw_scripts() {
  55. global $post;
  56. wp_enqueue_style( 'style-min', get_template_directory_uri() . '/v4-style.min.css');
  57. wp_deregister_script('jquery');
  58. if ( is_page('about') ) {
  59. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  60. // FullCalendar is About-only — load its bundle + CSS here (before about.js consumes it),
  61. // not site-wide.
  62. wp_enqueue_style( 'fullcalendar', get_template_directory_uri() . '/css/v4-fullcalendar.css' );
  63. wp_enqueue_script( 'fullcalendar', get_template_directory_uri() . '/js/v4-fullcalendar.min.js', '', '', true );
  64. wp_enqueue_script( 'init', get_template_directory_uri() . '/js/about.js', '', '', true );
  65. }
  66. elseif ( is_page('studio') ) {
  67. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  68. wp_enqueue_script( 'init', get_template_directory_uri() . '/js/studio.js', '', '', true );
  69. }
  70. elseif ( is_page('music') ) {
  71. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  72. wp_enqueue_script( 'last-fm', get_template_directory_uri() . '/js/music.js', '', '', true );
  73. }
  74. elseif ( is_page('art') ) {
  75. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  76. wp_enqueue_script( 'art', get_template_directory_uri() . '/js/art.js', '', '', true );
  77. }
  78. elseif ( is_page('contact') ) {
  79. require( get_template_directory() . '/inc/form.php' );
  80. //gravity_form_enqueue_scripts(1, false);
  81. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  82. wp_enqueue_style( 'gforms', get_template_directory_uri() . '/css/form.css');
  83. wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery-3.1.0.min.js', array(), false, true);
  84. wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', array(), '3', true);
  85. wp_enqueue_script( 'form', get_template_directory_uri() . '/js/contact.js', '', '', true );
  86. }
  87. elseif ( is_page('guests') ) {
  88. require( get_template_directory() . '/inc/form.php' );
  89. //gravity_form_enqueue_scripts(1, false);
  90. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  91. wp_enqueue_style( 'gforms', get_template_directory_uri() . '/css/form.css');
  92. wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery-3.1.0.min.js', array(), false, true);
  93. wp_enqueue_script( 'form', get_template_directory_uri() . '/js/contact.js', '', '', true );
  94. }
  95. elseif ( is_page('contract') ) {
  96. require( get_template_directory() . '/inc/form.php' );
  97. //gravity_form_enqueue_scripts(1, false);
  98. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  99. wp_enqueue_style( 'gforms', get_template_directory_uri() . '/css/form.css');
  100. wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery-3.1.0.min.js', array(), false, true);
  101. wp_enqueue_script( 'form', get_template_directory_uri() . '/js/contact.js', '', '', true );
  102. }
  103. elseif ( is_page('pay') ) {
  104. require( get_template_directory() . '/inc/form.php' );
  105. //gravity_form_enqueue_scripts(1, false);
  106. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  107. wp_enqueue_style( 'gforms', get_template_directory_uri() . '/css/form.css');
  108. wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery-3.1.0.min.js', array(), false, true);
  109. }
  110. elseif ( is_page('analytics') ) {
  111. require( get_template_directory() . '/inc/analytics.php' );
  112. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  113. wp_enqueue_script( 'dashboardjs', get_template_directory_uri() . '/js/analytics.js', '', '', true );
  114. }
  115. elseif ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  116. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  117. wp_enqueue_script( 'single', get_template_directory_uri() . '/js/single.js', '', '', true );
  118. wp_enqueue_script( 'comment-reply' );
  119. }
  120. elseif ( is_page('desk') || is_archive() || is_search() ) {
  121. global $wp_rewrite;
  122. wp_enqueue_script( 'jquery', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  123. wp_enqueue_script( 'desk', get_template_directory_uri() . '/js/desk.js', '', '', true );
  124. wp_enqueue_script( '_s_backbone-loop', get_template_directory_uri() . '/js/loop.js', array( 'jquery', 'backbone', 'underscore', 'wp-api' ), '1.0', true );
  125. $queried_object = get_queried_object();
  126. $local = array(
  127. 'loopType' => 'home',
  128. 'queriedObject' => $queried_object,
  129. 'pathInfo' => array(
  130. 'author_permastruct' => $wp_rewrite->get_author_permastruct(),
  131. 'host' => preg_replace( '#^http(s)?://#i', '', untrailingslashit( home_url() ) ),
  132. 'path' => _s_backbone_get_request_path(),
  133. 'use_trailing_slashes' => $wp_rewrite->use_trailing_slashes,
  134. 'parameters' => _s_backbone_get_request_parameters(),
  135. ),
  136. );
  137. if ( is_category() || is_tag() || is_tax() ) {
  138. $local['loopType'] = 'archive';
  139. $local['taxonomy'] = get_taxonomy( $queried_object->taxonomy );
  140. } elseif ( is_search() ) {
  141. $local['loopType'] = 'search';
  142. $local['searchQuery'] = get_search_query();
  143. } elseif ( is_author() ) {
  144. $local['loopType'] = 'author';
  145. }
  146. if ( is_paged() ) {
  147. $local['page'] = absint( get_query_var( 'paged' ) ) + 1;
  148. }
  149. wp_localize_script( '_s_backbone-loop', 'settings', $local );
  150. }
  151. else {
  152. //wp_deregister_script('mediaelement');
  153. wp_enqueue_script( 'scriptmin', get_template_directory_uri() . '/js/v4-script.min.js', '', '', true );
  154. wp_enqueue_script( 'single', get_template_directory_uri() . '/js/single.js', '', '', true );
  155. wp_enqueue_script( 'mediaelement-me', get_template_directory_uri() .'/js/mediaelement-and-player.min.js', '', '', true);
  156. wp_enqueue_script( 'mediaelement-wp', get_template_directory_uri() .'/js/wp-mediaelement.min.js', '', '', true);
  157. }
  158. }
  159. // davo-bot 2000 — AI ask widget. Printed directly on wp_footer (like dw_analytics)
  160. // rather than enqueued, because front-page.php skips wp_head() so wp_enqueue_scripts
  161. // never fires there. The loader pulls /ask/widget.js (proxied same-origin to ralph).
  162. // On the homepage, window.dwAsk.open = 'once' auto-opens the terminal on first visit.
  163. function dw_ask_widget() {
  164. if ( is_admin() ) return;
  165. $src = get_template_directory_uri() . '/js/ask-widget.js';
  166. $ver = filemtime( get_template_directory() . '/js/ask-widget.js' );
  167. $open = is_front_page() ? 'once' : '';
  168. ?>
  169. <script>window.dwAsk = {open:"<?php echo esc_js( $open ); ?>"};</script>
  170. <script src="<?php echo esc_url( $src . '?ver=' . $ver ); ?>"></script>
  171. <?php
  172. }
  173. add_action( 'wp_footer', 'dw_ask_widget' );
  174. // front-page.php is fully self-contained (no wp_head, hand-rolled critical CSS, zero
  175. // blocks/presets), but WordPress still injects theme.json's global styles — and its
  176. // body/h1-h6 element rules override the homepage's intended typography. Strip them on
  177. // the front page only; the rest of the site keeps them. (front-page.php skips wp_head,
  178. // so the global styles print during wp_footer — dequeue before that late-print runs.)
  179. function dw_no_global_styles_on_home() {
  180. if ( is_front_page() ) {
  181. wp_dequeue_style( 'global-styles' );
  182. wp_dequeue_style( 'global-styles-css-custom-properties' );
  183. }
  184. }
  185. add_action( 'wp_enqueue_scripts', 'dw_no_global_styles_on_home', 100 );
  186. add_action( 'wp_footer', 'dw_no_global_styles_on_home', 1 );
  187. // Dev only: on a real content save, ping BrowserSync's reload endpoint so the front-end
  188. // preview refreshes — DB content changes aren't visible to a filesystem watcher otherwise.
  189. // Hooks the REST save events the block editor actually fires (+ customizer + nav menus).
  190. // Gated to WP_DEBUG → no-op in production.
  191. if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
  192. function dw_bs_reload_on_save( $post = null ) {
  193. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  194. if ( $post && is_object( $post ) && $post->post_status === 'auto-draft' ) return;
  195. wp_remote_get( 'https://daw.stu:81/__browser_sync__?method=reload', array(
  196. 'blocking' => false,
  197. 'sslverify' => false,
  198. ) );
  199. }
  200. add_action( 'rest_after_insert_page', 'dw_bs_reload_on_save', 10, 3 );
  201. add_action( 'rest_after_insert_post', 'dw_bs_reload_on_save', 10, 3 );
  202. add_action( 'customize_save_after', 'dw_bs_reload_on_save', 10, 3 );
  203. add_action( 'wp_update_nav_menu', 'dw_bs_reload_on_save', 10, 3 );
  204. }
  205. add_action('wp_footer', 'dw_analytics', 22);
  206. function dw_analytics() { ?>
  207. <script>
  208. var _paq = window._paq = window._paq || [];
  209. /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  210. _paq.push(['trackPageView']);
  211. _paq.push(['enableLinkTracking']);
  212. (function() {
  213. var u="https://davidawindham.com/wik/";
  214. _paq.push(['setTrackerUrl', u+'matomo.php']);
  215. _paq.push(['setSiteId', '1']);
  216. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  217. g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  218. })();
  219. </script>
  220. <noscript><p><img src="https://davidawindham.com/wik/matomo.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript>
  221. <?php }
  222. ?>