Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎯 fix: Product edit link on email template redirects to the products listing instead of single product edit page #2034

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions includes/Dashboard/Templates/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
add_action( 'template_redirect', [ $this, 'handle_delete_product' ] );
add_action( 'dokan_render_new_product_template', [ $this, 'render_new_product_template' ], 10 );
add_action( 'dokan_render_product_edit_template', [ $this, 'load_product_edit_template' ], 11 );
add_action( 'template_redirect', [ $this, 'render_product_edit_page_for_email' ], 1 );
add_action( 'dokan_after_listing_product', [ $this, 'load_add_new_product_popup' ], 10 );
add_action( 'dokan_after_listing_product', [ $this, 'load_add_new_product_modal' ], 10 );
add_action( 'dokan_product_edit_after_title', [ __CLASS__, 'load_download_virtual_template' ], 10, 2 );
Expand Down Expand Up @@ -203,7 +204,7 @@
* @return void
*/
public function load_product_edit_template() {
if ( current_user_can( 'dokan_edit_product' ) ) {

Check warning on line 207 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_edit_product" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
dokan_get_template_part( 'products/edit-product-single' );
} else {
dokan_get_template_part(
Expand All @@ -215,6 +216,28 @@
}
}

/**
* Render Product Edit Page for Email.
*
* @since DOKAN_SINCE
*
* @return void
*/
public function render_product_edit_page_for_email() {
if (
! isset( $_GET['action'], $_GET['_view_mode'] ) ||

Check warning on line 228 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 228 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
'edit' !== sanitize_text_field( wp_unslash( $_GET['action'] ) ) ||

Check warning on line 229 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
'product_email' !== sanitize_text_field( wp_unslash( $_GET['_view_mode'] ) ) ) {

Check warning on line 230 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
return;
}

$product_edit_url = remove_query_arg( '_view_mode', dokan_get_current_page_url() );
$product_edit_url = add_query_arg( '_dokan_edit_product_nonce', wp_create_nonce( 'dokan_edit_product_nonce' ), $product_edit_url );

wp_safe_redirect( $product_edit_url );
exit();
}

/**
* Render Product Listing Template
*
Expand All @@ -224,7 +247,7 @@
*
* @return void
*/
public function render_product_listing_template( $action ) {

Check warning on line 250 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $action is never used
$bulk_statuses = apply_filters(
'dokan_bulk_product_statuses', [
'-1' => __( 'Bulk Actions', 'dokan-lite' ),
Expand Down Expand Up @@ -274,7 +297,7 @@
if ( absint( $postdata['product_cat'] ) < 0 ) {
$errors[] = __( 'Please select a category', 'dokan-lite' );
}
} else {

Check failure on line 300 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( ! isset( $postdata['product_cat'] ) || empty( $postdata['product_cat'] ) ) {
$errors[] = __( 'Please select at least one category', 'dokan-lite' );
}
Expand Down Expand Up @@ -317,7 +340,7 @@
if ( ! isset( $postdata['chosen_product_cat'] ) ) {
if ( Helper::product_category_selection_is_single() ) {
wp_set_object_terms( $product_id, (int) $postdata['product_cat'], 'product_cat' );
} else {

Check failure on line 343 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( isset( $postdata['product_cat'] ) && ! empty( $postdata['product_cat'] ) ) {
$cat_ids = array_map( 'absint', (array) $postdata['product_cat'] );
wp_set_object_terms( $product_id, $cat_ids, 'product_cat' );
Expand Down Expand Up @@ -381,7 +404,7 @@

do_action( 'dokan_new_product_added', $product_id, $postdata );

if ( current_user_can( 'dokan_edit_product' ) ) {

Check warning on line 407 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_edit_product" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
$redirect = dokan_edit_product_url( $product_id );
} else {
$redirect = dokan_get_navigation_url( 'products' );
Expand Down Expand Up @@ -573,7 +596,7 @@
return;
}

if ( ! current_user_can( 'dokan_delete_product' ) ) {

Check warning on line 599 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_delete_product" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
return;
}

Expand Down Expand Up @@ -608,4 +631,4 @@
exit;
}

}

Check failure on line 634 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The closing brace for the class must go on the next line after the body
5 changes: 4 additions & 1 deletion includes/Emails/ProductPublished.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function trigger( $post, $seller ) {
return;
}

$product_edit_url = remove_query_arg( '_dokan_edit_product_nonce', dokan_edit_product_url( $post->ID ) );
$product_edit_url = add_query_arg( '_view_mode', 'product_email', $product_edit_url );

$this->object = $product;

$this->find['product-title'] = '{product_title}';
Expand All @@ -87,7 +90,7 @@ public function trigger( $post, $seller ) {
$this->replace['price'] = $product->get_price();
$this->replace['seller-name'] = $seller->display_name;
$this->replace['product_url'] = get_permalink( $post->ID );
$this->replace['product_edit_link'] = dokan_edit_product_url( $post->ID );
$this->replace['product_edit_link'] = $product_edit_url;
$this->replace['site_name'] = $this->get_from_name();
$this->replace['site_url'] = site_url();

Expand Down
13 changes: 13 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* @return int
*/
function dokan_get_current_user_id() {
if ( current_user_can( 'vendor_staff' ) ) {

Check warning on line 49 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "vendor_staff" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
$staff_id = get_current_user_id();
$vendor_id = (int) get_user_meta( $staff_id, '_vendor_id', true );

Expand All @@ -68,7 +68,7 @@
* @return bool
*/
function dokan_is_user_seller( $user_id ) {
if ( ! user_can( $user_id, 'dokandar' ) ) {

Check warning on line 71 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokandar" in function call to user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
return false;
}

Expand Down Expand Up @@ -300,7 +300,7 @@
SELECT tr.object_id FROM {$wpdb->prefix}terms AS t
LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt ON t.term_id = tt.term_taxonomy_id
LEFT JOIN {$wpdb->prefix}term_relationships AS tr ON t.term_id = tr.term_taxonomy_id
WHERE tt.taxonomy = 'product_type' AND t.slug NOT IN ({$exclude_product_types_text})

Check failure on line 303 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Use placeholders and $wpdb->prepare(); found interpolated variable {$exclude_product_types_text} at WHERE tt.taxonomy = 'product_type' AND t.slug NOT IN ({$exclude_product_types_text})
)
GROUP BY p.post_status",
$post_type,
Expand Down Expand Up @@ -1100,7 +1100,7 @@
* @return mixed
*/
function dokan_get_option( $option, $section, $default = '' ) {
[ $option, $section ] = dokan_admin_settings_rearrange_map( $option, $section );

Check failure on line 1103 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The shorthand list syntax "[]" to destructure arrays is not available in PHP 7.0 or earlier.

$options = get_option( $section );

Expand Down Expand Up @@ -1181,6 +1181,19 @@
return home_url( '/' . $custom_store_url . '/' . $user_nicename . '/' );
}

/**
* Get current page URL.
*
* @since DOKAN_SINCE
*
* @return string
*/
function dokan_get_current_page_url() {
global $wp;

return add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $wp->request ) );

Check failure on line 1194 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a possibly undefined superglobal array index: $_SERVER['QUERY_STRING']. Use isset() or empty() to check the index exists before using it

Check failure on line 1194 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar

Check failure on line 1194 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_SERVER['QUERY_STRING']
}

/**
* Check if current page is store review page
*
Expand Down Expand Up @@ -2292,7 +2305,7 @@
global $wpdb;

$search_ids = [];
$terms = explode( ',', wc_clean( wp_unslash( $_GET['product_search_name'] ) ) );

Check failure on line 2308 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_GET['product_search_name']

foreach ( $terms as $term ) {
if ( is_numeric( $term ) ) {
Expand Down Expand Up @@ -3939,7 +3952,7 @@
return $email;
}

[ $first, $last ] = explode( '@', $email );

Check failure on line 3955 in includes/functions.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The shorthand list syntax "[]" to destructure arrays is not available in PHP 7.0 or earlier.
$first = str_replace( substr( $first, '1' ), str_repeat( '*', strlen( $first ) - 1 ), $first );
$last = explode( '.', $last );
$last_domain = str_replace( substr( $last['0'], '1' ), str_repeat( '*', strlen( $last['0'] ) - 1 ), $last['0'] );
Expand Down
Loading