@@ -16,176 +16,176 @@  | 
                                                    ||
| 16 | 16 | */  | 
                                                        
| 17 | 17 |  class Cron { | 
                                                        
| 18 | 18 | |
| 19 | - /**  | 
                                                        |
| 20 | - * Holds class instance  | 
                                                        |
| 21 | - *  | 
                                                        |
| 22 | - * @since 1.0.0  | 
                                                        |
| 23 | - *  | 
                                                        |
| 24 | - * @var object|Module_Template  | 
                                                        |
| 25 | - */  | 
                                                        |
| 26 | - protected static $instance = null;  | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | - /**  | 
                                                        |
| 29 | - * Initialize the plugin by setting localization, filters, and administration functions.  | 
                                                        |
| 30 | - *  | 
                                                        |
| 31 | - * @since 1.0.0  | 
                                                        |
| 32 | - *  | 
                                                        |
| 33 | - * @access private  | 
                                                        |
| 34 | - */  | 
                                                        |
| 35 | -	public function __construct() { | 
                                                        |
| 36 | - add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );  | 
                                                        |
| 37 | - add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );  | 
                                                        |
| 38 | - add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );  | 
                                                        |
| 39 | - add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10 );  | 
                                                        |
| 40 | - }  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - /**  | 
                                                        |
| 43 | - * Return an instance of this class.  | 
                                                        |
| 44 | - *  | 
                                                        |
| 45 | - * @since 1.0.0  | 
                                                        |
| 46 | - *  | 
                                                        |
| 47 | - * @return object Cron() A single instance of this class.  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | -	public static function get_instance() { | 
                                                        |
| 50 | - // If the single instance hasn't been set, set it now.  | 
                                                        |
| 51 | -		if ( null === self::$instance ) { | 
                                                        |
| 52 | - self::$instance = new self();  | 
                                                        |
| 53 | - }  | 
                                                        |
| 54 | - return self::$instance;  | 
                                                        |
| 55 | - }  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - /**  | 
                                                        |
| 58 | - * Registers a 5 min schedule for us to use.  | 
                                                        |
| 59 | - *  | 
                                                        |
| 60 | - * @param array $schedules  | 
                                                        |
| 61 | - * @return array  | 
                                                        |
| 62 | - */  | 
                                                        |
| 63 | -	public function register_schedule( $schedules ) { | 
                                                        |
| 64 | - $schedules['wetu-5-minutes'] = array(  | 
                                                        |
| 65 | - 'interval' => 5 * MINUTE_IN_SECONDS,  | 
                                                        |
| 66 | - 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ),  | 
                                                        |
| 67 | - );  | 
                                                        |
| 68 | - return $schedules;  | 
                                                        |
| 69 | - }  | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | - /**  | 
                                                        |
| 72 | - * Watches for changes in the button triggers.  | 
                                                        |
| 73 | - *  | 
                                                        |
| 74 | - * @return void  | 
                                                        |
| 75 | - */  | 
                                                        |
| 76 | -	public function watch_for_trigger() { | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | -		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { | 
                                                        |
| 79 | - $options = lsx_wetu_get_options();  | 
                                                        |
| 80 | -  | 
                                                        |
| 81 | - // Check what state the option is in.  | 
                                                        |
| 82 | - $accommodation_cron = 'deactivate';  | 
                                                        |
| 83 | -			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { | 
                                                        |
| 84 | - $accommodation_cron = 'activate';  | 
                                                        |
| 85 | - }  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - // Check what state the cron is in.  | 
                                                        |
| 88 | - $schedule = false;  | 
                                                        |
| 89 | -			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { | 
                                                        |
| 90 | - $schedule = true;  | 
                                                        |
| 91 | - }  | 
                                                        |
| 92 | -  | 
                                                        |
| 93 | - // If activate and its not running.  | 
                                                        |
| 94 | -			if ( false === $schedule && 'activate' === $accommodation_cron ) { | 
                                                        |
| 95 | - $schedule = 'daily';  | 
                                                        |
| 96 | - $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );  | 
                                                        |
| 97 | -			} elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { | 
                                                        |
| 98 | - $this->deactivate();  | 
                                                        |
| 99 | - }  | 
                                                        |
| 100 | - }  | 
                                                        |
