| 1 |
<?php |
| 2 |
/** |
| 3 |
* ConvertKit WordPress Cron functions. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Refresh the Posts Resource cache, triggered by WordPress' Cron. |
| 11 |
* |
| 12 |
* @since 1.9.7.4 |
| 13 |
*/ |
| 14 |
function convertkit_resource_refresh_posts() { |
| 15 |
|
| 16 |
// Get Settings and Log classes. |
| 17 |
$settings = new ConvertKit_Settings(); |
| 18 |
$log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH ); |
| 19 |
|
| 20 |
// If debug logging is enabled, write to it now. |
| 21 |
if ( $settings->debug_enabled() ) { |
| 22 |
$log->add( 'CRON: convertkit_resource_refresh_posts(): Started' ); |
| 23 |
} |
| 24 |
|
| 25 |
// Refresh Posts Resource. |
| 26 |
$posts = new ConvertKit_Resource_Posts( 'cron' ); |
| 27 |
$result = $posts->refresh(); |
| 28 |
|
| 29 |
// If debug logging is enabled, write to it now. |
| 30 |
if ( $settings->debug_enabled() ) { |
| 31 |
// If an error occured, log it. |
| 32 |
if ( is_wp_error( $result ) ) { |
| 33 |
$log->add( 'CRON: convertkit_resource_refresh_posts(): Error: ' . $result->get_error_message() ); |
| 34 |
} |
| 35 |
if ( is_array( $result ) ) { |
| 36 |
$log->add( 'CRON: convertkit_resource_refresh_posts(): Success: ' . count( $result ) . ' broadcasts fetched from API and cached.' ); |
| 37 |
} |
| 38 |
|
| 39 |
$log->add( 'CRON: convertkit_resource_refresh_posts(): Finished' ); |
| 40 |
} |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
// Register action to run above function; this action is created by WordPress' wp_schedule_event() function |
| 45 |
// in the ConvertKit_Resource_Posts class. |
| 46 |
add_action( 'convertkit_resource_refresh_posts', 'convertkit_resource_refresh_posts' ); |
| 47 |
|