<?php
/**
 * Theme Functions
 *
 * @package Betheme
 * @author Muffin group
 * @link http://muffingroup.com
 */


define( 'THEME_DIR', get_template_directory() );
define( 'THEME_URI', get_template_directory_uri() );

define( 'THEME_NAME', 'betheme' );
define( 'THEME_VERSION', '15.3' );

define( 'LIBS_DIR', THEME_DIR. '/functions' );
define( 'LIBS_URI', THEME_URI. '/functions' );
define( 'LANG_DIR', THEME_DIR. '/languages' );

add_filter( 'widget_text', 'do_shortcode' );

add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');


/* ---------------------------------------------------------------------------
 * White Label
 * IMPORTANT: We recommend the use of Child Theme to change this
 * --------------------------------------------------------------------------- */
defined( 'WHITE_LABEL' ) or define( 'WHITE_LABEL', false );


/* ---------------------------------------------------------------------------
 * Loads Theme Textdomain
 * --------------------------------------------------------------------------- */
load_theme_textdomain( 'betheme',  LANG_DIR );
load_theme_textdomain( 'mfn-opts', LANG_DIR );


/* ---------------------------------------------------------------------------
 * Loads the Options Panel
 * --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_admin_scripts' ) )
{
	function mfn_admin_scripts() {
		wp_enqueue_script( 'jquery-ui-sortable' );
	}
}   
add_action( 'wp_enqueue_scripts', 'mfn_admin_scripts' );
add_action( 'admin_enqueue_scripts', 'mfn_admin_scripts' );
	
require( THEME_DIR .'/muffin-options/theme-options.php' );

$theme_disable = mfn_opts_get( 'theme-disable' );


/* ---------------------------------------------------------------------------
 * Loads Theme Functions
 * --------------------------------------------------------------------------- */

// Functions ------------------------------------------------------------------
require_once( LIBS_DIR .'/theme-functions.php' );

// Header ---------------------------------------------------------------------
require_once( LIBS_DIR .'/theme-head.php' );

// Menu -----------------------------------------------------------------------
require_once( LIBS_DIR .'/theme-menu.php' );
if( ! isset( $theme_disable['mega-menu'] ) ){
	require_once( LIBS_DIR .'/theme-mega-menu.php' );
}

// Muffin Builder -------------------------------------------------------------
require_once( LIBS_DIR .'/builder/fields.php' );
require_once( LIBS_DIR .'/builder/back.php' );
require_once( LIBS_DIR .'/builder/front.php' );

// Custom post types ----------------------------------------------------------
$post_types_disable = mfn_opts_get( 'post-type-disable' );

if( ! isset( $post_types_disable['client'] ) ){
	require_once( LIBS_DIR .'/meta-client.php' );
}
if( ! isset( $post_types_disable['offer'] ) ){
	require_once( LIBS_DIR .'/meta-offer.php' );
}
if( ! isset( $post_types_disable['portfolio'] ) ){
	require_once( LIBS_DIR .'/meta-portfolio.php' );
}
if( ! isset( $post_types_disable['slide'] ) ){
	require_once( LIBS_DIR .'/meta-slide.php' );
}
if( ! isset( $post_types_disable['testimonial'] ) ){
	require_once( LIBS_DIR .'/meta-testimonial.php' );
}

if( ! isset( $post_types_disable['layout'] ) ){
	require_once( LIBS_DIR .'/meta-layout.php' );
}
if( ! isset( $post_types_disable['template'] ) ){
	require_once( LIBS_DIR .'/meta-template.php' );
}

require_once( LIBS_DIR .'/meta-page.php' );
require_once( LIBS_DIR .'/meta-post.php' );

// Content ----------------------------------------------------------------------
require_once( THEME_DIR .'/includes/content-post.php' );
require_once( THEME_DIR .'/includes/content-portfolio.php' );

// Shortcodes -------------------------------------------------------------------
require_once( LIBS_DIR .'/theme-shortcodes.php' );

// Hooks ------------------------------------------------------------------------
require_once( LIBS_DIR .'/theme-hooks.php' );

// Widgets ----------------------------------------------------------------------
require_once( LIBS_DIR .'/widget-functions.php' );

require_once( LIBS_DIR .'/widget-flickr.php' );
require_once( LIBS_DIR .'/widget-login.php' );
require_once( LIBS_DIR .'/widget-menu.php' );
require_once( LIBS_DIR .'/widget-recent-comments.php' );
require_once( LIBS_DIR .'/widget-recent-posts.php' );
require_once( LIBS_DIR .'/widget-tag-cloud.php' );

// TinyMCE ----------------------------------------------------------------------
require_once( LIBS_DIR .'/tinymce/tinymce.php' );

// Plugins ---------------------------------------------------------------------- 
if( ! isset( $theme_disable['demo-data'] ) ){
	require_once( LIBS_DIR .'/importer/import.php' );
}

require_once( LIBS_DIR .'/system-status.php' );

