Skip to content

Commit

Permalink
Merge pull request #153 from godaddy/feat/open-new-tab
Browse files Browse the repository at this point in the history
feat: add 'open in new tab' option
  • Loading branch information
cbicuti-godaddy authored Aug 3, 2023
2 parents 6651f3f + 22b1992 commit 7fe935f
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .dev/src/blocks/domain-search/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const attributes = {
type: 'boolean',
default: false,
},
new_tab: {
type: 'boolean',
default: false,
},
page_size: {
type: 'number',
default: 5,
Expand Down
9 changes: 9 additions & 0 deletions .dev/src/blocks/domain-search/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ const Inspector = ( { attributes, setAttributes } ) => {
label={ __( 'Display results in a modal', 'reseller-store' ) }
checked={ attributes.modal }
onChange={ ( modal ) => setAttributes( { modal } ) }
/>
</Fragment>
) }
{ 'advanced' !== attributes.search_type && (
<Fragment>
<CheckboxControl
label={ __( 'Display results in a new tab', 'reseller-store' ) }
checked={ attributes.new_tab }
onChange={ ( new_tab ) => setAttributes( { new_tab } ) }
/>
</Fragment>
) }
Expand Down
4 changes: 4 additions & 0 deletions .dev/src/blocks/product/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const attributes = {
type: 'string',
default: __( 'Add to cart', 'reseller-store' ),
},
button_new_tab: {
type: 'boolean',
default: false,
},
content_height: {
type: 'number',
default: 250,
Expand Down
7 changes: 7 additions & 0 deletions .dev/src/blocks/product/components/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ const Inspector = ( { posts, media, attributes, setAttributes } ) => {
value={ attributes.button_label }
onChange={ ( buttonLabel ) => setAttributes( { button_label: buttonLabel } ) }
/>
<CheckboxControl
label={ __( 'Display results in a new tab', 'reseller-store' ) }
checked={ attributes.button_new_tab }
onChange={ ( checked ) => {
setAttributes( { button_new_tab: checked } );
} }
/>
</PanelBody>
<PanelBody>
<CheckboxControl
Expand Down
2 changes: 1 addition & 1 deletion assets/js/editor.blocks.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Plugin {
*
* @var string
*/
const VERSION = '2.2.13';
const VERSION = '2.2.14';

/**
* Plugin prefix.
Expand Down
10 changes: 6 additions & 4 deletions includes/functions/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function rstore_price( $post = null, $echo = false ) {
*
* @return string|null
*/
function rstore_add_to_cart_form( $post, $echo = false, $button_label = null, $text_cart = null, $redirect = true ) {
function rstore_add_to_cart_form( $post, $echo = false, $button_label = null, $button_new_tab = null, $text_cart = null, $redirect = true ) {

$post = get_post( $post );

Expand Down Expand Up @@ -132,10 +132,12 @@ function rstore_add_to_cart_form( $post, $echo = false, $button_label = null, $t
$items = json_encode( array( $data ) );

$cart_form = sprintf(
'<form class="rstore-add-to-cart-form" method="POST" action="%s" ><input type="hidden" name="items" value=\'%s\' /><button class="rstore-add-to-cart button btn btn-primary" type="submit">%s</button><div class="rstore-loading rstore-loading-hidden"></div></form>',
'<form class="rstore-add-to-cart-form" method="POST" action="%s"%s><input type="hidden" name="items" value=\'%s\' /><button class="rstore-add-to-cart button btn btn-primary" type="submit">%s</button>%s</form>',
$cart_url,
$button_new_tab ? ' target="_blank"' : '',
$items,
esc_html( $button_label )
esc_html( $button_label ),
$button_new_tab ? '' : '<div class="rstore-loading rstore-loading-hidden"></div>'
);

} else {
Expand Down Expand Up @@ -209,7 +211,7 @@ function rstore_append_add_to_cart_form( $content ) {
$content .= rstore_price( $post->ID );

$redirect = ! ( (bool) rstore_get_product_meta( $post->ID, 'skip_cart_redirect' ) );
$content .= rstore_add_to_cart_form( $post->ID, false, null, null, $redirect );
$content .= rstore_add_to_cart_form( $post->ID, false, null, null, null, $redirect );

}

Expand Down
9 changes: 9 additions & 0 deletions includes/modules/rstore-fl-domain-simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public function __construct() {
'label' => __( 'Button', 'reseller-store' ),
'default' => __( 'Search', 'reseller-store' ),
),
'new_tab' => array(
'type' => 'select',
'label' => __( 'Display results in a new tab', 'reseller-store' ),
'default' => '0',
'options' => array(
'1' => __( 'Yes', 'reseller-store' ),
'0' => __( 'No', 'reseller-store' ),
),
),
),
),
),
Expand Down
9 changes: 9 additions & 0 deletions includes/modules/rstore-fl-domain-transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public function __construct() {
'label' => __( 'Button', 'reseller-store' ),
'default' => __( 'Transfer', 'reseller-store' ),
),
'new_tab' => array(
'type' => 'select',
'label' => __( 'Display results in a new tab', 'reseller-store' ),
'default' => '0',
'options' => array(
'1' => __( 'Yes', 'reseller-store' ),
'0' => __( 'No', 'reseller-store' ),
),
),
),
),
),
Expand Down
9 changes: 9 additions & 0 deletions includes/modules/rstore-fl-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public function __construct() {
'description' => __( 'Leave blank to hide button', 'reseller-store' ),
'default' => __( 'Add to cart', 'reseller-store' ),
),
'button_new_tab' => array(
'type' => 'select',
'label' => __( 'Open Results In A New Tab', 'reseller-store' ),
'default' => '0',
'options' => array(
'1' => __( 'Yes', 'reseller-store' ),
'0' => __( 'No', 'reseller-store' ),
),
),
'show_title' => array(
'type' => 'select',
'label' => __( 'Title', 'reseller-store' ),
Expand Down
12 changes: 12 additions & 0 deletions includes/modules/rstore-vc-domain-simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public function vc_mapping() {
'weight' => 0,
),

array(
'type' => 'checkbox',
'holder' => 'div',
'class' => 'text-class',
'heading' => __( 'Display results in a new tab', 'reseller-store' ),
'param_name' => 'new_tab',
'value' => array(
__( 'Show', 'reseller-store' ) => 1,
),
'group' => 'Results',
),

),
)
);
Expand Down
12 changes: 12 additions & 0 deletions includes/modules/rstore-vc-domain-transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ public function vc_mapping() {
'group' => 'Custom Group',
),

