Skip to content

Commit

Permalink
feat: use url helpers for all urls
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Oct 17, 2024
1 parent 3a00896 commit 176f43b
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<div class="vrts-notice notice notice-error is-dismissable" data-view="<?php echo esc_attr( $data['view'] ); ?>">
<h3><?php esc_html_e( 'Ready for an Upgrade?', 'visual-regression-tests' ); ?></h3>
<p>
<?php
printf(
'%1$s <a href="%2$s" title="%3$s">%3$s</a>',
esc_html__( 'Looks like you need a bigger plan to add more tests.', 'visual-regression-tests' ),
esc_url( admin_url( 'admin.php?page=vrts-upgrade' ) ),
esc_url( Url_Helpers::get_page_url( 'upgrade' ) ),
esc_html__( 'Upgrade here!', 'visual-regression-tests' )
);
?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<div class="vrts-notice notice notice-info" data-view="<?php echo esc_attr( $data['view'] ); ?>">
<h3><?php esc_html_e( 'Unlock more tests', 'visual-regression-tests' ); ?></h3>
<p>
Expand All @@ -13,7 +18,7 @@
sprintf(
/* translators: %1$s, %2$s: link wrapper. */
esc_html__( 'Upgrade %1$shere%2$s to add more tests to your website!', 'visual-regression-tests' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-upgrade' ) ) . '">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'upgrade' ) ) . '">',
'</a>'
)
)
Expand Down
7 changes: 6 additions & 1 deletion components/alert-actions/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<vrts-alert-actions class="vrts-alert-actions">
<button type="button" data-vrts-dropdown-open class="vrts-alert-actions__trigger" aria-expanded="false" aria-controls="vrts-alert-actions-dropdown">
<?php vrts()->icon( 'more-horizontal' ); ?>
Expand Down Expand Up @@ -36,7 +41,7 @@
<?php esc_html_e( 'Hide elements', 'visual-regression-tests' ); ?>
</h2>
<div class="vrts-modal__content-inner">
<form data-vrts-hide-elements-form action="<?php echo esc_url( admin_url( 'admin.php?page=vrts-runs' ) ); ?>" method="put">
<form data-vrts-hide-elements-form action="<?php echo esc_url( Url_Helpers::get_page_url( 'runs' ) ); ?>" method="put">
<input type="hidden" name="post_id" value="<?php echo esc_attr( $data['alert']->post_id ); ?>">
<input type="hidden" name="test_id" value="<?php echo esc_attr( $data['test_settings']['test_id'] ); ?>">
<textarea class="widefat" name="hide_css_selectors" placeholder="<?php esc_html_e( 'e.g.: .lottie, #ads', 'visual-regression-tests' ); ?>" rows="4"><?php echo esc_html( $data['test_settings']['hide_css_selectors'] ); ?></textarea>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<div class="vrts-metabox-notice vrts-metabox-notice-is-info">
<p><strong><?php esc_html_e( 'Unlock more tests', 'visual-regression-tests' ); ?></strong></p>
<p>
Expand All @@ -13,7 +18,7 @@
sprintf(
/* translators: %1$s, %2$s: link wrapper. */
esc_html__( 'Upgrade %1$shere%2$s to add more tests to your website!', 'visual-regression-tests' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-upgrade' ) ) . '" target="_blank">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'upgrade' ) ) . '" target="_blank">',
'</a>'
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@

<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<div class="vrts-metabox-notice vrts-metabox-notice-is-error">
<p><strong><?php esc_html_e( 'Ready for an Upgrade?', 'visual-regression-tests' ); ?></strong></p>
<p>
<?php
printf(
'%1$s <a href="%2$s" target="_blank" title="%3$s">%3$s</a>',
esc_html__( 'Looks like you need a bigger plan to add more tests.', 'visual-regression-tests' ),
esc_url( admin_url( 'admin.php?page=vrts-upgrade' ) ),
esc_url( Url_Helpers::get_page_url( 'upgrade' ) ),
esc_html__( 'Upgrade here!', 'visual-regression-tests' )
);
?>
Expand Down
7 changes: 6 additions & 1 deletion components/settings-page/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

use Vrts\Core\Utilities\Url_Helpers;

?>
<vrts-settings class="wrap vrts-settings">
<h1><?php echo esc_html( $data['title'] ); ?></h1>
<form method="post" action="options.php">
Expand All @@ -16,7 +21,7 @@
</h2>
<div class="vrts-modal__content-inner">
<p class="vrts-settings__modal-info"><?php esc_html_e( 'Upgrade your plan and unlock automatic testing after updates, plus more tools like manual testing to keep your sites running smoothly.', 'visual-regression-tests' ); ?></p>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=vrts-upgrade' ) ); ?>" class="button button-primary vrts-settings__modal-link"><?php esc_html_e( 'Unlock Now', 'visual-regression-tests' ); ?></a>
<a href="<?php echo esc_url( Url_Helpers::get_page_url( 'upgrade' ) ); ?>" class="button button-primary vrts-settings__modal-link"><?php esc_html_e( 'Unlock Now', 'visual-regression-tests' ); ?></a>
</div>
</div>
</vrts-modal>
Expand Down
5 changes: 3 additions & 2 deletions components/test-run-alerts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

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

$unread_alerts = Alert::get_unread_count_by_test_run_ids( $data['run']->id );
$unread_count = $unread_alerts[0]->count ?? 0;

?>
<vrts-test-run-alerts class="vrts-test-run-alerts" data-vrts-current-alert="<?php echo esc_attr( isset( $data['alert']->id ) ? $data['alert']->id : 'false' ); ?>">
<div class="vrts-test-run-alerts__heading">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=vrts-runs' ) ); ?>" class="vrts-test-run-alerts__heading-link">
<a href="<?php echo esc_url( Url_Helpers::get_page_url( 'runs' ) ); ?>" class="vrts-test-run-alerts__heading-link">
<?php vrts()->icon( 'chevron-left' ); ?>
<?php esc_html_e( 'All Runs', 'visual-regression-tests' ); ?>
</a>
Expand All @@ -32,7 +33,7 @@
$alert_link = add_query_arg( [
'run_id' => $data['run']->id,
'alert_id' => $alert->id,
], admin_url( 'admin.php?page=vrts-runs' ) );
], Url_Helpers::get_page_url( 'runs' ) );

