/** * Parse the CF7 shortcode ID in single or nested shortcodes * @return (array) of CF7 id(s) * @since 1.0.2 */ function parse_shortcode_id($content) { $tag = 'contact-form-7'; // Return if there is no CF7 shortcode in post content if (!has_shortcode($content, $tag)) { return false; } // Get all the CF7 form shortcodes in the post content // Use similar approach as wp-includes\shortcodes.php has_shortcode() function preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER); if (empty($matches)) { return false; } // Loop through shortcodes, parse shortcode attributes and get the CF7 form ID foreach ($matches as $shortcode) { if ($tag === $shortcode[2]) { $atts = shortcode_parse_atts($shortcode[3]); $ids[] = $atts['id']; // Add the CF7 form ID // Nested shortcode } elseif (!empty($shortcode[5]) && has_shortcode($shortcode[5], $tag)) { // nested shortcodes $shortcode = $this->parse_shortcode_id($shortcode[5]); } } // Return all the CF7 form ID if (isset($ids)) { return $ids; } }
public function enqueue_scripts($posts) { if (empty($posts)) { return $posts; } // false because we have to search through the posts first $found = false; // search through each post foreach ($posts as $post) { if (has_shortcode($post->post_content, self::slug)) { // we have found a post with the short code $found = true; // stop the search break; } } if ($found) { if ($this->load_css) { wp_enqueue_style('avca-google-map', AVCA_URL . 'modules/avca-google-map/assets/css/avca-google-map.css'); } if ($this->load_map_api_js) { wp_enqueue_script('googlemap', '//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '3.0', false); } if ($this->load_infobox_js) { wp_enqueue_script('infobox', AVCA_URL . 'modules/avca-google-map/assets/js/infobox.js', array(), '3.0', false); } wp_enqueue_script('avca-google-map', AVCA_URL . 'modules/avca-google-map/assets/js/avca-google-map.js', array('jquery'), '3.0', false); } return $posts; }
function drstk_video_shortcode_scripts() { global $post; if (has_shortcode($post->post_content, 'drstk_collection_playlist')) { wp_enqueue_script('drstk_jwplayer'); } }
/** * Head. * * @return string */ public function wp_head() { global $post; if (isset($post) && isset($post->post_content) && has_shortcode($post->post_content, 'gmaps')) { Wabbr::view('maps/head'); } }
/** * Shortcode stuff! */ public static function list_event_shortcode($atts) { global $post; if (is_home() || is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'list-events') || is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'list_events') || is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'list-event') || is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'list_event')) { $event_list_attributes = shortcode_atts(array('event_id' => null, 'client_id' => null, 'event-id' => null, 'client-id' => null), $atts); $localized_variables = array('ajaxurl' => admin_url('admin-ajax.php'), 'bptNonce' => wp_create_nonce('bpt-event-list-nonce'), 'postID' => $post->ID); $purchase_options = get_option('_bpt_purchase_settings'); if (isset($purchase_options['enable_sales'])) { $localized_variables['enableSales'] = $purchase_options['enable_sales']; } if ($event_list_attributes['event_id']) { $localized_variables['eventID'] = $event_list_attributes['event_id']; } if ($event_list_attributes['event-id']) { $localized_variables['eventID'] = $event_list_attributes['event-id']; } if ($event_list_attributes['client-id']) { $localized_variables['clientID'] = $event_list_attributes['client-id']; } if ($event_list_attributes['client_id']) { $localized_variables['clientID'] = $event_list_attributes['client_id']; } wp_enqueue_style('bpt_event_list_css', plugins_url('/assets/css/bpt-event-list-shortcode.css', __FILE__), array(), plugin::get_plugin_version()); wp_register_script('event_feed_js_' . $post->ID, plugins_url('/assets/js/event-feed.js', __FILE__), array('jquery', 'underscore', 'ractive_js', 'ractive_transitions_slide_js', 'moment_with_langs_min'), null, true); wp_enqueue_script('event_feed_js_' . $post->ID); wp_localize_script('event_feed_js_' . $post->ID, 'bptEventFeedAjaxPost' . $post->ID, $localized_variables); } return require __DIR__ . '/assets/templates/event-list.php'; }
function _base_scripts() { global $post; // remove version add_filter('script_loader_src', 'remove_src_version'); // global styles wp_enqueue_style('bootstrap-min', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), ''); wp_enqueue_style('font-awesome', get_template_directory_uri() . '/assets/css/font-awesome.min.css', array(), ''); if (class_exists('bbPress')) { if (is_bbpress()) { wp_enqueue_style('bbpress-custom', get_template_directory_uri() . '/assets/css/bbpress.css', array(), ''); } } wp_enqueue_style('custom', get_template_directory_uri() . '/assets/css/customs.css', array(), ''); wp_enqueue_style('custom-style', get_template_directory_uri() . '/style.css', array(), ''); // global scripts wp_enqueue_script('jquery'); wp_enqueue_script('bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array(), '', true); if (is_single() && get_post_type() == 'course_unit') { wp_enqueue_script('froogaloop2', get_template_directory_uri() . '/assets/js/froogaloop2.min.js', array(), '', true); } if (is_page_template('page-templates/tpl-webinars.php')) { wp_enqueue_style('fancybox', get_template_directory_uri() . '/assets/lib/fancybox/jquery.fancybox.css', array(), ''); wp_enqueue_script('fancybox', get_template_directory_uri() . '/assets/lib/fancybox/jquery.fancybox.pack.js', array(), '', true); wp_enqueue_script('fancybox-media', get_template_directory_uri() . '/assets/lib/fancybox/helpers/jquery.fancybox-media.js', array(), '', true); } if (has_shortcode($post->post_content, 'iard_table')) { wp_enqueue_script('angular', get_template_directory_uri() . '/assets/js/angular.min.js', array(), '', true); wp_enqueue_script('angular-sanitize', get_template_directory_uri() . '/assets/js/angular-sanitize.js', array(), '', true); wp_enqueue_script('table-app', get_template_directory_uri() . '/assets/js/tables.js', array(), '', true); } wp_enqueue_script('main', get_template_directory_uri() . '/assets/js/main.js', array(), '', true); }
public function hoo_api() { global $post; // /if the page contains the hoo-api shortcode send json and exit :} if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'hoo-api')) { $locations_repo = $this->entity_manager->getRepository('Hoo\\Model\\Location'); $json_response = array(); $date = isset($_GET['date']) ? new \DateTime($_GET['date']) : new \DateTime(date('Y-m-d')); if (isset($_GET['location_id'])) { $location = Location::get_location_by_id_or_shortname($_GET['location_id'], $this->entity_manager); if (!$location) { return wp_send_json_error('Not Found'); } $hours = $location->get_hours_for_date($date); $json_response['location'] = $location->to_api_response(); $json_response['location']['address'] = $location->address->to_api_response(); $json_response['hours'] = $hours ? $hours->to_api_response() : null; $json_response['weekly'] = $location->get_weekly_hours(); } else { $locations_repo = $this->entity_manager->getRepository('Hoo\\Model\\Location'); foreach ($locations_repo->findBy(array('is_visible' => true)) as $location) { $hours = $location->get_hours_for_date($date); $json_response[]['location'] = $location->to_api_response(); $json_response[]['location']['address'] = $location->address->to_api_response(); $json_response[]['hours'] = $hours ? $hours->to_api_response() : null; $json_response[]['weekly'] = $location->get_weekly_hours(); } } wp_send_json($json_response); exit; } }
function ecf_enqueue_on_the_fly() { global $post; if (function_exists('has_shortcode')) { if (has_shortcode($post->post_content, 'easy-contactform')) { wp_enqueue_script('ecf-ladda-spin'); wp_enqueue_script('ecf-notify'); wp_enqueue_script('ecf-ladda-js'); global $is_IE; if ($is_IE) { wp_enqueue_script('ecf-placeholder'); } } } else { if (emg_old_has_shortcode('easy-contactform')) { wp_enqueue_script('ecf-ladda-spin'); wp_enqueue_script('ecf-notify'); wp_enqueue_script('ecf-ladda-js'); global $is_IE; if ($is_IE) { wp_enqueue_script('ecf-placeholder'); } } } }
/** * Check if the content contains the shortcode. Will use WP 3.6+ has_shortcode if available, otherwise * fall back to string matching. * * @param $content * * @return bool * @since 2.4 */ protected function hasShortCode($content) { if (function_exists('has_shortcode')) { return has_shortcode($content, 'utcw'); } return strpos($content, '[utcw') !== false; }
/** * Search a string for ingot shortcodes and return ids used * * @since 1.1.0 * * @param string $content String to search * * @return array Array of group IDs */ public static function find_ids($content) { $ids = []; $tag = 'ingot'; if (!has_shortcode($content, $tag) || false === strpos($content, '[')) { return $ids; } if (shortcode_exists($tag)) { preg_match_all('/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER); if (empty($matches)) { return $ids; } foreach ($matches as $shortcode) { if ($tag === $shortcode[2] && isset($shortcode[3])) { $_id = self::find_id($shortcode); if (is_numeric($_id)) { $ids[] = $_id; } } elseif (!empty($shortcode[5]) && has_shortcode($shortcode[5], $tag)) { $_id = self::find_id($shortcode); if (is_numeric($_id)) { $ids[] = $_id; } } } } return $ids; }
/** * @param checks to see if the current post has a [video] shortcode. * @return script that will autoplay an HTML5 video player when in viewport, pauses when exits viewport. * @extends https://codex.wordpress.org/Video_Shortcode */ function ccb_video_script() { global $post; if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'video')) { ?> <script type="text/javascript"> // Add :in-viewport jQuery detection (function($){$.belowthefold=function(element,settings){var fold=$(window).height()+$(window).scrollTop();return fold<=$(element).offset().top-settings.threshold;};$.abovethetop=function(element,settings){var top=$(window).scrollTop();return top>=$(element).offset().top+$(element).height()-settings.threshold;};$.rightofscreen=function(element,settings){var fold=$(window).width()+$(window).scrollLeft();return fold<=$(element).offset().left-settings.threshold;};$.leftofscreen=function(element,settings){var left=$(window).scrollLeft();return left>=$(element).offset().left+$(element).width()-settings.threshold;};$.inviewport=function(element,settings){return!$.rightofscreen(element,settings)&&!$.leftofscreen(element,settings)&&!$.belowthefold(element,settings)&&!$.abovethetop(element,settings);};$.extend($.expr[':'],{"below-the-fold":function(a,i,m){return $.belowthefold(a,{threshold:0});},"above-the-top":function(a,i,m){return $.abovethetop(a,{threshold:0});},"left-of-screen":function(a,i,m){return $.leftofscreen(a,{threshold:0});},"right-of-screen":function(a,i,m){return $.rightofscreen(a,{threshold:0});},"in-viewport":function(a,i,m){return $.inviewport(a,{threshold:0});}});})(jQuery); // Autplay video elements that are WP shortcodes. jQuery(window).bind("load",function(){ jQuery(function() { jQuery(window).scroll(function() { jQuery('.wp-video-shortcode').each(function() { var str = jQuery(this).attr('id'); var arr = str.split('_'); typecheck = arr[0]; if (jQuery(this).is(":in-viewport( 400 )") && typecheck == "mep") { mejs.players[jQuery(this).attr('id')].media.play(); } else if (typecheck == "mep") { mejs.players[jQuery(this).attr('id')].media.pause(); } }); }); }); }); </script> <?php } }
function wp_rss_retriever_css() { global $post; if (has_shortcode($post->post_content, 'wp_rss_retriever')) { wp_enqueue_style('rss-retriever', plugin_dir_url(__FILE__) . 'inc/css/rss-retriever.css'); } }
function cfs_clear_css() { global $post; if (has_shortcode($post->post_content, 'clear')) { echo "\n<style>\n/*\n * Clear Floats Shortcode CSS\n */\n.cfs-clearfix:before,\n.cfs-clearfix:after {\n\tcontent: \" \";\n\tdisplay: table;\n}\n.cfs-clearfix:after {\n\tclear: both;\n}\n\n.cfs-both {\n\tclear: both;\n}\n\n.cfs-right {\n\tclear: right;\n}\n\n.cfs-left {\n\tclear: left;\n}\n</style>"; } }
/** * Enqueue scripts and stylesheets * * @param array $posts WordPress posts to check for the shortcode * @return array $posts Checked WordPress posts * */ function fep_enqueue_files($posts) { if (empty($posts)) { return $posts; } $found = false; foreach ($posts as $post) { if (has_shortcode($post->post_content, 'fep_article_list') || has_shortcode($post->post_content, 'fep_submission_form')) { $found = true; break; } } if ($found) { wp_enqueue_style('fep-style', plugins_url('static/css/style.css', __FILE__), array(), '1.0', 'all'); wp_enqueue_script("fep-script", plugins_url('static/js/scripts.js', __FILE__), array('jquery')); wp_localize_script('fep-script', 'fepajaxhandler', array('ajaxurl' => admin_url('admin-ajax.php'))); $fep_rules = get_option('fep_post_restrictions'); $fep_roles = get_option('fep_role_settings'); $fep_rules['check_required'] = isset($fep_roles['no_check']) && $fep_roles['no_check'] && current_user_can($fep_roles['no_check']) ? 0 : 1; wp_localize_script('fep-script', 'fep_rules', $fep_rules); $enable_media = isset($fep_roles['enable_media']) && $fep_roles['enable_media'] ? current_user_can($fep_roles['enable_media']) : 1; if ($enable_media) { wp_enqueue_media(); } } return $posts; }
function curly_tabs_vc($atts, $content = null) { $GLOBALS['tabsID'] = isset($GLOBALS['tabsID']) ? $GLOBALS['tabsID'] + 1 : 0; $GLOBALS['tabsSlideID'] = $GLOBALS['tabsID'] * 100; $pattern = get_shortcode_regex(); preg_match_all("/{$pattern}/", $content, $shortcodes); $shortcodes_array = $shortcodes[2]; $shortcodes_values_array = $shortcodes[3]; $shortcodes_content_array = $shortcodes[5]; extract(shortcode_atts(array(), $atts)); if (has_shortcode($content, 'curly_tab')) { $html = '<div class="tabs-container">'; $html .= '<ul class="nav nav-tabs">'; $tabs_keys = array_keys($shortcodes_array, 'curly_tab'); $index = 0; foreach ($tabs_keys as $key => $tab) { extract(shortcode_atts(array('title' => null), shortcode_parse_atts($shortcodes_values_array[$tab]), 'curly_tab')); $html .= '<li class="' . ($index === 0 ? 'active' : '') . '"><a href="#tab' . (100 * $GLOBALS['tabsID'] + 1) . '" data-toggle="tab">' . $title . '</a></li>'; $index++; } $html .= '</ul>'; $html .= '<div class="tab-content">'; $html .= do_shortcode($content); $html .= '</div>'; $html .= '</div>'; return $html; } }
/** * Enqueue script when gallery shortcode is used. */ function device_mockups_script() { global $post; if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'gallery')) { wp_enqueue_script('device-mockups-scripts', DEVICE_MOCKUPS_URL . 'js/device-mockups.js', array(), DEVICE_MOCKUPS_VERSION, true); } }
function google_map_block_enqueue_scripts() { if (has_shortcode($GLOBALS['post']->post_content, 'map')) { wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?sensor=false'); wp_enqueue_script('google-maps-map', plugins_url('front.js', __FILE__)); } }
/** * Output the styles and scripts necessary * * @param boolean $force Will be empty string when passed by `wp_enqueue_scripts`, but will be `true` when passed by `wunderground_print_scripts` * @return [type] [description] */ function print_scripts($force = false) { global $post, $pagenow; // Is the widget active? $widget = is_active_widget(false, false, 'wunderground_forecast_widget') ? true : false; // Check if the content has the shortcode $content = false; if (!empty($post->post_content) && function_exists('has_shortcode') && has_shortcode($post->post_content, 'wunderground')) { $content = true; } $admin = is_admin() && in_array($pagenow, array('widgets.php', 'customize.php')); if ($admin || $widget || $content || $force === true) { // Only show the front-end display on the front-end if (!$admin) { wp_enqueue_style('wunderground', plugins_url('assets/css/wunderground.css', Wunderground_Plugin::$file), array('dashicons'), Wunderground_Plugin::version); } else { // And the backend on the backend wp_enqueue_style('wunderground-admin', plugins_url('assets/css/admin.css', Wunderground_Plugin::$file)); } // If using SCRIPT_DEBUG, don't use the minified version. $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('wunderground-widget', plugins_url('assets/js/widget' . $min . '.js', Wunderground_Plugin::$file), array('jquery-ui-autocomplete'), Wunderground_Plugin::version); wp_localize_script('wunderground-widget', 'WuWidget', array('apiKey' => esc_attr(Wunderground_Plugin::$api_key), '_wpnonce' => wp_create_nonce('wunderground-aq'), 'ajaxurl' => admin_url('admin-ajax.php'), 'is_admin' => is_admin(), 'subdomain' => wunderground_get_subdomain())); } }
public static function frontend_scripts_register() { global $post; global $contact_people_page_id; if (is_admin()) { return; } global $is_IE; $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; $_upload_dir = wp_upload_dir(); wp_register_style('people_contact_style', PEOPLE_CONTACT_CSS_URL . '/style' . $suffix . '.css'); if (file_exists($_upload_dir['basedir'] . '/sass/wp_contact_people' . $suffix . '.css')) { wp_register_style('wp_contact_people', str_replace(array('http:', 'https:'), '', $_upload_dir['baseurl']) . '/sass/wp_contact_people' . $suffix . '.css'); } if ($is_IE) { wp_register_script('respondjs', PEOPLE_CONTACT_JS_URL . '/respond-ie.js'); } if ($post && ($contact_people_page_id == $post->ID || has_shortcode($post->post_content, 'people_contacts'))) { self::add_google_fonts(); wp_enqueue_style('people_contact_style'); wp_enqueue_style('wp_contact_people'); wp_enqueue_script('jquery'); wp_enqueue_script('respondjs'); add_action('wp_head', array('People_Contact_Hook_Filter', 'fix_window_console_ie')); add_action('wp_head', array('People_Contact_Hook_Filter', 'frontend_footer_scripts')); } }
function acf_contact_display_form_head() { global $post; if (has_shortcode($post->post_content, 'acf_contact')) { acf_form_head(); } }
function enqueue_video_expander_scripts() { global $post; if (has_shortcode($post->post_content, 'video-expander')) { wp_enqueue_script('videoexpander-js'); wp_enqueue_style('videoexpander-css'); } }
function custom_shortcode_scripts() { global $post; global $JSON_RENDERED_FORM; if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'JSON_form')) { $JSON_RENDERED_FORM->render_form(); } }
function drstk_video_shortcode_scripts() { global $post; if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'drstk_collection_playlist')) { wp_register_script('drstk_jwplayer', plugins_url('/assets/js/jwplayer/jwplayer.js', dirname(__FILE__)), array(), $VERSION, false); wp_enqueue_script('drstk_jwplayer'); } }
public function __construct() { global $post; if (is_page() && has_shortcode($post->post_content, 'jazel-calculator')) { $this->setup_shortcode(); add_action('wp_enqueue_scripts', [$this, 'enqueue_resources']); } }
static function enqueue_script() { global $post; if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'lmcsearchbox')) { wp_register_script('lmc_search_script', plugins_url() . '/lmc-search-plugin/lmc.js', array('jquery')); wp_enqueue_script('lmc_search_script'); } }
function web_body_class($c) { global $post; if (isset($post->post_content) && has_shortcode($post->post_content, 'vc_row')) { $c[] = 'visual-composer-active'; } return $c; }
function bootstrap_shortcodes_popover_script() { global $post; if (has_shortcode($post->post_content, 'popover')) { // Bootstrap popover js wp_enqueue_script('bootstrap-shortcodes-popover', BS_SHORTCODES_URL . 'js/bootstrap-shortcodes-popover.js', array('jquery'), false, true); } }
public function body_class($classes) { global $post; if (listify_is_job_manager_archive() && 'side' == $this->position() && $this->display() && !(is_page_template('page-templates/template-home.php') || is_page_template('page-templates/template-full-width-blank.php')) && !has_shortcode($post->post_content, 'jobs')) { $classes[] = 'fixed-map'; } return $classes; }
/** * Force the frontend scripts to load on pages with the shortcodes * * @since 1.0 */ public function force_frontend_scripts($ret) { global $post; if (has_shortcode($post->post_content, 'affiliate_area_creatives') || has_shortcode($post->post_content, 'affiliate_area_graphs') || has_shortcode($post->post_content, 'affiliate_area_referrals') || has_shortcode($post->post_content, 'affiliate_area_settings') || has_shortcode($post->post_content, 'affiliate_area_stats') || has_shortcode($post->post_content, 'affiliate_area_urls') || has_shortcode($post->post_content, 'affiliate_area_visits')) { $ret = true; } return $ret; }
/** * Enqueue css stylesheet and some script */ function script_and_style() { global $post; if (isset($post->post_content) and has_shortcode($post->post_content, 'ctimeline')) { /* wp_enqueue_script( 'csstimeline_script', plugins_url('js/csstimeline_script.js', __FILE__), 'jquery'); */ wp_enqueue_style('csstimeline_style', plugins_url('css/csstimeline_style.css', __FILE__)); } }