From 26b2bdcf17ef2c08aa6a1f055f0b2dc051d25756 Mon Sep 17 00:00:00 2001 From: Asad Nur Date: Wed, 4 Oct 2023 15:28:04 +0600 Subject: [PATCH] fix: Product edit link on email template redirects to the products lising instead of single product edit page --- includes/Dashboard/Templates/Products.php | 23 +++++++++++++++++++++++ includes/Emails/ProductPublished.php | 5 ++++- includes/functions.php | 13 +++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/includes/Dashboard/Templates/Products.php b/includes/Dashboard/Templates/Products.php index 3a4a42bed2..9fcf16b64c 100644 --- a/includes/Dashboard/Templates/Products.php +++ b/includes/Dashboard/Templates/Products.php @@ -32,6 +32,7 @@ public function __construct() { 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 ); @@ -215,6 +216,28 @@ public function load_product_edit_template() { } } + /** + * 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'] ) || + 'edit' !== sanitize_text_field( wp_unslash( $_GET['action'] ) ) || + 'product_email' !== sanitize_text_field( wp_unslash( $_GET['_view_mode'] ) ) ) { + 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 * diff --git a/includes/Emails/ProductPublished.php b/includes/Emails/ProductPublished.php index 3c28999e49..f9541c78ce 100644 --- a/includes/Emails/ProductPublished.php +++ b/includes/Emails/ProductPublished.php @@ -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}'; @@ -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(); diff --git a/includes/functions.php b/includes/functions.php index 703e92c016..acdc6d9be1 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1181,6 +1181,19 @@ function dokan_get_store_url( $user_id ) { 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 if current page is store review page *