Usage How to add a cron job via Wp Crontrol
June 29, 2024 at 4:56 AMIf you want to use the Synchronize to WordPress/AD feature you need to set up a cron job. You can do this by using the WordPress plugin WP Crontrol.
Get WP Crontrol
- Download WP Control from https://wordpress.org/plugins/wp-crontrol/. Alternatively you can install the plug-in in the WordPress UI through Plugins > Add new.
- After installing WP Crontrol, activate the plug-in.
Add the PHP Cron Event
- In WordPress, click on Tools > Cron Events and select Add PHP Cron Event in the upper-right tab:
-
Inside the PHP Code area, paste the following code:
$postData = http_build_query( array( 'next_ad_int-task' => 'sync-to-wordpress', // if you want to add a cronjob for Sync to AD as well just change 'wordpress' to 'ad' 'auth-code' => '$YOUR_AUTHCODE' // get the authentication code from Sync to WordPress/AD ) ); $opts = array('http' => array( 'method' => 'POST', 'content' => $postData ) ); $context = stream_context_create($opts); $result = file_get_contents('$YOUR_WORDPRESS_URL/wp-admin/admin.php', false, $context); // replace $YOUR_WORDPRESS_URL with the URL of your WordPress instance.
-
Replace
$YOUR_AUTHCODE
with the authentication code of Sync to WordPress/AD and$YOUR_WORDPRESS_URL
with the URL of your WordPress instance.
Make sure that the URL is accessible from the webserver.
-
Configure Next Run and Recurrence settings. Depending upon the size of your Active Directory, the recurrence should not happen to often.
-
Click Add PHP Cron Event.
The added task will automatically run on the next scheduled date.