WPIntell

Source evidence

DOING_CRON defined on every page load in multisite

WP-Cron Control · support · 2017-09-13T02:38:00+00:00

complaintsentiment
highseverity
1.0relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

7 / 35 rows with source links

20.0% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

28 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
taropaa unresolved
Hi, I am using this plugin in multisite, network activated. It does a decent job of securing cron jobs, however it seems that it is declaring DOING_CRON on every single page load (even if it’s not a cron request). I have declared DISABLE_WP_CRON true and define(‘ALTERNATE_WP_CRON’, false); but I am still getting that on every page within the network. How can i stop this behaviour? (only happens when the plugin is active) I just want to add… this seems to be a pretty serious issue, since many plugins (including ours) rely on being able to correctly determine whether we are being called from inside a cron task or not. The way to do this is by checking DOING_CRON… but defining DOING_CRON as “true” all the time, even when it’s not really a cron request, makes doing so impossible. In 4.8 WordPress added a new function wp_doing_cron() which also relies on checking DOING_CRON, so this core function would also be broken by WP-Cron Control. The problematic code is in validate_cron_request(): // for all other cases disable wp-cron.php and spawn_cron() by telling the system it's already running if ( !defined( 'DOING_CRON' ) ) define( 'DOING_CRON', true ); // and also disable the wp_cron() call execution if ( !defined( 'DISABLE_WP_CRON' ) ) define( 'DISABLE_WP_CRON', true ); Honestly I don’t see the reason for defining DOING_CRON here… I think that defining DISABLE_WP_CRON as true would be sufficient to prevent cron jobs running on their own. As a temporary workaround to anyone experiencing this issue, I would suggest you either comment out the “define( ‘DOING_CRON’, true );” line referenced above, or if you don’t want to modify the plugin file directly you could try adding the following snippet to your functions.php file: add_action( 'init', 'sliced_fix_wp_cron_control', 9 ); function sliced_fix_wp_cron_control() { if ( ! defined( 'DOING_CRON' ) ) { define( 'DOING_CRON', false ); } } What this does is it runs just before WP-Cron Control and defines DOING_CRON as “false”… preventing WP-Cron Control from defining it as “true”. Since PHP constants can only be defined one time, the later attempt will fail silently. (Or, depending on your PHP error reporting setting, it may emit a “Notice: Constant DOING_CRON already defined” message, but this is harmless.) If we actually *are* in a cron request, DOING_CRON will have already been defined true by WordPress (see wp-cron.php, line 22), and the above snippet won’t come into play. Thus we can check whether DOING_CRON is true or false and act accordingly. This is less than ideal, however, because many plugins may only check to see if DOING_CRON is defined… not whether it is true or false. In these cases the above code snippet won’t help. I hope that one of the authors of WP-Cron Control takes note and comes up with a permanent solution to this. If I can be of any assistance, please let me know. Regards, David Grant Developer of Sliced Invoices Hi David, thank you so much for your support. I actually started this ticket on your helpdesk but I am really happy to see you go beyond to help out. I hope the plugin developers get wind of this issue and patch it in an upcoming release. In the meantime I have commented the line out and the issue seems to be resolved. I will update this ticket if I notice other issues with this fix

Comments

2 shown
SlicedInvoices 2017-09-13T07:01:00+00:00

I just want to add… this seems to be a pretty serious issue, since many plugins (including ours) rely on being able to correctly determine whether we are being called from inside a cron task or not. The way to do this is by checking DOING_CRON… but defining DOING_CRON as “true” all the time, even when it’s not really a cron request, makes doing so impossible. In 4.8 WordPress added a new function wp_doing_cron() which also relies on checking DOING_CRON, so this core function would also be broken by WP-Cron Control. The problematic code is in validate_cron_request(): // for all other cases disable wp-cron.php and spawn_cron() by telling the system it's already running if ( !defined( 'DOING_CRON' ) ) define( 'DOING_CRON', true ); // and also disable the wp_cron() call execution if ( !defined( 'DISABLE_WP_CRON' ) ) define( 'DISABLE_WP_CRON', true ); Honestly I don’t see the reason for defining DOING_CRON here… I think that defining DISABLE_WP_CRON as true would be sufficient to prevent cron jobs running on their own. As a temporary workaround to anyone experiencing this issue, I would suggest you either comment out the “define( ‘DOING_CRON’, true );” line referenced above, or if you don’t want to modify the plugin file directly you could try adding the following snippet to your functions.php file: add_action( 'init', 'sliced_fix_wp_cron_control', 9 ); function sliced_fix_wp_cron_control() { if ( ! defined( 'DOING_CRON' ) ) { define( 'DOING_CRON', false ); } } What this does is it runs just before WP-Cron Control and defines DOING_CRON as “false”… preventing WP-Cron Control from defining it as “true”. Since PHP constants can only be defined one time, the later attempt will fail silently. (Or, depending on your PHP error reporting setting, it may emit a “Notice: Constant DOING_CRON already defined” message, but this is harmless.) If we actually *are* in a cron request, DOING_CRON will have already been defined true by WordPress (see wp-cron.php, line 22), and the above snippet won’t come into play. Thus we can check whether DOING_CRON is true or false and act accordingly. This is less than ideal, however, because many plugins may only check to see if DOING_CRON is defined… not whether it is true or false. In these cases the above code snippet won’t help. I hope that one of the authors of WP-Cron Control takes note and comes up with a permanent solution to this. If I can be of any assistance, please let me know. Regards, David Grant Developer of Sliced Invoices

taropaa 2017-09-13T15:36:00+00:00

Hi David, thank you so much for your support. I actually started this ticket on your helpdesk but I am really happy to see you go beyond to help out. I hope the plugin developers get wind of this issue and patch it in an upcoming release. In the meantime I have commented the line out and the issue seems to be resolved. I will update this ticket if I notice other issues with this fix