array(
'type' => 'checkbox',
'holder' => 'div',
'class' => 'text-class',
'heading' => __( 'Display results in a new tab', 'reseller-store' ),
'param_name' => 'new_tab',
'value' => array(
__( 'Show', 'reseller-store' ) => 1,
),
'group' => 'Results',
),

),
)
);
Expand Down
12 changes: 12 additions & 0 deletions includes/modules/rstore-vc-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ public function vc_mapping() {
'group' => __( 'Display', 'reseller-store' ),
),

array(
'type' => 'checkbox',
'holder' => 'div',
'class' => 'text-class',
'heading' => __( 'Open Results In A New Tab', 'reseller-store' ),
'param_name' => 'new_tab',
'value' => array(
__( 'No', 'reseller-store' ) => 0,
),
'group' => __( 'Display', 'reseller-store' ),
),

array(
'type' => 'checkbox',
'holder' => 'div',
Expand Down
8 changes: 7 additions & 1 deletion includes/widgets/class-domain-simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ public function widget( $args, $instance ) {

}

$target = '';
if ( ! empty($data['new_tab'])) {
$target = ' target="_blank"';
}

?>
<form role="search" method="get" class="search-form" action="<?php echo esc_url_raw( rstore()->api->url( 'www', 'products/domain-registration/find' ), 'https' ); ?>">
<form role="search" method="get" class="search-form" action="<?php echo esc_url_raw( rstore()->api->url( 'www', 'products/domain-registration/find' ), 'https' ); ?>"<?php echo $target; ?>>
<label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr( $data['text_placeholder'] ); ?>" name="domainToCheck" required>
</label>
Expand Down Expand Up @@ -172,6 +177,7 @@ private function get_data( $instance ) {
'title' => isset( $instance['title'] ) ? $instance['title'] : apply_filters( 'rstore_domain_title', '' ),
'text_placeholder' => isset( $instance['text_placeholder'] ) ? $instance['text_placeholder'] : apply_filters( 'rstore_domain_text_placeholder', esc_html__( 'Find your perfect domain name', 'reseller-store' ) ),
'text_search' => isset( $instance['text_search'] ) ? $instance['text_search'] : apply_filters( 'rstore_domain_text_search', esc_html__( 'Search', 'reseller-store' ) ),
'new_tab' => isset( $instance['new_tab'] ) ? $instance['new_tab'] : false,
);
}