$parsed_tested_url = wp_parse_url( get_permalink( $alert->post_id ) );
$tested_url = $parsed_tested_url['path'];
Expand Down
11 changes: 6 additions & 5 deletions components/test-runs-page/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<?php

use Vrts\Features\Admin_Notices;
use Vrts\Services\Manual_Test_Service;

?>
<vrts-test-runs-page class="wrap vrts-list-table-page vrts-test-runs-page">
<h1 class="wp-heading-inline">
<?php esc_html_e( 'Runs', 'visual-regression-tests' ); ?>
Expand All @@ -12,8 +18,6 @@
$list_table->display();
?>

<form id="vrts-filter-alerts-form" action="<?php echo esc_url( admin_url( 'admin.php?page=vrts-alerts' ) ); ?>" method="post"></form>

<form method="post">
<?php
$list_table = $data['list_table'];
Expand All @@ -27,9 +31,6 @@
?>
</form>
<?php
use Vrts\Features\Admin_Notices;
use Vrts\Services\Manual_Test_Service;

$vrts_manual_test_service = new Manual_Test_Service();
$test_status = $vrts_manual_test_service->get_option();
if ( $test_status ) {
Expand Down
2 changes: 1 addition & 1 deletion editor/components/metabox-notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const NotificationUpgradeRequired = ( { upgradeUrl = '' } ) => {
'Looks like you need a bigger plan to add more tests.',
'visual-regression-tests'
),
upgradeUrl, //admin_url( 'admin.php?page=vrts-upgrade' )
upgradeUrl,
__( 'Upgrade here!', 'visual-regression-tests' )
)
),
Expand Down
1 change: 1 addition & 0 deletions includes/core/utilities/class-url-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static function get_relative_permalink( $post_id ) {
* @return string
*/
public static function get_page_url( $page ) {
$page = 'tests' === $page ? 'vrts' : 'vrts-' . $page;
return admin_url( 'admin.php?page=' . $page );
}

Expand Down
3 changes: 2 additions & 1 deletion includes/features/class-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Vrts\Features;

use Vrts\Core\Utilities\Sanitization;
use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Features\Subscription;

class Settings_Page {
Expand Down Expand Up @@ -103,7 +104,7 @@ public function add_settings() {
'description' => sprintf(
'%1$s <a href="%2$s" title="%3$s">%3$s</a>',
esc_html__( 'No license key yet?', 'visual-regression-tests' ),
esc_url( admin_url( 'admin.php?page=vrts-upgrade' ) ),
esc_url( Url_Helpers::get_page_url( 'upgrade' ) ),
esc_html__( 'Upgrade here.', 'visual-regression-tests' )
),
'placeholder' => esc_html_x( 'XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX', 'license key placeholder', 'visual-regression-tests' ),
Expand Down
3 changes: 2 additions & 1 deletion includes/features/class-test-runs-page.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\List_Tables\Test_Runs_List_Table;
use Vrts\List_Tables\Test_Runs_Queue_List_Table;
use Vrts\Models\Alert;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function render_page() {
list($alert_id, $alert) = $this->get_alert( $alerts );
$base_link = add_query_arg( [
'run_id' => $run_id,
], admin_url( 'admin.php?page=vrts-runs' ) );
], Url_Helpers::get_page_url( 'runs' ) );

Alert::set_alert_state( $alert_id, 1 );
$service = new Test_Run_Service();
Expand Down
2 changes: 1 addition & 1 deletion includes/list-tables/class-test-runs-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function get_sortable_columns() {
* @return array
*/
public function get_views() {
$base_link = admin_url( 'admin.php?page=vrts-runs' );
$base_link = Url_Helpers::get_page_url( 'runs' );

$links = [
'all' => [
Expand Down
6 changes: 3 additions & 3 deletions includes/list-tables/class-test-runs-queue-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function get_columns() {
* @return array
*/
public function get_views() {
$base_link = admin_url( 'admin.php?page=vrts-runs' );
$base_link = Url_Helpers::get_page_url( 'runs' );

$links = [
'all' => [
Expand Down Expand Up @@ -241,7 +241,7 @@ public function column_status( $item ) {
sprintf(
// translators: %1$s: link start to test runs page. %2$s: link end to test runs page.
wp_kses( __( '%1$sRefresh page%2$s to see results', 'visual-regression-tests' ), [ 'a' => [ 'href' => [] ] ] ),
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-runs' ) ) . '">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'runs' ) ) . '">',
'</a>'
)
);
Expand All @@ -257,7 +257,7 @@ public function column_status( $item ) {
esc_html( _n( '%s Test', '%s Tests', $number_of_tests, 'visual-regression-tests' ) ),
$number_of_tests
),
esc_url( admin_url( 'admin.php?page=vrts-settings' ) ),
esc_url( Url_Helpers::get_page_url( 'settings' ) ),
esc_html__( 'Edit configuration', 'visual-regression-tests' )
);
}//end if
Expand Down
3 changes: 0 additions & 3 deletions includes/list-tables/class-tests-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace Vrts\List_Tables;

use Vrts\Core\Utilities\Date_Time_Helpers;
use Vrts\Core\Utilities\Url_Helpers;
use Vrts\Models\Test;
use Vrts\Features\Service;
use Vrts\Features\Subscription;
use Vrts\Models\Alert;
use Vrts\Services\Manual_Test_Service;
use Vrts\Services\Test_Service;

if ( ! class_exists( 'WP_List_Table' ) ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/models/class-test-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public static function get_status_data( $test_run ) {
sprintf(
// translators: %1$s: link start to test runs page. %2$s: link end to test runs page.
wp_kses( __( '%1$sRefresh page%2$s to see results', 'visual-regression-tests' ), [ 'a' => [ 'href' => [] ] ] ),
'<a href="' . esc_url( admin_url( 'admin.php?page=vrts-runs' ) ) . '">',
'<a href="' . esc_url( Url_Helpers::get_page_url( 'runs' ) ) . '">',
'</a>'
)
);
Expand All @@ -472,7 +472,7 @@ public static function get_status_data( $test_run ) {
$text = esc_html__( 'Pending', 'visual-regression-tests' );
$instructions .= sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( admin_url( 'admin.php?page=vrts-settings' ) ),
esc_url( Url_Helpers::get_page_url( 'settings' ) ),
esc_html__( 'Edit Test Configuration', 'visual-regression-tests' )
);
break;
Expand Down
2 changes: 1 addition & 1 deletion includes/models/class-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ public static function get_status_data( $test ) {
case 'no-credit-left':
$class = 'paused';
$text = esc_html__( 'Disabled', 'visual-regression-tests' );
$base_link = admin_url( 'admin.php?page=vrts-upgrade' );
$base_link = Url_Helpers::get_page_url( 'upgrade' );
$instructions = sprintf(
/* translators: %1$s and %2$s: link wrapper. */
esc_html__( '%1$sUpgrade plugin%2$s to resume testing', 'visual-regression-tests' ),
Expand Down

0 comments on commit 176f43b

Please sign in to comment.