diff --git a/bluem-idin.php b/bluem-idin.php index 79b22e6..a0b61ba 100644 --- a/bluem-idin.php +++ b/bluem-idin.php @@ -895,7 +895,6 @@ function bluem_idin_form(): string return $html; } -add_action('parse_request', 'bluem_idin_shortcode_idin_execute'); /** * This function is called POST from the form rendered on a page or post * @@ -903,13 +902,6 @@ function bluem_idin_form(): string */ function bluem_idin_shortcode_idin_execute(): void { - $shortcode_execution_url = 'bluem-woocommerce/idin_execute'; - - if (!isset($_SERVER['REQUEST_URI']) || !str_contains(sanitize_url(wp_unslash($_SERVER['REQUEST_URI'])), $shortcode_execution_url)) { - // any other request - return; - } - $goto = false; if (!empty($_GET['redirect_to_checkout']) && sanitize_text_field(wp_unslash($_GET['redirect_to_checkout'])) === 'true' diff --git a/bluem-mandates-shortcode.php b/bluem-mandates-shortcode.php index 5a85c23..8cd7b74 100644 --- a/bluem-mandates-shortcode.php +++ b/bluem-mandates-shortcode.php @@ -6,8 +6,6 @@ use Bluem\BluemPHP\Bluem; -add_action( 'parse_request', 'bluem_mandate_shortcode_execute' ); - /** * This function is called POST from the form rendered on a page or post * @@ -17,10 +15,6 @@ * @throws \Bluem\BluemPHP\Exceptions\InvalidBluemConfigurationException */ function bluem_mandate_shortcode_execute(): void { - if ( substr( sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ), -43 ) !== 'bluem-woocommerce/mandate_shortcode_execute' ) { - return; - } - $nonce = $_REQUEST['_wpnonce']; if ( ! wp_verify_nonce( $nonce, 'bluem-nonce' ) ) { die( 'Did not pass security check' ); diff --git a/bluem.php b/bluem.php index 3ddf63b..d38886b 100644 --- a/bluem.php +++ b/bluem.php @@ -143,10 +143,45 @@ function bluem_is_permalinks_enabled(): bool function bluem_woocommerce_plugin_activate() { update_option('bluem_plugin_registration', false); + + // Rewrite rules: + add_rewrite_rule('^bluem-woocommerce/idin_execute/?$', 'index.php?bluem_idin_shortcode_execute=1', 'top'); + add_rewrite_rule('^bluem-woocommerce/mandate_shortcode_execute/?$', 'index.php?bluem_mandate_shortcode_execute=1', 'top'); + + // Flush the rules after adding them + flush_rewrite_rules(); } register_activation_hook(__FILE__, 'bluem_woocommerce_plugin_activate'); + + +add_filter('query_vars', function ($vars) { + $vars[] = 'bluem_idin_shortcode_execute'; + $vars[] = 'bluem_mandate_shortcode_execute'; + return $vars; +}); +add_action('template_redirect', function () { + if (get_query_var('bluem_idin_shortcode_execute') == 1 && $_SERVER['REQUEST_METHOD'] === 'POST') { + bluem_idin_shortcode_idin_execute(); + return; + } + elseif (get_query_var('bluem_mandate_shortcode_execute') == 1 && $_SERVER['REQUEST_METHOD'] === 'POST') { + bluem_mandate_shortcode_execute(); + return; + } +}); + + +// Plug-in deactivation +function bluem_woocommerce_plugin_deactivate() { + // Flush to remove custom rules added by us + flush_rewrite_rules(); +} + +register_deactivation_hook(__FILE__, 'bluem_woocommerce_plugin_deactivate'); + + // Update CSS within in Admin function bluem_add_admin_style() { @@ -1496,6 +1531,7 @@ function bluem_error_report_email($data = []): bool esc_html__("Sent error report mail to %s", 'bluem'), $to)); } + // or no mail sent return $mailing;