Skip to content

Commit

Permalink
Fix - Compatibility with all editors (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhnath005 authored Aug 4, 2023
1 parent 1405c06 commit c85f08f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 161 deletions.
61 changes: 9 additions & 52 deletions includes/frontend/class-ur-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,68 +194,25 @@ public function prevent_core_login_page() {
$login_page = get_post( get_option( 'user_registration_login_options_login_redirect_url', 'unset' ) );
$myaccount_page = get_post( get_option( 'user_registration_myaccount_page_id' ) );
$matched = 0;
$page_id = 0;

if ( ( isset( $_POST['learndash-login-form'] ) || isset( $_POST['learndash-registration-form'] ) ) ) { //phpcs:ignore
return;
}

if ( ! empty( $login_page ) ) {
$shortcodes = parse_blocks( $login_page->post_content );
foreach ( $shortcodes as $shortcode ) {
if ( ! empty( $shortcode['blockName'] ) ) {
if ( 'user-registration/form-selector' === $shortcode['blockName'] && isset( $shortcode['attrs']['shortcode'] ) ) {
$matched = 1;
break;
} elseif ( ( 'core/shortcode' === $shortcode['blockName'] || 'core/paragraph' === $shortcode['blockName'] ) && isset( $shortcode['innerHTML'] ) ) {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
}
if ( 0 < absint( $matched ) ) {
break;
}
}
} else {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $login_page->post_content );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $login_page->post_content );
}
if ( 0 < absint( $matched ) ) {
break;
}
}
$matched = ur_find_my_account_in_page( $login_page->ID );
if ( $matched > 0 ) {
$page_id = $login_page->ID;
}
$page_id = $login_page->ID;
} elseif ( ! empty( $myaccount_page ) ) {
$shortcodes = parse_blocks( $myaccount_page->post_content );
foreach ( $shortcodes as $shortcode ) {
if ( ! empty( $shortcode['blockName'] ) ) {
if ( 'user-registration/form-selector' === $shortcode['blockName'] && isset( $shortcode['attrs']['shortcode'] ) ) {
$matched = 1;
break;
} elseif ( ( 'core/shortcode' === $shortcode['blockName'] || 'core/paragraph' === $shortcode['blockName'] ) && isset( $shortcode['innerHTML'] ) ) {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
}
if ( 0 < absint( $matched ) ) {
break;
}
}
} else {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $myaccount_page->post_content );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $myaccount_page->post_content );
}
if ( 0 < absint( $matched ) ) {
break;
}
}
} elseif ( ! empty( $myaccount_page ) && 0 !== $page_id ) {
$matched = ur_find_my_account_in_page( $myaccount_page->ID );
if ( $matched > 0 ) {
$page_id = $myaccount_page->ID;
}
$page_id = $myaccount_page->ID;
}

