public function has_flowplayer_shortcode() { if (is_404() || isset($this->has_flowplayer_shortcode)) { return; } $post = get_queried_object(); $has_shortcode = array(); $shortcode_args = array(); if (isset($post->post_content)) { $shortcode_args = fp5_has_shortcode_arg($post->post_content, 'flowplayer'); if (is_array($shortcode_args)) { foreach ($shortcode_args as $key => $value) { if (isset($value['id'])) { $has_shortcode['id' . $value['id']] = $value['id']; } elseif (isset($value['playlist'])) { $has_shortcode['playlist' . $value['playlist']] = $value['playlist']; } elseif (!empty($value['mp4']) || !empty($value['webm']) || !empty($value['ogg']) || !empty($value['flash']) || !empty($value['hls'])) { $video_id = substr(md5(serialize($value)), 0, 5); $has_shortcode['video' . $video_id] = $video_id; } } } } else { global $wp_query; foreach ($wp_query->posts as $post) { $post_content = isset($post->post_content) ? $post->post_content : ''; $shortcode_args = fp5_has_shortcode_arg($post_content, 'flowplayer'); if (!$shortcode_args) { continue; } foreach ($shortcode_args as $key => $value) { if (isset($value['id'])) { $has_shortcode['id' . $value['id']] = $value['id']; } elseif (isset($value['playlist'])) { $has_shortcode['playlist' . $value['playlist']] = $value['playlist']; } elseif (!empty($value['mp4']) || !empty($value['webm']) || !empty($value['ogg']) || !empty($value['flash']) || !empty($value['hls'])) { $video_id = substr(md5(serialize($value)), 0, 5); $has_shortcode['video' . $video_id] = $video_id; } } } } $this->has_flowplayer_shortcode = array_filter($has_shortcode); }
/** * Whether the passed content contains the specified shortcode and return args * * @since 1.10.0 * * @param string $content Content to search for shortcodes. * @param string $tag Shortcode tag to check. * @return false|array */ function fp5_has_shortcode_arg($content, $tag) { if (false === strpos($content, '[')) { return false; } if (shortcode_exists($tag)) { preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER); if (empty($matches)) { return false; } $shortcode_arg = false; foreach ($matches as $shortcode) { if ($tag === $shortcode[2]) { $shortcode_arg[] = shortcode_parse_atts($shortcode[3]); } elseif (!empty($shortcode[5]) && has_shortcode($shortcode[5], $tag)) { $shortcode_arg = fp5_has_shortcode_arg($shortcode[5], $tag); } } return $shortcode_arg; } return false; }