Expand Down
9 changes: 8 additions & 1 deletion includes/widgets/class-domain-transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ public function widget( $args, $instance ) {

}

$target = '';
if ( ! empty($data['new_tab'])) {
$target = ' target="_blank"';
}

?>
<form role="search" method="get" class="search-form" action="<?php echo esc_url_raw( rstore()->api->url( 'www', 'products/domain-transfer' ), 'https' ); ?>">
<form role="search" method="get" class="search-form" action="<?php echo esc_url_raw( rstore()->api->url( 'www', 'products/domain-transfer' ), 'https' ); ?>"<?php echo $target ?>>
<label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr( $data['text_placeholder'] ); ?>" name="domainToCheck" required>
</label>
Expand Down Expand Up @@ -153,6 +158,7 @@ public function update( $new_instance, $old_instance ) {
$instance['title'] = isset( $new_instance['title'] ) ? sanitize_text_field( $new_instance['title'] ) : null;
$instance['text_placeholder'] = isset( $new_instance['text_placeholder'] ) ? wp_kses_post( $new_instance['text_placeholder'] ) : null;
$instance['text_search'] = isset( $new_instance['text_search'] ) ? wp_kses_post( $new_instance['text_search'] ) : null;
$instance['new_tab'] = isset( $new_instance['new_tab'] ) ? (bool) $new_instance['new_tab'] : false;

return $instance;

Expand All @@ -172,6 +178,7 @@ private function get_data( $instance ) {
'title' => isset( $instance['title'] ) ? $instance['title'] : apply_filters( 'rstore_domain_transfer_title', '' ),
'text_placeholder' => isset( $instance['text_placeholder'] ) ? $instance['text_placeholder'] : apply_filters( 'rstore_domain_transfer_text_placeholder', esc_html__( 'Enter domain to transfer', 'reseller-store' ) ),
'text_search' => isset( $instance['text_search'] ) ? $instance['text_search'] : apply_filters( 'rstore_domain_transfer_text_search', esc_html__( 'Transfer', 'reseller-store' ) ),
'new_tab' => isset( $instance['new_tab'] ) ? $instance['new_tab'] : false,
);
}

