当前位置: 首页>>代码示例>>PHP>>正文


PHP strip_shortcodes函数代码示例

本文整理汇总了PHP中strip_shortcodes函数的典型用法代码示例。如果您正苦于以下问题:PHP strip_shortcodes函数的具体用法?PHP strip_shortcodes怎么用?PHP strip_shortcodes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了strip_shortcodes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: widget

 /**
  * Displays the Widget
  *
  */
 function widget($args, $instance)
 {
     extract($args);
     extract($instance);
     if (is_multisite()) {
         switch_to_blog($blog_id);
     }
     $output = '';
     global $wpdb;
     $request = $wpdb->prepare("SELECT " . $wpdb->prefix . "posts.*\n                   FROM " . $wpdb->prefix . "posts\n                   WHERE post_type='{$post_type}' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 0,%d", (int) $limit);
     $results = $wpdb->get_results($request);
     $results = $wpdb->get_results($request);
     if (!empty($results)) {
         $output = '<ul>';
         foreach ($results as $post) {
             $post_link = get_permalink($post->ID);
             if (!empty($post->post_excerpt)) {
                 $excerpt = $post->post_excerpt;
             } else {
                 $excerpt = $post->post_content;
                 $excerpt = strip_shortcodes($excerpt);
                 $excerpt = strip_tags($excerpt);
             }
             $excerpt = $this->truncate_string($excerpt, $excerpt_length);
             $image = "";
             if (has_post_thumbnail($post->ID)) {
                 $thumb_id = get_post_thumbnail_id($post->ID);
                 $image_data = wp_get_attachment_image_src($thumb_id, 'full');
                 if (is_array($image_data)) {
                     $image_src = plugins_url('timthumb.php', __FILE__) . "?src=" . $image_data[0] . "&w={$imagew}&h={$imageh}&zc=1&a=t";
                     $image = "<img src='{$image_src}' alt='{$post->post_title}' />";
                 }
             }
             $template = trim($template);
             if (empty($template)) {
                 $output .= '<li>';
                 $output .= '<a rel="bookmark" href="' . $post_link . '"><strong class="title">' . $post->post_title . '</strong></a>';
                 $output .= '</li>';
             } else {
                 $tokens = array("{title}", "{link}", "{image}", "{excerpt}");
                 $data = array($post->post_title, $post_link, $image, $excerpt);
                 $matches = null;
                 $returnValue = preg_match_all('/%%(\\w+)%%/', $template, $matches);
                 if (is_array($matches[1])) {
                     foreach ($matches[1] as $customfield) {
                         $tokens[] = "%%{$customfield}%%";
                         $data[] = get_post_meta($post->ID, $customfield, true);
                     }
                 }
                 $output .= '<li>' . str_replace($tokens, $data, $template) . '</li>';
             }
         }
         $output .= '</ul>';
     }
     if (is_multisite()) {
         restore_current_blog();
     }
     echo $before_widget . $before_title . $title . $after_title;
     echo $output . $after_widget;
 }
开发者ID:Wikipraca,项目名称:Wikipraca-WikiSquare,代码行数:64,代码来源:latest_posts_multisite.php

示例2: porto_get_excerpt

function porto_get_excerpt($limit = 45, $more_link = true)
{
    global $porto_settings;
    if (!$limit) {
        $limit = 45;
    }
    if (has_excerpt()) {
        $content = strip_tags(strip_shortcodes(get_the_excerpt()));
    } else {
        $content = strip_tags(strip_shortcodes(get_the_content()));
    }
    $content = explode(' ', $content, $limit);
    if (count($content) >= $limit) {
        array_pop($content);
        if ($more_link) {
            $content = implode(" ", $content) . '... ';
        } else {
            $content = implode(" ", $content) . ' [...]';
        }
    } else {
        $content = implode(" ", $content);
    }
    if ($porto_settings['blog-excerpt-type'] == 'html') {
        $content = apply_filters('the_content', $content);
        $content = do_shortcode($content);
    }
    if ($more_link) {
        $content .= ' <a class="read-more" href="' . esc_url(apply_filters('the_permalink', get_permalink())) . '">' . __('read more', 'porto') . ' <i class="fa fa-angle-right"></i></a>';
    }
    if ($porto_settings['blog-excerpt-type'] != 'html') {
        $content = '<p class="post-excerpt">' . $content . '</p>';
    }
    return $content;
}
开发者ID:prosenjit-itobuz,项目名称:Unitee,代码行数:34,代码来源:post.php

