functions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /***********************************************************
  3. ###################### Child Theme #########################
  4. ************************************************************/
  5. //add_action( 'wp_enqueue_scripts', 'twenty_five_enqueue_styles' );
  6. function twenty_five_enqueue_styles() {
  7. wp_enqueue_style( '2025-style', get_parent_theme_file_uri( 'style.css' ));
  8. }
  9. add_action( 'wp_enqueue_scripts', 'srh25_enqueue_styles' );
  10. function srh25_enqueue_styles() {
  11. wp_enqueue_style( 'srh-style', get_stylesheet_uri() );
  12. }
  13. /***********************************************************
  14. ###################### Admin Clean #########################
  15. ************************************************************/
  16. add_filter('gettext', 'srh25_change_howdy', 10, 3);
  17. function srh25_change_howdy($translated, $text, $domain) {
  18. if (false !== strpos($translated, 'Howdy,'))
  19. return str_replace('Howdy,', '', $translated);
  20. return $translated;
  21. }
  22. add_filter( 'gettext', 'srh25_change_howdy_text_email', 10, 2 );
  23. function srh25_change_howdy_text_email( $translation, $original ) {
  24. if( 'Howdy, %1$s' == $original )
  25. $translation = '%1$s';
  26. return $translation;
  27. }
  28. add_filter( 'show_admin_bar', '__return_false' );
  29. add_action( 'admin_bar_menu', 'srh25_admin_bar', 999 );
  30. function srh25_admin_bar( $wp_admin_bar ) {
  31. //$wp_admin_bar->remove_menu('my-account');
  32. //$wp_admin_bar->remove_menu( 'edit' );
  33. //$wp_admin_bar->remove_menu('site-name');
  34. $wp_admin_bar->remove_node('wp-logo');
  35. $wp_admin_bar->remove_node('themes');
  36. $wp_admin_bar->remove_node('widgets');
  37. $wp_admin_bar->remove_node('menus');
  38. $wp_admin_bar->remove_node('new-media');
  39. $wp_admin_bar->remove_menu('edit-profile');
  40. $wp_admin_bar->remove_menu('comments');
  41. $wp_admin_bar->remove_menu('about');
  42. $wp_admin_bar->remove_menu('wporg');
  43. $wp_admin_bar->remove_menu('documentation');
  44. $wp_admin_bar->remove_menu('support-forums');
  45. $wp_admin_bar->remove_menu('feedback');
  46. $wp_admin_bar->remove_menu('customize');
  47. $wp_admin_bar->remove_menu('view-site');
  48. $wp_admin_bar->remove_menu('updates');
  49. $wp_admin_bar->remove_menu('comments');
  50. $wp_admin_bar->remove_menu('new-content');
  51. $wp_admin_bar->remove_menu('view');
  52. }
  53. add_action( 'admin_init', 'srh25_remove_dashboard_meta' );
  54. function srh25_remove_dashboard_meta() {
  55. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  56. remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
  57. remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
  58. remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
  59. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  60. remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
  61. }
  62. add_action( 'admin_head-profile.php', 'srh25_remove_admin_color' );
  63. function srh25_remove_admin_color() {
  64. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  65. }
  66. add_filter('admin_footer_text', 'srh25_remove_admin_footer_text', 1000);
  67. function srh25_remove_admin_footer_text(){return '';}
  68. add_filter('update_footer', 'srh25_remove_admin_footer_upgrade', 1000);
  69. function srh25_remove_admin_footer_upgrade(){return '';}
  70. /***********************************************************
  71. ###################### Log In/Out ##########################
  72. ************************************************************/
  73. add_filter( 'login_headerurl', 'srh25_login_logo_url' );
  74. function srh25_login_logo_url() {
  75. return home_url();
  76. }
  77. add_filter( 'login_headertext', 'srh25_login_url_title' );
  78. function srh25_login_url_title() {
  79. return 'SRH Physicians';
  80. }
  81. add_action( 'login_enqueue_scripts', 'srh25_login_logo' );
  82. function srh25_login_logo() { ?>
  83. <style type="text/css">
  84. .login h1 a {
  85. background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/disc.png) !important;
  86. padding-bottom: 30px;
  87. }
  88. .wp-core-ui .button-primary {
  89. background: #4FB54F;
  90. border-color: #027643;
  91. }
  92. .login .message {
  93. border-left: 4px solid #027643;
  94. }
  95. .login form .forgetmenot label {
  96. display:none;
  97. }
  98. .login #backtoblog a {
  99. display:none;
  100. }
  101. </style>
  102. <?php }
  103. /***********************************************************
  104. ####################### Allow SVG ##########################
  105. ************************************************************/
  106. add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
  107. global $wp_version;
  108. if ( $wp_version !== '4.7.1' ) {
  109. return $data;
  110. }
  111. $filetype = wp_check_filetype( $filename, $mimes );
  112. return [
  113. 'ext' => $filetype['ext'],
  114. 'type' => $filetype['type'],
  115. 'proper_filename' => $data['proper_filename']
  116. ];
  117. }, 10, 4 );
  118. add_action( 'admin_head', 'fix_svg' );
  119. function cc_mime_types( $mimes ){
  120. $mimes['svg'] = 'image/svg+xml';
  121. return $mimes;
  122. }
  123. add_filter( 'upload_mimes', 'cc_mime_types' );
  124. function fix_svg() {
  125. echo '<style type="text/css">
  126. .attachment-266x266, .thumbnail img {
  127. width: 100% !important;
  128. height: auto !important;
  129. }
  130. </style>';
  131. }
  132. /***********************************************************
  133. #################### Edit Page Link ########################
  134. ************************************************************/
  135. function add_edit_link() {
  136. ob_start();
  137. edit_post_link( __( 'Edit Page', 'textdomain' ), '<div class="wp-block-button">', '</div>', null, 'wp-block-button__link has-accent-2-background-color has-background wp-element-button' );
  138. return ob_get_clean();
  139. }
  140. add_action( 'init', 'add_edit_link_shortcode' );
  141. function add_edit_link_shortcode() {
  142. add_shortcode( 'edit-link', 'add_edit_link' );
  143. }
  144. /***********************************************************
  145. ################ Auto-Hide Navigation ######################
  146. ************************************************************/
  147. // Enqueue the auto-hide navigation JavaScript
  148. add_action( 'wp_enqueue_scripts', 'srh25_enqueue_navigation_script' );
  149. function srh25_enqueue_navigation_script() {
  150. // Option 1: Use separate JavaScript file (commented out for debugging)
  151. /*
  152. wp_enqueue_script(
  153. 'srh25-auto-hide-nav',
  154. get_stylesheet_directory_uri() . '/js/auto-hide-nav.js',
  155. array(),
  156. '1.0.1',
  157. true
  158. );
  159. */
  160. // Option 2: Inline script (active for better compatibility)
  161. wp_enqueue_script( 'jquery' );
  162. $navigation_script = "
  163. jQuery(document).ready(function($) {
  164. console.log('Auto-hide navigation: jQuery script loaded');
  165. let lastScrollTop = 0;
  166. let scrollThreshold = 100;
  167. // Find header with multiple selectors
  168. let header = $('header').first();
  169. if (header.length === 0) {
  170. header = $('.wp-site-header, .wp-block-template-part[data-area=\"header\"], [class*=\"header\"]').first();
  171. }
  172. let body = $('body');
  173. let headerHeight = 0;
  174. console.log('Header element found:', header.length > 0 ? header[0] : 'None');
  175. if (header.length === 0) {
  176. console.warn('No header element found for auto-hide navigation');
  177. return;
  178. }
  179. // Add identifying class
  180. header.addClass('srh-auto-hide-header');
  181. function calculateHeaderHeight() {
  182. headerHeight = header.outerHeight() || 80;
  183. document.documentElement.style.setProperty('--header-height', headerHeight + 'px');
  184. console.log('Header height calculated:', headerHeight);
  185. }
  186. calculateHeaderHeight();
  187. $(window).on('resize', calculateHeaderHeight);
  188. $(window).on('scroll', function() {
  189. let scrollTop = $(this).scrollTop();
  190. if (scrollTop > 50) {
  191. body.addClass('header-offset');
  192. header.addClass('header-scrolled');
  193. } else {
  194. body.removeClass('header-offset');
  195. header.removeClass('header-scrolled');
  196. }
  197. if (scrollTop > scrollThreshold) {
  198. if (scrollTop > lastScrollTop) {
  199. // Scrolling down - hide header
  200. header.removeClass('header-visible').addClass('header-hidden');
  201. } else {
  202. // Scrolling up - show header
  203. header.removeClass('header-hidden').addClass('header-visible');
  204. }
  205. } else {
  206. // Near top - always show header
  207. header.removeClass('header-hidden header-visible');
  208. }
  209. lastScrollTop = scrollTop;
  210. });
  211. $(document).on('mousemove', function(e) {
  212. if (e.clientY < 100 && $(window).scrollTop() > scrollThreshold) {
  213. header.removeClass('header-hidden').addClass('header-visible');
  214. }
  215. });
  216. $('a[href^=\"#\"]').on('click', function(e) {
  217. let target = $(this.getAttribute('href'));
  218. if (target.length) {
  219. e.preventDefault();
  220. $('html, body').animate({
  221. scrollTop: target.offset().top - headerHeight
  222. }, 600);
  223. }
  224. });
  225. $(document).on('keydown', function(e) {
  226. if (e.key === 'Tab' || e.key === 'Escape') {
  227. header.removeClass('header-hidden').addClass('header-visible');
  228. }
  229. });
  230. header.find('a, button, input, textarea, select').on('focus', function() {
  231. header.removeClass('header-hidden').addClass('header-visible');
  232. });
  233. console.log('Auto-hide navigation: Initialization complete');
  234. });
  235. ";
  236. wp_add_inline_script( 'jquery', $navigation_script );
  237. }
  238. // Add CSS custom properties support for older browsers
  239. add_action( 'wp_head', 'srh25_navigation_css_vars' );
  240. function srh25_navigation_css_vars() {
  241. ?>
  242. <script>
  243. // CSS custom properties fallback
  244. if (!window.CSS || !CSS.supports('color', 'var(--fake-var)')) {
  245. document.documentElement.style.setProperty = document.documentElement.style.setProperty || function(property, value, priority) {
  246. this[property] = value;
  247. };
  248. }
  249. </script>
  250. <?php
  251. }