/** * 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 paragraph_not_contains_element($paragraph) { if (preg_match_all('/' . get_shortcode_regex() . '/s', $paragraph, $matches, PREG_SET_ORDER)) { return false; } return true; }
/** * Short Code Detach Function To UpLoad JS And CSS */ function PGP_ShortCodeDetect() { global $wp_query; $Posts = $wp_query->posts; $Pattern = get_shortcode_regex(); foreach ($Posts as $Post) { if (strpos($Post->post_content, 'PGP')) { /** * js scripts */ wp_enqueue_script('jquery'); /** * Load Light Box 3 Swipebox JS CSS */ wp_enqueue_style('PGP-swipe-css1', PGP_PLUGIN_URL . 'lightbox/swipebox/swipebox.css'); wp_enqueue_script('PGP-swipe-js1', PGP_PLUGIN_URL . 'lightbox/swipebox/jquery.swipebox.min.js', array('jquery')); /** * css scripts */ wp_enqueue_style('PGP-boot-strap-css', PGP_PLUGIN_URL . 'css/bootstrap.css'); wp_enqueue_style('PGP-Main-css', PGP_PLUGIN_URL . 'css/main.css'); /** * font awesome css */ wp_enqueue_style('PGP-font-awesome-4', PGP_PLUGIN_URL . 'css/font-awesome-latest/css/font-awesome.min.css'); break; } //end of if } //end of foreach }
/** * WordPress has a few shortcodes for handling embedding media: [audio], [video], and [embed]. This * method figures out the shortcode used in the content. Once it's found, the appropriate method for * the shortcode is executed. * * @return void * @access public * @since 1.0.0 */ public function do_shortcode_media() { /* Finds matches for shortcodes in the content. */ preg_match_all('/' . get_shortcode_regex() . '/s', $this->content, $matches, PREG_SET_ORDER); /* If matches are found, loop through them and check if they match one of WP's media shortcodes. */ if (!empty($matches)) { foreach ($matches as $shortcode) { if (!in_array($shortcode[2], $this->valid_shortcodes)) { continue; } /* Call the method related to the specific shortcode found and break out of the loop. */ if (in_array($shortcode[2], array('playlist', 'embed', $this->type))) { call_user_func(array($this, "do_{$shortcode[2]}_shortcode_media"), $shortcode); break; } /* Check for Jetpack audio/video shortcodes. */ if (in_array($shortcode[2], array('blip.tv', 'dailymotion', 'flickr', 'ted', 'vimeo', 'vine', 'youtube', 'wpvideo', 'soundcloud', 'bandcamp'))) { $this->do_jetpack_shortcode_media($shortcode); break; } /* Call shortcode handler for shortcode not handled before. */ $callback = apply_filters('hybrid_media_grabber_do_shortcode_callback', array($this, 'do_default_shortcode_media'), $shortcode[2]); call_user_func($callback, $shortcode); } } }
function pl_get_attachment_ids_from_gallery() { global $post; if ($post != null) { $attachment_ids = array(); $pattern = get_shortcode_regex(); $ids = array(); //finds the "gallery" shortcode, puts the image ids in an associative array: $matches[3] if (preg_match_all('/' . $pattern . '/s', $post->post_content, $matches)) { $count = count($matches[3]); //in case there is more than one gallery in the post. for ($i = 0; $i < $count; $i++) { $atts = shortcode_parse_atts($matches[3][$i]); if (isset($atts['ids'])) { $attachment_ids = explode(',', $atts['ids']); $ids = array_merge($ids, $attachment_ids); } } } return $ids; } else { $ids = array(); return $ids; } }
/** * Loop over all the content in the main loop and do a request for all the items present so that we're only getting * a few API hits instead of all of them. Then, when anything else calls `easyazon_get_item` it will get the cached * data and not have to hit the API. */ public static function prefetch_items() { global $wp_query; $identifiers = array_fill_keys(array_keys(easyazon_get_locales()), array()); $preparsed = array(); $shortcodes = easyazon_get_shortcodes(); foreach ($wp_query->posts as $post) { preg_match_all('/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $shortcode = trim($match[2]); if (in_array($shortcode, $shortcodes)) { $attributes = shortcode_parse_atts($match[3]); $locale = isset($attributes['locale']) ? $attributes['locale'] : false; $identifier = isset($attributes['identifier']) ? $attributes['identifier'] : false; if (!is_array($preparsed[$shortcode])) { $preparsed[$shortcode] = array(); } $preparsed[$shortcode][] = $attributes; if ($locale && $identifier) { $identifiers[$locale][] = $identifier; } } } } foreach ($identifiers as $locale => $queryable) { $cached_items = easyazon_get_items($queryable, $locale); } self::$preparsed_shortcodes = $preparsed; }
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; } }
/** * Get Image from Post core file * * This file contains all the logic required for the plugin * * @package Get Post Gallery Images * @copyright Copyright (c) 2013, Sierj Khaletski * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer) * * @since Get Post Gallery Images 0.1 */ function get_post_gallery_images_gpgi() { $attachment_ids = array(); $pattern = get_shortcode_regex(); $images = array(); if (preg_match_all('/' . $pattern . '/s', get_the_content(), $matches)) { //finds the "gallery" shortcode and puts the image ids in an associative array at $matches[3] $count = count($matches[3]); //in case there is more than one gallery in the post. for ($i = 0; $i < $count; $i++) { $atts = shortcode_parse_atts($matches[3][$i]); if (isset($atts['ids'])) { $attachment_ids = explode(',', $atts['ids']); $attachementsCount = count($attachment_ids); if ($attachementsCount > 0) { for ($j = 0; $j < $attachementsCount; $j++) { $image = array(); $attachmentId = intval($attachment_ids[$j]); $image['id'] = $attachmentId; $image['full'] = wp_get_attachment_image_src($attachmentId, 'full'); $image['medium'] = wp_get_attachment_image_src($attachmentId, 'medium'); $image['thumbnail'] = wp_get_attachment_image_src($attachmentId, 'thumbnail'); array_push($images, $image); } } } } } return $images; }
/** * 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; }
function lidd_mc_detect_shortcode() { global $post; $pattern = get_shortcode_regex(); // Check the content. return preg_match_all('/' . $pattern . '/s', $post->post_content, $matches) && array_key_exists(2, $matches) && (in_array('mortgagecalculator', $matches[2]) || in_array('rmc', $matches[2])) || strpos($post->post_content, 'lidd_mc_form') !== false; }
/** * Weblizar Image Gallery Shortcode Detect Function */ function WRGF_ShortCodeDetect() { global $wp_query; $Posts = $wp_query->posts; $Pattern = get_shortcode_regex(); /** * js scripts */ wp_enqueue_script('jquery'); wp_enqueue_script('wrgf-hover-pack-js', WRGF_PLUGIN_URL . 'js/hover-pack.js', array('jquery')); /** * Load Light Box 4 Swipebox JS CSS */ wp_enqueue_style('wl-wrgf-swipe-css', WRGF_PLUGIN_URL . 'lightbox/swipebox/swipebox.css'); wp_enqueue_script('wl-wrgf-swipe-js', WRGF_PLUGIN_URL . 'lightbox/swipebox/jquery.swipebox.js'); /** * css scripts */ wp_enqueue_style('wrgf-hover-pack-css', WRGF_PLUGIN_URL . 'css/hover-pack.css'); wp_enqueue_style('wrgf-boot-strap-css', WRGF_PLUGIN_URL . 'css/bootstrap.css'); wp_enqueue_style('wrgf-img-gallery-css', WRGF_PLUGIN_URL . 'css/img-gallery.css'); /** * font awesome css */ wp_enqueue_style('wrgf-font-awesome-4', WRGF_PLUGIN_URL . 'css/font-awesome-latest/css/font-awesome.min.css'); /** * envira & isotope js */ wp_enqueue_script('wrgf_masonry', WRGF_PLUGIN_URL . 'js/masonry.pkgd.min.js', array('jquery')); wp_enqueue_script('wrgf_imagesloaded', WRGF_PLUGIN_URL . 'js/imagesloaded.pkgd.min.js', array('jquery')); }
function shortcodesOnPost() { // get the post data global $post; // get the shortcode regex $pattern = get_shortcode_regex(); // run regex on the content to find all the shortcodes being used preg_match_all('/' . $pattern . '/s', $post->post_content, $matches); // only if there are matches if (!empty($matches)) { //loop through the results //$matches[3] contains the atts //$matches[2] contains the shortcode name //$matches[5] contains the shortcode Data foreach ($matches[3] as $key => $arg) { $shortcode = $matches[2][$key]; //check to see if the found code is mine :) if ($shortcode == 'myShortCode') { // Parse the attributes to an array $data = shortcode_parse_atts($arg); // get the shortcode content $content = $matches[5][$key]; // wp_enqueue_script // wp_enqueue_style // for the specific shortcodes used } } } }
function callback($path = '', $blog_id = 0) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } if (!current_user_can('edit_posts')) { return new WP_Error('unauthorized', 'Your token must have permission to post on this blog.', 403); } $args = $this->query_args(); $shortcode = trim($args['shortcode']); // Quick validation - shortcodes should always be enclosed in brackets [] if (!wp_startswith($shortcode, '[') || !wp_endswith($shortcode, ']')) { return new WP_Error('invalid_shortcode', 'The shortcode parameter must begin and end with square brackets.', 400); } // Make sure only one shortcode is being rendered at a time $pattern = get_shortcode_regex(); preg_match_all("/{$pattern}/s", $shortcode, $matches); if (count($matches[0]) > 1) { return new WP_Error('invalid_shortcode', 'Only one shortcode can be rendered at a time.', 400); } $render = $this->process_render(array($this, 'do_shortcode'), $shortcode); // if nothing happened, then the shortcode does not exist. if ($shortcode == $render['result']) { return new WP_Error('invalid_shortcode', 'The requested shortcode does not exist.', 400); } // our output for this endpoint.. $return['shortcode'] = $shortcode; $return['result'] = $render['result']; $return = $this->add_assets($return, $render['loaded_scripts'], $render['loaded_styles']); return $return; }
public static function content($content) { global $post; if (!self::allowed($post)) { return $content; } self::setup_links($post); if (!self::$links) { return $content; } $header_replacements = array(); $link_replacements = array(); $other_replacements = array(); $shortcode_replacements = array(); $filtered = $content; preg_match_all('/' . get_shortcode_regex() . '/', $filtered, $scodes); if (!empty($scodes[0])) { $shortcode_replacements = self::gen_replacements($scodes[0], 'shortcode'); $filtered = self::replace($shortcode_replacements, $filtered); } preg_match_all('/<h[1-6][^>]*>.+?<\\/h[1-6]>/iu', $filtered, $headers); if (!empty($headers[0])) { $header_replacements = self::gen_replacements($headers[0], 'header'); $filtered = self::replace($header_replacements, $filtered); } preg_match_all('/<(img|input)(.*?) \\/?>/iu', $filtered, $others); if (!empty($others[0])) { $other_replacements = self::gen_replacements($others[0], 'others'); $filtered = self::replace($other_replacements, $filtered); } foreach (self::$links as $count => $l) { if (apply_filters('seoal_should_continue', false, $l, $count)) { continue; } preg_match_all('/<a(.*?)href="(.*?)"(.*?)>(.*?)<\\/a>/iu', $filtered, $links); if (!empty($links[0])) { $start = count($link_replacements); $tmp = self::gen_replacements($links[0], 'links', $start); $filtered = self::replace($tmp, $filtered); $link_replacements = array_merge($link_replacements, $tmp); } $regex = self::get_kw_regex($l); $url = self::get_link_url($l); $max = self::get_link_max($l); if (!$regex || !$url || !$max || $url == self::$permalink && !self::self_links_allowed($l)) { continue; } $cls = apply_filters('seoal_link_class', 'auto-link', $l); $target = self::get_link_target($l); $replace = sprintf('$1<a href="%1$s" title="$2" target="%2$s" %3$s %4$s>$2</a>$3', esc_url($url), esc_attr($target), $cls ? 'class="' . esc_attr($cls) . '"' : '', self::is_nofollow($l) ? 'rel="nofollow"' : ''); $filtered = preg_replace($regex, $replace, $filtered, absint($max)); } $filtered = apply_filters('seoal_pre_replace', $filtered, $post); $filtered = self::replace_bak($shortcode_replacements, $filtered); $filtered = self::replace_bak($header_replacements, $filtered); $filtered = self::replace_bak($link_replacements, $filtered); $filtered = self::replace_bak($other_replacements, $filtered); return apply_filters('seoal_post_replace', $filtered, $post); }
/** * Get the gallery shortcode from the project content. */ function argent_get_gallery() { global $post; $pattern = get_shortcode_regex(); if (preg_match_all('/' . $pattern . '/s', $post->post_content, $matches) && array_key_exists(2, $matches) && in_array('gallery', $matches[2])) { return $matches; } }
/** * Extract any shortcodes by removing all other text from the provided content */ function extract_shortcodes($content) { $c = ''; preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER); foreach ($matches as $shortcode) { $c .= $shortcode[0]; } return $c; }
protected function get_shortcodes($text, $single = false) { $regex = get_shortcode_regex(); preg_match_all('/' . $regex . '/s', $text, $matches); if (isset($matches[0])) { return $single ? $matches[0][0] : $matches[0]; } return null; }
function do_shortcode($content) { global $shortcode_tags; if (empty($shortcode_tags) || !is_array($shortcode_tags)) { return $content; } $pattern = get_shortcode_regex(); return preg_replace_callback('/' . $pattern . '/s', 'do_shortcode_tag', $content); }
/** * If a slideshow is embedded within a post, then parse out the images involved and return them */ static function from_slideshow($post_id, $width = 200, $height = 200) { $images = array(); $post = get_post($post_id); if (!$post) { return $images; } if (!empty($post->post_password)) { return $images; } if (false === has_shortcode($post->post_content, 'slideshow')) { return $images; // no slideshow - bail } $permalink = get_permalink($post->ID); // Mechanic: Somebody set us up the bomb $old_post = $GLOBALS['post']; $GLOBALS['post'] = $post; $old_shortcodes = $GLOBALS['shortcode_tags']; $GLOBALS['shortcode_tags'] = array('slideshow' => $old_shortcodes['slideshow']); // Find all the slideshows preg_match_all('/' . get_shortcode_regex() . '/sx', $post->post_content, $slideshow_matches, PREG_SET_ORDER); ob_start(); // The slideshow shortcode handler calls wp_print_scripts and wp_print_styles... not too happy about that foreach ($slideshow_matches as $slideshow_match) { $slideshow = do_shortcode_tag($slideshow_match); if (false === ($pos = stripos($slideshow, 'jetpack-slideshow'))) { // must be something wrong - or we changed the output format in which case none of the following will work continue; } $start = strpos($slideshow, '[', $pos); $end = strpos($slideshow, ']', $start); $post_images = json_decode(wp_specialchars_decode(str_replace("'", '"', substr($slideshow, $start, $end - $start + 1)), ENT_QUOTES)); // parse via JSON foreach ($post_images as $post_image) { if (!($post_image_id = absint($post_image->id))) { continue; } $meta = wp_get_attachment_metadata($post_image_id); // Must be larger than 200x200 (or user-specified) if (!isset($meta['width']) || $meta['width'] < $width) { continue; } if (!isset($meta['height']) || $meta['height'] < $height) { continue; } $url = wp_get_attachment_url($post_image_id); $images[] = array('type' => 'image', 'from' => 'slideshow', 'src' => $url, 'src_width' => $meta['width'], 'src_height' => $meta['height'], 'href' => $permalink); } } ob_end_clean(); // Operator: Main screen turn on $GLOBALS['shortcode_tags'] = $old_shortcodes; $GLOBALS['post'] = $old_post; return $images; }
function ro_theme_get_shortcode_from_content($param) { global $post; $pattern = get_shortcode_regex(); $content = $post->post_content; if (preg_match_all('/' . $pattern . '/s', $content, $matches) && array_key_exists(2, $matches) && in_array($param, $matches[2])) { $key = array_search($param, $matches[2]); return $matches[0][$key]; } }
function wpcis_my_shortcode_head() { global $posts; $pattern = get_shortcode_regex(); preg_match('/(\\[(creativeslider) id="([0-9]+)"\\])/s', $posts[0]->post_content, $matches); if (is_array($matches) && $matches[2] == 'creativeslider') { $slider_id = (int) $matches[3]; wpcis_enqueue_front_scripts($slider_id); } }
/** * @see CPAC_Column::get_raw_value() * @since 2.3.5 */ public function get_raw_value($post_id) { $content = get_post_field('post_content', $post_id); $pattern = get_shortcode_regex(); preg_match_all("/{$pattern}/s", $content, $matches); if (!isset($matches[2])) { return false; } return $matches[2]; }
function gallery_shortcode_exists() { global $post; # Check the content for an instance of [gallery] with or without arguments $pattern = get_shortcode_regex(); if (preg_match_all('/' . $pattern . '/s', $post->post_content, $matches) && array_key_exists(2, $matches) && in_array('gallery', $matches[2])) { return true; } # Sourced from http://codex.wordpress.org/Function_Reference/get_shortcode_regex }
/** * Get the current page description * * @param int $post_id * @return string $share_image */ function wolf_get_meta_description($post) { $excerpt = ''; $excerpt = sanitize_text_field($post->post_excerpt); if ('' == $excerpt) { $excerpt = strip_tags(preg_replace('/' . get_shortcode_regex() . '/i', '', $post->post_content)); $excerpt = preg_replace('/\\s+/', ' ', $excerpt); $excerpt = wolf_meta_sample(sanitize_text_field($excerpt)); } return $excerpt; }
/** * Remove the first instance of a [gallery] * shortcode from a block of content. * * This is intended to be a helper function that * can be filtered onto the_content() for use in * the loop with the "gallery" post format. * * @since 2.3.0 * * @param string $content Content of post * @return string $content Filtered content of post */ function themeblvd_content_format_gallery($content) { // Only continue if this is a "gallery" format post. if (!has_post_format('gallery')) { return $content; } $pattern = get_shortcode_regex(); if (preg_match("/{$pattern}/s", $content, $match) && 'gallery' == $match[2]) { $content = str_replace($match[0], '', $content); } return $content; }
function the_secondary_content($content) { $pattern = get_shortcode_regex(); if (preg_match_all('/' . $pattern . '/s', $content, $matches)) { foreach ($matches as $key => $match) { foreach ($match as $m) { $content = str_replace($m, do_shortcode($m), $content); } } } echo $content; }
function gdlr_fix_shortcodes($content) { global $shortcode_tags; // backup all shortcodes $orig_shortcode_tags = $shortcode_tags; // wrap p around non-autop shortcode $shortcode_tags = array('gdlr_text_align' => 'gdlr_text_align_shortcode', 'gdlr_accordion' => 'gdlr_accordion_shortcode', 'gdlr_toggle_box' => 'gdlr_toggle_box_shortcode', 'gdlr_process' => 'gdlr_process_shortcode', 'gdlr_price_table' => 'gdlr_price_table_shortcode', 'gdlr_tabs' => 'gdlr_tabs_shortcode', 'gdlr_tab' => 'gdlr_tab_shortcode', 'gdlr_button' => 'gdlr_button_shortcode', 'gdlr_heading' => 'gdlr_heading_shortcode', 'gdlr_divider' => 'gdlr_divider_shortcode', 'gdlr_circle_progress' => 'gdlr_circle_progress_shortcode', 'gdlr_stunning_text' => 'gdlr_stunning_text_shortcode', 'gdlr_skill_bar' => 'gdlr_skill_bar_shortcode', 'gdlr_row' => 'gdlr_row_shortcode', 'gdlr_column' => 'gdlr_column_shortcode', 'gdlr_frame' => 'gdlr_frame_shortcode', 'gdlr_image_link' => 'gdlr_image_link_shortcode', 'gdlr_space' => 'gdlr_space_shortcode', 'gdlr_quote' => 'gdlr_quote_shortcode', 'gdlr_dropcap' => 'gdlr_dropcap_shortcode', 'gdlr_icon' => 'gdlr_icon_shortcode', 'gdlr_notification' => 'gdlr_notification_shortcode', 'gdlr_box_icon' => 'gdlr_box_icon_shortcode', 'gdlr_styled_box' => 'gdlr_styled_box_shortcode', 'gdlr_testimonial' => 'gdlr_testimonial_shortcode', 'gdlr_personnel' => 'gdlr_personnel_shortcode', 'gdlr_blog' => 'gdlr_blog_shortcode', 'gdlr_portfolio' => 'gdlr_portfolio_shortcode', 'gdlr_page' => 'gdlr_page_shortcode', 'gdlr_post_slider' => 'gdlr_post_slider_shortcode', 'gdlr_video' => 'gdlr_video_shortcode', 'gallery' => 'gdlr_gallery_shortcode', 'gdlr_title' => 'gdlr_title_shortcode'); $pattern = '/' . get_shortcode_regex() . '/s'; $content = preg_replace($pattern, '<pre class="gdlr_rp">${0}gdlr_rp</pre>', $content); // return all shortcodes $shortcode_tags = $orig_shortcode_tags; return $content; }
function remove_gallery($content = null) { global $post; if (is_single() && is_main_query() && $post->post_type == 'post') { $pattern = get_shortcode_regex(); preg_match('/' . $pattern . '/s', $content, $matches); if (isset($matches[2]) && is_array($matches) && $matches[2] == 'gallery') { //shortcode is being used $content = str_replace($matches['0'], '', $content); } } return $content; }
/** * @param $post_id * * @return string|void */ public static function get_excerpt_by_id($post_id) { $the_post = get_post($post_id); $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt //kill shortcode $shortcode_pattern = get_shortcode_regex(); $the_excerpt = preg_replace('/' . $shortcode_pattern . '/', '', $the_excerpt); // kill tags $the_excerpt = strip_tags($the_excerpt); return esc_attr(substr($the_excerpt, 0, 200)); // to prevent meta from being broken by e.g "" }
function kt_get_all_attributes($tag, $text) { preg_match_all('/' . get_shortcode_regex() . '/s', $text, $matches); $out = array(); if (isset($matches[2])) { foreach ((array) $matches[2] as $key => $value) { if ($tag === $value) { $out[] = shortcode_parse_atts($matches[3][$key]); } } } return $out; }