› Forums › Post Pay Counter PRO › Support › Post Pay Counter Pro – Flushing Rewrite Rules
We are based in Europe with a GMT+1/GMT+2 time zone - support replies may be delayed due to time zone differences with your country.
- This topic has 5 replies, 1 voice, and was last updated 9 years, 1 month ago by Serkan.
-
AuthorPosts
-
October 20, 2015 at 5:18 am #48103SerkanKeymaster
Hi Stefano,
I have come across a problem with Post Pay Counter Pro where it is clashing with another plugin and not allowing rewrite rules to be flushed.
The other plugin is rtMedia Pro. It adds more media functionality to Buddypress.
This problem started happening because recently rtMedia Pro released a new version etc.
So after upgrading rtMedia Pro, certain areas of the site started to break (blank white page). I installed Rewrite Rules Inspector and saw that there were a whole bunch of rewrite rules that weren’t able to be set (red).
So after hours of debugging, I discovered that the clash was happning with Post Pay Counter Pro.
If I disable Post Pay Counter Pro, all works (except I don’t have Post Pay Counter Pro aymore lol)I found in the code, the following two functions within ppcp_paypal_class.php…
/** * Adds plugin's IPN rewrite rule (ppcp/paypal). * * @access public * @since 1.3 */ static function ipn_add_rewrite_rule() { global $wp_rewrite; if( ! is_object( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite(); //Add IPN listener rule if not there already $rules = $wp_rewrite->wp_rewrite_rules(); if( ! isset( $rules['ppcp/paypal$'] ) ) { add_rewrite_rule( 'ppcp/paypal$', 'index.php?ppcp=paypal', 'top' ); $wp_rewrite->flush_rules(); } } /** * Deletes plugin's IPN rewrite rule (ppcp/paypal). * * @access public * @since 1.3.2 */ static function ipn_delete_rewrite_rule() { global $wp_rewrite; if( ! is_object( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite(); //Delete IPN listener rule if there $rules = $wp_rewrite->wp_rewrite_rules(); if( isset( $rules['ppcp/paypal$'] ) ) { unset( $rules['ppcp/paypal$'] ); $wp_rewrite->flush_rules(); } }
I don’t know if there are any other places in Post Pay Counter Pro where flushing rules is involved but I think this is where the problem is.
Can you please tell me how I can get by this issue and have both plugins (Post Pay Counter Pro and rtMedia) working together nicely.
Thank you
SerkanOctober 20, 2015 at 7:49 am #48109StefanoKeymasterHi Serkan,
I’m not sure (it could be a problem with my plugin), but since the issue started showing up after an update of the other plugin, could you please ask their support team what could have changed that affected this feature?Have a nice day,
StefanoOctober 20, 2015 at 2:56 pm #48126SerkanKeymasterHi Stefano,
Thanks for your response.Well, I think a lot changed with their plugin because they essentially took their 1 plugin with many different features, and split it up into 30+ plugins (one for each feature). They provided a migration tool that split it all up accordingly into 30+ individual plugins.
I will ask them, but I don’t know if they will be able to give me a clean cut answer.
I can tell you that their plugin creates quite a few different rewrite rules, and when I had your plugin and their plugin enabled at the same time, none of their rewrite rules were able to be created.
Btw, I wasn’t implying that it was a problem with your plugin, I just thought it would be easier to fix with your plugin.
Thanks again, I will contact them as well.
SerkanOctober 27, 2015 at 4:07 pm #48331SerkanKeymasterHi Stefano,
rtCamp has given me a response regarding this issue. Here it is…
Hi Serkan,
This is Ritesh from rtMedia team. I have checked Post Pay Counter Pro plugin’s code for rewrite rules in your site. First of all, it isn’t a proper way to add rewrite rules in WordPress.
//In post-pay-counter-pro.php file add_action( 'init', array( 'PPCP_paypal_functions', 'ipn_add_rewrite_rule' ) ); //In classes/PPCP_paypal_functions.php file static function ipn_add_rewrite_rule() { global $wp_rewrite; if( ! is_object( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite(); //Add IPN listener rule if not there already $rules = $wp_rewrite->wp_rewrite_rules(); if( ! isset( $rules['ppcp/paypal$'] ) ) { add_rewrite_rule( 'ppcp/paypal$', 'index.php?ppcp=paypal', 'top' ); $wp_rewrite->flush_rules(); } }
If you are familiar with WordPress ecosystem, look at the above code. This ipn_add_rewrite_rule function is bind to WordPress’ init hook with default priority which will be called on every page request and that function contains this line $wp_rewrite->flush_rules() which flushes the rewrite rules. If you comment that line, it will work all fine without any issue. This can only be fixed in Post Pay Counter Pro plugin.
In rtMedia, we too flush the rewrite rules but it’s only happen on new version update. I hope you understand my point here.
Thanks.
If I comment out the line
$wp_rewrite->flush_rules();
, do you think there will be any problem with Post Pay Counter not working correctly?Thanks
SerkanOctober 27, 2015 at 8:50 pm #48340StefanoKeymasterHi Serkan,
well, yes and no.WordPress advises not to flush rules on init (it’s a slow process and running it at each page load is not a good idea), but I don’t actually do that. That function runs on every page load, but it just checks whether PPC rewrite rules are correctly set up, and if yes it just doesn’t do anything. However, if it finds an issue, it does flush the rules, so maybe in this specific case where rules can’t be added, it keeps flushing them.
Try to comment that line out, although I’m not at all sure this will fix it. Please do let me know!
Have a nice day,
StefanoOctober 28, 2015 at 5:14 am #48356SerkanKeymasterHi Stefano,
Ok, I can confirm that commenting out those two lines
$wp_rewrite->flush_rules();
lines did in fact resolve the issue. After activating Post Pay Counter and Post Pay Counter PRO, I went to the Rewrite Rules Inspector and saw that the rewrite rule for ppcp/paypal$ was red (because activating the plugin didn’t flush it anymore. So I flushed the rewrite rules and all is working peacefully now. I am not sure exactly which function it was (maybe both), but here are the two functions where I commented the lines out. Both located in post-pay-counter-pro/classes/ppcp_paypal_class.php…/** * Adds plugin's IPN rewrite rule (ppcp/paypal). * * @access public * @since 1.3 */ static function ipn_add_rewrite_rule() { global $wp_rewrite; if( ! is_object( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite(); //Add IPN listener rule if not there already $rules = $wp_rewrite->wp_rewrite_rules(); if( ! isset( $rules['ppcp/paypal$'] ) ) { add_rewrite_rule( 'ppcp/paypal$', 'index.php?ppcp=paypal', 'top' ); //$wp_rewrite->flush_rules(); } } /** * Deletes plugin's IPN rewrite rule (ppcp/paypal). * * @access public * @since 1.3.2 */ static function ipn_delete_rewrite_rule() { global $wp_rewrite; if( ! is_object( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite(); //Delete IPN listener rule if there $rules = $wp_rewrite->wp_rewrite_rules(); if( isset( $rules['ppcp/paypal$'] ) ) { unset( $rules['ppcp/paypal$'] ); //$wp_rewrite->flush_rules(); } }
Not sure what’s going on in regards to when the flush_rules() is supposed to run but it’s definitely causing the conflict with rtMedia. Maybe something to do with priority??
Anyway, let me know if theres anything else you want to know and also if you plan on changing this for future releases so I know what to do when I update Post Pay Counter PRO.
Thanks
Serkan -
AuthorPosts
- The topic ‘Post Pay Counter Pro – Flushing Rewrite Rules’ is closed to new replies.