示例3: smart_excerpt

/**
 * Smart Excerpt
 *
 * Returns an excerpt which is not longer than the given length and always
 * ends with a complete sentence. If first sentence is longer than length,
 * it will add the standard ellipsis… Length is the number of characters.
 *
 * Usage: <?php smart_excerpt(450); >
 *
 * http://www.distractedbysquirrels.com/blog/wordpress-improved-dynamic-excerpt
 */
function smart_excerpt($length, $postId = false)
{
    if ($postId) {
        $post = get_post($postId);
        $text = $post->post_excerpt;
    } else {
        global $post;
        $text = $post->post_excerpt;
    }
    if ('' == $text) {
        if ($postId) {
            $text = $post->post_content;
        } else {
            $text = get_the_content('');
        }
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
    }
    $text = strip_shortcodes($text);
    $text = wp_strip_all_tags($text, true);
    if (empty($length)) {
        $length = 300;
    }
    $text = substr($text, 0, $length);
    $excerpt = nucleus_reverse_strrchr($text, '.', 1);
    if ($excerpt) {
        echo apply_filters('the_excerpt', $excerpt);
    } else {
        echo apply_filters('the_excerpt', $text . '…');
    }
}
开发者ID:rgfx,项目名称:Nucleus,代码行数:42,代码来源:extras.php

示例4: remove_shortcode_from_index

function remove_shortcode_from_index($content)
{
    if (is_home()) {
        $content = strip_shortcodes($content);
    }
    return $content;
}
开发者ID:bangjojo,项目名称:wp,代码行数:7,代码来源:filters.php

示例5: mantra_trim_excerpt

/**
 * Allows post excerpts to contain HTML tags
 * @since mantra 1.8.7
 * @return string Excerpt with most HTML tags intact
 */
function mantra_trim_excerpt($text)
{
    global $mantra_excerptwords;
    global $mantra_excerptcont;
    global $mantra_excerptdots;
    $raw_excerpt = $text;
    if ('' == $text) {
        //Retrieve the post content.
        $text = get_the_content('');
        //Delete all shortcode tags from the content.
        $text = strip_shortcodes($text);
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]&gt;', $text);
        $allowed_tags = '<a>,<img>,<b>,<strong>,<ul>,<li>,<i>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<pre>,<code>,<em>,<u>,<br>,<p>';
        $text = strip_tags($text, $allowed_tags);
        $words = preg_split("/[\n\r\t ]+/", $text, $mantra_excerptwords + 1, PREG_SPLIT_NO_EMPTY);
        if (count($words) > $mantra_excerptwords) {
            array_pop($words);
            $text = implode(' ', $words);
            $text = $text . ' ' . $mantra_excerptdots . ' <a href="' . get_permalink() . '">' . $mantra_excerptcont . ' <span class="meta-nav">&rarr; </span>' . '</a>';
        } else {
            $text = implode(' ', $words);
        }
    }
    return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
开发者ID:rzb,项目名称:boletos2,代码行数:31,代码来源:theme-loop.php

示例6: sb_cl_get_the_excerpt

function sb_cl_get_the_excerpt($id = false)
{
    global $post;
    $old_post = $post;
    if ($id != $post->ID) {
        $post = get_page($id);
    }
    if (!($excerpt = trim($post->post_excerpt))) {
        $excerpt = $post->post_content;
        if (!($more_pos = strpos($excerpt, '<!--more-->'))) {
            if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
                $excerpt = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($excerpt);
            }
            $excerpt = strip_shortcodes($excerpt);
            $excerpt = apply_filters('the_content', $excerpt);
            $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
            $excerpt = strip_tags($excerpt);
            $excerpt_length = apply_filters('excerpt_length', 55);
            $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
            $words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
            if (count($words) > $excerpt_length) {
                array_pop($words);
                $excerpt = implode(' ', $words);
                $excerpt = $excerpt . $excerpt_more;
            } else {
                $excerpt = implode(' ', $words);
            }
        } else {
            $excerpt = substr($excerpt, 0, $more_pos);
        }
    }
    $post = $old_post;
    return $excerpt;
}
开发者ID:elliottoman,项目名称:shero2016,代码行数:34,代码来源:sb_child_list.php

