Skip to content

Commit

Permalink
feat: switch plugin base url to just vrts and update url helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Oct 17, 2024
1 parent 0417022 commit 3a00896
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 103 deletions.
7 changes: 6 additions & 1 deletion components/admin-header-navigation/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<nav class="vrts_admin_header_menu">
<a class="vrts_logo_link" href="<?php echo esc_url( admin_url( 'admin.php?page=vrts-tests' ) ); ?>">
<a class="vrts_logo_link" href="<?php echo esc_url( Url_Helpers::get_page_url( 'tests' ) ); ?>">
<h2>
<span class="vrts_logo"><?php vrts()->logo(); ?></span>
<?php echo esc_html( $data['plugin_name'] ); ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<div class="notice updated is-dismissible" data-view="<?php echo esc_attr( $data['view'] ); ?>">
<p>
<strong><?php esc_html_e( 'VRTs Plugin successfully activated!', 'visual-regression-tests' ); ?></strong>
<?php
printf(
/* translators: %1$s, %2$s and %3$s, %4$s: link wrapper. */
esc_html__( 'Start to %1$sconfigure tests%2$s, or check the customization options in the %3$splugin settings%4$s.', 'visual-regression-tests' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-tests' ) ) . '">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'tests' ) ) . '">',
'</a>',
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-settings' ) ) . '">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'settings' ) ) . '">',
'</a>'
);
?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<div class="vrts-metabox-notice vrts-metabox-notice-is-error">
<p><strong><?php esc_html_e( 'Connection failed', 'visual-regression-tests' ); ?></strong></p>
<p><?php esc_html_e( 'Something went wrong while trying to connect to the external service.', 'visual-regression-tests' ); ?></p>
<p><a href="<?php echo esc_attr( admin_url( 'admin.php?page=vrts-tests' ) ); ?>"><?php esc_html_e( 'Go to plugin page', 'visual-regression-tests' ); ?></a></p>
<p><a href="<?php echo esc_attr( Url_Helpers::get_page_url( 'tests' ) ); ?>"><?php esc_html_e( 'Go to plugin page', 'visual-regression-tests' ); ?></a></p>
</div>
2 changes: 1 addition & 1 deletion editor/components/metabox-notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const NotificationConnectionFailed = ( { pluginUrl = '' } ) => {
__html: DOMPurify.sanitize(
sprintf(
'<a href="%1$s" title="%2$s">%2$s</a>',
pluginUrl, //admin_url( 'admin.php?page=vrts-tests' )
pluginUrl,
__(
'Go to plugin page',
'visual-regression-tests'
Expand Down
84 changes: 13 additions & 71 deletions includes/core/utilities/class-url-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public static function get_relative_permalink( $post_id ) {
return $permalink;
}

/**
* Get the page URL.
*
* @param string $page Page.
*
* @return string
*/
public static function get_page_url( $page ) {
return admin_url( 'admin.php?page=' . $page );
}

/**
* Get the alert page URL.
*
Expand Down Expand Up @@ -68,7 +79,7 @@ public static function get_alerts_page( $test_run ) {
*/
public static function get_run_manual_test_url( $test_id ) {
return add_query_arg( [
'page' => 'vrts-tests',
'page' => 'vrts',
'action' => 'run-manual-test',
'test_id' => $test_id,
], admin_url( 'admin.php' ) );
Expand All @@ -83,7 +94,7 @@ public static function get_run_manual_test_url( $test_id ) {
*/
public static function get_disable_testing_url( $test_id ) {
return add_query_arg( [
'page' => 'vrts-tests',
'page' => 'vrts',
'action' => 'disable-testing',
'test_id' => $test_id,
], admin_url( 'admin.php' ) );
Expand All @@ -106,73 +117,4 @@ public static function get_test_run_page( $test_run_id ) {
'run_id' => $test_run_id,
], admin_url( 'admin.php' ) );
}

/**
* Get the test runs page URL.
*
* @return string
*/
public static function get_test_runs_page() {
return add_query_arg( [
'page' => 'vrts-runs',
], admin_url( 'admin.php' ) );
}

/**
* Get the mark run as read page URL.
*
* @param int $test_run_id Test run id.
* @param bool $redirect_to_overview Redirect to overview.
*
* @return string
*/
public static function get_mark_as_read_url( $test_run_id, $redirect_to_overview = false ) {
$url = static::get_test_run_page( $test_run_id );
return add_query_arg( [
'action' => 'mark_as_read',
'redirect' => $redirect_to_overview ? 'overview' : '',
], $url );
}

/**
* Get the mark run as unread page URL.
*
* @param int $test_run_id Test run id.
* @param bool $redirect_to_overview Redirect to overview.
*
* @return string
*/
public static function get_mark_as_unread_url( $test_run_id, $redirect_to_overview = false ) {
$url = static::get_test_run_page( $test_run_id );
return add_query_arg( [
'action' => 'mark_as_unread',
'redirect' => $redirect_to_overview ? 'overview' : '',
], $url );
}

/**
* Get the tests page URL.
*
* @return string
*/
public static function get_tests_url() {
return admin_url( 'admin.php?page=vrts-tests' );
}

/**
* Get the set false positive page URL.
*
* @param int $test_run_id Test run id.
* @param int $alert_id Alert id.
* @param bool $is_false_positive Is false positive.
*
* @return string
*/
public static function get_set_false_positive_url( $test_run_id, $alert_id, $is_false_positive = false ) {
$url = static::get_test_run_page( $test_run_id ) . '&alert_id=' . $alert_id;
return add_query_arg( [
'action' => $is_false_positive ? 'remove_false_positive' : 'flag_false_positive',
'redirect' => '',
], $url );
}
}
5 changes: 3 additions & 2 deletions includes/features/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vrts\Features;

use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Models\Alert;

class Admin {
Expand Down Expand Up @@ -40,8 +41,8 @@ public function add_main_menu() {
* @return array $links Plugin Action links.
*/
public function plugin_action_links( $links ) {
$links['tests'] = '<a href="' . esc_url( admin_url( 'admin.php?page=vrts-tests' ) ) . '" aria-label="' . esc_attr__( 'Tests', 'visual-regression-tests' ) . '">' . esc_html__( 'Tests', 'visual-regression-tests' ) . '</a>';
$links['settings'] = '<a href="' . esc_url( admin_url( 'admin.php?page=vrts-settings' ) ) . '" aria-label="' . esc_attr__( 'Settings', 'visual-regression-tests' ) . '">' . esc_html__( 'Settings', 'visual-regression-tests' ) . '</a>';
$links['tests'] = '<a href="' . esc_url( Url_Helpers::get_page_url( 'tests' ) ) . '" aria-label="' . esc_attr__( 'Tests', 'visual-regression-tests' ) . '">' . esc_html__( 'Tests', 'visual-regression-tests' ) . '</a>';
$links['settings'] = '<a href="' . esc_url( Url_Helpers::get_page_url( 'settings' ) ) . '" aria-label="' . esc_attr__( 'Settings', 'visual-regression-tests' ) . '">' . esc_html__( 'Settings', 'visual-regression-tests' ) . '</a>';
return $links;
}
}
3 changes: 2 additions & 1 deletion includes/features/class-bulk-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vrts\Features;

use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Services\Test_Service;

class Bulk_Actions {
Expand Down Expand Up @@ -47,7 +48,7 @@ public function handle_bulk_optimize_action( $redirect_to, $doaction, $post_ids

$service = new Test_Service();
$created_tests = $service->create_tests( $post_ids );
$vrts_url = admin_url( 'admin.php?page=vrts-tests' );
$vrts_url = Url_Helpers::get_page_url( 'tests' );

if ( is_wp_error( $created_tests ) ) {
$redirect_to = add_query_arg([
Expand Down
7 changes: 3 additions & 4 deletions includes/features/class-enqueue-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

use Vrts\Core\Utilities\Date_Time_Helpers;
use Vrts\Core\Utilities\Image_Helpers;
use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Models\Test;
use Vrts\Features\Metaboxes;
use Vrts\Features\Subscription;
use Vrts\Models\Alert;

class Enqueue_Scripts {
/**
Expand Down Expand Up @@ -113,8 +112,8 @@ public function enqueue_block_editor_assets() {
'base_screenshot_date' => Date_Time_Helpers::get_formatted_date_time( Test::get_base_screenshot_date( $post->ID ) ),
'remaining_tests' => Subscription::get_remaining_tests(),
'total_tests' => Subscription::get_total_tests(),
'upgrade_url' => admin_url( 'admin.php?page=vrts-upgrade' ),
'plugin_url' => admin_url( 'admin.php?page=vrts-tests' ),
'upgrade_url' => Url_Helpers::get_page_url( 'upgrade' ),
'plugin_url' => Url_Helpers::get_page_url( 'tests' ),
'is_connected' => Service::is_connected(),
'test_status' => Test::get_status_data( $test ),
'screenshot' => Test::get_screenshot_data( $test ),
Expand Down
4 changes: 1 addition & 3 deletions includes/features/class-metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use Vrts\Core\Utilities\Date_Time_Helpers;
use Vrts\Core\Utilities\Image_Helpers;
use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Models\Alert;
use Vrts\Models\Test;
use Vrts\Services\Test_Service;
use WP_Error;

class Metaboxes {

Expand Down Expand Up @@ -136,7 +134,7 @@ public function render_metabox() {
vrts()->component('metabox-classic-editor', [
'post_id' => $post_id,
'nonce' => $this->nonce,
'plugin_url' => admin_url( 'admin.php?page=vrts-tests' ),
'plugin_url' => Url_Helpers::get_page_url( 'tests' ),
'run_tests_checked' => $run_tests_checked,
'field_test_status_key' => self::$field_test_status_key,
'has_post_alert' => Test::has_post_alert( $post_id ),
Expand Down
8 changes: 4 additions & 4 deletions includes/features/class-onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function get_onboardings() {
*/
public function should_display_tests_welcome_onboarding() {
$page = sanitize_text_field( wp_unslash( $_GET['page'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
if ( 'vrts-tests' === $page ) {
if ( 'vrts' === $page ) {
$frontpage_id = get_option( 'page_on_front' );
$is_front_page_added = ! is_null( Test::get_item_id( $frontpage_id ) );
$next_id = Test::get_autoincrement_value();
Expand All @@ -175,7 +175,7 @@ public function should_display_first_test_onboarding() {
$page = sanitize_text_field( wp_unslash( $_GET['page'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
$is_new_test_added = isset( $_GET['new-test-added'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.

if ( 'vrts-tests' === $page && $is_new_test_added ) {
if ( 'vrts' === $page && $is_new_test_added ) {
$frontpage_id = get_option( 'page_on_front' );
$is_front_page_added = ! is_null( Test::get_item_id( $frontpage_id ) );
$next_id = Test::get_autoincrement_value();
Expand All @@ -197,7 +197,7 @@ public function should_display_run_test_onboarding() {
$page = sanitize_text_field( wp_unslash( $_GET['page'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
$has_subscription = (bool) Subscription::get_subscription_status();

if ( 'vrts-tests' === $page && $has_subscription ) {
if ( 'vrts' === $page && $has_subscription ) {
$tests = Test::get_items();

foreach ( $tests as $test ) {
Expand All @@ -219,7 +219,7 @@ public function should_display_run_test_onboarding() {
public function should_display_runs_introduction_onboarding() {
$page = sanitize_text_field( wp_unslash( $_GET['page'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.

if ( in_array( $page, [ 'vrts-tests', 'vrts-runs', 'vrts-settings' ], true ) ) {
if ( in_array( $page, [ 'vrts', 'vrts-runs', 'vrts-settings' ], true ) ) {
$has_migrated_alerts = get_option( 'vrts_test_runs_has_migrated_alerts' );

if ( $has_migrated_alerts ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/features/class-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function add_settings() {
'id' => 'vrts_email_manual_notification_address',
'section' => 'vrts-settings-section-notifications',
'title' => esc_html__( 'Manual', 'visual-regression-tests' ),
'description' => esc_html__( 'Alerts are automatically sent to the user who Triggers the Manual Test.', 'visual-regression-tests' ),
'description' => esc_html__( 'Alerts are automatically sent to the user who triggers the Manual Test.', 'visual-regression-tests' ),
'is_pro' => $has_subscription,
]);
}
Expand Down
12 changes: 6 additions & 6 deletions includes/features/class-tests-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function add_submenu_page() {
__( 'Tests', 'visual-regression-tests' ),
__( 'Tests', 'visual-regression-tests' ),
'manage_options',
'vrts-tests',
'vrts',
[ $this, 'render_page' ],
1
);
Expand Down Expand Up @@ -108,7 +108,7 @@ public function submit_add_new_test() {
}

$errors = [];
$page_url = admin_url( 'admin.php?page=vrts-tests' );
$page_url = Url_Helpers::get_page_url( 'tests' );

$post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : 0;

Expand Down Expand Up @@ -165,7 +165,7 @@ public function submit_run_manual_tests() {
$service = new Manual_Test_Service();
$service->run_tests();

$page_url = Url_Helpers::get_test_runs_page();
$page_url = Url_Helpers::get_page_url( 'runs' );
wp_safe_redirect( $page_url );
exit;
}
Expand All @@ -188,7 +188,7 @@ public function submit_retry_connection() {

$response = Service::retry_connection();

$page_url = admin_url( 'admin.php?page=vrts-tests' );
$page_url = Url_Helpers::get_page_url( 'tests' );
wp_safe_redirect( $page_url );
exit;
}
Expand All @@ -210,7 +210,7 @@ public function process_column_actions() {
}

$errors = [];
$page_url = admin_url( 'admin.php?page=vrts-tests' );
$page_url = Url_Helpers::get_page_url( 'tests' );

$test_id = isset( $_GET['test_id'] ) ? sanitize_text_field( wp_unslash( $_GET['test_id'] ) ) : 0;
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : 0;
Expand Down Expand Up @@ -509,7 +509,7 @@ public function handle_bulk_actions() {

$manual_test_service = new Manual_Test_Service();
$manual_test_service->run_tests( $test_ids );
$page_url = Url_Helpers::get_test_runs_page();
$page_url = Url_Helpers::get_page_url( 'runs' );
wp_safe_redirect( $page_url );
exit;
}
Expand Down
4 changes: 2 additions & 2 deletions includes/list-tables/class-test-runs-queue-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function no_items() {
printf(
/* translators: %1$s, %2$s link wrapper. */
esc_html__( 'No Runs in the queue. %1$sAdd Tests%2$s to get started.', 'visual-regression-tests' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-tests' ) ) . '">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'tests' ) ) . '">',
'</a>'
);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public function column_status( $item ) {
$instructions = sprintf(
'<a href="%1$s">%2$s</a> | <a href="%3$s">%4$s</a>',
// translators: %s: number of tests.
esc_url( Url_Helpers::get_tests_url() ),
esc_url( Url_Helpers::get_page_url( 'tests' ) ),
sprintf(
/* translators: %s Test. Test count */
esc_html( _n( '%s Test', '%s Tests', $number_of_tests, 'visual-regression-tests' ) ),
Expand Down
2 changes: 1 addition & 1 deletion includes/list-tables/class-tests-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function column_cb( $item ) {
* @return array
*/
public function get_views() {
$base_link = admin_url( 'admin.php?page=vrts-tests' );
$base_link = Url_Helpers::get_page_url( 'tests' );

$links = [
'all' => [
Expand Down
4 changes: 2 additions & 2 deletions includes/models/class-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ public static function get_status_data( $test ) {
$instructions = Date_Time_Helpers::get_formatted_relative_date_time( $next_run->scheduled_at );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required here.
if ( $has_subscription && isset( $_GET['page'] ) && 'vrts-tests' === $_GET['page'] ) {
if ( $has_subscription && isset( $_GET['page'] ) && 'vrts' === $_GET['page'] ) {
$instructions .= sprintf(
'<a class="vrts-run-test" href="%s" data-id="%d" title="%s">%s</a>',
Url_Helpers::get_run_manual_test_url( $test->id ),
Expand All @@ -965,7 +965,7 @@ public static function get_status_data( $test ) {
$instructions .= Date_Time_Helpers::get_formatted_relative_date_time( $test->last_comparison_date );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required here.
if ( $has_subscription && isset( $_GET['page'] ) && 'vrts-tests' === $_GET['page'] ) {
if ( $has_subscription && isset( $_GET['page'] ) && 'vrts' === $_GET['page'] ) {
$instructions .= sprintf(
'<a class="vrts-run-test" href="%s" data-id="%d" title="%s">%s</a>',
Url_Helpers::get_run_manual_test_url( $test->id ),
Expand Down
1 change: 0 additions & 1 deletion includes/services/class-email-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Vrts\Services;

use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Models\Alert;
use Vrts\Models\Test;
use Vrts\Models\Test_Run;
Expand Down

0 comments on commit 3a00896

Please sign in to comment.