FIX: Leaflet scripts and styles were not enqued for shortcodes event_full and event_venue
This commit is contained in:
@@ -1684,3 +1684,32 @@ if( ! function_exists( 'array_replace' ) ) {
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a shortcode is shown on content
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function sp_has_shortcodes( $content, $tags ) {
|
||||||
|
if( is_array( $tags ) ) {
|
||||||
|
foreach ( $tags as $tag ) {
|
||||||
|
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
|
||||||
|
if ( empty( $matches ) )
|
||||||
|
return false;
|
||||||
|
foreach ( $matches as $shortcode ) {
|
||||||
|
if ( $tag === $shortcode[2] )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( shortcode_exists( $tags ) ) {
|
||||||
|
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
|
||||||
|
if ( empty( $matches ) )
|
||||||
|
return false;
|
||||||
|
foreach ( $matches as $shortcode ) {
|
||||||
|
if ( $tags === $shortcode[2] )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,7 +96,8 @@ if ( ! class_exists( 'SportsPress_OpenStreetMap' ) ):
|
|||||||
* Enqueue frontend venue scripts
|
* Enqueue frontend venue scripts
|
||||||
*/
|
*/
|
||||||
public function frontend_venue_scripts() {
|
public function frontend_venue_scripts() {
|
||||||
if( ( is_single() || is_tax() ) && get_post_type()=='sp_event' ){
|
global $post;
|
||||||
|
if( ( ( is_single() || is_tax() ) && get_post_type()=='sp_event' ) || sp_has_shortcodes( $post->post_content, array('event_full', 'event_venue') ) ) {
|
||||||
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
|
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
|
||||||
wp_enqueue_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' );
|
wp_enqueue_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user