示例7: fb_strip_and_format_desc

function fb_strip_and_format_desc($post)
{
    $desc_no_html = "";
    $desc_no_html = strip_shortcodes($desc_no_html);
    // Strip shortcodes first in case there is HTML inside the shortcode
    $desc_no_html = wp_strip_all_tags($desc_no_html);
    // Strip all html
    $desc_no_html = trim($desc_no_html);
    // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case
    // Check if empty, may be that the strip functions above made excerpt empty, doubhtful but we want to be 100% sure.
    if (empty($desc_no_html)) {
        $desc_no_html = $post->post_content;
        // Start over, this time with the post_content
        $desc_no_html = strip_shortcodes($desc_no_html);
        // Strip shortcodes first in case there is HTML inside the shortcode
        $desc_no_html = str_replace(']]>', ']]&gt;', $desc_no_html);
        // Angelo Recommendation, if for some reason ]]> happens to be in the_content, rare but We've seen it happen
        $desc_no_html = wp_strip_all_tags($desc_no_html);
        $excerpt_length = apply_filters('excerpt_length', 55);
        $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
        $desc_no_html = wp_trim_words($desc_no_html, $excerpt_length, $excerpt_more);
        $desc_no_html = trim($desc_no_html);
        // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case
    }
    $desc_no_html = str_replace(array("\r\n", "\r", "\n"), ' ', $desc_no_html);
    // I take it Facebook doesn't like new lines?
    return $desc_no_html;
}
开发者ID:hscale,项目名称:webento,代码行数:28,代码来源:fb-open-graph.php

示例8: easy_event_the_excerpt

/**
 * Custom excerpt
 *
 * @param $post_excerpt
 *
 * @return mixed|string
 */
function easy_event_the_excerpt($post_excerpt)
{
    $post_id = get_the_ID();
    $post = get_post($post_id);
    $excerpt_temp = $post->post_excerpt;
    if ($excerpt_temp == '') {
        $excerpt_temp = get_post_meta($post_id, 'easy_event_description', true);
    }
    if ($excerpt_temp == '') {
        $excerpt_temp = strip_tags($post->post_content);
    }
    $excerpt_temp = strip_shortcodes($excerpt_temp);
    /**
     * Excerpt length
     */
    $excerpt_length = get_option('easy_event_excerpt_length');
    if ($excerpt_length == false) {
        $excerpt_length = 250;
    }
    $excerpt_length += 5;
    if (mb_strlen($excerpt_temp) > $excerpt_length) {
        $subex = mb_substr($excerpt_temp, 0, $excerpt_length - 5);
        $exwords = explode(' ', $subex);
        $excut = -mb_strlen($exwords[count($exwords) - 1]);
        if ($excut < 0) {
            return mb_substr($subex, 0, $excut) . '[...]';
        } else {
            return $subex . '[...]';
        }
    } else {
        return $excerpt_temp;
    }
}
开发者ID:tutv95,项目名称:easy-events,代码行数:40,代码来源:functions.php

示例9: clean_description

 /**
  * Clean post description text in preparation for Open Graph protocol description or Facebook post caption|description
  *
  * @since 1.1
  * @uses strip_shortcodes()
  * @uses wp_trim_words()
  * @param string $description description text
  * @return string description text passed through WordPress Core description cleaners, possibly trimmed
  */
 public static function clean_description($description, $trimmed = true)
 {
     $description = trim($description);
     if (!$description) {
         return '';
     }
     // basic filters from wp_trim_excerpt() that should apply to both excerpt and content
     // note: the_content filter is so polluted with extra third-party stuff we purposely avoid to better represent page content
     $description = strip_shortcodes($description);
     // remove any shortcodes that may exist, such as an image macro
     $description = str_replace(']]>', ']]&gt;', $description);
     $description = trim($description);
     if (!$description) {
         return '';
     }
     if ($trimmed) {
         // use the built-in WordPress function for localized support of words vs. characters
         // pass in customizations based on WordPress with publisher overrides
         $description = wp_trim_words($description, apply_filters('facebook_excerpt_length', apply_filters('excerpt_length', 55)), apply_filters('facebook_excerpt_more', __('&hellip;')));
     } else {
         $description = wp_strip_all_tags($description);
     }
     if ($description) {
         return $description;
     }
     return '';
 }
开发者ID:batruji,项目名称:metareading,代码行数:36,代码来源:open-graph-protocol.php

示例10: fb_description

function fb_description()
{
    global $post;
    if (!empty($post->post_excerpt)) {
        $description = $post->post_excerpt;
    } else {
        $description = trim(strip_shortcodes(strip_tags($post->post_content)));
        $pos0 = strpos($description, '.') + 1;
        $pos0 = $pos0 === false ? strlen($description) : $pos0;
        $pos = strpos(substr($description, $pos0), '.');
        if ($pos < 0 || $pos === false) {
            $pos = strlen($description);
        } else {
            $pos = $pos + $pos0;
        }
        $description = str_replace("\n", "", substr($description, 0, $pos));
        $description = str_replace("\r", "", $description);
        $description = str_replace("\"", "'", $description);
        $description = nl2br($description);
    }
    if (is_front_page()) {
        $description = get_bloginfo('description');
    }
    return $description;
}
开发者ID:nixter,项目名称:d.school,代码行数:25,代码来源:facebook-opengraph.php

示例11: register_meta_tags

 public function register_meta_tags()
 {
     add_action('wp_head', function () {
         if (is_singular() && false == post_password_required()) {
             if ('' == ($description = get_the_excerpt())) {
                 $description = wp_trim_words(esc_html(strip_shortcodes(get_the_content())), 20, '...');
             }
         } elseif (is_category() && '' != category_description()) {
             $description = category_description();
         } elseif (is_tag() && '' != term_description()) {
             $description = term_description();
         } else {
             $description = get_bloginfo('description');
         }
         $description = esc_attr($description);
         echo "<meta name=\"description\" content=\"{$description}\" />\n";
         echo "<meta name=\"og:description\" content=\"{$description}\" />\n";
         if (is_singular() && false == post_password_required() && has_post_thumbnail()) {
             list($image, $width, $height) = wp_get_attachment_image_src(get_post_thumbnail_id(), 'facebook');
         } else {
             $image = apply_filters('', $this->get_theme_assets_url() . '/images/logo-fb.png');
         }
         $image = esc_url($image);
         echo "<meta name=\"og:image\" content=\"{$image}\" />\n";
         echo "<meta name=\"twitter:image\" content=\"{$image}\" />\n";
     });
 }
开发者ID:shtrihstr,项目名称:wpk15-theme-wpkit,代码行数:27,代码来源:Initialization.php

示例12: jl_brd_dashboard_recent_drafts

function jl_brd_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $drafts_query = new WP_Query(array('post_type' => 'any', 'post_status' => array('draft', 'pending'), 'posts_per_page' => 150, 'orderby' => 'modified', 'order' => 'DESC'));
        $drafts =& $drafts_query->posts;
    }
    if ($drafts && is_array($drafts)) {
        $list = array();
        foreach ($drafts as $draft) {
            $url = get_edit_post_link($draft->ID);
            $title = _draft_or_post_title($draft->ID);
            $last_id = get_post_meta($draft->ID, '_edit_last', true);
            $last_user = get_userdata($last_id);
            $last_modified = '<i>' . esc_html($last_user->display_name) . '</i>';
            $item = '<h4><a href="' . $url . '" title="' . sprintf(__('Edit ?%s?'), esc_attr($title)) . '">' . esc_html($title) . '</a>' . '<abbr> ' . $draft->post_status . ' ' . $draft->post_type . '</abbr>' . '<abbr style="display:block;margin-left:0;">' . sprintf(__('Last edited by %1$s on %2$s at %3$s'), $last_modified, mysql2date(get_option('date_format'), $draft->post_modified), mysql2date(get_option('time_format'), $draft->post_modified)) . '</abbr></h4>';
            if ($the_content = preg_split('#\\s#', strip_shortcodes(strip_tags($draft->post_content), 11, PREG_SPLIT_NO_EMPTY))) {
                $item .= '<p>' . join(' ', array_slice($the_content, 0, 10)) . (10 < count($the_content) ? '&hellip;' : '') . '</p>';
            }
            $list[] = $item;
        }
        ?>
	<ul>
		<li><?php 
        echo join("</li>\n<li>", $list);
        ?>
</li>
	</ul>
<?php 
    } else {
        _e('There are no drafts at the moment');
    }
}
开发者ID:aarontgrogg,项目名称:aarontgrogg,代码行数:32,代码来源:better-recent-drafts.php

