functions.php 11 KB

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