/**
* Sage includes
*
* The $sage_includes array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*
* Please note that missing files will produce a fatal error.
*
* @link https://github.com/roots/sage/pull/1042
*/
$sage_includes = [
'lib/assets.php', // Scripts and stylesheets
'lib/extras.php', // Custom functions
'lib/setup.php', // Theme setup
'lib/titles.php', // Page titles
'lib/wrapper.php', // Theme wrapper class
'lib/customizer.php' // Theme customizer
];
foreach ($sage_includes as $file) {
if (!$filepath = locate_template($file)) {
trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR);
}
require_once $filepath;
}
unset($file, $filepath);
function get_asset($relativePath) {
return get_template_directory_uri().'/assets/'.$relativePath;
}
function get_svg($name){
return file_get_contents(get_template_directory_uri()."/assets/svg/".$name.".svg");
}
function the_svg($name){
echo get_svg($name);
}
function get_svg_icon($name){
return file_get_contents(get_template_directory_uri()."/assets/svg/icons/".$name.".svg");
}
function the_svg_icon($name){
echo get_svg_icon($name);
}
function the_button($field,$class=false){
set_query_var('btn_field',$field);
set_query_var('btn_class',$class);
get_template_part('templates/button');
}
function the_quote($quote){
set_query_var('quote',$quote);
get_template_part('templates/content','quote');
}
function button_shortcode($atts, $content=null){
$a = shortcode_atts( array(
'icon' => '',
'url' => '#',
'class' => '',
), $atts );
$button = array(
'text' => $content,
'type' => 'url',
'url' => $a['url'],
'icon' => $a['icon']
);
ob_start();
the_button($button,esc_attr($a['class']));
$the_button = ob_get_clean();
return $the_button;
}
add_shortcode('btn', 'button_shortcode');
function quote_shortcode($atts, $content=null){
$a = shortcode_atts( array(
'from' => '',
'class' => '',
), $atts );
$quote = array(
'content' => $content,
'from' => $a['from'],
'class' => $a['class']
);
ob_start();
the_quote($quote);
$the_quote = ob_get_clean();
return $the_quote;
}
add_shortcode('quote', 'quote_shortcode');
function custom_nav_classes( $classes, $item ) {
$classes[] = 'nav__item';
if (in_array('current-menu-item', $classes) ){
$classes[] = 'nav__item--current';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'custom_nav_classes', 10, 2 );
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
function get_gmaps_api_key() {
return 'AIzaSyDHdODI4k0_tpfVxmo1HC_0eMw3ACy74Cs';
}
function my_acf_google_map_api( $api ){
$api['key'] = get_gmaps_api_key();
return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
function add_cpt_author( $query ) {
if ( !is_admin() && $query->is_author() && $query->is_main_query() ) {
$query->set( 'post_type', array('post', 'news' ) );
}
}
add_action( 'pre_get_posts', 'add_cpt_author' );
function br2sp($string) {
return preg_replace('/\
/i', " ", $string);
}
function check_url_target($url) {
// Abort if parameter URL is empty
if( empty($url) ) {
return false;
}
// Parse home URL and parameter URL
$link_url = parse_url( $url );
$home_url = parse_url( home_url() ); // Works for WordPress
//$home_url = parse_url( $_SERVER['HTTP_HOST'] );
// Decide on target
if( $url[0] == '#' || $link_url['host'] == $home_url['host'] ) {
return 'int';
} else {
return 'ext';
}
}