Changeset 3383669
- Timestamp:
- 10/23/2025 11:47:12 PM (5 months ago)
- Location:
- wp-members/trunk
- Files:
-
- 9 edited
-
includes/api/api-products.php (modified) (2 diffs)
-
includes/api/api-users.php (modified) (2 diffs)
-
includes/class-wp-members-shortcodes.php (modified) (2 diffs)
-
includes/class-wp-members-user-profile.php (modified) (1 diff)
-
includes/class-wp-members-user.php (modified) (3 diffs)
-
includes/class-wp-members.php (modified) (2 diffs)
-
includes/cli/class-wp-members-cli-user.php (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
-
wp-members.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-members/trunk/includes/api/api-products.php
r3368566 r3383669 167 167 * 168 168 * @since 3.5.0 169 * @since 3.5.5 Return false if no role. 169 170 * 170 171 * @param string $slug The membership slug (meta key). … … 172 173 function wpmem_get_membership_role( $membership_slug ) { 173 174 global $wpmem; 174 return ( isset( $wpmem->membership->memberships[ $membership_slug ]['role'] ) ) ? $wpmem->membership->memberships[ $membership_slug ]['role'] : '';175 return ( isset( $wpmem->membership->memberships[ $membership_slug ]['role'] ) ) ? $wpmem->membership->memberships[ $membership_slug ]['role'] : false; 175 176 } 176 177 -
wp-members/trunk/includes/api/api-users.php
r3368566 r3383669 281 281 282 282 /** 283 * Checks if a user is specifically deactivated. 284 * Note: this is not the same as not activated. 285 * 286 * @since 3.5.5 287 * 288 * @param int $user_id 289 * @return bool 290 */ 291 function wpmem_is_user_deactivated( $user_id ) { 292 $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id; 293 $status = get_user_meta( $user_id, 'active', true ); 294 return ( 2 == $status ) ? true : false; 295 } 296 297 /** 283 298 * Gets an array of the user's registration data. 284 299 * … … 446 461 $product_key = ( false == $product_key ) ? key( $memberships ) : $product_key; 447 462 $exp_date = ( is_numeric( $memberships[ $product_key ] ) ) ? $memberships[ $product_key ] : strtotime( $memberships[ $product_key ] ); 463 $exp_date = ( $format ) ? wpmem_format_date( array( 'date'=>$exp_date, 'date_format'=>$format ) ) : $exp_date; 448 464 return $exp_date; 465 } 466 467 function wpmem_get_user_time_remaining( $product_key = false, $user_id = false, $interval = 'days' ) { 468 $user_id = ( false === $user_id ) ? get_current_user_id() : $user_id; 469 $expires = wpmem_get_user_expiration( $product_key, $user_id, 'Y-m-d' ); 470 $target_date = new DateTime( $expires ); 471 $current_date = new DateTime(); 472 $date_diff = $current_date->diff( $target_date ); 473 switch( $interval ) { 474 case 'months': 475 return $date_diff->months; 476 break; 477 default: 478 return $date_diff->days; 479 break; 480 } 481 } 482 483 function wpmem_prorate_membership( $args ) { 484 449 485 } 450 486 -
wp-members/trunk/includes/class-wp-members-shortcodes.php
r3368566 r3383669 270 270 * @since 3.2.3 Added product attribute. 271 271 * @since 3.3.0 Added compare attribute for meta key/value compare (=|!=). 272 * @since 3.5.5 Added attribute for display on various states of [wpmem_profile]. 272 273 * 273 274 * @global object $wpmem The WP_Members object. … … 400 401 401 402 // Prevents display if the current page is the user profile and an action is being handled. 402 if ( ( wpmem_current_url( true, false ) == wpmem_profile_url() ) && isset( $_GET['a'] ) ) { 403 $do_return = false; 403 if ( ( wpmem_current_url( true, false ) == wpmem_profile_url() ) ) { 404 405 if ( isset( $_GET['a'] ) ) { 406 $do_return = false; 407 } 404 408 } 405 409 -
wp-members/trunk/includes/class-wp-members-user-profile.php
r3368566 r3383669 449 449 if ( 'enable' == $product_value ) { 450 450 // Does product require a role? 451 if ( false != wpmem_get_membership_role( $product_key ) || '' !=wpmem_get_membership_role( $product_key ) ) {451 if ( wpmem_get_membership_role( $product_key ) ) { 452 452 wpmem_update_user_role( $user_id, wpmem_get_membership_role( $product_key ), 'add' ); 453 453 } -
wp-members/trunk/includes/class-wp-members-user.php
r3292820 r3383669 86 86 */ 87 87 public function load_user_products() { 88 if ( is_user_logged_in() ) {89 $this->access = wpmem_get_user_ products( get_current_user_id() );88 if ( is_user_logged_in() && wpmem_is_enabled( 'enable_products' ) ) { 89 $this->access = wpmem_get_user_memberships( get_current_user_id() ); 90 90 } 91 91 } … … 1053 1053 * product). Maybe add role checking to the expiration block if both exist. 1054 1054 * 1055 * @global object $wpmem1056 1055 * @param mixed $membership Accepts a single membership slug/meta, or an array of multiple memberships. 1057 1056 * @param int $user_id (optional) … … 1059 1058 */ 1060 1059 public function has_access( $membership, $user_id = false ) { 1061 global $wpmem; 1060 1061 // If the user is not logged in and there is no user id, there's nothing to check. 1062 1062 if ( ! is_user_logged_in() && ! $user_id ) { 1063 1063 return false; 1064 1064 } 1065 1066 // Product must be an array. 1065 1066 // Current user or requested user? 1067 $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id; 1068 1069 // Membership must be an array. 1067 1070 $membership_array = ( ! is_array( $membership ) ) ? explode( ",", $membership ) : $membership; 1068 1071 1072 // Get the membership hierarchy. 1069 1073 $membership_array = $this->get_membership_stack( $membership_array ); 1070 1071 // Current user or requested user. 1072 $user_id = ( ! $user_id ) ? get_current_user_id() : $user_id; 1073 1074 // Load user memberships array. 1075 $memberships = ( false == $user_id ) ? $this->access : wpmem_get_user_memberships( $user_id ); 1074 1075 // What memberships does the user have?. 1076 $memberships = wpmem_get_user_memberships( $user_id ); 1076 1077 1077 1078 // Start by assuming no access. 1078 $access = false;1079 1080 // Start checking memberships. If the user has a valid membership, quit checking.1079 $access = false; 1080 1081 // Start checking memberships. If a valid membership is found, quit checking (break). 1081 1082 foreach ( $membership_array as $prod ) { 1082 $expiration_product = false; 1083 $role_product = false; 1083 1084 1084 // Does the user have this membership? 1085 1085 if ( isset( $memberships[ $prod ] ) ) { 1086 // Is this an expiration membership? 1087 if ( isset( $wpmem->membership->memberships[ $prod ]['expires'][0] ) && ! is_bool( $memberships[ $prod ] ) ) { 1088 $expiration_product = true; 1086 // Is this a role membership? 1087 if ( wpmem_get_membership_role( $prod ) ) { 1088 // Does user have the required role? 1089 if ( wpmem_user_has_role( wpmem_get_membership_role( $prod ) ) ) { 1090 // Is it an expiration membership? If not, they're OK at this point. 1091 if ( ! $expiration_product ) { 1092 $access = true; 1093 break; 1094 } else { 1095 // If an expiration membership, is the user current? 1096 if ( $this->is_current( $memberships[ $prod ] ) ) { 1097 $access = true; 1098 break; 1099 } 1100 } 1101 } 1102 } elseif ( wpmem_is_membership_expirable( $prod ) ) { 1103 // If an expiration membership, is the user current? 1089 1104 if ( $this->is_current( $memberships[ $prod ] ) ) { 1090 1105 $access = true; 1091 1106 break; 1092 } 1093 } 1094 // Is this a role membership? 1095 if ( '' != wpmem_get_membership_role( $prod ) ) { 1096 $role_product = true; 1097 if ( $memberships[ $prod ] && wpmem_user_has_role( wpmem_get_membership_role( $prod ) ) ) { 1098 if ( $expiration_product && ! $this->is_current( $memberships[ $prod ] ) ) { 1099 $access = false; 1100 break; 1101 } 1102 $access = true; 1103 break; 1104 } 1105 } 1106 if ( ! $expiration_product && ! $role_product && $memberships[ $prod ] ) { 1107 } 1108 } else { 1109 // No required role, no expiry, and user has membership. 1107 1110 $access = true; 1108 1111 break; -
wp-members/trunk/includes/class-wp-members.php
r3368566 r3383669 1607 1607 */ 1608 1608 public function do_loginout_script() { 1609 $logout = wpmem_logout_link(); 1610 ?><script type="text/javascript"> 1611 jQuery('.wpmem_loginout').html('<a class="login_button" href="<?php echo esc_url( $logout ); ?>"><?php echo wpmem_get_text( 'menu_logout' ); ?></a>'); 1609 $logout = wpmem_logout_link(); ?> 1610 <script type="text/javascript"> 1611 jQuery(document).ready(function() { 1612 jQuery('.wpmem_loginout').html('<a class="login_button" href="<?php echo esc_url( $logout ); ?>"><?php echo wpmem_get_text( 'menu_logout' ); ?></a>'); 1613 }); 1612 1614 </script><?php 1613 1615 } … … 1965 1967 } 1966 1968 1969 /** 1970 * Loads the activation object if enabled. 1971 * 1972 * @since Unknown 1973 * 1974 * @todo Can this be evaluated for loading based only when specifically 1975 * needed for the actual processed used? 1976 * @todo Apart from the above, can this load at load_dependent_classes()? 1977 */ 1967 1978 public function after_wpmem_loaded() { 1968 1979 if ( wpmem_is_enabled( 'act_link' ) ) { -
wp-members/trunk/includes/cli/class-wp-members-cli-user.php
r3308067 r3383669 151 151 * ## OPTIONS 152 152 * 153 * <pending|activated|deactivated|confirmed|unconfirmed >153 * <pending|activated|deactivated|confirmed|unconfirmed|memberships> 154 154 * : status of the user 155 * 156 * [--id=<user_id>] 157 * : User ID if listing memberships. 155 158 * 156 159 * @subcommand list … … 161 164 162 165 // Accepted list args. 163 $accepted = array( 'pending', 'activated', 'deactivated', 'confirmed', 'unconfirmed' );166 $accepted = array( 'pending', 'activated', 'deactivated', 'confirmed', 'unconfirmed', 'memberships', 'membership' ); 164 167 165 168 $status = $args[0]; 169 170 if ( ( 'memberships' == $status || 'membership' == $status ) && ! isset( $assoc_args['id'] ) ) { 171 WP_CLI::error( 'Listing user memberships requires a user ID as [--id]' ); 172 } 173 166 174 switch ( $status ) { 167 175 case 'pending': … … 180 188 $users = wpmem_get_users_by_meta( '_wpmem_user_confirmed', false ); 181 189 break; 182 } 183 184 if ( ! empty( $users ) ) { 185 foreach ( $users as $user_id ) { 186 $user = get_userdata( $user_id ); 187 $list[] = array( 188 'ID' => $user->ID, 189 'username' => $user->user_login, 190 'email' => $user->user_email, 191 'status' => $status, 190 case 'memberships': 191 case 'membership': 192 $user_id = $assoc_args['id']; 193 $memberships = wpmem_get_user_memberships( $user_id ); 194 break; 195 } 196 197 if ( 'memberships' == $status || 'membership' == $status ) { 198 199 foreach ( $memberships as $key => $time ) { 200 201 $expires = rktgk_format_date( $time ); 202 $days_to_go = wpmem_get_user_time_remaining( $key, $user_id ); 203 204 $list[] = array( 205 'membership' => wpmem_get_membership_name( $key ), 206 'meta' => $key, 207 'expires' => $expires, 208 'remaining' => $days_to_go . ' days', 192 209 ); 193 210 } 194 195 $formatter = new \WP_CLI\Formatter( $assoc_args, array( ' ID', 'username', 'email', 'status' ) );211 212 $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'membership', 'meta', 'expires', 'remaining' ) ); 196 213 $formatter->display_items( $list ); 214 197 215 } else { 198 WP_CLI::line( sprintf( 'Currently there are no %s users.', $status ) ); 216 217 if ( ! empty( $users ) ) { 218 foreach ( $users as $user_id ) { 219 $user = get_userdata( $user_id ); 220 $list[] = array( 221 'ID' => $user->ID, 222 'username' => $user->user_login, 223 'email' => $user->user_email, 224 'status' => $status, 225 ); 226 } 227 228 $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'ID', 'username', 'email', 'status' ) ); 229 $formatter->display_items( $list ); 230 } else { 231 WP_CLI::line( sprintf( 'Currently there are no %s users.', $status ) ); 232 } 199 233 } 200 234 } … … 405 439 406 440 /** 441 * Displays a given users expiration date for a specific membership. 442 * 443 * --membership=<meta_key> 444 * : The membership to check. 445 * 446 * --id=<user_id> 447 * : The user ID to check. 448 * 449 * [--format=<date_format>] 450 * : Date format to display (defaults to WP date format setting). 451 */ 452 public function expires( $args, $assoc_args ) { 453 $product_key = $assoc_args['membership']; 454 $user_id = $assoc_args['id']; 455 $format = ( isset( $assoc_args['format'] ) ) ? $assoc_args['format'] : get_option( 'date_format' ); 456 $expires = wpmem_get_user_expiration( $product_key, $user_id, $format ); 457 WP_CLI::line( sprintf( 'User membership for %s expires %s.', wpmem_get_membership_name( $product_key ), $expires ) ); 458 } 459 460 /** 461 * Displays the user's remaining time for a specific membership. 462 * 463 * --membership=<meta_key> 464 * : The membership to check. 465 * 466 * --id=<user_id> 467 * : The user ID to check. 468 * 469 * [--interval=<days|months>] 470 * : Date interval displayed as result (defaults to "days"). 471 */ 472 public function remaining( $args, $assoc_args ) { 473 $product_key = $assoc_args['membership']; 474 $user_id = $assoc_args['id']; 475 $interval = ( isset( $assoc_args['interval'] ) ) ? $interval : 'days'; 476 $remaining = wpmem_get_user_time_remaining( $product_key, $user_id, $interval ); 477 WP_CLI::line( sprintf( 'User %s has %s %s remaining for %s.', $user_id, $remaining, $interval, wpmem_get_membership_name( $product_key ) ) ); 478 } 479 480 /** 481 * Gets prorated value of user's remaining time for a specific membership. 482 * 483 * --membership=<meta_key> 484 * : The membership to check. 485 * 486 * --id=<user_id> 487 * : The user ID to check. 488 * 489 * --value=<price> 490 * : The full value of the membership to prorate. 491 * 492 * [--interval=<days|months>] 493 * : Date interval displayed as result (defaults to "days"). 494 */ 495 public function prorate( $args, $assoc_args ) { 496 $product_key = $assoc_args['membership']; 497 $user_id = $assoc_args['id']; 498 $value = $assoc_args['value']; 499 $interval = ( isset( $assoc_args['interval'] ) ) ? $assoc_args['interval'] : 'days'; 500 $val_remaining = wpmem_prorate_membership( $product_key, $user_id, $value, $interval ); 501 WP_CLI::line( sprintf( 'Remaining value of %s for user ID %s is %s', wpmem_get_membership_name( $product_key ), $user_id, round( $val_remaining, 2 ) ) ); 502 } 503 504 /** 407 505 * Handles user detail display. 408 506 * -
wp-members/trunk/readme.txt
r3368568 r3383669 139 139 * Add sorting to [wpmem_user_membership_posts] shortcode. 140 140 * Add sorting arguments to `wpmem_get_membership_post_list()` function. 141 * Add date format support for `wpmem_get_user_expiration()` function. 141 142 * Add `wpmem_show_membership_posts_sc_list_item` filter for [wpmem_user_membership_posts] shortcode output. 143 * Add `wpmem_is_user_deactivated()` API function. 144 * Add `wpmem_get_user_time_remaining()` API function to check for remaining time on memberships. 145 * Add WP CLI command for checking remaining time on memberships. 146 * Add WP CLI command for listing user memberships. 147 * Update `wpmem_get_membership_role()` to return false (rather than null) if no role for the membership. 142 148 * Code improvement to consolidate `wpmem_logout_link` filter instances into `wpmem_logout_link()` function. 149 * Code improvement in `has_access()` logic with better handling of role-based memberships. 143 150 * Security patches from 3.5.4.1, 3.5.4.2, and 3.4.5.3. 144 151 -
wp-members/trunk/wp-members.php
r3368566 r3383669 4 4 Plugin URI: https://rocketgeek.com 5 5 Description: WP access restriction and user registration. For more information on plugin features, refer to <a href="https://rocketgeek.com/plugins/wp-members/docs/">the online Users Guide</a>. A <a href="https://rocketgeek.com/plugins/wp-members/quick-start-guide/">Quick Start Guide</a> is also available. WP-Members(tm) is a trademark of butlerblog.com. 6 Version: 3.5.5.b. 16 Version: 3.5.5.b.2 7 7 Author: Chad Butler 8 8 Author URI: https://butlerblog.com/ … … 59 59 60 60 // Initialize constants. 61 define( 'WPMEM_VERSION', '3.5.5 beta rc 1' );61 define( 'WPMEM_VERSION', '3.5.5 beta rc 2' ); 62 62 define( 'WPMEM_DB_VERSION', '2.4.3' ); 63 63 define( 'WPMEM_PATH', plugin_dir_path( __FILE__ ) ); // @todo Fairly certain this is obsolete.
Note: See TracChangeset
for help on using the changeset viewer.