| 101 | - }  | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | - /**  | 
                                                        |
| 104 | - * Remove our cron from the shedule.  | 
                                                        |
| 105 | - *  | 
                                                        |
| 106 | - * @return void  | 
                                                        |
| 107 | - */  | 
                                                        |
| 108 | -	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { | 
                                                        |
| 109 | - wp_clear_scheduled_hook( $task );  | 
                                                        |
| 110 | - }  | 
                                                        |
| 111 | -  | 
                                                        |
| 112 | - /**  | 
                                                        |
| 113 | - * This function will schedule the cron event.  | 
                                                        |
| 114 | - *  | 
                                                        |
| 115 | - * @param string $task  | 
                                                        |
| 116 | - * @param string $schedule  | 
                                                        |
| 117 | - * @param string $time  | 
                                                        |
| 118 | - * @return void  | 
                                                        |
| 119 | - */  | 
                                                        |
| 120 | -	public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { | 
                                                        |
| 121 | -		if ( '' === $time ) { | 
                                                        |
| 122 | - $time = time();  | 
                                                        |
| 123 | - }  | 
                                                        |
| 124 | - wp_schedule_event( $time, $schedule, $task, array( $task ) );  | 
                                                        |
| 125 | - }  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - /**  | 
                                                        |
| 128 | - * This is the function that will be triggered by the cron event.  | 
                                                        |
| 129 | - *  | 
                                                        |
| 130 | - * @return void  | 
                                                        |
| 131 | - */  | 
                                                        |
| 132 | -	public function process( $task = '' ) { | 
                                                        |
| 133 | -		switch ( $task ) { | 
                                                        |
| 134 | - case 'lsx_wetu_accommodation_images_cron':  | 
                                                        |
| 135 | - $this->register_accommodation_images_sync();  | 
                                                        |
| 136 | - break;  | 
                                                        |
| 137 | -  | 
                                                        |
| 138 | - default:  | 
                                                        |
| 139 | - break;  | 
                                                        |
| 140 | - }  | 
                                                        |
| 141 | - }  | 
                                                        |
| 142 | -  | 
                                                        |
| 143 | - /**  | 
                                                        |
| 144 | - * This is the function that will be triggered by the cron event.  | 
                                                        |
| 145 | - *  | 
                                                        |
| 146 | - * @return void  | 
                                                        |
| 147 | - */  | 
                                                        |
| 148 | -	public function register_accommodation_images_sync() { | 
                                                        |
| 149 | - $time = strtotime( '+1 min' );  | 
                                                        |
| 150 | -		if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { | 
                                                        |
| 151 | - $this->load_items_to_sync( 'accommodation_images' );  | 
                                                        |
| 152 | - $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );  | 
                                                        |
| 153 | - }  | 
                                                        |
| 154 | - }  | 
                                                        |
| 155 | -  | 
                                                        |
| 156 | - /**  | 
                                                        |
| 157 | - * This is the function that will be triggered by the cron event.  | 
                                                        |
| 158 | - *  | 
                                                        |
| 159 | - * @return void  | 
                                                        |
| 160 | - */  | 
                                                        |
| 161 | -	public function cron_callback() { | 
                                                        |
| 162 | - }  | 
                                                        |
| 163 | -  | 
                                                        |
| 164 | - /**  | 
                                                        |
| 165 | - * This will grab the accommodation ids and load them up into an option field.  | 
                                                        |
| 166 | - *  | 
                                                        |
| 167 | - * @param string $task  | 
                                                        |
| 168 | - * @return void  | 
                                                        |
| 169 | - */  | 
                                                        |
