-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathclass-bb-header-footer.php
288 lines (235 loc) · 8.81 KB
/
class-bb-header-footer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/**
* Entry point for the plugin. Checks if Beaver Builder is installed and activated and loads it's own files and actions.
*
* @package bb-header-footer
*/
/**
* Class BB_Header_Footer
*/
class BB_Header_Footer {
/**
* Current theme template
*
* @var String
*/
public $template;
/**
* Constructor
*/
function __construct() {
$this->template = get_template();
if ( class_exists( 'FLBuilder' ) && is_callable( 'FLBuilderShortcodes::insert_layout' ) ) {
$this->includes();
$this->load_textdomain();
// Load themes compatibility.
add_action( 'init', array( $this, 'themes_compat' ) );
// Scripts and styles.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'body_class', array( $this, 'body_class' ) );
} else {
add_action( 'admin_notices', array( $this, 'bb_not_available' ) );
add_action( 'network_admin_notices', array( $this, 'bb_not_available' ) );
}
}
/**
* Themes compatibility
*/
public function themes_compat() {
if ( 'genesis' == $this->template ) {
// Genesis framework theme compatibility.
require BBHF_DIR . 'themes/genesis/class-genesis-compat.php';
} elseif ( 'astra' == $this->template ) {
// Beaver Builder Theme compatibility.
require BBHF_DIR . 'themes/astra/class-astra-compat.php';
} elseif ( 'bb-theme' == $this->template || 'beaver-builder-theme' == $this->template ) {
// Beaver Builder Theme compatibility.
$this->template = 'beaver-builder-theme';
require BBHF_DIR . 'themes/bb-theme/class-bb-theme-compat.php';
} elseif ( 'generatepress' == $this->template ) {
// GeneratePress theme compatibility.
require BBHF_DIR . 'themes/generatepress/class-generatepress-compat.php';
} elseif ( 'wp-primer-theme' == $this->template || 'primer' == $this->template ) {
$this->template = 'primer';
require BBHF_DIR . 'themes/wp-primer-theme/class-bhf-primer-theme-compat.php';
} elseif ( ! current_theme_supports( 'bb-header-footer' ) ) {
// If the theme does not support this plugin, display admin notices.
add_action( 'admin_notices', array( $this, 'unsupported_theme' ) );
add_action( 'network_admin_notices', array( $this, 'unsupported_theme' ) );
}
}
/**
* Prints the admin notics when Beaver Builder is not installed or activated.
*/
public function bb_not_available() {
if ( file_exists( plugin_dir_path( 'bb-plugin-agency/fl-builder.php' ) )
|| file_exists( plugin_dir_path( 'beaver-builder-lite-version/fl-builder.php' ) )
) {
$url = network_admin_url() . 'plugins.php?s=Beaver+Builder+Plugin';
} else {
$url = network_admin_url() . 'plugin-install.php?s=billyyoung&tab=search&type=author';
}
echo '<div class="notice notice-error">';
/* Translators: URL to activate/install Beaver Builder lite version */
echo '<p>' . sprintf( __( 'The <strong>BB Header Footer</strong> plugin requires Latest version of <strong><a href="%s">Beaver Builder</strong></a> plugin installed & activated.', 'bb-header-footer' ) . '</p>', $url );
echo '</div>';
}
/**
* Loads the globally required files for the plugin.
*/
public function includes() {
require_once BBHF_DIR . 'admin/class-bb-admin-ui.php';
// Astra notices.
require_once BBHF_DIR . 'lib/astra-notices/class-astra-notices.php';
// BSF Analytics Tracker.
require_once BBHF_DIR . 'admin/bsf-analytics/class-bsf-analytics.php';
}
/**
* Loads textdomain for the plugin.
*/
public function load_textdomain() {
load_plugin_textdomain( 'bb-header-footer' );
}
/**
* Enqueue styles and scripts.
*/
public function enqueue_scripts() {
wp_enqueue_style( 'bbhf-style', BBHF_URL . 'assets/css/bb-header-footer.css', array(), BBHF_VER );
wp_register_script( 'bb-header-footer', BBHF_URL . 'assets/js/bb-header-footer.js', array( 'jquery' ), BBHF_VER, true );
wp_enqueue_script( 'bb-header-footer' );
if ( is_callable( 'FLBuilder::enqueue_layout_styles_scripts_by_id' ) ) {
$header_id = BB_Header_Footer::get_settings( 'bb_header_id', '' );
FLBuilder::enqueue_layout_styles_scripts_by_id( $header_id );
$footer_id = BB_Header_Footer::get_settings( 'bb_footer_id', '' );
FLBuilder::enqueue_layout_styles_scripts_by_id( $footer_id );
}
}
/**
* Adds classes to the body tag conditionally.
*
* @param Array $classes array with class names for the body tag.
* @return Array array with class names for the body tag.
*/
public function body_class( $classes ) {
$header_id = BB_Header_Footer::get_settings( 'bb_header_id', '' );
$footer_id = BB_Header_Footer::get_settings( 'bb_footer_id', '' );
$bb_transparent_header = BB_Header_Footer::get_settings( 'bb_transparent_header', 'off' );
$bb_sticky_header = BB_Header_Footer::get_settings( 'bb_sticky_header', 'off' );
$bb_shrink_header = BB_Header_Footer::get_settings( 'bb_shrink_header', 'on' );
if ( '' !== $header_id ) {
$classes[] = 'dhf-header';
}
if ( '' !== $footer_id ) {
$classes[] = 'dhf-footer';
}
if ( '' !== $header_id && 'on' == $bb_transparent_header ) {
$classes[] = 'bbhf-transparent-header';
}
if ( '' !== $header_id && 'on' == $bb_sticky_header ) {
$classes[] = 'bhf-sticky-header';
}
if ( '' !== $header_id && 'on' == $bb_shrink_header ) {
$classes[] = 'bhf-shrink-header';
}
$classes[] = 'dhf-template-' . $this->template;
$classes[] = 'dhf-stylesheet-' . get_stylesheet();
return $classes;
}
/**
* Prints an admin notics oif the currently installed theme is not supported by bb-header-footer.
*/
public function unsupported_theme() {
$class = 'notice notice-error';
$message = __( 'Hey, your current theme is not supported by BB Header Footer, click <a href="https://github.com/Nikschavan/bb-header-footer#which-themes-are-supported-by-this-plugin">here</a> to check out the supported themes.', 'bb-header-footer' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
/**
* Prints the Header content.
*/
public static function get_header_content() {
$header_id = BB_Header_Footer::get_settings( 'bb_header_id', '' );
$bb_sticky_header = BB_Header_Footer::get_settings( 'bb_sticky_header', 'off' );
if ( 'on' == $bb_sticky_header ) {
echo '<div class="bhf-fixed-header">';
}
echo self::render_bb_layout( $header_id, 'header' );
if ( 'on' == $bb_sticky_header ) {
echo '</div>';
echo '<div class="bhf-ffixed-header-fixer" style="display:none;"></div>';
}
}
/**
* Prints the Footer content.
*/
public static function get_footer_content() {
$footer_id = BB_Header_Footer::get_settings( 'bb_footer_id', '' );
echo "<div class='footer-width-fixer'>";
echo self::render_bb_layout( $footer_id, 'footer' );
echo '</div>';
}
/**
* Render the Beaver Builder Layout.
* If method FLBuilder::render_content_by_id() is available it will be used, This was introduced in v1.10 of beaver builder.
* If at all user is on a older version of beaver builder then it will render using the method FLBuilderShortcodes::insert_layout()
*
* @since 1.1.6
*
* @param String $post_id post of which is to be rendered.
* @param String $data_type data-type of which is to be rendered.
*
* @return String Rendered markup of the layout
*/
public static function render_bb_layout( $post_id, $data_type ) {
$data_array = array(
'itemscope' => 'itemscope',
'data-type' => $data_type,
);
switch ( $data_type ) {
case 'header':
$data_array['itemtype'] = 'http://schema.org/WPHeader';
break;
case 'footer':
$data_array['itemtype'] = 'http://schema.org/WPFooter';
break;
}
return FLBuilder::render_content_by_id(
$post_id,
'div',
$data_array
);
}
/**
* Checks if UABB is installed and displays upgrade links if it is not available.
*/
public static function uabb_upsell_message() {
if ( ! is_plugin_active( 'bb-ultimate-addon/bb-ultimate-addon.php' ) ) {
$html = '<hr>';
$html .= '<span class="upsell-uabb">Want more Beaver Builder Addons? Check out <a target="_blank" href="' . self::uabb_purchase_url() . '">Ultimate Addon for Beaver Builder.</a></span>';
echo $html;
}
}
/**
* Returns the UABB purchase URL.
*
* @return String url
*/
public static function uabb_purchase_url() {
$url = 'https://www.ultimatebeaver.com/pricing/?bsf=162&utm_source=plugin-dashboard&utm_campaign=bb-header-footer-upgrade&utm_medium=upgrade-link';
return $url;
}
/**
* Get option for the plugin settings
*
* @param mixed $setting Option name.
* @param mixed $default Default value to be received if the option value is not stored in the option.
* @return mixed.
*/
public static function get_settings( $setting = '', $default = '' ) {
$value = $default;
$options = get_option( 'bbhf_settings' );
if ( isset( $options[ $setting ] ) ) {
$value = $options[ $setting ];
}
return apply_filters( "bhf_setting_{$setting}", $value );
}
}