Hot answers tagged

18

I know I'm three months late, but the function you want here is get_date_from_gmt(). The function accepts a GMT/UTC date in Y-m-d H:i:s format as the first parameter, and your desired date format as the second parameter. It'll convert your date to the local timezone as set on the Settings screen. Example usage: echo get_date_from_gmt( date( 'Y-m-d H:i:s', ...


17

My favorite plugin for that is Core Control which has very nice module for display of what is going in the cron - which events are set up, when are they next firing, etc. On getting your hands dirty level see _get_cron_array(), which returns internal stored data for cron events (top level of keys are timestamps).


10

After some testing indeed, both WP Super Cache and W3 Total Cache do not release the buffer (or prevent the buffer from being released). Turning off "output delay" is simple and depends on the caching plugin involved. WP Super Cache: wp_cache_disable(); ob_end_flush(); // or ob_end_clean(); This should be added after including wp-load.php, this stops ...


10

The answer is apparently YES, I should worry. After some research, I've found that the warning seems to be related to misconfigurations on the server that WordPress is hosted on (ie. a problem with my server, not WordPress). Common misconfigurations: Server doesn't have DNS, and so it can't figure out who "example.com" is, even though it is itself. Server ...


10

Firstly, define your custom cron job schedules. add_filter('cron_schedules', array($this, 'cron_schedules')); public function cron_schedules($schedules){ $prefix = 'cron_';// Avoid conflict with other crons. Example Reference: cron_30_mins $schedule_options = array( '30_mins' => array( 'display' => '30 Minutes', ...


9

time() only returns current time, it doesn't accept any inputs. $time = time(); // works out to 2016-04-11T12:11:34+00:00 What you want is midnight tomorrow: $tomorrow = strtotime( 'tomorrow' ); // works out to 2016-04-12T00:00:00+00:00 Note that these are PHP functions and they ignore WP timezone, since it resets PHP time zone to UTC. So if using ...


8

Why don't you just create a cron job, make a database dump and look where the info about the cron job is kept? That's what I did. As suspected, WordPress 3.5.1 keeps its cron jobs in the {wp}_options table under the name 'cron'. SELECT * FROM `wp_options` WHERE `option_name` LIKE '%cron%' Or through functions.php: $cron_jobs = get_option( 'cron' ); ...


7

I think you have mismatch in how you pass arguments and how you expect it to work. You pass array of arguments to schedule and expect your hooked function to receive identical array of arguments. This is not the case. Cron events are processed by do_action_ref_array(), which in turn passes arguments via call_user_func_array(). So your hooked function does ...


7

Thanks to Rarst this makes a hell of a lot more sense now. So I've updated this post to elaborate the differences Rarst mentioned and upvoted his for shedding light on this ; ) Basically wp_schedule_single_event passes the arguments to your function through the variable args as shown in the codex. This variable "args" must be an array because each value in ...


7

It's a sign that you have ALTERNATE_WP_CRON defined in your wp-config.php In order to do some background processing (like publishing scheduled posts), WordPress redirects you to the URL with ?doing_wp_cron appended.


7

Neither. register_activation_hook( __FILE__, 'trigger_me' ); function trigger_me() { if ( !wp_next_scheduled( 'my_plugin_cron' ) ) { wp_schedule_event(time(), 'hourly', 'my_plugin_cron'); } } Why parse code on every request when you don't need to?


6

Check out wp_cron and the cron_schedules filter. There are lots of good tutorials out there like this one from WPTuts or this one from Viper007Bond.


5

WordPress lets you add custom cron schedules, which is normally what you'd want to do in this situation, in conjunction with wp_schedule_event(). But, they work based on intervals rather than specific dates/times. For instance, add_filter( 'cron_schedules', 'addCustomCronIntervals' ); function addCustomCronIntervals( $schedules ) { $schedules[ self::...


5

Yes, the event will trigger when the wp-cron process gets run. If something is preventing wp-cron from running, then it won't trigger at all. If you're having it not work, then something about your server configuration is preventing it from working. For these cases, you can generally work around them by adding this define to your wp-config file: define('...


5

Edit: wp_next_scheduled() returns the timestamp of the next scheduled job of a specified wp-cron job-arguments pair. Please note that this differs slightly in functionality to the answer below, in that you have to provide the arguments passed to cron job's callback (if it has any). The original answer would provide the time of the next specified job ...


5

First can you please confirm that you don't have any caching plugins enabled? Caching plugins can interfere with cron jobs because your visitors are not served a live page but a cached version of your page. If you have a caching plugin enabled, you can choose one of your pages, add an exclussion to your caching plugin's settings for that page so that it is ...


5

WordPress has an undocumented function, _get_cron_array, that returns an array of all currently scheduled tasks. We are going to use a crude but effective method to dump out all the tasks using var_dump. For ease of use place the following code in the plugin: echo '<pre>'; print_r( _get_cron_array() ); echo '</pre>'; for more info:https://...


5

This is the intended use of the WP_CRON_LOCK_TIMEOUT constant. When WordPress is loaded, it checks to see if a cron job is running (if cron is locked). If cron is not locked, it will try to create a lock - if the lock timeout has not been reached, no lock can be acquired and cron is not run. If no cron job is running, and the timeout has passed (meaning a ...


5

This is what normal query run by wp_get_associated_nav_menu_items() looks like: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.id = wp_postmeta.post_id ) WHERE 1 = 1 AND wp_posts.post_type = 'nav_menu_item' AND (( wp_posts.post_status <> 'trash' AND wp_posts.post_status &...


5

I think the best way is to use WP-CLI but you'd need to write a bash script to do this. Here is one that should do it for you: WP_PATH="/path/to/wp" for SITE_URL in = $(wp site list --fields=domain,path,archived,deleted --format=csv --path="$WP_PATH" | grep ",0,0$" | awk -F ',' '{print $1 $2}') do for EVENT_HOOK in $(wp cron event list --format=csv --...


5

You can create new schedule times via cron_schedules: function my_cron_schedules($schedules){ if(!isset($schedules["5min"])){ $schedules["5min"] = array( 'interval' => 5*60, 'display' => __('Once every 5 minutes')); } if(!isset($schedules["30min"])){ $schedules["30min"] = array( 'interval'...


5

If you deactivate the plugin, the scheduled event will still try to run ( and fail ) unless you remove that event from the schedule using wp_clear_scheduled_hook


4

It looks for me that you are adding this event only when there is no such event 'send_email_alerts_hook' scheduled yet. Try something like this and let me know if it workded. function shedule_email_alerts() { if ( !wp_next_scheduled( 'send_email_alerts_hook' ) ) { wp_schedule_event(time(), 'daily', 'send_email_alerts_hook'); } else { ...


4

Due to your server configuration, you may need to use the alternate cron method, which uses redirect rather than http loopback. Try adding the following to your wp-config.php file: // Alternate cron method define( 'ALTERNATE_WP_CRON', true );


4

This is only a partial answer. You can use Cron View to see what crons are still active on your blog. If you find some crons that shouldn't be there then maybe my answer here will help you remove that cron: Cron jobs for deactivated plugins


4

Disable any plugins you may have that do whole-page caching. WP-Super-Cache, W3 Total Cache, etc. WordPress does not "delay output". But whole page caching plugins usually do. This is because they are trying to get that output and save it somewhere, for later usage in serving the page. Thus, the page output is delayed until the end, where the plugin can ...


4

As you've noted, cron jobs are only fired when someone visits your website. WordPress checks if they are any events that have been scheduled before 'now' that have not yet occurred - and runs them. Importantly with events that are recur according to a regularly pattern (say hourly) - their occurrence is relative not absolute. That is, once your event ...


4

Basically every page load looks to see if there is anything scheduled to run, so by that logic the cron is checked and can possibly run on every page load. I can only presume you want to schedule something to run every so often. If that's the case you need to look at wp_schedule_event() Below is the code to get some code to run ever hour: add_action('...


4

After this remark from the OP: To be clearer, I have scheduled posts in the future, and I want the cache to clear when the are published via the wp-cron trigger. There might be a better way? I do not know if the W3 Total Cache plug-in not automatically flushes the cache when posts are published. I believed it did. If it does not - then in this intance ...


4

Whenever you do get_posts or WP_Query or anything like that, it's important to remember that the code is actually getting all of the Posts at once, and loading them from the database into memory. If you run out of memory, then your process will simply die with an error. Attempting to get very large numbers of posts at once will cause this quite often. Turn ...



Only top voted, non community-wiki answers of a minimum length are eligible