| 170 | -	public function load_items_to_sync( $task = 'accommodation_images' ) { | 
                                                        |
| 171 | - $args = array(  | 
                                                        |
| 172 | - 'post_status' => 'publish',  | 
                                                        |
| 173 | - 'posts_per_page' => -1,  | 
                                                        |
| 174 | - 'nopagin' => true,  | 
                                                        |
| 175 | - 'fields' => 'ids',  | 
                                                        |
| 176 | - );  | 
                                                        |
| 177 | -		switch ( $task ) { | 
                                                        |
| 178 | - case 'accommodation_images':  | 
                                                        |
| 179 | - $args['post_type'] = 'accommodation';  | 
                                                        |
| 180 | - break;  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - default:  | 
                                                        |
| 183 | - break;  | 
                                                        |
| 184 | - }  | 
                                                        |
| 185 | - $items = new \WP_Query( $args );  | 
                                                        |
| 186 | -		if ( $items->have_posts() ) { | 
                                                        |
| 187 | - add_option( 'lsx_wetu_' . $task . '_sync', $items->posts );  | 
                                                        |
| 188 | - }  | 
                                                        |
| 189 | - }  | 
                                                        |
| 19 | + /**  | 
                                                        |
| 20 | + * Holds class instance  | 
                                                        |
| 21 | + *  | 
                                                        |
| 22 | + * @since 1.0.0  | 
                                                        |
| 23 | + *  | 
                                                        |
| 24 | + * @var object|Module_Template  | 
                                                        |
| 25 | + */  | 
                                                        |
| 26 | + protected static $instance = null;  | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | + /**  | 
                                                        |
| 29 | + * Initialize the plugin by setting localization, filters, and administration functions.  | 
                                                        |
| 30 | + *  | 
                                                        |
| 31 | + * @since 1.0.0  | 
                                                        |
| 32 | + *  | 
                                                        |
| 33 | + * @access private  | 
                                                        |
| 34 | + */  | 
                                                        |
| 35 | +     public function __construct() { | 
                                                        |
| 36 | + add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );  | 
                                                        |
| 37 | + add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );  | 
                                                        |
| 38 | + add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );  | 
                                                        |
| 39 | + add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10 );  | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + /**  | 
                                                        |
| 43 | + * Return an instance of this class.  | 
                                                        |
| 44 | + *  | 
                                                        |
| 45 | + * @since 1.0.0  | 
                                                        |
| 46 | + *  | 
                                                        |
| 47 | + * @return object Cron() A single instance of this class.  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | +     public static function get_instance() { | 
                                                        |
| 50 | + // If the single instance hasn't been set, set it now.  | 
                                                        |
| 51 | +          if ( null === self::$instance ) { | 
                                                        |
| 52 | + self::$instance = new self();  | 
                                                        |
| 53 | + }  | 
                                                        |
| 54 | + return self::$instance;  | 
                                                        |
| 55 | + }  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + /**  | 
                                                        |
| 58 | + * Registers a 5 min schedule for us to use.  | 
                                                        |
| 59 | + *  | 
                                                        |
| 60 | + * @param array $schedules  | 
                                                        |
| 61 | + * @return array  | 
                                                        |
| 62 | + */  | 
                                                        |
| 63 | +     public function register_schedule( $schedules ) { | 
                                                        |
| 64 | + $schedules['wetu-5-minutes'] = array(  | 
                                                        |
| 65 | + 'interval' => 5 * MINUTE_IN_SECONDS,  | 
                                                        |
| 66 | + 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ),  | 
                                                        |
| 67 | + );  | 
                                                        |
| 68 | + return $schedules;  | 
                                                        |
| 69 | + }  | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | + /**  | 
                                                        |
| 72 | + * Watches for changes in the button triggers.  | 
                                                        |
| 73 | + *  | 
                                                        |
| 74 | + * @return void  | 
                                                        |
| 75 | + */  | 
                                                        |
