<?php
error_reporting(0);
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
	   function wpcf7_validate_email_check($emailAddress) {
       // Check the formatting is correct
        if(filter_var($emailAddress, FILTER_VALIDATE_EMAIL) === false){
          return false;
        }
        $domain = explode("@", $emailAddress, 2);
        return $response = (checkdnsrr($domain[1]) ? true : false);
      
    }

    function wpcf7_custom_email_validation_filter($result, $tags) {
                
        $tags = new WPCF7_FormTag( $tags );

        $type = $tags->type;
        $name = $tags->name;

        if ('email' == $type || 'email*' == $type) { // Only apply to fields with the form field name of "company-email"
          
          $email_value = sanitize_email($_POST[$name]);
          
          if(!wpcf7_validate_email_check($email_value)){
              //code commented to enable translations

            $result->invalidate( $tags, __( 'Email address entered is not valid', 'contact-form-7-email-validation' ));
          }
        }
        return $result;
    }

    add_filter('wpcf7_validate_email', 'wpcf7_custom_email_validation_filter', 20, 2); // Email field
    add_filter('wpcf7_validate_email*', 'wpcf7_custom_email_validation_filter', 20, 2); // Req. Email field
	// define the wpcf7_is_tel callback 
/*function custom_filter_wpcf7_is_tel( $result, $tel ) { 
  $result = preg_match( '/^\(?\+?([0-9]{1,4})?\)?[-\. ]?(\d{10})$/', $tel );
  return $result; 
}

add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 );*/
/*
* Creating a function to create worship CPT
*/
add_action( 'init', 'custom_post_type_worship' );
function custom_post_type_worship(){
    register_post_type( 'worship',
        array(
            'labels' => array(
                'name' => __('worship'),
                'singular_name' => __('worship'),
                'add_new' => 'Add New worship',
                'add_new_item' => 'Add New worship',
                'edit' => 'Edit',
                'edit_item' => 'Edit worship',
                'new_item' => 'New worship',
                'view' => 'View',
                'view_item' => 'View worship',
                'search_items' => 'Search worship',
                'not_found' => 'No worship found',
                'not_found_in_trash' => 'No worship found in Trash',
                'parent' => 'Parent worship' 
            ),
            'public' => true, 
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
            'has_archive' => true,
            'query_var' => true,
        )
    );
} 
/**
 * Show cart contents / total Ajax
 */
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );

function woocommerce_header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;

    ob_start();

    ?>
    <a class="cart-customlocation" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><span class="cartcount"><?php echo sprintf(_n('%d ', '%d ', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></span>Cart</a>
    <?php
    $fragments['a.cart-customlocation'] = ob_get_clean();
    return $fragments;
}
add_filter('doing_it_wrong_trigger_error', function () {return false;}, 10, 0);

// disable for posts
	add_filter('use_block_editor_for_post', '__return_false', 10);
