本文整理汇总了PHP中do_shortcode_tag函数的典型用法代码示例。如果您正苦于以下问题:PHP do_shortcode_tag函数的具体用法?PHP do_shortcode_tag怎么用?PHP do_shortcode_tag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_shortcode_tag函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: from_slideshow
/**
* 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;
}
示例2: getFeaturedAudio
public static function getFeaturedAudio()
{
$featured_audio = null;
if (preg_match_all('/' . get_shortcode_regex() . '/s', get_the_content(), $matches, PREG_SET_ORDER)) {
foreach ($matches as $shortcode) {
if ('audio' === $shortcode[2] or 'playlist' === $shortcode[2]) {
$featured_audio = trim(do_shortcode_tag($shortcode));
if ($featured_audio) {
break;
}
}
}
}
return $featured_audio;
}
示例3: get_post_galleries
/**
* Retrieves galleries from the passed post's content.
*
* @since 3.6.0
*
* @param int|WP_Post $post Post ID or object.
* @param bool $html Optional. Whether to return HTML or data in the array. Default true.
* @return array A list of arrays, each containing gallery data and srcs parsed
* from the expanded shortcode.
*/
function get_post_galleries($post, $html = true)
{
if (!($post = get_post($post))) {
return array();
}
if (!has_shortcode($post->post_content, 'gallery')) {
return array();
}
$galleries = array();
if (preg_match_all('/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $shortcode) {
if ('gallery' === $shortcode[2]) {
$srcs = array();
$gallery = do_shortcode_tag($shortcode);
if ($html) {
$galleries[] = $gallery;
} else {
preg_match_all('#src=([\'"])(.+?)\\1#is', $gallery, $src, PREG_SET_ORDER);
if (!empty($src)) {
foreach ($src as $s) {
$srcs[] = $s[2];
}
}
$data = shortcode_parse_atts($shortcode[3]);
$data['src'] = array_values(array_unique($srcs));
$galleries[] = $data;
}
}
}
}
/**
* Filter the list of all found galleries in the given post.
*
* @since 3.6.0
*
* @param array $galleries Associative array of all found post galleries.
* @param WP_Post $post Post object.
*/
return apply_filters('get_post_galleries', $galleries, $post);
}
示例4: from_gallery
/**
* If a gallery is detected, then get all the images from it.
*/
static function from_gallery($post_id)
{
$images = array();
$post = get_post($post_id);
if (!empty($post->post_password)) {
return $images;
}
if (false === strpos($post->post_content, '[gallery')) {
return false;
}
// no gallery - bail
$permalink = get_permalink($post->ID);
// CATS: All your base are belong to us
$old_post = $GLOBALS['post'];
$GLOBALS['post'] = $post;
$old_shortcodes = $GLOBALS['shortcode_tags'];
$GLOBALS['shortcode_tags'] = array('gallery' => $old_shortcodes['gallery']);
// Find all the galleries
preg_match_all('/' . get_shortcode_regex() . '/s', $post->post_content, $gallery_matches, PREG_SET_ORDER);
foreach ($gallery_matches as $gallery_match) {
$gallery = do_shortcode_tag($gallery_match);
// Um... no images in the gallery - bail
if (false === ($pos = stripos($gallery, '<img'))) {
continue;
}
preg_match_all('/<img\\s+[^>]*src=([\'"])([^\'"]*)\\1/', $gallery, $image_match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
$a_pos = 0;
foreach ($image_match[2] as $src) {
list($raw_src) = explode('?', $src[0]);
// pull off any Query string (?w=250)
$raw_src = wp_specialchars_decode($raw_src);
// rawify it
$raw_src = esc_url_raw($raw_src);
// clean it
$a_pos = strrpos(substr($gallery, 0, $src[1]), '<a', $a_pos);
// is there surrounding <a>?
if (false !== $a_pos && preg_match('/<a\\s+[^>]*href=([\'"])([^\'"]*)\\1/', $gallery, $href_match, 0, $a_pos)) {
$href = wp_specialchars_decode($href_match[2]);
$href = esc_url_raw($href);
} else {
// CATS: You have no chance to survive make your time
$href = $raw_src;
}
$a_pos = $src[1];
$images[] = array('type' => 'image', 'from' => 'gallery', 'src' => $raw_src, 'href' => $permalink);
}
}
// Captain: For great justice
$GLOBALS['shortcode_tags'] = $old_shortcodes;
$GLOBALS['post'] = $old_post;
return $images;
}
示例5: presscore_search_post_galleries
/**
* Recursively search for gallery shortcodes in given content.
*
* @since 1.0.0
*
* @param string $content Target content
* @param boolean $html If true - return array of galleries html
* @param integer $num Number of galleries to search
* @param array $galleries Base galleries array
* @return array Found galleries array
*/
function presscore_search_post_galleries($content = '', $html = true, $num = 0, $galleries = array())
{
if (preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $shortcode) {
if ('gallery' === $shortcode[2]) {
$srcs = array();
$gallery = do_shortcode_tag($shortcode);
if ($html) {
$galleries[] = $gallery;
} else {
preg_match_all('#src=([\'"])(.+?)\\1#is', $gallery, $src, PREG_SET_ORDER);
if (!empty($src)) {
foreach ($src as $s) {
$srcs[] = $s[2];
}
}
$data = shortcode_parse_atts($shortcode[3]);
$data['src'] = array_values(array_unique($srcs));
$galleries[] = $data;
}
}
if ($num && count($galleries) >= $num) {
break;
}
if (!empty($shortcode[5])) {
$galleries = presscore_search_post_galleries($shortcode[5], $html, $num, $galleries);
}
}
}
return $galleries;
}
示例6: get_post_galleries
/**
* Retrieve galleries from the passed post's content
*
* @since 3.6.0
*
* @param mixed $post Optional. Post ID or object.
* @param boolean $html Whether to return HTML or data in the array
* @return array A list of arrays, each containing gallery data and srcs parsed
* from the expanded shortcode
*/
function get_post_galleries($post, $html = true)
{
if (!($post = get_post($post))) {
return array();
}
if (!has_shortcode($post->post_content, 'gallery')) {
return array();
}
$galleries = array();
if (preg_match_all('/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $shortcode) {
if ('gallery' === $shortcode[2]) {
$srcs = array();
$count = 1;
$gallery = do_shortcode_tag($shortcode);
if ($html) {
$galleries[] = $gallery;
} else {
preg_match_all('#src=([\'"])(.+?)\\1#is', $gallery, $src, PREG_SET_ORDER);
if (!empty($src)) {
foreach ($src as $s) {
$srcs[] = $s[2];
}
}
$data = shortcode_parse_atts($shortcode[3]);
$data['src'] = array_values(array_unique($srcs));
$galleries[] = $data;
}
}
}
}
return apply_filters('get_post_galleries', $galleries, $post);
}
示例7: gallery_images
/**
* Find gallery shortcodes in the post. Build Open Graph protocol image results.
*
* @since 1.1.9
* @param stdClass $post current post object
* @return array array of arrays containing Open Graph protocol image markup
*/
public static function gallery_images($post)
{
global $shortcode_tags;
$og_images = array();
if (!(isset($shortcode_tags['gallery']) && isset($post->post_content) && $post->post_content)) {
return $og_images;
}
$first_gallery = strpos($post->post_content, '[gallery');
if ($first_gallery === false) {
return $og_images;
}
// use regex finder with only the gallery shortcode
$old_shortcodes = $shortcode_tags;
$shortcode_tags = array('gallery' => $shortcode_tags['gallery']);
// find all the gallery shortcodes in the post content
preg_match_all('/' . get_shortcode_regex() . '/s', $post->post_content, $galleries, PREG_SET_ORDER, $first_gallery);
// reset
$shortcode_tags = $old_shortcodes;
foreach ($galleries as $gallery_shortcode) {
// request the full-sized image
if (empty($gallery_shortcode[3])) {
$gallery_shortcode[3] = ' size="full"';
} else {
// break it down
$parsed_attributes = shortcode_parse_atts($gallery_shortcode[3]);
// add new attribute or override existing
$parsed_attributes['size'] = 'full';
// build it up again
$attr_str = '';
foreach ($parsed_attributes as $attribute => $value) {
$attr_str .= ' ' . $attribute . '="' . $value . '"';
}
unset($parsed_attributes);
if ($attr_str) {
$gallery_shortcode[3] = $attr_str;
}
unset($attr_str);
}
// pass the shortcode through all filters and actors
$gallery_html = do_shortcode_tag($gallery_shortcode);
if (!$gallery_html) {
continue;
}
$gallery_html = strip_tags($gallery_html, '<img>');
if (!$gallery_html) {
continue;
}
$first_image = strpos($gallery_html, '<img');
if ($first_image === false) {
continue;
}
preg_match_all('/<img[^>]+>/i', $gallery_html, $images, PREG_PATTERN_ORDER, $first_image);
unset($gallery_html);
if (!(is_array($images) && is_array($images[0]))) {
continue;
}
$images = $images[0];
foreach ($images as $image) {
preg_match_all('/(src|width|height)="([^"]*)"/i', $image, $image_attributes, PREG_SET_ORDER);
$og_image = array();
foreach ($image_attributes as $parsed_attributes) {
if ($parsed_attributes[1] === 'src') {
$url = esc_url_raw(wp_specialchars_decode($parsed_attributes[2]), array('http', 'https'));
if ($url) {
$og_image['url'] = $url;
}
unset($url);
} else {
if ($parsed_attributes[1] === 'width' || $parsed_attributes[1] === 'height') {
$pixels = absint($parsed_attributes[2]);
if ($pixels > 0) {
$og_image[$parsed_attributes[1]] = $pixels;
}
unset($pixels);
}
}
}
if (!isset($og_image['url']) || isset($og_image['width']) && $og_image['width'] < self::MIN_IMAGE_DIMENSION || isset($og_image['height']) && $og_image['height'] < self::MIN_IMAGE_DIMENSION) {
continue;
}
$og_images[] = $og_image;
unset($og_image);
}
}
return $og_images;
}
示例8: get_content_galleries
/**
* Check the content blob for galleries and return their image srcs
*
* @since 3.6.0
*
* @param string $content A string which might contain image data.
* @param boolean $html Whether to return HTML or data
* @param boolean $remove Optional. Whether to remove the found data from the passed content.
* @param int $limit Optional. The number of galleries to return
* @return array A list of galleries, which in turn are a list of their srcs in order
*/
function get_content_galleries(&$content, $html = true, $remove = false, $limit = 0)
{
$galleries = array();
if (preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER) && !empty($matches)) {
foreach ($matches as $shortcode) {
if ('gallery' === $shortcode[2]) {
$srcs = array();
$count = 1;
if ($remove) {
$content = str_replace($shortcode[0], '', $content, $count);
}
$data = shortcode_parse_atts($shortcode[3]);
$gallery = do_shortcode_tag($shortcode);
if ($html) {
$galleries[] = $gallery;
} else {
preg_match_all('#src=([\'"])(.+?)\\1#is', $gallery, $src, PREG_SET_ORDER);
if (!empty($src)) {
foreach ($src as $s) {
$srcs[] = $s[2];
}
}
$data['src'] = array_values(array_unique($srcs));
$galleries[] = $data;
}
if ($limit > 0 && count($galleries) >= $limit) {
break;
}
}
}
}
return apply_filters('content_galleries', $galleries, $content);
}
示例9: strip_first_button_shortcode
protected function strip_first_button_shortcode(&$content = null)
{
$button = '';
if (has_shortcode($content, 'dt_button') && '1' == $this->atts['style']) {
// search button shortcode in content
if (preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER) && !empty($matches)) {
foreach ($matches as $shortcode) {
if ('dt_button' === $shortcode[2]) {
$button = do_shortcode_tag($shortcode);
$button = '<div class="shortcode-action-container action-button">' . $button . '</div>';
$content = str_replace($shortcode[0], '', $content);
break;
}
}
}
}
return $button;
}
示例10: duena_featured_gallery
function duena_featured_gallery()
{
$pattern = get_shortcode_regex();
if (preg_match("/{$pattern}/s", get_the_content(), $match) && 'gallery' == $match[2]) {
add_filter('shortcode_atts_gallery', 'duena_gallery_atts');
echo do_shortcode_tag($match);
}
}
示例11: shortcode
public function shortcode($atts, $content = null)
{
$default_atts = array('style' => '0', 'background' => 'plain', 'content_size' => 'normal', 'text_align' => 'left', 'animation' => 'none', 'line' => '1');
$attributes = shortcode_atts($default_atts, $atts);
$attributes['animation'] = in_array($attributes['animation'], array('none', 'scale', 'fade', 'left', 'right', 'bottom', 'top')) ? $attributes['animation'] : $default_atts['animation'];
$attributes['style'] = in_array($attributes['style'], array('1', '0')) ? $attributes['style'] : $default_atts['style'];
$attributes['background'] = in_array($attributes['background'], array('no', 'plain', 'fancy')) ? $attributes['background'] : $default_atts['background'];
$attributes['content_size'] = in_array($attributes['content_size'], array('normal', 'small', 'big')) ? $attributes['content_size'] : $default_atts['content_size'];
$attributes['text_align'] = in_array($attributes['text_align'], array('left', 'center', 'centre')) ? $attributes['text_align'] : $default_atts['text_align'];
$attributes['line'] = apply_filters('dt_sanitize_flag', $attributes['line']);
$container_classes = array('shortcode-action-box');
$content_classes = array('shortcode-action-container');
$media = '';
// container classes
switch ($attributes['style']) {
case '1':
$container_classes[] = 'box-style-table';
break;
default:
$container_classes[] = 'table';
}
switch ($attributes['background']) {
case 'fancy':
$container_classes[] = 'shortcode-action-bg';
$container_classes[] = 'block-style-widget';
break;
case 'plain':
$container_classes[] = 'shortcode-action-bg';
$container_classes[] = 'plain-bg';
}
if (in_array($attributes['text_align'], array('center', 'centre'))) {
$container_classes[] = 'text-centered';
}
if (!$attributes['line']) {
$container_classes[] = 'no-line';
}
if ('none' != $attributes['animation']) {
switch ($attributes['animation']) {
case 'scale':
$container_classes[] = 'scale-up';
break;
case 'fade':
$container_classes[] = 'fade-in';
break;
case 'left':
$container_classes[] = 'right-to-left';
break;
case 'right':
$container_classes[] = 'left-to-right';
break;
case 'bottom':
$container_classes[] = 'top-to-bottom';
break;
case 'top':
$container_classes[] = 'bottom-to-top';
break;
}
$container_classes[] = 'animate-element';
}
// content classes
switch ($attributes['content_size']) {
case 'small':
$content_classes[] = 'text-small';
break;
case 'big':
$content_classes[] = 'text-big';
}
$button = '';
if (has_shortcode($content, 'dt_button') && '1' == $attributes['style']) {
// search button shortcode in content
if (preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER) && !empty($matches)) {
foreach ($matches as $shortcode) {
if ('dt_button' === $shortcode[2]) {
$button = do_shortcode_tag($shortcode);
$button = '<div class="shortcode-action-container action-button">' . $button . '</div>';
$content = str_replace($shortcode[0], '', $content);
break;
}
}
}
}
// $content = strip_shortcodes( $content );
$output = sprintf('<section class="%s"><div class="%s">%s</div>%s</section>', esc_attr(implode(' ', $container_classes)), esc_attr(implode(' ', $content_classes)), do_shortcode(shortcode_unautop(wpautop($content))), $button);
return $output;
}
示例12: shortcode_hack_extra_escape_escaped_shortcodes_and_parse
/**
* This is a combination of this class's shortcode_hack_extra_escape_escaped_shortcodes()
* and do_shortcode_tag() for performance reasons so that we don't have to run some regex twice.
*
* @param array $match Regular expression match array.
*
* @return string|false False on failure, otherwise a parse shortcode tag.
*/
function shortcode_hack_extra_escape_escaped_shortcodes_and_parse($match)
{
$match[0] = $this->shortcode_hack_extra_escape_escaped_shortcodes($match);
return do_shortcode_tag($match);
}
示例13: manual_process
function manual_process($user_id, $content, $dataonly = false)
{
$user = get_userdata($user_id);
if ($user->ID) {
$GLOBALS['wlm_shortcode_user'] = $user;
$pattern = get_shortcode_regex();
preg_match_all('/' . $pattern . '/s', $content, $matches, PREG_SET_ORDER);
if (is_array($matches) && count($matches)) {
$data = array();
foreach ($matches as $match) {
$scode = $match[2];
$code = $match[0];
if (isset($this->shortcode_functions[$scode])) {
if (!isset($data[$code])) {
$data[$code] = do_shortcode_tag($match);
}
}
}
if ($dataonly == false) {
$content = str_replace(array_keys($data), $data, $content);
} else {
$content = $data;
}
}
}
return $content;
}