admin管理员组文章数量:1391995
We have a custom plugin we developed for events that includes shortcodes to display feeds of events based on categories or tags. For some reason, we've noticed that from time to time when saving posts that contain the shortcode that pulls in the tag feed, it slows the save function down significantly, sometimes to the point that it actually times out. The shortcode itself works, but in testing, it seems like WordPress is actually trying to render it as part of the save process.
This is the code for the shortcode:
add_shortcode('event-tags', 'tags_shortcode');
function tags_shortcode($atts){
date_default_timezone_set(get_option('timezone_string'));
$atts = shortcode_atts( array(
'tag' => null,
'date' => date('m/d/Y'),
'span' => '+30 days',
'format' => 'list',
'show' =>null,
'free' => false
), $atts, 'show_events' );
$my_content = '';
if ( $atts['tag'] != null ) {
$tag = get_term_by('slug', $atts['tag'], 'post_tag');
if ( $tag != NULL ) {
$span_pieces = explode(' ', $atts['span']);
$how_many = $span_pieces[0];
$freq = $span_pieces[1];
$max_events = false;
$show_events = new Event();
if ( $atts['format'] != 'month' ) {
$today = $show_events->one_day_events( date('Y-m-d', strtotime($atts['date'])), $atts['format'], false, $atts['free'], $max_events, null, null, $tag->term_id, $atts['show'] );
if ( $today != NULL ) {
$my_content .= '<h3>'.date('l, F j, Y', strtotime($atts['date'])).'</h3>';
$my_content .= $today;
}
if ( $atts['span'] ) {
if ( $freq = 'days' ) {
for ( $i = 1; $i < str_replace('+', '', $how_many); $i++ ) {
$today = $show_events->one_day_events(date('Y-m-d', strtotime($atts['date'].' +'.$i.' day')), $atts['format'], false, $atts['free'], $max_events, null, null, $tag->term_id, $atts['show']);
if ( $today != NULL ) {
$my_content .= '<h3>'.date('l, F j, Y', strtotime($atts['date'].' +'.$i.' day')).'</h3>';
$my_content .= $today;
}
}
}
}
} else {
$my_content .= $show_events->calendar_events(date('m'),date('Y'), false, false, null, null, $tag->term_id, $atts['show']);
}
return $my_content;
}
}
}
Like I said, the shortcode works on the frontend, it's only causing an issue on the backend when saving a post that is using it. We also have some functionality that hooks into save_post and edit_post, but the way it is set up, it shouldn't be running on the posts that we are having this issue with.
本文标签: pluginsIssue Saving Posts That Contain Shortcode
版权声明:本文标题:plugins - Issue Saving Posts That Contain Shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744661750a2618286.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论