123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- <?php
- /**
- * Additional logging in WordPress 6.1+ that generates the following
- * message regarding cron schedules:
- *
- * Cron reschedule event error for hook:
- * action_scheduler_run_queue,
- * Error code: invalid_schedule,
- * Error message: Event schedule does not exist.,
- * Data: {"schedule":"every_minute","args":,"interval":60}
- *
- * This function needs to fire prior to loading Action Scheduler as its a
- * pre-requisite for it to schedule our tasks.
- *
- * This filter seeks to manually add the schedule to the list of schedules to
- * address this bug.
- */
- add_filter('cron_schedules', function ($schedules) {
- $schedules = [
- 'interval' => 60,
- 'display' => 'Every Minute',
- ];
- return $schedules;
- });
- /***********************************************************
- ############### REST API and Iframe Support ################
- ************************************************************/
- // Add REST API and iframe communication support
- add_action('after_setup_theme', 'srh25_setup_theme_support');
- function srh25_setup_theme_support() {
- add_theme_support('editor-styles');
- add_theme_support('responsive-embeds');
- add_theme_support('custom-units');
-
- // Ensure proper communication for block editor
- if (is_admin()) {
- add_filter('allowed_http_origins', 'srh25_allow_local_origins');
- }
- }
- function srh25_allow_local_origins($origins) {
- $origins[] = home_url();
- return array_unique($origins);
- }
- // Add headers for iframe communication
- add_action('send_headers', 'srh25_add_frame_headers');
- function srh25_add_frame_headers() {
- if (is_admin()) {
- header('Access-Control-Allow-Origin: ' . esc_url(home_url()));
- header('Access-Control-Allow-Credentials: true');
- }
- }
- /***********************************************************
- #################### SRH Theme #############################
- ************************************************************/
- //add_action( 'wp_enqueue_scripts', 'twenty_five_enqueue_styles' );
- function twenty_five_enqueue_styles() {
- wp_enqueue_style( '2025-style', get_parent_theme_file_uri( 'style.css' ));
- }
- add_action( 'wp_enqueue_scripts', 'srh25_enqueue_styles' );
- function srh25_enqueue_styles() {
- wp_enqueue_style( 'srh-style', get_stylesheet_uri() );
- }
- // Registers pattern categories.
- add_action( 'init', 'srh25_pattern_categories' );
- function srh25_pattern_categories() {
- register_block_pattern_category(
- 'srh25_page',
- array(
- 'label' => __( 'Pages', 'srh25' ),
- 'description' => __( 'A collection of full page layouts.', 'srh25' ),
- )
- );
- }
- /***********************************************************
- ###################### Admin Clean #########################
- ************************************************************/
- add_filter('gettext', 'srh25_change_howdy', 10, 3);
- function srh25_change_howdy($translated, $text, $domain) {
- if (false !== strpos($translated, 'Howdy,'))
- return str_replace('Howdy,', '', $translated);
- return $translated;
- }
- add_filter( 'gettext', 'srh25_change_howdy_text_email', 10, 2 );
- function srh25_change_howdy_text_email( $translation, $original ) {
- if( 'Howdy, %1$s' == $original )
- $translation = '%1$s';
- return $translation;
- }
- add_filter( 'show_admin_bar', '__return_false' );
- add_action( 'admin_bar_menu', 'srh25_admin_bar', 999 );
- function srh25_admin_bar( $wp_admin_bar ) {
- //$wp_admin_bar->remove_menu('my-account');
- //$wp_admin_bar->remove_menu( 'edit' );
- //$wp_admin_bar->remove_menu('site-name');
- $wp_admin_bar->remove_node('wp-logo');
- $wp_admin_bar->remove_node('themes');
- $wp_admin_bar->remove_node('widgets');
- $wp_admin_bar->remove_node('menus');
- $wp_admin_bar->remove_node('new-media');
- $wp_admin_bar->remove_menu('edit-profile');
- $wp_admin_bar->remove_menu('comments');
- $wp_admin_bar->remove_menu('about');
- $wp_admin_bar->remove_menu('wporg');
- $wp_admin_bar->remove_menu('documentation');
- $wp_admin_bar->remove_menu('support-forums');
- $wp_admin_bar->remove_menu('feedback');
- $wp_admin_bar->remove_menu('customize');
- $wp_admin_bar->remove_menu('view-site');
- $wp_admin_bar->remove_menu('updates');
- $wp_admin_bar->remove_menu('comments');
- $wp_admin_bar->remove_menu('new-content');
- $wp_admin_bar->remove_menu('view');
- }
- add_action( 'admin_init', 'srh25_remove_dashboard_meta' );
- function srh25_remove_dashboard_meta() {
- remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
- remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
- remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
- remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
- remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
- remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
- }
- add_action( 'admin_head-profile.php', 'srh25_remove_admin_color' );
- function srh25_remove_admin_color() {
- remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
- }
- add_filter('admin_footer_text', 'srh25_remove_admin_footer_text', 1000);
- function srh25_remove_admin_footer_text(){return '';}
- add_filter('update_footer', 'srh25_remove_admin_footer_upgrade', 1000);
- function srh25_remove_admin_footer_upgrade(){return '';}
- /***********************************************************
- ###################### Log In/Out ##########################
- ************************************************************/
- add_filter( 'login_headerurl', 'srh25_login_logo_url' );
- function srh25_login_logo_url() {
- return home_url();
- }
- add_filter( 'login_headertext', 'srh25_login_url_title' );
- function srh25_login_url_title() {
- return 'SRH Physicians';
- }
- add_action( 'login_enqueue_scripts', 'srh25_login_logo' );
- function srh25_login_logo() { ?>
- <style type="text/css">
- .login h1 a {
- background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/disc.png) !important;
- padding-bottom: 30px;
- }
- .wp-core-ui .button-primary {
- background: #4FB54F;
- border-color: #027643;
- }
- .login .message {
- border-left: 4px solid #027643;
- }
- .login form .forgetmenot label {
- display:none;
- }
- .login #backtoblog a {
- display:none;
- }
- </style>
- <?php }
- /***********************************************************
- ####################### Allow SVG ##########################
- ************************************************************/
- add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
- global $wp_version;
- if ( $wp_version !== '4.7.1' ) {
- return $data;
- }
- $filetype = wp_check_filetype( $filename, $mimes );
- return [
- 'ext' => $filetype['ext'],
- 'type' => $filetype['type'],
- 'proper_filename' => $data['proper_filename']
- ];
- }, 10, 4 );
- add_action( 'admin_head', 'fix_svg' );
- function cc_mime_types( $mimes ){
- $mimes['svg'] = 'image/svg+xml';
- return $mimes;
- }
- add_filter( 'upload_mimes', 'cc_mime_types' );
- function fix_svg() {
- echo '<style type="text/css">
- .attachment-266x266, .thumbnail img {
- width: 100% !important;
- height: auto !important;
- }
- </style>';
- }
-
- /***********************************************************
- #################### Edit Page Link ########################
- ************************************************************/
- function add_edit_link() {
- ob_start();
- 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' );
- return ob_get_clean();
- }
- add_action( 'init', 'add_edit_link_shortcode' );
- function add_edit_link_shortcode() {
- add_shortcode( 'edit-link', 'add_edit_link' );
- }
- /***********************************************************
- ################ Auto-Hide Navigation ######################
- ************************************************************/
- // Auto-Hide Navigation JavaScript - External File (jQuery Version)
- add_action( 'wp_enqueue_scripts', 'srh25_enqueue_navigation_script' );
- function srh25_enqueue_navigation_script() {
- // Option 1: Use separate JavaScript file (ACTIVE)
- wp_enqueue_script(
- 'srh-auto-hide-nav',
- get_stylesheet_directory_uri() . '/js/auto-hide-nav.js',
- array('jquery'),
- '1.0.0',
- true
- );
- }
- /***********************************************************
- #################### Off Canvas Menu #######################
- ************************************************************/
- // Register custom block category
- function srh_block_categories($categories) {
- return array_merge(
- [
- [
- 'slug' => 'srh-blocks',
- 'title' => 'SRH Blocks'
- ],
- ],
- $categories
- );
- }
- add_filter('block_categories_all', 'srh_block_categories', 10, 2);
- // Register the block
- function register_offcanvas_menu_block() {
- wp_register_script(
- 'srh-offcanvas-menu-editor',
- get_stylesheet_directory_uri() . '/blocks/offcanvas-menu/index.js',
- array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components', 'wp-i18n'),
- filemtime(get_stylesheet_directory() . '/blocks/offcanvas-menu/index.js')
- );
- register_block_type(get_stylesheet_directory() . '/blocks/offcanvas-menu', array(
- 'api_version' => 3,
- 'editor_script' => 'srh-offcanvas-menu-editor',
- 'render_callback' => 'render_offcanvas_menu'
- ));
- }
- add_action('init', 'register_offcanvas_menu_block', 5);
- // Frontend assets remain the same
- function enqueue_offcanvas_menu_assets() {
- wp_enqueue_style(
- 'offcanvas-menu-style',
- get_stylesheet_directory_uri() . '/css/offcanvas-menu.css',
- array(),
- '1.0.0'
- );
-
- wp_enqueue_script(
- 'offcanvas-menu',
- get_stylesheet_directory_uri() . '/js/offcanvas-menu.js',
- array('jquery'),
- '1.0.0',
- true
- );
- }
- add_action('wp_enqueue_scripts', 'enqueue_offcanvas_menu_assets');
- function render_offcanvas_menu($attributes, $content) {
- $pattern_content = do_blocks('<!-- wp:pattern {"slug":"srh/offcanvas-content"} /-->');
-
- return sprintf(
- '<div class="wp-block-srh-offcanvas-menu">
- <button class="hamburger-toggle" aria-label="Toggle Menu">
- <div class="hamburger-lines">
- <span></span>
- <span></span>
- <span></span>
- </div>
- <span class="menu-text">Menu</span>
- </button>
- <div class="offcanvas-menu">
- <div class="offcanvas-menu-inner">%s</div>
- </div>
- </div>',
- $pattern_content
- );
- }
- /***********************************************************
- ############### Disable External Blocks ####################
- ************************************************************/
- remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
- add_filter('should_load_remote_block_patterns', '__return_false');
- add_filter('block_directory_enabled', '__return_false');
- add_filter( 'block_editor_settings_all', function( $settings, $context ) {
- $settings['enableOpenverseMediaCategory'] = false;
- return $settings;
- }, 10, 2 );
- /***********************************************************
- ############### Disable Some Blocks ########################
- ************************************************************/
- function srh25_deny_list_blocks() {
- wp_enqueue_script(
- 'deny-list-blocks',
- get_stylesheet_directory_uri() . '/js/deny-list-blocks.js',
- array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
- '1.0.1',
- true
- );
- }
- add_action('enqueue_block_editor_assets', 'srh25_deny_list_blocks' );
- /***********************************************************
- ############### Unregister Patterns ########################
- ************************************************************/
- function srh25_remove_core_patterns() {
- remove_theme_support( 'core-block-patterns' );
- }
- add_action( 'after_setup_theme', 'srh25_remove_core_patterns' );
- /***********************************************************
- ############### Hide JQuery Notice #########################
- ************************************************************/
- add_action('wp_default_scripts', function ($scripts) {
- if (!empty($scripts->registered['jquery'])) {
- $scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']);
- }
- });
|