| 76 | +     public function watch_for_trigger() { | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | +          if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { | 
                                                        |
| 79 | + $options = lsx_wetu_get_options();  | 
                                                        |
| 80 | +  | 
                                                        |
| 81 | + // Check what state the option is in.  | 
                                                        |
| 82 | + $accommodation_cron = 'deactivate';  | 
                                                        |
| 83 | +               if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { | 
                                                        |
| 84 | + $accommodation_cron = 'activate';  | 
                                                        |
| 85 | + }  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + // Check what state the cron is in.  | 
                                                        |
| 88 | + $schedule = false;  | 
                                                        |
| 89 | +               if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { | 
                                                        |
| 90 | + $schedule = true;  | 
                                                        |
| 91 | + }  | 
                                                        |
| 92 | +  | 
                                                        |
| 93 | + // If activate and its not running.  | 
                                                        |
| 94 | +               if ( false === $schedule && 'activate' === $accommodation_cron ) { | 
                                                        |
| 95 | + $schedule = 'daily';  | 
                                                        |
| 96 | + $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );  | 
                                                        |
| 97 | +               } elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { | 
                                                        |
| 98 | + $this->deactivate();  | 
                                                        |
| 99 | + }  | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | + }  | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | + /**  | 
                                                        |
| 104 | + * Remove our cron from the shedule.  | 
                                                        |
| 105 | + *  | 
                                                        |
| 106 | + * @return void  | 
                                                        |
| 107 | + */  | 
                                                        |
| 108 | +     public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { | 
                                                        |
| 109 | + wp_clear_scheduled_hook( $task );  | 
                                                        |
| 110 | + }  | 
                                                        |
| 111 | +  | 
                                                        |
| 112 | + /**  | 
                                                        |
| 113 | + * This function will schedule the cron event.  | 
                                                        |
| 114 | + *  | 
                                                        |
| 115 | + * @param string $task  | 
                                                        |
| 116 | + * @param string $schedule  | 
                                                        |
| 117 | + * @param string $time  | 
                                                        |
| 118 | + * @return void  | 
                                                        |
| 119 | + */  | 
                                                        |
| 120 | +     public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { | 
                                                        |
| 121 | +          if ( '' === $time ) { | 
                                                        |
| 122 | + $time = time();  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | + wp_schedule_event( $time, $schedule, $task, array( $task ) );  | 
                                                        |
| 125 | + }  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + /**  | 
                                                        |
| 128 | + * This is the function that will be triggered by the cron event.  | 
                                                        |
| 129 | + *  | 
                                                        |
| 130 | + * @return void  | 
                                                        |
| 131 | + */  | 
                                                        |
| 132 | +     public function process( $task = '' ) { | 
                                                        |
| 133 | +          switch ( $task ) { | 
                                                        |
| 134 | + case 'lsx_wetu_accommodation_images_cron':  | 
                                                        |
| 135 | + $this->register_accommodation_images_sync();  | 
                                                        |
| 136 | + break;  | 
                                                        |
| 137 | +  | 
                                                        |
| 138 | + default:  | 
                                                        |
| 139 | + break;  | 
                                                        |
| 140 | + }  | 
                                                        |
| 141 | + }  | 
                                                        |
| 142 | +  | 
                                                        |
| 143 | + /**  | 
                                                        |
| 144 | + * This is the function that will be triggered by the cron event.  | 
                                                        |
| 145 | + *  | 
                                                        |
| 146 | + * @return void  | 
                                                        |
| 147 | + */  | 
                                                        |
| 148 | +     public function register_accommodation_images_sync() { | 
                                                        |
| 149 | + $time = strtotime( '+1 min' );  | 
                                                        |
| 150 | +          if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { | 
                                                        |
| 151 | + $this->load_items_to_sync( 'accommodation_images' );  | 
                                                        |
| 152 | + $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );  | 
                                                        |
| 153 | + }  | 
                                                        |
| 154 | + }  | 
                                                        |
| 155 | +  | 
                                                        |
| 156 | + /**  | 
                                                        |
| 157 | + * This is the function that will be triggered by the cron event.  | 
                                                        |
| 158 | + *  | 
                                                        |
| 159 | + * @return void  | 
                                                        |
| 160 | + */  | 
                                                        |
| 161 | +     public function cron_callback() { | 
                                                        |
| 162 | + }  | 
                                                        |
