Skip to content

Commit

Permalink
feat(Settings): update settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Oct 11, 2024
1 parent c3101f3 commit e5f3a5e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 41 deletions.
2 changes: 1 addition & 1 deletion includes/core/settings/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function get_section_page( $id ) {
* @param array $args Setting args.
*/
private function get_field( $args ) {
$value = $this->get_option( $args['id'] );
$value = $args['value'] ?? $this->get_option( $args['id'] );
include vrts()->get_plugin_path( "includes/core/settings/field-{$args['type']}/index.php" );
}

Expand Down
4 changes: 2 additions & 2 deletions includes/core/settings/field-checkbox/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<?php checked( $value, 1 ); ?>
<?php wp_readonly( isset( $args['readonly'] ) && $args['readonly'] ); ?>
<?php disabled( isset( $args['disabled'] ) && $args['disabled'] ); ?>>
<?php echo esc_html( $args['label'] ); ?>
<?php echo wp_kses_post( $args['label'] ); ?>
</label>
<?php
if ( isset( $args['is_pro'] ) && false === $args['is_pro'] ) :
Expand All @@ -22,6 +22,6 @@
<?php
if ( isset( $args['description'] ) ) :
?>
<p class="description"><?php echo esc_html( $args['description'] ); ?></p>
<p class="description"><?php echo wp_kses_post( $args['description'] ); ?></p>
<?php
endif;
100 changes: 62 additions & 38 deletions includes/features/class-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct() {
add_action( 'add_option_vrts_click_selectors', [ $this, 'do_after_update_click_selectors' ], 10, 2 );
add_action( 'update_option_vrts_click_selectors', [ $this, 'do_after_update_click_selectors' ], 10, 2 );
add_action( 'pre_update_option_vrts_license_key', [ $this, 'do_before_add_license_key' ], 10, 2 );
add_action( 'pre_update_option_vrts_email_update_notification_address', [ $this, 'do_before_updating_email_address' ], 10, 2 );
add_action( 'pre_update_option_vrts_email_api_notification_address', [ $this, 'do_before_updating_email_address' ], 10, 2 );
add_action( 'update_option_vrts_automatic_comparison', [ $this, 'do_after_update_vrts_automatic_comparison' ], 10, 2 );

$this->add_settings();
Expand Down Expand Up @@ -73,6 +75,7 @@ public function add_settings() {
vrts()->settings()->add_setting([
'type' => 'text',
'id' => 'vrts_click_selectors',
'section' => 'vrts-settings-section-general',
'title' => esc_html__( 'Click Element', 'visual-regression-tests' ),
'description' => sprintf(
'%s<br>%s',
Expand All @@ -84,30 +87,29 @@ public function add_settings() {
),
esc_html__( 'Useful to accept cookie banners or anything else that should be clicked after page load.', 'visual-regression-tests' )
),
'section' => 'vrts-settings-section-general',
'placeholder' => esc_html__( 'e.g.: #accept-cookies', 'visual-regression-tests' ),
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'value_type' => 'string',
'default' => '',
'placeholder' => esc_html__( 'e.g.: #accept-cookies', 'visual-regression-tests' ),
]);

vrts()->settings()->add_setting([
'type' => 'text',
'id' => 'vrts_license_key',
'section' => 'vrts-settings-section-general',
'title' => esc_html__( 'License Key', 'visual-regression-tests' ),
'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_html__( 'Upgrade here.', 'visual-regression-tests' )
),
'section' => 'vrts-settings-section-general',
'placeholder' => esc_html_x( 'XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX', 'license key placeholder', 'visual-regression-tests' ),
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'value_type' => 'string',
'default' => '',
'placeholder' => esc_html_x( 'XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX', 'license key placeholder', 'visual-regression-tests' ),
]);

vrts()->settings()->add_section([
Expand All @@ -120,55 +122,68 @@ public function add_settings() {
vrts()->settings()->add_setting([
'type' => 'checkbox',
'id' => 'vrts_automatic_comparison',
'title' => esc_html__( 'Schedule', 'visual-regression-tests' ),
'label' => esc_html__( 'Run daily tests.', 'visual-regression-tests' ),
'section' => 'vrts-settings-section-triggers',
'title' => esc_html__( 'Schedule', 'visual-regression-tests' ),
'label' => esc_html__( 'Run Tests every 24 hours.', 'visual-regression-tests' ),
'sanitize_callback' => [ Sanitization::class, 'sanitize_checkbox' ],
'show_in_rest' => true,
'value_type' => 'boolean',
'disabled' => 1,
'value' => 1,
'default' => 1,
'disabled' => 1,
]);

vrts()->settings()->add_setting([
'type' => 'checkbox',
'id' => 'vrts_updates_comparison',
'title' => esc_html__( 'Update', 'visual-regression-tests' ),
'label' => esc_html__( 'Run tests after WordPress and plugin updates.', 'visual-regression-tests' ),
'section' => 'vrts-settings-section-triggers',
'title' => esc_html__( 'Update', 'visual-regression-tests' ),
'label' => esc_html__( 'Run Tests after WordPress and plugin updates.', 'visual-regression-tests' ),
'sanitize_callback' => [ Sanitization::class, 'sanitize_checkbox' ],
'is_pro' => $has_subscription,
'show_in_rest' => true,
'value_type' => 'boolean',
'default' => 0,
'value' => $has_subscription,
'default' => $has_subscription,
'disabled' => $has_subscription,
'readonly' => ! $has_subscription,
'is_pro' => $has_subscription,
]);

vrts()->settings()->add_setting([
'type' => 'info',
'id' => 'vrts-settings-api-info',
'type' => 'checkbox',
'id' => 'vrts_api_comparison',
'section' => 'vrts-settings-section-triggers',
'title' => esc_html__( 'API', 'visual-regression-tests' ),
'description' => sprintf(
'<a href="%s" target="_blank">%s</a>',
esc_url( 'https://vrts.app/' ),
esc_html__( 'Read the docs.', 'visual-regression-tests' ),
'label' => sprintf(
/* translators: %1$s, %2$s: link wrapper. */
wp_kses_post( __( 'Run Tests with your favorite apps. %1$sRead the docs%2$s.', 'visual-regression-tests' ) ),
'<a href="' . esc_url( 'https://vrts.app/' ) . '" target="_blank">',
'</a>'
),
'section' => 'vrts-settings-section-triggers',
'sanitize_callback' => [ Sanitization::class, 'sanitize_checkbox' ],
'show_in_rest' => true,
'value_type' => 'boolean',
'value' => $has_subscription,
'default' => $has_subscription,
'disabled' => $has_subscription,
'readonly' => ! $has_subscription,
'is_pro' => $has_subscription,
]);

vrts()->settings()->add_setting([
'type' => 'checkbox',
'id' => 'vrts_manual_comparison',
'title' => esc_html__( 'Manual', 'visual-regression-tests' ),
'label' => esc_html__( 'Run tests on demand.', 'visual-regression-tests' ),
'section' => 'vrts-settings-section-triggers',
'title' => esc_html__( 'Manual', 'visual-regression-tests' ),
'label' => esc_html__( 'Run Tests on demand.', 'visual-regression-tests' ),
'sanitize_callback' => [ Sanitization::class, 'sanitize_checkbox' ],
'is_pro' => $has_subscription,
'show_in_rest' => true,
'value_type' => 'boolean',
'value' => $has_subscription,
'default' => $has_subscription,
'disabled' => $has_subscription,
'readonly' => ! $has_subscription,
'default' => $has_subscription
'is_pro' => $has_subscription,
]);

vrts()->settings()->add_section([
Expand All @@ -179,51 +194,51 @@ public function add_settings() {

vrts()->settings()->add_setting([
'type' => 'text',
'id' => 'vrts_schedule_notification_email',
'id' => 'vrts_email_notification_address',
'section' => 'vrts-settings-section-notifications',
'title' => esc_html__( 'Schedule', 'visual-regression-tests' ),
'description' => esc_html__( 'Separate multiple email addresses with commas. Or leave blank to disable notifications.', 'visual-regression-tests' ),
'section' => 'vrts-settings-section-notifications',
'placeholder' => esc_html__( 'Email address(es)', 'visual-regression-tests' ),
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'value_type' => 'string',
'default' => get_bloginfo( 'admin_email' ),
'placeholder' => esc_html__( 'Email address(es)', 'visual-regression-tests' ),
]);

vrts()->settings()->add_setting([
'type' => 'text',
'id' => 'vrts_update_notification_email',
'title' => esc_html__( 'Update', 'visual-regression-tests' ),
'id' => 'vrts_email_update_notification_address',
'section' => 'vrts-settings-section-notifications',
'title' => esc_html__( 'Update', 'visual-regression-tests' ),
'placeholder' => esc_html__( 'Email address(es)', 'visual-regression-tests' ),
'sanitize_callback' => 'sanitize_text_field',
'is_pro' => $has_subscription,
'show_in_rest' => true,
'value_type' => 'string',
'readonly' => ! $has_subscription,
'default' => '',
'placeholder' => esc_html__( 'Email address(es)', 'visual-regression-tests' ),
'readonly' => ! $has_subscription,
'is_pro' => $has_subscription,
]);

vrts()->settings()->add_setting([
'type' => 'text',
'id' => 'vrts_api_notification_email',
'title' => esc_html__( 'API', 'visual-regression-tests' ),
'id' => 'vrts_email_api_notification_address',
'section' => 'vrts-settings-section-notifications',
'title' => esc_html__( 'API', 'visual-regression-tests' ),
'placeholder' => esc_html__( 'Email address(es)', 'visual-regression-tests' ),
'sanitize_callback' => 'sanitize_text_field',
'is_pro' => $has_subscription,
'show_in_rest' => true,
'value_type' => 'string',
'readonly' => ! $has_subscription,
'default' => '',
'placeholder' => esc_html__( 'Email address(es)', 'visual-regression-tests' ),
'readonly' => ! $has_subscription,
'is_pro' => $has_subscription,
]);

vrts()->settings()->add_setting([
'type' => 'info',
'id' => 'vrts_manual_notification_email',
'id' => 'vrts_email_manual_notification_address',
'section' => 'vrts-settings-section-notifications',
'title' => esc_html__( 'Manul', 'visual-regression-tests' ),
'description' => esc_html__( 'Alerts are automatically sent to the user who triggers the manual test.', 'visual-regression-tests' ),
'section' => 'vrts-settings-section-notifications',
'is_pro' => $has_subscription,
]);
}
Expand Down Expand Up @@ -260,7 +275,6 @@ public function do_before_add_license_key( $new, $old ) {
if ( ! $new && $old ) {
self::remove_license_key();
update_option( 'vrts_license_failed', true );

return $new;
}

Expand Down Expand Up @@ -291,6 +305,16 @@ public function do_before_add_license_key( $new, $old ) {
return $old;
}

public function do_before_updating_email_address( $old, $new ) {
$has_subscription = (bool) Subscription::get_subscription_status();

if ( ! $has_subscription ) {
return '';
}

return $old;
}

/**
* Update automatic comparison settings for project in service
*
Expand Down
4 changes: 4 additions & 0 deletions includes/features/class-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public static function decrease_tests_count( $number = 1 ) {
*/
public static function delete_options() {
delete_option( 'vrts_email_notification_address' );
delete_option( 'vrts_email_notification_cc_address' );
delete_option( 'vrts_email_update_notification_address' );
delete_option( 'vrts_email_api_notification_address' );
delete_option( 'vrts_email_manual_notification_address' );
delete_option( 'vrts_click_selectors' );
delete_option( 'vrts_license_key' );
delete_option( 'vrts_automatic_comparison' );
Expand Down

0 comments on commit e5f3a5e

Please sign in to comment.