[wp-hackers] How to prevent multiple processing of shortcodes?

Kevinjohn Gallagher kevinjohngallagher at hotmail.com
Mon Jul 9 14:51:10 UTC 2012



No doubt there is a better WordPress way of doing it, but for one of my plugins I've had to do the same.
add a process check to do_shortcode()

function shortcode_counter(){ $shortcode_ran_before = true;}
add_action ('do_shortcode', 'shortcode_counter')

Then add in a check in your code to see if $shortcode_ran_before is true. If it has, don't fire your own action.
Thats probably a horrible, non-modern-programming way of doing things; but it'll work.


> Date: Mon, 9 Jul 2012 10:43:14 -0400
> From: mpwalsh8 at gmail.com
> To: wp-hackers at lists.automattic.com
> Subject: [wp-hackers] How to prevent multiple processing of shortcodes?
> 
> I am looking for some advice on how to prevent a shortcode from being
> processed multiple times.  I am trying to help a user of my WordPress
> Google Form plugin and figured out that another plugin is calling
> do_shortcode() as part of the wp_head action which causes my shortcode to
> be processed twice.  Because my shortcode uses the WordPress HTTP API to
> submit form data to Google Forms, processing the short code twice messes
> things up.  I am not sure if running do_shortcode() as part of wp_head is a
> bad idea, it seems to me like it is but I am sure there is a good reason
> for it.  So I am trying to update my plugin to deal with this situation.
> 
> Any recommendations or idea?  I thought about trying to use a transient to
> track when wp_remote_post() is called which might work for simple forms but
> since many Google Forms have more than one page, wp_remote_post() is called
> more than once and in theory could be called in unknown number of times
> since Google Forms support going back and forth through the pages.
> 
> Mike
> -- 
> Mike Walsh - mpwalsh8 at gmail.com
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
 		 	   		  


More information about the wp-hackers mailing list