Created
May 13, 2021 15:33
-
-
Save 465media/4fbeb544505e7d291cd830d45d1e073e to your computer and use it in GitHub Desktop.
Barriciad Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* barricaid functions and definitions | |
* | |
* @link https://developer.wordpress.org/themes/basics/theme-functions/ | |
* | |
* @package barricaid | |
*/ | |
use Barricaid\App; | |
if ( ! function_exists( 'barricaid_setup' ) ) : | |
/** | |
* Sets up theme defaults and registers support for various WordPress features. | |
* | |
* Note that this function is hooked into the after_setup_theme hook, which | |
* runs before the init hook. The init hook is too late for some features, such | |
* as indicating support for post thumbnails. | |
*/ | |
function barricaid_setup() { | |
/* | |
* Make theme available for translation. | |
* Translations can be filed in the /languages/ directory. | |
* If you're building a theme based on barricaid, use a find and replace | |
* to change 'barricaid' to the name of your theme in all the template files. | |
*/ | |
load_theme_textdomain( 'barricaid', get_template_directory() . '/languages' ); | |
// Add default posts and comments RSS feed links to head. | |
add_theme_support( 'automatic-feed-links' ); | |
/* | |
* Let WordPress manage the document title. | |
* By adding theme support, we declare that this theme does not use a | |
* hard-coded <title> tag in the document head, and expect WordPress to | |
* provide it for us. | |
*/ | |
add_theme_support( 'title-tag' ); | |
/* | |
* Enable support for Post Thumbnails on posts and pages. | |
* | |
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ | |
*/ | |
add_theme_support( 'post-thumbnails' ); | |
register_nav_menus( array( | |
'menu-1' => esc_html__( 'Primary', 'barricaid' ), | |
'menu-2' => esc_html__( 'Secondary', 'barricaid' ), | |
'menu-footer' => esc_html__( 'Footer', 'barricaid' ), | |
) ); | |
//Full width hero image. Aspect Ratio: 1.99445983:1.0 | |
add_image_size( '1440x722', 1440, 722, array( 'center', 'center' ) ); | |
add_image_size( '768x385', 768, 385, array( 'center', 'center' ) ); | |
add_image_size( '400x200', 400, 200, array( 'center', 'center' ) ); | |
//Default page header image size. Aspect ratio: 2.72093023:1.0 | |
add_image_size( '1170x430', 1170, 430, array( 'center', 'center' ) ); | |
//Default mobile page header size. Aspect ratio 1.79310345:1.0 | |
add_image_size( '768x428', 768, 428, array( 'center', 'center' ) ); | |
// Square image size for news archive and single | |
add_image_size( '720x720', 720, 720, array( 'center', 'center' ) ); | |
/* | |
* Switch default core markup for search form, comment form, and comments | |
* to output valid HTML5. | |
*/ | |
add_theme_support( 'html5', array( | |
'search-form', | |
'comment-form', | |
'comment-list', | |
'gallery', | |
'caption', | |
) ); | |
// Set up the WordPress core custom background feature. | |
add_theme_support( 'custom-background', apply_filters( 'barricaid_custom_background_args', array( | |
'default-color' => 'ffffff', | |
'default-image' => '', | |
) ) ); | |
// Add theme support for selective refresh for widgets. | |
add_theme_support( 'customize-selective-refresh-widgets' ); | |
/** | |
* Add support for core custom logo. | |
* | |
* @link https://codex.wordpress.org/Theme_Logo | |
*/ | |
add_theme_support( 'custom-logo', array( | |
'height' => 250, | |
'width' => 250, | |
'flex-width' => true, | |
'flex-height' => true, | |
) ); | |
} | |
endif; | |
add_action( 'after_setup_theme', 'barricaid_setup' ); | |
/** | |
* Set the content width in pixels, based on the theme's design and stylesheet. | |
* | |
* Priority 0 to make it available to lower priority callbacks. | |
* | |
* @global int $content_width | |
*/ | |
function barricaid_content_width() { | |
// This variable is intended to be overruled from themes. | |
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}. | |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound | |
$GLOBALS['content_width'] = apply_filters( 'barricaid_content_width', 640 ); | |
} | |
add_action( 'after_setup_theme', 'barricaid_content_width', 0 ); | |
/** | |
* Register widget area. | |
* | |
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar | |
*/ | |
function barricaid_widgets_init() { | |
register_sidebar( array( | |
'name' => esc_html__( 'Sidebar', 'barricaid' ), | |
'id' => 'sidebar-1', | |
'description' => esc_html__( 'Add widgets here.', 'barricaid' ), | |
'before_widget' => '<section id="%1$s" class="widget %2$s">', | |
'after_widget' => '</section>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
} | |
add_action( 'widgets_init', 'barricaid_widgets_init' ); | |
/** | |
* Enqueue scripts and styles. | |
*/ | |
function barricaid_scripts() { | |
wp_register_style( 'rubik-font', 'https://fonts.googleapis.com/css?family=Rubik:300,400,500,700&display=swap', array() ); | |
wp_enqueue_style( 'barricaid-style', get_stylesheet_uri() ); | |
wp_enqueue_style( 'barricaid-vendor', get_stylesheet_directory_uri() . '/dist/js/vendor.css'); | |
wp_enqueue_style( 'barricaid-custom', get_stylesheet_directory_uri() . '/dist/css/style.css', array( 'rubik-font' ) ); | |
wp_enqueue_script( 'barricaid-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true ); | |
wp_enqueue_script( 'barricaid-custom', get_template_directory_uri() . '/js/custom.js', array('jquery'), '20151215', true ); | |
wp_enqueue_script( 'barricaid-bundle', get_stylesheet_directory_uri() . '/dist/js/app.js', array( 'jquery' ), false, true ); | |
wp_enqueue_script( 'barricaid-vendor-bundle', get_stylesheet_directory_uri() . '/dist/js/vendor.js', array( 'jquery' ), false, true ); | |
wp_enqueue_script( 'barricaid-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true ); | |
wp_enqueue_script( 'fontawesome', '//kit.fontawesome.com/dcebb50704.js', array(), null, true ); | |
if ( function_exists( 'gravity_form_enqueue_scripts' ) ) { | |
gravity_form_enqueue_scripts( 1, 'is_ajax' ); | |
} | |
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | |
wp_enqueue_script( 'comment-reply' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'barricaid_scripts', 100 ); | |
/** | |
* Implement the Custom Header feature. | |
*/ | |
require get_template_directory() . '/inc/custom-header.php'; | |
/** | |
* Custom template tags for this theme. | |
*/ | |
require get_template_directory() . '/inc/template-tags.php'; | |
/** | |
* Functions which enhance the theme by hooking into WordPress. | |
*/ | |
require get_template_directory() . '/inc/template-functions.php'; | |
/** | |
* Customizer additions. | |
*/ | |
require get_template_directory() . '/inc/customizer.php'; | |
require get_template_directory() . '/inc/class-theme.php'; | |
/** | |
* Load Jetpack compatibility file. | |
*/ | |
if ( defined( 'JETPACK__VERSION' ) ) { | |
require get_template_directory() . '/inc/jetpack.php'; | |
} | |
/** | |
* WP Store Locator - Additional Fields | |
*/ | |
add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_fields' ); | |
function custom_meta_box_fields( $meta_fields ) { | |
$meta_fields[__( 'Additional Information', 'wpsl' )] = array( | |
'phone' => array( | |
'label' => __( 'Tel', 'wpsl' ) | |
), | |
'fax' => array( | |
'label' => __( 'Fax', 'wpsl' ) | |
), | |
'email' => array( | |
'label' => __( 'Email', 'wpsl' ) | |
), | |
'url' => array( | |
'label' => __( 'Url', 'wpsl' ) | |
), | |
'appointment_url' => array( | |
'label' => __( 'Appointment URL', 'wpsl' ) | |
), | |
'surgeon_name' => array( | |
'label' => __( 'Surgeon Name', 'wpsl' ) | |
) | |
); | |
return $meta_fields; | |
} | |
add_filter( 'wpsl_frontend_meta_fields', 'custom_frontend_meta_fields' ); | |
function custom_frontend_meta_fields( $store_fields ) { | |
$store_fields['wpsl_appointment_url'] = array( | |
'name' => 'appointment_url', | |
'type' => 'url' | |
); | |
$store_fields['wpsl_surgeon_name'] = array( | |
'name' => 'surgeon_name', | |
'type' => 'text' | |
); | |
return $store_fields; | |
} | |
add_filter( 'wpsl_listing_template', 'custom_listing_template' ); | |
function custom_listing_template() { | |
global $wpsl_settings; | |
$listing_template = '<li data-store-id="<%= id %>">' . "\r\n"; | |
$listing_template .= "\t\t" . '<div>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . wpsl_store_header_template( 'listing' ) . "\r\n"; | |
$listing_template .= "\t\t\t" . '<p><%= thumb %>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<span class="wpsl-surgeon"><%= surgeon_name %></span>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<span class="wpsl-phone"><a href="tel:<%= phone %>"><%= phone %></a></span>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<span class="wpsl-street"><%= address %></span>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<% if ( address2 ) { %>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<span class="wpsl-street"><%= address2 %></span>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<% } %>' . "\r\n"; | |
$listing_template .= "\t\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n"; | |
// Check if the 'appointment_url' contains data before including it. | |
$listing_template .= "\t\t\t" . '<div id="link-sect"><% if ( appointment_url ) { %>' . "\r\n"; | |
$listing_template .= "\t\t\t" . '<br><a href="<%= appointment_url %>" target=blank">' . __( 'Schedule a Consultation', 'wpsl' ) . '</a></div>' . "\r\n"; | |
$listing_template .= "\t\t\t" . '<% } %>' . "\r\n"; | |
// Check if we need to show the distance. | |
if ( !$wpsl_settings['hide_distance'] ) { | |
$listing_template .= "\t\t" . '<%= distance %> ' . esc_html( $wpsl_settings['distance_unit'] ) . '' . "\r\n"; | |
} | |
$listing_template .= "\t\t" . '<%= createDirectionUrl() %>' . "\r\n"; | |
$listing_template .= "\t" . '</li>' . "\r\n"; | |
$listing_template .= "\t\t\t" . '</p>' . "\r\n"; | |
$listing_template .= "\t\t" . '</div>' . "\r\n"; | |
return $listing_template; | |
} | |
add_filter( 'wpsl_store_header_template', 'custom_store_header_template' ); | |
function custom_store_header_template() { | |
$header_template = '<% if ( wpslSettings.storeUrl == 1 && url ) { %>' . "\r\n"; | |
$header_template .= '<h3><a href="<%= url %>"><%= store %></a></h3>' . "\r\n"; | |
$header_template .= '<% } else { %>' . "\r\n"; | |
$header_template .= '<h3><%= store %></h3>' . "\r\n"; | |
$header_template .= '<% } %>'; | |
return $header_template; | |
} | |
add_filter( 'wpsl_thumb_size', 'custom_thumb_size' ); | |
function custom_thumb_size() { | |
$size = array( 100, 100 ); | |
return $size; | |
} | |
add_filter( 'wpsl_store_data', 'custom_result_sort' ); | |
function custom_result_sort( $store_meta ) { | |
$custom_sort = array(); | |
foreach ( $store_meta as $key => $row ) { | |
$custom_sort[$key] = $row['fax']; | |
} | |
array_multisort( $custom_sort, SORT_DESC, SORT_REGULAR, $store_meta ); | |
return $store_meta; | |
} | |
add_filter( 'wpsl_info_window_template', 'custom_info_window_template' ); | |
function custom_info_window_template() { | |
global $wpsl_settings, $wpsl; | |
$info_window_template = '<div data-store-id="<%= id %>" class="wpsl-info-window">' . "\r\n"; | |
$info_window_template .= "\t\t" . '<p>' . "\r\n"; | |
$info_window_template .= "\t\t" . '<% if ( surgeon_name ) { %>' . "\r\n"; | |
$info_window_template .= "\t\t" . '<span class="window_name"><%= surgeon_name %></span>' . "\r\n"; | |
$info_window_template .= "\t\t" . '<% } %>' . "\r\n"; | |
$info_window_template .= "\t\t\t" . '<span><%= address %></span>' . "\r\n"; | |
$info_window_template .= "\t\t\t" . '<% if ( address2 ) { %>' . "\r\n"; | |
$info_window_template .= "\t\t\t" . '<span><%= address2 %></span>' . "\r\n"; | |
$info_window_template .= "\t\t\t" . '<% } %>' . "\r\n"; | |
$info_window_template .= "\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n"; | |
$info_window_template .= "\t\t" . '</p>' . "\r\n"; | |
/** | |
* Include the data from a custom field called 'my_textinput'. | |
* | |
* Before you can access the 'my_textinput' data in the template, | |
* you first need to make sure the data is included in the JSON output. | |
* | |
* You can make the data accessible through the wpsl_frontend_meta_fields filter. | |
*/ | |
$info_window_template .= "\t\t" . '<%= createInfoWindowActions( id ) %>' . "\r\n"; | |
$info_window_template .= "\t" . '</div>' . "\r\n"; | |
return $info_window_template; | |
} | |
add_filter( 'wpsl_admin_marker_dir', 'custom_admin_marker_dir' ); | |
function custom_admin_marker_dir() { | |
$admin_marker_dir = get_stylesheet_directory() . '/wpsl-markers/'; | |
return $admin_marker_dir; | |
} | |
define( 'WPSL_MARKER_URI', dirname( get_bloginfo( 'stylesheet_url') ) . '/wpsl-markers/' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment