本文整理汇总了PHP中wpseo_strip_shortcode函数的典型用法代码示例。如果您正苦于以下问题:PHP wpseo_strip_shortcode函数的具体用法?PHP wpseo_strip_shortcode怎么用?PHP wpseo_strip_shortcode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpseo_strip_shortcode函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: wpseo_replace_vars
/**
* @param string $string the string to replace the variables in.
* @param array $args the object some of the replacement values might come from, could be a post, taxonomy or term.
* @param array $omit variables that should not be replaced by this function.
* @return string
*/
function wpseo_replace_vars($string, $args, $omit = array())
{
$args = (array) $args;
$string = strip_tags($string);
// Let's see if we can bail super early.
if (strpos($string, '%%') === false) {
return trim(preg_replace('/\\s+/u', ' ', $string));
}
global $sep;
if (!isset($sep) || empty($sep)) {
$sep = '-';
}
$simple_replacements = array('%%sep%%' => $sep, '%%sitename%%' => get_bloginfo('name'), '%%sitedesc%%' => get_bloginfo('description'), '%%currenttime%%' => date('H:i'), '%%currentdate%%' => date('M jS Y'), '%%currentmonth%%' => date('F'), '%%currentyear%%' => date('Y'));
foreach ($simple_replacements as $var => $repl) {
$string = str_replace($var, $repl, $string);
}
// Let's see if we can bail early.
if (strpos($string, '%%') === false) {
return trim(preg_replace('/\\s+/u', ' ', $string));
}
global $wp_query;
$defaults = array('ID' => '', 'name' => '', 'post_author' => '', 'post_content' => '', 'post_date' => '', 'post_excerpt' => '', 'post_modified' => '', 'post_title' => '', 'taxonomy' => '', 'term_id' => '');
if (isset($args['post_content'])) {
$args['post_content'] = wpseo_strip_shortcode($args['post_content']);
}
if (isset($args['post_excerpt'])) {
$args['post_excerpt'] = wpseo_strip_shortcode($args['post_excerpt']);
}
$r = (object) wp_parse_args($args, $defaults);
$max_num_pages = 1;
if (!is_single()) {
$pagenum = get_query_var('paged');
if ($pagenum === 0) {
$pagenum = 1;
}
if (isset($wp_query->max_num_pages) && $wp_query->max_num_pages != '' && $wp_query->max_num_pages != 0) {
$max_num_pages = $wp_query->max_num_pages;
}
} else {
global $post;
$pagenum = get_query_var('page');
$max_num_pages = isset($post->post_content) ? substr_count($post->post_content, '<!--nextpage-->') : 1;
if ($max_num_pages >= 1) {
$max_num_pages++;
}
}
// Let's do date first as it's a bit more work to get right.
if ($r->post_date != '') {
$date = mysql2date(get_option('date_format'), $r->post_date);
} else {
if (get_query_var('day') && get_query_var('day') != '') {
$date = get_the_date();
} else {
if (single_month_title(' ', false) && single_month_title(' ', false) != '') {
$date = single_month_title(' ', false);
} else {
if (get_query_var('year') != '') {
$date = get_query_var('year');
} else {
$date = '';
}
}
}
}
$replacements = array('%%date%%' => $date, '%%searchphrase%%' => esc_html(get_query_var('s')), '%%page%%' => $max_num_pages > 1 && $pagenum > 1 ? sprintf($sep . ' ' . __('Page %d of %d', 'wordpress-seo'), $pagenum, $max_num_pages) : '', '%%pagetotal%%' => $max_num_pages, '%%pagenumber%%' => $pagenum);
if (isset($r->ID)) {
$replacements = array_merge($replacements, array('%%caption%%' => $r->post_excerpt, '%%category%%' => wpseo_get_terms($r->ID, 'category'), '%%excerpt%%' => !empty($r->post_excerpt) ? strip_tags($r->post_excerpt) : utf8_encode(substr(strip_shortcodes(strip_tags(utf8_decode($r->post_content))), 0, 155)), '%%excerpt_only%%' => strip_tags($r->post_excerpt), '%%focuskw%%' => wpseo_get_value('focuskw', $r->ID), '%%id%%' => $r->ID, '%%modified%%' => mysql2date(get_option('date_format'), $r->post_modified), '%%name%%' => get_the_author_meta('display_name', !empty($r->post_author) ? $r->post_author : get_query_var('author')), '%%tag%%' => wpseo_get_terms($r->ID, 'post_tag'), '%%title%%' => stripslashes($r->post_title), '%%userid%%' => !empty($r->post_author) ? $r->post_author : get_query_var('author')));
}
if (!empty($r->taxonomy)) {
$replacements = array_merge($replacements, array('%%category_description%%' => trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))), '%%tag_description%%' => trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))), '%%term_description%%' => trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))), '%%term_title%%' => $r->name));
}
foreach ($replacements as $var => $repl) {
if (!in_array($var, $omit)) {
$string = str_replace($var, $repl, $string);
}
}
if (strpos($string, '%%') === false) {
$string = preg_replace('/\\s+/u', ' ', $string);
return trim($string);
}
if (isset($wp_query->query_vars['post_type']) && preg_match_all('/%%pt_([^%]+)%%/u', $string, $matches, PREG_SET_ORDER)) {
$pt = get_post_type_object($wp_query->query_vars['post_type']);
$pt_plural = $pt_singular = $pt->name;
if (isset($pt->labels->singular_name)) {
$pt_singular = $pt->labels->singular_name;
}
if (isset($pt->labels->name)) {
$pt_plural = $pt->labels->name;
}
$string = str_replace('%%pt_single%%', $pt_singular, $string);
$string = str_replace('%%pt_plural%%', $pt_plural, $string);
}
if (preg_match_all('/%%cf_([^%]+)%%/u', $string, $matches, PREG_SET_ORDER)) {
global $post;
//.........这里部分代码省略.........
开发者ID:juslee,项目名称:e27,代码行数:101,代码来源:wpseo-functions.php
示例2: get_body
/**
* Retrieve the body from the post.
*
* @param object $post The post object.
*
* @return string The post content.
*/
function get_body($post)
{
// This filter allows plugins to add their content to the content to be analyzed.
$post_content = apply_filters('wpseo_pre_analysis_post_content', $post->post_content, $post);
// Strip shortcodes, for obvious reasons, if plugins think their content should be in the analysis, they should
// hook into the above filter.
$post_content = wpseo_strip_shortcode($post_content);
if (trim($post_content) == '') {
return '';
}
$htmdata3 = preg_replace('`<(?:\\x20*script|script).*?(?:/>|/script>)`', '', $post_content);
if ($htmdata3 == null) {
$htmdata3 = $post_content;
} else {
unset($post_content);
}
$htmdata4 = preg_replace('`<!--.*?-->`', '', $htmdata3);
if ($htmdata4 == null) {
$htmdata4 = $htmdata3;
} else {
unset($htmdata3);
}
$htmdata5 = preg_replace('`<(?:\\x20*style|style).*?(?:/>|/style>)`', '', $htmdata4);
if ($htmdata5 == null) {
$htmdata5 = $htmdata4;
} else {
unset($htmdata4);
}
return $htmdata5;
}
开发者ID:michalvittek,项目名称:wordpress-seo,代码行数:37,代码来源:class-metabox.php
示例3: get_body
/**
* Retrieve the body from the post.
*
* @param object $post The post object.
* @return string The post content.
*/
function get_body($post)
{
// Strip shortcodes, for obvious reasons
$origHtml = wpseo_strip_shortcode($post->post_content);
if (trim($origHtml) == '') {
return '';
}
$htmdata2 = preg_replace("/\n|\r/", " ", $origHtml);
if ($htmdata2 == null) {
$htmdata2 = $origHtml;
} else {
unset($origHtml);
}
$htmdata3 = preg_replace("/<( *script|script).*?(\\/>|\\/script>)/", "", $htmdata2);
if ($htmdata3 == null) {
$htmdata3 = $htmdata2;
} else {
unset($htmdata2);
}
$htmdata4 = preg_replace("/<!--.*?-->/", "", $htmdata3);
if ($htmdata4 == null) {
$htmdata4 = $htmdata3;
} else {
unset($htmdata3);
}
$htmdata5 = preg_replace("/<( *style|style).*?(\\/>|\\/style>)/", "", $htmdata4);
if ($htmdata5 == null) {
$htmdata5 = $htmdata4;
} else {
unset($htmdata4);
}
return $htmdata5;
}
开发者ID:macosxvn,项目名称:techheroes,代码行数:39,代码来源:class-metabox.php
示例4: wpseo_replace_vars
/**
* @param string $string the string to replace the variables in.
* @param array $args the object some of the replacement values might come from, could be a post, taxonomy or term.
* @param array $omit variables that should not be replaced by this function.
* @return string
*/
function wpseo_replace_vars( $string, $args, $omit = array() ) {
$args = (array) $args;
$string = strip_tags( $string );
// Let's see if we can bail super early.
if ( strpos( $string, '%%' ) === false ) {
return trim( preg_replace( '`\s+`u', ' ', $string ) );
}
global $sep;
if ( ! isset( $sep ) || empty( $sep ) ) {
$sep = '-';
}
$simple_replacements = array(
'%%sep%%' => $sep,
'%%sitename%%' => get_bloginfo( 'name' ),
'%%sitedesc%%' => get_bloginfo( 'description' ),
'%%currenttime%%' => date( get_option( 'time_format' ) ),
'%%currentdate%%' => date( get_option( 'date_format' ) ),
'%%currentday%%' => date( 'j' ),
'%%currentmonth%%' => date( 'F' ),
'%%currentyear%%' => date( 'Y' ),
);
foreach ( $simple_replacements as $var => $repl ) {
$string = str_replace( $var, $repl, $string );
}
// Let's see if we can bail early.
if ( strpos( $string, '%%' ) === false ) {
return trim( preg_replace( '`\s+`u', ' ', $string ) );
}
global $wp_query;
$defaults = array(
'ID' => '',
'name' => '',
'post_author' => '',
'post_content' => '',
'post_date' => '',
'post_excerpt' => '',
'post_modified' => '',
'post_title' => '',
'taxonomy' => '',
'term_id' => '',
'term404' => '',
);
if ( isset( $args['post_content'] ) ) {
$args['post_content'] = wpseo_strip_shortcode( $args['post_content'] );
}
if ( isset( $args['post_excerpt'] ) ) {
$args['post_excerpt'] = wpseo_strip_shortcode( $args['post_excerpt'] );
}
$r = (object) wp_parse_args( $args, $defaults );
$max_num_pages = 1;
if ( ! is_singular() ) {
$pagenum = get_query_var( 'paged' );
if ( $pagenum === 0 ) {
$pagenum = 1;
}
if ( isset( $wp_query->max_num_pages ) && $wp_query->max_num_pages != '' && $wp_query->max_num_pages != 0 ) {
$max_num_pages = $wp_query->max_num_pages;
}
}
else {
global $post;
$pagenum = get_query_var( 'page' );
$max_num_pages = ( isset( $post->post_content ) ) ? substr_count( $post->post_content, '<!--nextpage-->' ) : 1;
if ( $max_num_pages >= 1 ) {
$max_num_pages++;
}
}
// Let's do date first as it's a bit more work to get right.
if ( $r->post_date != '' ) {
$date = mysql2date( get_option( 'date_format' ), $r->post_date );
}
else {
if ( get_query_var( 'day' ) && get_query_var( 'day' ) != '' ) {
$date = get_the_date();
}
else {
if ( single_month_title( ' ', false ) && single_month_title( ' ', false ) != '' ) {
$date = single_month_title( ' ', false );
}
elseif ( get_query_var( 'year' ) != '' ) {
//.........这里部分代码省略.........
开发者ID:xiaoguizhidao,项目名称:autotech_design,代码行数:101,代码来源:wpseo-functions.php
示例5: replace
/**
* Replace `%%variable_placeholders%%` with their real value based on the current requested page/post/cpt/etc
*
* @param string $string the string to replace the variables in.
* @param array $args the object some of the replacement values might come from,
* could be a post, taxonomy or term.
* @param array $omit variables that should not be replaced by this function.
*
* @return string
*/
public function replace($string, $args, $omit = array())
{
$string = strip_tags($string);
// Let's see if we can bail super early.
if (strpos($string, '%%') === false) {
return wpseo_standardize_whitespace($string);
}
$args = (array) $args;
if (isset($args['post_content']) && !empty($args['post_content'])) {
$args['post_content'] = wpseo_strip_shortcode($args['post_content']);
}
if (isset($args['post_excerpt']) && !empty($args['post_excerpt'])) {
$args['post_excerpt'] = wpseo_strip_shortcode($args['post_excerpt']);
}
$this->args = (object) wp_parse_args($args, $this->defaults);
// Clean $omit array
if (is_array($omit) && $omit !== array()) {
$omit = array_map(array(__CLASS__, 'remove_var_delimiter'), $omit);
}
$replacements = array();
if (preg_match_all('`%%([^%]+(%%single)?)%%?`iu', $string, $matches)) {
$replacements = $this->set_up_replacements($matches, $omit);
}
/**
* Filter: 'wpseo_replacements' - Allow customization of the replacements before they are applied
*
* @api array $replacements The replacements
*/
$replacements = apply_filters('wpseo_replacements', $replacements);
// Do the actual replacements
if (is_array($replacements) && $replacements !== array()) {
$string = str_replace(array_keys($replacements), array_values($replacements), $string);
}
/**
* Filter: 'wpseo_replacements_final' - Allow overruling of whether or not to remove placeholders
* which didn't yield a replacement
*
* @example <code>add_filter( 'wpseo_replacements_final', '__return_false' );</code>
*
* @api bool $final
*/
if (apply_filters('wpseo_replacements_final', true) === true && (isset($matches[1]) && is_array($matches[1]))) {
// Remove non-replaced variables
$remove = array_diff($matches[1], $omit);
// Make sure the $omit variables do not get removed
$remove = array_map(array(__CLASS__, 'add_var_delimiter'), $remove);
$string = str_replace($remove, '', $string);
}
// Undouble separators which have nothing between them, i.e. where a non-replaced variable was removed
if (isset($replacements['%%sep%%']) && (is_string($replacements['%%sep%%']) && $replacements['%%sep%%'] !== '')) {
$q_sep = preg_quote($replacements['%%sep%%'], '`');
$string = preg_replace('`' . $q_sep . '(?:\\s*' . $q_sep . ')*`u', $replacements['%%sep%%'], $string);
}
// Remove superfluous whitespace
$string = wpseo_standardize_whitespace($string);
return trim($string);
}
开发者ID:CrankMaster336,项目名称:FFW-TR,代码行数:67,代码来源:class-wpseo-replace-vars.php
示例6: wpseo_replace_vars
function wpseo_replace_vars($string, $args, $omit = array())
{
$args = (array) $args;
$string = strip_tags($string);
// Let's see if we can bail super early.
if (strpos($string, '%%') === false) {
return trim(preg_replace('/\\s+/', ' ', $string));
}
$simple_replacements = array('%%sitename%%' => get_bloginfo('name'), '%%sitedesc%%' => get_bloginfo('description'), '%%currenttime%%' => date('H:i'), '%%currentdate%%' => date('M jS Y'), '%%currentmonth%%' => date('F'), '%%currentyear%%' => date('Y'));
foreach ($simple_replacements as $var => $repl) {
$string = str_replace($var, $repl, $string);
}
// Let's see if we can bail early.
if (strpos($string, '%%') === false) {
return trim(preg_replace('/\\s+/', ' ', $string));
}
global $wp_query;
$defaults = array('ID' => '', 'name' => '', 'post_author' => '', 'post_content' => '', 'post_date' => '', 'post_content' => '', 'post_excerpt' => '', 'post_modified' => '', 'post_title' => '', 'taxonomy' => '', 'term_id' => '');
$pagenum = get_query_var('paged');
if ($pagenum === 0) {
if ($wp_query->max_num_pages > 1) {
$pagenum = 1;
} else {
$pagenum = '';
}
}
if (isset($args['post_content'])) {
$args['post_content'] = wpseo_strip_shortcode($args['post_content']);
}
if (isset($args['post_excerpt'])) {
$args['post_excerpt'] = wpseo_strip_shortcode($args['post_excerpt']);
}
$r = (object) wp_parse_args($args, $defaults);
// Only global $post on single's, otherwise some expressions will return wrong results.
if (is_singular() || is_front_page() && 'posts' != get_option('show_on_front')) {
global $post;
}
// Let's do date first as it's a bit more work to get right.
if ($r->post_date != '') {
$date = mysql2date(get_option('date_format'), $r->post_date);
} else {
if (get_query_var('day') && get_query_var('day') != '') {
$date = get_the_date();
} else {
if (single_month_title(' ', false) && single_month_title(' ', false) != '') {
$date = single_month_title(' ', false);
} else {
if (get_query_var('year') != '') {
$date = get_query_var('year');
} else {
$date = '';
}
}
}
}
$replacements = array('%%date%%' => $date, '%%title%%' => stripslashes($r->post_title), '%%excerpt%%' => !empty($r->post_excerpt) ? strip_tags($r->post_excerpt) : substr(strip_shortcodes(strip_tags($r->post_content)), 0, 155), '%%excerpt_only%%' => strip_tags($r->post_excerpt), '%%category%%' => wpseo_get_terms($r->ID, 'category'), '%%category_description%%' => !empty($r->taxonomy) ? trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))) : '', '%%tag_description%%' => !empty($r->taxonomy) ? trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))) : '', '%%term_description%%' => !empty($r->taxonomy) ? trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))) : '', '%%term_title%%' => $r->name, '%%focuskw%%' => wpseo_get_value('focuskw', $r->ID), '%%tag%%' => wpseo_get_terms($r->ID, 'post_tag'), '%%modified%%' => mysql2date(get_option('date_format'), $r->post_modified), '%%id%%' => $r->ID, '%%name%%' => get_the_author_meta('display_name', !empty($r->post_author) ? $r->post_author : get_query_var('author')), '%%userid%%' => !empty($r->post_author) ? $r->post_author : get_query_var('author'), '%%searchphrase%%' => esc_html(get_query_var('s')), '%%page%%' => get_query_var('paged') != 0 ? 'Page ' . get_query_var('paged') . ' of ' . $wp_query->max_num_pages : '', '%%pagetotal%%' => $wp_query->max_num_pages > 1 ? $wp_query->max_num_pages : '', '%%pagenumber%%' => $pagenum, '%%caption%%' => $r->post_excerpt);
foreach ($replacements as $var => $repl) {
if (!in_array($var, $omit)) {
$string = str_replace($var, $repl, $string);
}
}
if (strpos($string, '%%') === false) {
$string = preg_replace('/\\s\\s+/', ' ', $string);
return trim($string);
}
if (preg_match_all('/%%cf_([^%]+)%%/', $string, $matches, PREG_SET_ORDER)) {
global $post;
foreach ($matches as $match) {
$string = str_replace($match[0], get_post_meta($post->ID, $match[1], true), $string);
}
}
$string = preg_replace('/\\s\\s+/', ' ', $string);
return trim($string);
}
开发者ID:vinvinh315,项目名称:maintainwebsolutions.com,代码行数:74,代码来源:wpseo-functions.php
注:本文中的wpseo_strip_shortcode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论