require_once( LIBS_DIR .'/class-love.php' );
require_once( LIBS_DIR .'/class-tgm-plugin-activation.php' );

require_once( LIBS_DIR .'/plugins/visual-composer.php' );

// WooCommerce specified functions
if( function_exists( 'is_woocommerce' ) ){
	require_once( LIBS_DIR .'/theme-woocommerce.php' );
}

// Hide activation and update specific parts ------------------------------------

// Slider Revolution
if( ! mfn_opts_get( 'plugin-rev' ) ){
	if( function_exists( 'set_revslider_as_theme' ) ){
		set_revslider_as_theme();
	}
}

// LayerSlider
if( ! mfn_opts_get( 'plugin-layer' ) ){
	add_action('layerslider_ready', 'mfn_layerslider_overrides');
	function mfn_layerslider_overrides() {
		// Disable auto-updates
		$GLOBALS['lsAutoUpdateBox'] = false;
	}
}

// Visual Composer 
if( ! mfn_opts_get( 'plugin-visual' ) ){
	add_action( 'vc_before_init', 'mfn_vcSetAsTheme' );
	function mfn_vcSetAsTheme() {
		vc_set_as_theme();
	}
}



//For removing ddn from Shop page
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

//For changing Add to Cart button text
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );
//For Single Product Page.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
//For Archives Product Page.
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text()
{
    return __( 'Add Consultation time', 'woocommerce' );
}

// For changing some messages
add_filter('gettext', 'wpse_124400_woomessages', 10, 3);
/**
* change some WooCommerce labels
* @param string $translation
* @param string $text
* @param string $domain
* @return string
*/
function wpse_124400_woomessages($translation, $text, $domain) {
if ($domain == 'woocommerce') {
if ($text == 'Cart updated.') {
$translation = 'List updated.';
}
if ($text == 'Cart') {
$translation = 'Fee';
}
if ($text == 'cart') {
$translation = 'fee';
}
if ($text == 'Order Notes') {
$translation = 'Notes';
}
if ($text == 'Order') {
$translation = 'Payment';
}
if ($text == 'orders') {
$translation = 'Consultation Time';
}
if ($text == 'Continue Shopping') {
$translation = 'Continue';
}
if ($text == 'Order Subtotal') {
$translation = 'Fee Subtotal';
}
if ($text == 'Order Total') {
$translation = 'Fee Total';
}
if ($text == 'Order Total:') {
$translation = 'Fee Total:';
}
if ($text == 'Your cart is currently empty.') {
$translation = 'Your list is currently empty.';
}
if ($text == 'Thank you for shopping with us. We will keep you posted regarding the status of your order through e-mail') {
$translation = 'Please check the payment status below. If successful, please call on the mentioned contact numbers to schedule your consultation';
}
if ($text == 'Cart Totals') {
$translation = 'Fee Totals';
}
if ($text == 'Cart Subtotal') {
$translation = 'Fee Subtotal';
}
if ($text == 'Cart Subtotal:') {
$translation = 'Fee Subtotal:';
}
if ($text == 'Cart Total') {
$translation = 'Fee Total';
}
if ($text == 'Product') {
$translation = 'Consultation Time';
}
if ($text == 'Price') {
$translation = 'Fee';
}
if ($text == 'Recent Orders') {
$translation = 'Recent Payments';
}
if ($text == 'There are some issues with the items in your cart (shown above). Please go back to the cart page and resolve these issues before checking out.') {
$translation = 'There are some issues with the items in your booking (shown above). Please go back to the Appointments page and resolve these issues before payment.';
}
if ($text == 'You must be logged in to checkout.') {
$translation = 'You must be logged in to pay.';
}
if ($text == 'Your order') {
$translation = 'Your Fee Payment Details';
}
if ($text == 'Thank you. Your order has been received.') {
$translation = 'Thank you. Your payment has been received.';
}
if ($text == 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.') {
$translation = 'Unfortunately your payment cannot be processed as the originating bank/merchant has declined your transaction.';
}
if ($text == 'Please attempt your purchase again or go to your account page.') {
$translation = 'Please attempt your payment again or go to your account page.';
}
if ($text == 'Please attempt your purchase again.') {
$translation = 'Please attempt your payment again.';
}
if ($text == 'Order:') {
$translation = 'Payment:';
}
if ($text == 'The following addresses will be used on the checkout page by default.') {
$translation = 'The following addresses will be used on the payments page by default.';
}
if ($text == 'Your order was cancelled.') {
$translation = 'Your payment was cancelled.';
}
if ($text == 'Order Details') {
$translation = 'Payment Details';
}
if ($text == 'Proceed to Checkout') {
$translation = 'Proceed to Pay';
}
if ($text == 'Update Cart') {
$translation = 'Update';
}
if ($text == 'Place order') {
$translation = 'Pay Fees';
}
}
return $translation;
} 

// Editing the text inside the Notes textbox. Can remove some fields in this function, if needed
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_company']);
$fields['order']['order_comments']['placeholder'] = 'Mention in brief any note about the payment request';
return $fields;
}