product_slug = $slug; $this->product_version = $version; $this->product_cron = self::key_ready_name( $this->product_slug ) . "_log_activity"; } /** * @param string $string the String to be normalized for cron handler * * @return string $name the normalized string */ static function key_ready_name( $string ) { return str_replace( "-", "_", strtolower( trim( $string ) ) ); } /** * Start the cron to send the log. It will randomize the interval in order to not send all the logs at the same time. */ public function start() { if ( ! wp_next_scheduled( $this->product_cron ) ) { wp_schedule_single_event( time() + ( rand( 15, 24 ) * 3600 ), $this->product_cron ); } add_action( $this->product_cron, array( $this, "send_log" ) ); } /** * Send the statistics to the api endpoint */ public function send_log() { wp_remote_post( $this->logging_url, array( 'method' => 'POST', 'timeout' => 3, 'redirection' => 5, 'headers' => array( "X-ThemeIsle-Event" => "log_site" ), 'body' => array( 'site' => get_site_url(), 'product' => $this->product_slug, 'version' => $this->product_version ), ) ); } } endif;