could you figure out why I'm unable to get shortcode filters applied in ajax inclusion of posts?
Let me explain better: I've managed to include a post from within another post, through admin-ajax.php, as recommended in the famous 5 tips.
Obviously I don't want to display the shortcode tags, nor I'd like to strip them, so I'm echoing
At this point, the post gallery gets rendered but unfiltered, even though I'm running the "Cleaner Gallery" plugin, which starts with
add_filter( 'post_gallery', 'cleaner_gallery', 10, 2 ); and succesfully works in normal (non-ajax) posts.
I've been trying to debug this issue by replacing
$output = apply_filters('post_gallery', '', $attr); if ( $output != '' ) return $output;
$output = apply_filters('post_gallery', '', $attr); echo 'FILTERED OUTPUT = '.$output.' !'; if ( $output != '' ) return $output;
inside the function gallery_shortcode($attr) located in wp-includes/media.php. It seems that it runs twice, but in ajax inclusions the output is empty at first time and then it's not filtered.
Well, in all effect it happens that also the "2nd round" echoed output I mentioned remains empty when setting again add_filter before do_shortcode; otherwise it's shown (but, as I said, unfiltered).
I've also tried to track it with
echo has_filter('post_gallery'); echo current_filter();
and I've discovered that has returns always 1, while current first returns 'post-gallery' as expected, and then it gets overwritten by the '*wp_ajax_nopriv_etc*' hook, which is required to handle requests with admin-ajax.php but it's actually an action and not a filter. (?!?)
I've also tried without success to hack the cleaner gallery plugin, in order to make it directly run the shortcode without filtering the default function, removed the originary shortcode and added that new one. It works like a charm for normal posts, but it seems there is no way to implement the plugin in ajax requests.
I'm getting more and more confused. Please help me!
(also posted on the WP.org forums)