Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Mar 20, 2024
1 parent 33c7a32 commit 2b0514e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions includes/core/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public function component( $name, $data = [] ) {
* @return string Desired plugin information.
*/
public function get_plugin_info( $info ) {
if( !function_exists('get_plugin_data') ){
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin = get_plugin_data( $this->plugin_file );

$infos = [
Expand Down
20 changes: 19 additions & 1 deletion includes/features/class-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Vrts\Services\Test_Service;

class Service {
const DB_VERSION = '1.0';
const DB_VERSION = '1.1';
const SERVICE = 'vrts_service';
const BASE_URL = VRTS_SERVICE_ENDPOINT;

Expand All @@ -27,6 +27,12 @@ public static function connect_service() {
if ( self::is_connected() && ! self::has_secret() ) {
self::create_secret();
}
if ( $installed_version && version_compare( $installed_version, '1.1', '<' ) ) {
$service_project_id = get_option( 'vrts_project_id' );
$service_api_route = 'sites/' . $service_project_id;

Service::rest_service_request( $service_api_route, [], 'put' );
}
}

/**
Expand Down Expand Up @@ -105,6 +111,8 @@ public static function rest_service_request( $service_api_route, $parameters = [
$args['headers']['Authorization'] = 'Bearer ' . $service_project_token;
}

add_filter( 'http_headers_useragent', [ static::class, 'set_user_agent' ], 10);

switch ( $request_type ) {
case 'get':
$args = [
Expand Down Expand Up @@ -148,6 +156,9 @@ public static function rest_service_request( $service_api_route, $parameters = [
'status_code' => wp_remote_retrieve_response_code( $data ),
];
}

remove_filter( 'http_headers_useragent', [ static::class, 'set_user_agent' ], 10);

return $response;
}

Expand Down Expand Up @@ -322,6 +333,13 @@ public static function has_secret() {
return (bool) get_option( 'vrts_project_secret' );
}

/**
* Set user agent for the request.
*/
public static function set_user_agent( $user_agent ) {
return 'VRTs/' . vrts()->get_plugin_info('version') . ';' . $user_agent;
}

/**
* Create secret for the project
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/services/class-test-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function update_test_from_api_data( $data ) {
$this->update_test_from_schedule( $test_id, $data );
} elseif ( $data['comparison'] ?? null ) {
$alert_id = null;
if ( $data['is_paused'] ?? null && $data['comparison']['pixels_diff'] > 1 ) {
if ( $data['comparison']['pixels_diff'] > 1 && ! $data['matches_false_positive'] ) {
$comparison = $data['comparison'];
$alert_service = new Alert_Service();
$alert_id = $alert_service->create_alert_from_comparison( $post_id, $test_id, $comparison );
Expand Down
2 changes: 1 addition & 1 deletion visual-regression-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: VRTs – Visual Regression Tests
* Plugin URI: https://bleech.de/en/products/visual-regression-tests/
* Description: Test your website for unwanted visual changes. Run automatic tests and spot differences.
* Version: 1.8.0
* Version: 1.9.0
* Requires at least: 5.0
* Requires PHP: 7.0
* Author: Bleech
Expand Down

0 comments on commit 2b0514e

Please sign in to comment.