Skip to content

Commit

Permalink
My Account blocks issue on page builders
Browse files Browse the repository at this point in the history
  • Loading branch information
zhea-son committed Sep 10, 2024
1 parent a3c6ea2 commit 27e3a85
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= 3.3.2 - 09/09/2024 =
= 3.3.2 - 10/09/2024 =
* Feature - All User Registration widgets for WPBakery.
* Feature - All User Registration widgets for Elementor.
* Enhance - User Registration Dashboard Page.
Expand Down
11 changes: 5 additions & 6 deletions includes/blocks/block-types/class-ur-block-myaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ protected function build_html( $content ) {
if ( ! empty( $attr['userState'] ) ) {
$parameters['userState'] = $attr['userState'];
}


if ( empty( $parameters ) || ( isset($parameters['userState']) && "logged_in" === $parameters['userState'] )) {
if ( (empty( $parameters ) || ( isset($parameters['userState']) && "logged_in" === $parameters['userState'] ) ) || (!empty($parameters) && !isset($parameters['userState'])) ) {
return UR_Shortcodes::my_account(
$parameters
);
} else if(isset($parameters['userState']) && "logged_out" === $parameters['userState']) {
return UR_Shortcodes::login(
$parameters
);
}

return UR_Shortcodes::login(
$parameters
);
}
}
4 changes: 2 additions & 2 deletions includes/functions-ur-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -6505,7 +6505,7 @@ function create_wpbakery_widget_category() {
array(
'type' => 'textfield',
'heading' => esc_html__( 'Logout URL', 'user-registration' ),
'param_name' => 'logout_url',
'param_name' => 'logout_redirect',
'value' => '',
'description' => esc_html__( 'Enter url which redirect after logout.', 'user-registration' ),
),
Expand All @@ -6530,7 +6530,7 @@ function create_wpbakery_widget_category() {
array(
'type' => 'textfield',
'heading' => esc_html__( 'Logout URL', 'user-registration' ),
'param_name' => 'logout_url',
'param_name' => 'logout_redirect',
'value' => '',
'description' => esc_html__( 'Enter url which redirect after logout.', 'user-registration' ),
),
Expand Down
27 changes: 27 additions & 0 deletions includes/functions-ur-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ function ur_logout_url( $redirect = '' ) {
$wp_version = '5.0';
$post_content = isset( $post->post_content ) ? $post->post_content : '';


if ( ( ur_post_content_has_shortcode( 'user_registration_login' ) || ur_post_content_has_shortcode( 'user_registration_my_account' ) ) && is_user_logged_in() ) {
if ( version_compare( $GLOBALS['wp_version'], $wp_version, '>=' ) ) {
$blocks = parse_blocks( $post_content );
Expand Down Expand Up @@ -1307,6 +1308,32 @@ function ur_logout_url( $redirect = '' ) {
foreach ( $blocks as $block ) {
if ( ( 'user-registration/form-selector' === $block['blockName'] || 'user-registration/myaccount' === $block['blockName'] || 'user-registration/login-form' === $block['blockName'] ) && isset( $block['attrs']['logoutUrl'] ) ) {
$redirect = '' != $block['attrs']['logoutUrl'] ? ur_check_external_url( $block['attrs']['logoutUrl'] ) : ur_get_page_permalink( 'myaccount' );
} else {

$new_shortcode = wp_strip_all_tags( $block['innerHTML'] );
$pattern = '/\[user_registration_my_account(?:\s+redirect_url="[^"]*")?(?:\s+logout_redirect="[^"]*")?\s*\]/';

preg_match($pattern, $new_shortcode, $shortcodes);

if( !empty( $shortcodes[0] ) ) {
preg_match( '/' . get_shortcode_regex() . '/s', $shortcodes[0], $matches );
$matches_attr = isset( $matches[3] ) ? $matches[3] : '';
$attributes = shortcode_parse_atts( $matches_attr );

/**
* Introduced logout_redirect parameter in user_registration_my_account shortcode.
*
* @since 1.7.5
*/
if ( isset( $attributes['logout_redirect'] ) ) {
$redirect = isset( $attributes['logout_redirect'] ) ? $attributes['logout_redirect'] : '';
$redirect = trim( $redirect, ']' );
$redirect = trim( $redirect, '"' );
$redirect = trim( $redirect, "'" );
$redirect = '' != $redirect ? ur_check_external_url( $redirect ) : ur_get_page_permalink( 'myaccount' );
}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro

== Changelog ==

= 3.3.2 - 09/09/2024 =
= 3.3.2 - 10/09/2024 =
* Feature - All User Registration widgets for WPBakery.
* Feature - All User Registration widgets for Elementor.
* Enhance - User Registration Dashboard Page.
Expand Down

0 comments on commit 27e3a85

Please sign in to comment.