/* Theme Name: Whiteraysoft Technologies Theme URI: https://butlershealthcare.com Author: Whiteraysoft Technologies Author URI: https://www.whiteraysofttechnologies.net Description: Custom WordPress theme for Butlers Healthcare & Staffing, rebuilt from the static site using Divi-compatible markup, custom navigation, contact form handler and auto-created pages. Version: 1.0.0 License: GPL v2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Text Domain: whiteraysoft */ if ( ! defined( 'ABSPATH' ) ) { exit; } define( 'WHITERAYSOFT_VERSION', '1.0.0' ); define( 'WHITERAYSOFT_ASSETS_URI', get_template_directory_uri() . '/assets' ); if ( ! function_exists( 'whiteraysoft_setup' ) ) : function whiteraysoft_setup() { load_theme_textdomain( 'whiteraysoft', get_template_directory() . '/languages' ); add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'post-thumbnails' ); add_theme_support( 'custom-logo', array( 'height' => 80, 'width' => 280, 'flex-height' => true, 'flex-width' => true, ) ); add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', ) ); register_nav_menus( array( 'primary' => esc_html__( 'Primary Menu', 'whiteraysoft' ), 'footer' => esc_html__( 'Footer Menu', 'whiteraysoft' ), ) ); } endif; add_action( 'after_setup_theme', 'whiteraysoft_setup' ); function whiteraysoft_content_width() { $GLOBALS['content_width'] = apply_filters( 'whiteraysoft_content_width', 1080 ); } add_action( 'after_setup_theme', 'whiteraysoft_content_width', 0 ); function whiteraysoft_enqueue_assets() { wp_enqueue_style( 'whiteraysoft-fonts', 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800|Montserrat:100,200,300,400,500,600,700,800,900|Lobster&display=swap', array(), null ); wp_enqueue_style( 'whiteraysoft-style', get_stylesheet_uri(), array(), WHITERAYSOFT_VERSION ); wp_enqueue_style( 'whiteraysoft-main', WHITERAYSOFT_ASSETS_URI . '/css/main.css', array( 'whiteraysoft-style' ), WHITERAYSOFT_VERSION ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'whiteraysoft-nav-active', WHITERAYSOFT_ASSETS_URI . '/js/nav-active.js', array(), WHITERAYSOFT_VERSION, true ); wp_enqueue_script( 'whiteraysoft-main', WHITERAYSOFT_ASSETS_URI . '/js/main.js', array( 'jquery' ), WHITERAYSOFT_VERSION, true ); } add_action( 'wp_enqueue_scripts', 'whiteraysoft_enqueue_assets' ); function whiteraysoft_fallback_nav_menu() { $pages = array( 'home' => __( 'Home', 'whiteraysoft' ), 'our-services' => __( 'Our Services', 'whiteraysoft' ), 'why-us' => __( 'Why Us', 'whiteraysoft' ), 'about-us' => __( 'About Us', 'whiteraysoft' ), 'employment' => __( 'Employment', 'whiteraysoft' ), 'contact' => __( 'Contact Us', 'whiteraysoft' ), ); echo ''; } function whiteraysoft_handle_contact() { if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'whiteraysoft_nonce' ) ) { $redirect = add_query_arg( 'contact', 'error', home_url( '/contact' ) ); wp_safe_redirect( $redirect ); exit; } $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; $phone = isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : ''; $subject = isset( $_POST['subject'] ) ? sanitize_text_field( wp_unslash( $_POST['subject'] ) ) : ''; $message = isset( $_POST['message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['message'] ) ) : ''; if ( empty( $name ) || empty( $email ) || empty( $message ) ) { $redirect = add_query_arg( 'contact', 'error', home_url( '/contact' ) ); wp_safe_redirect( $redirect ); exit; } if ( isset( $_POST['captcha_answer'], $_POST['captcha_expected'] ) ) { $expected = (int) $_POST['captcha_expected']; $given = (int) $_POST['captcha_answer']; if ( $expected !== $given ) { $redirect = add_query_arg( 'contact', 'captcha', home_url( '/contact' ) ); wp_safe_redirect( $redirect ); exit; } } $to = get_option( 'admin_email' ); $mail_subject = sprintf( '[%s] %s', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $subject ); $body = sprintf( "Name: %s\nEmail: %s\nPhone: %s\n\nMessage:\n%s", $name, $email, $phone, $message ); $headers = array( 'Reply-To: ' . $name . ' <' . $email . '>', 'Content-Type: text/plain; charset=UTF-8', ); $sent = wp_mail( $to, $mail_subject, $body, $headers ); $status = $sent ? 'sent' : 'error'; $redirect = add_query_arg( 'contact', $status, home_url( '/contact' ) ); wp_safe_redirect( $redirect ); exit; } add_action( 'admin_post_whiteraysoft_contact', 'whiteraysoft_handle_contact' ); add_action( 'admin_post_nopriv_whiteraysoft_contact', 'whiteraysoft_handle_contact' ); function whiteraysoft_create_pages() { $pages = array( array( 'title' => 'Home', 'slug' => 'home', 'template' => 'front-page.php', ), array( 'title' => 'About Us', 'slug' => 'about-us', 'template' => 'page-about-us.php', ), array( 'title' => 'Our Services', 'slug' => 'our-services', 'template' => 'page-our-services.php', ), array( 'title' => 'Our Gallery', 'slug' => 'our-gallery', 'template' => 'page-our-gallery.php', ), array( 'title' => 'Contact', 'slug' => 'contact', 'template' => 'page-contact.php', ), ); foreach ( $pages as $p ) { $existing = get_posts( array( 'post_type' => 'page', 'name' => $p['slug'], 'posts_per_page' => 1, 'post_status' => array( 'publish', 'draft', 'private', 'trash', 'pending', 'future' ), ) ); if ( ! empty( $existing ) ) { $page_id = $existing[0]->ID; } else { $page_id = wp_insert_post( array( 'post_title' => $p['title'], 'post_name' => $p['slug'], 'post_status' => 'publish', 'post_type' => 'page', 'post_content'=> '', ) ); } if ( $page_id && ! is_wp_error( $page_id ) && ! empty( $p['template'] ) ) { update_post_meta( $page_id, '_wp_page_template', $p['template'] ); } } $home = get_page_by_path( 'home' ); if ( $home ) { update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $home->ID ); } } add_action( 'after_switch_theme', 'whiteraysoft_create_pages' ); function whiteraysoft_maybe_create_pages() { if ( ! get_option( 'whiteraysoft_pages_created' ) ) { whiteraysoft_create_pages(); update_option( 'whiteraysoft_pages_created', '1' ); } } add_action( 'admin_init', 'whiteraysoft_maybe_create_pages' ); function whiteraysoft_widgets_init() { register_sidebar( array( 'name' => esc_html__( 'Sidebar', 'whiteraysoft' ), 'id' => 'sidebar-1', 'description' => esc_html__( 'Main sidebar.', 'whiteraysoft' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'whiteraysoft_widgets_init' ); function whiteraysoft_contact_status_notice() { if ( ! isset( $_GET['contact'] ) ) { return; } $status = sanitize_text_field( wp_unslash( $_GET['contact'] ) ); $messages = array( 'sent' => array( 'success', __( 'Thank you! Your message has been sent.', 'whiteraysoft' ) ), 'error' => array( 'error', __( 'There was an error sending your message. Please try again.', 'whiteraysoft' ) ), 'captcha' => array( 'error', __( 'Captcha answer was incorrect.', 'whiteraysoft' ) ), ); if ( ! isset( $messages[ $status ] ) ) { return; } list( $type, $text ) = $messages[ $status ]; printf( '
%s
', esc_attr( $type ), esc_html( $text ) ); }