if ( ! ( defined( 'UR_DISABLE_PREVENT_CORE_LOGIN' ) && true === UR_DISABLE_PREVENT_CORE_LOGIN ) && ur_option_checked( 'user_registration_login_options_prevent_core_login', false ) && 1 <= absint( $matched ) ) {
if ( ! ( defined( 'UR_DISABLE_PREVENT_CORE_LOGIN' ) && true === UR_DISABLE_PREVENT_CORE_LOGIN ) && ur_option_checked( 'user_registration_login_options_prevent_core_login', false ) && 0 < absint( $matched ) ) {

// Redirect to core login reset password page on multisite.
if ( is_multisite() && ( 'lostpassword' === $action || 'resetpass' === $action ) ) {
Expand Down
122 changes: 13 additions & 109 deletions includes/functions-ur-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2803,8 +2803,7 @@ function user_registration_install_pages_notice() {
}

if ( ! empty( $myaccount_page ) ) {
$shortcodes = parse_blocks( $myaccount_page->post_content );
$matched = ur_find_my_account_in_page( $shortcodes, $myaccount_page, $matched );
$matched = ur_find_my_account_in_page( $myaccount_page->ID );
}

if ( 0 === $matched ) {
Expand All @@ -2827,118 +2826,23 @@ function user_registration_install_pages_notice() {
/**
* Find My Account Shortcode.
*
* @param array $shortcodes Shortcode.
* @param mixed $myaccount_page My Account Page.
* @param int $matched Default 0.
* @param int $login_page_id Login Page ID.
* @return int If matched then 1 else 0.
* @since 2.2.7
*/
function ur_find_my_account_in_page( $shortcodes, $myaccount_page, $matched ) {

foreach ( $shortcodes as $shortcode ) {
if ( ! empty( $shortcode['blockName'] ) ) {
if ( 'user-registration/form-selector' === $shortcode['blockName'] && isset( $shortcode['attrs']['shortcode'] ) ) {
$matched = 1;
return $matched;
} elseif ( ( 'core/shortcode' === $shortcode['blockName'] || 'core/paragraph' === $shortcode['blockName'] ) && isset( $shortcode['innerHTML'] ) ) {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
}
if ( 0 < absint( $matched ) ) {
return $matched;
}
} elseif ( 'core/group' === $shortcode['blockName'] ) {
if ( isset( $shortcode['innerBlocks'] ) && ! empty( $shortcode['innerBlocks'] ) ) {
foreach ( $shortcode['innerBlocks'] as $inner_block ) {
if ( 'user-registration/form-selector' === $inner_block['blockName'] && isset( $inner_block['attrs']['shortcode'] ) ) {
$matched = 1;
return $matched;
} elseif ( ( 'core/shortcode' === $inner_block['blockName'] || 'core/paragraph' === $inner_block['blockName'] ) && isset( $inner_block['innerHTML'] ) ) {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $inner_block['innerHTML'] );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
}
if ( 0 < absint( $matched ) ) {
return $matched;
}
} elseif ( 'core/group' === $inner_block['blockName'] || 'core/column' === $inner_block['blockName'] || 'core/columns' === $inner_block['blockName'] ) {

$matched = ur_find_my_account_in_page( $shortcode['innerBlocks'], $myaccount_page, $matched );
if ( 0 < absint( $matched ) ) {
return $matched;
}
} elseif ( 'core/block' === $inner_block['blockName'] ) {
if ( isset( $inner_block['attrs']['ref'] ) && ! empty( $inner_block['attrs']['ref'] ) ) {
$resuable_block_page = get_post( $inner_block['attrs']['ref'] );
if ( ! empty( $resuable_block_page ) ) {
$resuable_block = parse_blocks( $resuable_block_page->post_content );
$matched = ur_find_my_account_in_page( $resuable_block, $resuable_block_page, $matched );
if ( 0 < absint( $matched ) ) {
return $matched;
}
}
}
}
}
}
} elseif ( 'core/columns' === $shortcode['blockName'] ) {
if ( isset( $shortcode['innerBlocks'] ) && ! empty( $shortcode['innerBlocks'] ) ) {
foreach ( $shortcode['innerBlocks'] as $inner_block ) {
if ( 'user-registration/form-selector' === $inner_block['blockName'] && isset( $inner_block['attrs']['shortcode'] ) ) {
$matched = 1;
return $matched;
} elseif ( ( 'core/shortcode' === $inner_block['blockName'] || 'core/paragraph' === $inner_block['blockName'] ) && isset( $inner_block['innerHTML'] ) ) {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $inner_block['innerHTML'] );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $shortcode['innerHTML'] );
}
if ( 0 < absint( $matched ) ) {
return $matched;
}
} elseif ( 'core/group' === $inner_block['blockName'] || 'core/column' === $inner_block['blockName'] || 'core/columns' === $inner_block['blockName'] ) {
function ur_find_my_account_in_page( $login_page_id ) {
global $wpdb;
$post_table = $wpdb->prefix . 'posts';
$post_meta_table = $wpdb->prefix . 'postmeta';

$matched = ur_find_my_account_in_page( $inner_block['innerBlocks'], $myaccount_page, $matched );
$matched = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM {$post_table} WHERE ID = '{$login_page_id}' AND ( post_content LIKE '%[user_registration_login%' OR post_content LIKE '%[user_registration_my_account%' OR post_content LIKE '%[woocommerce_my_account%' )" )
);

if ( 0 < absint( $matched ) ) {
return $matched;
}
} elseif ( 'core/block' === $inner_block['blockName'] ) {
if ( isset( $inner_block['attrs']['ref'] ) && ! empty( $inner_block['attrs']['ref'] ) ) {
$resuable_block_page = get_post( $inner_block['attrs']['ref'] );
if ( ! empty( $resuable_block_page ) ) {
$resuable_block = parse_blocks( $resuable_block_page->post_content );
$matched = ur_find_my_account_in_page( $resuable_block, $resuable_block_page, $matched );
if ( 0 < absint( $matched ) ) {
return $matched;
}
}
}
}
}
}
} elseif ( 'core/block' === $shortcode['blockName'] ) {

if ( isset( $shortcode['attrs']['ref'] ) && ! empty( $shortcode['attrs']['ref'] ) ) {
$resuable_block_page = get_post( $shortcode['attrs']['ref'] );
if ( ! empty( $resuable_block_page ) ) {
$resuable_block = parse_blocks( $resuable_block_page->post_content );
$matched = ur_find_my_account_in_page( $resuable_block, $resuable_block_page, $matched );
if ( 0 < absint( $matched ) ) {
return $matched;
}
}
}
}
} else {
$matched = preg_match( '/\[user_registration_my_account(\s\S+){0,3}\]|\[user_registration_login(\s\S+){0,3}\]/', $myaccount_page->post_content );
if ( 1 > absint( $matched ) ) {
$matched = preg_match( '/\[woocommerce_my_account(\s\S+){0,3}\]/', $myaccount_page->post_content );
}
if ( 0 < absint( $matched ) ) {
return $matched;
}
}
if ( $matched <= 0 ){
$matched = $wpdb->get_var(
$wpdb->prepare("SELECT COUNT(*) FROM {$post_meta_table} WHERE post_id = '{$login_page_id}' AND ( meta_value LIKE '%[user_registration_login%' OR meta_value LIKE '%[user_registration_my_account%' OR meta_value LIKE '%[woocommerce_my_account%' )" )
);
}
return $matched;
}
Expand Down

0 comments on commit c85f08f

Please sign in to comment.