Expand Down
6 changes: 4 additions & 2 deletions includes/widgets/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function widget( $args, $instance ) {

if ( ! empty( $data['button_label'] ) ) {

$content .= rstore_add_to_cart_form( $post_id, false, $data['button_label'], $data['text_cart'], $data['redirect'] ); // xss ok.
$content .= rstore_add_to_cart_form( $post_id, false, $data['button_label'], $data['button_new_tab'], $data['text_cart'], $data['redirect'] ); // xss ok.

}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function widget( $args, $instance ) {

if ( ! empty( $data['button_label'] ) ) {

$content .= rstore_add_to_cart_form( $post_id, false, $data['button_label'], $data['text_cart'], $data['redirect'] );
$content .= rstore_add_to_cart_form( $post_id, false, $data['button_label'], $data['button_new_tab'], $data['text_cart'], $data['redirect'] );

}
}
Expand Down Expand Up @@ -273,6 +273,7 @@ public function update( $new_instance, $old_instance ) {
$instance['redirect'] = isset( $new_instance['redirect'] ) ? (bool) absint( $new_instance['redirect'] ) : false;
$instance['image_size'] = isset( $new_instance['image_size'] ) ? sanitize_text_field( $new_instance['image_size'] ) : null;
$instance['button_label'] = isset( $new_instance['button_label'] ) ? sanitize_text_field( $new_instance['button_label'] ) : '';
$instance['button_new_tab'] = isset( $new_instance['button_new_tab'] ) ? sanitize_text_field( $new_instance['button_new_tab'] ) : '';
$instance['text_cart'] = isset( $new_instance['text_cart'] ) ? sanitize_text_field( $new_instance['text_cart'] ) : '';
$instance['text_more'] = isset( $new_instance['text_more'] ) ? sanitize_text_field( $new_instance['text_more'] ) : '';
$instance['content_height'] = isset( $new_instance['content_height'] ) ? absint( $new_instance['content_height'] ) : null;
Expand Down Expand Up @@ -346,6 +347,7 @@ private function get_data( $instance ) {
'show_price' => isset( $instance['show_price'] ) ? ! empty( $instance['show_price'] ) : apply_filters( 'rstore_product_show_price', true ),
'redirect' => isset( $instance['redirect'] ) ? ! empty( $instance['redirect'] ) : apply_filters( 'rstore_product_redirect', true ),
'button_label' => isset( $instance['button_label'] ) ? $instance['button_label'] : apply_filters( 'rstore_product_button_label', esc_html__( 'Add to cart', 'reseller-store' ) ),
'button_new_tab' => isset( $instance['button_new_tab'] ) ? $instance['button_new_tab'] : false,
'text_cart' => isset( $instance['text_cart'] ) ? $instance['text_cart'] : apply_filters( 'rstore_product_text_cart', esc_html__( 'Continue to cart', 'reseller-store' ) ),
'text_more' => isset( $instance['text_more'] ) ? $instance['text_more'] : apply_filters( 'rstore_product_text_more', esc_html__( 'More info', 'reseller-store' ) ),
'content_height' => isset( $instance['content_height'] ) ? intval( $instance['content_height'] ) : apply_filters( 'rstore_product_content_height', 250 ),
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
**Requires at least:** 4.6
**Tested up to:** 6.2.2
**Requires PHP:** 5.4
**Stable tag:** 2.2.13
**Stable tag:** 2.2.14
**License:** GPL-2.0
**License URI:** https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -102,6 +102,11 @@ While we recommend you use our widgets for your storefront, we do have a shortco
You can add `?domainToCheck=example.com` to your query string on any page that has the domain search widget and the widget will perform an automatic search on page load.

## Changelog ##

### 2.2.14 - August 2023 ###

* Update: Add option to open cart and search results in new tab

### 2.2.13 - July 2023 ###

* Update: Fix for compatibility with Beaver Builder and Classic Editor Plugins
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: reseller, program, storefront, products, posts, shortcode, ec
Requires at least: 4.6
Tested up to: 6.2.2
Requires PHP: 5.4
Stable tag: 2.2.13
Stable tag: 2.2.14
License: GPL-2.0
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -98,6 +98,11 @@ While we recommend you use our widgets for your storefront, we do have a shortco
You can add `?domainToCheck=example.com` to your query string on any page that has the domain search widget and the widget will perform an automatic search on page load.

== Changelog ==

= 2.2.14 - August 2023 =

* Update: Add option to open cart and search results in new tab

= 2.2.13 - July 2023 =

* Update: Fix for compatibility with Beaver Builder and Classic Editor Plugins
Expand Down
2 changes: 1 addition & 1 deletion reseller-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Reseller Store
* Description: Sell hosting, domains, and more right from your WordPress site.
* Version: 2.2.13
* Version: 2.2.14
* Author: GoDaddy
* Author URI: https://reseller.godaddy.com/
* License: GPL-2.0
Expand Down
16 changes: 14 additions & 2 deletions tests/test-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ public function test_rstore_add_to_cart_form_echo_redirect() {

rstore_add_to_cart_form( $post, true );

$this->expectOutputRegex( '/<form class="rstore-add-to-cart-form" method="POST" action="https:\/\/www.secureserver.net\/api\/v1\/cart\/1592\/\?redirect=1&plid=1592" ><input type="hidden" name="items" value=\'\[{"id":"wordpress-basic","quantity":1}\]\' \/><button class="rstore-add-to-cart button btn btn-primary" type="submit">Add to cart<\/button><div class="rstore-loading rstore-loading-hidden"><\/div><\/form>/' );
$this->expectOutputRegex( '/<form class="rstore-add-to-cart-form" method="POST" action="https:\/\/www.secureserver.net\/api\/v1\/cart\/1592\/\?redirect=1&plid=1592"><input type="hidden" name="items" value=\'\[{"id":"wordpress-basic","quantity":1}\]\' \/><button class="rstore-add-to-cart button btn btn-primary" type="submit">Add to cart<\/button><div class="rstore-loading rstore-loading-hidden"><\/div><\/form>/' );

}

public function test_rstore_add_to_cart_form_open_new_tab() {

rstore_update_option( 'pl_id', 1592 );

$post = Tests\Helper::create_product();

rstore_add_to_cart_form( $post, true, null, true);

$this->expectOutputRegex( '/<form class="rstore-add-to-cart-form" method="POST" action="https:\/\/www.secureserver.net\/api\/v1\/cart\/1592\/\?redirect=1&plid=1592" target="_blank"><input type="hidden" name="items" value=\'\[{"id":"wordpress-basic","quantity":1}\]\' \/><button class="rstore-add-to-cart button btn btn-primary" type="submit">Add to cart<\/button><\/form>/' );

}

Expand All @@ -29,7 +41,7 @@ public function test_rstore_add_to_cart_form_echo_no_redirect() {

$post = Tests\Helper::create_product();

rstore_add_to_cart_form( $post, true, null, null, false );
rstore_add_to_cart_form( $post, true, null, null, null, false );

$this->expectOutputRegex( '/<div class="rstore-add-to-cart-form"><div><button class="rstore-add-to-cart button btn btn-primary" data-id="wordpress-basic" data-quantity="1">Add to cart<\/button><\/div><div class="rstore-loading rstore-loading-hidden"><\/div><div class="rstore-cart rstore-cart-hidden"><span class="dashicons dashicons-yes rstore-success"><\/span><a href="https:\/\/cart.secureserver.net\/go\/checkout\/" rel="nofollow">Continue to cart<\/a><\/div><div class="rstore-message rstore-message-hidden"><\/div><\/div>/' );

Expand Down
1 change: 1 addition & 0 deletions tests/test-widget-domain-transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function test_widget_update() {
'title' => 'title 1',
'text_placeholder' => 'placeholder',
'text_search' => 'text_search',
'new_tab' => false,
);

$instance = $widget->update( $new_instance, $old_instance );
Expand Down
1 change: 1 addition & 0 deletions tests/test-widget-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function test_widget_update() {
'text_more' => 'text_more 1',
'content_height' => 150,
'layout_type' => 'default',
'button_new_tab' => false,
);

$instance = $widget->update( $new_instance, $old_instance );
Expand Down

0 comments on commit 7fe935f

Please sign in to comment.