| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Planning cron |
| 6 |
* If the task is not programmed, it is automatically triggered |
| 7 |
* |
| 8 |
* @since 1.4.2 |
| 9 |
*/ |
| 10 |
add_action( 'init', '_imagify_rating_scheduled' ); |
| 11 |
function _imagify_rating_scheduled() { |
| 12 |
if ( ! wp_next_scheduled( 'imagify_rating_event' ) && ! get_site_transient( 'do_imagify_rating_cron' ) ) { |
| 13 |
wp_schedule_event( time(), 'daily', 'imagify_rating_event' ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
/* |
| 18 |
* Saved the user images count to display it later |
| 19 |
* in a notice message to ask him to rate Imagify on WordPress.org |
| 20 |
* |
| 21 |
* @since 1.4.2 |
| 22 |
*/ |
| 23 |
add_action( 'imagify_rating_event', '_do_imagify_rating_cron' ); |
| 24 |
function _do_imagify_rating_cron() { |
| 25 |
// Stop the process if the plugin isn't installed since 3 days |
| 26 |
if ( get_site_transient( 'imagify_seen_rating_notice' ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
// Check if the Imagify servers & the API are accessible |
| 31 |
if ( ! is_imagify_servers_up() ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$user = get_imagify_user(); |
| 36 |
|
| 37 |
if ( isset( $user ) && (int) $user->image_count > 100 ) { |
| 38 |
set_site_transient( 'imagify_user_images_count', $user->image_count ); |
| 39 |
} |
| 40 |
} |