| 163 | +  | 
                                                        |
| 164 | + /**  | 
                                                        |
| 165 | + * This will grab the accommodation ids and load them up into an option field.  | 
                                                        |
| 166 | + *  | 
                                                        |
| 167 | + * @param string $task  | 
                                                        |
| 168 | + * @return void  | 
                                                        |
| 169 | + */  | 
                                                        |
| 170 | +     public function load_items_to_sync( $task = 'accommodation_images' ) { | 
                                                        |
| 171 | + $args = array(  | 
                                                        |
| 172 | + 'post_status' => 'publish',  | 
                                                        |
| 173 | + 'posts_per_page' => -1,  | 
                                                        |
| 174 | + 'nopagin' => true,  | 
                                                        |
| 175 | + 'fields' => 'ids',  | 
                                                        |
| 176 | + );  | 
                                                        |
| 177 | +          switch ( $task ) { | 
                                                        |
| 178 | + case 'accommodation_images':  | 
                                                        |
| 179 | + $args['post_type'] = 'accommodation';  | 
                                                        |
| 180 | + break;  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + default:  | 
                                                        |
| 183 | + break;  | 
                                                        |
| 184 | + }  | 
                                                        |
| 185 | + $items = new \WP_Query( $args );  | 
                                                        |
| 186 | +          if ( $items->have_posts() ) { | 
                                                        |
| 187 | + add_option( 'lsx_wetu_' . $task . '_sync', $items->posts );  | 
                                                        |
| 188 | + }  | 
                                                        |
| 189 | + }  | 
                                                        |
| 190 | 190 | }  | 
                                                        
| 191 | 191 | Cron::get_instance();  | 
                                                        
@@ -33,10 +33,10 @@ discard block  | 
                                                    ||
| 33 | 33 | * @access private  | 
                                                        
| 34 | 34 | */  | 
                                                        
| 35 | 35 |  	public function __construct() { | 
                                                        
| 36 | - add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );  | 
                                                        |
| 37 | - add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );  | 
                                                        |
| 38 | - add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );  | 
                                                        |
| 39 | - add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10 );  | 
                                                        |
| 36 | +		add_filter('cron_schedules', array($this, 'register_schedule'), 10, 1); | 
                                                        |
| 37 | +		add_action('lsx_wetu_importer_settings_before', array($this, 'watch_for_trigger'), 200); | 
                                                        |
| 38 | +		add_action('lsx_wetu_accommodation_images_cron', array($this, 'process'), 10, 1); | 
                                                        |
| 39 | +		add_action('lsx_wetu_accommodation_images_sync', array($this, 'cron_callback'), 10); | 
                                                        |
| 40 | 40 | }  | 
                                                        
| 41 | 41 | |
| 42 | 42 | /**  | 
                                                        
@@ -48,7 +48,7 @@ discard block  | 
                                                    ||
| 48 | 48 | */  | 
                                                        
