From ea4357ae823988b2e725aa9f7e66c9c32209a7ec Mon Sep 17 00:00:00 2001 From: smitpatelx Date: Wed, 25 Oct 2023 17:46:13 -0500 Subject: [PATCH 1/7] RUS_ADMIN_CAPABILITY added. --- constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.php b/constants.php index d178ca1..8915ddd 100644 --- a/constants.php +++ b/constants.php @@ -22,6 +22,7 @@ private function define_rus_constants(){ define('RUS_DIRECTORY', __DIR__); define('RUS_WP_CURRENT_VERSION', $wp_version); define('RUS_CAPABILITY', 'robust_user_search'); + define('RUS_ADMIN_CAPABILITY', 'manage_options'); define('RUS_MENU_ICON_URL', plugins_url('/assets/robust_teal.svg', __FILE__)); define('RUS_FAVICON_URL', plugins_url('/dist/favicon.ico', __FILE__)); From c14eb914d0a9b81e26663fdef68b3642ffcdb8d6 Mon Sep 17 00:00:00 2001 From: smitpatelx Date: Wed, 25 Oct 2023 17:46:30 -0500 Subject: [PATCH 2/7] Readme package version updated. --- readme.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 02f3d2b..9b8569d 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://apps.smitpatelx.com/donate Tags: Ajax, Axios, Robust Search, User Management, Edit User, Update, smitpatelx, Vue, WooCommerce, Axios Requires at least: 5.2 Tested up to: 6.3.2 -Stable tag: 1.1.0 +Stable tag: 1.1.1 License: GPLv2 A comprehensive, user-friendly, live user search & edit plugin for your site. @@ -111,6 +111,10 @@ None == Changelog == += 1.1.1 = +- Fixed SQL script for searching by first name, last name and business name. +- Fixed empty first and last name field when its empty. + = 1.1.0 = - Major next release. - Rewrite using Typescript & Vue 3.3. From 1ab9b62f2cfbba66da56f4cb9c661949515465f2 Mon Sep 17 00:00:00 2001 From: smitpatelx Date: Wed, 25 Oct 2023 17:47:01 -0500 Subject: [PATCH 3/7] Version in main filed bumped. Fixed imports. --- robust-user-search.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/robust-user-search.php b/robust-user-search.php index ce3ade0..e7be469 100644 --- a/robust-user-search.php +++ b/robust-user-search.php @@ -6,7 +6,7 @@ * Text Domain: robust-user-search * Author: Smit Patel * Author URI: https://smitpatelx.com - * Version: 1.1.0 + * Version: 1.1.1 * Requires at least: 5.2 * Requires PHP: 7.1 * License: gpl-v2-only @@ -72,8 +72,8 @@ protected function checkWpVersion(){ protected function includingFile(){ require_once(__DIR__."/constants.php"); - require_once(__DIR__.'/helper/Helper.php'); - require_once(__DIR__.'/helper/Validation.php'); + require_once(__DIR__.'/helper/helper.php'); + require_once(__DIR__.'/helper/validation.php'); require_once(__DIR__.'/includes/activation.php'); require_once(__DIR__.'/includes/deactivate.php'); From 2600ea9cfc72cdbfc935c1b7c176e3d902dc224d Mon Sep 17 00:00:00 2001 From: smitpatelx Date: Wed, 25 Oct 2023 17:49:00 -0500 Subject: [PATCH 4/7] Role filter query fixed for list-all-users. --- api/list-all-users.php | 120 +++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 35 deletions(-) diff --git a/api/list-all-users.php b/api/list-all-users.php index fb6d3c9..fa6111c 100644 --- a/api/list-all-users.php +++ b/api/list-all-users.php @@ -59,24 +59,42 @@ function processRequest(\WP_REST_Request $request){ $search_text = self::filterNull($search_text); $role = self::filterNull($role); - $sql_on = " - t1.ID = t2.user_id - AND (t2.meta_value LIKE '%$role%' AND t2.meta_key = 'wp_capabilities') - "; + if (trim($role) == '') { + $sql_on = " + t1.ID = t2.user_id + "; + $sql_on_2 = " + t1.ID = t3.user_id + AND t3.meta_value LIKE '%$search_text%' + "; + } else { + $sql_on = " + t1.ID = t2.user_id + AND t2.meta_value LIKE '%$search_text%' + "; + $sql_on_2 = " + t1.ID = t3.user_id + AND (t3.meta_key = 'wp_capabilities' + AND t3.meta_value LIKE '%$role%') + "; + } $sql_where = " t1.user_login LIKE '%$search_text%' OR t1.user_email LIKE '%$search_text%' OR t1.user_nicename LIKE '%$search_text%' OR t1.display_name LIKE '%$search_text%' + OR t2.meta_value LIKE '%$search_text%' "; $sql = " SELECT * FROM {$wpdb->users} as t1 INNER JOIN {$wpdb->usermeta} as t2 ON ($sql_on) + INNER JOIN {$wpdb->usermeta} as t3 + ON ($sql_on_2) WHERE $sql_where - GROUP BY t2.user_id + GROUP BY t2.user_id, t3.user_id, t1.user_login ORDER BY $sort_by $sort_order LIMIT $offset, $page_size "; @@ -88,9 +106,11 @@ function processRequest(\WP_REST_Request $request){ SELECT COUNT(*) FROM {$wpdb->users} as t1 INNER JOIN {$wpdb->usermeta} as t2 ON ($sql_on) + INNER JOIN {$wpdb->usermeta} as t3 + ON ($sql_on_2) WHERE $sql_where - GROUP BY t2.user_id + GROUP BY t2.user_id, t3.user_id, t1.user_login "; $total_count_result = count($wpdb->get_results($sql_for_total_count)); @@ -98,43 +118,73 @@ function processRequest(\WP_REST_Request $request){ $DBRecord['page'] = (int) $page; $DBRecord['page_size'] = (int) $page_size; $DBRecord['users'] = array(); - $i=0; - foreach ( $users as $user ) + // var_dump($users); + foreach ($users as $user) { $record = array(); - $record['roles'] = self::filterNull($user->roles); - $record['username'] = self::filterNull($user->user_login); - $record['id'] = self::filterNull($user->ID); - $record['user_registered'] = self::filterNull($user->user_registered); - $record['email'] = self::filterNull($user->user_email); - - $UserData = get_user_meta( $user->ID ); + $record['username'] = self::filterNull($user->user_login); + $record['id'] = self::filterNull($user->ID); + $record['user_registered'] = self::filterNull($user->user_registered); + $record['email'] = self::filterNull($user->user_email); + + $user_data = get_user_meta($user->ID); - // https://regex101.com/library/3q3RYF - smit - // a:1:{s:11:"contributor";b:1;} ==to==> ["contributor"] - $re = '/"([^"]+)"/'; - preg_match_all($re, $user->meta_value, $matches, PREG_SET_ORDER, 0); - if ($matches) { - $record['roles'] = []; - foreach ($matches as $key => $value) { - array_push($record['roles'], $value[1]); + $record['roles'] = self::extract_roles_from_meta_value($user_data['wp_capabilities']); + $record['first_name'] = self::filterNullFirst($user_data['first_name']); + $record['last_name'] = self::filterNullFirst($user_data['last_name']); + $record['billing_company'] = self::filterNullFirst($user_data['billing_company']); + $record['billing_address_1'] = self::filterNullFirst($user_data['billing_address_1']); + $record['billing_city'] = self::filterNullFirst($user_data['billing_city']); + $record['billing_state'] = self::filterNullFirst($user_data['billing_state']); + $record['billing_postcode'] = self::filterNullFirst($user_data['billing_postcode']); + $record['billing_country'] = self::filterNullFirst($user_data['billing_country']); + $record['billing_phone'] = self::filterNullFirst($user_data['billing_phone']); + array_push($DBRecord['users'], $record); + } + return new \WP_REST_Response($DBRecord, 200); + } + + /** + * Check if meta_value is array or not and extract roles from it + * + * @param string $meta_value + * @return string[] $roles + */ + protected function extract_roles_from_meta_value($meta_value) { + $roles = []; + + if (!is_array($meta_value)) { + return self::match_role($roles); + } else { + foreach ($meta_value as $value) { + $role = self::match_role($value); + if (!empty($role)) { + array_push($roles, $role); } } + } - $record['first_name'] = self::filterNullFirst($UserData['first_name']); - $record['last_name'] = self::filterNullFirst($UserData['last_name']); - $record['billing_company'] = self::filterNullFirst($UserData['billing_company']); - $record['billing_address_1'] = self::filterNullFirst($UserData['billing_address_1']); - $record['billing_city'] = self::filterNullFirst($UserData['billing_city']); - $record['billing_state'] = self::filterNullFirst($UserData['billing_state']); - $record['billing_postcode'] = self::filterNullFirst($UserData['billing_postcode']); - $record['billing_country'] = self::filterNullFirst($UserData['billing_country']); - $record['billing_phone'] = self::filterNullFirst($UserData['billing_phone']); - $DBRecord['users'][$i] = $record; - $i++; + return $roles; + } + + /** + * Extract role from meta_value + * + * @param string $meta_value + * @return string "" + */ + protected function match_role($meta_value) { + // https://regex101.com/library/3q3RYF - smit + // a:1:{s:11:"contributor";b:1;} ==to==> ["contributor"] + $re = '/"([^"]+)"/'; + $matches = NULL; + preg_match_all($re, $meta_value, $matches, PREG_SET_ORDER, 0); + if (!empty($matches) && is_array($matches) && !is_null($matches)) { + foreach ($matches as $value) { + return $value[1]; + } } - return new \WP_REST_Response($DBRecord, 200); } /** From e688eea991b6b224725a2ee78a4eec7db9e56100 Mon Sep 17 00:00:00 2001 From: smitpatelx Date: Wed, 25 Oct 2023 17:50:07 -0500 Subject: [PATCH 5/7] Vue mount id fixed. Javascript bundle updated. --- controller/index.php | 2 +- dist/assets/index.css | 2 +- dist/assets/index.js | 2 +- dist/css/app.css | 1 + dist/js/app.js | 2 ++ dist/js/app.js.LICENSE.txt | 14 ++++++++++++++ dist/js/manifest.js | 1 + dist/js/vendor.js | 2 ++ dist/js/vendor.js.LICENSE.txt | 5 +++++ 9 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 dist/css/app.css create mode 100644 dist/js/app.js create mode 100644 dist/js/app.js.LICENSE.txt create mode 100644 dist/js/manifest.js create mode 100644 dist/js/vendor.js create mode 100644 dist/js/vendor.js.LICENSE.txt diff --git a/controller/index.php b/controller/index.php index 70837e5..03eddaa 100644 --- a/controller/index.php +++ b/controller/index.php @@ -89,7 +89,7 @@ public function indexOutput() { echo wp_kses('
-
+