functions.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. /**
  3. * Additional logging in WordPress 6.1+ that generates the following
  4. * message regarding cron schedules:
  5. *
  6. * Cron reschedule event error for hook:
  7. * action_scheduler_run_queue,
  8. * Error code: invalid_schedule,
  9. * Error message: Event schedule does not exist.,
  10. * Data: {"schedule":"every_minute","args":,"interval":60}
  11. *
  12. * This function needs to fire prior to loading Action Scheduler as its a
  13. * pre-requisite for it to schedule our tasks.
  14. *
  15. * This filter seeks to manually add the schedule to the list of schedules to
  16. * address this bug.
  17. */
  18. add_filter('cron_schedules', function ($schedules) {
  19. $schedules = [
  20. 'interval' => 60,
  21. 'display' => 'Every Minute',
  22. ];
  23. return $schedules;
  24. });
  25. /***********************************************************
  26. ############### REST API and Iframe Support ################
  27. ************************************************************/
  28. // Add REST API and iframe communication support
  29. add_action('after_setup_theme', 'srh25_setup_theme_support');
  30. function srh25_setup_theme_support() {
  31. add_theme_support('editor-styles');
  32. add_theme_support('responsive-embeds');
  33. add_theme_support('custom-units');
  34. // Ensure proper communication for block editor
  35. if (is_admin()) {
  36. add_filter('allowed_http_origins', 'srh25_allow_local_origins');
  37. }
  38. }
  39. function srh25_allow_local_origins($origins) {
  40. $origins[] = home_url();
  41. return array_unique($origins);
  42. }
  43. // Add headers for iframe communication
  44. add_action('send_headers', 'srh25_add_frame_headers');
  45. function srh25_add_frame_headers() {
  46. if (is_admin()) {
  47. header('Access-Control-Allow-Origin: ' . esc_url(home_url()));
  48. header('Access-Control-Allow-Credentials: true');
  49. }
  50. }
  51. /***********************************************************
  52. #################### SRH Theme #############################
  53. ************************************************************/
  54. //add_action( 'wp_enqueue_scripts', 'twenty_five_enqueue_styles' );
  55. function twenty_five_enqueue_styles() {
  56. wp_enqueue_style( '2025-style', get_parent_theme_file_uri( 'style.css' ));
  57. }
  58. add_action( 'wp_enqueue_scripts', 'srh25_enqueue_styles' );
  59. function srh25_enqueue_styles() {
  60. wp_enqueue_style( 'srh-style', get_stylesheet_uri() );
  61. }
  62. // Registers pattern categories.
  63. add_action( 'init', 'srh25_pattern_categories' );
  64. function srh25_pattern_categories() {
  65. register_block_pattern_category(
  66. 'srh25_page',
  67. array(
  68. 'label' => __( 'Pages', 'srh25' ),
  69. 'description' => __( 'A collection of full page layouts.', 'srh25' ),
  70. )
  71. );
  72. }
  73. /***********************************************************
  74. ###################### Admin Clean #########################
  75. ************************************************************/
  76. add_filter('gettext', 'srh25_change_howdy', 10, 3);
  77. function srh25_change_howdy($translated, $text, $domain) {
  78. if (false !== strpos($translated, 'Howdy,'))
  79. return str_replace('Howdy,', '', $translated);
  80. return $translated;
  81. }
  82. add_filter( 'gettext', 'srh25_change_howdy_text_email', 10, 2 );
  83. function srh25_change_howdy_text_email( $translation, $original ) {
  84. if( 'Howdy, %1$s' == $original )
  85. $translation = '%1$s';
  86. return $translation;
  87. }
  88. add_filter( 'show_admin_bar', '__return_false' );
  89. add_action( 'admin_bar_menu', 'srh25_admin_bar', 999 );
  90. function srh25_admin_bar( $wp_admin_bar ) {
  91. //$wp_admin_bar->remove_menu('my-account');
  92. //$wp_admin_bar->remove_menu( 'edit' );
  93. //$wp_admin_bar->remove_menu('site-name');
  94. $wp_admin_bar->remove_node('wp-logo');
  95. $wp_admin_bar->remove_node('themes');
  96. $wp_admin_bar->remove_node('widgets');
  97. $wp_admin_bar->remove_node('menus');
  98. $wp_admin_bar->remove_node('new-media');
  99. $wp_admin_bar->remove_menu('edit-profile');
  100. $wp_admin_bar->remove_menu('comments');
  101. $wp_admin_bar->remove_menu('about');
  102. $wp_admin_bar->remove_menu('wporg');
  103. $wp_admin_bar->remove_menu('documentation');
  104. $wp_admin_bar->remove_menu('support-forums');
  105. $wp_admin_bar->remove_menu('feedback');
  106. $wp_admin_bar->remove_menu('customize');
  107. $wp_admin_bar->remove_menu('view-site');
  108. $wp_admin_bar->remove_menu('updates');
  109. $wp_admin_bar->remove_menu('comments');
  110. $wp_admin_bar->remove_menu('new-content');
  111. $wp_admin_bar->remove_menu('view');
  112. }
  113. add_action( 'admin_init', 'srh25_remove_dashboard_meta' );
  114. function srh25_remove_dashboard_meta() {
  115. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  116. remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
  117. remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
  118. remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
  119. remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
  120. remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
  121. }
  122. add_action( 'admin_head-profile.php', 'srh25_remove_admin_color' );
  123. function srh25_remove_admin_color() {
  124. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  125. }
  126. add_filter('admin_footer_text', 'srh25_remove_admin_footer_text', 1000);
  127. function srh25_remove_admin_footer_text(){return '';}
  128. add_filter('update_footer', 'srh25_remove_admin_footer_upgrade', 1000);
  129. function srh25_remove_admin_footer_upgrade(){return '';}
  130. /***********************************************************
  131. ###################### Log In/Out ##########################
  132. ************************************************************/
  133. add_filter( 'login_headerurl', 'srh25_login_logo_url' );
  134. function srh25_login_logo_url() {
  135. return home_url();
  136. }
  137. add_filter( 'login_headertext', 'srh25_login_url_title' );
  138. function srh25_login_url_title() {
  139. return 'SRH Physicians';
  140. }
  141. add_action( 'login_enqueue_scripts', 'srh25_login_logo' );
  142. function srh25_login_logo() { ?>
  143. <style type="text/css">
  144. .login h1 a {
  145. background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/disc.png) !important;
  146. padding-bottom: 30px;
  147. }
  148. .wp-core-ui .button-primary {
  149. background: #4FB54F;
  150. border-color: #027643;
  151. }
  152. .login .message {
  153. border-left: 4px solid #027643;
  154. }
  155. .login form .forgetmenot label {
  156. display:none;
  157. }
  158. .login #backtoblog a {
  159. display:none;
  160. }
  161. </style>
  162. <?php }
  163. /***********************************************************
  164. ####################### Allow SVG ##########################
  165. ************************************************************/
  166. add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
  167. global $wp_version;
  168. if ( $wp_version !== '4.7.1' ) {
  169. return $data;
  170. }
  171. $filetype = wp_check_filetype( $filename, $mimes );
  172. return [
  173. 'ext' => $filetype['ext'],
  174. 'type' => $filetype['type'],
  175. 'proper_filename' => $data['proper_filename']
  176. ];
  177. }, 10, 4 );
  178. add_action( 'admin_head', 'fix_svg' );
  179. function cc_mime_types( $mimes ){
  180. $mimes['svg'] = 'image/svg+xml';
  181. return $mimes;
  182. }
  183. add_filter( 'upload_mimes', 'cc_mime_types' );
  184. function fix_svg() {
  185. echo '<style type="text/css">
  186. .attachment-266x266, .thumbnail img {
  187. width: 100% !important;
  188. height: auto !important;
  189. }
  190. </style>';
  191. }
  192. /***********************************************************
  193. #################### Edit Page Link ########################
  194. ************************************************************/
  195. function add_edit_link() {
  196. ob_start();
  197. 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' );
  198. return ob_get_clean();
  199. }
  200. add_action( 'init', 'add_edit_link_shortcode' );
  201. function add_edit_link_shortcode() {
  202. add_shortcode( 'edit-link', 'add_edit_link' );
  203. }
  204. /***********************************************************
  205. ################ Auto-Hide Navigation ######################
  206. ************************************************************/
  207. // Auto-Hide Navigation JavaScript - External File (jQuery Version)
  208. add_action( 'wp_enqueue_scripts', 'srh25_enqueue_navigation_script' );
  209. function srh25_enqueue_navigation_script() {
  210. // Option 1: Use separate JavaScript file (ACTIVE)
  211. wp_enqueue_script(
  212. 'srh-auto-hide-nav',
  213. get_stylesheet_directory_uri() . '/js/auto-hide-nav.js',
  214. array('jquery'),
  215. '1.0.0',
  216. true
  217. );
  218. }
  219. /***********************************************************
  220. #################### Off Canvas Menu #######################
  221. ************************************************************/
  222. // Register custom block category
  223. function srh_block_categories($categories) {
  224. return array_merge(
  225. [
  226. [
  227. 'slug' => 'srh-blocks',
  228. 'title' => 'SRH Blocks'
  229. ],
  230. ],
  231. $categories
  232. );
  233. }
  234. add_filter('block_categories_all', 'srh_block_categories', 10, 2);
  235. // Register the block
  236. function register_offcanvas_menu_block() {
  237. wp_register_script(
  238. 'srh-offcanvas-menu-editor',
  239. get_stylesheet_directory_uri() . '/blocks/offcanvas-menu/index.js',
  240. array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components', 'wp-i18n'),
  241. filemtime(get_stylesheet_directory() . '/blocks/offcanvas-menu/index.js')
  242. );
  243. register_block_type(get_stylesheet_directory() . '/blocks/offcanvas-menu', array(
  244. 'api_version' => 3,
  245. 'editor_script' => 'srh-offcanvas-menu-editor',
  246. 'render_callback' => 'render_offcanvas_menu'
  247. ));
  248. }
  249. add_action('init', 'register_offcanvas_menu_block', 5);
  250. // Frontend assets remain the same
  251. function enqueue_offcanvas_menu_assets() {
  252. wp_enqueue_style(
  253. 'offcanvas-menu-style',
  254. get_stylesheet_directory_uri() . '/css/offcanvas-menu.css',
  255. array(),
  256. '1.0.0'
  257. );
  258. wp_enqueue_script(
  259. 'offcanvas-menu',
  260. get_stylesheet_directory_uri() . '/js/offcanvas-menu.js',
  261. array('jquery'),
  262. '1.0.0',
  263. true
  264. );
  265. }
  266. add_action('wp_enqueue_scripts', 'enqueue_offcanvas_menu_assets');
  267. function render_offcanvas_menu($attributes, $content) {
  268. $pattern_content = do_blocks('<!-- wp:pattern {"slug":"srh/offcanvas-content"} /-->');
  269. return sprintf(
  270. '<div class="wp-block-srh-offcanvas-menu">
  271. <button class="hamburger-toggle" aria-label="Toggle Menu">
  272. <div class="hamburger-lines">
  273. <span></span>
  274. <span></span>
  275. <span></span>
  276. </div>
  277. <span class="menu-text">Menu</span>
  278. </button>
  279. <div class="offcanvas-menu">
  280. <div class="offcanvas-menu-inner">%s</div>
  281. </div>
  282. </div>',
  283. $pattern_content
  284. );
  285. }
  286. /***********************************************************
  287. ############### Disable External Blocks ####################
  288. ************************************************************/
  289. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
  290. add_filter('should_load_remote_block_patterns', '__return_false');
  291. add_filter('block_directory_enabled', '__return_false');
  292. add_filter( 'block_editor_settings_all', function( $settings, $context ) {
  293. $settings['enableOpenverseMediaCategory'] = false;
  294. return $settings;
  295. }, 10, 2 );
  296. /***********************************************************
  297. ############### Disable Some Blocks ########################
  298. ************************************************************/
  299. function srh25_deny_list_blocks() {
  300. wp_enqueue_script(
  301. 'deny-list-blocks',
  302. get_stylesheet_directory_uri() . '/js/deny-list-blocks.js',
  303. array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
  304. '1.0.1',
  305. true
  306. );
  307. }
  308. add_action('enqueue_block_editor_assets', 'srh25_deny_list_blocks' );
  309. /***********************************************************
  310. ############### Unregister Patterns ########################
  311. ************************************************************/
  312. function srh25_remove_core_patterns() {
  313. remove_theme_support( 'core-block-patterns' );
  314. }
  315. add_action( 'after_setup_theme', 'srh25_remove_core_patterns' );
  316. /***********************************************************
  317. ############### Hide JQuery Notice #########################
  318. ************************************************************/
  319. add_action('wp_default_scripts', function ($scripts) {
  320. if (!empty($scripts->registered['jquery'])) {
  321. $scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']);
  322. }
  323. });