Hot answers tagged

17

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', ...


16

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

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', ...


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 ...


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

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

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

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?


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.


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[ ...


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

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

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: ...


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

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

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 ...


4

I was working with wp_cron last week in a plugin and we have a fight and are no longer on speaking terms, but for reference this is what I do; 1) - set the scheduled cron event on register_activation_hook 2) - remove the scheduled cron event on register_deactivation_hook If you are concerned that your scheduled cron event might get wiped from the database ...


4

wp_cron is used to schedule tasks such as deleting old posts from trash, deleting old spam comments, and checking for plugin/theme updates.


4

The Problem: When wp-cron.php is called, it includes only: require_once( dirname( __FILE__ ) . '/wp-load.php' ); so the problem you are facing is that wpmu_delete_blog() is undefined when you call it from your remove_blogs_daily() function. Possible Solution: You therefore need to add this line: require_once( ABSPATH . 'wp-admin/includes/admin.php' ...


4

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

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( ...


4

Sending mass emails that actually get delivered is not a simple matter at all. Even if your code sends 1000 messages correctly, many if not most of them will get blocked or labeled as spam unless you comply with a long list of mass email best practices. (See also: The FTC's CAN-SPAM Act - Compliance Guide.) I recommend that you use (or study the code of) a ...


4

From the codex: current_time('timestamp') should be used in lieu of time() to return the blog's local time. In WordPress, PHP's time() will always return UTC and is the same as calling current_time('timestamp', true). Try this: define( 'MY_TIMEZONE', (get_option( 'timezone_string' ) ? get_option( 'timezone_string' ) : date_default_timezone_get() ) ...


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

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

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



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