functions.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. // Auto-Hide Navigation JavaScript - External File (jQuery Version)
  148. add_action( 'wp_enqueue_scripts', 'srh25_enqueue_navigation_script' );
  149. function srh25_enqueue_navigation_script() {
  150. // Option 1: Use separate JavaScript file (ACTIVE)
  151. wp_enqueue_script(
  152. 'srh-auto-hide-nav',
  153. get_stylesheet_directory_uri() . '/js/auto-hide-nav.js',
  154. array('jquery'),
  155. '1.0.0',
  156. true
  157. );
  158. }
  159. /***********************************************************
  160. #################### Off Canvas Menu #######################
  161. ************************************************************/
  162. // Register custom block category
  163. function srh_block_categories($categories) {
  164. return array_merge(
  165. [
  166. [
  167. 'slug' => 'srh-blocks',
  168. 'title' => 'SRH Blocks'
  169. ],
  170. ],
  171. $categories
  172. );
  173. }
  174. add_filter('block_categories_all', 'srh_block_categories', 10, 2);
  175. // Register the block
  176. function register_offcanvas_menu_block() {
  177. register_block_type(__DIR__ . '/blocks/offcanvas-menu', [
  178. 'editor_script' => 'offcanvas-menu-editor',
  179. 'editor_style' => 'offcanvas-menu-editor-style',
  180. 'script' => 'offcanvas-menu-frontend',
  181. 'style' => 'offcanvas-menu-style',
  182. 'render_callback' => 'render_offcanvas_menu'
  183. ]);
  184. wp_register_script(
  185. 'offcanvas-menu-editor',
  186. get_stylesheet_directory_uri() . '/blocks/offcanvas-menu/build/index.build.js',
  187. ['wp-blocks', 'wp-element', 'wp-editor']
  188. );
  189. }
  190. add_action('init', 'register_offcanvas_menu_block');
  191. // Frontend assets remain the same
  192. function enqueue_offcanvas_menu_assets() {
  193. wp_enqueue_script(
  194. 'offcanvas-menu-frontend',
  195. get_stylesheet_directory_uri() . '/js/offcanvas-menu.js',
  196. array('jquery'),
  197. '1.0.0',
  198. true
  199. );
  200. wp_enqueue_style(
  201. 'offcanvas-menu-style',
  202. get_stylesheet_directory_uri() . '/css/offcanvas-menu.css',
  203. array(),
  204. '1.0.0'
  205. );
  206. }
  207. add_action('wp_enqueue_scripts', 'enqueue_offcanvas_menu_assets');
  208. function render_offcanvas_menu($attributes, $content) {
  209. ob_start(); ?>
  210. <div class="wp-block-srh-offcanvas-menu">
  211. <button class="hamburger-toggle" aria-label="Toggle Menu">
  212. <span></span>
  213. <span></span>
  214. <span></span>
  215. </button>
  216. <div class="offcanvas-menu">
  217. <div class="offcanvas-menu-inner">
  218. <?php wp_nav_menu(array('theme_location' => 'primary-menu')); ?>
  219. </div>
  220. </div>
  221. </div>
  222. <?php
  223. return ob_get_clean();
  224. }
  225. /***********************************************************
  226. ############### Disable External Blocks ####################
  227. ************************************************************/
  228. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
  229. add_filter('should_load_remote_block_patterns', '__return_false');
  230. add_filter('block_directory_enabled', '__return_false');
  231. /***********************************************************
  232. ############### Disable Some Blocks ########################
  233. ************************************************************/
  234. function srh25_deny_list_blocks() {
  235. wp_enqueue_script(
  236. 'deny-list-blocks',
  237. get_stylesheet_directory_uri() . '/js/deny-list-blocks.js',
  238. array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
  239. '1.0.0',
  240. true
  241. );
  242. }
  243. add_action('enqueue_block_editor_assets', 'srh25_deny_list_blocks' );