| 1 |
<?php |
| 2 |
|
| 3 |
use Imagify\Traits\InstanceGetterTrait; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class that handles the plugin rating cron. |
| 7 |
* |
| 8 |
* @since 1.7 |
| 9 |
* @author Grégory Viguier |
| 10 |
*/ |
| 11 |
class Imagify_Cron_Rating extends Imagify_Abstract_Cron { |
| 12 |
use InstanceGetterTrait; |
| 13 |
|
| 14 |
/** |
| 15 |
* Class version. |
| 16 |
* |
| 17 |
* @var string |
| 18 |
* @since 1.7 |
| 19 |
*/ |
| 20 |
const VERSION = '1.0'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Cron name. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
* @since 1.7 |
| 27 |
* @access protected |
| 28 |
*/ |
| 29 |
protected $event_name = 'imagify_rating_event'; |
| 30 |
|
| 31 |
/** |
| 32 |
* Cron recurrence. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
* @since 1.7 |
| 36 |
* @access protected |
| 37 |
*/ |
| 38 |
protected $event_recurrence = 'daily'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Cron time. |
| 42 |
* |
| 43 |
* @var string |
| 44 |
* @since 1.7 |
| 45 |
* @access protected |
| 46 |
*/ |
| 47 |
protected $event_time = '15:00'; |
| 48 |
|
| 49 |
/** ----------------------------------------------------------------------------------------- */ |
| 50 |
/** HOOKS =================================================================================== */ |
| 51 |
/** ----------------------------------------------------------------------------------------- */ |
| 52 |
|
| 53 |
/** |
| 54 |
* Initiate the event. |
| 55 |
* |
| 56 |
* @since 1.7 |
| 57 |
* @access public |
| 58 |
* @author Grégory Viguier |
| 59 |
*/ |
| 60 |
public function schedule_event() { |
| 61 |
if ( ! wp_next_scheduled( $this->get_event_name() ) && ! get_site_transient( 'do_imagify_rating_cron' ) ) { |
| 62 |
wp_schedule_event( $this->get_event_timestamp(), $this->get_event_recurrence(), $this->get_event_name() ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* The event action. |
| 68 |
* |
| 69 |
* @since 1.7 |
| 70 |
* @access public |
| 71 |
* @author Grégory Viguier |
| 72 |
*/ |
| 73 |
public function do_event() { |
| 74 |
// Stop the process if the plugin isn't installed for 3 days. |
| 75 |
if ( get_site_transient( 'imagify_seen_rating_notice' ) ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
$user = get_imagify_user(); |
| 80 |
|
| 81 |
if ( ! is_wp_error( $user ) && isset( $user->image_count ) && (int) $user->image_count > 100 ) { |
| 82 |
set_site_transient( 'imagify_user_images_count', $user->image_count ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|