Changeset 2908629
- Timestamp:
- 05/05/2023 04:11:25 PM (3 years ago)
- Location:
- user-toolkit/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (5 diffs)
-
src/RestEndpoints.php (modified) (2 diffs)
-
user-toolkit.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
user-toolkit/trunk/README.txt
r2876129 r2908629 4 4 Tags: user profile, last login, disable user, registration date 5 5 Requires at least: 5.9.5 6 Tested up to: 6. 16 Tested up to: 6.2 7 7 Requires PHP: 7.3 8 Stable tag: 1.2 8 Stable tag: 1.2.1 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 31 31 Full support for administration over SSL (if applicable). 32 32 33 ** REST API Support ** 34 35 The field last_login is included as a result in endpoint wp/v2/users/. 36 Filtering the endpoint wp/v2/users/ using parameter last_login is also supported. 37 33 38 ## USAGE 34 39 … … 52 57 2. Disable all or any column clicking "Screen Options" on the right top corner of the screen. 53 58 59 ** Retrieve Last Login info using REST API ** 60 61 1. Get last_login field with ISO 8601 form on endpoint wp/v2/users/ 62 2. Filter using parameter last_login using the following options wp/v2/users/?last_login=FROM,[TO:optional] using ISO 8601 or Y-m-d format. 54 63 55 64 ## PRIVACY STATEMENT … … 84 93 85 94 == Changelog == 95 96 = 1.2.1 = 97 * Added last_login as a filter parameter in user endpoint. 86 98 87 99 = 1.2 = … … 122 134 == Upgrade Notice == 123 135 136 = 1.2.1 = 137 * Added last_login as a filter parameter in user endpoint. 138 124 139 = 1.2 = 125 140 * Last Login date is now filterable in User List -
user-toolkit/trunk/src/RestEndpoints.php
r2876117 r2908629 12 12 add_action( 'rest_api_init', [ $this, 'registerCanLoginField' ] ); 13 13 add_action( 'rest_api_init', [ $this, 'registerLastLoginField' ] ); 14 add_filter( 'rest_user_collection_params', [ $this, 'registerParams' ] ); 15 add_filter( 'rest_user_query', [ $this, 'filterByParams' ], 10, 2 ); 14 16 } 15 17 … … 76 78 } 77 79 80 public function registerParams( $params ) { 81 $params['last_login'] = [ 82 'description' => 'Last login range', 83 'type' => 'string', 84 ]; 85 86 return $params; 87 } 88 89 public function filterByParams( $prepared_args, \WP_REST_Request $request ) { 90 $last_login = $request->get_param( 'last_login' ); 91 if ( ! empty( $last_login ) ) { 92 93 $last_login_range = explode( ',', $last_login ); 94 95 if ( count( $last_login_range ) === 1 ) { 96 $last_login_range[1] = date( 'Y-m-d\TH:i:s', strtotime( 'now' ) ); 97 } 98 99 $last_login_args = array_map( function ( $date ) { 100 return strtotime( $date ); 101 }, $last_login_range ); 102 103 $prepared_args['meta_query'] = [ 104 [ 105 'key' => 'last_login', 106 'value' => $last_login_args, 107 'compare' => 'BETWEEN', 108 ], 109 ]; 110 } 111 112 return $prepared_args; 113 } 114 78 115 79 116 } -
user-toolkit/trunk/user-toolkit.php
r2876117 r2908629 9 9 * Plugin URI: https://deryckoe.com/user-toolkit 10 10 * Description: The missing user tools and activity data that you need and don't have by default. 11 * Version: 1.2 11 * Version: 1.2.1 12 12 * Author: Deryck Oñate 13 13 * Author URI: http://deryckoe.com
Note: See TracChangeset
for help on using the changeset viewer.