1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace LSX\Classes; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* All the functions for setting up the theme. |
6
|
|
|
* |
7
|
|
|
* @package LSX |
8
|
|
|
* @author LightSpeed |
9
|
|
|
* @license GPL3 |
10
|
|
|
* @link |
11
|
|
|
* @copyright 2023 LightSpeed |
12
|
|
|
*/ |
13
|
|
|
class Frontend { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Contructor |
17
|
|
|
*/ |
18
|
|
|
public function __construct() { |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Initiate our class. |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function init() { |
27
|
|
|
// Styles and Scripts |
|
|
|
|
28
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
29
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'yoast_faq_asset_files' ) ); |
30
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'woo_asset_files' ) ); |
31
|
|
|
add_filter( 'script_loader_tag', array( $this, 'cf_async_disable' ), 10, 3); |
|
|
|
|
32
|
|
|
|
33
|
|
|
//Output on the frontend. |
|
|
|
|
34
|
|
|
add_filter( 'wpforms_frontend_form_data', array( $this, 'wpforms_match_button_block' ) ); |
35
|
|
|
add_filter( 'woocommerce_account_menu_items', array( $this, 'woocommerce_account_menu_items_fix' ), 10, 2 ); |
36
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Enqueues the frontend styles |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function enqueue_styles() { |
45
|
|
|
wp_enqueue_style( 'lsx-styles', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) ); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Load the assets files for Yoast |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function yoast_faq_asset_files() { |
55
|
|
|
if ( function_exists( 'wpseo_init' ) ) { |
56
|
|
|
wp_enqueue_style( 'lsx-yoast-faq-css', get_template_directory_uri() . '/assets/css/faq/style.css', array() ); |
|
|
|
|
57
|
|
|
wp_enqueue_script( 'lsx-yoast-faq-js', get_template_directory_uri() . '/assets/js/faq.js', array( "jquery" ), "1.0", true ); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Load the assets files for Yoast |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function woo_asset_files() { |
67
|
|
|
if ( class_exists( 'woocommerce' ) ) { |
68
|
|
|
wp_enqueue_style( 'lsx-woo-css', get_template_directory_uri() . '/assets/css/woocommerce.css', array() ); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* WPForms submit button, match Gutenberg button block |
74
|
|
|
* |
75
|
|
|
* @param [type] $form_data |
|
|
|
|
76
|
|
|
* @return void |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
function wpforms_match_button_block( $form_data ) { |
|
|
|
|
79
|
|
|
$form_data['settings']['submit_class'] .= ' btn'; |
80
|
|
|
return $form_data; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
|
|
|
|
84
|
|
|
* Fixes the plural for the edit address my account menu. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function woocommerce_account_menu_items_fix( $items, $endpoints ) { |
|
|
|
|
89
|
|
|
if ( ! isset( $items['edit-address'] ) || '' !== $items['edit-address'] ) { |
90
|
|
|
return $items; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ( true === wc_shipping_enabled() ) { |
|
|
|
|
94
|
|
|
$items['edit-address'] = __( 'Addresses', 'woocommerce' ); |
95
|
|
|
} else { |
96
|
|
|
$items['edit-address'] = __( 'Address', 'woocommerce' ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $items; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
|
|
|
|
103
|
|
|
* Make comment reply button work with CloudFlare Rocket Loader |
104
|
|
|
* @see https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-specific-JavaScripts- |
|
|
|
|
105
|
|
|
*/ |
106
|
|
|
public function cf_async_disable( $tag, $handle, $src ) { |
|
|
|
|
107
|
|
|
if ( 'comment-reply' !== $handle ) { |
108
|
|
|
return $tag; |
109
|
|
|
} |
110
|
|
|
return str_replace( ' src', ' data-cfasync="false" src', $tag ); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|