diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 9d6311e5..136528db 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -1684,3 +1684,32 @@ if( ! function_exists( 'array_replace' ) ) { 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; +} diff --git a/modules/sportspress-openstreetmap.php b/modules/sportspress-openstreetmap.php index bc717906..28f20d1d 100644 --- a/modules/sportspress-openstreetmap.php +++ b/modules/sportspress-openstreetmap.php @@ -96,7 +96,8 @@ if ( ! class_exists( 'SportsPress_OpenStreetMap' ) ): * Enqueue 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_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' ); }