| 49 | 49 |  	public static function get_instance() { | 
                                                        
| 50 | 50 | // If the single instance hasn't been set, set it now.  | 
                                                        
| 51 | -		if ( null === self::$instance ) { | 
                                                        |
| 51 | +		if (null === self::$instance) { | 
                                                        |
| 52 | 52 | self::$instance = new self();  | 
                                                        
| 53 | 53 | }  | 
                                                        
| 54 | 54 | return self::$instance;  | 
                                                        
@@ -60,10 +60,10 @@ discard block  | 
                                                    ||
| 60 | 60 | * @param array $schedules  | 
                                                        
| 61 | 61 | * @return array  | 
                                                        
| 62 | 62 | */  | 
                                                        
| 63 | -	public function register_schedule( $schedules ) { | 
                                                        |
| 63 | +	public function register_schedule($schedules) { | 
                                                        |
| 64 | 64 | $schedules['wetu-5-minutes'] = array(  | 
                                                        
| 65 | 65 | 'interval' => 5 * MINUTE_IN_SECONDS,  | 
                                                        
| 66 | - 'display' => __( 'Every 5 minutes', 'lsx-wetu-importer' ),  | 
                                                        |
| 66 | +			'display'  => __('Every 5 minutes', 'lsx-wetu-importer'), | 
                                                        |
| 67 | 67 | );  | 
                                                        
| 68 | 68 | return $schedules;  | 
                                                        
| 69 | 69 | }  | 
                                                        
@@ -75,26 +75,26 @@ discard block  | 
                                                    ||
| 75 | 75 | */  | 
                                                        
| 76 | 76 |  	public function watch_for_trigger() { | 
                                                        
| 77 | 77 | |
| 78 | -		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { | 
                                                        |
| 78 | +		if (isset($_GET['page']) && 'lsx-wetu-importer' === $_GET['page'] && isset($_GET['tab']) && 'settings' === $_GET['tab']) { | 
                                                        |
| 79 | 79 | $options = lsx_wetu_get_options();  | 
                                                        
| 80 | 80 | |
| 81 | 81 | // Check what state the option is in.  | 
                                                        
| 82 | 82 | $accommodation_cron = 'deactivate';  | 
                                                        
| 83 | -			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { | 
                                                        |
| 83 | +			if (isset($options['accommodation_images_cron']) && '' !== $options['accommodation_images_cron']) { | 
                                                        |
| 84 | 84 | $accommodation_cron = 'activate';  | 
                                                        
| 85 | 85 | }  | 
                                                        
| 86 | 86 | |
| 87 | 87 | // Check what state the cron is in.  | 
                                                        
| 88 | 88 | $schedule = false;  | 
                                                        
| 89 | -			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { | 
                                                        |
| 89 | +			if (wp_next_scheduled('lsx_wetu_accommodation_images_cron')) { | 
                                                        |
| 90 | 90 | $schedule = true;  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | 92 | |
| 93 | 93 | // If activate and its not running.  | 
                                                        
| 94 | -			if ( false === $schedule && 'activate' === $accommodation_cron ) { | 
                                                        |
| 94 | +			if (false === $schedule && 'activate' === $accommodation_cron) { | 
                                                        |
| 95 | 95 | $schedule = 'daily';  | 
                                                        
| 96 | - $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );  | 
                                                        |
| 97 | -			} elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { | 
                                                        |
| 96 | +				$this->schedule('lsx_wetu_accommodation_images_cron', $schedule); | 
                                                        |
| 97 | +			} elseif (true === $schedule && 'deactivate' === $accommodation_cron) { | 
                                                        |
| 98 | 98 | $this->deactivate();  | 
                                                        
| 99 | 99 | }  | 
                                                        
| 100 | 100 | }  | 
                                                        
@@ -105,8 +105,8 @@ discard block  | 
                                                    ||
| 105 | 105 | *  | 
                                                        
| 106 | 106 | * @return void  | 
                                                        
| 107 | 107 | */  | 
                                                        
| 108 | -	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { | 
                                                        |
| 109 | - wp_clear_scheduled_hook( $task );  | 
                                                        |
| 108 | +	public function deactivate($task = 'lsx_wetu_accommodation_images_cron') { | 
                                                        |
| 109 | + wp_clear_scheduled_hook($task);  | 
                                                        |
| 110 | 110 | }  | 
                                                        
| 111 | 111 | |
| 112 | 112 | /**  | 
                                                        
@@ -117,11 +117,11 @@ discard block  | 
                                                    ||
| 117 | 117 | * @param string $time  | 
                                                        
| 118 | 118 | * @return void  | 
                                                        
| 119 | 119 | */  | 
                                                        
| 120 | -	public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { | 
                                                        |
| 121 | -		if ( '' === $time ) { | 
                                                        |
| 120 | +	public function schedule($task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '') { | 
                                                        |
| 121 | +		if ('' === $time) { | 
                                                        |
| 122 | 122 | $time = time();  | 
                                                        
| 123 | 123 | }  | 
                                                        
| 124 | - wp_schedule_event( $time, $schedule, $task, array( $task ) );  | 
                                                        |
| 124 | + wp_schedule_event($time, $schedule, $task, array($task));  | 
                                                        |
| 125 | 125 | }  | 
                                                        
| 126 | 126 | |
| 127 | 127 | /**  | 
                                                        
@@ -129,8 +129,8 @@ discard block  | 
                                                    ||
| 129 | 129 | *  | 
                                                        
| 130 | 130 | * @return void  | 
                                                        
| 131 | 131 | */  | 
                                                        
| 132 | -	public function process( $task = '' ) { | 
                                                        |
| 133 | -		switch ( $task ) { | 
                                                        |
| 132 | +	public function process($task = '') { | 
                                                        |
| 133 | +		switch ($task) { | 
                                                        |
| 134 | 134 | case 'lsx_wetu_accommodation_images_cron':  | 
                                                        
| 135 | 135 | $this->register_accommodation_images_sync();  | 
                                                        
| 136 | 136 | break;  | 
                                                        
@@ -146,10 +146,10 @@ discard block  | 
                                                    ||
| 146 | 146 | * @return void  | 
                                                        
| 147 | 147 | */  | 
                                                        
| 148 | 148 |  	public function register_accommodation_images_sync() { | 
                                                        
| 149 | - $time = strtotime( '+1 min' );  | 
                                                        |
| 150 | -		if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) { | 
                                                        |
| 151 | - $this->load_items_to_sync( 'accommodation_images' );  | 
                                                        |
| 152 | - $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );  | 
                                                        |
| 149 | +		$time = strtotime('+1 min'); | 
                                                        |
| 150 | +		if (!wp_next_scheduled('lsx_wetu_accommodation_images_sync')) { | 
                                                        |
| 151 | +			$this->load_items_to_sync('accommodation_images'); | 
                                                        |
| 152 | +			$this->schedule('lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time); | 
                                                        |
| 153 | 153 | }  | 
                                                        
| 154 | 154 | }  | 
                                                        
| 155 | 155 | |
@@ -167,14 +167,14 @@ discard block  | 
                                                    ||
| 167 | 167 | * @param string $task  | 
                                                        
| 168 | 168 | * @return void  | 
                                                        
| 169 | 169 | */  | 
                                                        
| 170 | -	public function load_items_to_sync( $task = 'accommodation_images' ) { | 
                                                        |
| 170 | +	public function load_items_to_sync($task = 'accommodation_images') { | 
                                                        |
| 171 | 171 | $args = array(  | 
                                                        
| 172 | 172 | 'post_status' => 'publish',  | 
                                                        
| 173 | 173 | 'posts_per_page' => -1,  | 
                                                        
| 174 | 174 | 'nopagin' => true,  | 
                                                        
| 175 | 175 | 'fields' => 'ids',  | 
                                                        
| 176 | 176 | );  | 
                                                        
| 177 | -		switch ( $task ) { | 
                                                        |
| 177 | +		switch ($task) { | 
                                                        |
| 178 | 178 | case 'accommodation_images':  | 
                                                        
| 179 | 179 | $args['post_type'] = 'accommodation';  | 
                                                        
| 180 | 180 | break;  | 
                                                        
@@ -182,9 +182,9 @@ discard block  | 
                                                    ||
| 182 | 182 | default:  | 
                                                        
| 183 | 183 | break;  | 
                                                        
| 184 | 184 | }  | 
                                                        
| 185 | - $items = new \WP_Query( $args );  | 
                                                        |
| 186 | -		if ( $items->have_posts() ) { | 
                                                        |
| 187 | - add_option( 'lsx_wetu_' . $task . '_sync', $items->posts );  | 
                                                        |
| 185 | + $items = new \WP_Query($args);  | 
                                                        |
| 186 | +		if ($items->have_posts()) { | 
                                                        |
| 187 | +			add_option('lsx_wetu_'.$task.'_sync', $items->posts); | 
                                                        |
| 188 | 188 | }  | 
                                                        
| 189 | 189 | }  | 
                                                        
| 190 | 190 | }  |