Getting this code to work in Multisite

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’ ); into your code to fix that. … Read more

Template Tag not available in real Cron Jobs

When you run things on the CLI (which is pretty much where Cronjob and runwhen jobs are running), then you don’t have access to some things like some server or request variable contents, etc. What you need to do is fire up WP Core. Else you won’t have access to the full WP API. One … Read more

Cleaning “cron” from options table, will affect anything?

If you want a quick programmatic way of looping through everything you have in the cron row inside wp_options and you have access to the site’s database directly (either in a local development environment or on a webhost), you can run something like this via the command line: mysql $YOUR_DB_NAME -e “SELECT option_value FROM wp_options … Read more

How to execute existing WP Cron programmatically

When you register a scheduled event for WordPress’ cron, the 3rd argument is a hook name: wp_schedule_event( time(), ‘hourly’, ‘my_hourly_event’ ); And you add a function to run on this hook with add_action(): add_action( ‘my_hourly_event’, ‘do_this_hourly’ ); This will cause do_this_hourly() to run whenever the scheduled event runs. This works because when the scheduled time … Read more

How to make WordPress emails async

Since wp_mail is pluggable, we can selectively override it. I run the following code in my general functionality plugin: /** * Email Async. * * We override the wp_mail function for all non-cron requests with a function that simply * captures the arguments and schedules a cron event to send the email. */ if ( … Read more

WP Cron job every 1st and 15th of the month

wp_cron operates on intervals and there is no interval that will hit exactly the first day and the 15th of every month. You could run your wp-cron job every day and check the date, similar to this but with a simple callback like: cron_callback_wpse_113675() { $date = date(‘d’); if (’01’ == $date || ’15’ == … Read more

Cron While Editing Post

It seems to have solved by changing the two functions, by taking a different approach: /* CHECK IF CURRENT USER IS NOT IN POST.PHP AND IN POST-NEW.PHP AND DOWNGRADE PUBLISH POSTS IN PENDING AFTER X DAYS */ if(is_admin() ) {global $pagenow; if( ‘post.php’ != $pagenow || ‘post-new.php’ != $pagenow) { add_action( ‘init’, ‘downgrade_publish_posts’ ); function … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)