in = false ) { $ignore_last_checkin = $ignore_last_checkin || defined( DOING_CRON ) && DOING_CRON; $home_url = trailingslashit( home_url() ); if ( strpos( $home_url, 'imagely.com' ) !== false ) { return false; } // Send a maximum of once per week. $last_send = get_option( 'nextgen_usage_tracking_last_checkin' ); if ( is_numeric( $last_send ) && $last_send > strtotime( '-1 week' ) && ! $ignore_last_checkin ) { return false; } $request = wp_remote_post( $this->endpoint, [ 'method' => 'POST', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.1', 'blocking' => false, 'body' => $this->get_data(), 'user-agent' => $this->user_agent, ] ); // If we have completed successfully, recheck in 1 week. update_option( 'nextgen_usage_tracking_last_checkin', time() ); return true; } /** * Schedule the checkin * * @since 3.59.5 * @return void */ public function schedule_send() { if ( wp_next_scheduled( 'nextgen_usage_tracking_cron' ) ) { return; } $tracking = []; $tracking['day'] = wp_rand( 0, 6 ); $tracking['hour'] = wp_rand( 0, 23 ); $tracking['minute'] = wp_rand( 0, 59 ); $tracking['second'] = wp_rand( 0, 59 ); $tracking['offset'] = ( $tracking['day'] * DAY_IN_SECONDS ); $tracking['offset'] += ( $tracking['hour'] * HOUR_IN_SECONDS ); $tracking['offset'] += ( $tracking['minute'] * MINUTE_IN_SECONDS ); $tracking['offset'] += $tracking['second']; $tracking['initsend'] = strtotime( 'next sunday' ) + $tracking['offset']; wp_schedule_event( $tracking['initsend'], 'weekly', 'nextgen_usage_tracking_cron' ); update_option( 'nextgen_usage_tracking_config', wp_json_encode( $tracking ) ); } /** * Add weekly schedule * * @since 3.59.5 * * @param array $schedules Array of schedules. * * @return array */ public function add_schedules( $schedules = [] ) { if ( isset( $schedules['weekly'] ) ) { return $schedules; } $schedules['weekly'] = [ 'interval' => 604800, 'display' => __( 'Once Weekly', 'nextgen-gallery' ), ]; return $schedules; } }