<?php
/**
 * Child theme functions
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development
 * and http://codex.wordpress.org/Child_Themes), you can override certain
 * functions (those wrapped in a function_exists() call) by defining them first
 * in your child theme's functions.php file. The child theme's functions.php
 * file is included before the parent theme's file, so the child theme
 * functions would be used.
 *
 * Text Domain: wpex
 * @link http://codex.wordpress.org/Plugin_API
 *
 */

/**
 * Load the parent style.css file
 *
 * @link http://codex.wordpress.org/Child_Themes
 */
function total_child_enqueue_parent_theme_style() {

	// Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
	$theme   = wp_get_theme( 'Total' );
	$version = $theme->get( 'Version' );

	// Load the stylesheet
	wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css', array(), $version );
	
}
add_action( 'wp_enqueue_scripts', 'total_child_enqueue_parent_theme_style' );

/**
 * Per-post FAQ repeater metabox + FAQPage schema.
 */
require_once get_stylesheet_directory() . '/inc/post-faq.php';


//Classis Editor Appoarch using Total Theme Setup
//Hide WPBakery Admin Bar 
function vc_remove_wp_admin_bar_button() {
  remove_action( 'admin_bar_menu', array( vc_frontend_editor(), 'adminBarEditLink' ), 1000 );
}
add_action( 'vc_after_init', 'vc_remove_wp_admin_bar_button' );

//Hide GTB switch
add_action('admin_head', 'i_love_classic_editor');

function i_love_classic_editor() {
  echo '<style>
   body .composer-switch a.wpb_switch-to-gutenberg {
      display:none;
	  }
    } 
  </style>';
}
//Disable gutenberg for posts
add_filter('use_block_editor_for_post', '__return_false', 10);

//Disable gutenberg for post types
add_filter('use_block_editor_for_post_type', '__return_false', 10);

add_filter('vc_gitem_template_attribute_author_image', 'vc_gitem_template_attribute_author_image', 10, 2);
function vc_gitem_template_attribute_author_image($value, $data){
  extract(array_merge(array(
    'post' => null,
    'data' => '',
  ), $data));

  $name = get_the_author_meta('display_name', $post->post_author);
  $avatar = get_avatar_url($post->post_author);

  $image = '<div class="post-author" style="
    display: inline-block;
    border-radius: 50%;
    overflow: hidden;
    width: 60px;
    -webkit-box-shadow: 2px 2px 10px 0 rgba(0,0,0,0.1);
    box-shadow: 2px 2px 10px 0 rgba(0,0,0,0.1);
    height: 60px;"><img src="' . $avatar . '" alt="' . $name . '"/></div>';

  return $image;
} 

//Display blog author image
add_shortcode( 'bw_post_author', 'bw_post_author' );
function bw_post_author( $atts ) {
  return '{{ author_image }}';
}



// Sample function showing how to tweak the metaboxes display for post types
add_filter( 'wpex_main_metaboxes_post_types', function( $types ) {

  // Add to my custom-type post type
  $types[] = 'project, client, l';

  // Remove from blog posts
  unset( $types['staff'] );

  // Return post types array
  return $types;
  
}, 40 );

/* Featured Image for Page Header Image */
function my_page_header_background_image( $image ) {
	if ( has_post_thumbnail() && is_page() || ( has_post_thumbnail() && is_singular('project') ) ) {
		$image = get_post_thumbnail_id();
	}
	return $image;
}
add_filter( 'wpex_header_background_image', 'my_page_header_background_image' );

/* add anchor confirm */
add_filter( 'gform_confirmation_anchor', '__return_true' );

// Move page header title area into site header wrap
add_action( 'init', function() {

	// Remove page header title from default hook
	remove_action( 'wpex_hook_main_top', 'wpex_page_header', 10 );

	// Insert page header title into the site header at the very bottom
	add_action( 'wpex_hook_header_bottom', 'wpex_page_header', PHP_INT_MAX );

} );

// remove page header on landing pages
function disable_product_title( $return ) {
    if ( is_singular( 'l' ) ) {
        return false;
    } else {
        return $return;
    }
}
add_filter( 'wpex_display_page_header', 'disable_product_title' );