Recently we’ve been playing around with the wordpress cron features. The one thing that’s very badly documented is how to know when its working and how to cancel them.

When scheduling the cron jobs via wordpress, the documentation explains that you should set them up using the “time()” function as the first argument in wp_schedule_event($timestamp, $recurrence, $hook, $args);.

Only when trying to un schedule an event do we find out that this is a very bad idea.  Bad idea since you probably don’t know what that “time()” function actually spit out. Why is that important you ask, well its needed for that wonderful new function:

[php]

wp_unschedule_event($timestamp, ‘my_schedule_hook’, original_args );

[/php]

The first argument there again, is the exact timestamp you generated however long ago.

OPTIONS

So what are your options at this point? Where are these things being stored anyway? My guess ironically enough is in the wordpress options table. Now since that’s not a realistic place to search (for the layman), lets try this, what’s actually in that wp_unshceulde_event() function? Aha, in that function we see how this thing floats around in memory like so many other things in the CMS.  So lets borrow a line from the function and use the following. Then stand back:

[php]

$crons = _get_cron_array();
var_dump($crons); // or print_r

[/php]

You should get a result like the following

[php]
[1326255415]=>
array(1) {
["my_twicedaily_event"]=>
array(1) {
["40cd750bba9870f18aada2478b24840a"]=>
array(3) {
["schedule"]=>
string(6) "twicedaily"
["args"]=> array(0) {}
["interval"]=>int(43200)
}
}
}

[/php]

Now we have all cron jobs spilled across your home page. Did i mention you should make sure to use that command in an unimportant area? Well lets hurry up since this code is messing up your wonderful site where ever it is. Note the time stamp of the event you would like to remove. Thats what you will use for the first argument in wp_unschedule_event().HOOK LINE AND SINKER

CONCLUSION

Much like how you launched the feature, the wordpress documentation doesnt lie. I.E. there is no return value yippy. You will simply need to recheck that variable or wait and monitor the cron ran event. I personally went for the first, all brute force and everything.

[php]

wp_unschedule_event("1326255411", ‘my_twicedaily_event’);
wp_unschedule_event("1326255415", ‘my_twicedaily_event’ );
$crons = _get_cron_array();
var_dump($crons);

[/php]

Yeah it started so quitely,  i launched multiple instances of the same thing. Judging from the stamp, right after each other hmm.

Recientemente nos hemos estado jugando con las características de cron de wordpress. La única cosa que está muy mal documentada es cómo saber cuándo su trabajo y cómo cancelarlos.
Cuando trabajando con cron en wordpress, la documentación explica que usted debería ponerlos utilizando la función “time()” como el primer argumento en wp_schedule_event ($timestamp,  $recurrencia , $gancho, $args);. 
Sólo cuando tratando de ONU programar una cita nos enteramos que esto es una muy mala idea. Mala idea ya que probablemente no sabes lo que esa función “time()” escupe.¿Por qué es importante pides, bien su necesaria para ese maravilloso wp_unschedule_event función nueva ($timestamp, ‘my_schedule_hook’, original_args);. El primer argumento allí una vez más, es la fecha y hora exacta que generó sin embargo hace mucho tiempo. 
OPCIONES
So ¿cuáles son sus opciones en este momento? ¿Donde estas cosas se almacena de todas formas? Mi conjetura es irónicamente en la tabla de opciones de wordpress. ¿Ahora ya no es un lugar realista para buscar (laico), permite probar esto, lo que realmente está en esa función de wp_unshceulde_event()? Aha, en esa función, vemos cómo esta cosa flota en la memoria como tantas otras cosas en el CMS. Así permite pedir una línea de la función y utiliza lo siguiente. 
  • $crons = _get_cron_array();
  • var_dump or print_r, whatever your flavor var_dump($crons);

Debe obtener un resultado similar al siguiente

[1326255415]=>
array(1) {
[“my_twicedaily_event”]=>
array(1) {
[“40cd750bba9870f18aada2478b24840a”]=>
array(3) {
[“schedule”]=>
string(6) “twicedaily”
[“args”]=>
array(0) {
}
[“interval”]=>
int(43200)
}
}
}
LÍNEA Y PLATINAS
gancho ahora tenemos todos los trabajos de cron se derramó a través de su página de inicio. ¿menciono que debe asegurarse de utilizar ese comando en una zona sin importancia? Bien le prisa ya que este código es estropear su sitio maravilloso donde siempre es.Tenga en cuenta la marca de tiempo del evento que desea quitar. Eso es lo que va a utilizar para el primer argumento en wp_unschedule_event(). 
CONCLUSION
Much como cómo inició la función, no encuentra la documentación de wordpress. Es decir, no hay ningún valor devuelto yippy.Simplemente tendrá que revisar esa variable o esperar y monitor el cron corrían el evento.Personalmente me fui para la primer fuerza bruta todos y todo.
  • wp_unschedule_event(“1326255411”, ‘my_twicedaily_event’);
  • wp_unschedule_event(“1326255415”, ‘my_twicedaily_event’ );
  • $crons = _get_cron_array();
  • var_dump($crons);
Sí comenzó tan quitely, he lanzado varias instancias de la misma cosa. A juzgar por el sello, después mutuamente hmm.

 

Leave a Comment

Sign in

Sign Up

Forgotten Password

Cart

Cart

Share