comment-meta.php
6 years ago
comment.php
5 years ago
meta.php
5 years ago
options.php
5 years ago
post-meta.php
6 years ago
post.php
5 years ago
user-meta.php
6 years ago
user.php
5 years ago
user.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex; |
| 4 | |
| 5 | use SearchRegex\Search_Source; |
| 6 | use SearchRegex\Result; |
| 7 | |
| 8 | /** |
| 9 | * User source |
| 10 | */ |
| 11 | class Source_User extends Search_Source { |
| 12 | /** |
| 13 | * Return an array of columns for this source |
| 14 | * |
| 15 | * @return Array The array of column names |
| 16 | */ |
| 17 | public function get_columns() { |
| 18 | $columns = [ |
| 19 | 'user_nicename', |
| 20 | 'user_url', |
| 21 | 'display_name', |
| 22 | ]; |
| 23 | |
| 24 | return $columns; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Return a visible label for the column. This is shown to the user and should be more descriptive than the column name itself |
| 29 | * |
| 30 | * @param String $column Column name. |
| 31 | * @return String Column label |
| 32 | */ |
| 33 | public function get_column_label( $column, $data ) { |
| 34 | $labels = [ |
| 35 | 'user_nicename' => __( 'Nicename', 'search-regex' ), |
| 36 | 'user_url' => __( 'URL', 'search-regex' ), |
| 37 | 'display_name' => __( 'Display name', 'search-regex' ), |
| 38 | ]; |
| 39 | |
| 40 | if ( isset( $labels[ $column ] ) ) { |
| 41 | return $labels[ $column ]; |
| 42 | } |
| 43 | |
| 44 | return $column; |
| 45 | } |
| 46 | |
| 47 | public function get_table_id() { |
| 48 | return 'ID'; |
| 49 | } |
| 50 | |
| 51 | public function get_table_name() { |
| 52 | global $wpdb; |
| 53 | |
| 54 | return $wpdb->users; |
| 55 | } |
| 56 | |
| 57 | public function get_actions( Result $result ) { |
| 58 | return [ |
| 59 | 'edit' => get_edit_profile_url( $result->get_row_id(), 'admin' ), |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | public function get_title_column() { |
| 64 | return 'user_nicename'; |
| 65 | } |
| 66 | |
| 67 | public function save( $row_id, $column_id, $content ) { |
| 68 | // This does all the sanitization |
| 69 | $result = wp_update_user( [ |
| 70 | 'ID' => $row_id, |
| 71 | $column_id => $content, |
| 72 | ] ); |
| 73 | |
| 74 | if ( $result ) { |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return new \WP_Error( 'searchregex', 'Failed to update user' ); |
| 79 | } |
| 80 | |
| 81 | public function delete_row( $row_id ) { |
| 82 | if ( wp_delete_user( $row_id ) ) { |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | return new \WP_Error( 'searchregex_delete', 'Failed to delete user', 401 ); |
| 87 | } |
| 88 | } |
| 89 |