From b72ee73172f6168d9071745e214be3e50e21ed53 Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Fri, 27 Nov 2015 11:21:48 +1000 Subject: [PATCH 1/3] Simplify Author object --- classes/class-author.php | 28 ++-------------------------- classes/class-list-table.php | 10 +++++++++- tests/tests/test-class-author.php | 4 ---- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/classes/class-author.php b/classes/class-author.php index ae6d29f6a..6b9608ca1 100644 --- a/classes/class-author.php +++ b/classes/class-author.php @@ -2,12 +2,6 @@ namespace WP_Stream; class Author { - /** - * Hold Plugin class - * @var Plugin - */ - public $plugin; - /** * @var int */ @@ -36,8 +30,6 @@ function __construct( $user_id, $user_meta = array() ) { if ( $this->id ) { $this->user = new \WP_User( $this->id ); } - - $this->plugin = wp_stream_get_instance(); } /** @@ -129,7 +121,8 @@ function get_avatar_img( $size = 80 ) { } if ( 0 === $this->id ) { - $url = $this->plugin->locations['url'] . 'ui/stream-icons/wp-cli.png'; + $stream = wp_stream_get_instance(); + $url = $stream->locations['url'] . 'ui/stream-icons/wp-cli.png'; $avatar = sprintf( '%1$s', esc_attr( $this->get_display_name() ), esc_url( $url ), esc_attr( $size ) ); } else { if ( $this->is_deleted() && isset( $this->meta['user_email'] ) ) { @@ -193,23 +186,6 @@ function get_role() { return $user_role; } - /** - * Construct a URL for viewing user-specific records - * - * @return string - */ - function get_records_page_url() { - $url = add_query_arg( - array( - 'page' => $this->plugin->admin->records_page_slug, - 'user_id' => absint( $this->id ), - ), - self_admin_url( $this->plugin->admin->admin_parent_page ) - ); - - return $url; - } - /** * True if user no longer exists, otherwise false * diff --git a/classes/class-list-table.php b/classes/class-list-table.php index e57680820..430604312 100644 --- a/classes/class-list-table.php +++ b/classes/class-list-table.php @@ -257,9 +257,17 @@ function column_default( $item, $column_name ) { case 'user_id' : $user = new Author( (int) $record->user_id, (array) maybe_unserialize( $record->user_meta ) ); + $filtered_records_url = add_query_arg( + array( + 'page' => $this->plugin->admin->records_page_slug, + 'user_id' => absint( $user->id ), + ), + self_admin_url( $this->plugin->admin->admin_parent_page ) + ); + $out = sprintf( '%s %s%s%s%s', - $user->get_records_page_url(), + $filtered_records_url, $user->get_avatar_img( 80 ), $user->get_display_name(), $user->is_deleted() ? sprintf( '
%s', esc_html__( 'Deleted User', 'stream' ) ) : '', diff --git a/tests/tests/test-class-author.php b/tests/tests/test-class-author.php index 9190598c2..03fb17d7e 100644 --- a/tests/tests/test-class-author.php +++ b/tests/tests/test-class-author.php @@ -75,10 +75,6 @@ public function test_get_role() { $this->assertEquals( 'Administrator', $this->author->get_role() ); } - public function test_get_records_page_url() { - $this->assertNotFalse( parse_url( $this->author->get_records_page_url() ) ); - } - public function test_is_deleted() { $this->assertFalse( $this->author->is_deleted() ); } From e5e0162b016f2e514368528b17dd22221fcc50f7 Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Fri, 27 Nov 2015 11:22:10 +1000 Subject: [PATCH 2/3] Fix incorrect GROUP BY query by changing it to DISTINCT --- classes/class-db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/class-db.php b/classes/class-db.php index 8305536ef..2d493cb71 100644 --- a/classes/class-db.php +++ b/classes/class-db.php @@ -187,7 +187,7 @@ function existing_records( $column ) { } $rows = $wpdb->get_results( - $wpdb->prepare( "SELECT $column FROM $wpdb->stream GROUP BY %s", $column ), // @codingStandardsIgnoreLine can't prepare column name + "SELECT DISTINCT $column FROM $wpdb->stream", // @codingStandardsIgnoreLine can't prepare column name 'ARRAY_A' ); From 2da3a3c0af36ec9b7678e26e0a57b0c34b252bed Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Fri, 27 Nov 2015 11:29:51 +1000 Subject: [PATCH 3/3] Update out of date unit test --- tests/tests/test-class-author.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests/test-class-author.php b/tests/tests/test-class-author.php index 03fb17d7e..5918f0dae 100644 --- a/tests/tests/test-class-author.php +++ b/tests/tests/test-class-author.php @@ -35,7 +35,6 @@ public function test_construct() { $this->assertNotEmpty( $this->author->id ); $this->assertInternalType( 'array', $this->author->meta ); $this->assertNotEmpty( $this->author->meta ); - $this->assertInstanceOf( '\WP_Stream\Plugin', $this->author->plugin ); } public function test_get() {