Skip to content

Commit

Permalink
feat(1.3.23): UYse template redirection for shortcode execution
Browse files Browse the repository at this point in the history
  • Loading branch information
daanrijpkemacb committed Nov 2, 2024
1 parent 82806f7 commit 1c1c23a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
8 changes: 0 additions & 8 deletions bluem-idin.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,21 +895,13 @@ 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
*
* @return void
*/
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'
Expand Down
6 changes: 0 additions & 6 deletions bluem-mandates-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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' );
Expand Down
36 changes: 36 additions & 0 deletions bluem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1c1c23a

Please sign in to comment.