示例13: postExcerptCallback

 function postExcerptCallback($matches)
 {
     $pageContent = strip_tags($this->page->post_content);
     //return "blah" .$exLength;
     if ($this->page->post_excerpt == "") {
         //if there's no excerpt applied to the post, extract one
         //$postCallback->pageContent = strip_tags($page->post_content);
         //$str = preg_replace_callback('#\[ *post_excerpt *(length=[\'|\"]([^\'\"]*)[\'|\"])? *\]#', array(&$postCallback, 'postExcerptCallback'), $str);
         if (isset($matches[2])) {
             $exLength = intval($matches[2]);
         } else {
             $exLength = 250;
         }
         //return "blah";
         if (strlen($pageContent) > $exLength) {
             return strip_shortcodes(substr($pageContent, 0, $exLength)) . "...";
             //clean up and return excerpt
         } else {
             return strip_shortcodes($pageContent);
         }
     } else {
         //if there is a post excerpt just use it and don't generate our own
         /* if(isset($matches[2])){//uncomment this if/else statement if you want the manual excerpt to be trimmed to the passed in length
            $exLength = intval($matches[2]);
            return substr($this->page->post_excerpt, 0, $exLength);
            }else{
            return $this->page->post_excerpt;
            } */
         return $this->page->post_excerpt;
     }
 }
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:31,代码来源:APLCallback.php

示例14: swp_get_excerpt_by_id

function swp_get_excerpt_by_id($post_id)
{
    // Check if the post has an excerpt
    if (has_excerpt()) {
        $the_post = get_post($post_id);
        //Gets post ID
        $the_excerpt = $the_post->post_excerpt;
        // If not, let's create an excerpt
    } else {
        $the_post = get_post($post_id);
        //Gets post ID
        $the_excerpt = $the_post->post_content;
        //Gets post_content to be used as a basis for the excerpt
    }
    $excerpt_length = 100;
    //Sets excerpt length by word count
    $the_excerpt = strip_tags(strip_shortcodes($the_excerpt));
    //Strips tags and images
    $the_excerpt = str_replace(']]>', ']]&gt;', $the_excerpt);
    $the_excerpt = strip_tags($the_excerpt);
    $excerpt_length = apply_filters('excerpt_length', 100);
    $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    $words = preg_split("/[\n\r\t ]+/", $the_excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if (count($words) > $excerpt_length) {
        array_pop($words);
        // array_push($words, '…');
        $the_excerpt = implode(' ', $words);
    }
    $the_excerpt = preg_replace("/\r|\n/", "", $the_excerpt);
    return $the_excerpt;
}
开发者ID:warfare-plugins,项目名称:social-warfare,代码行数:31,代码来源:excerpt.php

示例15: de_excerpt

function de_excerpt($excerpt, $content, $length = 0)
{
    if (strlen($excerpt)) {
        $length = $length == 0 ? strlen($excerpt) : $length;
        if (strlen($excerpt) > $length) {
            $result = mb_substr($excerpt, 0, $length, 'UTF-8');
            $result .= '...';
        } else {
            $result = $excerpt;
        }
    } else {
        $content = trim(strip_shortcodes($content));
        if (strlen($content) > strlen(strip_shortcodes($content))) {
            $length = $length == 0 ? strlen($content) : $length;
            $content = de_excerpt('', $content, $length);
        }
        $content = strip_tags($content);
        $length = $length == 0 ? strlen($content) : $length;
        if (strlen($content) > $length) {
            $result = mb_substr($content, 0, $length, 'UTF-8');
            $result .= '...';
        } else {
            $result = $content;
        }
    }
    return $result;
}
开发者ID:JerryXie96,项目名称:PBSMUNC2013WebSite,代码行数:27,代码来源:main.php


注:本文中的strip_shortcodes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。