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.