Wp_Schedule_Event tous les jours à une heure précise
-
-
Lafonction `time ()`ne prendpas d'argument d'entrée,essayez lafonction `strtotime ()` ou lafonction `strftime ()` à laplace,pour créer des horodatagespersonnalisés àpartir d'une chaîne.Mais si vous avez déjà l'horodatage,vousn'en avezpasbesoin.The `time()` function doesn't take an input argument, try the `strtotime()` function or the `strftime()` function instead, to create custom timestamps from a string. But if you already got the timestamp, you don't need them.
- 1
- 2015-02-27
- birgire
-
4 réponses
- votes
-
- 2015-02-28
WP Cron s'exécute lorsque quelqu'un visite votre site Web. Ainsi,sipersonnene visite,le cronne s'exécutejamais.
Ilexistemaintenant 2 solutions:
- Désactivez WP Cron,utilisez un vraitravail Cronet personnalisez-le.
-
Utilisez unintervallepersonnalisé dans
wp_schedule_event()
:function myprefix_custom_cron_schedule( $schedules ) { $schedules['every_six_hours'] = array( 'interval' => 21600, // Every 6 hours 'display' => __( 'Every 6 hours' ), ); return $schedules; } add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' ); //Schedule an action if it's not already scheduled if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) { wp_schedule_event( time(), 'every_six_hours', 'myprefix_cron_hook' ); } ///Hook into that action that'll fire every six hours add_action( 'myprefix_cron_hook', 'myprefix_cron_function' ); //create your function, that runs on cron function myprefix_cron_function() { //your function... }
et vouspouvez voir cestuts
http://www.nextscripts.com/tutorials/wp-cron-scheduling-tasks-in-wordpress/
http://www.iceablethemes.com/optimize -wordpress-replace-wp_cron-real-cron-job/
http://www.smashingmagazine.com/2013/10/16/programme-des-événements-en-utilisant-wordpress-cron/
cron Wppersonnalisé
http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
http://www.smashingmagazine.com/2013/10/16/programme-des-événements-en-utilisant-wordpress-cron/
http://www .viper007bond.com/2011/12/14/comment-créer-des-intervalles-cron-wordpress-personnalisés/
http://www.sitepoint.com/mastering-wordpress-cron/
https://tommcfarlin.com/wordpress-cron-jobs/
http://www.paulund.co.uk/create- cron-jobs-in-wordpress
cron linux
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
http://www.thesitewizard.com/general/set-cron-job.shtml
http://code.tutsplus.com/tutoriels/planification-de-tâches-avec-cron-jobs -net-8800
WP Cron runs, when somebody visits your website. Thus if nobody visits, the cron never runs.
Now there are 2 solutions:
- Disable WP Cron, use a real cron job and customize it.
Use a custom interval in
wp_schedule_event()
:function myprefix_custom_cron_schedule( $schedules ) { $schedules['every_six_hours'] = array( 'interval' => 21600, // Every 6 hours 'display' => __( 'Every 6 hours' ), ); return $schedules; } add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' ); //Schedule an action if it's not already scheduled if ( ! wp_next_scheduled( 'myprefix_cron_hook' ) ) { wp_schedule_event( time(), 'every_six_hours', 'myprefix_cron_hook' ); } ///Hook into that action that'll fire every six hours add_action( 'myprefix_cron_hook', 'myprefix_cron_function' ); //create your function, that runs on cron function myprefix_cron_function() { //your function... }
and you can see these tuts
http://www.nextscripts.com/tutorials/wp-cron-scheduling-tasks-in-wordpress/
http://www.iceablethemes.com/optimize-wordpress-replace-wp_cron-real-cron-job/
http://www.smashingmagazine.com/2013/10/16/schedule-events-using-wordpress-cron/
custom Wp cron
http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
http://www.smashingmagazine.com/2013/10/16/schedule-events-using-wordpress-cron/
http://www.viper007bond.com/2011/12/14/how-to-create-custom-wordpress-cron-intervals/
http://www.sitepoint.com/mastering-wordpress-cron/
https://tommcfarlin.com/wordpress-cron-jobs/
http://www.paulund.co.uk/create-cron-jobs-in-wordpress
cron linux
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
http://www.thesitewizard.com/general/set-cron-job.shtml
http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800
-
- 2015-08-31
Au lieu de time () ,utilisez strtotime () pour que vouspuissiez spécifier l'heure dujour -il utilisera la date dujour avec l'heure que vous spécifiez.Donc dans votre cas:
strtotime('16:20:00'); // 4:20 PM
L'utilisation dans lafonction
wp_schedule_event
ressemblerait à ceci:wp_schedule_event( strtotime('16:20:00'), 'daily', 'import_into_db' );
Instead of time(), use strtotime() function so you can specify the time of day - it will use today's date with the time that you specify. So in your case:
strtotime('16:20:00'); // 4:20 PM
Usage in the
wp_schedule_event
function would look like this:wp_schedule_event( strtotime('16:20:00'), 'daily', 'import_into_db' );
-
- 2015-02-27
Ehbien,1427488800 se résout au 27mars 2015,donc votre événementn'estmêmepasencoreprêt à commencer.
Deplus,gardez à l'esprit que les événements WPprogrammésne seront déclenchés que si quelqu'un accède au site à cemoment-là.
Well, 1427488800 resolves to March 27, 2015, so your event isn't even set to start yet.
Also, bear in mind that scheduled WP events will only fire if someone hits the site at that time.
-
Maintenant,comment réparer?@vancoderNow ,How fix? @vancoder
- 0
- 2015-02-28
- Mortzea
-
- 2018-04-05
Ce codefonctionnepourmoi,je pense qu'ilestplusproche de la questioninitiale.Vous voulez obtenir l'heure UNIX + lefuseau horairepour lemoment où vous voulez qu'il s'exécute.Unefois que le cron s'exécuteet est supprimé de WP,il se recrée aumoment que vous spécifiez.
Dans l'exemple suivant,je lefaisfonctionnerpour AEST (GMT + 10) à 6 heures dumatin chaquematin.Je leplanifie donctous lesjours à 20h00 GMT.
if (!wp_next_scheduled('cron_name')) { $time = strtotime('today'); //returns today midnight $time = $time + 72000; //add an offset for the time of day you want, keeping in mind this is in GMT. wp_schedule_event($time, 'daily', 'cron_name'); }
This code is working for me, I believe it is closer to the original question. You want to get the UNIX time + timezone for when you want it to execute. Once the cron executes and is removed from WP, it recreates itself at the time you specify.
In the following example, I have it working for AEST (GMT+10) @ 6AM each morning. So I am scheduling it for GMT 20:00 each day.
if (!wp_next_scheduled('cron_name')) { $time = strtotime('today'); //returns today midnight $time = $time + 72000; //add an offset for the time of day you want, keeping in mind this is in GMT. wp_schedule_event($time, 'daily', 'cron_name'); }
J'écris le code suivantpourexécutermafonctiontous lesjours à 16h20 ..
Maisje suppose que c'est leproblème du code ..
ne fonctionnepas
Horodatage de l'époque: 1427488800
28/03/2015 01:10:00