| 1 |
<?php |
| 2 |
/** |
| 3 |
* Flash Core Functions. |
| 4 |
* |
| 5 |
* General core functions available on both the front-end and admin. |
| 6 |
* |
| 7 |
* @author ThemeGrill |
| 8 |
* @category Core |
| 9 |
* @package FlashToolkit/Functions |
| 10 |
* @version 1.0.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
// Include core functions (available in both admin and frontend). |
| 18 |
include( 'functions-flash-deprecated.php' ); |
| 19 |
include( 'functions-flash-formatting.php' ); |
| 20 |
include( 'functions-flash-portfolio.php' ); |
| 21 |
|
| 22 |
/** |
| 23 |
* is_flash_pro_active - Check if Flash Pro is active. |
| 24 |
* @return bool |
| 25 |
*/ |
| 26 |
function is_flash_pro_active() { |
| 27 |
return false !== strpos( get_option( 'template' ), 'flash-pro' ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Queue some JavaScript code to be output in the footer. |
| 32 |
* @param string $code |
| 33 |
*/ |
| 34 |
function flash_toolkit_enqueue_js( $code ) { |
| 35 |
global $flash_toolkit_queued_js; |
| 36 |
|
| 37 |
if ( empty( $flash_toolkit_queued_js ) ) { |
| 38 |
$flash_toolkit_queued_js = ''; |
| 39 |
} |
| 40 |
|
| 41 |
$flash_toolkit_queued_js .= "\n" . $code . "\n"; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Output any queued javascript code in the footer. |
| 46 |
*/ |
| 47 |
function flash_toolkit_print_js() { |
| 48 |
global $flash_toolkit_queued_js; |
| 49 |
|
| 50 |
if ( ! empty( $flash_toolkit_queued_js ) ) { |
| 51 |
// Sanitize. |
| 52 |
$flash_toolkit_queued_js = wp_check_invalid_utf8( $flash_toolkit_queued_js ); |
| 53 |
$flash_toolkit_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $flash_toolkit_queued_js ); |
| 54 |
$flash_toolkit_queued_js = str_replace( "\r", '', $flash_toolkit_queued_js ); |
| 55 |
|
| 56 |
$js = "<!-- Flash Toolkit JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) { $flash_toolkit_queued_js });\n</script>\n"; |
| 57 |
|
| 58 |
/** |
| 59 |
* social_icons_queued_js filter. |
| 60 |
* @param string $js JavaScript code. |
| 61 |
*/ |
| 62 |
echo apply_filters( 'flash_toolkit_queued_js', $js ); |
| 63 |
|
| 64 |
unset( $flash_toolkit_queued_js ); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Display a FlashToolkit help tip. |
| 70 |
* |
| 71 |
* @param string $tip Help tip text |
| 72 |
* @param bool $allow_html Allow sanitized HTML if true or escape |
| 73 |
* @return string |
| 74 |
*/ |
| 75 |
function flash_toolkit_help_tip( $tip, $allow_html = false ) { |
| 76 |
if ( $allow_html ) { |
| 77 |
$tip = flash_toolkit_sanitize_tooltip( $tip ); |
| 78 |
} else { |
| 79 |
$tip = esc_attr( $tip ); |
| 80 |
} |
| 81 |
|
| 82 |
return '<span class="flash-toolkit-help-tip" data-tip="' . $tip . '"></span>'; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Get all available sidebars. |
| 87 |
* @param array $sidebars |
| 88 |
* @return array |
| 89 |
*/ |
| 90 |
function flash_toolkit_get_sidebars( $sidebars = array() ) { |
| 91 |
global $wp_registered_sidebars; |
| 92 |
|
| 93 |
foreach ( $wp_registered_sidebars as $sidebar ) { |
| 94 |
if ( ! in_array( $sidebar['name'], apply_filters( 'flash_toolkit_sidebars_exclude', array( 'Display Everywhere' ) ) ) ) { |
| 95 |
$sidebars[ $sidebar['id'] ] = $sidebar['name']; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return $sidebars; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* FlashToolkit Layout Supported Screens or Post types. |
| 104 |
* @return array |
| 105 |
*/ |
| 106 |
function flash_toolkit_get_layout_supported_screens() { |
| 107 |
return (array) apply_filters( 'flash_toolkit_layout_supported_screens', array( 'post', 'page', 'portfolio', 'jetpack-portfolio' ) ); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Get and include template files. |
| 112 |
* |
| 113 |
* @param string $template_name |
| 114 |
* @param array $args (default: array()) |
| 115 |
* @param string $template_path (default: '') |
| 116 |
* @param string $default_path (default: '') |
| 117 |
*/ |
| 118 |
function flash_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 119 |
if ( ! empty( $args ) && is_array( $args ) ) { |
| 120 |
extract( $args ); |
| 121 |
} |
| 122 |
|
| 123 |
$located = flash_locate_template( $template_name, $template_path, $default_path ); |
| 124 |
|
| 125 |
if ( ! file_exists( $located ) ) { |
| 126 |
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '1.0' ); |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
// Allow 3rd party plugin filter template file from their plugin. |
| 131 |
$located = apply_filters( 'flash_get_template', $located, $template_name, $args, $template_path, $default_path ); |
| 132 |
|
| 133 |
do_action( 'flash_toolkit_before_template_part', $template_name, $template_path, $located, $args ); |
| 134 |
|
| 135 |
include( $located ); |
| 136 |
|
| 137 |
do_action( 'flash_toolkit_after_template_part', $template_name, $template_path, $located, $args ); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Locate a template and return the path for inclusion. |
| 142 |
* |
| 143 |
* Note: FT_TEMPLATE_DEBUG_MODE will prevent overrides in themes from taking priority. |
| 144 |
* |
| 145 |
* This is the load order: |
| 146 |
* |
| 147 |
* yourtheme / $template_path / $template_name |
| 148 |
* yourtheme / $template_name |
| 149 |
* $default_path / $template_name |
| 150 |
* |
| 151 |
* @param string $template_name |
| 152 |
* @param string $template_path (default: '') |
| 153 |
* @param string $default_path (default: '') |
| 154 |
* @return string |
| 155 |
*/ |
| 156 |
function flash_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
| 157 |
if ( ! $template_path ) { |
| 158 |
$template_path = FT()->template_path(); |
| 159 |
} |
| 160 |
|
| 161 |
if ( ! $default_path ) { |
| 162 |
$default_path = FT()->plugin_path() . '/templates/'; |
| 163 |
} |
| 164 |
|
| 165 |
// Look within passed path within the theme - this is priority. |
| 166 |
$template = locate_template( |
| 167 |
array( |
| 168 |
trailingslashit( $template_path ) . $template_name, |
| 169 |
$template_name, |
| 170 |
) |
| 171 |
); |
| 172 |
|
| 173 |
// Get default template/ |
| 174 |
if ( ! $template || FT_TEMPLATE_DEBUG_MODE ) { |
| 175 |
$template = $default_path . $template_name; |
| 176 |
} |
| 177 |
|
| 178 |
// Return what we found. |
| 179 |
return apply_filters( 'flash_toolkit_locate_template', $template, $template_name, $template_path ); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Get permalink settings for FlashToolkit independent of the user locale. |
| 184 |
* |
| 185 |
* @since 1.2.0 |
| 186 |
* @return array |
| 187 |
*/ |
| 188 |
function flash_get_permalink_structure() { |
| 189 |
if ( did_action( 'admin_init' ) ) { |
| 190 |
flash_switch_to_site_locale(); |
| 191 |
} |
| 192 |
|
| 193 |
$permalinks = wp_parse_args( (array) get_option( 'flash_toolkit_permalinks', array() ), array( |
| 194 |
'portfolio_base' => '', |
| 195 |
'category_base' => '', |
| 196 |
'tag_base' => '', |
| 197 |
'portfolio_has_archive' => true, |
| 198 |
'use_verbose_page_rules' => false, |
| 199 |
) ); |
| 200 |
|
| 201 |
// Ensure rewrite slugs are set. |
| 202 |
$permalinks['portfolio_rewrite_slug'] = untrailingslashit( empty( $permalinks['portfolio_base'] ) ? _x( 'portfolio', 'slug', 'flash-toolkit' ) : $permalinks['portfolio_base'] ); |
| 203 |
$permalinks['category_rewrite_slug'] = untrailingslashit( empty( $permalinks['category_base'] ) ? _x( 'portfolio-category', 'slug', 'flash-toolkit' ) : $permalinks['category_base'] ); |
| 204 |
$permalinks['tag_rewrite_slug'] = untrailingslashit( empty( $permalinks['tag_base'] ) ? _x( 'portfolio-tag', 'slug', 'flash-toolkit' ) : $permalinks['tag_base'] ); |
| 205 |
|
| 206 |
if ( function_exists( 'restore_current_locale' ) && did_action( 'admin_init' ) ) { |
| 207 |
flash_restore_locale(); |
| 208 |
} |
| 209 |
return $permalinks; |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Switch FlashToolkit to site language. |
| 214 |
* |
| 215 |
* @since 1.2.0 |
| 216 |
*/ |
| 217 |
function flash_switch_to_site_locale() { |
| 218 |
if ( function_exists( 'switch_to_locale' ) ) { |
| 219 |
switch_to_locale( get_locale() ); |
| 220 |
|
| 221 |
// Filter on plugin_locale so load_plugin_textdomain loads the correct locale. |
| 222 |
add_filter( 'plugin_locale', 'get_locale' ); |
| 223 |
|
| 224 |
// Init FT locale. |
| 225 |
FT()->load_plugin_textdomain(); |
| 226 |
} |
| 227 |
} |
| 228 |
/** |
| 229 |
* Switch FlashToolkit language to original. |
| 230 |
* |
| 231 |
* @since 1.2.0 |
| 232 |
*/ |
| 233 |
function flash_restore_locale() { |
| 234 |
if ( function_exists( 'restore_previous_locale' ) ) { |
| 235 |
restore_previous_locale(); |
| 236 |
|
| 237 |
// Remove filter. |
| 238 |
remove_filter( 'plugin_locale', 'get_locale' ); |
| 239 |
|
| 240 |
// Init FT locale. |
| 241 |
FT()->load_plugin_textdomain(); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
if ( ! function_exists( 'flash_get_google_fonts' ) ) { |
| 246 |
|
| 247 |
/** |
| 248 |
* Get Google Font lists. |
| 249 |
* @return array |
| 250 |
*/ |
| 251 |
function flash_get_google_fonts() { |
| 252 |
return apply_filters( 'flash_get_google_fonts', include( FT()->plugin_path() . '/i18n/google-fonts.php' ) ); |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
if ( ! function_exists( 'flash_get_fontawesome_icons' ) ) { |
| 257 |
|
| 258 |
/** |
| 259 |
* Get fontawesome icon lists. |
| 260 |
* @return array |
| 261 |
*/ |
| 262 |
function flash_get_fontawesome_icons() { |
| 263 |
return apply_filters( 'flash_get_fontawesome_icons', include( FT()->plugin_path() . '/i18n/fontawesome.php' ) ); |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Check excerpt value in site origin page builder |
| 269 |
* |
| 270 |
* @param integer $id Post ID. |
| 271 |
* @return bool |
| 272 |
*/ |
| 273 |
function flash_is_so_pagebuilder_active_page( $id ) { |
| 274 |
if ( function_exists( 'siteorigin_panels_is_home' ) ) { |
| 275 |
if ( siteorigin_panels_is_home() || get_post_meta( $id, 'panels_data', true ) ) { |
| 276 |
return true; |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
return false; |
| 281 |
} |
| 282 |
|
| 283 |
/** |
| 284 |
* Get excerpt from the given post. |
| 285 |
* |
| 286 |
* @param object $post Post Object. |
| 287 |
* @return string $excerpt |
| 288 |
*/ |
| 289 |
function flash_so_pagebuilder_get_the_excerpt( $post ) { |
| 290 |
$excerpt = ''; |
| 291 |
|
| 292 |
if ( flash_is_so_pagebuilder_active_page( $post->ID ) ) { |
| 293 |
if ( flash_has_manual_excerpt( $post ) ) { |
| 294 |
$excerpt = get_the_excerpt( $post ); |
| 295 |
} |
| 296 |
} else { |
| 297 |
$excerpt = get_the_excerpt( $post ); |
| 298 |
} |
| 299 |
|
| 300 |
return $excerpt; |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Checks if manual excerpt exists. |
| 305 |
* |
| 306 |
* @param object $post Post Object. |
| 307 |
* @return bool |
| 308 |
*/ |
| 309 |
function flash_has_manual_excerpt( $post ) { |
| 310 |
if ( '' === $post->post_excerpt ) { |
| 311 |
return false; |
| 312 |
} |
| 313 |
|
| 314 |
return true; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Enqueue custom library files, which should be used for widgets. |
| 319 |
*/ |
| 320 |
function flashtoolkit_enqueue_script() { |
| 321 |
global $post; |
| 322 |
|
| 323 |
if ( ! $post instanceof \WP_Post ) { |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
$panels_data = get_post_meta( $post->ID, 'panels_data', true ); |
| 328 |
|
| 329 |
if ( ! empty( $panels_data['widgets'] ) ) { |
| 330 |
|
| 331 |
foreach ( $panels_data['widgets'] as $widget ) { |
| 332 |
// For FT: Slider widget, For FT: Logo widget, For FT: Testimonial widget, For FT: Instagram Slider widget, For FT: Post Slider widget, For FT: WooCommerce Category Slider widget. |
| 333 |
if ( 'FT_Widget_Slider' == $widget['panels_info']['class'] || 'FT_Widget_Logo' == $widget['panels_info']['class'] || 'FT_Widget_Testimonial' == $widget['panels_info']['class'] || 'FT_Widget_InstagramSlider' == $widget['panels_info']['class'] || 'FT_Widget_PostSlider' == $widget['panels_info']['class'] || 'FT_Widget_WcCatSlider' == $widget['panels_info']['class'] ) { |
| 334 |
wp_enqueue_style( 'swiper' ); |
| 335 |
wp_enqueue_script( 'swiper' ); |
| 336 |
} |
| 337 |
|
| 338 |
// For FT: Animated Number Counter widget. |
| 339 |
if ( 'FT_Widget_Counter' == $widget['panels_info']['class'] ) { |
| 340 |
wp_enqueue_script( 'waypoints' ); |
| 341 |
wp_enqueue_script( 'counterup' ); |
| 342 |
} |
| 343 |
|
| 344 |
// For FT: Portfolio widget. |
| 345 |
if ( 'FT_Widget_Portfolio' == $widget['panels_info']['class'] ) { |
| 346 |
wp_enqueue_script( 'isotope' ); |
| 347 |
} |
| 348 |
|
| 349 |
// For FT: Accordion widget. |
| 350 |
if ( 'FT_Accordion' == $widget['panels_info']['class'] ) { |
| 351 |
wp_enqueue_script( 'jquery-ui-accordion' ); |
| 352 |
} |
| 353 |
|
| 354 |
// For FT: Countdown widget. |
| 355 |
if ( 'FT_Widget_Countdown' == $widget['panels_info']['class'] ) { |
| 356 |
wp_enqueue_script( 'jquery.plugin' ); |
| 357 |
wp_enqueue_script( 'jquery.countdown' ); |
| 358 |
} |
| 359 |
|
| 360 |
// For FT: Google Map widget. |
| 361 |
if ( 'FT_Widget_GoogleMap' == $widget['panels_info']['class'] ) { |
| 362 |
wp_enqueue_script( 'googlemap' ); |
| 363 |
} |
| 364 |
|
| 365 |
// For FT: Progress Bar widget. |
| 366 |
if ( 'FT_Widget_ProgressBar' == $widget['panels_info']['class'] ) { |
| 367 |
wp_enqueue_script( 'waypoints' ); |
| 368 |
} |
| 369 |
|
| 370 |
// For FT: Tabs widget, For FT: WooCommerce Product Tab widget. |
| 371 |
if ( 'FT_Tabs' == $widget['panels_info']['class'] || 'FT_Widget_WcProductTab' == $widget['panels_info']['class'] ) { |
| 372 |
wp_enqueue_script( 'jquery-ui-tabs' ); |
| 373 |
} |
| 374 |
|
| 375 |
// For FT: Video Player widget. |
| 376 |
if ( 'FT_Video_Player' == $widget['panels_info']['class'] ) { |
| 377 |
wp_enqueue_style( 'jquery-swipebox' ); |
| 378 |
wp_enqueue_script( 'jquery-swipebox' ); |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
add_action( 'wp_enqueue_scripts', 'flashtoolkit_enqueue_script', 20 ); |
| 385 |
|