functions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. // Registers pattern categories.
  14. add_action( 'init', 'srh25_pattern_categories' );
  15. function srh25_pattern_categories() {
  16. register_block_pattern_category(
  17. 'srh25_page',
  18. array(
  19. 'label' => __( 'Pages', 'srh25' ),
  20. 'description' => __( 'A collection of full page layouts.', 'srh25' ),
  21. )
  22. );
  23. }
  24. /***********************************************************
  25. ###################### Admin Clean #########################
  26. ************************************************************/
  27. add_filter('gettext', 'srh25_change_howdy', 10, 3);
  28. function srh25_change_howdy($translated, $text, $domain) {
  29. if (false !== strpos($translated, 'Howdy,'))
  30. return str_replace('Howdy,', '', $translated);
  31. return $translated;
  32. }
  33. add_filter( 'gettext', 'srh25_change_howdy_text_email', 10, 2 );
  34. function srh25_change_howdy_text_email( $translation, $original ) {
  35. if( 'Howdy, %1$s' == $original )
  36. $translation = '%1$s';
  37. return $translation;
  38. }
  39. add_filter( 'show_admin_bar', '__return_false' );
  40. add_action( 'admin_bar_menu', 'srh25_admin_bar', 999 );
  41. function srh25_admin_bar( $wp_admin_bar ) {
  42. //$wp_admin_bar->remove_menu('my-account');
  43. //$wp_admin_bar->remove_menu( 'edit' );
  44. //$wp_admin_bar->remove_menu('site-name');
  45. $wp_admin_bar->remove_node('wp-logo');
  46. $wp_admin_bar->remove_node('themes');
  47. $wp_admin_bar->remove_node('widgets');
  48. $wp_admin_bar->remove_node('menus');
  49. $wp_admin_bar->remove_node('new-media');
  50. $wp_admin_bar->remove_menu('edit-profile');
  51. $wp_admin_bar->remove_menu('comments');
  52. $wp_admin_bar->remove_menu('about');
  53. $wp_admin_bar->remove_menu('wporg');
  54. $wp_admin_bar->remove_menu('documentation');
  55. $wp_admin_bar->remove_menu('support-forums');
  56. $wp_admin_bar->remove_menu('feedback');
  57. $wp_admin_bar->remove_menu('customize');
  58. $wp_admin_bar->remove_menu('view-site');
  59. $wp_admin_bar->remove_menu('updates');
  60. $wp_admin_bar->remove_menu('comments');
  61. $wp_admin_bar->remove_menu('new-content');
  62. $wp_admin_bar->remove_menu('view');
  63. }
  64. add_action( 'admin_init', 'srh25_remove_dashboard_meta' );
  65. function srh25_remove_dashboard_meta() {
  66. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  67. remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
  68. remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
  69. remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
  70. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  71. remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
  72. }
  73. add_action( 'admin_head-profile.php', 'srh25_remove_admin_color' );
  74. function srh25_remove_admin_color() {
  75. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  76. }
  77. add_filter('admin_footer_text', 'srh25_remove_admin_footer_text', 1000);
  78. function srh25_remove_admin_footer_text(){return '';}
  79. add_filter('update_footer', 'srh25_remove_admin_footer_upgrade', 1000);
  80. function srh25_remove_admin_footer_upgrade(){return '';}
  81. /***********************************************************
  82. ###################### Log In/Out ##########################
  83. ************************************************************/
  84. add_filter( 'login_headerurl', 'srh25_login_logo_url' );
  85. function srh25_login_logo_url() {
  86. return home_url();
  87. }
  88. add_filter( 'login_headertext', 'srh25_login_url_title' );
  89. function srh25_login_url_title() {
  90. return 'SRH Physicians';
  91. }
  92. add_action( 'login_enqueue_scripts', 'srh25_login_logo' );
  93. function srh25_login_logo() { ?>
  94. <style type="text/css">
  95. .login h1 a {
  96. background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/disc.png) !important;
  97. padding-bottom: 30px;
  98. }
  99. .wp-core-ui .button-primary {
  100. background: #4FB54F;
  101. border-color: #027643;
  102. }
  103. .login .message {
  104. border-left: 4px solid #027643;
  105. }
  106. .login form .forgetmenot label {
  107. display:none;
  108. }
  109. .login #backtoblog a {
  110. display:none;
  111. }
  112. </style>
  113. <?php }
  114. /***********************************************************
  115. ####################### Allow SVG ##########################
  116. ************************************************************/
  117. add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
  118. global $wp_version;
  119. if ( $wp_version !== '4.7.1' ) {
  120. return $data;
  121. }
  122. $filetype = wp_check_filetype( $filename, $mimes );
  123. return [
  124. 'ext' => $filetype['ext'],
  125. 'type' => $filetype['type'],
  126. 'proper_filename' => $data['proper_filename']
  127. ];
  128. }, 10, 4 );
  129. add_action( 'admin_head', 'fix_svg' );
  130. function cc_mime_types( $mimes ){
  131. $mimes['svg'] = 'image/svg+xml';
  132. return $mimes;
  133. }
  134. add_filter( 'upload_mimes', 'cc_mime_types' );
  135. function fix_svg() {
  136. echo '<style type="text/css">
  137. .attachment-266x266, .thumbnail img {
  138. width: 100% !important;
  139. height: auto !important;
  140. }
  141. </style>';
  142. }
  143. /***********************************************************
  144. #################### Edit Page Link ########################
  145. ************************************************************/
  146. function add_edit_link() {
  147. ob_start();
  148. 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' );
  149. return ob_get_clean();
  150. }
  151. add_action( 'init', 'add_edit_link_shortcode' );
  152. function add_edit_link_shortcode() {
  153. add_shortcode( 'edit-link', 'add_edit_link' );
  154. }
  155. /***********************************************************
  156. ################ Auto-Hide Navigation ######################
  157. ************************************************************/
  158. // Auto-Hide Navigation JavaScript - External File (jQuery Version)
  159. add_action( 'wp_enqueue_scripts', 'srh25_enqueue_navigation_script' );
  160. function srh25_enqueue_navigation_script() {
  161. // Option 1: Use separate JavaScript file (ACTIVE)
  162. wp_enqueue_script(
  163. 'srh-auto-hide-nav',
  164. get_stylesheet_directory_uri() . '/js/auto-hide-nav.js',
  165. array('jquery'),
  166. '1.0.0',
  167. true
  168. );
  169. }
  170. /***********************************************************
  171. #################### Off Canvas Menu #######################
  172. ************************************************************/
  173. // Register custom block category
  174. function srh_block_categories($categories) {
  175. return array_merge(
  176. [
  177. [
  178. 'slug' => 'srh-blocks',
  179. 'title' => 'SRH Blocks'
  180. ],
  181. ],
  182. $categories
  183. );
  184. }
  185. add_filter('block_categories_all', 'srh_block_categories', 10, 2);
  186. // Register the block
  187. function register_offcanvas_menu_block() {
  188. register_block_type( __DIR__ . '/blocks/offcanvas-menu', array(
  189. 'render_callback' => 'render_offcanvas_menu',
  190. 'editor_script' => 'offcanvas-menu-editor',
  191. 'editor_style' => 'offcanvas-menu-editor',
  192. 'supports' => array(
  193. 'inserter' => true,
  194. 'multiple' => true,
  195. 'parent' => array('core/navigation')
  196. )
  197. ));
  198. // Register editor assets
  199. wp_register_script(
  200. 'offcanvas-menu-editor',
  201. get_stylesheet_directory_uri() . '/js/offcanvas-menu-editor.js',
  202. array('wp-blocks', 'wp-element'),
  203. '1.0.0'
  204. );
  205. wp_register_style(
  206. 'offcanvas-menu-editor',
  207. get_stylesheet_directory_uri() . '/css/offcanvas-menu-editor.css',
  208. array(),
  209. '1.0.0'
  210. );
  211. }
  212. add_action('init', 'register_offcanvas_menu_block');
  213. // Frontend assets remain the same
  214. function enqueue_offcanvas_menu_assets() {
  215. wp_enqueue_style(
  216. 'offcanvas-menu-style',
  217. get_stylesheet_directory_uri() . '/css/offcanvas-menu.css',
  218. array(),
  219. '1.0.0'
  220. );
  221. wp_enqueue_script(
  222. 'offcanvas-menu',
  223. get_stylesheet_directory_uri() . '/js/offcanvas-menu.js',
  224. array('jquery'),
  225. '1.0.0',
  226. true
  227. );
  228. }
  229. add_action('wp_enqueue_scripts', 'enqueue_offcanvas_menu_assets');
  230. function render_offcanvas_menu($attributes, $content) {
  231. $template_part = do_blocks('<!-- wp:template-part {"slug":"offcanvas-content","theme":"edit-srh"} /-->');
  232. return sprintf(
  233. '<div class="wp-block-srh-offcanvas-menu">
  234. <button class="hamburger-toggle" aria-label="Toggle Menu">
  235. <div class="hamburger-lines">
  236. <span></span>
  237. <span></span>
  238. <span></span>
  239. </div>
  240. <span class="menu-text">Menu</span>
  241. </button>
  242. <div class="offcanvas-menu">
  243. <div class="offcanvas-menu-inner">%s</div>
  244. </div>
  245. </div>',
  246. $template_part
  247. );
  248. }
  249. /***********************************************************
  250. ############### Disable External Blocks ####################
  251. ************************************************************/
  252. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
  253. add_filter('should_load_remote_block_patterns', '__return_false');
  254. add_filter('block_directory_enabled', '__return_false');
  255. add_filter( 'block_editor_settings_all', function( $settings, $context ) {
  256. $settings['enableOpenverseMediaCategory'] = false;
  257. return $settings;
  258. }, 10, 2 );
  259. /***********************************************************
  260. ############### Disable Some Blocks ########################
  261. ************************************************************/
  262. function srh25_deny_list_blocks() {
  263. wp_enqueue_script(
  264. 'deny-list-blocks',
  265. get_stylesheet_directory_uri() . '/js/deny-list-blocks.js',
  266. array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
  267. '1.0.1',
  268. true
  269. );
  270. }
  271. add_action('enqueue_block_editor_assets', 'srh25_deny_list_blocks' );
  272. /***********************************************************
  273. ############### Unregister Patterns ########################
  274. ************************************************************/
  275. function srh25_unregister_patterns() {
  276. unregister_block_pattern( 'twentytwentyfive/vertical-header' );
  277. }
  278. add_action( 'init', 'srh25_unregister_patterns', 999 );
  279. function srh25_remove_core_patterns() {
  280. remove_theme_support( 'core-block-patterns' );
  281. }
  282. add_action( 'after_setup_theme', 'srh25_remove_core_patterns' );
  283. /***********************************************************
  284. ############### Hide JQuery Notice #########################
  285. ************************************************************/
  286. add_action('wp_default_scripts', function ($scripts) {
  287. if (!empty($scripts->registered['jquery'])) {
  288. $scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']);
  289. }
  290. });