Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/user-registration/includes/Functions/CoreFunctions.php
+++ b/user-registration/includes/Functions/CoreFunctions.php
@@ -708,6 +708,66 @@
}
}
+if ( ! function_exists( 'urm_get_tax_details' ) ) {
+ /**
+ * Resolve the tax rate and method for a country field value from the saved tax settings.
+ *
+ * @since 5.3.2
+ *
+ * @param string $country_value Country code, or the JSON the country field stores ({"country":"US","state":"CA"}).
+ * @return array Empty when no tax is charged (no rate, or tax at checkout is off), else tax_rate and tax_calculation_method.
+ */
+ function urm_get_tax_details( $country_value ) {
+ // With "add tax at checkout" off no tax is charged, so the order total must not add any either.
+ if ( ! ur_check_module_activation( 'taxes' ) || empty( $country_value ) || ! ur_string_to_bool( get_option( 'user_registration_tax_calculation_during_checkout', 'no' ) ) ) {
+ return array();
+ }
+
+ $location = json_decode( (string) $country_value, true );
+ $location = is_array( $location ) ? $location : array( 'country' => $country_value );
+ $country = isset( $location['country'] ) ? sanitize_text_field( $location['country'] ) : '';
+ $state = isset( $location['state'] ) ? sanitize_text_field( $location['state'] ) : '';
+ $settings = get_option( 'user_registration_tax_regions_and_rates', array() );
+
+ if ( empty( $settings['regions'][ $country ] ) ) {
+ return array();
+ }
+
+ $region = $settings['regions'][ $country ];
+ $rate = isset( $region['states'][ $state ] ) && '' !== $state ? $region['states'][ $state ] : ( isset( $region['rate'] ) ? $region['rate'] : 0 );
+ $rate = (float) $rate;
+
+ if ( $rate <= 0 || $rate > 100 ) {
+ return array();
+ }
+
+ return array(
+ 'tax_rate' => $rate,
+ 'tax_calculation_method' => 'true',
+ );
+ }
+}
+
+if ( ! function_exists( 'urm_get_user_tax_details' ) ) {
+ /**
+ * Resolve the tax details for a member from the country they saved on their account.
+ *
+ * @since 5.3.2
+ *
+ * @param int $user_id User ID.
+ * @return array See urm_get_tax_details().
+ */
+ function urm_get_user_tax_details( $user_id ) {
+ foreach ( (array) get_user_meta( absint( $user_id ) ) as $key => $values ) {
+ if ( 0 === strpos( $key, 'user_registration_country_' ) && ! empty( $values[0] ) ) {
+ return urm_get_tax_details( $values[0] );
+ }
+ }
+
+ return array();
+ }
+}
+
if ( ! function_exists( 'urm_get_thank_you_page' ) ) {
/**
* Get Thank Yu page url
--- a/user-registration/includes/admin/class-ur-admin-profile.php
+++ b/user-registration/includes/admin/class-ur-admin-profile.php
@@ -75,17 +75,6 @@
// if ( isset( $value['field_key'] ) && 'membership' === $value['field_key'] && isset( $_GET['user_id'] ) ) {
// unset( $form_fields[ $key ] );
// }
-
- if ( array_key_exists( $key, $all_meta_for_user ) ) {
- if ( isset( $value['field_key'], $value['choices'] ) && 'checkbox' === $value['field_key'] && empty( $value['choices'] ) ) {
- $unserialized_checkbox_value = maybe_unserialize( $all_meta_for_user[ $key ] );
- if ( is_array( $unserialized_checkbox_value ) ) {
- $form_fields[ $key ]['choices'] = $unserialized_checkbox_value;
- } else {
- $form_fields[ $key ]['choices'] = array( $unserialized_checkbox_value );
- }
- }
- }
}
unset( $form_fields['user_registration_profile_pic_url'] );
@@ -361,7 +350,7 @@
}
?>
><?php if ( trim( $choice ) !== '1' ) : ?>
- <?php echo wp_kses_post( trim( $choice ) ); ?>
+ <?php echo esc_html( trim( $choice ) ); ?>
<?php endif; ?></label><br/>
<?php
}
@@ -535,7 +524,11 @@
}
update_user_meta( absint( $user_id ), sanitize_text_field( $key ), $value );
} else {
- update_user_meta( absint( $user_id ), sanitize_text_field( $key ), '' );
+ // A checkbox with no options is one box on this screen, so a stored list of values must survive a save that leaves it out.
+ $stored_value = 'checkbox' === $field['type'] && empty( $field['choices'] ) && empty( $field['image_options'] ) ? maybe_unserialize( get_user_meta( absint( $user_id ), sanitize_text_field( $key ), true ) ) : '';
+ if ( ! is_array( $stored_value ) ) {
+ update_user_meta( absint( $user_id ), sanitize_text_field( $key ), '' );
+ }
}
} elseif ( isset( $_POST[ $key ] ) ) { //phpcs:ignore
update_user_meta( absint( $user_id ), sanitize_text_field( $key ), sanitize_text_field( $_POST[ $key ] ) ); //phpcs:ignore
--- a/user-registration/includes/admin/settings/class-ur-members-list-table.php
+++ b/user-registration/includes/admin/settings/class-ur-members-list-table.php
@@ -701,13 +701,13 @@
$row .= "<td $attributes>";
switch ( $column_name ) {
case 'username':
- $row .= "$avatar <a href='" . $edit_link . "'>$new_user_object->user_login</a>";
+ $row .= "$avatar <a href='" . $edit_link . "'>" . esc_html( $new_user_object->user_login ) . '</a>';
if ( ! empty( $actions ) ) {
$row .= $this->row_actions( $actions );
}
break;
case 'email':
- $row .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>";
+ $row .= "<a href='" . esc_url( "mailto:$email" ) . "'>" . esc_html( $email ) . '</a>';
break;
case 'role':
$row .= esc_html( $roles_list );
@@ -1459,7 +1459,7 @@
$meta_value = get_user_meta( $user_id, $column_name, true );
}
- $output .= is_array( $meta_value ) ? implode( ', ', $meta_value ) : $meta_value;
+ $output .= esc_html( is_array( $meta_value ) ? implode( ', ', $meta_value ) : $meta_value );
return $output;
}
--- a/user-registration/includes/admin/settings/class-ur-settings-advanced.php
+++ b/user-registration/includes/admin/settings/class-ur-settings-advanced.php
@@ -132,6 +132,14 @@
'css' => '',
'default' => 'no',
),
+ array(
+ 'title' => __( 'Enable AI Abilities', 'user-registration' ),
+ 'desc' => __( 'Let AI assistants read your site's membership data. <a href="https://docs.wpuserregistration.com/global-settings/ai-abilities/" rel="noreferrer noopener" target="_blank">Learn more</a>', 'user-registration' ),
+ 'id' => 'user_registration_enable_abilities',
+ 'type' => 'toggle',
+ 'css' => '',
+ 'default' => 'no',
+ ),
),
),
),
--- a/user-registration/includes/admin/settings/class-ur-users-list-table.php
+++ b/user-registration/includes/admin/settings/class-ur-users-list-table.php
@@ -537,7 +537,7 @@
}
break;
case 'email':
- $row .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>";
+ $row .= "<a href='" . esc_url( "mailto:$email" ) . "'>" . esc_html( $email ) . '</a>';
break;
case 'role':
$row .= esc_html( $roles_list );
@@ -997,7 +997,7 @@
$meta_value = get_user_meta( $user_id, $column_name, true );
}
- $output .= is_array( $meta_value ) ? implode( ', ', $meta_value ) : $meta_value;
+ $output .= esc_html( is_array( $meta_value ) ? implode( ', ', $meta_value ) : $meta_value );
return $output;
}
--- a/user-registration/includes/admin/views/html-login-page-forms.php
+++ b/user-registration/includes/admin/views/html-login-page-forms.php
@@ -46,7 +46,7 @@
</svg>
</button>
- <a id="ur-view-live-button" class="button button-secondary button-large" title="<?php echo esc_attr( sprintf( __( 'View Live in %s page', 'user-registration' ), $login_page_title ) ); ?>" href="<?php echo esc_url( add_query_arg( 'ur_login_preview', 'true', $login_page_url ) ); ?>" target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'View Live', 'user-registration' ); ?></a>
+ <a id="ur-view-live-button" class="button button-secondary button-large" title="<?php echo esc_attr( sprintf( __( 'View Live in %s page', 'user-registration' ), $login_page_title ) ); ?>" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'ur_login_preview', 'true', $login_page_url ), 'ur_login_preview' ) ); ?>" target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'View Live', 'user-registration' ); ?></a>
<?php else : ?>
<button name="create_login_page" data-form_id="<?php esc_attr_e( $login_page_id ); ?>" class="button button-large ur-embed-form-button ur-create-login-page-button" type="button" value="<?php esc_attr_e( 'Create Login Page', 'user-registration' ); ?>" title="<?php esc_attr_e( 'Create Login Page', 'user-registration' ); ?>">+ <?php esc_html_e( 'Create Login Page', 'user-registration' ); ?></button>
<?php endif; ?>
--- a/user-registration/includes/blocks/block-types/class-ur-block-abstract.php
+++ b/user-registration/includes/blocks/block-types/class-ur-block-abstract.php
@@ -39,6 +39,13 @@
protected $content = '';
/**
+ * Whether shortcode brackets in the rendered output are neutralised.
+ *
+ * @var bool
+ */
+ protected $escape_shortcodes = true;
+
+ /**
* Block instance.
*
* @var WP_Block
@@ -121,7 +128,7 @@
$this->build_html( $this->content ),
$this
);
- return $content;
+ return $this->escape_shortcodes ? ur_escape_shortcodes( $content ) : $content;
}
/**
--- a/user-registration/includes/blocks/block-types/class-ur-block-content-restriction.php
+++ b/user-registration/includes/blocks/block-types/class-ur-block-content-restriction.php
@@ -19,6 +19,13 @@
protected $block_name = 'content-restriction-enhanced';
/**
+ * Inner content is authored by the site owner and may hold shortcodes.
+ *
+ * @var bool
+ */
+ protected $escape_shortcodes = false;
+
+ /**
* Build html.
*
* @param string $content
--- a/user-registration/includes/blocks/block-types/class-ur-block-registration-form.php
+++ b/user-registration/includes/blocks/block-types/class-ur-block-registration-form.php
@@ -31,27 +31,11 @@
return $content;
}
- return $this->escape_shortcodes_in_html(
- UR_Shortcodes::form(
- array(
- 'id' => $form_id,
- 'userState' => $user_state,
- )
+ return UR_Shortcodes::form(
+ array(
+ 'id' => $form_id,
+ 'userState' => $user_state,
)
);
}
-
- /**
- * Escape shortcodes in html.
- *
- * @param string $html HTML content.
- * @return string
- */
- private function escape_shortcodes_in_html( $html ) {
- return str_replace(
- array( '[', ']' ),
- array( '[', ']' ),
- $html
- );
- }
}
--- a/user-registration/includes/class-ur-abilities-data.php
+++ b/user-registration/includes/class-ur-abilities-data.php
@@ -69,7 +69,10 @@
* @return array
*/
public static function list_members( $input ) {
- $page = self::page( $input );
+ $page = self::page( $input );
+ if ( isset( $input['status'] ) || isset( $input['email_verified'] ) ) {
+ return self::filter_members( $input, $page );
+ }
$query = new WP_User_Query(
self::member_query( $input ) + array(
'number' => $page['per_page'] + 1,
@@ -85,6 +88,221 @@
}
/**
+ * Page through members matching a status filter.
+ *
+ * Status spans several user meta keys, so members are filtered with the same
+ * resolver the output uses instead of a meta query that could disagree with it.
+ *
+ * @param array $input Validated input.
+ * @param array $page Page response.
+ * @return array|WP_Error
+ */
+ private static function filter_members( $input, $page ) {
+ $filters = array();
+ if ( isset( $input['status'] ) ) {
+ $filters['registration_status'] = $input['status'];
+ }
+ if ( isset( $input['email_verified'] ) ) {
+ // GET requests on WordPress 6.9 pass booleans as strings.
+ $filters['email_verified'] = rest_sanitize_boolean( $input['email_verified'] );
+ }
+ $skip = ( $page['page'] - 1 ) * $page['per_page'];
+ $args = self::member_query( $input ) + array(
+ 'number' => 200,
+ 'fields' => 'all_with_meta',
+ );
+ for ( $offset = 0; $offset < 10000; $offset += 200 ) {
+ $args['offset'] = $offset;
+ $query = new WP_User_Query( $args );
+ $users = $query->get_results();
+ foreach ( $users as $user ) {
+ $member = self::member( $user );
+ foreach ( $filters as $key => $value ) {
+ if ( $value !== $member[ $key ] ) {
+ continue 2;
+ }
+ }
+ if ( $skip > 0 ) {
+ --$skip;
+ continue;
+ }
+ if ( count( $page['items'] ) === $page['per_page'] ) {
+ $page['has_more'] = true;
+ return $page;
+ }
+ $page['items'][] = $member;
+ }
+ if ( count( $users ) < 200 ) {
+ return $page;
+ }
+ }
+ $args['offset'] = 10000;
+ $args['number'] = 1;
+ $args['fields'] = 'ID';
+ $query = new WP_User_Query( $args );
+ if ( ! $query->get_results() ) {
+ return $page;
+ }
+ return new WP_Error( 'ur_abilities_member_limit', __( 'More than 10000 members to filter. Add a form_id to narrow the list.', 'user-registration' ), array( 'status' => 400 ) );
+ }
+
+ /**
+ * List membership plans with their active member counts.
+ *
+ * @param array $input Validated input.
+ * @return array|WP_Error
+ */
+ public static function list_memberships( $input ) {
+ if ( ! self::membership_ready() ) {
+ return self::membership_unavailable();
+ }
+ $page = self::page( $input );
+ $repository = new WPEverestURMembershipAdminRepositoriesMembershipRepository();
+ $currency = get_option( 'user_registration_payment_currency', 'USD' );
+ $plans = array_filter(
+ array_reverse( $repository->get_all_memberships_without_status_filter() ),
+ function ( $plan ) {
+ return 'trash' !== $plan['post_status'];
+ }
+ );
+ $plans = array_slice( $plans, ( $page['page'] - 1 ) * $page['per_page'], $page['per_page'] + 1 );
+ $members = $repository->count_members_by_membership( 'active' );
+ $page['has_more'] = count( $plans ) > $page['per_page'];
+ foreach ( array_slice( $plans, 0, $page['per_page'] ) as $plan ) {
+ $meta = is_array( $plan['meta_value'] ) ? $plan['meta_value'] : array();
+ $type = isset( $meta['type'] ) ? (string) $meta['type'] : '';
+ $billing = 'subscription' === $type && isset( $meta['subscription']['value'], $meta['subscription']['duration'] );
+ $page['items'][] = array(
+ 'id' => (int) $plan['ID'],
+ 'name' => wp_strip_all_tags( $plan['post_title'] ),
+ 'enabled' => 'publish' === $plan['post_status'] && ! empty( $plan['post_content']['status'] ),
+ 'type' => $type,
+ 'amount' => isset( $meta['amount'] ) ? (string) $meta['amount'] : '0',
+ 'currency' => $currency,
+ 'billing_interval' => $billing ? (int) $meta['subscription']['value'] : null,
+ 'billing_period' => $billing ? (string) $meta['subscription']['duration'] : null,
+ 'active_members' => isset( $members[ $plan['ID'] ] ) ? $members[ $plan['ID'] ] : 0,
+ );
+ }
+ return $page;
+ }
+
+ /**
+ * List a bounded page of membership subscriptions.
+ *
+ * @param array $input Validated input.
+ * @return array|WP_Error
+ */
+ public static function list_subscriptions( $input ) {
+ if ( ! self::membership_ready() ) {
+ return self::membership_unavailable();
+ }
+ $error = self::date_range_error( $input, 'expiry_from', 'expiry_to' );
+ if ( $error ) {
+ return $error;
+ }
+ $page = self::page( $input );
+ $repository = new WPEverestURMembershipAdminRepositoriesSubscriptionRepository();
+ $result = $repository->query(
+ array(
+ 'page' => $page['page'],
+ 'per_page' => $page['per_page'],
+ 'orderby' => 'ID',
+ 'order' => 'ASC',
+ 'status' => isset( $input['status'] ) ? $input['status'] : '',
+ 'user_id' => isset( $input['member_id'] ) ? $input['member_id'] : 0,
+ 'item_id' => isset( $input['membership_id'] ) ? $input['membership_id'] : 0,
+ 'expiry_from' => isset( $input['expiry_from'] ) ? $input['expiry_from'] : '',
+ 'expiry_to' => isset( $input['expiry_to'] ) ? $input['expiry_to'] : '',
+ )
+ );
+ $page['has_more'] = $page['page'] * $page['per_page'] < $result['total'];
+ cache_users( wp_list_pluck( $result['items'], 'user_id' ) );
+ foreach ( $result['items'] as $subscription ) {
+ $user = get_userdata( $subscription->user_id );
+ $page['items'][] = array(
+ 'id' => (int) $subscription->ID,
+ 'member_id' => (int) $subscription->user_id,
+ 'member_email' => $user ? $user->user_email : '',
+ 'membership_id' => (int) $subscription->item_id,
+ 'membership_name' => wp_strip_all_tags( get_the_title( $subscription->item_id ) ),
+ 'status' => (string) $subscription->status,
+ 'start_date' => (string) $subscription->start_date,
+ 'expiry_date' => (string) $subscription->expiry_date,
+ 'next_billing_date' => (string) $subscription->next_billing_date,
+ 'billing_amount' => (string) $subscription->billing_amount,
+ );
+ }
+ return $page;
+ }
+
+ /**
+ * List a bounded page of membership payments, newest first.
+ *
+ * @param array $input Validated input.
+ * @return array|WP_Error
+ */
+ public static function list_orders( $input ) {
+ if ( ! self::membership_ready() ) {
+ return self::membership_unavailable();
+ }
+ $error = self::date_range_error( $input, 'date_from', 'date_to' );
+ if ( $error ) {
+ return $error;
+ }
+ $page = self::page( $input );
+ $args = array(
+ 'orderby' => 'ID',
+ 'order' => 'DESC',
+ 'limit' => $page['per_page'] + 1,
+ 'offset' => ( $page['page'] - 1 ) * $page['per_page'],
+ );
+ foreach ( array( 'membership_id', 'status', 'date_from', 'date_to' ) as $key ) {
+ if ( isset( $input[ $key ] ) ) {
+ $args[ $key ] = $input[ $key ];
+ }
+ }
+ if ( isset( $input['gateway'] ) ) {
+ $args['payment_method'] = $input['gateway'];
+ }
+ $repository = new WPEverestURMembershipAdminRepositoriesOrdersRepository();
+ $orders = $repository->get_all( $args );
+ // The repository returns an empty page shape, not rows, when the table is missing.
+ if ( isset( $orders['items'] ) ) {
+ return $page;
+ }
+ $page['has_more'] = count( $orders ) > $page['per_page'];
+ foreach ( array_slice( $orders, 0, $page['per_page'] ) as $order ) {
+ $page['items'][] = self::order( $order );
+ }
+ return $page;
+ }
+
+ /**
+ * Read one membership payment.
+ *
+ * @param array $input Validated input.
+ * @return array|WP_Error
+ */
+ public static function get_order( $input ) {
+ if ( ! self::membership_ready() ) {
+ return self::membership_unavailable();
+ }
+ $repository = new WPEverestURMembershipAdminRepositoriesOrdersRepository();
+ $order = $repository->get_order_detail( $input['id'] );
+ if ( empty( $order['order_id'] ) ) {
+ return self::not_found();
+ }
+ return self::order( $order ) + array(
+ 'member_id' => (int) $order['user_id'],
+ 'subscription_status' => (string) $order['subscription_status'],
+ 'expiry_date' => (string) $order['expiry_date'],
+ 'next_billing_date' => (string) $order['next_billing_date'],
+ 'coupon' => (string) $order['coupon'],
+ );
+ }
+
+ /**
* Read a member's identity and membership subscriptions.
*
* @param array $input Validated input.
@@ -102,7 +320,7 @@
return self::not_found();
}
$result = self::member( $users[0] );
- $result['membership_available'] = ur_check_module_activation( 'membership' ) && class_exists( 'WPEverestURMembershipAdminRepositoriesMembersRepository' );
+ $result['membership_available'] = self::membership_ready();
$result['subscriptions'] = array();
if ( $result['membership_available'] ) {
$repository = new WPEverestURMembershipAdminRepositoriesMembersRepository();
@@ -133,7 +351,7 @@
$start = DateTimeImmutable::createFromFormat( '!Y-m-d', $from, new DateTimeZone( 'UTC' ) );
$end = DateTimeImmutable::createFromFormat( '!Y-m-d', $to, new DateTimeZone( 'UTC' ) );
if ( ! $start || ! $end || $start->format( 'Y-m-d' ) !== $from || $end->format( 'Y-m-d' ) !== $to || $end < $start || $start->diff( $end )->days > 92 ) {
- return new WP_Error( 'ur_abilities_date_range', __( 'Use valid dates in ascending order spanning at most 93 days.', 'user-registration' ) );
+ return new WP_Error( 'ur_abilities_date_range', __( 'Use valid dates in ascending order spanning at most 93 days.', 'user-registration' ), array( 'status' => 400 ) );
}
$args = self::member_query( $input );
// Statistics count form registrations, excluding membership-only accounts.
@@ -157,7 +375,7 @@
$query = new WP_User_Query( $args );
$total = (int) $query->get_total();
if ( $total > 10000 ) {
- return new WP_Error( 'ur_abilities_stats_limit', __( 'More than 10000 registrations match. Narrow the dates or specify a form.', 'user-registration' ) );
+ return new WP_Error( 'ur_abilities_stats_limit', __( 'More than 10000 registrations match. Narrow the dates or specify a form.', 'user-registration' ), array( 'status' => 400 ) );
}
$groups = array();
$args['number'] = 500;
@@ -281,18 +499,86 @@
private static function page( $input ) {
return array(
'items' => array(),
- 'page' => isset( $input['page'] ) ? $input['page'] : 1,
- 'per_page' => isset( $input['per_page'] ) ? $input['per_page'] : 20,
+ 'page' => isset( $input['page'] ) ? absint( $input['page'] ) : 1,
+ 'per_page' => isset( $input['per_page'] ) ? absint( $input['per_page'] ) : 20,
'has_more' => false,
);
}
/**
+ * Serialize the payment fields shown in the admin payment list.
+ *
+ * @param array $order Order row.
+ * @return array
+ */
+ private static function order( $order ) {
+ return array(
+ 'id' => (int) $order['order_id'],
+ 'member_email' => (string) $order['user_email'],
+ 'member_name' => (string) $order['display_name'],
+ 'membership_id' => (int) $order['post_id'],
+ 'membership_name' => wp_strip_all_tags( $order['post_title'] ),
+ 'subscription_id' => (int) $order['subscription_id'],
+ 'status' => (string) $order['status'],
+ 'type' => isset( $order['order_type'] ) ? (string) $order['order_type'] : '',
+ 'gateway' => (string) $order['payment_method'],
+ 'transaction_id' => (string) $order['transaction_id'],
+ 'amount' => (string) $order['total_amount'],
+ 'currency' => get_option( 'user_registration_payment_currency', 'USD' ),
+ 'created_at' => (string) ( isset( $order['order_created_at'] ) ? $order['order_created_at'] : $order['created_at'] ),
+ );
+ }
+
+ /**
+ * Check optional Y-m-d dates are real and in ascending order.
+ *
+ * @param array $input Validated input.
+ * @param string $from_key Start date key.
+ * @param string $to_key End date key.
+ * @return WP_Error|null
+ */
+ private static function date_range_error( $input, $from_key, $to_key ) {
+ $dates = array();
+ foreach ( array( $from_key, $to_key ) as $key ) {
+ if ( ! isset( $input[ $key ] ) ) {
+ continue;
+ }
+ $date = DateTimeImmutable::createFromFormat( '!Y-m-d', $input[ $key ] );
+ if ( ! $date || $date->format( 'Y-m-d' ) !== $input[ $key ] ) {
+ return new WP_Error( 'ur_abilities_date_range', __( 'Use valid dates with the start date on or before the end date.', 'user-registration' ), array( 'status' => 400 ) );
+ }
+ $dates[] = $input[ $key ];
+ }
+ if ( 2 === count( $dates ) && $dates[0] > $dates[1] ) {
+ return new WP_Error( 'ur_abilities_date_range', __( 'Use valid dates with the start date on or before the end date.', 'user-registration' ), array( 'status' => 400 ) );
+ }
+ return null;
+ }
+
+ /**
+ * Whether the membership module and its repositories are loaded.
+ *
+ * @return bool
+ */
+ private static function membership_ready() {
+ return ur_check_module_activation( 'membership' ) && class_exists( 'WPEverestURMembershipAdminRepositoriesMembersRepository' );
+ }
+
+ /**
+ * Return a uniform error when membership is turned off.
+ *
+ * @return WP_Error
+ */
+ private static function membership_unavailable() {
+ return new WP_Error( 'ur_abilities_membership_disabled', __( 'Membership is not enabled on this site.', 'user-registration' ), array( 'status' => 403 ) );
+ }
+
+ /**
* Return a uniform missing-record error.
*
* @return WP_Error
*/
private static function not_found() {
- return new WP_Error( 'ur_abilities_not_found', __( 'Registration record not found.', 'user-registration' ) );
+ return new WP_Error( 'ur_abilities_not_found', __( 'Registration record not found.', 'user-registration' ), array( 'status' => 404 ) );
}
}
--- a/user-registration/includes/class-ur-abilities.php
+++ b/user-registration/includes/class-ur-abilities.php
@@ -17,17 +17,34 @@
/** Register the shared category. */
public static function register_category() {
+ if ( ! self::enabled() ) {
+ return;
+ }
wp_register_ability_category(
'user-registration',
array(
'label' => __( 'User Registration', 'user-registration' ),
- 'description' => __( 'Read registration forms and member information.', 'user-registration' ),
+ 'description' => __( 'Read registration forms, members, membership plans, subscriptions and payments.', 'user-registration' ),
)
);
}
+ /**
+ * Whether the site admin allows AI abilities.
+ *
+ * Off for new installs; existing sites are switched on once by UR_Install on update.
+ *
+ * @return bool
+ */
+ private static function enabled() {
+ return ur_option_checked( 'user_registration_enable_abilities', false );
+ }
+
/** Register bounded inputs and explicit output contracts. */
public static function register_abilities() {
+ if ( ! self::enabled() ) {
+ return;
+ }
$id = array(
'type' => 'integer',
'minimum' => 1,
@@ -102,11 +119,11 @@
);
$member_detail['required'][] = 'membership_available';
$member_detail['required'][] = 'subscriptions';
- $date = array(
+ $date = array(
'type' => 'string',
'pattern' => '^d{4}-d{2}-d{2}$',
);
- $stats = self::object_schema(
+ $stats = self::object_schema(
array(
'date_from' => $date,
'date_to' => $date,
@@ -131,7 +148,70 @@
),
)
);
- $definitions = array(
+ $nullable_string = array( 'type' => array( 'string', 'null' ) );
+ $count = array(
+ 'type' => 'integer',
+ 'minimum' => 0,
+ );
+ $key = array(
+ 'type' => 'string',
+ 'pattern' => '^[a-z0-9_-]+$',
+ 'maxLength' => 32,
+ );
+ $plan = self::object_schema(
+ array(
+ 'id' => $id,
+ 'name' => $string,
+ 'enabled' => array( 'type' => 'boolean' ),
+ 'type' => $string,
+ 'amount' => $string,
+ 'currency' => $string,
+ 'billing_interval' => array( 'type' => array( 'integer', 'null' ) ),
+ 'billing_period' => $nullable_string,
+ 'active_members' => $count,
+ )
+ );
+ $subscription = self::object_schema(
+ array(
+ 'id' => $id,
+ 'member_id' => $count,
+ 'member_email' => $string,
+ 'membership_id' => $count,
+ 'membership_name' => $string,
+ 'status' => $string,
+ 'start_date' => $string,
+ 'expiry_date' => $string,
+ 'next_billing_date' => $string,
+ 'billing_amount' => $string,
+ )
+ );
+ $order = self::object_schema(
+ array(
+ 'id' => $id,
+ 'member_email' => $string,
+ 'member_name' => $string,
+ 'membership_id' => $count,
+ 'membership_name' => $string,
+ 'subscription_id' => $count,
+ 'status' => $string,
+ 'type' => $string,
+ 'gateway' => $string,
+ 'transaction_id' => $string,
+ 'amount' => $string,
+ 'currency' => $string,
+ 'created_at' => $string,
+ )
+ );
+ $order_detail = self::object_schema(
+ $order['properties'] + array(
+ 'member_id' => $count,
+ 'subscription_status' => $string,
+ 'expiry_date' => $string,
+ 'next_billing_date' => $string,
+ 'coupon' => $string,
+ )
+ );
+ $definitions = array(
'list-forms' => array( __( 'List registration forms', 'user-registration' ), __( 'List editable registration forms. Pagination follows scanned form pages; inaccessible forms are omitted.', 'user-registration' ), $pagination, array(), self::page_schema( $form ), 'forms_permission' ),
'get-form' => array( __( 'Get registration form', 'user-registration' ), __( 'Read form identity and field definitions without raw settings or default values.', 'user-registration' ), array( 'id' => $id ), array( 'id' ), $detail, 'forms_permission' ),
'get-registration-stats' => array(
@@ -146,8 +226,52 @@
$stats,
'members_permission',
),
- 'list-members' => array( __( 'List registered members', 'user-registration' ), __( 'List users registered through a form or the membership module on this site.', 'user-registration' ), $pagination + array( 'form_id' => $id ), array(), self::page_schema( $member ), 'members_permission' ),
+ 'list-members' => array(
+ __( 'List registered members', 'user-registration' ),
+ __( 'List users registered through a form or the membership module on this site. Filter by approval status or email verification to find members waiting for review; filtering scans at most 10000 members.', 'user-registration' ),
+ $pagination + array(
+ 'form_id' => $id,
+ 'status' => array(
+ 'type' => 'string',
+ 'enum' => array( 'approved', 'pending', 'denied' ),
+ ),
+ 'email_verified' => array( 'type' => 'boolean' ),
+ ),
+ array(),
+ self::page_schema( $member ),
+ 'members_permission',
+ ),
'get-member' => array( __( 'Get registered member', 'user-registration' ), __( 'Read a registered member and their subscriptions. Membership availability is reported explicitly.', 'user-registration' ), array( 'id' => $id ), array( 'id' ), $member_detail, 'members_permission' ),
+ 'list-memberships' => array( __( 'List membership plans', 'user-registration' ), __( 'List membership plans with price, billing period and the number of members with an active subscription.', 'user-registration' ), $pagination, array(), self::page_schema( $plan ), 'members_permission' ),
+ 'list-subscriptions' => array(
+ __( 'List membership subscriptions', 'user-registration' ),
+ __( 'List subscriptions by status, plan, member or expiry date range, for example to find memberships that expire soon.', 'user-registration' ),
+ $pagination + array(
+ 'status' => $key,
+ 'membership_id' => $id,
+ 'member_id' => $id,
+ 'expiry_from' => $date,
+ 'expiry_to' => $date,
+ ),
+ array(),
+ self::page_schema( $subscription ),
+ 'members_permission',
+ ),
+ 'list-orders' => array(
+ __( 'List membership payments', 'user-registration' ),
+ __( 'List membership payments, newest first, by status, gateway, plan or payment date range.', 'user-registration' ),
+ $pagination + array(
+ 'status' => $key,
+ 'gateway' => $key,
+ 'membership_id' => $id,
+ 'date_from' => $date,
+ 'date_to' => $date,
+ ),
+ array(),
+ self::page_schema( $order ),
+ 'members_permission',
+ ),
+ 'get-order' => array( __( 'Get membership payment', 'user-registration' ), __( 'Read one membership payment with its subscription status and dates.', 'user-registration' ), array( 'id' => $id ), array( 'id' ), $order_detail, 'members_permission' ),
);
foreach ( $definitions as $name => $definition ) {
$input = self::object_schema( $definition[2] );
--- a/user-registration/includes/class-ur-ajax.php
+++ b/user-registration/includes/class-ur-ajax.php
@@ -53,55 +53,54 @@
add_action( 'wp_ajax_nopriv_user_registration_nocache_headers', array( __CLASS__, 'add_nocache_headers' ) );
$ajax_events = array(
- 'user_input_dropped' => true,
- 'user_form_submit' => true,
- 'get_recent_nonce' => true,
- 'update_profile_details' => true,
- 'profile_pic_upload' => true,
- 'ajax_login_submit' => true,
- 'send_test_email' => false,
- 'create_form' => false,
- 'rated' => false,
- 'dashboard_widget' => false,
- 'dismiss_notice' => false,
- 'dismiss_notice_per_user' => false,
- 'import_form_action' => false,
- 'template_licence_check' => false,
- 'captcha_setup_check' => false,
- 'install_extension' => false,
- 'profile_pic_remove' => false,
- 'form_save_action' => false,
- 'login_settings_save_action' => false,
- 'embed_form_action' => false,
- 'embed_page_list' => false,
- 'allow_usage_dismiss' => false,
- 'cancel_email_change' => false,
- 'email_setting_status' => false,
- 'locked_form_fields_notice' => false,
- 'search_global_settings' => false,
- 'php_notice_dismiss' => false,
- 'locate_form_action' => false,
- 'form_preview_save' => false,
- 'generate_row_settings' => false,
- 'my_account_selection_validator' => false,
- 'lost_password_selection_validator' => false,
- 'save_payment_settings' => false,
- 'disable_user' => false,
- 'validate_payment_currency' => false,
- 'save_captcha_settings' => false,
- 'reset_captcha_keys' => false,
- 'reset_payment_keys' => false,
- 'create_default_form' => false,
- 'generate_required_pages' => false,
- 'handle_default_wordpress_login' => false,
- 'enable_emails' => false,
- 'skip_site_assistant_section' => false,
- 'migrate_existing_users' => false,
- 'login_settings_page_validation' => false,
- 'activate_dependent_module' => false,
- 'add_membership_field_to_default_form' => false,
- 'update_state_field' => true,
- 'toggle_logging' => false,
+ 'user_input_dropped' => true,
+ 'user_form_submit' => true,
+ 'get_recent_nonce' => true,
+ 'update_profile_details' => true,
+ 'profile_pic_upload' => true,
+ 'ajax_login_submit' => true,
+ 'send_test_email' => false,
+ 'create_form' => false,
+ 'rated' => false,
+ 'dashboard_widget' => false,
+ 'dismiss_notice' => false,
+ 'dismiss_notice_per_user' => false,
+ 'import_form_action' => false,
+ 'template_licence_check' => false,
+ 'captcha_setup_check' => false,
+ 'install_extension' => false,
+ 'profile_pic_remove' => false,
+ 'form_save_action' => false,
+ 'login_settings_save_action' => false,
+ 'embed_form_action' => false,
+ 'embed_page_list' => false,
+ 'allow_usage_dismiss' => false,
+ 'cancel_email_change' => false,
+ 'email_setting_status' => false,
+ 'locked_form_fields_notice' => false,
+ 'search_global_settings' => false,
+ 'php_notice_dismiss' => false,
+ 'locate_form_action' => false,
+ 'form_preview_save' => false,
+ 'generate_row_settings' => false,
+ 'my_account_selection_validator' => false,
+ 'lost_password_selection_validator' => false,
+ 'save_payment_settings' => false,
+ 'disable_user' => false,
+ 'validate_payment_currency' => false,
+ 'save_captcha_settings' => false,
+ 'reset_captcha_keys' => false,
+ 'reset_payment_keys' => false,
+ 'create_default_form' => false,
+ 'generate_required_pages' => false,
+ 'handle_default_wordpress_login' => false,
+ 'enable_emails' => false,
+ 'skip_site_assistant_section' => false,
+ 'migrate_existing_users' => false,
+ 'login_settings_page_validation' => false,
+ 'activate_dependent_module' => false,
+ 'update_state_field' => true,
+ 'toggle_logging' => false,
);
foreach ( $ajax_events as $ajax_event => $nopriv ) {
@@ -220,8 +219,7 @@
* @return void
*/
public static function user_form_submit() {
- $nonce_value = isset( $_POST['ur_frontend_form_nonce'] ) ? wp_unslash( sanitize_key( $_POST['ur_frontend_form_nonce'] ) ) : '';
- ur_process_registration( $nonce_value );
+ ur_process_registration();
}
@@ -2352,68 +2350,13 @@
}
public static function get_recent_nonce() {
- // Public forms need public nonce refresh. A request referer is not authorization.
- if ( ( isset( $_POST['nonce_for'] ) && ! is_string( $_POST['nonce_for'] ) ) ||
- ( isset( $_POST['form_ids'] ) && ! is_string( $_POST['form_ids'] ) ) ) {
- wp_send_json_error( array( __( 'Invalid nonce request.', 'user-registration' ) ), 400 );
- }
+ // Only the login form needs a public nonce refresh. A request referer is not authorization.
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Public guest nonce refresh does not require an existing nonce.
- $for = isset( $_POST['nonce_for'] ) ? sanitize_key( wp_unslash( $_POST['nonce_for'] ) ) : 'registration';
- // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Public refresh; IDs are strictly validated below.
- $form_ids = isset( $_POST['form_ids'] ) ? array_unique( array_filter( explode( ',', wp_unslash( $_POST['form_ids'] ) ) ) ) : array();
- if ( ! in_array( $for, array( 'login', 'registration' ), true ) || count( $form_ids ) > 100 ) {
+ if ( ! isset( $_POST['nonce_for'] ) || 'login' !== $_POST['nonce_for'] ) {
wp_send_json_error( array( __( 'Invalid nonce request.', 'user-registration' ) ), 400 );
}
- if ( 'registration' === $for ) {
-
- if ( empty( $form_ids ) ) {
- wp_send_json_error(
- array(
- __( 'Form ID is missing!', 'user-registration' ),
- )
- );
- }
- foreach ( $form_ids as $form_id ) {
- if ( ! ctype_digit( $form_id ) || (int) $form_id < 1 ) {
- wp_send_json_error( array( __( 'Invalid form ID.', 'user-registration' ) ), 400 );
- }
- $post = get_post( (int) $form_id );
- if ( ! $post || 'user_registration' !== $post->post_type ||
- ( 'publish' !== $post->post_status && ! current_user_can( 'edit_post', (int) $form_id ) ) ) {
- wp_send_json_error( array( __( 'Form not found!', 'user-registration' ) ), 404 );
- }
- $form = ur_get_form_fields( $form_id );
- if ( empty( $form ) ) {
- wp_send_json_error(
- array(
- __( 'Form not found!', 'user-registration' ),
- )
- );
- }
- }
- }
-
- $updated_nonce_array = array();
- switch ( $for ) {
- case 'registration':
- foreach ( $form_ids as $form_id ) {
- $updated_nonce_array[ $form_id ] = wp_create_nonce( 'ur_frontend_form_id-' . $form_id );
- }
- break;
- default:
- $updated_nonce_array = wp_create_nonce( 'ur_login_form_save_nonce' );
- break;
- }
-
- if ( empty( $updated_nonce_array ) ) {
- wp_send_json_error(
- array(
- __( 'Nonce could not be updated', 'user-registration' ),
- )
- );
- }
- wp_send_json_success( $updated_nonce_array );
+ wp_send_json_success( wp_create_nonce( 'ur_login_form_save_nonce' ) );
}
public static function validate_payment_currency() {
--- a/user-registration/includes/class-ur-form-handler.php
+++ b/user-registration/includes/class-ur-form-handler.php
@@ -206,6 +206,11 @@
$field_name = $field->general_setting->field_name;
$key = 'user_registration_' . $field_name;
+ // The profile save below reads the checkbox straight from the post, so clean it first.
+ if ( isset( $field->field_key ) && 'checkbox' === $field->field_key && isset( $_POST[ $key ] ) ) {
+ $_POST[ $key ] = wp_slash( ur_sanitize_checkbox_profile_value( wp_unslash( $_POST[ $key ] ), $field ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ }
+
$field_obj = new StdClass();
$field_obj->field_name = $field_name;
$fields[ $field_name ] = user_registration_sanitize_profile_update( $_POST, $field->field_key, $key );
@@ -631,13 +636,9 @@
* @throws Exception Login errors.
*/
public static function process_registration() {
- $nonce_value = isset( $_POST['_wpnonce'] ) ? sanitize_key( $_POST['_wpnonce'] ) : '';
-
- $nonce_value = isset( $_POST['ur_frontend_form_nonce'] ) ? sanitize_key( $_POST['ur_frontend_form_nonce'] ) : $nonce_value;
-
if ( ! empty( $_POST['ur_fallback_submit'] ) ) {
$_POST['form_data'] = urldecode( $_POST['form_data'] );
- ur_process_registration( $nonce_value );
+ ur_process_registration();
}
}
--- a/user-registration/includes/class-ur-install.php
+++ b/user-registration/includes/class-ur-install.php
@@ -161,6 +161,8 @@
add_option( 'urm_is_legacy_ecommerce_addons_user', $has_legacy_ecommerce_addons ? 1 : 0 );
}
+ self::maybe_keep_abilities_for_existing_site();
+
self::create_files();
self::update_ur_version();
self::maybe_update_db_version();
@@ -236,6 +238,29 @@
}
/**
+ * Keep AI abilities on for sites that already had them.
+ *
+ * Abilities shipped without a setting in 5.3.0 and the setting is off by default. Free and Pro version
+ * numbers differ, so this runs once per site from a flag rather than from a version check.
+ *
+ * @since 5.3.2
+ *
+ * @return void
+ */
+ private static function maybe_keep_abilities_for_existing_site() {
+ if ( null !== get_option( 'urm_is_legacy_abilities_user', null ) ) {
+ return;
+ }
+
+ $is_existing_site = ! self::is_new_install();
+ add_option( 'urm_is_legacy_abilities_user', $is_existing_site ? 1 : 0 );
+
+ if ( $is_existing_site ) {
+ add_option( 'user_registration_enable_abilities', 'yes' );
+ }
+ }
+
+ /**
* See if we need the wizard or not.
*/
private static function maybe_enable_setup_wizard() {
@@ -359,6 +384,9 @@
include_once 'functions-ur-update.php';
+ // An update does not run install(), so decide here, before the new version is saved.
+ self::maybe_keep_abilities_for_existing_site();
+
// Finish any leftover ≤1.6.2 background callbacks / stuck DB version first.
self::sync_legacy_db_updates();
--- a/user-registration/includes/class-ur-preview.php
+++ b/user-registration/includes/class-ur-preview.php
@@ -37,7 +37,7 @@
add_action( 'template_redirect', array( $this, 'handle_preview' ) );
add_filter( 'astra_remove_entry_header_content', '__return_true' ); // Need to remove in next version, If astra release the patches.
- } elseif ( isset( $_GET['ur_login_preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ } elseif ( self::is_login_preview() ) {
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
add_action( 'template_redirect', array( $this, 'handle_login_preview' ) );
add_filter( 'home_template_hierarchy', array( $this, 'template_include' ) );
@@ -52,6 +52,18 @@
}
/**
+ * Whether this request is a valid login page preview: allowed user and a good nonce.
+ *
+ * @return bool
+ */
+ public static function is_login_preview() {
+ return isset( $_GET['ur_login_preview'], $_GET['_wpnonce'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ && is_user_logged_in()
+ && current_user_can( 'manage_user_registration' )
+ && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'ur_login_preview' );
+ }
+
+ /**
* Change edit link of preview page.
*
* @param string $link Link.
--- a/user-registration/includes/class-ur-query.php
+++ b/user-registration/includes/class-ur-query.php
@@ -39,7 +39,7 @@
* Get any errors from querystring.
*/
public function get_errors() {
- $error = ! empty( $_GET['ur_error'] ) ? sanitize_text_field( wp_unslash( $_GET['ur_error'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ $error = ! empty( $_GET['ur_error'] ) ? ur_escape_shortcodes( sanitize_text_field( wp_unslash( $_GET['ur_error'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( $error && ! ur_has_notice( $error, 'error' ) ) {
ur_add_notice( $error, 'error' );
--- a/user-registration/includes/class-ur-user-approval.php
+++ b/user-registration/includes/class-ur-user-approval.php
@@ -433,7 +433,7 @@
$form_id = ur_get_form_id_by_userid( get_current_user_id() );
- if ( 'admin_approval' === ur_get_user_login_option( get_current_user_id() ) && $form_id ) {
+ if ( in_array( ur_get_user_login_option( get_current_user_id() ), array( 'admin_approval', 'admin_approval_after_email_confirmation' ), true ) && $form_id ) {
// Try to hide the not approved users from any theme or plugin request in frontend.
$disable_pre_get = apply_filters( 'user_registration_disable_pre_get_users', 'no' );
@@ -446,7 +446,8 @@
$user_manager = new UR_Admin_User_Manager();
- if ( ! $user_manager->can_status_be_changed_by( get_current_user_id() ) ) {
+ // Admins are never logged out by the approval check.
+ if ( current_user_can( 'manage_options' ) ) {
return;
}
/**
@@ -460,7 +461,7 @@
*/
do_action( 'ur_user_before_check_status_on_page', $status, $user_manager );
- if ( UR_Admin_User_Manager::APPROVED === $status ) {
+ if ( $user_manager->is_approved() ) {
return;
}
--- a/user-registration/includes/form/class-ur-form-field-checkbox.php
+++ b/user-registration/includes/form/class-ur-form-field-checkbox.php
@@ -92,7 +92,8 @@
$field_label = $single_form_field->general_setting->field_name;
$value = $form_data->value;
$values = is_array( $value ) ? $value : json_decode( (string) $value, true );
- $values = is_array( $values ) ? $values : ( '' === $value || null === $value ? array() : array( array() ) );
+ // Saving a profile with every option unticked sends 0, which means nothing is selected.
+ $values = is_array( $values ) ? $values : ( '' === $value || null === $value || '0' === (string) $value ? array() : array( array() ) );
$options = isset( $single_form_field->general_setting->options ) ? (array) $single_form_field->general_setting->options : array();
if ( empty( $options ) && ! empty( $single_form_field->advance_setting->choices ) ) {
$options = explode( ',', $single_form_field->advance_setting->choices );
--- a/user-registration/includes/frontend/class-ur-frontend-form-handler.php
+++ b/user-registration/includes/frontend/class-ur-frontend-form-handler.php
@@ -543,16 +543,20 @@
$login_option = ur_get_user_login_option( $user_id );
update_user_meta( $user_id, 'ur_login_option', $login_option );
- // Server-side payment-gate flag so login fails closed even if the client omits membership signals. UR-4811.
+ // Arm the payment gate from the saved form, not the request, so omitting the membership field cannot skip it. UR-4811.
if ( 'payment' === $login_option && function_exists( 'ur_check_module_activation' ) && ur_check_module_activation( 'membership' ) ) {
- $hidden_fields = isset( $_POST['urcl_hide_fields'] ) ? (array) json_decode( wp_unslash( $_POST['urcl_hide_fields'] ), true ) : array();
- foreach ( $valid_form_data as $field ) {
- if ( isset( $field->extra_params['field_key'] ) && 'membership' === $field->extra_params['field_key'] ) {
- if ( ! in_array( $field->field_name, $hidden_fields, true ) ) {
- update_user_meta( $user_id, 'ur_requires_payment', 'yes' );
- }
- break;
+ $hidden_fields = isset( $_POST['urcl_hide_fields'] ) ? (array) json_decode( wp_unslash( $_POST['urcl_hide_fields'] ), true ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ foreach ( ur_get_form_fields( $form_id ) as $form_field ) {
+ if ( 'membership' !== $form_field->field_key ) {
+ continue;
}
+
+ // Only a membership field the admin made conditional can be hidden, which leaves a plain account with nothing to pay.
+ $is_conditional = isset( $form_field->advance_setting->enable_conditional_logic ) && ur_string_to_bool( $form_field->advance_setting->enable_conditional_logic );
+ if ( ! $is_conditional || ! in_array( $form_field->general_setting->field_name, $hidden_fields, true ) ) {
+ update_user_meta( $user_id, 'ur_requires_payment', 'yes' );
+ }
+ break;
}
}
--- a/user-registration/includes/functions-ur-core.php
+++ b/user-registration/includes/functions-ur-core.php
@@ -18,6 +18,8 @@
add_filter( 'sanitize_user_meta_first_name', 'sanitize_text_field' );
add_filter( 'sanitize_user_meta_last_name', 'sanitize_text_field' );
add_filter( 'sanitize_user_meta_nickname', 'sanitize_text_field' );
+// The bio is saved as user meta, which skips the filtering WordPress does in wp_update_user().
+add_filter( 'sanitize_user_meta_description', 'ur_sanitize_user_description' );
// Include core functions (available in both admin and frontend).
require UR_ABSPATH . 'includes/functions-ur-page.php';
@@ -238,6 +240,28 @@
}
/**
+ * Sanitize the user biography the way WordPress does when it saves it.
+ *
+ * @since xx.xx.xx
+ *
+ * @param mixed $value Biography value.
+ *
+ * @return mixed
+ */
+function ur_sanitize_user_description( $value ) {
+ if ( current_user_can( 'unfiltered_html' ) ) {
+ return $value;
+ }
+
+ // `description[]=...` reaches this filter as an array; clean every string inside it.
+ if ( is_array( $value ) || is_object( $value ) ) {
+ return map_deep( $value, 'ur_sanitize_user_description' );
+ }
+
+ return is_string( $value ) ? wp_kses( $value, 'user_description' ) : $value;
+}
+
+/**
* Sanitize a string destined to be a tooltip.
*
* @param string $var Value to sanitize.
@@ -5844,10 +5868,9 @@
/**
* Process Registration.
*
- * @param string $nonce_value Nonce value.
* @return void
*/
- function ur_process_registration( $nonce_value ) {
+ function ur_process_registration() {
/**
* Filter to modify user capability.
* Default value is 'create_users'.
@@ -7854,6 +7877,82 @@
}
}
+if ( ! function_exists( 'ur_sanitize_checkbox_profile_value' ) ) {
+
+ /**
+ * Clean a checkbox value submitted through a profile update.
+ *
+ * Arrays keep only the options the field offers, using the same matching as the registration check.
+ * A field with no options keeps plain, sanitized text.
+ *
+ * @param mixed $value Submitted value, an array or its JSON string.
+ * @param object|null $field Form field definition from ur_get_form_field_data().
+ *
+ * @since xx.xx.xx
+ *
+ * @return mixed Array of values, or a sanitized scalar.
+ */
+ function ur_sanitize_checkbox_profile_value( $value, $field = null ) {
+ if ( is_string( $value ) ) {
+ $decoded = json_decode( $value, true );
+ if ( is_array( $decoded ) || ( null !== $decoded && is_scalar( $decoded ) ) ) {
+ $value = $decoded;
+ }
+ }
+
+ $options = isset( $field->general_setting->options ) ? (array) $field->general_setting->options : array();
+ if ( empty( $options ) && ! empty( $field->advance_setting->choices ) ) {
+ $options = explode( ',', $field->advance_setting->choices );
+ }
+ $image_choice = ! empty( $field->general_setting->image_choice ) && ur_string_to_bool( $field->general_setting->image_choice );
+ if ( $image_choice && ! empty( $field->general_setting->image_options ) ) {
+ // The form builder stores a list of label and image pairs; accept the label or the key, whichever the form renders as the value.
+ $options = array();
+ foreach ( (array) $field->general_setting->image_options as $image_key => $image_option ) {
+ $options[] = (string) $image_key;
+ $label = is_array( $image_option ) ? ( isset( $image_option['label'] ) ? $image_option['label'] : '' ) : ( isset( $image_option->label ) ? $image_option->label : '' );
+ if ( is_scalar( $label ) && '' !== (string) $label ) {
+ $options[] = (string) $label;
+ }
+ }
+ }
+ $allowed = array_map(
+ function ( $option ) {
+ return html_entity_decode( ur_sanitize_tooltip( trim( (string) $option ) ) );
+ },
+ $options
+ );
+
+ // A single value must be one of the options too, when the field has any.
+ if ( ! is_array( $value ) ) {
+ if ( ! is_scalar( $value ) ) {
+ return '';
+ }
+ if ( empty( $allowed ) ) {
+ return is_string( $value ) ? sanitize_text_field( $value ) : $value;
+ }
+
+ return in_array( (string) $value, $allowed, true ) ? $value : array();
+ }
+
+ $clean = array();
+ foreach ( $value as $selected ) {
+ if ( ! is_scalar( $selected ) ) {
+ continue;
+ }
+ $selected = (string) $selected;
+
+ if ( empty( $allowed ) ) {
+ $clean[] = sanitize_text_field( $selected );
+ } elseif ( in_array( $selected, $allowed, true ) ) {
+ $clean[] = $selected;
+ }
+ }
+
+ return $clean;
+ }
+}
+
if ( ! file_exists( 'user_registration_sanitize_profile_update' ) ) {
/**
@@ -7870,7 +7969,7 @@
switch ( $field_type ) {
case 'checkbox':
if ( isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] ) ) { // phpcs:ignore
- $value = wp_unslash( $submitted_data[ $key ] ); // phpcs:ignore
+ $value = map_deep( wp_unslash( $submitted_data[ $key ] ), 'sanitize_text_field' ); // phpcs:ignore
} else {
$value = (int) isset( $submitted_data[ $key ] ); // phpcs:ignore
}
@@ -11891,6 +11990,14 @@
*/
function urm_process_profile_fields( $profile, $single_field, $form_data, $form_id, $user_id, $is_admin_user = false ) {
+ // Checkbox definitions by meta key, to keep submitted values to the options each field offers.
+ $checkbox_fields = array();
+ foreach ( $form_id ? (array) ur_get_form_field_data( $form_id ) : array() as $form_field ) {
+ if ( isset( $form_field->field_key, $form_field->general_setting->field_name ) && 'checkbox' === $form_field->field_key ) {
+ $checkbox_fields[ 'user_registration_' . $form_field->general_setting->field_name ] = $form_field;
+ }
+ }
+
foreach ( $profile as $key => $field ) {
if ( ! isset( $field['type'] ) ) {
@@ -11920,7 +12027,7 @@
case 'checkbox':
if ( isset( $single_field[ $key ] ) ) {
// Serialize values fo checkbox field.
- $single_field[ $key ] = ( json_decode( $single_field[ $key ] ) !== null ) ? json_decode( $single_field[ $key ] ) : sanitize_text_field( $single_field[ $key ] );
+ $single_field[ $key ] = ur_sanitize_checkbox_profile_value( $single_field[ $key ], isset( $checkbox_fields[ $key ] ) ? $checkbox_fields[ $key ] : null );
}
break;
case 'wysiwyg':
@@ -13876,3 +13983,37 @@
return $preserve_keys ? $invoices : array_values( $invoices );
}
}
+
+if ( ! function_exists( 'ur_escape_shortcodes' ) ) {
+ /**
+ * Replace shortcode brackets with HTML entities so output is never run through do_shortcode().
+ *
+ * Script and style blocks are left untouched because entities are not decoded inside them.
+ *
+ * @since 5.3.2
+ *
+ * @param string $html HTML content.
+ * @return string
+ */
+ function ur_escape_shortcodes( $html ) {
+ $escaped = preg_replace_callback(
+ '#<(script|style)b.*?</1s*>|[[]]#is',
+ function ( $match ) {
+ $entities = array(
+ '[' => '[',
+ ']' => ']',
+ );
+
+ return isset( $entities[ $match[0] ] ) ? $entities[ $match[0] ] : $match[0];
+ },
+ $html
+ );
+
+ // PCRE can fail on very large input; escape every bracket rather than return nothing.
+ if ( null === $escaped ) {
+ return str_replace( array( '[', ']' ), array( '[', ']' ), $html );
+ }
+
+ return $escaped;
+ }
+}
--- a/user-registration/includes/validation/class-ur-form-validation.php
+++ b/user-registration/includes/validation/class-ur-form-validation.php
@@ -896,7 +896,8 @@
if ( ! empty( $response ) ) {
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX && ! ur_option_checked( 'user_registration_ajax_form_submission_on_edit_profile', false ) ) {
- $response = array_values( $response );
+ // A validator may return a single message instead of a list of them.
+ $response = is_array( $response ) ? array_values( $response ) : array( $response );
ur_add_notice( $response[0], 'error' );
} else {
ur_add_notice( $response, 'error' );
--- a/user-registration/modules/content-restriction/class-urcr-rest-restriction.php
+++ b/user-registration/modules/content-restriction/class-urcr-rest-restriction.php
@@ -26,6 +26,8 @@
public static function init() {
add_action( 'rest_api_init', array( __CLASS__, 'register_response_filters' ) );
add_filter( 'rest_request_after_callbacks', array( __CLASS__, 'restrict_woocommerce_response' ), PHP_INT_MAX, 3 );
+ add_filter( 'rest_comment_query', array( __CLASS__, 'exclude_restricted_post_comments' ), PHP_INT_MAX );
+ add_filter( 'rest_request_after_callbacks', array( __CLASS__, 'restrict_single_comment' ), PHP_INT_MAX, 3 );
foreach ( array( 'product', 'product_variation' ) as $post_type ) {
// Legacy WC controllers pass WP_Post; newer controllers pass WC_Product.
add_filter( 'woocommerce_rest_prepare_' . $post_type, array( __CLASS__, 'restrict_response' ), PHP_INT_MAX, 3 );
@@ -168,6 +170,99 @@
return $response;
}
+
+ /**
+ * Leave out comments on inaccessible posts from REST comment collections.
+ * Done in the query so totals and pagination headers stay accurate.
+ *
+ * @since 5.3.2
+ *
+ * @param array $args WP_Comment_Query arguments.
+ * @return array
+ */
+ public static function exclude_restricted_post_comments( $args ) {
+ global $wpdb;
+
+ if ( ! function_exists( 'urcr_is_content_access_granted' ) ) {
+ return $args;
+ }
+
+ // Several comment queries in one request (batch, embeds) share the full scan below.
+ static $scanned = array();
+
+ // A request for specific posts only needs those checked, not every commented post.
+ if ( ! empty( $args['post__in'] ) ) {
+ $post_ids = (array) $args['post__in'];
+ } else {
+ $user_id = get_current_user_id();
+ if ( ! isset( $scanned[ $user_id ] ) ) {
+ // Spam and trash are never returned, so their posts need no access check. Pending comments stay, as moderators can read them.
+ $scanned[ $user_id ] = $wpdb->get_col( "SELECT DISTINCT comment_post_ID FROM {$wpdb->comm