From 461e0ca70af0d83e845c26b99bc164a6fe6934d6 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 12 May 2016 11:28:36 +0100 Subject: [PATCH 001/231] Sync helper from wpcom --- wpcom-helper.php | 227 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 wpcom-helper.php diff --git a/wpcom-helper.php b/wpcom-helper.php new file mode 100644 index 00000000..0e9c6cff --- /dev/null +++ b/wpcom-helper.php @@ -0,0 +1,227 @@ +is_enabled() && ! in_array( get_option( 'template' ), $wpcom_coauthors_plus_auto_apply_themes ) ) + add_action( 'admin_notices', function() { + + // Allow this to be short-circuted in mu-plugins + if ( ! apply_filters( 'wpcom_coauthors_show_enterprise_notice', true ) ) + return; + + echo '

' . __( "Co-Authors Plus isn't yet integrated with your theme. Please contact support to make it happen." ) . '

'; + } ); +} + +/** + * We want to let Elasticsearch know that it should search the author taxonomy's name as a search field + * See: https://elasticsearchp2.wordpress.com/2015/01/08/in-36757-z-vanguard-says-they/ + * + * @param $es_wp_query_args The ElasticSearch Query Parameters + * @param $query + * + * @return mixed + */ +function co_author_plus_es_support( $es_wp_query_args, $query ){ + if ( empty( $es_wp_query_args['query_fields'] ) ) { + $es_wp_query_args['query_fields'] = array( 'title', 'content', 'author', 'tag', 'category' ); + } + + // Search CAP author names + $es_wp_query_args['query_fields'][] = 'taxonomy.author.name'; + + // Filter based on CAP names + if ( !empty( $query->query['author'] ) ) { + $es_wp_query_args['terms']['author'] = 'cap-' . $query->query['author']; + } + + return $es_wp_query_args; +} +add_filter('wpcom_elasticsearch_wp_query_args', 'co_author_plus_es_support', 10, 2 ); + + +/** + * Change the post authors in the subscription email. + * + * Creates an array of authors, that will be used later. + * + * @param $author WP_User the original author + * @param $post_id + * + * @return array of coauthors + */ +add_filter( 'wpcom_subscriber_email_author', function( $author, $post_id ) { + + $authors = get_coauthors( $post_id ); + return $authors; + +}, 10, 2 ); + +/** + * Change the author avatar url. If there are multiple authors, link the avatar to the post. + * + * @param $author_url + * @param $post_id + * @param $authors + * + * @return string with new author url. + */ +add_filter( 'wpcom_subscriber_email_author_url', function( $author_url, $post_id, $authors ) { + if( is_array( $authors ) ) { + if ( count( $authors ) > 1 ) { + return get_permalink( $post_id ); + } + + return get_author_posts_url( $authors[0]->ID, $authors[0]->user_nicename ); + } + + return get_author_posts_url( $authors->ID, $authors->user_nicename ); +}, 10, 3); + +/** + * Change the avatar to be the avatar of the first author + * + * @param $author_avatar + * @param $post_id + * @param $authors + * + * @return string with the html for the avatar + */ +add_filter( 'wpcom_subscriber_email_author_avatar', function( $author_avatar, $post_id, $authors ) { + if( is_array( $authors ) ) + return coauthors_get_avatar( $authors[0], 50 ); + + return coauthors_get_avatar( $authors, 50 ); +}, 10, 3); + +/** + * Changes the author byline in the subscription email to include all the authors of the post + * + * @param $author_byline + * @param $post_id + * @param $authors + * + * @return string with the byline html + */ +add_filter( 'wpcom_subscriber_email_author_byline_html', function( $author_byline, $post_id, $authors ) { + // Check if $authors is a valid array + if( ! is_array( $authors ) ) { + $authors = array( $authors ); + } + + $byline = 'by '; + foreach( $authors as $author ) { + $byline .= '' . esc_html( $author->display_name ) . ''; + if ( $author != end( $authors ) ) { + $byline .= ', '; + } + } + + return $byline; +}, 10, 3); + +/** + * Change the meta information to include all the authors + * + * @param $meta + * @param $post_id + * @param $authors + * + * @return array with new meta information + */ +add_filter( 'wpcom_subscriber_email_meta', function( $meta, $post_id, $authors ) { + // Check if $authors is a valid array + if( ! is_array( $authors ) ) { + $authors = array( $authors ); + } + + $author_meta = ''; + foreach( $authors as $author ) { + $author_meta .= '' . esc_html( $author->display_name ) . ''; + + if ( $author != end( $authors ) ) { + $author_meta .= ', '; + } + } + + // Only the first entry of meta includes the author listing + $meta[0] = $author_meta; + + return $meta; +}, 10, 3); + +/** + * Change the author information in the text-only subscription email. + * + * @param $author + * @param $post_id + * + * @returns string with the authors + */ +add_filter( 'wpcom_subscriber_text_email_author', function( $author, $post_id ) { + // Check if $authors is a valid array + $authors = get_coauthors( $post_id ); + + $author_text = ''; + foreach( $authors as $author ) { + $author_text .= esc_html( $author->display_name ); + if ( $author != end( $authors ) ) { + $author_text .= ', '; + } + } + + return $author_text; +}, 10, 2); + +/** + * Replace author_url in oembed endpoint response + * Since the oembed specification does not allow multiple urls, we'll go with the first coauthor + * + * The function is meant as a filter for `get_author_posts_url` function, which it is using as well + * Recursion is prevented by a simple check agains original attributes passed to the funciton. That + * also prevents execution in case the only coauthor is real author. + * + * This function is hooked only to oembed endpoint and it should stay that way + */ + +function wpcom_vip_cap_replace_author_link( $link, $author_id, $author_nicename ) { + + //get coauthors and iterate to the first one + //in case there are no coauthors, the Iterator returns current author + $i = new CoAuthorsIterator(); + $i->iterate(); + + //check if the current $author_id and $author_nicename is not the same as the first coauthor + if ( $i->current_author->ID !== $author_id || $i->current_author->user_nicename !== $author_nicename ) { + + //alter the author_url + $link = get_author_posts_url( $i->current_author->ID, $i->current_author->user_nicename ); + + } + + return $link; +} +//Hook the above callback only on oembed endpoint reply +if ( true === defined( 'WPCOM_VIP_IS_OEMBED' ) && true === constant( 'WPCOM_VIP_IS_OEMBED' ) && true === apply_filters( 'wpcom_vip_coauthors_replace_oembed', false, 'author_url' ) ) { + add_filter( 'author_link', 'wpcom_vip_cap_replace_author_link', 99, 3 ); +} From 581f21b7758007a6a2cf22f481d859fffe12bcb1 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 12 May 2016 11:37:39 +0100 Subject: [PATCH 002/231] Updating readme etc for v3.2 --- co-authors-plus.php | 2 +- readme.txt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 339184a9..94e9566f 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -3,7 +3,7 @@ Plugin Name: Co-Authors Plus Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/ Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter. -Version: 3.1.2 +Version: 3.2 Author: Mohammad Jangda, Daniel Bachhuber, Automattic Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter diff --git a/readme.txt b/readme.txt index 608d7e83..b805eee8 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Co-Authors Plus === Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.5 +Tested up to: 4.5.2 Requires at least: 4.1 -Stable tag: 3.1.1 +Stable tag: 3.2 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box @@ -57,6 +57,9 @@ Bug fixes and minor enhancements == Changelog == += 3.2 = +Various minor bug and security fixes + = 3.1.2 (Aug. 31, 2015) = * Minor bug fixes and coding standards changes. * The author's display name is now filtered through the_author in coauthors_posts_links_single() From 8b98ad049d19d96bec6a832b27a96ba7d5cabe0a Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Mon, 16 May 2016 16:48:30 -0400 Subject: [PATCH 003/231] Hotfix: closing tag being caught in esc_attr Props JS Morisset https://wordpress.org/support/topic/fyi-v452-typo-in-class-coauthors-guest-authorsphp --- php/class-coauthors-guest-authors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 90537899..7c0ec502 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -676,7 +676,7 @@ function metabox_manage_guest_author_bio() { $pm_key = $this->get_post_meta_key( $field['key'] ); $value = get_post_meta( $post->ID, $pm_key, true ); echo ''; - echo ''; + echo ''; echo ''; echo ''; echo ''; From 69f58e2b84927643fc382dba45d935f0477bbf7d Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Mon, 16 May 2016 16:53:24 -0400 Subject: [PATCH 004/231] Bump to 3.2.1 --- co-authors-plus.php | 4 ++-- readme.txt | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 94e9566f..fdb5ca76 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -3,7 +3,7 @@ Plugin Name: Co-Authors Plus Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/ Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter. -Version: 3.2 +Version: 3.2.1 Author: Mohammad Jangda, Daniel Bachhuber, Automattic Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter @@ -24,7 +24,7 @@ */ -define( 'COAUTHORS_PLUS_VERSION', '3.1.2' ); +define( 'COAUTHORS_PLUS_VERSION', '3.2.1' ); require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); diff --git a/readme.txt b/readme.txt index b805eee8..f4dd35d8 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing Tested up to: 4.5.2 Requires at least: 4.1 -Stable tag: 3.2 +Stable tag: 3.2.1 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box @@ -57,14 +57,15 @@ Bug fixes and minor enhancements == Changelog == -= 3.2 = += 3.2.1 (May 16, 2016) = +* Hotfix for broken Guest Author bio metabox (props JS Morisset) + += 3.2 (May 12, 2016) = Various minor bug and security fixes = 3.1.2 (Aug. 31, 2015) = * Minor bug fixes and coding standards changes. * The author's display name is now filtered through the_author in coauthors_posts_links_single() - -= ??? (??? ?? ????) = * New Russian and Ukrainian translations, courtesy of [Jurko Chervony](http://skinik.name/). = 3.1.1 (Mar. 20, 2014) = From 2742fcb12b50c0c7445f6db5a6aab3add5b4bf88 Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Tue, 17 May 2016 16:32:49 -0500 Subject: [PATCH 005/231] Better formatting for metabox_manage_guest_author_bio(), use printf instead of concatenating and echoing strings. --- php/class-coauthors-guest-authors.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 7c0ec502..5c322ed0 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -675,11 +675,21 @@ function metabox_manage_guest_author_bio() { foreach ( $fields as $field ) { $pm_key = $this->get_post_meta_key( $field['key'] ); $value = get_post_meta( $post->ID, $pm_key, true ); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + printf( ' + + + + + + + + + ', + esc_attr( $pm_key ), + esc_html( $field['label'] ), + esc_attr( $pm_key ), + esc_textarea( $value ) + ); } echo ''; From 1ca3ab7ccf5c09f662bea7030c6a50ba6894976d Mon Sep 17 00:00:00 2001 From: Rob Skilling Date: Fri, 24 Jun 2016 16:02:23 +0100 Subject: [PATCH 006/231] Fix no moderation email if guest author has no email address --- co-authors-plus.php | 1 + 1 file changed, 1 insertion(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index fdb5ca76..ddea5bb1 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1595,6 +1595,7 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i if ( isset( $post_id ) ) { $coauthors = get_coauthors( $post_id ); + $extra_recipients = array(); foreach ( $coauthors as $user ) { if ( ! empty( $user->user_email ) ) { $extra_recipients[] = $user->user_email; From e0b8abce254ea63f0288542e8c786a4c3783d454 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 19 Jul 2016 09:56:50 -0600 Subject: [PATCH 007/231] Update CLI to use cached functions --- php/class-wp-cli.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 8dcf1ee2..9b334317 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -76,7 +76,8 @@ public function create_terms_for_posts() { $count++; - $terms = wp_get_post_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy ); + $terms = get_the_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy ); + if ( is_wp_error( $terms ) ) { WP_CLI::error( $terms->get_error_message() ); } @@ -235,7 +236,7 @@ public function assign_user_to_coauthor( $args, $assoc_args ) { $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user->ID ) ); $affected = 0; foreach ( $posts as $post_id ) { - if ( $coauthors = wp_get_post_terms( $post_id, $coauthors_plus->coauthor_taxonomy ) ) { + if ( $coauthors = get_the_terms( $post_id, $coauthors_plus->coauthor_taxonomy ) ) { WP_CLI::line( sprintf( __( 'Skipping - Post #%d already has co-authors assigned: %s', 'co-authors-plus' ), $post_id, implode( ', ', wp_list_pluck( $coauthors, 'slug' ) ) ) ); continue; } @@ -544,8 +545,8 @@ public function list_posts_without_terms( $args, $assoc_args ) { while ( $posts->post_count ) { foreach ( $posts->posts as $single_post ) { - - $terms = wp_get_post_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy ); + + $terms = get_the_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy ); if ( empty( $terms ) ) { $saved = array( $single_post->ID, @@ -697,8 +698,8 @@ public function remove_terms_from_revisions() { WP_CLI::line( 'Found ' . count( $ids ) . ' revisions to look through' ); $affected = 0; foreach ( $ids as $post_id ) { - - $terms = wp_get_post_terms( $post_id, 'author' ); + + $terms = get_the_terms( $post_id, $coauthors_plus->coauthor_taxonomy ); if ( ! $terms ) { continue; } From a1b33754ae79fe4919bbbf2af9a87cf9b25d0a7c Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 17:16:28 -0400 Subject: [PATCH 008/231] Rename test to be more specific --- ...test-author-queries.php => test-author-queried-object.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{test-author-queries.php => test-author-queried-object.php} (95%) diff --git a/tests/test-author-queries.php b/tests/test-author-queried-object.php similarity index 95% rename from tests/test-author-queries.php rename to tests/test-author-queried-object.php index 2f6c1524..94e357f8 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queried-object.php @@ -3,7 +3,7 @@ * Test Co-Authors Plus' modifications of author queries */ -class Test_Author_Queries extends CoAuthorsPlus_TestCase { +class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase { /** * On author pages, the queried object should only be set @@ -12,7 +12,7 @@ class Test_Author_Queries extends CoAuthorsPlus_TestCase { * * @see https://core.trac.wordpress.org/changeset/27290 */ - function test_author_queried_object_fix() { + function test__author_queried_object_fix() { global $wp_rewrite, $coauthors_plus; /** From ba486a0a710d554f7e25f40df302b91637fab424 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 17:25:38 -0400 Subject: [PATCH 009/231] Move setup / teardown from base class to test Not really being used in other tests --- tests/coauthorsplus-testcase.php | 63 +------------------------------- tests/test-manage-coauthors.php | 51 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 62 deletions(-) diff --git a/tests/coauthorsplus-testcase.php b/tests/coauthorsplus-testcase.php index eb56cd81..f58d7878 100644 --- a/tests/coauthorsplus-testcase.php +++ b/tests/coauthorsplus-testcase.php @@ -3,65 +3,4 @@ /** * Base unit test class for Co-Authors Plus */ - -class CoAuthorsPlus_TestCase extends WP_UnitTestCase { - - protected $suppress = false; - - public function setUp() { - global $wpdb; - parent::setUp(); - $this->suppress = $wpdb->suppress_errors(); - - $_SERVER['REMOTE_ADDR'] = ''; - - $this->author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); - $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor2' ) ); - - $post = array( - 'post_author' => $this->author1, - 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), - 'post_type' => 'post', - ); - - $this->author1_post1 = wp_insert_post( $post ); - - $post = array( - 'post_author' => $this->author1, - 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), - 'post_type' => 'post', - ); - - $this->author1_post2 = wp_insert_post( $post ); - - $page = array( - 'post_author' => $this->author1, - 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), - 'post_type' => 'page', - ); - - $this->author1_page1 = wp_insert_post( $page ); - - $page = array( - 'post_author' => $this->author1, - 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), - 'post_type' => 'page', - ); - - $this->author1_page2 = wp_insert_post( $page ); - } - - public function tearDown() { - global $wpdb; - parent::tearDown(); - $wpdb->suppress_errors( $this->suppress ); - } -} +class CoAuthorsPlus_TestCase extends WP_UnitTestCase {} diff --git a/tests/test-manage-coauthors.php b/tests/test-manage-coauthors.php index 1f5b1945..fad2f9ca 100644 --- a/tests/test-manage-coauthors.php +++ b/tests/test-manage-coauthors.php @@ -2,6 +2,57 @@ class Test_Manage_CoAuthors extends CoAuthorsPlus_TestCase { + public function setUp() { + parent::setUp(); + + $this->author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor2' ) ); + + $post = array( + 'post_author' => $this->author1, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'post', + ); + + $this->author1_post1 = wp_insert_post( $post ); + + $post = array( + 'post_author' => $this->author1, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'post', + ); + + $this->author1_post2 = wp_insert_post( $post ); + + $page = array( + 'post_author' => $this->author1, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'page', + ); + + $this->author1_page1 = wp_insert_post( $page ); + + $page = array( + 'post_author' => $this->author1, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'page', + ); + + $this->author1_page2 = wp_insert_post( $page ); + } + + public function tearDown() { + parent::tearDown(); + } + /** * Test assigning a Co-Author to a post */ From ba23fb5a6a7611ca7067aa18667e1cc095f199aa Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 19:02:48 -0400 Subject: [PATCH 010/231] Add some basic WP_Query tests We can use these to verify that our author query mods work --- tests/coauthorsplus-testcase.php | 9 ++- tests/test-author-queries.php | 105 +++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/test-author-queries.php diff --git a/tests/coauthorsplus-testcase.php b/tests/coauthorsplus-testcase.php index f58d7878..99116c10 100644 --- a/tests/coauthorsplus-testcase.php +++ b/tests/coauthorsplus-testcase.php @@ -3,4 +3,11 @@ /** * Base unit test class for Co-Authors Plus */ -class CoAuthorsPlus_TestCase extends WP_UnitTestCase {} +class CoAuthorsPlus_TestCase extends WP_UnitTestCase { + public function setUp() { + parent::setUp(); + + global $coauthors_plus; + $this->_cap = $coauthors_plus; + } +} diff --git a/tests/test-author-queries.php b/tests/test-author-queries.php new file mode 100644 index 00000000..13a7c3da --- /dev/null +++ b/tests/test-author-queries.php @@ -0,0 +1,105 @@ +factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $post_id = $this->factory->post->create( array( + 'post_author' => $author_id, + 'post_status' => 'publish', + 'post_type' => 'post', + ) ); + + $query = new WP_Query( array( + 'author' => $author_id, + ) ); + + $this->assertEquals( 1, count( $query->posts ) ); + $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); + } + + public function test__author_name_arg__user_is_post_author() { + $author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $author = get_userdata( $author_id ); + $post_id = $this->factory->post->create( array( + 'post_author' => $author_id, + 'post_status' => 'publish', + 'post_type' => 'post', + ) ); + + $query = new WP_Query( array( + 'author_name' => $author->user_login, + ) ); + + $this->assertEquals( 1, count( $query->posts ) ); + $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); + } + + + public function test__author_name_arg__user_is_coauthor() { + $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $author1 = get_userdata( $author1_id ); + $author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) ); + $author2 = get_userdata( $author2_id ); + + $post_id = $this->factory->post->create( array( + 'post_author' => $author1_id, + 'post_status' => 'publish', + 'post_type' => 'post', + ) ); + $this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) ); + + $query = new WP_Query( array( + 'author_name' => $author2->user_login, + ) ); + + $this->assertEquals( 1, count( $query->posts ) ); + $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); + } + + public function test__author_arg__user_is_coauthor__author_arg() { + return; // TODO: re-enable; fails currently because WordPress generates query as `post_author IN (id)` which doesn't match our regex in the posts_where filter. + + $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $author1 = get_userdata( $author1_id ); + $author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) ); + $author2 = get_userdata( $author2_id ); + + $post_id = $this->factory->post->create( array( + 'post_author' => $author1_id, + 'post_status' => 'publish', + 'post_type' => 'post', + ) ); + $this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) ); + + $query = new WP_Query( array( + 'author' => $author2_id, + ) ); + + $this->assertEquals( 1, count( $query->posts ) ); + $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); + } + + public function tests__author_name_arg_plus_tax_query__is_coauthor() { + $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $author1 = get_userdata( $author1_id ); + $author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) ); + $author2 = get_userdata( $author2_id ); + + $post_id = $this->factory->post->create( array( + 'post_author' => $author1_id, + 'post_status' => 'publish', + 'post_type' => 'post', + ) ); + $this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) ); + wp_set_post_terms( $post_id, 'test', 'post_tag' ); + + $query = new WP_Query( array( + 'author_name' => $author2->user_login, + 'tag' => 'test', + ) ); + + $this->assertEquals( 1, count( $query->posts ) ); + $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); + } +} From a7209e1199acd55739f9bce18d3fa3747ac5a400 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 19:07:43 -0400 Subject: [PATCH 011/231] Update Travis config with newer versions --- .travis.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index da7b0e08..80b95d51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,24 @@ language: php php: - - 5.3 - - 5.5 + - "nightly" env: - WP_VERSION=latest - - WP_VERSION=4.1 - - WP_VERSION=4.0 + +matrix: + include: + - php: "nightly" + env: WP_VERSION=latest + - php: "nightly" + env: WP_VERSION=4.5 + - php: "5.2" + env: WP_VERSION=latest + - php: "5.2" + env: WP_VERSION=4.5 + # 5.6 / latest already included above as first build. + # - php: "5.6" + # env: WP_VERSION=4.4 before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION From 9228687e28091e89d322081c0a38b8ffd802917e Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 22:50:09 -0400 Subject: [PATCH 012/231] Call `add_coauthors` for WP_Query tests And add an additional test for post_author + tax query --- tests/test-author-queries.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test-author-queries.php b/tests/test-author-queries.php index 13a7c3da..ca7b1cc2 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queries.php @@ -4,11 +4,13 @@ class Test_Author_Queries extends CoAuthorsPlus_TestCase { public function test__author_arg__user_is_post_author() { $author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $author = get_userdata( $author_id ); $post_id = $this->factory->post->create( array( 'post_author' => $author_id, 'post_status' => 'publish', 'post_type' => 'post', ) ); + $this->_cap->add_coauthors( $post_id, array( $author->user_login ) ); $query = new WP_Query( array( 'author' => $author_id, @@ -26,6 +28,7 @@ public function test__author_name_arg__user_is_post_author() { 'post_status' => 'publish', 'post_type' => 'post', ) ); + $this->_cap->add_coauthors( $post_id, array( $author->user_login ) ); $query = new WP_Query( array( 'author_name' => $author->user_login, @@ -35,7 +38,6 @@ public function test__author_name_arg__user_is_post_author() { $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); } - public function test__author_name_arg__user_is_coauthor() { $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); $author1 = get_userdata( $author1_id ); @@ -80,6 +82,26 @@ public function test__author_arg__user_is_coauthor__author_arg() { $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); } + public function test__author_name_arg_plus_tax_query__user_is_post_author() { + $author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); + $author = get_userdata( $author_id ); + $post_id = $this->factory->post->create( array( + 'post_author' => $author_id, + 'post_status' => 'publish', + 'post_type' => 'post', + ) ); + $this->_cap->add_coauthors( $post_id, array( $author->user_login ) ); + wp_set_post_terms( $post_id, 'test', 'post_tag' ); + + $query = new WP_Query( array( + 'author_name' => $author->user_login, + 'tag' => 'test', + ) ); + + $this->assertEquals( 1, count( $query->posts ) ); + $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); + } + public function tests__author_name_arg_plus_tax_query__is_coauthor() { $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); $author1 = get_userdata( $author1_id ); From 54b84e79bf529a1679ea58b61f5d778a8b351a18 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 22:54:31 -0400 Subject: [PATCH 013/231] Disable author_name+tax_query+coauthor test Known issue in CAP --- tests/test-author-queries.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test-author-queries.php b/tests/test-author-queries.php index ca7b1cc2..d6d58c7a 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queries.php @@ -103,6 +103,8 @@ public function test__author_name_arg_plus_tax_query__user_is_post_author() { } public function tests__author_name_arg_plus_tax_query__is_coauthor() { + return; // TODO: re-enable; fails currently because our posts_join_filter doesn't add an exclusive JOIN on relationships + taxonomy to match the query mods we make. We'd need aliased JOINs on relationships + taxonomy on top of the JOIN that the tax query already adds. + $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); $author1 = get_userdata( $author1_id ); $author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) ); From c438333d1e31dd6f85346c24381de03e5921dc3e Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 23:09:47 -0400 Subject: [PATCH 014/231] Add more builds to matrix --- .travis.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80b95d51..ddfc75dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,21 +8,27 @@ env: matrix: include: +# nightly+latest already included above as first build. - php: "nightly" env: WP_VERSION=latest + - php: "nightly" + env: WP_VERSION=4.6 - php: "nightly" env: WP_VERSION=4.5 - php: "5.2" env: WP_VERSION=latest - php: "5.2" + env: WP_VERSION=4.6 + - php: "5.2" + env: WP_VERSION=4.5 + - php: "5.6" + env: WP_VERSION=latest + - php: "5.6" env: WP_VERSION=4.5 - # 5.6 / latest already included above as first build. - # - php: "5.6" - # env: WP_VERSION=4.4 + - php: "5.6" + env: WP_VERSION=4.4 before_script: - - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION + - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION -script: - - make lint - - make phpunit +script: phpunit From 786777a38bde89c84852794e05a844f932b7f596 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 23:17:55 -0400 Subject: [PATCH 015/231] 4.6+ uses a LEFT JOIN for tax queries We need to check for both INNER and LEFT JOINs to avoid adding a dupe query which leads to query errors in 4.6+. See #374 --- co-authors-plus.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddea5bb1..f537e168 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -611,12 +611,17 @@ function posts_join_filter( $join, $query ) { } // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley - $term_relationship_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; + $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; + $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; - if ( false === strpos( $join, trim( $term_relationship_join ) ) ) { - $join .= str_replace( 'INNER JOIN', 'LEFT JOIN', $term_relationship_join ); + // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both + if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) + && false === strpos( $join, trim( $term_relationship_left_join ) ) ) { + $join .= $term_relationship_left_join; } + if ( false === strpos( $join, trim( $term_taxonomy_join ) ) ) { $join .= str_replace( 'INNER JOIN', 'LEFT JOIN', $term_taxonomy_join ); } From 9b6d95f15dd0ab9903980306d0d4a997a077d147 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Thu, 1 Sep 2016 23:20:25 -0400 Subject: [PATCH 016/231] Don't bother running latest on travis twice --- .travis.yml | 8 ++++---- readme.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ddfc75dc..9e4f89af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ env: matrix: include: # nightly+latest already included above as first build. - - php: "nightly" - env: WP_VERSION=latest +# - php: "nightly" +# env: WP_VERSION=latest - php: "nightly" env: WP_VERSION=4.6 - php: "nightly" @@ -24,9 +24,9 @@ matrix: - php: "5.6" env: WP_VERSION=latest - php: "5.6" - env: WP_VERSION=4.5 + env: WP_VERSION=4.6 - php: "5.6" - env: WP_VERSION=4.4 + env: WP_VERSION=4.5 before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION diff --git a/readme.txt b/readme.txt index f4dd35d8..8ca2a6b9 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Co-Authors Plus === Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.5.2 +Tested up to: 4.6 Requires at least: 4.1 Stable tag: 3.2.1 From e1bda7689236ad86c7f911ddc339f59dcb19bb6a Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 10 Nov 2016 15:22:21 -0800 Subject: [PATCH 017/231] Join term_relationships with alias When joining term_taxonomy, also join term_relationships with alias to prevent unintended matches in case of another taxonomy query. --- co-authors-plus.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index f537e168..40bcc112 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -614,7 +614,8 @@ function posts_join_filter( $join, $query ) { $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; + $term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) From 7372bdec9f7bc68d3b4cae310e2c18f12a59a97a Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 10 Nov 2016 15:53:09 -0800 Subject: [PATCH 018/231] Make sure to echo wp_kses() wp_kses() doesn't print, only returns, so make sure we echo it. --- co-authors-plus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index f537e168..164ba30d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -375,14 +375,14 @@ public function coauthors_meta_box( $post ) { ?>
-

Note: To edit post authors, please enable javascript or use a javascript-capable browser', 'co-authors-plus' ), array( 'strong' => array() ) ); ?>

+

Note: To edit post authors, please enable javascript or use a javascript-capable browser', 'co-authors-plus' ), array( 'strong' => array() ) ); ?>

-

Remove to remove them.', 'co-authors-plus' ), array( 'strong' => array() ) ); ?>

+

Remove to remove them.', 'co-authors-plus' ), array( 'strong' => array() ) ); ?>

@@ -506,7 +506,7 @@ function _action_quick_edit_custom_box( $column_name, $post_type ) { From 26941de3813e5c27a21b698e793cdcd98729f1e5 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Tue, 15 Nov 2016 22:04:09 -0800 Subject: [PATCH 019/231] Let guest authors query args (admin-side) be filtered Add filter to allow query args to be filtered for the guest authors listing. Allows, for example, sorting by last-name-first-name. --- php/class-coauthors-wp-list-table.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index dacbf203..552f6db0 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -64,6 +64,8 @@ function prepare_items() { 'order' => 'ASC', ); + $args = apply_filters( 'coauthors_guest_author_query_args', $args ); + if ( isset( $_REQUEST['orderby'] ) ) { switch ( $_REQUEST['orderby'] ) { case 'display_name': From 35b1cf14a0068eee63bb3be096615c2e3e07bf55 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Fri, 18 Nov 2016 10:06:03 -0800 Subject: [PATCH 020/231] Replace post_author portion of where clause with tax query only where author ID is the queried object id see https://github.com/Automattic/Co-Authors-Plus/issues/375 Greedy replacments could let, for example, a contributor see an author's private posts. Instead make sure that private posts are only shown to the primary author. --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 164ba30d..3f6bc34b 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -685,7 +685,7 @@ function posts_where_filter( $where, $query ) { } $terms_implode = rtrim( $terms_implode, ' OR' ); $this->having_terms = rtrim( $this->having_terms, ' OR' ); - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(\d+))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_queried_object_id() . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND } } return $where; From 08c0315ec164553a11373d442bc506e7b952d499 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Sat, 19 Nov 2016 22:14:15 -0800 Subject: [PATCH 021/231] Let coauthors see private posts in author archive see https://github.com/Automattic/Co-Authors-Plus/issues/375 Allow coauthors to see their private posts in the author archive. --- co-authors-plus.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 3f6bc34b..c0ef1ed6 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -684,8 +684,25 @@ function posts_where_filter( $where, $query ) { $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $term->term_id .'\' OR '; } $terms_implode = rtrim( $terms_implode, ' OR' ); - $this->having_terms = rtrim( $this->having_terms, ' OR' ); + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_queried_object_id() . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + + // the block targets the private posts clause (if it exists) + if ( + is_user_logged_in() && + get_queried_object_id() != get_current_user_id() + ) { + $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); + $current_coauthor_term = $this->get_author_term( $current_coauthor ); + + $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\''; + $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR '; + + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + } + + $this->having_terms = rtrim( $this->having_terms, ' OR' ); + } } return $where; From efc193fe1ecded3dd43fbdbe374fbd4fa3892715 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 20 Nov 2016 14:30:10 +0000 Subject: [PATCH 022/231] Include PHP 7 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9e4f89af..e28cfc7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,8 @@ matrix: env: WP_VERSION=4.6 - php: "5.6" env: WP_VERSION=4.5 + - php: "7" + env: WP_VERSION=4.6 before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION From c835d7f279a3fcc40c7c8436de3454779fca2fbc Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 20 Nov 2016 14:33:04 +0000 Subject: [PATCH 023/231] Run PHPCS on WP 4.6 with PHP 5.6 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e28cfc7c..6152b93f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,9 @@ matrix: - php: "5.6" env: WP_VERSION=latest - php: "5.6" - env: WP_VERSION=4.6 + env: + - WP_VERSION=4.6 + - SNIFF=1 - php: "5.6" env: WP_VERSION=4.5 - php: "7" From 0f7ae5de401aeefef41e3f3c763f39b8c9df13bf Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 20 Nov 2016 14:35:27 +0000 Subject: [PATCH 024/231] Add the sniff and also check for PHP syntax errors --- .travis.yml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6152b93f..fea742a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,5 +34,33 @@ matrix: before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION + # PHPCS + - export PHPCS_DIR=/tmp/phpcs + - export SNIFFS_DIR=/tmp/sniffs + # Install CodeSniffer for WordPress Coding Standards checks. + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi + # Install WordPress Coding Standards. + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $SNIFFS_DIR; fi + # Install PHP Compatibility sniffs. + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/wimg/PHPCompatibility.git $SNIFFS_DIR/PHPCompatibility; fi + # Set install path for PHPCS sniffs. + # @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941 + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $SNIFFS_DIR; fi + # After CodeSniffer install you should refresh your path. + - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi -script: phpunit +script: + # Search for PHP syntax errors. + - find -L . -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l + # WordPress Coding Standards. + # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + # @link http://pear.php.net/package/PHP_CodeSniffer/ + # -p flag: Show progress of the run. + # -s flag: Show sniff codes in all reports. + # -v flag: Print verbose output. + # -n flag: Do not print warnings. (shortcut for --warning-severity=0) + # --standard: Use WordPress as the standard. + # --extensions: Only sniff PHP files. + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p -s -v -n . --standard="WordPress-VIP" --extensions=php; fi + # Unit tests + - phpunit From 4fffcaab45cb3f907586ad69a461dfe00533532a Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Sun, 20 Nov 2016 19:53:07 -0800 Subject: [PATCH 025/231] Only add additional private post where clause filtering when it's an author archive Make sure additional filtering on private post clause only goes into effect if it's an author archive. --- co-authors-plus.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c0ef1ed6..9edd3659 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -685,11 +685,14 @@ function posts_where_filter( $where, $query ) { } $terms_implode = rtrim( $terms_implode, ' OR' ); - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_queried_object_id() . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + $id = is_author() ? get_queried_object_id() : '\d'; + + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . $id . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND // the block targets the private posts clause (if it exists) if ( is_user_logged_in() && + is_author() && get_queried_object_id() != get_current_user_id() ) { $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); From a16a135ad317e82d57ef829c0ea058e9d9da46dd Mon Sep 17 00:00:00 2001 From: Philip John Date: Fri, 9 Dec 2016 12:39:23 +0000 Subject: [PATCH 026/231] Tested tag to 4.7 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 8ca2a6b9..9a9b413e 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Co-Authors Plus === Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.6 +Tested up to: 4.7 Requires at least: 4.1 Stable tag: 3.2.1 From bd3d8b5369d9ba9efbb14ad8ade97a2160bd6601 Mon Sep 17 00:00:00 2001 From: Linnea Wilhelm Date: Sat, 10 Dec 2016 08:17:22 -0800 Subject: [PATCH 027/231] get the coauthors by term_order --- template-tags.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/template-tags.php b/template-tags.php index 725fc47f..7e23830c 100644 --- a/template-tags.php +++ b/template-tags.php @@ -14,8 +14,7 @@ function get_coauthors( $post_id = 0 ) { } if ( $post_id ) { - $coauthor_terms = get_the_terms( $post_id, $coauthors_plus->coauthor_taxonomy ); - + $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( 'orderby' => 'term_order', 'order' => 'ASC' ) ); if ( is_array( $coauthor_terms ) && ! empty( $coauthor_terms ) ) { foreach ( $coauthor_terms as $coauthor ) { $coauthor_slug = preg_replace( '#^cap\-#', '', $coauthor->slug ); From fb28394300497c28ef1ba8966f259412584700c2 Mon Sep 17 00:00:00 2001 From: Linnea Wilhelm Date: Sat, 10 Dec 2016 08:46:16 -0800 Subject: [PATCH 028/231] added caching --- co-authors-plus.php | 7 +++++++ template-tags.php | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 5d11c433..92f8c306 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -116,6 +116,9 @@ function __construct() { // Support infinite scroll for Guest Authors on author pages add_filter( 'infinite_scroll_js_settings', array( $this, 'filter_infinite_scroll_js_settings' ), 10, 2 ); + // Delete CoAuthor Cache on Post Save + add_action( 'save_post', array( $this, 'clear_cache') ); + add_action( 'delete_post', array( $this, 'clear_cache') ); } /** @@ -1469,6 +1472,10 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { // Send back the updated Open Graph Tags return apply_filters( 'coauthors_open_graph_tags', $og_tags ); } + + public function clear_cache( $post_id ) { + wp_cache_delete( 'coauthors_post_' . $post_id ); + } } global $coauthors_plus; diff --git a/template-tags.php b/template-tags.php index 7e23830c..4a50c89a 100644 --- a/template-tags.php +++ b/template-tags.php @@ -14,7 +14,11 @@ function get_coauthors( $post_id = 0 ) { } if ( $post_id ) { - $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( 'orderby' => 'term_order', 'order' => 'ASC' ) ); + $cache_key = 'coauthors_post_' . $post_id; + if ( false === ( $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ) ) ) { + $coauthor_terms = wp_get_object_terms($post_id, $coauthors_plus->coauthor_taxonomy, array('orderby' => 'term_order', 'order' => 'ASC')); + wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); + } if ( is_array( $coauthor_terms ) && ! empty( $coauthor_terms ) ) { foreach ( $coauthor_terms as $coauthor ) { $coauthor_slug = preg_replace( '#^cap\-#', '', $coauthor->slug ); From c9af2d7f521abf2e170e3dfa2232b3ed7a08697b Mon Sep 17 00:00:00 2001 From: Linnea Wilhelm Date: Sat, 10 Dec 2016 08:50:10 -0800 Subject: [PATCH 029/231] phpDoc and spaces --- co-authors-plus.php | 7 ++++++- template-tags.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 92f8c306..d067bdb1 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -116,7 +116,7 @@ function __construct() { // Support infinite scroll for Guest Authors on author pages add_filter( 'infinite_scroll_js_settings', array( $this, 'filter_infinite_scroll_js_settings' ), 10, 2 ); - // Delete CoAuthor Cache on Post Save + // Delete CoAuthor Cache on Post Save & Post Delete add_action( 'save_post', array( $this, 'clear_cache') ); add_action( 'delete_post', array( $this, 'clear_cache') ); } @@ -1473,6 +1473,11 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { return apply_filters( 'coauthors_open_graph_tags', $og_tags ); } + /** + * Callback to clear the cache on post save and post delete. + * + * @param $post_id The Post ID. + */ public function clear_cache( $post_id ) { wp_cache_delete( 'coauthors_post_' . $post_id ); } diff --git a/template-tags.php b/template-tags.php index 4a50c89a..a5cd99ab 100644 --- a/template-tags.php +++ b/template-tags.php @@ -16,7 +16,7 @@ function get_coauthors( $post_id = 0 ) { if ( $post_id ) { $cache_key = 'coauthors_post_' . $post_id; if ( false === ( $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ) ) ) { - $coauthor_terms = wp_get_object_terms($post_id, $coauthors_plus->coauthor_taxonomy, array('orderby' => 'term_order', 'order' => 'ASC')); + $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( 'orderby' => 'term_order', 'order' => 'ASC' ) ); wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); } if ( is_array( $coauthor_terms ) && ! empty( $coauthor_terms ) ) { From 628b6f54fd96480d241cbdf4548118c0247b1a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane?= Date: Tue, 17 Jan 2017 15:53:20 -0500 Subject: [PATCH 030/231] Reduce amount of sleep This command was taking multiple days to run for some sites. I think reducing the amount of sleep here is reasonable. No need to pause for 5s at each 20 queries. --- php/class-wp-cli.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 9b334317..1f4e4cf9 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -244,8 +244,8 @@ public function assign_user_to_coauthor( $args, $assoc_args ) { $coauthors_plus->add_coauthors( $post_id, array( $coauthor->user_login ) ); WP_CLI::line( sprintf( __( "Updating - Adding %s's byline to post #%d", 'co-authors-plus' ), $coauthor->user_login, $post_id ) ); $affected++; - if ( $affected && 0 === $affected % 20 ) { - sleep( 5 ); + if ( $affected && 0 === $affected % 100 ) { + sleep( 2 ); } } WP_CLI::success( sprintf( __( 'All done! %d posts were affected.', 'co-authors-plus' ), $affected ) ); From 1bcb21e6aa9f73543bd5b64e860b5f3dc4f7f165 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 11 Mar 2017 17:42:10 +0000 Subject: [PATCH 031/231] Add missing group parameter to wp_cache_delete() call. See #391.# --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index d067bdb1..ad68feb4 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1479,7 +1479,7 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { * @param $post_id The Post ID. */ public function clear_cache( $post_id ) { - wp_cache_delete( 'coauthors_post_' . $post_id ); + wp_cache_delete( 'coauthors_post_' . $post_id, 'co-authors-plus' ); } } From bd133868490f014733ebb9b7b37be65cdf17963b Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 11 Mar 2017 17:44:59 +0000 Subject: [PATCH 032/231] Sync helper updates from wpcom --- wpcom-helper.php | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/wpcom-helper.php b/wpcom-helper.php index 0e9c6cff..1c9bb1b1 100644 --- a/wpcom-helper.php +++ b/wpcom-helper.php @@ -1,28 +1,36 @@ is_enabled() && ! in_array( get_option( 'template' ), $wpcom_coauthors_plus_auto_apply_themes ) ) + if ( Enterprise()->is_enabled() && ! in_array( get_option( 'template' ), wpcom_vip_get_coauthors_plus_auto_apply_themes() ) ) add_action( 'admin_notices', function() { // Allow this to be short-circuted in mu-plugins @@ -221,7 +229,10 @@ function wpcom_vip_cap_replace_author_link( $link, $author_id, $author_nicename return $link; } -//Hook the above callback only on oembed endpoint reply -if ( true === defined( 'WPCOM_VIP_IS_OEMBED' ) && true === constant( 'WPCOM_VIP_IS_OEMBED' ) && true === apply_filters( 'wpcom_vip_coauthors_replace_oembed', false, 'author_url' ) ) { - add_filter( 'author_link', 'wpcom_vip_cap_replace_author_link', 99, 3 ); -} + +add_action( 'init', function() { + //Hook the above callback only on oembed endpoint reply + if ( true === defined( 'WPCOM_VIP_IS_OEMBED' ) && true === constant( 'WPCOM_VIP_IS_OEMBED' ) && true === apply_filters( 'wpcom_vip_coauthors_replace_oembed', false, 'author_url' ) ) { + add_filter( 'author_link', 'wpcom_vip_cap_replace_author_link', 99, 3 ); + } +}, 9 ); From 8cd994d86a3a71579993e9bb8afdef61b7bed9b9 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 11 Mar 2017 17:56:17 +0000 Subject: [PATCH 033/231] Prepare v3.2.2 release Full changeset for this release: https://github.com/Automattic/Co-Authors-Plus/compare/69f58e2b84927643fc382dba45d935f0477bbf7d...bd133868490f014733ebb9b7b37be65cdf17963b --- co-authors-plus.php | 2 +- readme.txt | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ad68feb4..46a6401d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -3,7 +3,7 @@ Plugin Name: Co-Authors Plus Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/ Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter. -Version: 3.2.1 +Version: 3.2.2 Author: Mohammad Jangda, Daniel Bachhuber, Automattic Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter diff --git a/readme.txt b/readme.txt index 9a9b413e..ba030853 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Co-Authors Plus === Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.7 +Tested up to: 4.7.3 Requires at least: 4.1 -Stable tag: 3.2.1 +Stable tag: 3.2.2 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box @@ -57,6 +57,13 @@ Bug fixes and minor enhancements == Changelog == += 3.2.2 = +* Fix broken author ordering in 4.7+ (props mslinnea) +* Fix no moderation e-mail bug (props RobjS) +* Cached functions in CLI commands (props jasonbahl) +* Fix missing echos (props trepmal) +* Add `coauthors_guest_author_query_args` filter (props trepmal) + = 3.2.1 (May 16, 2016) = * Hotfix for broken Guest Author bio metabox (props JS Morisset) From 2086458e8b496aa62c9728ddd98e1b5fe7900bea Mon Sep 17 00:00:00 2001 From: Philip John Date: Mon, 20 Mar 2017 13:35:29 +0000 Subject: [PATCH 034/231] Introduce helper function for grabbing cached list of coauthor terms. --- co-authors-plus.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index ad68feb4..4535623c 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1624,3 +1624,37 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i } return $recipients; } + +/** + * Retrieve a list of coauthor terms for a single post. + * + * Grabs a correctly ordered list of authors for a single post, appropriately + * cached because it requires `wp_get_object_terms()` to succeed. + * + * @param int $post_id ID of the post for which to retrieve authors. + * @return array Array of coauthor WP_Term objects + */ +function cap_get_coauthor_terms_for_post( $post_id = false ) { + + if ( ! $post_id ) { + return array(); + } + + global $coauthors_plus; + + $cache_key = 'coauthors_post_' . $post_id; + $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ) + + if ( false === $coauthor_terms ) { + $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( + 'orderby' => 'term_order', + 'order' => 'ASC', + ) ); + wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); + } else { + $coauthor_terms = array(); + } + + return $coauthor_terms; + +} From 4aea6b153941b34da5e9eb848283ffb0885288d2 Mon Sep 17 00:00:00 2001 From: Philip John Date: Mon, 20 Mar 2017 13:35:55 +0000 Subject: [PATCH 035/231] Use the new helper function for grabbing cached co-author terms lists. --- php/class-wp-cli.php | 19 +++++++++---------- template-tags.php | 6 +----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 9b334317..08706e80 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -76,10 +76,9 @@ public function create_terms_for_posts() { $count++; - $terms = get_the_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy ); - - if ( is_wp_error( $terms ) ) { - WP_CLI::error( $terms->get_error_message() ); + $terms = cap_get_coauthor_terms_for_post( $single_post->ID ); + if ( empty( $terms ) ) { + WP_CLI::error( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); } if ( ! empty( $terms ) ) { @@ -236,7 +235,7 @@ public function assign_user_to_coauthor( $args, $assoc_args ) { $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user->ID ) ); $affected = 0; foreach ( $posts as $post_id ) { - if ( $coauthors = get_the_terms( $post_id, $coauthors_plus->coauthor_taxonomy ) ) { + if ( $coauthors = cap_get_coauthor_terms_for_post( $post_id ) ) { WP_CLI::line( sprintf( __( 'Skipping - Post #%d already has co-authors assigned: %s', 'co-authors-plus' ), $post_id, implode( ', ', wp_list_pluck( $coauthors, 'slug' ) ) ) ); continue; } @@ -545,8 +544,8 @@ public function list_posts_without_terms( $args, $assoc_args ) { while ( $posts->post_count ) { foreach ( $posts->posts as $single_post ) { - - $terms = get_the_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy ); + + $terms = cap_get_coauthor_terms_for_post( $single_post->ID ); if ( empty( $terms ) ) { $saved = array( $single_post->ID, @@ -698,9 +697,9 @@ public function remove_terms_from_revisions() { WP_CLI::line( 'Found ' . count( $ids ) . ' revisions to look through' ); $affected = 0; foreach ( $ids as $post_id ) { - - $terms = get_the_terms( $post_id, $coauthors_plus->coauthor_taxonomy ); - if ( ! $terms ) { + + $terms = cap_get_coauthor_terms_for_post( $post_id ); + if ( empty( $terms ) ) { continue; } diff --git a/template-tags.php b/template-tags.php index a5cd99ab..ffc398ae 100644 --- a/template-tags.php +++ b/template-tags.php @@ -14,11 +14,7 @@ function get_coauthors( $post_id = 0 ) { } if ( $post_id ) { - $cache_key = 'coauthors_post_' . $post_id; - if ( false === ( $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ) ) ) { - $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( 'orderby' => 'term_order', 'order' => 'ASC' ) ); - wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); - } + $coauthor_terms = cap_get_coauthor_terms_for_post( $post_id ); if ( is_array( $coauthor_terms ) && ! empty( $coauthor_terms ) ) { foreach ( $coauthor_terms as $coauthor ) { $coauthor_slug = preg_replace( '#^cap\-#', '', $coauthor->slug ); From 0a640ad7d4782b2daa554afe1c05d4895180078e Mon Sep 17 00:00:00 2001 From: Philip John Date: Mon, 20 Mar 2017 13:44:49 +0000 Subject: [PATCH 036/231] Explicitly check for a non-empty array and tidy up the code a little. --- php/class-wp-cli.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 08706e80..7e96d10d 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -235,8 +235,13 @@ public function assign_user_to_coauthor( $args, $assoc_args ) { $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user->ID ) ); $affected = 0; foreach ( $posts as $post_id ) { - if ( $coauthors = cap_get_coauthor_terms_for_post( $post_id ) ) { - WP_CLI::line( sprintf( __( 'Skipping - Post #%d already has co-authors assigned: %s', 'co-authors-plus' ), $post_id, implode( ', ', wp_list_pluck( $coauthors, 'slug' ) ) ) ); + $coauthors = cap_get_coauthor_terms_for_post( $post_id ) + if ( ! empty( $coauthors ) ) { + WP_CLI::line( sprintf( + __( 'Skipping - Post #%d already has co-authors assigned: %s', 'co-authors-plus' ), + $post_id, + implode( ', ', wp_list_pluck( $coauthors, 'slug' ) ) + ) ); continue; } From 81017509869c98bf95d1e8aba95e272e26dcb6df Mon Sep 17 00:00:00 2001 From: Philip John Date: Mon, 20 Mar 2017 13:50:01 +0000 Subject: [PATCH 037/231] Must. Remember. Semicolons. --- co-authors-plus.php | 2 +- php/class-wp-cli.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 4535623c..0ac73e12 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1643,7 +1643,7 @@ function cap_get_coauthor_terms_for_post( $post_id = false ) { global $coauthors_plus; $cache_key = 'coauthors_post_' . $post_id; - $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ) + $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ); if ( false === $coauthor_terms ) { $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 7e96d10d..568f988e 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -235,7 +235,7 @@ public function assign_user_to_coauthor( $args, $assoc_args ) { $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user->ID ) ); $affected = 0; foreach ( $posts as $post_id ) { - $coauthors = cap_get_coauthor_terms_for_post( $post_id ) + $coauthors = cap_get_coauthor_terms_for_post( $post_id ); if ( ! empty( $coauthors ) ) { WP_CLI::line( sprintf( __( 'Skipping - Post #%d already has co-authors assigned: %s', 'co-authors-plus' ), From d5305b5a941f89fe4aaa60b596c02512c8c18563 Mon Sep 17 00:00:00 2001 From: Philip John Date: Mon, 20 Mar 2017 14:35:49 +0000 Subject: [PATCH 038/231] Bust the coauthors terms order cache when the objects terms are updated too. --- co-authors-plus.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index 0ac73e12..4a7aeaa0 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -119,6 +119,7 @@ function __construct() { // Delete CoAuthor Cache on Post Save & Post Delete add_action( 'save_post', array( $this, 'clear_cache') ); add_action( 'delete_post', array( $this, 'clear_cache') ); + add_action( 'set_object_terms', array( $this, 'clear_cache_on_terms_set' ), 10, 6 ); } /** @@ -1481,6 +1482,23 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { public function clear_cache( $post_id ) { wp_cache_delete( 'coauthors_post_' . $post_id, 'co-authors-plus' ); } + + /** + * Callback to clear the cache when an object's terms are changed. + * + * @param $post_id The Post ID. + */ + public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) { + + // We only care about the coauthors taxonomy + if ( $this->coauthor_taxonomy !== $taxonomy ) { + return; + } + + wp_cache_delete( 'coauthors_post_' . $object_id, 'co-authors-plus' ); + + } + } global $coauthors_plus; From d58d3ae664e2175fa7371fdbc8cf5c7df54200ea Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 21 Mar 2017 08:05:29 +0000 Subject: [PATCH 039/231] Cache empty arrays when wp_get_object_terms() returns a WP_Error --- co-authors-plus.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 4a7aeaa0..5db8b313 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1652,7 +1652,7 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i * @param int $post_id ID of the post for which to retrieve authors. * @return array Array of coauthor WP_Term objects */ -function cap_get_coauthor_terms_for_post( $post_id = false ) { +function cap_get_coauthor_terms_for_post( $post_id ) { if ( ! $post_id ) { return array(); @@ -1664,13 +1664,13 @@ function cap_get_coauthor_terms_for_post( $post_id = false ) { $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ); if ( false === $coauthor_terms ) { - $coauthor_terms = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( + $cached = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( 'orderby' => 'term_order', 'order' => 'ASC', ) ); + // Cache an empty array if the taxonomy doesn't exist. + $coauthor_terms = ( is_wp_error( $cached ) ) ? array() : $cached; wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); - } else { - $coauthor_terms = array(); } return $coauthor_terms; From b1fe8c2d4e0fbdcd3373ef6d3747b74b4fa4faf8 Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 21 Mar 2017 08:27:32 +0000 Subject: [PATCH 040/231] Move cap_get_coauthor_terms_for_post() logic into the CoAuthors_Plus class and make the helper dumb --- co-authors-plus.php | 54 +++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 5db8b313..89186ab8 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1474,6 +1474,38 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { return apply_filters( 'coauthors_open_graph_tags', $og_tags ); } + /** + * Retrieve a list of coauthor terms for a single post. + * + * Grabs a correctly ordered list of authors for a single post, appropriately + * cached because it requires `wp_get_object_terms()` to succeed. + * + * @param int $post_id ID of the post for which to retrieve authors. + * @return array Array of coauthor WP_Term objects + */ + public function get_coauthor_terms_for_post( $post_id ) { + + if ( ! $post_id ) { + return array(); + } + + $cache_key = 'coauthors_post_' . $post_id; + $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ); + + if ( false === $coauthor_terms ) { + $cached = wp_get_object_terms( $post_id, $this->coauthor_taxonomy, array( + 'orderby' => 'term_order', + 'order' => 'ASC', + ) ); + // Cache an empty array if the taxonomy doesn't exist. + $coauthor_terms = ( is_wp_error( $cached ) ) ? array() : $cached; + wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); + } + + return $coauthor_terms; + + } + /** * Callback to clear the cache on post save and post delete. * @@ -1653,26 +1685,6 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i * @return array Array of coauthor WP_Term objects */ function cap_get_coauthor_terms_for_post( $post_id ) { - - if ( ! $post_id ) { - return array(); - } - global $coauthors_plus; - - $cache_key = 'coauthors_post_' . $post_id; - $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ); - - if ( false === $coauthor_terms ) { - $cached = wp_get_object_terms( $post_id, $coauthors_plus->coauthor_taxonomy, array( - 'orderby' => 'term_order', - 'order' => 'ASC', - ) ); - // Cache an empty array if the taxonomy doesn't exist. - $coauthor_terms = ( is_wp_error( $cached ) ) ? array() : $cached; - wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); - } - - return $coauthor_terms; - + return $coauthors_plus->get_coauthor_terms_for_post( $post_id ); } From c1c73479067aedd801c50ae3e3981f19641013e7 Mon Sep 17 00:00:00 2001 From: haleeben Date: Wed, 22 Mar 2017 16:43:13 +1100 Subject: [PATCH 041/231] Fixed the ajax loading spinner not showing Show a message if no matching authors found --- co-authors-plus.php | 3 +++ css/co-authors-plus.css | 1 + js/co-authors-plus.js | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ad68feb4..b398d66d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1074,6 +1074,9 @@ public function ajax_suggest() { $authors = $this->search_authors( $search, $ignore ); + // Return message if no authors found + if( empty( $authors ) ) echo apply_filters( 'coauthors_no_matching_authors_message', 'Sorry, no matching authors found.'); + foreach ( $authors as $author ) { echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . $author->user_nicename ) . "\n"; } diff --git a/css/co-authors-plus.css b/css/co-authors-plus.css index 8f9fdb8f..9bec9c79 100644 --- a/css/co-authors-plus.css +++ b/css/co-authors-plus.css @@ -88,6 +88,7 @@ } #coauthors-loading { margin: 10px 0px 5px 10px; + float: left; } #coauthors-readonly { diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 7691f91b..f365dfa5 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -337,7 +337,7 @@ jQuery( document ).ready(function () { var newCO = coauthors_create_autosuggest( '', false ); coauthors_add_to_table( newCO ); - $coauthors_loading = jQuery( '#ajax-loading' ).clone().attr( 'id', 'coauthors-loading' ); + $coauthors_loading = jQuery( '#publishing-action .spinner' ).clone().attr( 'id', 'coauthors-loading' ); move_loading( newCO ); From 934a2615e329514504b97768f8a55d9cbdd484c8 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 23 Mar 2017 09:20:29 -0700 Subject: [PATCH 042/231] Don't create test tables as temporary In Test_Author_Queried_Object, tests will fail when, by default, tables for subsite are created as temporary. --- tests/test-author-queried-object.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test-author-queried-object.php b/tests/test-author-queried-object.php index 94e357f8..25689cf5 100644 --- a/tests/test-author-queried-object.php +++ b/tests/test-author-queried-object.php @@ -5,6 +5,20 @@ class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase { + /** + * Set up for test + * + * Don't create tables as 'temporary'. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/398 + */ + function setUp() { + parent::setUp(); + + remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); + remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); + } + /** * On author pages, the queried object should only be set * to a user that's not a member of the blog if they From fe48900551c20bb6a2b41412e756d55d7f65624f Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Tue, 28 Mar 2017 11:46:03 -0400 Subject: [PATCH 043/231] Don't cache when get_object_terms fails It can lead to unexpected bugs and make it not clear why we cached an empty array (and therefore harder to debug). --- co-authors-plus.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 89186ab8..66b18e0c 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1493,12 +1493,16 @@ public function get_coauthor_terms_for_post( $post_id ) { $coauthor_terms = wp_cache_get( $cache_key, 'co-authors-plus' ); if ( false === $coauthor_terms ) { - $cached = wp_get_object_terms( $post_id, $this->coauthor_taxonomy, array( + $coauthor_terms = wp_get_object_terms( $post_id, $this->coauthor_taxonomy, array( 'orderby' => 'term_order', 'order' => 'ASC', ) ); - // Cache an empty array if the taxonomy doesn't exist. - $coauthor_terms = ( is_wp_error( $cached ) ) ? array() : $cached; + + // This usually happens if the taxonomy doesn't exist, which should never happen, but you never know. + if ( is_wp_error( $coauthor_terms ) ) { + return array(); + } + wp_cache_set( $cache_key, $coauthor_terms, 'co-authors-plus' ); } From 3248dfcd10941a7cec2b7e0acffd90c4e16a20b7 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Tue, 28 Mar 2017 13:59:59 -0400 Subject: [PATCH 044/231] Update travis config to handle phpunit + php7 https://core.trac.wordpress.org/changeset/40255 --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index fea742a8..38be5006 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,6 +48,15 @@ before_script: - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $SNIFFS_DIR; fi # After CodeSniffer install you should refresh your path. - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi + # Properly handle PHPunit versions + - export PATH="$HOME/.composer/vendor/bin:$PATH" + - | + if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then + composer global require "phpunit/phpunit=5.7.*" + elif [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then + composer global require "phpunit/phpunit=4.8.*" + fi + - phpunit --version script: # Search for PHP syntax errors. From f53d8f767b0b3ceece487f2c0d6921c06ecb918e Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Tue, 28 Mar 2017 14:00:41 -0400 Subject: [PATCH 045/231] Update Travis environment matrix No need to test PHP nightly for now; 7 + 7.1 are good for now. Drop WordPress 4.5. --- .travis.yml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38be5006..28765d3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,30 @@ language: php php: - - "nightly" + - 7.1 env: - WP_VERSION=latest +matrix: matrix: include: -# nightly+latest already included above as first build. -# - php: "nightly" -# env: WP_VERSION=latest - - php: "nightly" - env: WP_VERSION=4.6 - - php: "nightly" - env: WP_VERSION=4.5 - php: "5.2" env: WP_VERSION=latest - php: "5.2" env: WP_VERSION=4.6 - - php: "5.2" - env: WP_VERSION=4.5 - - php: "5.6" - env: WP_VERSION=latest - php: "5.6" env: - - WP_VERSION=4.6 + - WP_VERSION=latest - SNIFF=1 - php: "5.6" - env: WP_VERSION=4.5 - - php: "7" + env: WP_VERSION=4.6 + - php: "7.0" + env: WP_VERSION=latest + - php: "7.0" + env: WP_VERSION=4.6 + # 7.1 / latest already included above as first build. + - php: "7.1" env: WP_VERSION=4.6 before_script: From 525f211c38b56e6b52bbb1e8b88e8f408dc411be Mon Sep 17 00:00:00 2001 From: philipjohn Date: Mon, 3 Apr 2017 16:17:43 +0100 Subject: [PATCH 046/231] Update version constant --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 33a8198f..ce08105d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -24,7 +24,7 @@ */ -define( 'COAUTHORS_PLUS_VERSION', '3.2.1' ); +define( 'COAUTHORS_PLUS_VERSION', '3.2.2' ); require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); From e6a4f244fc08642017b74330513008806e82f227 Mon Sep 17 00:00:00 2001 From: Chirag Patel Date: Wed, 24 May 2017 18:01:57 +0530 Subject: [PATCH 047/231] Remove associated guest user when mapped user id deleted. --- co-authors-plus.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index ce08105d..dfaec8a7 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -890,6 +890,17 @@ function delete_user_action( $delete_id ) { // Delete term wp_delete_term( $delete_user->user_login, $this->coauthor_taxonomy ); } + + // Get the deleted user data by user id. + $user_data = get_user_by( 'id', $delete_id ); + + // Get the associated user. + $associated_user = $this->guest_authors->get_guest_author_by( 'linked_account', $user_data->data->user_login ); + + if ( isset( $associated_user->ID ) ) { + // Delete associated guest user. + $this->guest_authors->delete( $associated_user->ID ); + } } /** From 0fbede4b7fadb7a47901af3e6950e31278406b2c Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Mon, 29 May 2017 19:20:00 -0600 Subject: [PATCH 048/231] Removed Duplicate Left Join and kept Alias --- co-authors-plus.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ce08105d..ddbea3f3 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -616,10 +616,9 @@ function posts_join_filter( $join, $query ) { // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; + $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; - $term_taxonomy_join = " INNER JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; - $term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) From 1602f48b5c5e9418dd7d6be72ec33689a2efd6fe Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Mon, 29 May 2017 19:25:30 -0600 Subject: [PATCH 049/231] Revert "Removed Duplicate Left Join and kept Alias" This reverts commit 0fbede4b7fadb7a47901af3e6950e31278406b2c. --- co-authors-plus.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddbea3f3..ce08105d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -616,9 +616,10 @@ function posts_join_filter( $join, $query ) { // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; + $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; + $term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) From 6e7da2bd54b5b7b8f87e4c5226745c13a7506a11 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Mon, 29 May 2017 19:39:19 -0600 Subject: [PATCH 050/231] Removed duplicate left join for optimization --- co-authors-plus.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ce08105d..ddbea3f3 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -616,10 +616,9 @@ function posts_join_filter( $join, $query ) { // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; + $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; - $term_taxonomy_join = " INNER JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; - $term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) From f75974429b8b804ea9e49f59f969aacd2eda1ddb Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 30 May 2017 12:09:36 -0600 Subject: [PATCH 051/231] Fixed WP CLI create-terms-for-posts if no co-authors found Script was stopping after no co-authors was find. Now script will display an error message and continue to the next post. --- php/class-wp-cli.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 568f988e..e2d5ae71 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -78,7 +78,8 @@ public function create_terms_for_posts() { $terms = cap_get_coauthor_terms_for_post( $single_post->ID ); if ( empty( $terms ) ) { - WP_CLI::error( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); + WP_CLI::line( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); + continue; } if ( ! empty( $terms ) ) { From 76c59ef41d764aa68c3cc11aedc6db4379f664ff Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 30 May 2017 12:11:23 -0600 Subject: [PATCH 052/231] Revert "Fixed WP CLI create-terms-for-posts if no co-authors found" This reverts commit f75974429b8b804ea9e49f59f969aacd2eda1ddb. --- php/class-wp-cli.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index e2d5ae71..568f988e 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -78,8 +78,7 @@ public function create_terms_for_posts() { $terms = cap_get_coauthor_terms_for_post( $single_post->ID ); if ( empty( $terms ) ) { - WP_CLI::line( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); - continue; + WP_CLI::error( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); } if ( ! empty( $terms ) ) { From 9f8a1d58c70eafa5cd81fb52bae85a5e9fb3d935 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 30 May 2017 12:11:31 -0600 Subject: [PATCH 053/231] Revert "Removed duplicate left join for optimization" This reverts commit 6e7da2bd54b5b7b8f87e4c5226745c13a7506a11. --- co-authors-plus.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddbea3f3..ce08105d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -616,9 +616,10 @@ function posts_join_filter( $join, $query ) { // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; + $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; + $term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) From 68bcb6e4b7f905ef5276c92f1e5dbc532787a915 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 30 May 2017 12:18:20 -0600 Subject: [PATCH 054/231] Fixed WP CLI create-terms-for-posts if no co-authors found Script was stopping after no co-authors was find. Now script will display an error message and continue to the next post. --- php/class-wp-cli.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 568f988e..e2d5ae71 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -78,7 +78,8 @@ public function create_terms_for_posts() { $terms = cap_get_coauthor_terms_for_post( $single_post->ID ); if ( empty( $terms ) ) { - WP_CLI::error( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); + WP_CLI::line( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); + continue; } if ( ! empty( $terms ) ) { From a5222a9e8601443b956d0a153ac6705a8c6a41cf Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 30 May 2017 15:49:44 -0600 Subject: [PATCH 055/231] Removed double left join on posts_join_filter (#419) Resolves #417 * Removed duplicate left join for optimization --- co-authors-plus.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ce08105d..ddbea3f3 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -616,10 +616,9 @@ function posts_join_filter( $join, $query ) { // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; - $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; + $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; - $term_taxonomy_join = " INNER JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)"; - $term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; + $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both if ( false === strpos( $join, trim( $term_relationship_inner_join ) ) From ea4ef6275d34aa730145db74fe39e8df0d209881 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 31 May 2017 15:19:26 -0600 Subject: [PATCH 056/231] CoAuthors display now for Pages and JS is being enqueued on Pages --- co-authors-plus.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddbea3f3..349740a2 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -413,7 +413,10 @@ function remove_quick_edit_authors_box() { function _filter_manage_posts_columns( $posts_columns ) { $new_columns = array(); - if ( ! $this->is_post_type_enabled() ) { + + $post_type = get_current_screen()->post_type; + + if ( ! $this->is_post_type_enabled( $post_type ) ) { return $posts_columns; } @@ -959,11 +962,16 @@ function current_user_can_set_authors( $post = null ) { if ( ! $post ) { $post = get_post(); if ( ! $post ) { - return false; + // if user is on pages, you need to grab post type another way + $post_type = get_current_screen()->post_type; + } + else { + $post_type = $post->post_type; } } - - $post_type = $post->post_type; + else { + $post_type = $post->post_type; + } // TODO: need to fix this; shouldn't just say no if don't have post_type if ( ! $post_type ) { @@ -1177,7 +1185,9 @@ function filter_terms_clauses( $pieces ) { function enqueue_scripts( $hook_suffix ) { global $pagenow, $post; - if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled() || ! $this->current_user_can_set_authors() ) { + $post_type = get_current_screen()->post_type; + + if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled( $post_type ) || ! $this->current_user_can_set_authors() ) { return; } From bcc875bdadd8996af622468f44557e00a1a6e893 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 31 May 2017 16:29:28 -0600 Subject: [PATCH 057/231] JS error goes away from js_vars() --- co-authors-plus.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 349740a2..c3429b0b 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1256,7 +1256,9 @@ function filter_views( $views ) { */ public function js_vars() { - if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled() || ! $this-> current_user_can_set_authors() ) { + $post_type = get_current_screen()->post_type; + + if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled( $post_type ) || ! $this-> current_user_can_set_authors() ) { return; } ?> From f226e9c08d38e19e4de307956199a6a388abe842 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 31 May 2017 16:40:15 -0600 Subject: [PATCH 058/231] changed is_post_type_enabled() to clean up code --- co-authors-plus.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c3429b0b..ae4bee0d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -293,7 +293,12 @@ public function get_coauthor_by( $key, $value, $force = false ) { public function is_post_type_enabled( $post_type = null ) { if ( ! $post_type ) { - $post_type = get_post_type(); + if ( is_admin() ) { + $post_type = get_current_screen()->post_type; + } + else { + $post_type = get_post_type(); + } } return (bool) in_array( $post_type, $this->supported_post_types ); @@ -414,9 +419,7 @@ function _filter_manage_posts_columns( $posts_columns ) { $new_columns = array(); - $post_type = get_current_screen()->post_type; - - if ( ! $this->is_post_type_enabled( $post_type ) ) { + if ( ! $this->is_post_type_enabled() ) { return $posts_columns; } @@ -1256,9 +1259,7 @@ function filter_views( $views ) { */ public function js_vars() { - $post_type = get_current_screen()->post_type; - - if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled( $post_type ) || ! $this-> current_user_can_set_authors() ) { + if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled() || ! $this-> current_user_can_set_authors() ) { return; } ?> From 29e1e90c7feff425d37d1bd786ba8185ba1373b5 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 31 May 2017 16:42:25 -0600 Subject: [PATCH 059/231] removed extra whitespace --- co-authors-plus.php | 1 - 1 file changed, 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ae4bee0d..a34c998f 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -418,7 +418,6 @@ function remove_quick_edit_authors_box() { function _filter_manage_posts_columns( $posts_columns ) { $new_columns = array(); - if ( ! $this->is_post_type_enabled() ) { return $posts_columns; } From 6b3ea351ea51fc296b040033dd3ad8d75916a660 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 31 May 2017 16:43:19 -0600 Subject: [PATCH 060/231] removed all traces of $post_type in functions, since is_post_type_enabled() should do the trick now --- co-authors-plus.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index a34c998f..47623668 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1187,9 +1187,7 @@ function filter_terms_clauses( $pieces ) { function enqueue_scripts( $hook_suffix ) { global $pagenow, $post; - $post_type = get_current_screen()->post_type; - - if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled( $post_type ) || ! $this->current_user_can_set_authors() ) { + if ( ! $this->is_valid_page() || ! $this->is_post_type_enabled() || ! $this->current_user_can_set_authors() ) { return; } From 5ac7d9a2288d49db6462a98d9211dfa42480a0f7 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Wed, 31 May 2017 15:57:03 -0700 Subject: [PATCH 061/231] Revert "Update version constant" This reverts commit 525f211c38b56e6b52bbb1e8b88e8f408dc411be. --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddbea3f3..cfa52988 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -24,7 +24,7 @@ */ -define( 'COAUTHORS_PLUS_VERSION', '3.2.2' ); +define( 'COAUTHORS_PLUS_VERSION', '3.2.1' ); require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); From 8f498c4fd9e080f0b9266eebd45c5df178eeecec Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 31 May 2017 21:52:19 -0600 Subject: [PATCH 062/231] Edited words to match glossary --- co-authors-plus.php | 74 +++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddbea3f3..d96fe511 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -22,6 +22,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +----------------- + +Glossary: + +User - a WordPress user account +Guest author - a CAP-created co-author +Co-author - in the context of a single post, a guest author or user assigned to the post alongside others +Author - user with the role of author */ define( 'COAUTHORS_PLUS_VERSION', '3.2.2' ); @@ -39,7 +47,7 @@ class CoAuthors_Plus { // Name for the taxonomy we're using to store relationships - // and the post type we're using to store co-authors + // and the post type we're using to store guest authors var $coauthor_taxonomy = 'author'; var $coreauthors_meta_box_name = 'authordiv'; @@ -68,38 +76,38 @@ function __construct() { // Load admin_init function add_action( 'admin_init', array( $this, 'admin_init' ) ); - // Modify SQL queries to include coauthors + // Modify SQL queries to include guest authors add_filter( 'posts_where', array( $this, 'posts_where_filter' ), 10, 2 ); add_filter( 'posts_join', array( $this, 'posts_join_filter' ), 10, 2 ); add_filter( 'posts_groupby', array( $this, 'posts_groupby_filter' ), 10, 2 ); - // Action to set users when a post is saved + // Action to set co-authors when a post is saved add_action( 'save_post', array( $this, 'coauthors_update_post' ), 10, 2 ); // Filter to set the post_author field when wp_insert_post is called add_filter( 'wp_insert_post_data', array( $this, 'coauthors_set_post_author_field' ), 10, 2 ); - // Action to reassign posts when a user is deleted + // Action to reassign posts when a guest author is deleted add_action( 'delete_user', array( $this, 'delete_user_action' ) ); add_filter( 'get_usernumposts', array( $this, 'filter_count_user_posts' ), 10, 2 ); - // Action to set up author auto-suggest + // Action to set up co-author auto-suggest add_action( 'wp_ajax_coauthors_ajax_suggest', array( $this, 'ajax_suggest' ) ); - // Filter to allow coauthors to edit posts + // Filter to allow co-authors to edit posts add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10, 3 ); - // Handle the custom author meta box + // Handle the custom co-author meta box add_action( 'add_meta_boxes', array( $this, 'add_coauthors_box' ) ); add_action( 'add_meta_boxes', array( $this, 'remove_authors_box' ) ); - // Removes the author dropdown from the post quick edit + // Removes the co-author dropdown from the post quick edit add_action( 'admin_head', array( $this, 'remove_quick_edit_authors_box' ) ); // Restricts WordPress from blowing away term order on bulk edit add_filter( 'wp_get_object_terms', array( $this, 'filter_wp_get_object_terms' ), 10, 4 ); - // Make sure we've correctly set author data on author pages + // Make sure we've correctly set data on guest author pages add_filter( 'posts_selection', array( $this, 'fix_author_page' ) ); // use posts_selection since it's after WP_Query has built the request and before it's queried any posts add_action( 'the_post', array( $this, 'fix_author_page' ) ); @@ -110,13 +118,13 @@ function __construct() { // Support Jetpack Open Graph Tags add_filter( 'jetpack_open_graph_tags', array( $this, 'filter_jetpack_open_graph_tags' ), 10, 2 ); - // Filter to send comment moderation notification e-mail to multiple authors + // Filter to send comment moderation notification e-mail to multiple co-authors add_filter( 'comment_moderation_recipients', 'cap_filter_comment_moderation_email_recipients', 10, 2 ); // Support infinite scroll for Guest Authors on author pages add_filter( 'infinite_scroll_js_settings', array( $this, 'filter_infinite_scroll_js_settings' ), 10, 2 ); - // Delete CoAuthor Cache on Post Save & Post Delete + // Delete Co-Author Cache on Post Save & Post Delete add_action( 'save_post', array( $this, 'clear_cache') ); add_action( 'delete_post', array( $this, 'clear_cache') ); add_action( 'set_object_terms', array( $this, 'clear_cache_on_terms_set' ), 10, 6 ); @@ -193,13 +201,13 @@ public function admin_init() { // Add necessary JS variables add_action( 'admin_head', array( $this, 'js_vars' ) ); - // Hooks to add additional coauthors to author column to Edit page + // Hooks to add additional co-authors to 'authors' column to edit page add_filter( 'manage_posts_columns', array( $this, '_filter_manage_posts_columns' ) ); add_filter( 'manage_pages_columns', array( $this, '_filter_manage_posts_columns' ) ); add_action( 'manage_posts_custom_column', array( $this, '_filter_manage_posts_custom_column' ) ); add_action( 'manage_pages_custom_column', array( $this, '_filter_manage_posts_custom_column' ) ); - // Add quick-edit author select field + // Add quick-edit guest author select field add_action( 'quick_edit_custom_box', array( $this, '_action_quick_edit_custom_box' ), 10, 2 ); // Hooks to modify the published post number count on the Users WP List Table @@ -225,7 +233,7 @@ public function is_guest_authors_enabled() { } /** - * Get a co-author object by a specific type of key + * Get a guest author object by a specific type of key * * @param string $key Key to search by (slug,email) * @param string $value Value to search for @@ -300,8 +308,8 @@ public function is_post_type_enabled( $post_type = null ) { } /** - * Removes the standard WordPress Author box. - * We don't need it because the Co-Authors one is way cooler. + * Removes the standard WordPress 'Author' box. + * We don't need it because the Co-Authors Plus one is way cooler. */ public function remove_authors_box() { @@ -311,7 +319,7 @@ public function remove_authors_box() { } /** - * Adds a custom Authors box + * Adds a custom 'Authors' box */ public function add_coauthors_box() { @@ -321,7 +329,7 @@ public function add_coauthors_box() { } /** - * Callback for adding the custom author box + * Callback for adding the custom 'authors' box */ public function coauthors_meta_box( $post ) { global $post, $coauthors_plus, $current_screen; @@ -406,7 +414,7 @@ function remove_quick_edit_authors_box() { } /** - * Add coauthors to author column on edit pages + * Add co-authors to author column on edit pages * * @param array $post_columns */ @@ -431,7 +439,7 @@ function _filter_manage_posts_columns( $posts_columns ) { } /** - * Insert coauthors into post rows on Edit Page + * Insert co-authors into post rows on Edit Page * * @param string $column_name */ @@ -518,7 +526,7 @@ function _action_quick_edit_custom_box( $column_name, $post_type ) { } /** - * When we update the terms at all, we should update the published post count for each author + * When we update the terms at all, we should update the published post count for each author and guest author */ function _update_users_posts_count( $tt_ids, $taxonomy ) { global $wpdb; @@ -872,7 +880,7 @@ function delete_user_action( $delete_id ) { if ( $reassign_id ) { // Get posts belonging to deleted author $reassign_user = get_user_by( 'id', $reassign_id ); - // Set to new author + // Set to new guest author if ( is_object( $reassign_user ) ) { $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $delete_id ) ); @@ -988,12 +996,12 @@ function current_user_can_set_authors( $post = null ) { /** * Fix for author pages 404ing or not properly displaying on author pages * - * If an author has no posts, we only want to force the queried object to be - * the author if they're a member of the blog. + * If a guest author has no posts, we only want to force the queried object to be + * the author if they're a user. * - * If the author does have posts, it doesn't matter that they're not an author. + * If the guest author does have posts, it doesn't matter that they're not an author. * - * Alternatively, on an author archive, if the first story has coauthors and + * Alternatively, on an author archive, if the first story has co-authors and * the first author is NOT the same as the author for the archive, * the query_var is changed. * @@ -1057,7 +1065,7 @@ public function filter_infinite_scroll_js_settings( $settings ) { } /** - * Main function that handles search-as-you-type for adding authors + * Main function that handles search-as-you-type for adding guest authors */ public function ajax_suggest() { @@ -1083,7 +1091,7 @@ public function ajax_suggest() { } /** - * Get matching authors based on a search value + * Get matching guest authors based on a search value */ public function search_authors( $search = '', $ignored_authors = array() ) { @@ -1127,7 +1135,7 @@ public function search_authors( $search = '', $ignored_authors = array() ) { return array(); } - // Get the co-author objects + // Get the guest author objects $found_users = array(); foreach ( $found_terms as $found_term ) { $found_user = $this->get_coauthor_by( 'user_nicename', $found_term->slug ); @@ -1278,7 +1286,7 @@ public function is_valid_page() { } /** - * Allows coauthors to edit the post they're coauthors of + * Allows guest authors to edit the post they're co-authors of */ function filter_user_has_cap( $allcaps, $caps, $args ) { @@ -1474,12 +1482,12 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { } /** - * Retrieve a list of coauthor terms for a single post. + * Retrieve a list of co-author terms for a single post. * * Grabs a correctly ordered list of authors for a single post, appropriately * cached because it requires `wp_get_object_terms()` to succeed. * - * @param int $post_id ID of the post for which to retrieve authors. + * @param int $post_id ID of the post for which to retrieve co-authors. * @return array Array of coauthor WP_Term objects */ public function get_coauthor_terms_for_post( $post_id ) { @@ -1679,7 +1687,7 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i } /** - * Retrieve a list of coauthor terms for a single post. + * Retrieve a list of co-author terms for a single post. * * Grabs a correctly ordered list of authors for a single post, appropriately * cached because it requires `wp_get_object_terms()` to succeed. From 8ba461182d574a6c08750fb7767c6356073598ad Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 1 Jun 2017 00:29:45 -0600 Subject: [PATCH 063/231] Removed continue because the script would stop running. --- php/class-wp-cli.php | 1 - 1 file changed, 1 deletion(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index e2d5ae71..881e23bf 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -79,7 +79,6 @@ public function create_terms_for_posts() { $terms = cap_get_coauthor_terms_for_post( $single_post->ID ); if ( empty( $terms ) ) { WP_CLI::line( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) ); - continue; } if ( ! empty( $terms ) ) { From 4c23011ed1f3160c9ed770ba6f209accea0dcf74 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 1 Jun 2017 12:58:32 -0600 Subject: [PATCH 064/231] Added better consistencies with glossary --- co-authors-plus.php | 34 +++++++++++----------- js/co-authors-plus.js | 42 +++++++++++++-------------- php/class-coauthors-guest-authors.php | 9 +++--- php/class-coauthors-wp-list-table.php | 4 +-- php/class-wp-cli.php | 8 ++--- 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index d96fe511..723010c7 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -207,7 +207,7 @@ public function admin_init() { add_action( 'manage_posts_custom_column', array( $this, '_filter_manage_posts_custom_column' ) ); add_action( 'manage_pages_custom_column', array( $this, '_filter_manage_posts_custom_column' ) ); - // Add quick-edit guest author select field + // Add quick-edit co-author select field add_action( 'quick_edit_custom_box', array( $this, '_action_quick_edit_custom_box' ), 10, 2 ); // Hooks to modify the published post number count on the Users WP List Table @@ -329,7 +329,7 @@ public function add_coauthors_box() { } /** - * Callback for adding the custom 'authors' box + * Callback for adding the custom 'Authors' box */ public function coauthors_meta_box( $post ) { global $post, $coauthors_plus, $current_screen; @@ -403,7 +403,7 @@ public function coauthors_meta_box( $post ) { } /** - * Removes the author dropdown from the post quick edit + * Removes the default 'author' dropdown from quick edit */ function remove_quick_edit_authors_box() { global $pagenow; @@ -414,7 +414,7 @@ function remove_quick_edit_authors_box() { } /** - * Add co-authors to author column on edit pages + * Add co-authors to 'authors' column on edit pages * * @param array $post_columns */ @@ -526,7 +526,7 @@ function _action_quick_edit_custom_box( $column_name, $post_type ) { } /** - * When we update the terms at all, we should update the published post count for each author and guest author + * When we update the terms at all, we should update the published post count for each user */ function _update_users_posts_count( $tt_ids, $taxonomy ) { global $wpdb; @@ -670,7 +670,7 @@ function posts_where_filter( $where, $query ) { if ( $author_term = $this->get_author_term( $coauthor ) ) { $terms[] = $author_term; } - // If this coauthor has a linked account, we also need to get posts with those terms + // If this co-author has a linked account, we also need to get posts with those terms if ( ! empty( $coauthor->linked_account ) ) { $linked_account = get_user_by( 'login', $coauthor->linked_account ); if ( $guest_author_term = $this->get_author_term( $linked_account ) ) { @@ -753,7 +753,7 @@ function coauthors_set_post_author_field( $data, $postarr ) { } } - // If for some reason we don't have the coauthors fields set + // If for some reason we don't have the co-authors fields set if ( ! isset( $data['post_author'] ) ) { $user = wp_get_current_user(); $data['post_author'] = $user->ID; @@ -830,7 +830,7 @@ public function add_coauthors( $post_id, $coauthors, $append = false ) { $coauthors = array( $current_user->user_login ); } - // Set the coauthors + // Set the co-authors $coauthors = array_unique( array_merge( $existing_coauthors, $coauthors ) ); $coauthor_objects = array(); foreach ( $coauthors as &$author_name ) { @@ -866,9 +866,9 @@ public function add_coauthors( $post_id, $coauthors, $append = false ) { } /** - * Action taken when user is deleted. - * - User term is removed from all associated posts - * - Option to specify alternate user in place for each post + * Action taken when co-author is deleted. + * - Co-Author term is removed from all associated posts + * - Option to specify alternate co-author in place for each post * @param delete_id */ function delete_user_action( $delete_id ) { @@ -900,7 +900,7 @@ function delete_user_action( $delete_id ) { } /** - * Restrict WordPress from blowing away author order when bulk editing terms + * Restrict WordPress from blowing away co-author order when bulk editing terms * * @since 2.6 * @props kingkool68, http://wordpress.org/support/topic/plugin-co-authors-plus-making-authors-sortable @@ -959,7 +959,7 @@ function filter_count_user_posts( $count, $user_id ) { } /** - * Checks to see if the current user can set authors or not + * Checks to see if the current user can set co-authors or not */ function current_user_can_set_authors( $post = null ) { global $typenow; @@ -1065,7 +1065,7 @@ public function filter_infinite_scroll_js_settings( $settings ) { } /** - * Main function that handles search-as-you-type for adding guest authors + * Main function that handles search-as-you-type for adding co-authors */ public function ajax_suggest() { @@ -1091,7 +1091,7 @@ public function ajax_suggest() { } /** - * Get matching guest authors based on a search value + * Get matching co-authors based on a search value */ public function search_authors( $search = '', $ignored_authors = array() ) { @@ -1482,9 +1482,9 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { } /** - * Retrieve a list of co-author terms for a single post. + * Retrieve a list of author terms for a single post. * - * Grabs a correctly ordered list of authors for a single post, appropriately + * Grabs a correctly ordered list of co-authors for a single post, appropriately * cached because it requires `wp_get_object_terms()` to succeed. * * @param int $post_id ID of the post for which to retrieve co-authors. diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 7691f91b..8950c61d 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -39,9 +39,9 @@ jQuery( document ).ready(function () { } /* - * Save coauthor - * @param int Author ID - * @param string Author Name + * Save co-author + * @param int Co-Author ID + * @param string Co-Author Name * @param object The autosuggest input box */ function coauthors_save_coauthor( author, co ) { @@ -59,8 +59,8 @@ jQuery( document ).ready(function () { /* - * Add coauthor - * @param string Author Name + * Add co-author + * @param string Co-Author Name * @param object The autosuggest input box * @param boolean Initial set up or not? */ @@ -70,11 +70,11 @@ jQuery( document ).ready(function () { if ( co && co.siblings( '.coauthor-tag' ).length ) { coauthors_save_coauthor( author, co ); } else { - // Not editing, so we create a new author entry + // Not editing, so we create a new co-author entry if ( count == 0 ) { var coName = ( count == 0 ) ? 'coauthors-main' : ''; - // Add new author to + //coauthors_select_author( co-author ); } var options = { addDelete: true, addEdit: false }; @@ -98,7 +98,7 @@ jQuery( document ).ready(function () { co.bind( 'blur', coauthors_stop_editing ); - // Set the value for the auto-suggest box to the Author's name and hide it + // Set the value for the auto-suggest box to the co-author's name and hide it co.val( unescape( author.name ) ) .hide() .unbind( 'focus' ) @@ -132,8 +132,8 @@ jQuery( document ).ready(function () { } /* - * Adds a delete and edit button next to an author - * @param object The row to which the new author should be added + * Adds a delete and edit button next to a co-author + * @param object The row to which the new co-author should be added */ function coauthors_insert_author_edit_cells( $div, options ){ @@ -156,7 +156,7 @@ jQuery( document ).ready(function () { /* * Creates autosuggest input box - * @param string [optional] Name of the author + * @param string [optional] Name of the co-author * @param string [optional] Name to be applied to the input box */ function coauthors_create_autosuggest( authorName, inputName ) { @@ -189,7 +189,7 @@ jQuery( document ).ready(function () { } - // Callback for when a user selects an author + // Callback for when a user selects a co-author function coauthors_autosuggest_select() { $this = jQuery( this ); var vals = this.value.split( '|' ); @@ -234,8 +234,8 @@ jQuery( document ).ready(function () { } /* - * Creates the text tag for an author - * @param string Name of the author + * Creates the text tag for a co-author + * @param string Name of the co-author */ function coauthors_create_author_tag( author ) { @@ -278,8 +278,8 @@ jQuery( document ).ready(function () { } /* - * Creates the text tag for an author - * @param string Name of the author + * Creates the text tag for a co-author + * @param string Name of the co-author */ function coauthors_create_author_hidden_input ( author ) { var input = jQuery( '' ) @@ -319,7 +319,7 @@ jQuery( document ).ready(function () { $coauthors_div.append( table ); } - // Select authors already added to the post + // Select co-authors already added to the post var addedAlready = []; //jQuery('#the-list tr').each(function(){ var count = 0; @@ -341,7 +341,7 @@ jQuery( document ).ready(function () { move_loading( newCO ); - // Make co-authors sortable so an editor can control the order of the authors + // Make co-authors sortable so an editor can control the order of the co-authors jQuery( '#coauthors-edit' ).ready(function( $ ) { $( '#coauthors-list' ).sortable({ axis: 'y', @@ -398,7 +398,7 @@ jQuery( document ).ready(function () { }); } - // Remove the read-only coauthors so we don't get craziness + // Remove the read-only co-authors so we don't get craziness jQuery( '#coauthors-readonly' ).remove(); coauthors_initialize( post_coauthors ); } @@ -425,7 +425,7 @@ jQuery( document ).ready(function () { var el = jQuery( '.inline-edit-group.inline-edit-coauthors', '#edit-' + postId ); el.detach().appendTo( '.quick-edit-row .inline-edit-col-left .inline-edit-col' ).show(); - // initialize coauthors + // initialize co-authors var post_coauthors = jQuery.map( jQuery( '.column-coauthors a', $postRow ), function( el ) { return { login: jQuery( el ).data( 'user_login' ), diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 5c322ed0..3c351884 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -91,7 +91,7 @@ function __construct() { 'metabox_about' => __( 'About the guest author', 'co-authors-plus' ), ) ); - // Register a post type to store our authors that aren't WP.com users + // Register a post type to store our guest authors $args = array( 'label' => $this->labels['singular'], 'labels' => array( @@ -177,7 +177,7 @@ function filter_post_updated_messages( $messages ) { /** * Handle the admin action to create a guest author based - * on an existing WordPress user + * on an existing user * * @since 3.0 */ @@ -592,7 +592,7 @@ public function filter_wp_dropdown_users_to_disable( $output ) { } /** - * Metabox to display all of the pertient names for a Guest Author without a user account + * Metabox to display all of the pertient names for a Guest Author not linked to user account * * @since 3.0 */ @@ -627,7 +627,8 @@ function metabox_manage_guest_author_name() { } /** - * Metabox to display all of the pertient contact details for a Guest Author without a user account + * Metabox to display all of the pertient contact details for a Guest Author not linked to + * user account * * @since 3.0 */ diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index 552f6db0..497fe623 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -137,10 +137,10 @@ function filter_query_for_search( $where ) { } /** - * Either there are no guest authors, or the search doesn't match any + * Either there are no co-authors, or the search doesn't match any */ function no_items() { - esc_html_e( 'No matching guest authors were found.', 'co-authors-plus' ); + esc_html_e( 'No matching co-authors were found.', 'co-authors-plus' ); } /** diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 568f988e..f3db0f34 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -115,7 +115,7 @@ public function create_terms_for_posts() { } /** - * Subcommand to assign coauthors to a post based on a given meta key + * Subcommand to assign co-authors to a post based on a given meta key * * @since 3.0 * @@ -408,8 +408,8 @@ public function rename_coauthor( $args, $assoc_args ) { } /** - * Swap one Co Author with another on all posts for which they are an author. Unlike rename-coauthor, - * this leaves the original Co Author term intact and works when the 'to' user already has a co-author term. + * Swap one co-author with another on all posts for which they are a co-author. Unlike rename-coauthor, + * this leaves the original co-author term intact and works when the 'to' user already has a co-author term. * * @subcommand swap-coauthors * @synopsis --from= --to= [--post_type=] [--dry=] @@ -611,7 +611,7 @@ public function migrate_author_terms( $args, $assoc_args ) { } /** - * Update the post count and description for each author + * Update the post count and description for each author and guest author * * @since 3.0 * From 586dcdc7ffb199b5e7590834e7781854e9d27a89 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 1 Jun 2017 14:08:28 -0700 Subject: [PATCH 065/231] Revert "Revert "Update version constant"" This reverts commit 5ac7d9a2288d49db6462a98d9211dfa42480a0f7. --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index cfa52988..ddbea3f3 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -24,7 +24,7 @@ */ -define( 'COAUTHORS_PLUS_VERSION', '3.2.1' ); +define( 'COAUTHORS_PLUS_VERSION', '3.2.2' ); require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); From 1a272fa87fcb7c419cd152eb144333a2b7cff7db Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 1 Jun 2017 21:21:38 -0600 Subject: [PATCH 066/231] doesn't return false after quick edit saves --- co-authors-plus.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 47623668..3a2318ab 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -293,12 +293,10 @@ public function get_coauthor_by( $key, $value, $force = false ) { public function is_post_type_enabled( $post_type = null ) { if ( ! $post_type ) { - if ( is_admin() ) { + $post_type = get_post_type(); + if ( is_admin() && ! $post_type) { $post_type = get_current_screen()->post_type; } - else { - $post_type = get_post_type(); - } } return (bool) in_array( $post_type, $this->supported_post_types ); From 84d8394244fcea9780c5f5b8cb46099f48299479 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 2 Jun 2017 13:44:34 -0600 Subject: [PATCH 067/231] replaced hardcoded 'author' with $this->coauthor_taxonomy --- co-authors-plus.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ddbea3f3..def93c51 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -174,7 +174,7 @@ public function action_init_late() { $post_types_with_authors = array_values( get_post_types() ); foreach ( $post_types_with_authors as $key => $name ) { - if ( ! post_type_supports( $name, 'author' ) || in_array( $name, array( 'revision', 'attachment' ) ) ) { + if ( ! post_type_supports( $name, $this->coauthor_taxonomy ) || in_array( $name, array( 'revision', 'attachment' ) ) ) { unset( $post_types_with_authors[ $key ] ); } } @@ -401,7 +401,7 @@ function remove_quick_edit_authors_box() { global $pagenow; if ( 'edit.php' == $pagenow && $this->is_post_type_enabled() ) { - remove_post_type_support( get_post_type(), 'author' ); + remove_post_type_support( get_post_type(), $this->coauthor_taxonomy ); } } @@ -423,7 +423,7 @@ function _filter_manage_posts_columns( $posts_columns ) { $new_columns['coauthors'] = __( 'Authors', 'co-authors-plus' ); } - if ( 'author' === $key ) { + if ( $this->coauthor_taxonomy === $key ) { unset( $new_columns[ $key ] ); } } @@ -649,7 +649,7 @@ function posts_where_filter( $where, $query ) { if ( $query->get( 'author_name' ) ) { $author_name = sanitize_title( $query->get( 'author_name' ) ); } else { - $author_data = get_userdata( $query->get( 'author' ) ); + $author_data = get_userdata( $query->get( $this->coauthor_taxonomy ) ); if ( is_object( $author_data ) ) { $author_name = $author_data->user_nicename; } else { @@ -898,8 +898,7 @@ function delete_user_action( $delete_id ) { * @props kingkool68, http://wordpress.org/support/topic/plugin-co-authors-plus-making-authors-sortable */ function filter_wp_get_object_terms( $terms, $object_ids, $taxonomies, $args ) { - - if ( ! isset( $_REQUEST['bulk_edit'] ) || "'author'" !== $taxonomies ) { + if ( ! isset( $_REQUEST['bulk_edit'] ) || $this->coauthor_taxonomy !== $taxonomies ) { return $terms; } @@ -1048,7 +1047,7 @@ public function filter_infinite_scroll_js_settings( $settings ) { $author = get_queried_object(); if ( $author && 'guest-author' == $author->type ) { - unset( $settings['query_args']['author'] ); + unset( $settings['query_args'][$this->coauthor_taxonomy] ); $settings['query_args']['author_name'] = $author->user_nicename; } @@ -1397,19 +1396,19 @@ public function update_author_term( $coauthor ) { function filter_ef_calendar_item_information_fields( $information_fields, $post_id ) { // Don't add the author row again if another plugin has removed - if ( ! array_key_exists( 'author', $information_fields ) ) { + if ( ! array_key_exists( $this->coauthor_taxonomy, $information_fields ) ) { return $information_fields; } $co_authors = get_coauthors( $post_id ); if ( count( $co_authors ) > 1 ) { - $information_fields['author']['label'] = __( 'Authors', 'co-authors-plus' ); + $information_fields[$this->coauthor_taxonomy]['label'] = __( 'Authors', 'co-authors-plus' ); } $co_authors_names = ''; foreach ( $co_authors as $co_author ) { $co_authors_names .= $co_author->display_name . ', '; } - $information_fields['author']['value'] = rtrim( $co_authors_names, ', ' ); + $information_fields[$this->coauthor_taxonomy]['value'] = rtrim( $co_authors_names, ', ' ); return $information_fields; } @@ -1426,7 +1425,7 @@ function filter_ef_calendar_item_information_fields( $information_fields, $post_ function filter_ef_story_budget_term_column_value( $column_name, $post, $parent_term ) { // We only want to modify the 'author' column - if ( 'author' != $column_name ) { + if ( $this->coauthor_taxonomy != $column_name ) { return $column_name; } From 5206a534792c50a286a5dc77a5f342d9de0498e6 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 8 Jun 2017 15:04:01 +0100 Subject: [PATCH 068/231] Tested tag to 4.8 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index ba030853..bfe56edf 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Co-Authors Plus === Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.7.3 +Tested up to: 4.8 Requires at least: 4.1 Stable tag: 3.2.2 From 830987be9663655c4072de25836e6cb55dd07fe3 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Tue, 27 Jun 2017 16:35:35 -0700 Subject: [PATCH 069/231] Move parenthesis to fix esc_html and sprintf Fixes warning: `Warning: sprintf(): Too few arguments in /path/wp-content/plugins/co-authors-plus/php/class-coauthors-guest-authors.php on line 487` Warning surfaces when deleting a guest author that is mapped to a WP user --- php/class-coauthors-guest-authors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 3c351884..a5c3c470 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -484,7 +484,7 @@ function view_guest_authors_list() { // Leave mapped to a linked account if ( get_user_by( 'login', $guest_author->linked_account ) ) { echo '
  • '; } // Remove bylines from the posts From 06c123de5cdaaca865f7b22f2f128c0167a97217 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 27 Jun 2017 18:42:37 -0600 Subject: [PATCH 070/231] Added progress so users have an idea of how long it will take --- php/class-wp-cli.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index cc448dca..537c51a5 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -36,6 +36,9 @@ public function create_guest_authors( $args, $assoc_args ) { } else { $created++; } + WP_CLI::line( '# Processed ' . ( $created + $skipped ) . ' out of ' . count( $users ) . ' users.' ); + $percent = number_format( ( ( $created + $skipped ) / count( $users ) * 100 ), 2 ); + WP_CLI::line( "--- {$percent}% complete!" ); } WP_CLI::line( 'All done! Here are your results:' ); From b91e7d4828195df95e8a9a0b217a850eb025b2f1 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 12:07:01 -0600 Subject: [PATCH 071/231] Added a better style of progress bar! --- php/class-wp-cli.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 537c51a5..c44ca8f8 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -28,6 +28,7 @@ public function create_guest_authors( $args, $assoc_args ) { $users = get_users(); $created = 0; $skipped = 0; + $progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) ); foreach ( $users as $user ) { $result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID ); @@ -36,15 +37,12 @@ public function create_guest_authors( $args, $assoc_args ) { } else { $created++; } - WP_CLI::line( '# Processed ' . ( $created + $skipped ) . ' out of ' . count( $users ) . ' users.' ); - $percent = number_format( ( ( $created + $skipped ) / count( $users ) * 100 ), 2 ); - WP_CLI::line( "--- {$percent}% complete!" ); + $progress->tick(); } - + $progress->finish(); WP_CLI::line( 'All done! Here are your results:' ); WP_CLI::line( "- {$created} guest author profiles were created" ); WP_CLI::line( "- {$skipped} users already had guest author profiles" ); - } /** From d404fec87d221e470878483e9f58023dbff97e53 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 14:46:31 -0600 Subject: [PATCH 072/231] Deleting guest authors is less confusing --- php/class-coauthors-guest-authors.php | 61 ++++++++++++++++++++------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 3c351884..2dd1678e 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -463,13 +463,34 @@ function view_guest_authors_list() { wp_die( esc_html( sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $this->labels['singular'] ) ) ); } + // get post count + global $coauthors_plus; + $term = $coauthors_plus->get_author_term( $guest_author ); + if ( $term ) { + $count = $term->count; + } else { + $count = 0; + } + echo '
    '; echo '

    '; echo '

    ' . esc_html( sprintf( __( 'Delete %s', 'co-authors-plus ' ), $this->labels['plural'] ) ) . '

    '; echo '

    ' . esc_html( sprintf( __( 'You have specified this %s for deletion:', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '

    '; echo '

    #' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '

    '; - echo '

    ' . esc_html( sprintf( __( 'What should be done with posts assigned to this %s?', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '

    '; - echo '

    ' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '

    '; + + if ( $count === 0 ) { + $post_count_message = '

    ' . esc_html( sprintf( __( 'There are %d posts associated with this guest author.', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + } + else if ( $count === 1 ) { + $post_count_message = '

    ' . esc_html( sprintf( __( 'There is %d post associated with this guest author. What should be done with the post assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + } + else { + $post_count_message = '

    ' . esc_html( sprintf( __( 'There are %d posts associated with this guest author. What should be done with the posts assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + } + echo $post_count_message; + if ( $count > 0 ) { + echo '

    ' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '

    '; + } echo '
    '; // Hidden stuffs echo ''; @@ -477,22 +498,30 @@ function view_guest_authors_list() { echo ''; echo '
      '; // Reassign to another user - echo '
    • '; - echo ''; - echo '
    • '; - // Leave mapped to a linked account - if ( get_user_by( 'login', $guest_author->linked_account ) ) { - echo '
    • '; + if ( $count > 0 ) { + echo '
    • '; + echo ''; + echo '
    • '; + // Leave mapped to a linked account + if ( get_user_by( 'login', $guest_author->linked_account ) ) { + echo '
    • '; + } + // Remove bylines from the posts + echo '  ' . esc_html__( 'Remove byline from posts (but leave each post in its current status).', 'co-authors-plus' ); + } + else { + echo ''; } - // Remove bylines from the posts - echo '
    • '; echo '
    '; - submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) ); + if ( $count === 0 ) { + submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true ); + } + else { + submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) ); + } echo '
    '; echo '
    '; } else { From 19d94b9d77d8199c5b1daae43b416fb4b39ee6de Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 15:47:57 -0600 Subject: [PATCH 073/231] Fixed merge conflicts --- php/class-coauthors-guest-authors.php | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 2dd1678e..06e49628 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -477,28 +477,30 @@ function view_guest_authors_list() { echo '

    ' . esc_html( sprintf( __( 'Delete %s', 'co-authors-plus ' ), $this->labels['plural'] ) ) . '

    '; echo '

    ' . esc_html( sprintf( __( 'You have specified this %s for deletion:', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '

    '; echo '

    #' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '

    '; - - if ( $count === 0 ) { - $post_count_message = '

    ' . esc_html( sprintf( __( 'There are %d posts associated with this guest author.', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; - } - else if ( $count === 1 ) { - $post_count_message = '

    ' . esc_html( sprintf( __( 'There is %d post associated with this guest author. What should be done with the post assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + // display wording differently per post count + if ( 0 === $count ) { + $post_count_message = '

    ' . esc_html( sprintf( __( 'There are no posts associated with this guest author.', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '

    '; } else { - $post_count_message = '

    ' . esc_html( sprintf( __( 'There are %d posts associated with this guest author. What should be done with the posts assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + $note = '

    ' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '

    '; + if ( 1 === $count ) { + $post_count_message = '

    ' . esc_html( sprintf( __( 'There is %d post associated with this guest author. What should be done with the post assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + } + else { + $post_count_message = '

    ' . esc_html( sprintf( __( 'There are %d posts associated with this guest author. What should be done with the posts assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + } + $post_count_message .= $note; } echo $post_count_message; - if ( $count > 0 ) { - echo '

    ' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '

    '; - } echo '
    '; // Hidden stuffs echo ''; wp_nonce_field( 'delete-guest-author' ); echo ''; echo '
      '; - // Reassign to another user + // show delete options if posts are > 0 if ( $count > 0 ) { + // Reassign to another user echo '
    • '; echo ''; @@ -506,17 +508,19 @@ function view_guest_authors_list() { // Leave mapped to a linked account if ( get_user_by( 'login', $guest_author->linked_account ) ) { echo '
    • '; } // Remove bylines from the posts - echo '  ' . esc_html__( 'Remove byline from posts (but leave each post in its current status).', 'co-authors-plus' ); + echo '
    • '; } else { - echo ''; + echo ''; } echo '
    '; - if ( $count === 0 ) { + if ( 0 === $count ) { submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true ); } else { From 3380114e97fb2e6fe6bff245867fbc90a198dcb7 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 15:52:09 -0600 Subject: [PATCH 074/231] Hopefully now merge conflict is gone now... --- php/class-coauthors-guest-authors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 06e49628..d90a39d0 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -508,7 +508,7 @@ function view_guest_authors_list() { // Leave mapped to a linked account if ( get_user_by( 'login', $guest_author->linked_account ) ) { echo '
  • '; } // Remove bylines from the posts From e80cb473f7a8571aed1befd5d3505ab5e0c74e17 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 16:02:36 -0600 Subject: [PATCH 075/231] some extra notes. --- php/class-coauthors-guest-authors.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index d90a39d0..c48370df 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -498,7 +498,7 @@ function view_guest_authors_list() { wp_nonce_field( 'delete-guest-author' ); echo ''; echo '
      '; - // show delete options if posts are > 0 + // only show delete options if post count > 0 if ( $count > 0 ) { // Reassign to another user echo '
    '; + // disable disabled submit button for 0 post count if ( 0 === $count ) { submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true ); } From 5433e372e9324a02a04d2cfd97757a990a97b764 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 18:23:34 -0600 Subject: [PATCH 076/231] featured image to avatar --- php/class-coauthors-guest-authors.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index a5c3c470..36b0aecd 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -89,6 +89,10 @@ function __construct() { 'not_found_in_trash' => __( 'No guest authors found in Trash', 'co-authors-plus' ), 'update_item' => __( 'Update Guest Author', 'co-authors-plus' ), 'metabox_about' => __( 'About the guest author', 'co-authors-plus' ), + 'featured_image' => __( 'Avatar', 'co-authors-plus' ), + 'set_featured_image' => __( 'Set Avatar', 'co-authors-plus' ), + 'use_featured_image' => __( 'Use Avatar', 'co-authors-plus' ), + 'remove_featured_image' => __( 'Remove Avatar', 'co-authors-plus' ), ) ); // Register a post type to store our guest authors @@ -106,6 +110,10 @@ function __construct() { 'search_items' => $this->labels['search_items'], 'not_found' => $this->labels['not_found'], 'not_found_in_trash' => $this->labels['not_found_in_trash'], + 'featured_image' => $this->labels['featured_image'], + 'set_featured_image' => $this->labels['set_featured_image'], + 'use_featured_image' => $this->labels['use_featured_image'], + 'remove_featured_image' => $this->labels['remove_featured_image'] ), 'public' => true, 'publicly_queryable' => false, From e0902c05a1787ebbfc133d11bf243a9393d9dd61 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 10:00:21 -0600 Subject: [PATCH 077/231] Removed avatar sizing --- php/class-coauthors-guest-authors.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index a5c3c470..a03afc06 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -123,17 +123,7 @@ function __construct() { register_post_type( $this->post_type, $args ); // Some of the common sizes used by get_avatar - $this->avatar_sizes = array( - 32, - 50, - 64, - 96, - 128, - ); - $this->avatar_sizes = apply_filters( 'coauthors_guest_author_avatar_sizes', $this->avatar_sizes ); - foreach ( $this->avatar_sizes as $size ) { - add_image_size( 'guest-author-' . $size, $size, $size, true ); - } + $this->avatar_sizes = array(); // Hacky way to remove the title and the editor remove_post_type_support( $this->post_type, 'title' ); @@ -932,11 +922,8 @@ function get_guest_author_thumbnail( $guest_author, $size ) { $args = array( 'class' => "avatar avatar-{$size} photo", ); - if ( in_array( $size, $this->avatar_sizes ) ) { - $size = 'guest-author-' . $size; - } else { - $size = array( $size, $size ); - } + + $size = array( $size, $size ); $thumbnail = get_the_post_thumbnail( $guest_author->ID, $size, $args ); From b5fd5d5b1f2249ec56aa65a97113c4bf861e7bfd Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 14:41:20 -0600 Subject: [PATCH 078/231] remove duplicated linked author byline --- template-tags.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/template-tags.php b/template-tags.php index ffc398ae..8993984a 100644 --- a/template-tags.php +++ b/template-tags.php @@ -35,6 +35,8 @@ function get_coauthors( $post_id = 0 ) { } } // the empty else case is because if we force guest authors, we don't ever care what value wp_posts.post_author has. } + // remove duplicate $coauthors objects from mapping user accounts to guest authors accounts + $coauthors = array_unique( $coauthors, SORT_REGULAR ); return $coauthors; } From 9b57a4344c75e0825e5a30118721ae6a9f94cef9 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 16:56:10 -0600 Subject: [PATCH 079/231] coauthors_wp_list_authors has the option now of listing only guest authors --- template-tags.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/template-tags.php b/template-tags.php index ffc398ae..d63a1720 100644 --- a/template-tags.php +++ b/template-tags.php @@ -448,6 +448,7 @@ function coauthors_wp_list_authors( $args = array() ) { 'style' => 'list', 'html' => true, 'number' => 20, // A sane limit to start to avoid breaking all the things + 'guest_authors_only' => false ); $args = wp_parse_args( $args, $defaults ); @@ -472,6 +473,17 @@ function coauthors_wp_list_authors( $args = array() ) { } $authors = apply_filters( 'coauthors_wp_list_authors_array', $authors ); + + // only show guest authors if the $args is set to true + if ( $args['guest_authors_only'] ) { + $guest_authors = []; + foreach ( $authors as $author ) { + if ( $author->type === 'guest-author' ) { + $guest_authors[] = $author; + } + } + $authors = $guest_authors; + } foreach ( (array) $authors as $author ) { From 9f641543b3826701e097dcf77eb13414ccd9926d Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 4 Jul 2017 13:09:24 -0600 Subject: [PATCH 080/231] remove duplicates from linked accounts --- template-tags.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/template-tags.php b/template-tags.php index ffc398ae..e9754619 100644 --- a/template-tags.php +++ b/template-tags.php @@ -473,6 +473,12 @@ function coauthors_wp_list_authors( $args = array() ) { $authors = apply_filters( 'coauthors_wp_list_authors_array', $authors ); + // remove duplicates from linked accounts + $linked_accounts = array_unique( array_column( $authors, 'linked_account' ) ); + foreach ( $linked_accounts as $linked_account ) { + unset( $authors[$linked_account] ); + } + foreach ( (array) $authors as $author ) { $link = ''; From f4791d007a1209ff04ec1ac8cd78aa9b1454b6b2 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 4 Jul 2017 17:14:05 -0600 Subject: [PATCH 081/231] changes as per philipjoin --- template-tags.php | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/template-tags.php b/template-tags.php index d63a1720..2b7a8171 100644 --- a/template-tags.php +++ b/template-tags.php @@ -438,16 +438,16 @@ function coauthors_wp_list_authors( $args = array() ) { global $coauthors_plus; $defaults = array( - 'optioncount' => false, - 'show_fullname' => false, - 'hide_empty' => true, - 'feed' => '', - 'feed_image' => '', - 'feed_type' => '', - 'echo' => true, - 'style' => 'list', - 'html' => true, - 'number' => 20, // A sane limit to start to avoid breaking all the things + 'optioncount' => false, + 'show_fullname' => false, + 'hide_empty' => true, + 'feed' => '', + 'feed_image' => '', + 'feed_type' => '', + 'echo' => true, + 'style' => 'list', + 'html' => true, + 'number' => 20, // A sane limit to start to avoid breaking all the things 'guest_authors_only' => false ); @@ -460,6 +460,7 @@ function coauthors_wp_list_authors( $args = array() ) { 'number' => (int) $args['number'], ); $author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args ); + $authors = array(); foreach ( $author_terms as $author_term ) { // Something's wrong in the state of Denmark @@ -469,21 +470,16 @@ function coauthors_wp_list_authors( $args = array() ) { $authors[ $author_term->name ] = $coauthor; - $authors[ $author_term->name ]->post_count = $author_term->count; + // only show guest authors if the $args is set to true + if ( ! $args['guest_authors_only'] || $authors[ $author_term->name ]->type === 'guest-author' ) { + $authors[ $author_term->name ]->post_count = $author_term->count; + } + else { + unset( $authors[ $author_term->name ] ); + } } $authors = apply_filters( 'coauthors_wp_list_authors_array', $authors ); - - // only show guest authors if the $args is set to true - if ( $args['guest_authors_only'] ) { - $guest_authors = []; - foreach ( $authors as $author ) { - if ( $author->type === 'guest-author' ) { - $guest_authors[] = $author; - } - } - $authors = $guest_authors; - } foreach ( (array) $authors as $author ) { From 3fbbebc77c7c589334b4116f2bce515ad6c0af84 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 4 Jul 2017 20:59:53 -0600 Subject: [PATCH 082/231] Added later escaping --- php/class-coauthors-guest-authors.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index c48370df..9752d4e5 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -479,19 +479,24 @@ function view_guest_authors_list() { echo '

    #' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '

    '; // display wording differently per post count if ( 0 === $count ) { - $post_count_message = '

    ' . esc_html( sprintf( __( 'There are no posts associated with this guest author.', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '

    '; + $post_count_message = '

    ' . sprintf( __( 'There are no posts associated with this guest author.', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) . '

    '; } else { - $note = '

    ' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '

    '; + $note = '

    ' . sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) . '

    '; if ( 1 === $count ) { - $post_count_message = '

    ' . esc_html( sprintf( __( 'There is %d post associated with this guest author. What should be done with the post assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + $post_count_message = '

    ' . sprintf( __( 'There is %d post associated with this guest author. What should be done with the post assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) . '

    '; } else { - $post_count_message = '

    ' . esc_html( sprintf( __( 'There are %d posts associated with this guest author. What should be done with the posts assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '

    '; + $post_count_message = '

    ' . sprintf( __( 'There are %d posts associated with this guest author. What should be done with the posts assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) . '

    '; } $post_count_message .= $note; } - echo $post_count_message; + $allowed_html = array( + 'p' => array( + 'class' => array(), + ), + ); + echo wp_kses( $post_count_message, $allowed_html ); echo ''; // Hidden stuffs echo ''; From c281135c8f2054917875868a65658f325eb02177 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 11:23:02 -0600 Subject: [PATCH 083/231] Use linked account for accurate post count --- co-authors-plus.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 9c1661e8..d956a640 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1344,11 +1344,17 @@ public function get_author_term( $coauthor ) { if ( false !== ( $term = wp_cache_get( $cache_key, 'co-authors-plus' ) ) ) { return $term; } - - // See if the prefixed term is available, otherwise default to just the nicename - $term = get_term_by( 'slug', 'cap-' . $coauthor->user_nicename, $this->coauthor_taxonomy ); - if ( ! $term ) { - $term = get_term_by( 'slug', $coauthor->user_nicename, $this->coauthor_taxonomy ); + + // use linked user for accurate post count + if ( ! empty ( $coauthor->linked_account ) ) { + $term = get_term_by( 'slug', 'cap-' . $coauthor->linked_account, $this->coauthor_taxonomy ); + } + else { + // See if the prefixed term is available, otherwise default to just the nicename + $term = get_term_by( 'slug', 'cap-' . $coauthor->user_nicename, $this->coauthor_taxonomy ); + if ( ! $term ) { + $term = get_term_by( 'slug', $coauthor->user_nicename, $this->coauthor_taxonomy ); + } } wp_cache_set( $cache_key, $term, 'co-authors-plus' ); return $term; From 863a6e67aefac38208c3d404f7fda504ddb2f650 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 12:04:27 -0600 Subject: [PATCH 084/231] Redid README.md with better markdown formatting --- readme.txt => README.md | 167 ++++++++++++++++++++-------------------- 1 file changed, 84 insertions(+), 83 deletions(-) rename readme.txt => README.md (71%) diff --git a/readme.txt b/README.md similarity index 71% rename from readme.txt rename to README.md index bfe56edf..3e0ef6c4 100644 --- a/readme.txt +++ b/README.md @@ -1,13 +1,14 @@ -=== Co-Authors Plus === -Contributors: batmoo, danielbachhuber, automattic -Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.8 -Requires at least: 4.1 -Stable tag: 3.2.2 +# Co-Authors Plus + +* Contributors: batmoo, danielbachhuber, automattic +* Tags: authors, users, multiple authors, coauthors, multi-author, publishing +* Tested up to: 4.8 +* Requires at least: 4.1 +* Stable tag: 3.2.2 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box -== Description == +## Description Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box. Co-authored posts appear on a co-author's archive page and in their feed. Co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is core behavior). @@ -17,68 +18,68 @@ On the frontend, use the [Co-Authors Plus template tags](http://vip.wordpress.co This plugin is an almost complete rewrite of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/) (2007). The original plugin was inspired by the 'Multiple Authors' plugin by Mark Jaquith (2005). -== Frequently Asked Questions == +## Frequently Asked Questions -= How do I add Co-Authors Plus support to my theme? = +* How do I add Co-Authors Plus support to my theme? -If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. +> If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. -= What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = +* What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = -When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. +> When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. -= Can I use Co-Authors Plus with WordPress multisite? = +* Can I use Co-Authors Plus with WordPress multisite? = -Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. +> Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. -= Who needs permission to do what? = +* Who needs permission to do what? -To assign co-authors to posts, a WordPress user will need the 'edit_others_posts' capability. This is typically granted to the Editor role, but can be altered with the 'coauthors_plus_edit_authors' filter. +> To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. -To create new guest author profiles, a WordPress will need the 'list_users' capability. This is typically granted to the Administrator role, but can be altered with the 'coauthors_guest_author_manage_cap' filter. +> To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. -= Can I easily create a list of all co-authors? = +* Can I easily create a list of all co-authors? -Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. +> Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. -== Upgrade Notice == +## Upgrade Notice -= 3.1 = +**3.1** Manage co-authors from quick edit, Jetpack Open Graph support, bug fixes. -= 3.0.7 = +**3.0.7** Support for symlink installations, updated French translation, bug fixes. -= 3.0.4 = +**3.0.4** Bug fixes and the ability to automatically add co-authors to your feeds. -= 3.0.1 = +**3.0.1** Bug fixes and minor enhancements -== Changelog == +### Changelog ### -= 3.2.2 = +**3.2.2** * Fix broken author ordering in 4.7+ (props mslinnea) * Fix no moderation e-mail bug (props RobjS) * Cached functions in CLI commands (props jasonbahl) * Fix missing echos (props trepmal) * Add `coauthors_guest_author_query_args` filter (props trepmal) -= 3.2.1 (May 16, 2016) = +**3.2.1 (May 16, 2016)** * Hotfix for broken Guest Author bio metabox (props JS Morisset) -= 3.2 (May 12, 2016) = -Various minor bug and security fixes +**3.2 (May 12, 2016)** +* Various minor bug and security fixes -= 3.1.2 (Aug. 31, 2015) = +**3.1.2 (Aug. 31, 2015)** * Minor bug fixes and coding standards changes. -* The author's display name is now filtered through the_author in coauthors_posts_links_single() +* The author's display name is now filtered through `the_author` in `coauthors_posts_links_single()` * New Russian and Ukrainian translations, courtesy of [Jurko Chervony](http://skinik.name/). -= 3.1.1 (Mar. 20, 2014) = +**3.1.1 (Mar. 20, 2014)** * Bug fix: Co-authors selection UI should appear when creating a new post too. -= 3.1 (Mar. 17, 2014) = +**3.1 (Mar. 17, 2014)** * Manage co-authors from Quick Edit. Props [mpatek](https://github.com/mpatek). * Updated Spanish translation, courtesy of [sergiomajluf](https://github.com/sergiomajluf). * Now matches core behavior when displaying author archive on multisite: user of the blog, or previously published author on the blog. @@ -91,14 +92,14 @@ Various minor bug and security fixes * Packages a composer.json file for those using Composer. * Beginnings of unit test coverage for core features. Increased minimum required WordPress version to 3.7 because WordPress.org unit testing framework doesn't work reliabilty below that. -= 3.0.7 (Jan. 27, 2014) = +**3.0.7 (Jan. 27, 2014)** * Better support for installing Co-Authors Plus as a symlinked directory. [Follow these instructions](http://kaspars.net/blog/wordpress/plugins-via-symlinks) to filter `plugins_url`. * Links to authors' posts pages to comply to hCard microformat, which Google depends on. * New `coauthors_emails()` template tag to list email addresses of the co-authors. Props [benlk](https://github.com/benlk). * Bug fix: Remove extraneous space between last two co-authors output. Props [johnciacia](https://github.com/johnciacia). * Updated French translation, courtesy of Jojaba (via email). -= 3.0.6 (Dec. 9, 2013) = +**3.0.6 (Dec. 9, 2013)** * New Swedish translation, courtesy of [alundstroem](https://github.com/alundstroem) * Updated German translation, courtesy of [krafit](https://github.com/krafit). * New Dutch translation, courtesy of [kardotim](https://github.com/kardotim) @@ -108,151 +109,151 @@ Various minor bug and security fixes * Fix Strict warnings from CPT's that don't define all capabilities * New swap-coauthors CLI command for replacing one co-author with another -= 3.0.5 (Feb. 18, 2013) = -* New filter 'coauthors_search_authors_get_terms_args' allows you to increase the number of matches returned with AJAX co-author selection +**3.0.5 (Feb. 18, 2013)** +* New filter `coauthors_search_authors_get_terms_args` allows you to increase the number of matches returned with AJAX co-author selection * Bug fix: If there isn't an author term yet for a co-author, avoid an erronous join that caused duplicate posts to appear. -= 3.0.4 (Jan. 6, 2013) = +**3.0.4 (Jan. 6, 2013)** = * Support for automatically adding co-authors to your feeds. Props [cfg](https://github.com/cfg). * Bug fix: No Co-Authors Plus on attachments. For now. * Bug fix: Better support for co-authors with non-standard user_nicenames. Props [STRML](https://github.com/STRML). -= 3.0.3 (Dec. 3, 2012) = -* Bug fix: The default order for the 'author' taxonomy should be 'term_order', in order for the author positions to stick. Props [lgedeon](https://github.com/lgedeon) +**3.0.3 (Dec. 3, 2012)** +* Bug fix: The default order for the 'author' taxonomy should be `term_order`, in order for the author positions to stick. Props [lgedeon](https://github.com/lgedeon) -= 3.0.2 (Nov. 23, 2012) = -* Bug fix: Fall back to non-pretty permalinks when the author permastruct is empty, so that coauthors_posts_links() doesn't link to the homepage +**3.0.2 (Nov. 23, 2012)** +* Bug fix: Fall back to non-pretty permalinks when the author permastruct is empty, so that `coauthors_posts_links()` doesn't link to the homepage -= 3.0.1 (Nov. 21, 2012) = +**3.0.1 (Nov. 21, 2012)** * Add your own custom columns to the guest authors table using filters. Props [cfg](https://github.com/cfg) * A new wp-cli subcommand for renaming co-authors and another for removing author terms mistakenly assigned to revisions * Bug fix: Using a featured image for a guest author avatar didn't work. Now it does. * Bug fix: Don't assign author terms to revisions to avoid unnecessary database bloat -* Bug fix: Make the coauthors_wp_list_authors() template tag work again -* Bug fix: Improve capability filtering by properly handling super admin access and situations where user_id = 0 +* Bug fix: Make the `coauthors_wp_list_authors()` template tag work again +* Bug fix: Improve capability filtering by properly handling super admin access and situations where `user_id = 0` * Minor UI enhancements for guest authors -= 3.0 (Nov. 12, 2012) = +**3.0 (Nov. 12, 2012)** * Create guest author profiles for bylines you'd like to assign without creating WordPress user accounts. Guest authors can have all of the same fields as normal users including display name, biography, and avatars. * Support for non-Latin characters in usernames and guest author names * wp-cli subcommands for creating, assigning, and reassigning co-authors -* For themes using core template tags like the_author() or the_author_posts_link(), you enable Co-Authors Plus support with a simple filter -* New author terms are now prefixed with 'cap-' to avoid collisions with global scope -* Bug fix: Apply query filters to only post_types registered with the taxonomy. Props [Tom Ransom](https://github.com/1bigidea) -* Filter coauthors_posts_link_single() with 'coauthors_posts_link'. Also adds rel="author". Props [Amit Sannad](https://github.com/asannad) and [Gabriel Koen](https://github.com/mintindeed) +* For themes using core template tags like `the_author()` or `the_author_posts_link()`, you enable Co-Authors Plus support with a simple filter +* New author terms are now prefixed with `cap-` to avoid collisions with global scope +* Bug fix: Apply query filters to only `post_types` registered with the taxonomy. Props [Tom Ransom](https://github.com/1bigidea) +* Filter `coauthors_posts_link_single()` with `coauthors_posts_link`. Also adds `rel="author"`. Props [Amit Sannad](https://github.com/asannad) and [Gabriel Koen](https://github.com/mintindeed) * Filter for the context and priorities of the Co-Authors meta boxes. Props [Tomáš Kapler](https://github.com/tkapler) * Renamed the post meta box for selecting authors so it applies to many post types. Props [John Blackbourn](https://github.com/johnbillion) -= 2.6.4 (May 7, 2012) = +**2.6.4 (May 7, 2012)** * Bug fix: Properly filter the user query so users can AJAX search against the display name field again * If https is used for the admin, also use the secure Gravatar URL. Props [rmcfrazier](https://github.com/rmcfrazier) -= 2.6.3 (Apr. 30, 2012) = +**2.6.3 (Apr. 30, 2012)** * AJAX user search is back to searching against user login, display name, email address and user ID. The method introduced in v2.6.2 didn't scale well * French translation courtesy of Sylvain Bérubé * Spanish translation courtesy of Alejandro Arcos * Bug fix: Resolved incorrect caps check against user editing an already published post. [See forum thread](http://wordpress.org/support/topic/multiple-authors-cant-edit-pages?replies=17#post-2741243) -= 2.6.2 (Mar. 6, 2012) = +**2.6.2 (Mar. 6, 2012)** * AJAX user search matches against first name, last name, and nickname fields too, in addition to display name, user login, and email address * Comment moderation and approved notifications are properly sent to all co-authors with the correct caps -* Filter required capability for user to be returned in an AJAX search with 'coauthors_edit_author_cap' -* Filter out administrators and other non-authors from AJAX search with 'coauthors_edit_ignored_authors' +* Filter required capability for user to be returned in an AJAX search with `coauthors_edit_author_cap` +* Filter out administrators and other non-authors from AJAX search with `coauthors_edit_ignored_authors` * Automatically adds co-authors to Edit Flow's story budget and calendar views * Bug fix: Don't set post_author value to current user when quick editing a post. This doesn't appear in the UI anywhere, but adds the post to the current user's list of posts * Bug fix: Properly cc other co-authors on new comment email notifications * Bug fix: If a user has already been added as an author to a post, don't show them in the AJAX search again * Bug fix: Allow output constants to be defined in a theme's functions.php file and include filters you can use instead -= 2.6.1 (Dec. 30, 2011) = +**2.6.1 (Dec. 30, 2011)** * Fix mangled usernames because of sanitize_key http://wordpress.org/support/topic/plugin-co-authors-plus-26-not-working-with-wp-33 -= 2.6 (Dec. 22, 2011) = +**2.6 (Dec. 22, 2011)** * Sortable authors: Drag and drop the order of the authors as you'd like them to appear ([props kingkool68](http://profiles.wordpress.org/users/kingkool68/)) * Search for authors by display name (instead of nicename which was essentially the same as user_login) * Option to remove the first author when there are two or more so it's less confusing * Bumped requirements to WordPress 3.1 * Bug fix: Update the published post count for each user more reliably -= 2.5.3 (Aug. 14, 2011) = -* Bug fix: Removed extra comma when only two authors were listed. If you used the COAUTHORS_DEFAULT_BETWEEN_LAST constant, double-check what you have +**2.5.3 (Aug. 14, 2011)** +* Bug fix: Removed extra comma when only two authors were listed. If you used the `COAUTHORS_DEFAULT_BETWEEN_LAST` constant, double-check what you have -= 2.5.2 (Apr. 23, 2011) = +**2.5.2 (Apr. 23, 2011)** * Bug: Couldn't query terms and authors at the same time (props nbaxley) * Bug: Authors with empty fields (e.g. first name) were displaying blank in some cases * Bug: authors with spaces in usernames not getting saved (props MLmsw, Ruben S. and others!) * Bug: revisions getting wrong user attached (props cliquenoir!) -= 2.5.1 (Mar. 26, 2011) = +**2.5.1 (Mar. 26, 2011)** * Fix with author post count (throwing errors) -= 2.5 (Mar. 26, 2011) = +**2.5 (Mar. 26, 2011)** * Custom Post Type Support * Compatibility with WP 3.0 and 3.1 * Gravatars * Lots and lots and lots of bug fixes * Thanks to everyone who submitted bugs, fixes, and suggestions! And for your patience! -= 2.1.1 (Oct. 16, 2009) = +**2.1.1 (Oct. 16, 2009)** * Fix for coauthors not being added if their username is different from display name * Fixes to readme.txt (fixes for textual and punctuation errors, language clarification, minor formatting changes) courtesy of [Waldo Jaquith](http://www.vqronline.org) -= 2.1 (Oct. 11, 2009) = +**2.1 (Oct. 11, 2009)** * Fixed issues related to localization. Thanks to Jan Zombik for the fixes. -* Added set_time_limit to update function to get around timeout issues when upgrading plugin +* Added `set_time_limit` to update function to get around timeout issues when upgrading plugin -= 2.0 (Oct. 11, 2009) = -* Plugin mostly rewritten to make use of taxonomy instead of post_meta +**2.0 (Oct. 11, 2009)** +* Plugin mostly rewritten to make use of taxonomy instead of `post_meta` * Can now see all authors of a post under the author column from Edit Posts page * All authors of a post are now notified on a new comment * Various javascript enhancements * New option to allow subscribers to be added as authors * All Authors can edit they posts of which they are coauthors -* FIX: Issues with wp_coauthors_list function +* FIX: Issues with `wp_coauthors_list` function * FIX: Issues with coauthored posts not showing up on author archives -= 1.2.0 (Jun. 16, 2012) = +**1.2.0 (Jun. 16, 2012)** * FIX: Added compatibility for WordPress 2.8 -* FIX: Added new template tags (get_the_coauthor_meta & the_coauthor_meta) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details. -* FIX: Plugin should now work for plugins not using the 'wp_' DB prefix +* FIX: Added new template tags (`get_the_coauthor_meta` & `the_coauthor_meta`) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details. +* FIX: Plugin should now work for plugins not using the `wp_` DB prefix * FIX: Coauthors should no longer be alphabetically reordered when the post is updated * FIX: Plugin now used WordPress native AJAX calls to tighten security * DOCS: Added details about the new template tags -= 1.1.5 (Apr. 26, 2009) = +**1.1.5 (Apr. 26, 2009)** * FIX: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname * FIX: When editing an author, and clicking on a suggested author, the original author was not be removed * DOCS: Added code comments to javascript; more still to be added * DOCS: Updated readme information -= 1.1.4 (Apr. 25, 2009) = +**1.1.4 (Apr. 25, 2009)** * Disabled "New Author" output in suggest box, for now * Hopefully fixed SVN issue (if you're having trouble with the plugin, please delete the plugin and reinstall) -= 1.1.3 (Apr. 23, 2009) = +**1.1.3 (Apr. 23, 2009)** * Add blur event to disable input box * Limit only one edit at a time. * Checked basic cross-browser compatibility (Firefox 3 OS X, Safari 3 OS X, IE7 Vista). * Add suggest javascript plugin to Edit Page. -= 1.1.2 (Apr. 19, 2009) = +**1.1.2 (Apr. 19, 2009)** * Disabled form submit when enter pressed. -= 1.1.1 (Apr. 15, 2009) = +**1.1.1 (Apr. 15, 2009)** * Changed SQL query to return only contributor-level and above users. -= 1.1.0 (Apr. 14, 2009) = +**1.1.0 (Apr. 14, 2009)** * Initial beta release. -== Installation == +## Installation 1. IMPORTANT: Please disable the original Co-Authors plugin (if you are using it) before installing Co-Authors Plus -1. Extract the coauthors-plus.zip file and upload its contents to the `/wp-content/plugins/` directory. Alternately, you can install directly from the Plugin directory within your WordPress Install. -1. Activate the plugin through the "Plugins" menu in WordPress. -1. Place the appropriate [co-authors template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) in your template. -1. Add co-authors to your posts and pages. +2. Extract the coauthors-plus.zip file and upload its contents to the `/wp-content/plugins/` directory. Alternately, you can install directly from the Plugin directory within your WordPress Install. +3. Activate the plugin through the "Plugins" menu in WordPress. +4. Place the appropriate [co-authors template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) in your template. +5. Add co-authors to your posts and pages. -== Screenshots == +## Screenshots 1. Multiple authors can be added to a Post, Page, or Custom Post Type using an auto-complete interface. 2. The order of your co-authors can be changed by drag and drop. From cdd7e0f33fc04f79be3ed4a574017c2d68084769 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 12:21:06 -0600 Subject: [PATCH 085/231] added readme.txt back --- readme.txt | 259 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 readme.txt diff --git a/readme.txt b/readme.txt new file mode 100644 index 00000000..bfe56edf --- /dev/null +++ b/readme.txt @@ -0,0 +1,259 @@ +=== Co-Authors Plus === +Contributors: batmoo, danielbachhuber, automattic +Tags: authors, users, multiple authors, coauthors, multi-author, publishing +Tested up to: 4.8 +Requires at least: 4.1 +Stable tag: 3.2.2 + +Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box + +== Description == + +Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box. Co-authored posts appear on a co-author's archive page and in their feed. Co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is core behavior). + +Add writers as bylines without creating WordPress user accounts. Simply [create a guest author profile](http://vip.wordpress.com/documentation/add-guest-bylines-to-your-content-with-co-authors-plus/) for the writer and assign the byline as you normally would. + +On the frontend, use the [Co-Authors Plus template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) to list co-authors anywhere you'd normally list the author. + +This plugin is an almost complete rewrite of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/) (2007). The original plugin was inspired by the 'Multiple Authors' plugin by Mark Jaquith (2005). + +== Frequently Asked Questions == + += How do I add Co-Authors Plus support to my theme? = + +If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. + += What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = + +When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. + += Can I use Co-Authors Plus with WordPress multisite? = + +Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. + += Who needs permission to do what? = + +To assign co-authors to posts, a WordPress user will need the 'edit_others_posts' capability. This is typically granted to the Editor role, but can be altered with the 'coauthors_plus_edit_authors' filter. + +To create new guest author profiles, a WordPress will need the 'list_users' capability. This is typically granted to the Administrator role, but can be altered with the 'coauthors_guest_author_manage_cap' filter. + += Can I easily create a list of all co-authors? = + +Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. + +== Upgrade Notice == + += 3.1 = +Manage co-authors from quick edit, Jetpack Open Graph support, bug fixes. + += 3.0.7 = +Support for symlink installations, updated French translation, bug fixes. + += 3.0.4 = +Bug fixes and the ability to automatically add co-authors to your feeds. + += 3.0.1 = +Bug fixes and minor enhancements + +== Changelog == + += 3.2.2 = +* Fix broken author ordering in 4.7+ (props mslinnea) +* Fix no moderation e-mail bug (props RobjS) +* Cached functions in CLI commands (props jasonbahl) +* Fix missing echos (props trepmal) +* Add `coauthors_guest_author_query_args` filter (props trepmal) + += 3.2.1 (May 16, 2016) = +* Hotfix for broken Guest Author bio metabox (props JS Morisset) + += 3.2 (May 12, 2016) = +Various minor bug and security fixes + += 3.1.2 (Aug. 31, 2015) = +* Minor bug fixes and coding standards changes. +* The author's display name is now filtered through the_author in coauthors_posts_links_single() +* New Russian and Ukrainian translations, courtesy of [Jurko Chervony](http://skinik.name/). + += 3.1.1 (Mar. 20, 2014) = +* Bug fix: Co-authors selection UI should appear when creating a new post too. + += 3.1 (Mar. 17, 2014) = +* Manage co-authors from Quick Edit. Props [mpatek](https://github.com/mpatek). +* Updated Spanish translation, courtesy of [sergiomajluf](https://github.com/sergiomajluf). +* Now matches core behavior when displaying author archive on multisite: user of the blog, or previously published author on the blog. +* Breaking change: "Create Profile" link is no longer shown by default on the Manage Users screen. Instead, it can be enabled with the `coauthors_show_create_profile_user_link` filter. +* Guest authors work properly with Jetpack Open Graph tags. Props [hibernation](https://github.com/hibernation). +* Guest author profile editor now supports a few different fields. Props [alpha1](https://github.com/alpha1). +* New `coauthors_count_published_post_types` filter for specifying the post type(s) used when calculating the user's number of published posts. +* Bug fix: Ensure `post_author` is set to one of the co-authors assigned to a post. +* Bug fix: Filter author feed link for guest authors on the author page. Props [hibernation](https://github.com/hibernation). +* Packages a composer.json file for those using Composer. +* Beginnings of unit test coverage for core features. Increased minimum required WordPress version to 3.7 because WordPress.org unit testing framework doesn't work reliabilty below that. + += 3.0.7 (Jan. 27, 2014) = +* Better support for installing Co-Authors Plus as a symlinked directory. [Follow these instructions](http://kaspars.net/blog/wordpress/plugins-via-symlinks) to filter `plugins_url`. +* Links to authors' posts pages to comply to hCard microformat, which Google depends on. +* New `coauthors_emails()` template tag to list email addresses of the co-authors. Props [benlk](https://github.com/benlk). +* Bug fix: Remove extraneous space between last two co-authors output. Props [johnciacia](https://github.com/johnciacia). +* Updated French translation, courtesy of Jojaba (via email). + += 3.0.6 (Dec. 9, 2013) = +* New Swedish translation, courtesy of [alundstroem](https://github.com/alundstroem) +* Updated German translation, courtesy of [krafit](https://github.com/krafit). +* New Dutch translation, courtesy of [kardotim](https://github.com/kardotim) +* New filter for specifying the default author assigned to a post. Props [tannerm](https://github.com/tannerm) +* Bug fix: When filtering a user's published post count, use the value of their guest author profile if one is mapped. +* Added support for checkboxes in Guest Author profiles +* Fix Strict warnings from CPT's that don't define all capabilities +* New swap-coauthors CLI command for replacing one co-author with another + += 3.0.5 (Feb. 18, 2013) = +* New filter 'coauthors_search_authors_get_terms_args' allows you to increase the number of matches returned with AJAX co-author selection +* Bug fix: If there isn't an author term yet for a co-author, avoid an erronous join that caused duplicate posts to appear. + += 3.0.4 (Jan. 6, 2013) = +* Support for automatically adding co-authors to your feeds. Props [cfg](https://github.com/cfg). +* Bug fix: No Co-Authors Plus on attachments. For now. +* Bug fix: Better support for co-authors with non-standard user_nicenames. Props [STRML](https://github.com/STRML). + += 3.0.3 (Dec. 3, 2012) = +* Bug fix: The default order for the 'author' taxonomy should be 'term_order', in order for the author positions to stick. Props [lgedeon](https://github.com/lgedeon) + += 3.0.2 (Nov. 23, 2012) = +* Bug fix: Fall back to non-pretty permalinks when the author permastruct is empty, so that coauthors_posts_links() doesn't link to the homepage + += 3.0.1 (Nov. 21, 2012) = +* Add your own custom columns to the guest authors table using filters. Props [cfg](https://github.com/cfg) +* A new wp-cli subcommand for renaming co-authors and another for removing author terms mistakenly assigned to revisions +* Bug fix: Using a featured image for a guest author avatar didn't work. Now it does. +* Bug fix: Don't assign author terms to revisions to avoid unnecessary database bloat +* Bug fix: Make the coauthors_wp_list_authors() template tag work again +* Bug fix: Improve capability filtering by properly handling super admin access and situations where user_id = 0 +* Minor UI enhancements for guest authors + += 3.0 (Nov. 12, 2012) = +* Create guest author profiles for bylines you'd like to assign without creating WordPress user accounts. Guest authors can have all of the same fields as normal users including display name, biography, and avatars. +* Support for non-Latin characters in usernames and guest author names +* wp-cli subcommands for creating, assigning, and reassigning co-authors +* For themes using core template tags like the_author() or the_author_posts_link(), you enable Co-Authors Plus support with a simple filter +* New author terms are now prefixed with 'cap-' to avoid collisions with global scope +* Bug fix: Apply query filters to only post_types registered with the taxonomy. Props [Tom Ransom](https://github.com/1bigidea) +* Filter coauthors_posts_link_single() with 'coauthors_posts_link'. Also adds rel="author". Props [Amit Sannad](https://github.com/asannad) and [Gabriel Koen](https://github.com/mintindeed) +* Filter for the context and priorities of the Co-Authors meta boxes. Props [Tomáš Kapler](https://github.com/tkapler) +* Renamed the post meta box for selecting authors so it applies to many post types. Props [John Blackbourn](https://github.com/johnbillion) + += 2.6.4 (May 7, 2012) = +* Bug fix: Properly filter the user query so users can AJAX search against the display name field again +* If https is used for the admin, also use the secure Gravatar URL. Props [rmcfrazier](https://github.com/rmcfrazier) + += 2.6.3 (Apr. 30, 2012) = +* AJAX user search is back to searching against user login, display name, email address and user ID. The method introduced in v2.6.2 didn't scale well +* French translation courtesy of Sylvain Bérubé +* Spanish translation courtesy of Alejandro Arcos +* Bug fix: Resolved incorrect caps check against user editing an already published post. [See forum thread](http://wordpress.org/support/topic/multiple-authors-cant-edit-pages?replies=17#post-2741243) + += 2.6.2 (Mar. 6, 2012) = +* AJAX user search matches against first name, last name, and nickname fields too, in addition to display name, user login, and email address +* Comment moderation and approved notifications are properly sent to all co-authors with the correct caps +* Filter required capability for user to be returned in an AJAX search with 'coauthors_edit_author_cap' +* Filter out administrators and other non-authors from AJAX search with 'coauthors_edit_ignored_authors' +* Automatically adds co-authors to Edit Flow's story budget and calendar views +* Bug fix: Don't set post_author value to current user when quick editing a post. This doesn't appear in the UI anywhere, but adds the post to the current user's list of posts +* Bug fix: Properly cc other co-authors on new comment email notifications +* Bug fix: If a user has already been added as an author to a post, don't show them in the AJAX search again +* Bug fix: Allow output constants to be defined in a theme's functions.php file and include filters you can use instead + += 2.6.1 (Dec. 30, 2011) = +* Fix mangled usernames because of sanitize_key http://wordpress.org/support/topic/plugin-co-authors-plus-26-not-working-with-wp-33 + += 2.6 (Dec. 22, 2011) = +* Sortable authors: Drag and drop the order of the authors as you'd like them to appear ([props kingkool68](http://profiles.wordpress.org/users/kingkool68/)) +* Search for authors by display name (instead of nicename which was essentially the same as user_login) +* Option to remove the first author when there are two or more so it's less confusing +* Bumped requirements to WordPress 3.1 +* Bug fix: Update the published post count for each user more reliably + += 2.5.3 (Aug. 14, 2011) = +* Bug fix: Removed extra comma when only two authors were listed. If you used the COAUTHORS_DEFAULT_BETWEEN_LAST constant, double-check what you have + += 2.5.2 (Apr. 23, 2011) = +* Bug: Couldn't query terms and authors at the same time (props nbaxley) +* Bug: Authors with empty fields (e.g. first name) were displaying blank in some cases +* Bug: authors with spaces in usernames not getting saved (props MLmsw, Ruben S. and others!) +* Bug: revisions getting wrong user attached (props cliquenoir!) + += 2.5.1 (Mar. 26, 2011) = +* Fix with author post count (throwing errors) + += 2.5 (Mar. 26, 2011) = +* Custom Post Type Support +* Compatibility with WP 3.0 and 3.1 +* Gravatars +* Lots and lots and lots of bug fixes +* Thanks to everyone who submitted bugs, fixes, and suggestions! And for your patience! + += 2.1.1 (Oct. 16, 2009) = +* Fix for coauthors not being added if their username is different from display name +* Fixes to readme.txt (fixes for textual and punctuation errors, language clarification, minor formatting changes) courtesy of [Waldo Jaquith](http://www.vqronline.org) + += 2.1 (Oct. 11, 2009) = +* Fixed issues related to localization. Thanks to Jan Zombik for the fixes. +* Added set_time_limit to update function to get around timeout issues when upgrading plugin + += 2.0 (Oct. 11, 2009) = +* Plugin mostly rewritten to make use of taxonomy instead of post_meta +* Can now see all authors of a post under the author column from Edit Posts page +* All authors of a post are now notified on a new comment +* Various javascript enhancements +* New option to allow subscribers to be added as authors +* All Authors can edit they posts of which they are coauthors +* FIX: Issues with wp_coauthors_list function +* FIX: Issues with coauthored posts not showing up on author archives + += 1.2.0 (Jun. 16, 2012) = +* FIX: Added compatibility for WordPress 2.8 +* FIX: Added new template tags (get_the_coauthor_meta & the_coauthor_meta) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details. +* FIX: Plugin should now work for plugins not using the 'wp_' DB prefix +* FIX: Coauthors should no longer be alphabetically reordered when the post is updated +* FIX: Plugin now used WordPress native AJAX calls to tighten security +* DOCS: Added details about the new template tags + += 1.1.5 (Apr. 26, 2009) = +* FIX: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname +* FIX: When editing an author, and clicking on a suggested author, the original author was not be removed +* DOCS: Added code comments to javascript; more still to be added +* DOCS: Updated readme information + += 1.1.4 (Apr. 25, 2009) = +* Disabled "New Author" output in suggest box, for now +* Hopefully fixed SVN issue (if you're having trouble with the plugin, please delete the plugin and reinstall) + += 1.1.3 (Apr. 23, 2009) = +* Add blur event to disable input box +* Limit only one edit at a time. +* Checked basic cross-browser compatibility (Firefox 3 OS X, Safari 3 OS X, IE7 Vista). +* Add suggest javascript plugin to Edit Page. + += 1.1.2 (Apr. 19, 2009) = +* Disabled form submit when enter pressed. + += 1.1.1 (Apr. 15, 2009) = +* Changed SQL query to return only contributor-level and above users. + += 1.1.0 (Apr. 14, 2009) = +* Initial beta release. + +== Installation == + +1. IMPORTANT: Please disable the original Co-Authors plugin (if you are using it) before installing Co-Authors Plus +1. Extract the coauthors-plus.zip file and upload its contents to the `/wp-content/plugins/` directory. Alternately, you can install directly from the Plugin directory within your WordPress Install. +1. Activate the plugin through the "Plugins" menu in WordPress. +1. Place the appropriate [co-authors template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) in your template. +1. Add co-authors to your posts and pages. + +== Screenshots == + +1. Multiple authors can be added to a Post, Page, or Custom Post Type using an auto-complete interface. +2. The order of your co-authors can be changed by drag and drop. +3. Guest authors allow you to assign bylines without creating WordPress user accounts. You can also override existing WordPress account meta by mapping a guest author to a WordPress user. From 90e201cdade65815993d345df250de73c38e43f9 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 13:35:22 -0600 Subject: [PATCH 086/231] remove quotes, stray =s and upgrade notice section --- README.md | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3e0ef6c4..b3c93f1a 100644 --- a/README.md +++ b/README.md @@ -22,41 +22,27 @@ This plugin is an almost complete rewrite of the Co-Authors plugin originally de * How do I add Co-Authors Plus support to my theme? -> If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. +If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. -* What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = +* What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? -> When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. +When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. -* Can I use Co-Authors Plus with WordPress multisite? = +* Can I use Co-Authors Plus with WordPress multisite? -> Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. +Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. * Who needs permission to do what? -> To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. +To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. -> To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. +To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. * Can I easily create a list of all co-authors? -> Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. +Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. -## Upgrade Notice - -**3.1** -Manage co-authors from quick edit, Jetpack Open Graph support, bug fixes. - -**3.0.7** -Support for symlink installations, updated French translation, bug fixes. - -**3.0.4** -Bug fixes and the ability to automatically add co-authors to your feeds. - -**3.0.1** -Bug fixes and minor enhancements - -### Changelog ### +## Changelog ## **3.2.2** * Fix broken author ordering in 4.7+ (props mslinnea) From bc5a46bea1e811c5edd5a95d7a54ae34e8ec3f55 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 23:00:24 -0600 Subject: [PATCH 087/231] added check for false $term --- co-authors-plus.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index d956a640..f49861e7 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1348,6 +1348,9 @@ public function get_author_term( $coauthor ) { // use linked user for accurate post count if ( ! empty ( $coauthor->linked_account ) ) { $term = get_term_by( 'slug', 'cap-' . $coauthor->linked_account, $this->coauthor_taxonomy ); + if ( ! $term ) { + $term = get_term_by( 'slug', $coauthor->linked_account, $this->coauthor_taxonomy ); + } } else { // See if the prefixed term is available, otherwise default to just the nicename From c066be29aa8bcedab0606a9cf3947e19087425e0 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 6 Jul 2017 16:54:26 -0700 Subject: [PATCH 088/231] Do not 404 when guest author archive has 0 posts. Addresses #425 (#440) Resolves #425, #409 --- co-authors-plus.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 9c1661e8..db329c73 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1026,10 +1026,10 @@ public function fix_author_page() { $term = $this->get_author_term( $authordata ); } - if ( ( is_object( $authordata ) ) - || ( ! empty( $term ) && $term->count ) ) { + if ( is_object( $authordata ) || ! empty( $term ) ) { $wp_query->queried_object = $authordata; $wp_query->queried_object_id = $authordata->ID; + add_filter( 'pre_handle_404', '__return_true' ); } else { $wp_query->queried_object = $wp_query->queried_object_id = null; $wp_query->is_author = $wp_query->is_archive = false; From f6a82caa0a2494fbafb476fc2772408fc5cb2ea5 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Tue, 27 Jun 2017 16:35:35 -0700 Subject: [PATCH 089/231] Move parenthesis to fix esc_html and sprintf Fixes warning: `Warning: sprintf(): Too few arguments in /path/wp-content/plugins/co-authors-plus/php/class-coauthors-guest-authors.php on line 487` Warning surfaces when deleting a guest author that is mapped to a WP user --- php/class-coauthors-guest-authors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 3c351884..a5c3c470 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -484,7 +484,7 @@ function view_guest_authors_list() { // Leave mapped to a linked account if ( get_user_by( 'login', $guest_author->linked_account ) ) { echo '
  • '; } // Remove bylines from the posts From f2eba65dbd493ab926165359b7ca9772fb98ca9d Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 18:23:34 -0600 Subject: [PATCH 090/231] featured image to avatar --- php/class-coauthors-guest-authors.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index a5c3c470..36b0aecd 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -89,6 +89,10 @@ function __construct() { 'not_found_in_trash' => __( 'No guest authors found in Trash', 'co-authors-plus' ), 'update_item' => __( 'Update Guest Author', 'co-authors-plus' ), 'metabox_about' => __( 'About the guest author', 'co-authors-plus' ), + 'featured_image' => __( 'Avatar', 'co-authors-plus' ), + 'set_featured_image' => __( 'Set Avatar', 'co-authors-plus' ), + 'use_featured_image' => __( 'Use Avatar', 'co-authors-plus' ), + 'remove_featured_image' => __( 'Remove Avatar', 'co-authors-plus' ), ) ); // Register a post type to store our guest authors @@ -106,6 +110,10 @@ function __construct() { 'search_items' => $this->labels['search_items'], 'not_found' => $this->labels['not_found'], 'not_found_in_trash' => $this->labels['not_found_in_trash'], + 'featured_image' => $this->labels['featured_image'], + 'set_featured_image' => $this->labels['set_featured_image'], + 'use_featured_image' => $this->labels['use_featured_image'], + 'remove_featured_image' => $this->labels['remove_featured_image'] ), 'public' => true, 'publicly_queryable' => false, From 555cd7226fbc9c3f6a750535eb6fe539351a6b6a Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 10:00:21 -0600 Subject: [PATCH 091/231] Removed avatar sizing --- php/class-coauthors-guest-authors.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 36b0aecd..fda129b9 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -131,17 +131,7 @@ function __construct() { register_post_type( $this->post_type, $args ); // Some of the common sizes used by get_avatar - $this->avatar_sizes = array( - 32, - 50, - 64, - 96, - 128, - ); - $this->avatar_sizes = apply_filters( 'coauthors_guest_author_avatar_sizes', $this->avatar_sizes ); - foreach ( $this->avatar_sizes as $size ) { - add_image_size( 'guest-author-' . $size, $size, $size, true ); - } + $this->avatar_sizes = array(); // Hacky way to remove the title and the editor remove_post_type_support( $this->post_type, 'title' ); @@ -940,11 +930,8 @@ function get_guest_author_thumbnail( $guest_author, $size ) { $args = array( 'class' => "avatar avatar-{$size} photo", ); - if ( in_array( $size, $this->avatar_sizes ) ) { - $size = 'guest-author-' . $size; - } else { - $size = array( $size, $size ); - } + + $size = array( $size, $size ); $thumbnail = get_the_post_thumbnail( $guest_author->ID, $size, $args ); From 0372cf0829ef88c7f219055ebf9c85c7e1b58560 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 14:41:20 -0600 Subject: [PATCH 092/231] remove duplicated linked author byline --- template-tags.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/template-tags.php b/template-tags.php index ffc398ae..8993984a 100644 --- a/template-tags.php +++ b/template-tags.php @@ -35,6 +35,8 @@ function get_coauthors( $post_id = 0 ) { } } // the empty else case is because if we force guest authors, we don't ever care what value wp_posts.post_author has. } + // remove duplicate $coauthors objects from mapping user accounts to guest authors accounts + $coauthors = array_unique( $coauthors, SORT_REGULAR ); return $coauthors; } From 8f8a0e7ca47a82e28351aa4c29556cd00177b254 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 6 Jul 2017 23:29:21 -0600 Subject: [PATCH 093/231] fixed author archive title --- co-authors-plus.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index db329c73..5863c557 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -128,6 +128,9 @@ function __construct() { add_action( 'save_post', array( $this, 'clear_cache') ); add_action( 'delete_post', array( $this, 'clear_cache') ); add_action( 'set_object_terms', array( $this, 'clear_cache_on_terms_set' ), 10, 6 ); + + // Change Author Archive header to plural + add_filter( 'get_the_archive_title', array( $this, 'filter_author_archive_title'), 10, 2 ); } /** @@ -1541,6 +1544,15 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy } + /** + * Filter of the header of author archive pages to correctly display author. + */ + public function filter_author_archive_title() { + if ( is_author() ) { + $author = sanitize_user( get_query_var( 'author_name' ) ); + return "Author: ". $author; + } + } } global $coauthors_plus; From b60a7ef976ea792db52867072a19d0bed46521d7 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 6 Jul 2017 23:32:46 -0600 Subject: [PATCH 094/231] revised comment --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 5863c557..d99f304e 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -129,7 +129,7 @@ function __construct() { add_action( 'delete_post', array( $this, 'clear_cache') ); add_action( 'set_object_terms', array( $this, 'clear_cache_on_terms_set' ), 10, 6 ); - // Change Author Archive header to plural + // Filter to correct author on author archive page add_filter( 'get_the_archive_title', array( $this, 'filter_author_archive_title'), 10, 2 ); } From 0be3eca8db7f85d0aa8dbea4768f918673bdb0cf Mon Sep 17 00:00:00 2001 From: jordie23 Date: Wed, 12 Jul 2017 15:26:43 +1000 Subject: [PATCH 095/231] Fix invalid CSS (#442) --- css/co-authors-plus.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/css/co-authors-plus.css b/css/co-authors-plus.css index 8f9fdb8f..cf96a9df 100644 --- a/css/co-authors-plus.css +++ b/css/co-authors-plus.css @@ -42,7 +42,7 @@ width:200px; } #coauthors-list .ui-sortable-helper .coauthor-tag { - cursor: cursor:grabbing; + cursor: grabbing; cursor:-moz-grabbing; cursor:-webkit-grabbing; } @@ -107,4 +107,4 @@ padding: 5px 3px; margin-left: 30px; font-size: 13px; - } \ No newline at end of file + } From 8a8424b4cc964364915de922938ad84a1d0f8055 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 12 Jul 2017 19:39:27 -0600 Subject: [PATCH 096/231] fixed coauthors_link_single to work with guest authors --- template-tags.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/template-tags.php b/template-tags.php index 8993984a..f4dacb8f 100644 --- a/template-tags.php +++ b/template-tags.php @@ -378,14 +378,26 @@ function coauthors_emails( $between = null, $betweenLast = null, $before = null, * @return string */ function coauthors_links_single( $author ) { - if ( get_the_author_meta( 'url' ) ) { - return sprintf( '%s', - get_the_author_meta( 'url' ), - esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), - get_the_author() - ); - } else { - return get_the_author(); + if ( 'guest-author' === $author->type ) { + if ( get_the_author_meta( 'website' ) ) { + return sprintf( '%s', + get_the_author_meta( 'website' ), + esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), + get_the_author() + ); + } + } + else { + if ( get_the_author_meta( 'url' ) ) { + return sprintf( '%s', + get_the_author_meta( 'url' ), + esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), + get_the_author() + ); + } + else { + return get_the_author(); + } } } From 9746d3db979e7cfc086736cd9e05cb9b1c0c79c0 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 12 Jul 2017 19:41:55 -0600 Subject: [PATCH 097/231] added _blank target --- template-tags.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-tags.php b/template-tags.php index f4dacb8f..761e0edd 100644 --- a/template-tags.php +++ b/template-tags.php @@ -389,7 +389,7 @@ function coauthors_links_single( $author ) { } else { if ( get_the_author_meta( 'url' ) ) { - return sprintf( '%s', + return sprintf( '%s', get_the_author_meta( 'url' ), esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), get_the_author() From 5abc3ce0b53a2e6b64c47afd91e0a5ffd1a511b7 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 12 Jul 2017 19:46:14 -0600 Subject: [PATCH 098/231] switched logic around --- template-tags.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/template-tags.php b/template-tags.php index 761e0edd..8128ee04 100644 --- a/template-tags.php +++ b/template-tags.php @@ -387,17 +387,15 @@ function coauthors_links_single( $author ) { ); } } + elseif ( get_the_author_meta( 'url' ) ) { + return sprintf( '%s', + get_the_author_meta( 'url' ), + esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), + get_the_author() + ); + } else { - if ( get_the_author_meta( 'url' ) ) { - return sprintf( '%s', - get_the_author_meta( 'url' ), - esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), - get_the_author() - ); - } - else { - return get_the_author(); - } + return get_the_author(); } } From b3fb700c3a4c919ba3176b44fcc80b1cf5d295a0 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 11 Aug 2017 12:45:32 -0600 Subject: [PATCH 099/231] added hooks for creating/deleting guest authors --- php/class-coauthors-guest-authors.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index fda129b9..2bc39b44 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -201,6 +201,8 @@ function handle_create_guest_author_action() { wp_die( esc_html( $post_id->get_error_message() ) ); } + do_action( 'cap_guest_author_create' ); + // Redirect to the edit Guest Author screen $edit_link = get_edit_post_link( $post_id, 'redirect' ); $redirect_to = add_query_arg( 'message', 'guest-author-created', $edit_link ); @@ -271,6 +273,8 @@ function handle_delete_guest_author_action() { $args['message'] = 'delete-error'; } else { $args['message'] = 'guest-author-deleted'; + + do_action( 'cap_guest_author_del' ); } // Redirect to safety From 2eeb8b75630ebb6501aee2ec342df0ddad14112b Mon Sep 17 00:00:00 2001 From: Linnea Wilhelm Date: Wed, 30 Aug 2017 19:19:57 -0700 Subject: [PATCH 100/231] fix logic for doing_autosave check --- co-authors-plus.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 6f47c238..ce3be05f 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -729,7 +729,7 @@ function posts_groupby_filter( $groupby, $query ) { function coauthors_set_post_author_field( $data, $postarr ) { // Bail on autosave - if ( defined( 'DOING_AUTOSAVE' ) && ! DOING_AUTOSAVE ) { + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $data; } @@ -772,7 +772,7 @@ function coauthors_set_post_author_field( $data, $postarr ) { */ function coauthors_update_post( $post_id, $post ) { - if ( defined( 'DOING_AUTOSAVE' ) && ! DOING_AUTOSAVE ) { + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } From 3da2471ebb3e9e2d58adf2bddc2a09d8b4d6e232 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Tue, 27 Jun 2017 16:35:35 -0700 Subject: [PATCH 101/231] Move parenthesis to fix esc_html and sprintf Fixes warning: `Warning: sprintf(): Too few arguments in /path/wp-content/plugins/co-authors-plus/php/class-coauthors-guest-authors.php on line 487` Warning surfaces when deleting a guest author that is mapped to a WP user --- php/class-coauthors-guest-authors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 3c351884..a5c3c470 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -484,7 +484,7 @@ function view_guest_authors_list() { // Leave mapped to a linked account if ( get_user_by( 'login', $guest_author->linked_account ) ) { echo '
  • '; } // Remove bylines from the posts From c0341e7d1353e268e2fdbc543e20e0cae15b501a Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Thu, 29 Jun 2017 18:23:34 -0600 Subject: [PATCH 102/231] featured image to avatar --- php/class-coauthors-guest-authors.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index a5c3c470..36b0aecd 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -89,6 +89,10 @@ function __construct() { 'not_found_in_trash' => __( 'No guest authors found in Trash', 'co-authors-plus' ), 'update_item' => __( 'Update Guest Author', 'co-authors-plus' ), 'metabox_about' => __( 'About the guest author', 'co-authors-plus' ), + 'featured_image' => __( 'Avatar', 'co-authors-plus' ), + 'set_featured_image' => __( 'Set Avatar', 'co-authors-plus' ), + 'use_featured_image' => __( 'Use Avatar', 'co-authors-plus' ), + 'remove_featured_image' => __( 'Remove Avatar', 'co-authors-plus' ), ) ); // Register a post type to store our guest authors @@ -106,6 +110,10 @@ function __construct() { 'search_items' => $this->labels['search_items'], 'not_found' => $this->labels['not_found'], 'not_found_in_trash' => $this->labels['not_found_in_trash'], + 'featured_image' => $this->labels['featured_image'], + 'set_featured_image' => $this->labels['set_featured_image'], + 'use_featured_image' => $this->labels['use_featured_image'], + 'remove_featured_image' => $this->labels['remove_featured_image'] ), 'public' => true, 'publicly_queryable' => false, From 84de506a037eb53ef2d605d8b91022827a109106 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 10:00:21 -0600 Subject: [PATCH 103/231] Removed avatar sizing --- php/class-coauthors-guest-authors.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 36b0aecd..fda129b9 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -131,17 +131,7 @@ function __construct() { register_post_type( $this->post_type, $args ); // Some of the common sizes used by get_avatar - $this->avatar_sizes = array( - 32, - 50, - 64, - 96, - 128, - ); - $this->avatar_sizes = apply_filters( 'coauthors_guest_author_avatar_sizes', $this->avatar_sizes ); - foreach ( $this->avatar_sizes as $size ) { - add_image_size( 'guest-author-' . $size, $size, $size, true ); - } + $this->avatar_sizes = array(); // Hacky way to remove the title and the editor remove_post_type_support( $this->post_type, 'title' ); @@ -940,11 +930,8 @@ function get_guest_author_thumbnail( $guest_author, $size ) { $args = array( 'class' => "avatar avatar-{$size} photo", ); - if ( in_array( $size, $this->avatar_sizes ) ) { - $size = 'guest-author-' . $size; - } else { - $size = array( $size, $size ); - } + + $size = array( $size, $size ); $thumbnail = get_the_post_thumbnail( $guest_author->ID, $size, $args ); From c8b4a166a4d6a3b89795d4babdddd47c792392ec Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 30 Jun 2017 14:41:20 -0600 Subject: [PATCH 104/231] remove duplicated linked author byline --- template-tags.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/template-tags.php b/template-tags.php index ffc398ae..8993984a 100644 --- a/template-tags.php +++ b/template-tags.php @@ -35,6 +35,8 @@ function get_coauthors( $post_id = 0 ) { } } // the empty else case is because if we force guest authors, we don't ever care what value wp_posts.post_author has. } + // remove duplicate $coauthors objects from mapping user accounts to guest authors accounts + $coauthors = array_unique( $coauthors, SORT_REGULAR ); return $coauthors; } From 39e7e5e9ff617bfc19764cf654835131601b0621 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 12:04:27 -0600 Subject: [PATCH 105/231] Redid README.md with better markdown formatting --- readme.txt => README.md | 167 ++++++++++++++++++++-------------------- 1 file changed, 84 insertions(+), 83 deletions(-) rename readme.txt => README.md (71%) diff --git a/readme.txt b/README.md similarity index 71% rename from readme.txt rename to README.md index bfe56edf..3e0ef6c4 100644 --- a/readme.txt +++ b/README.md @@ -1,13 +1,14 @@ -=== Co-Authors Plus === -Contributors: batmoo, danielbachhuber, automattic -Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.8 -Requires at least: 4.1 -Stable tag: 3.2.2 +# Co-Authors Plus + +* Contributors: batmoo, danielbachhuber, automattic +* Tags: authors, users, multiple authors, coauthors, multi-author, publishing +* Tested up to: 4.8 +* Requires at least: 4.1 +* Stable tag: 3.2.2 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box -== Description == +## Description Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box. Co-authored posts appear on a co-author's archive page and in their feed. Co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is core behavior). @@ -17,68 +18,68 @@ On the frontend, use the [Co-Authors Plus template tags](http://vip.wordpress.co This plugin is an almost complete rewrite of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/) (2007). The original plugin was inspired by the 'Multiple Authors' plugin by Mark Jaquith (2005). -== Frequently Asked Questions == +## Frequently Asked Questions -= How do I add Co-Authors Plus support to my theme? = +* How do I add Co-Authors Plus support to my theme? -If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. +> If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. -= What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = +* What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = -When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. +> When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. -= Can I use Co-Authors Plus with WordPress multisite? = +* Can I use Co-Authors Plus with WordPress multisite? = -Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. +> Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. -= Who needs permission to do what? = +* Who needs permission to do what? -To assign co-authors to posts, a WordPress user will need the 'edit_others_posts' capability. This is typically granted to the Editor role, but can be altered with the 'coauthors_plus_edit_authors' filter. +> To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. -To create new guest author profiles, a WordPress will need the 'list_users' capability. This is typically granted to the Administrator role, but can be altered with the 'coauthors_guest_author_manage_cap' filter. +> To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. -= Can I easily create a list of all co-authors? = +* Can I easily create a list of all co-authors? -Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. +> Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. -== Upgrade Notice == +## Upgrade Notice -= 3.1 = +**3.1** Manage co-authors from quick edit, Jetpack Open Graph support, bug fixes. -= 3.0.7 = +**3.0.7** Support for symlink installations, updated French translation, bug fixes. -= 3.0.4 = +**3.0.4** Bug fixes and the ability to automatically add co-authors to your feeds. -= 3.0.1 = +**3.0.1** Bug fixes and minor enhancements -== Changelog == +### Changelog ### -= 3.2.2 = +**3.2.2** * Fix broken author ordering in 4.7+ (props mslinnea) * Fix no moderation e-mail bug (props RobjS) * Cached functions in CLI commands (props jasonbahl) * Fix missing echos (props trepmal) * Add `coauthors_guest_author_query_args` filter (props trepmal) -= 3.2.1 (May 16, 2016) = +**3.2.1 (May 16, 2016)** * Hotfix for broken Guest Author bio metabox (props JS Morisset) -= 3.2 (May 12, 2016) = -Various minor bug and security fixes +**3.2 (May 12, 2016)** +* Various minor bug and security fixes -= 3.1.2 (Aug. 31, 2015) = +**3.1.2 (Aug. 31, 2015)** * Minor bug fixes and coding standards changes. -* The author's display name is now filtered through the_author in coauthors_posts_links_single() +* The author's display name is now filtered through `the_author` in `coauthors_posts_links_single()` * New Russian and Ukrainian translations, courtesy of [Jurko Chervony](http://skinik.name/). -= 3.1.1 (Mar. 20, 2014) = +**3.1.1 (Mar. 20, 2014)** * Bug fix: Co-authors selection UI should appear when creating a new post too. -= 3.1 (Mar. 17, 2014) = +**3.1 (Mar. 17, 2014)** * Manage co-authors from Quick Edit. Props [mpatek](https://github.com/mpatek). * Updated Spanish translation, courtesy of [sergiomajluf](https://github.com/sergiomajluf). * Now matches core behavior when displaying author archive on multisite: user of the blog, or previously published author on the blog. @@ -91,14 +92,14 @@ Various minor bug and security fixes * Packages a composer.json file for those using Composer. * Beginnings of unit test coverage for core features. Increased minimum required WordPress version to 3.7 because WordPress.org unit testing framework doesn't work reliabilty below that. -= 3.0.7 (Jan. 27, 2014) = +**3.0.7 (Jan. 27, 2014)** * Better support for installing Co-Authors Plus as a symlinked directory. [Follow these instructions](http://kaspars.net/blog/wordpress/plugins-via-symlinks) to filter `plugins_url`. * Links to authors' posts pages to comply to hCard microformat, which Google depends on. * New `coauthors_emails()` template tag to list email addresses of the co-authors. Props [benlk](https://github.com/benlk). * Bug fix: Remove extraneous space between last two co-authors output. Props [johnciacia](https://github.com/johnciacia). * Updated French translation, courtesy of Jojaba (via email). -= 3.0.6 (Dec. 9, 2013) = +**3.0.6 (Dec. 9, 2013)** * New Swedish translation, courtesy of [alundstroem](https://github.com/alundstroem) * Updated German translation, courtesy of [krafit](https://github.com/krafit). * New Dutch translation, courtesy of [kardotim](https://github.com/kardotim) @@ -108,151 +109,151 @@ Various minor bug and security fixes * Fix Strict warnings from CPT's that don't define all capabilities * New swap-coauthors CLI command for replacing one co-author with another -= 3.0.5 (Feb. 18, 2013) = -* New filter 'coauthors_search_authors_get_terms_args' allows you to increase the number of matches returned with AJAX co-author selection +**3.0.5 (Feb. 18, 2013)** +* New filter `coauthors_search_authors_get_terms_args` allows you to increase the number of matches returned with AJAX co-author selection * Bug fix: If there isn't an author term yet for a co-author, avoid an erronous join that caused duplicate posts to appear. -= 3.0.4 (Jan. 6, 2013) = +**3.0.4 (Jan. 6, 2013)** = * Support for automatically adding co-authors to your feeds. Props [cfg](https://github.com/cfg). * Bug fix: No Co-Authors Plus on attachments. For now. * Bug fix: Better support for co-authors with non-standard user_nicenames. Props [STRML](https://github.com/STRML). -= 3.0.3 (Dec. 3, 2012) = -* Bug fix: The default order for the 'author' taxonomy should be 'term_order', in order for the author positions to stick. Props [lgedeon](https://github.com/lgedeon) +**3.0.3 (Dec. 3, 2012)** +* Bug fix: The default order for the 'author' taxonomy should be `term_order`, in order for the author positions to stick. Props [lgedeon](https://github.com/lgedeon) -= 3.0.2 (Nov. 23, 2012) = -* Bug fix: Fall back to non-pretty permalinks when the author permastruct is empty, so that coauthors_posts_links() doesn't link to the homepage +**3.0.2 (Nov. 23, 2012)** +* Bug fix: Fall back to non-pretty permalinks when the author permastruct is empty, so that `coauthors_posts_links()` doesn't link to the homepage -= 3.0.1 (Nov. 21, 2012) = +**3.0.1 (Nov. 21, 2012)** * Add your own custom columns to the guest authors table using filters. Props [cfg](https://github.com/cfg) * A new wp-cli subcommand for renaming co-authors and another for removing author terms mistakenly assigned to revisions * Bug fix: Using a featured image for a guest author avatar didn't work. Now it does. * Bug fix: Don't assign author terms to revisions to avoid unnecessary database bloat -* Bug fix: Make the coauthors_wp_list_authors() template tag work again -* Bug fix: Improve capability filtering by properly handling super admin access and situations where user_id = 0 +* Bug fix: Make the `coauthors_wp_list_authors()` template tag work again +* Bug fix: Improve capability filtering by properly handling super admin access and situations where `user_id = 0` * Minor UI enhancements for guest authors -= 3.0 (Nov. 12, 2012) = +**3.0 (Nov. 12, 2012)** * Create guest author profiles for bylines you'd like to assign without creating WordPress user accounts. Guest authors can have all of the same fields as normal users including display name, biography, and avatars. * Support for non-Latin characters in usernames and guest author names * wp-cli subcommands for creating, assigning, and reassigning co-authors -* For themes using core template tags like the_author() or the_author_posts_link(), you enable Co-Authors Plus support with a simple filter -* New author terms are now prefixed with 'cap-' to avoid collisions with global scope -* Bug fix: Apply query filters to only post_types registered with the taxonomy. Props [Tom Ransom](https://github.com/1bigidea) -* Filter coauthors_posts_link_single() with 'coauthors_posts_link'. Also adds rel="author". Props [Amit Sannad](https://github.com/asannad) and [Gabriel Koen](https://github.com/mintindeed) +* For themes using core template tags like `the_author()` or `the_author_posts_link()`, you enable Co-Authors Plus support with a simple filter +* New author terms are now prefixed with `cap-` to avoid collisions with global scope +* Bug fix: Apply query filters to only `post_types` registered with the taxonomy. Props [Tom Ransom](https://github.com/1bigidea) +* Filter `coauthors_posts_link_single()` with `coauthors_posts_link`. Also adds `rel="author"`. Props [Amit Sannad](https://github.com/asannad) and [Gabriel Koen](https://github.com/mintindeed) * Filter for the context and priorities of the Co-Authors meta boxes. Props [Tomáš Kapler](https://github.com/tkapler) * Renamed the post meta box for selecting authors so it applies to many post types. Props [John Blackbourn](https://github.com/johnbillion) -= 2.6.4 (May 7, 2012) = +**2.6.4 (May 7, 2012)** * Bug fix: Properly filter the user query so users can AJAX search against the display name field again * If https is used for the admin, also use the secure Gravatar URL. Props [rmcfrazier](https://github.com/rmcfrazier) -= 2.6.3 (Apr. 30, 2012) = +**2.6.3 (Apr. 30, 2012)** * AJAX user search is back to searching against user login, display name, email address and user ID. The method introduced in v2.6.2 didn't scale well * French translation courtesy of Sylvain Bérubé * Spanish translation courtesy of Alejandro Arcos * Bug fix: Resolved incorrect caps check against user editing an already published post. [See forum thread](http://wordpress.org/support/topic/multiple-authors-cant-edit-pages?replies=17#post-2741243) -= 2.6.2 (Mar. 6, 2012) = +**2.6.2 (Mar. 6, 2012)** * AJAX user search matches against first name, last name, and nickname fields too, in addition to display name, user login, and email address * Comment moderation and approved notifications are properly sent to all co-authors with the correct caps -* Filter required capability for user to be returned in an AJAX search with 'coauthors_edit_author_cap' -* Filter out administrators and other non-authors from AJAX search with 'coauthors_edit_ignored_authors' +* Filter required capability for user to be returned in an AJAX search with `coauthors_edit_author_cap` +* Filter out administrators and other non-authors from AJAX search with `coauthors_edit_ignored_authors` * Automatically adds co-authors to Edit Flow's story budget and calendar views * Bug fix: Don't set post_author value to current user when quick editing a post. This doesn't appear in the UI anywhere, but adds the post to the current user's list of posts * Bug fix: Properly cc other co-authors on new comment email notifications * Bug fix: If a user has already been added as an author to a post, don't show them in the AJAX search again * Bug fix: Allow output constants to be defined in a theme's functions.php file and include filters you can use instead -= 2.6.1 (Dec. 30, 2011) = +**2.6.1 (Dec. 30, 2011)** * Fix mangled usernames because of sanitize_key http://wordpress.org/support/topic/plugin-co-authors-plus-26-not-working-with-wp-33 -= 2.6 (Dec. 22, 2011) = +**2.6 (Dec. 22, 2011)** * Sortable authors: Drag and drop the order of the authors as you'd like them to appear ([props kingkool68](http://profiles.wordpress.org/users/kingkool68/)) * Search for authors by display name (instead of nicename which was essentially the same as user_login) * Option to remove the first author when there are two or more so it's less confusing * Bumped requirements to WordPress 3.1 * Bug fix: Update the published post count for each user more reliably -= 2.5.3 (Aug. 14, 2011) = -* Bug fix: Removed extra comma when only two authors were listed. If you used the COAUTHORS_DEFAULT_BETWEEN_LAST constant, double-check what you have +**2.5.3 (Aug. 14, 2011)** +* Bug fix: Removed extra comma when only two authors were listed. If you used the `COAUTHORS_DEFAULT_BETWEEN_LAST` constant, double-check what you have -= 2.5.2 (Apr. 23, 2011) = +**2.5.2 (Apr. 23, 2011)** * Bug: Couldn't query terms and authors at the same time (props nbaxley) * Bug: Authors with empty fields (e.g. first name) were displaying blank in some cases * Bug: authors with spaces in usernames not getting saved (props MLmsw, Ruben S. and others!) * Bug: revisions getting wrong user attached (props cliquenoir!) -= 2.5.1 (Mar. 26, 2011) = +**2.5.1 (Mar. 26, 2011)** * Fix with author post count (throwing errors) -= 2.5 (Mar. 26, 2011) = +**2.5 (Mar. 26, 2011)** * Custom Post Type Support * Compatibility with WP 3.0 and 3.1 * Gravatars * Lots and lots and lots of bug fixes * Thanks to everyone who submitted bugs, fixes, and suggestions! And for your patience! -= 2.1.1 (Oct. 16, 2009) = +**2.1.1 (Oct. 16, 2009)** * Fix for coauthors not being added if their username is different from display name * Fixes to readme.txt (fixes for textual and punctuation errors, language clarification, minor formatting changes) courtesy of [Waldo Jaquith](http://www.vqronline.org) -= 2.1 (Oct. 11, 2009) = +**2.1 (Oct. 11, 2009)** * Fixed issues related to localization. Thanks to Jan Zombik for the fixes. -* Added set_time_limit to update function to get around timeout issues when upgrading plugin +* Added `set_time_limit` to update function to get around timeout issues when upgrading plugin -= 2.0 (Oct. 11, 2009) = -* Plugin mostly rewritten to make use of taxonomy instead of post_meta +**2.0 (Oct. 11, 2009)** +* Plugin mostly rewritten to make use of taxonomy instead of `post_meta` * Can now see all authors of a post under the author column from Edit Posts page * All authors of a post are now notified on a new comment * Various javascript enhancements * New option to allow subscribers to be added as authors * All Authors can edit they posts of which they are coauthors -* FIX: Issues with wp_coauthors_list function +* FIX: Issues with `wp_coauthors_list` function * FIX: Issues with coauthored posts not showing up on author archives -= 1.2.0 (Jun. 16, 2012) = +**1.2.0 (Jun. 16, 2012)** * FIX: Added compatibility for WordPress 2.8 -* FIX: Added new template tags (get_the_coauthor_meta & the_coauthor_meta) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details. -* FIX: Plugin should now work for plugins not using the 'wp_' DB prefix +* FIX: Added new template tags (`get_the_coauthor_meta` & `the_coauthor_meta`) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details. +* FIX: Plugin should now work for plugins not using the `wp_` DB prefix * FIX: Coauthors should no longer be alphabetically reordered when the post is updated * FIX: Plugin now used WordPress native AJAX calls to tighten security * DOCS: Added details about the new template tags -= 1.1.5 (Apr. 26, 2009) = +**1.1.5 (Apr. 26, 2009)** * FIX: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname * FIX: When editing an author, and clicking on a suggested author, the original author was not be removed * DOCS: Added code comments to javascript; more still to be added * DOCS: Updated readme information -= 1.1.4 (Apr. 25, 2009) = +**1.1.4 (Apr. 25, 2009)** * Disabled "New Author" output in suggest box, for now * Hopefully fixed SVN issue (if you're having trouble with the plugin, please delete the plugin and reinstall) -= 1.1.3 (Apr. 23, 2009) = +**1.1.3 (Apr. 23, 2009)** * Add blur event to disable input box * Limit only one edit at a time. * Checked basic cross-browser compatibility (Firefox 3 OS X, Safari 3 OS X, IE7 Vista). * Add suggest javascript plugin to Edit Page. -= 1.1.2 (Apr. 19, 2009) = +**1.1.2 (Apr. 19, 2009)** * Disabled form submit when enter pressed. -= 1.1.1 (Apr. 15, 2009) = +**1.1.1 (Apr. 15, 2009)** * Changed SQL query to return only contributor-level and above users. -= 1.1.0 (Apr. 14, 2009) = +**1.1.0 (Apr. 14, 2009)** * Initial beta release. -== Installation == +## Installation 1. IMPORTANT: Please disable the original Co-Authors plugin (if you are using it) before installing Co-Authors Plus -1. Extract the coauthors-plus.zip file and upload its contents to the `/wp-content/plugins/` directory. Alternately, you can install directly from the Plugin directory within your WordPress Install. -1. Activate the plugin through the "Plugins" menu in WordPress. -1. Place the appropriate [co-authors template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) in your template. -1. Add co-authors to your posts and pages. +2. Extract the coauthors-plus.zip file and upload its contents to the `/wp-content/plugins/` directory. Alternately, you can install directly from the Plugin directory within your WordPress Install. +3. Activate the plugin through the "Plugins" menu in WordPress. +4. Place the appropriate [co-authors template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) in your template. +5. Add co-authors to your posts and pages. -== Screenshots == +## Screenshots 1. Multiple authors can be added to a Post, Page, or Custom Post Type using an auto-complete interface. 2. The order of your co-authors can be changed by drag and drop. From 457033dc385e89e844d4dfcc36fdde61d7f15290 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 12:21:06 -0600 Subject: [PATCH 106/231] added readme.txt back --- readme.txt | 259 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 readme.txt diff --git a/readme.txt b/readme.txt new file mode 100644 index 00000000..bfe56edf --- /dev/null +++ b/readme.txt @@ -0,0 +1,259 @@ +=== Co-Authors Plus === +Contributors: batmoo, danielbachhuber, automattic +Tags: authors, users, multiple authors, coauthors, multi-author, publishing +Tested up to: 4.8 +Requires at least: 4.1 +Stable tag: 3.2.2 + +Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box + +== Description == + +Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box. Co-authored posts appear on a co-author's archive page and in their feed. Co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is core behavior). + +Add writers as bylines without creating WordPress user accounts. Simply [create a guest author profile](http://vip.wordpress.com/documentation/add-guest-bylines-to-your-content-with-co-authors-plus/) for the writer and assign the byline as you normally would. + +On the frontend, use the [Co-Authors Plus template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) to list co-authors anywhere you'd normally list the author. + +This plugin is an almost complete rewrite of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/) (2007). The original plugin was inspired by the 'Multiple Authors' plugin by Mark Jaquith (2005). + +== Frequently Asked Questions == + += How do I add Co-Authors Plus support to my theme? = + +If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. + += What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = + +When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. + += Can I use Co-Authors Plus with WordPress multisite? = + +Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. + += Who needs permission to do what? = + +To assign co-authors to posts, a WordPress user will need the 'edit_others_posts' capability. This is typically granted to the Editor role, but can be altered with the 'coauthors_plus_edit_authors' filter. + +To create new guest author profiles, a WordPress will need the 'list_users' capability. This is typically granted to the Administrator role, but can be altered with the 'coauthors_guest_author_manage_cap' filter. + += Can I easily create a list of all co-authors? = + +Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. + +== Upgrade Notice == + += 3.1 = +Manage co-authors from quick edit, Jetpack Open Graph support, bug fixes. + += 3.0.7 = +Support for symlink installations, updated French translation, bug fixes. + += 3.0.4 = +Bug fixes and the ability to automatically add co-authors to your feeds. + += 3.0.1 = +Bug fixes and minor enhancements + +== Changelog == + += 3.2.2 = +* Fix broken author ordering in 4.7+ (props mslinnea) +* Fix no moderation e-mail bug (props RobjS) +* Cached functions in CLI commands (props jasonbahl) +* Fix missing echos (props trepmal) +* Add `coauthors_guest_author_query_args` filter (props trepmal) + += 3.2.1 (May 16, 2016) = +* Hotfix for broken Guest Author bio metabox (props JS Morisset) + += 3.2 (May 12, 2016) = +Various minor bug and security fixes + += 3.1.2 (Aug. 31, 2015) = +* Minor bug fixes and coding standards changes. +* The author's display name is now filtered through the_author in coauthors_posts_links_single() +* New Russian and Ukrainian translations, courtesy of [Jurko Chervony](http://skinik.name/). + += 3.1.1 (Mar. 20, 2014) = +* Bug fix: Co-authors selection UI should appear when creating a new post too. + += 3.1 (Mar. 17, 2014) = +* Manage co-authors from Quick Edit. Props [mpatek](https://github.com/mpatek). +* Updated Spanish translation, courtesy of [sergiomajluf](https://github.com/sergiomajluf). +* Now matches core behavior when displaying author archive on multisite: user of the blog, or previously published author on the blog. +* Breaking change: "Create Profile" link is no longer shown by default on the Manage Users screen. Instead, it can be enabled with the `coauthors_show_create_profile_user_link` filter. +* Guest authors work properly with Jetpack Open Graph tags. Props [hibernation](https://github.com/hibernation). +* Guest author profile editor now supports a few different fields. Props [alpha1](https://github.com/alpha1). +* New `coauthors_count_published_post_types` filter for specifying the post type(s) used when calculating the user's number of published posts. +* Bug fix: Ensure `post_author` is set to one of the co-authors assigned to a post. +* Bug fix: Filter author feed link for guest authors on the author page. Props [hibernation](https://github.com/hibernation). +* Packages a composer.json file for those using Composer. +* Beginnings of unit test coverage for core features. Increased minimum required WordPress version to 3.7 because WordPress.org unit testing framework doesn't work reliabilty below that. + += 3.0.7 (Jan. 27, 2014) = +* Better support for installing Co-Authors Plus as a symlinked directory. [Follow these instructions](http://kaspars.net/blog/wordpress/plugins-via-symlinks) to filter `plugins_url`. +* Links to authors' posts pages to comply to hCard microformat, which Google depends on. +* New `coauthors_emails()` template tag to list email addresses of the co-authors. Props [benlk](https://github.com/benlk). +* Bug fix: Remove extraneous space between last two co-authors output. Props [johnciacia](https://github.com/johnciacia). +* Updated French translation, courtesy of Jojaba (via email). + += 3.0.6 (Dec. 9, 2013) = +* New Swedish translation, courtesy of [alundstroem](https://github.com/alundstroem) +* Updated German translation, courtesy of [krafit](https://github.com/krafit). +* New Dutch translation, courtesy of [kardotim](https://github.com/kardotim) +* New filter for specifying the default author assigned to a post. Props [tannerm](https://github.com/tannerm) +* Bug fix: When filtering a user's published post count, use the value of their guest author profile if one is mapped. +* Added support for checkboxes in Guest Author profiles +* Fix Strict warnings from CPT's that don't define all capabilities +* New swap-coauthors CLI command for replacing one co-author with another + += 3.0.5 (Feb. 18, 2013) = +* New filter 'coauthors_search_authors_get_terms_args' allows you to increase the number of matches returned with AJAX co-author selection +* Bug fix: If there isn't an author term yet for a co-author, avoid an erronous join that caused duplicate posts to appear. + += 3.0.4 (Jan. 6, 2013) = +* Support for automatically adding co-authors to your feeds. Props [cfg](https://github.com/cfg). +* Bug fix: No Co-Authors Plus on attachments. For now. +* Bug fix: Better support for co-authors with non-standard user_nicenames. Props [STRML](https://github.com/STRML). + += 3.0.3 (Dec. 3, 2012) = +* Bug fix: The default order for the 'author' taxonomy should be 'term_order', in order for the author positions to stick. Props [lgedeon](https://github.com/lgedeon) + += 3.0.2 (Nov. 23, 2012) = +* Bug fix: Fall back to non-pretty permalinks when the author permastruct is empty, so that coauthors_posts_links() doesn't link to the homepage + += 3.0.1 (Nov. 21, 2012) = +* Add your own custom columns to the guest authors table using filters. Props [cfg](https://github.com/cfg) +* A new wp-cli subcommand for renaming co-authors and another for removing author terms mistakenly assigned to revisions +* Bug fix: Using a featured image for a guest author avatar didn't work. Now it does. +* Bug fix: Don't assign author terms to revisions to avoid unnecessary database bloat +* Bug fix: Make the coauthors_wp_list_authors() template tag work again +* Bug fix: Improve capability filtering by properly handling super admin access and situations where user_id = 0 +* Minor UI enhancements for guest authors + += 3.0 (Nov. 12, 2012) = +* Create guest author profiles for bylines you'd like to assign without creating WordPress user accounts. Guest authors can have all of the same fields as normal users including display name, biography, and avatars. +* Support for non-Latin characters in usernames and guest author names +* wp-cli subcommands for creating, assigning, and reassigning co-authors +* For themes using core template tags like the_author() or the_author_posts_link(), you enable Co-Authors Plus support with a simple filter +* New author terms are now prefixed with 'cap-' to avoid collisions with global scope +* Bug fix: Apply query filters to only post_types registered with the taxonomy. Props [Tom Ransom](https://github.com/1bigidea) +* Filter coauthors_posts_link_single() with 'coauthors_posts_link'. Also adds rel="author". Props [Amit Sannad](https://github.com/asannad) and [Gabriel Koen](https://github.com/mintindeed) +* Filter for the context and priorities of the Co-Authors meta boxes. Props [Tomáš Kapler](https://github.com/tkapler) +* Renamed the post meta box for selecting authors so it applies to many post types. Props [John Blackbourn](https://github.com/johnbillion) + += 2.6.4 (May 7, 2012) = +* Bug fix: Properly filter the user query so users can AJAX search against the display name field again +* If https is used for the admin, also use the secure Gravatar URL. Props [rmcfrazier](https://github.com/rmcfrazier) + += 2.6.3 (Apr. 30, 2012) = +* AJAX user search is back to searching against user login, display name, email address and user ID. The method introduced in v2.6.2 didn't scale well +* French translation courtesy of Sylvain Bérubé +* Spanish translation courtesy of Alejandro Arcos +* Bug fix: Resolved incorrect caps check against user editing an already published post. [See forum thread](http://wordpress.org/support/topic/multiple-authors-cant-edit-pages?replies=17#post-2741243) + += 2.6.2 (Mar. 6, 2012) = +* AJAX user search matches against first name, last name, and nickname fields too, in addition to display name, user login, and email address +* Comment moderation and approved notifications are properly sent to all co-authors with the correct caps +* Filter required capability for user to be returned in an AJAX search with 'coauthors_edit_author_cap' +* Filter out administrators and other non-authors from AJAX search with 'coauthors_edit_ignored_authors' +* Automatically adds co-authors to Edit Flow's story budget and calendar views +* Bug fix: Don't set post_author value to current user when quick editing a post. This doesn't appear in the UI anywhere, but adds the post to the current user's list of posts +* Bug fix: Properly cc other co-authors on new comment email notifications +* Bug fix: If a user has already been added as an author to a post, don't show them in the AJAX search again +* Bug fix: Allow output constants to be defined in a theme's functions.php file and include filters you can use instead + += 2.6.1 (Dec. 30, 2011) = +* Fix mangled usernames because of sanitize_key http://wordpress.org/support/topic/plugin-co-authors-plus-26-not-working-with-wp-33 + += 2.6 (Dec. 22, 2011) = +* Sortable authors: Drag and drop the order of the authors as you'd like them to appear ([props kingkool68](http://profiles.wordpress.org/users/kingkool68/)) +* Search for authors by display name (instead of nicename which was essentially the same as user_login) +* Option to remove the first author when there are two or more so it's less confusing +* Bumped requirements to WordPress 3.1 +* Bug fix: Update the published post count for each user more reliably + += 2.5.3 (Aug. 14, 2011) = +* Bug fix: Removed extra comma when only two authors were listed. If you used the COAUTHORS_DEFAULT_BETWEEN_LAST constant, double-check what you have + += 2.5.2 (Apr. 23, 2011) = +* Bug: Couldn't query terms and authors at the same time (props nbaxley) +* Bug: Authors with empty fields (e.g. first name) were displaying blank in some cases +* Bug: authors with spaces in usernames not getting saved (props MLmsw, Ruben S. and others!) +* Bug: revisions getting wrong user attached (props cliquenoir!) + += 2.5.1 (Mar. 26, 2011) = +* Fix with author post count (throwing errors) + += 2.5 (Mar. 26, 2011) = +* Custom Post Type Support +* Compatibility with WP 3.0 and 3.1 +* Gravatars +* Lots and lots and lots of bug fixes +* Thanks to everyone who submitted bugs, fixes, and suggestions! And for your patience! + += 2.1.1 (Oct. 16, 2009) = +* Fix for coauthors not being added if their username is different from display name +* Fixes to readme.txt (fixes for textual and punctuation errors, language clarification, minor formatting changes) courtesy of [Waldo Jaquith](http://www.vqronline.org) + += 2.1 (Oct. 11, 2009) = +* Fixed issues related to localization. Thanks to Jan Zombik for the fixes. +* Added set_time_limit to update function to get around timeout issues when upgrading plugin + += 2.0 (Oct. 11, 2009) = +* Plugin mostly rewritten to make use of taxonomy instead of post_meta +* Can now see all authors of a post under the author column from Edit Posts page +* All authors of a post are now notified on a new comment +* Various javascript enhancements +* New option to allow subscribers to be added as authors +* All Authors can edit they posts of which they are coauthors +* FIX: Issues with wp_coauthors_list function +* FIX: Issues with coauthored posts not showing up on author archives + += 1.2.0 (Jun. 16, 2012) = +* FIX: Added compatibility for WordPress 2.8 +* FIX: Added new template tags (get_the_coauthor_meta & the_coauthor_meta) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details. +* FIX: Plugin should now work for plugins not using the 'wp_' DB prefix +* FIX: Coauthors should no longer be alphabetically reordered when the post is updated +* FIX: Plugin now used WordPress native AJAX calls to tighten security +* DOCS: Added details about the new template tags + += 1.1.5 (Apr. 26, 2009) = +* FIX: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname +* FIX: When editing an author, and clicking on a suggested author, the original author was not be removed +* DOCS: Added code comments to javascript; more still to be added +* DOCS: Updated readme information + += 1.1.4 (Apr. 25, 2009) = +* Disabled "New Author" output in suggest box, for now +* Hopefully fixed SVN issue (if you're having trouble with the plugin, please delete the plugin and reinstall) + += 1.1.3 (Apr. 23, 2009) = +* Add blur event to disable input box +* Limit only one edit at a time. +* Checked basic cross-browser compatibility (Firefox 3 OS X, Safari 3 OS X, IE7 Vista). +* Add suggest javascript plugin to Edit Page. + += 1.1.2 (Apr. 19, 2009) = +* Disabled form submit when enter pressed. + += 1.1.1 (Apr. 15, 2009) = +* Changed SQL query to return only contributor-level and above users. + += 1.1.0 (Apr. 14, 2009) = +* Initial beta release. + +== Installation == + +1. IMPORTANT: Please disable the original Co-Authors plugin (if you are using it) before installing Co-Authors Plus +1. Extract the coauthors-plus.zip file and upload its contents to the `/wp-content/plugins/` directory. Alternately, you can install directly from the Plugin directory within your WordPress Install. +1. Activate the plugin through the "Plugins" menu in WordPress. +1. Place the appropriate [co-authors template tags](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) in your template. +1. Add co-authors to your posts and pages. + +== Screenshots == + +1. Multiple authors can be added to a Post, Page, or Custom Post Type using an auto-complete interface. +2. The order of your co-authors can be changed by drag and drop. +3. Guest authors allow you to assign bylines without creating WordPress user accounts. You can also override existing WordPress account meta by mapping a guest author to a WordPress user. From 51ac36670d7d38f2d740342c501f1f34177d8d14 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 5 Jul 2017 13:35:22 -0600 Subject: [PATCH 107/231] remove quotes, stray =s and upgrade notice section --- README.md | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3e0ef6c4..b3c93f1a 100644 --- a/README.md +++ b/README.md @@ -22,41 +22,27 @@ This plugin is an almost complete rewrite of the Co-Authors plugin originally de * How do I add Co-Authors Plus support to my theme? -> If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. +If you've just installed Co-Authors Plus, you might notice that the bylines are being added in the backend but aren't appearing on the frontend. You'll need to [add the template tags to your theme](http://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme/) before the bylines will appear. -* What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? = +* What happens to posts and pages when I delete a user assigned to a post or page as a coauthor? -> When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. +When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. -* Can I use Co-Authors Plus with WordPress multisite? = +* Can I use Co-Authors Plus with WordPress multisite? -> Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. +Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. * Who needs permission to do what? -> To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. +To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. -> To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. +To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. * Can I easily create a list of all co-authors? -> Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. +Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. -## Upgrade Notice - -**3.1** -Manage co-authors from quick edit, Jetpack Open Graph support, bug fixes. - -**3.0.7** -Support for symlink installations, updated French translation, bug fixes. - -**3.0.4** -Bug fixes and the ability to automatically add co-authors to your feeds. - -**3.0.1** -Bug fixes and minor enhancements - -### Changelog ### +## Changelog ## **3.2.2** * Fix broken author ordering in 4.7+ (props mslinnea) From b78650f46c0e15b040af677db928c41abe5bc86c Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 6 Jul 2017 16:54:26 -0700 Subject: [PATCH 108/231] Do not 404 when guest author archive has 0 posts. Addresses #425 (#440) Resolves #425, #409 --- co-authors-plus.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 9c1661e8..db329c73 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1026,10 +1026,10 @@ public function fix_author_page() { $term = $this->get_author_term( $authordata ); } - if ( ( is_object( $authordata ) ) - || ( ! empty( $term ) && $term->count ) ) { + if ( is_object( $authordata ) || ! empty( $term ) ) { $wp_query->queried_object = $authordata; $wp_query->queried_object_id = $authordata->ID; + add_filter( 'pre_handle_404', '__return_true' ); } else { $wp_query->queried_object = $wp_query->queried_object_id = null; $wp_query->is_author = $wp_query->is_archive = false; From 0e25f15cd2a0aa5f25dfa7f39b26beb54364aa81 Mon Sep 17 00:00:00 2001 From: jordie23 Date: Wed, 12 Jul 2017 15:26:43 +1000 Subject: [PATCH 109/231] Fix invalid CSS (#442) --- css/co-authors-plus.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/css/co-authors-plus.css b/css/co-authors-plus.css index 8f9fdb8f..cf96a9df 100644 --- a/css/co-authors-plus.css +++ b/css/co-authors-plus.css @@ -42,7 +42,7 @@ width:200px; } #coauthors-list .ui-sortable-helper .coauthor-tag { - cursor: cursor:grabbing; + cursor: grabbing; cursor:-moz-grabbing; cursor:-webkit-grabbing; } @@ -107,4 +107,4 @@ padding: 5px 3px; margin-left: 30px; font-size: 13px; - } \ No newline at end of file + } From ca4d450f6fb2586ea9b70423420bbbf546dc28fa Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 11 Aug 2017 12:45:32 -0600 Subject: [PATCH 110/231] added hooks for creating/deleting guest authors --- php/class-coauthors-guest-authors.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index fda129b9..2bc39b44 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -201,6 +201,8 @@ function handle_create_guest_author_action() { wp_die( esc_html( $post_id->get_error_message() ) ); } + do_action( 'cap_guest_author_create' ); + // Redirect to the edit Guest Author screen $edit_link = get_edit_post_link( $post_id, 'redirect' ); $redirect_to = add_query_arg( 'message', 'guest-author-created', $edit_link ); @@ -271,6 +273,8 @@ function handle_delete_guest_author_action() { $args['message'] = 'delete-error'; } else { $args['message'] = 'guest-author-deleted'; + + do_action( 'cap_guest_author_del' ); } // Redirect to safety From 4756ca8b6f8ec7daa2d8bd5ee658498c62342278 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 8 Sep 2017 14:03:23 -0600 Subject: [PATCH 111/231] Fixes "Notice: Trying to get property of non-object" for users who have user_login with spaces --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 6f47c238..ced75e15 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -794,7 +794,7 @@ function coauthors_update_post( $post_id, $post ) { if ( ! $this->has_author_terms( $post_id ) ) { $user = get_userdata( $post->post_author ); if ( $user ) { - $this->add_coauthors( $post_id, array( $user->user_login ) ); + $this->add_coauthors( $post_id, array( $user->user_nicename ) ); } } } From 636397abbb3a651ae86e86ab8d5f708416b14fc9 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Fri, 8 Sep 2017 14:04:46 -0600 Subject: [PATCH 112/231] Fixes issue of not being able to reassign posts to user with user_login with spaces on deletion of a user --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ced75e15..79cf0d4f 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -886,7 +886,7 @@ function delete_user_action( $delete_id ) { if ( $post_ids ) { foreach ( $post_ids as $post_id ) { - $this->add_coauthors( $post_id, array( $reassign_user->user_login ), true ); + $this->add_coauthors( $post_id, array( $reassign_user->user_nicename ), true ); } } } From c4624caa88ba5e47e069c0b3ae86c51c5122dd03 Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Fri, 13 Oct 2017 11:27:32 -0600 Subject: [PATCH 113/231] Adding escaping --- template-tags.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/template-tags.php b/template-tags.php index 8128ee04..df7b9574 100644 --- a/template-tags.php +++ b/template-tags.php @@ -381,21 +381,21 @@ function coauthors_links_single( $author ) { if ( 'guest-author' === $author->type ) { if ( get_the_author_meta( 'website' ) ) { return sprintf( '%s', - get_the_author_meta( 'website' ), - esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), - get_the_author() + esc_url( get_the_author_meta( 'website' ) ), + esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ), + esc_html( get_the_author() ) ); } } elseif ( get_the_author_meta( 'url' ) ) { return sprintf( '%s', - get_the_author_meta( 'url' ), - esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), - get_the_author() + esc_url( get_the_author_meta( 'url' ) ), + esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ), + esc_html( get_the_author() ) ); } else { - return get_the_author(); + return esc_html( get_the_author() ); } } From b1d8a37fcd1ee297de5d72084c44f17f31311ac2 Mon Sep 17 00:00:00 2001 From: Paul Kevan Date: Fri, 20 Oct 2017 14:21:05 +0100 Subject: [PATCH 114/231] Adding details of filter for slow performance - Use simple tax queries for CAP to improve performance - Detail of filter to add to theme - Adding CLI command to run --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index b3c93f1a..43f8e09d 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,22 @@ To create new guest author profiles, a WordPress will need the `list_users` capa Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. +* I have a large database, will this make it slow? + +If the site has a large database, you may run into issues with heavier than usual queries. You can work around this by disabling compat mode and force it to use simpler, tax-only queries by adding the following to your theme: + +``` +// Use simple tax queries for CAP to improve performance +add_filter( 'coauthors_plus_should_query_post_author', '__return_false' ); +``` + +Note that this requires the site(s) to have proper terms set up for all users. You can do this with the following wp-cli command: + +``` +# This is pretty long-running and can be expensive; be careful! +$ wp --url=example.com co-authors-plus create-terms-for-posts +``` + ## Changelog ## **3.2.2** From 03dd56373a59d77b54e3de392a9709935f25d9a1 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 22 Oct 2017 13:38:01 +0100 Subject: [PATCH 115/231] Remove redundant test for 404 on Author Archive Since we made CAP consistent with core in it's handling of author archives where there are no posts (see https://github.com/Automattic/Co-Authors-Plus/issues/425) we no longer expect there to be a 404 response on the author archive for a guest author. --- tests/test-author-queried-object.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/test-author-queried-object.php b/tests/test-author-queried-object.php index 25689cf5..bba21db9 100644 --- a/tests/test-author-queried-object.php +++ b/tests/test-author-queried-object.php @@ -52,12 +52,6 @@ function test__author_queried_object_fix() { $this->go_to( get_author_posts_url( $author1 ) ); $this->assertQueryTrue( 'is_author', 'is_archive' ); - /** - * Author 2 is not yet an author on the blog - */ - $this->go_to( get_author_posts_url( $author2 ) ); - $this->assertQueryTrue( 'is_404' ); - // Add the user to the blog add_user_to_blog( $blog2, $author2, 'author' ); @@ -93,7 +87,6 @@ function test__author_queried_object_fix() { * Author 2 is no more */ $this->go_to( get_author_posts_url( $author2 ) ); - $this->assertQueryTrue( 'is_404' ); $this->assertEquals( false, get_user_by( 'id', $author2 ) ); restore_current_blog(); From 1ae3db4e3c34632d668b0d0de4c83a25532137b3 Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Mon, 30 Oct 2017 16:44:14 -0600 Subject: [PATCH 116/231] Fixed counting for guest author posts --- php/class-coauthors-wp-list-table.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index 497fe623..74f6b83a 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -251,7 +251,10 @@ function column_linked_account( $item ) { function column_posts( $item ) { global $coauthors_plus; $term = $coauthors_plus->get_author_term( $item ); - if ( $term ) { + $guest_count = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy ); + if ( ! empty( $item->linked_account ) && $guest_count->count ) { + $count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID ) + $guest_count->count; + } elseif ( $term ) { $count = $term->count; } else { $count = 0; From ec2209a8d8c22afec4fcbce19e8ea2009654c73e Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Mon, 30 Oct 2017 17:22:49 -0600 Subject: [PATCH 117/231] Users table will give accurate post count if linked guest author has post(s) --- co-authors-plus.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 2daeb4a6..0b0ef356 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -963,8 +963,15 @@ function filter_count_user_posts( $count, $user_id ) { $user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename ); $term = $this->get_author_term( $user ); - // Only modify the count if the author already exists as a term - if ( $term && ! is_wp_error( $term ) ) { + $guest_count = get_term_by( 'slug', 'cap-' . $user->user_nicename, $this->coauthor_taxonomy ); + // Only modify the count if it has a linked account with posts or the author exists as a term + if ( $user->linked_account && $guest_count->count ) { + if ( $term ) { + $count = $guest_count->count + $term->count; + } else { + $count = $guest_count->count; + } + } elseif ( $term && ! is_wp_error( $term ) ) { $count = $term->count; } From eddbc21408db328a80d5dffa48f80f298eff9baa Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Mon, 30 Oct 2017 17:30:54 -0600 Subject: [PATCH 118/231] No need to add $guest_count->count anymore now that the Users table displays the count properly --- php/class-coauthors-wp-list-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index 74f6b83a..58190639 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -253,7 +253,7 @@ function column_posts( $item ) { $term = $coauthors_plus->get_author_term( $item ); $guest_count = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy ); if ( ! empty( $item->linked_account ) && $guest_count->count ) { - $count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID ) + $guest_count->count; + $count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID ); } elseif ( $term ) { $count = $term->count; } else { From c8456e67ec37e1ee13b834425fac15e248ec6321 Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Mon, 30 Oct 2017 21:36:10 -0600 Subject: [PATCH 119/231] Added one more validation --- co-authors-plus.php | 10 +++++----- php/class-coauthors-wp-list-table.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 0b0ef356..4bd565b0 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -963,13 +963,13 @@ function filter_count_user_posts( $count, $user_id ) { $user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename ); $term = $this->get_author_term( $user ); - $guest_count = get_term_by( 'slug', 'cap-' . $user->user_nicename, $this->coauthor_taxonomy ); + $guest_term = get_term_by( 'slug', 'cap-' . $user->user_nicename, $this->coauthor_taxonomy ); // Only modify the count if it has a linked account with posts or the author exists as a term - if ( $user->linked_account && $guest_count->count ) { - if ( $term ) { - $count = $guest_count->count + $term->count; + if ( $user->linked_account && $guest_term->count ) { + if ( $term && ! is_wp_error( $term )) { + $count = $guest_term->count + $term->count; } else { - $count = $guest_count->count; + $count = $guest_term->count; } } elseif ( $term && ! is_wp_error( $term ) ) { $count = $term->count; diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index 58190639..a1f5046b 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -251,8 +251,8 @@ function column_linked_account( $item ) { function column_posts( $item ) { global $coauthors_plus; $term = $coauthors_plus->get_author_term( $item ); - $guest_count = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy ); - if ( ! empty( $item->linked_account ) && $guest_count->count ) { + $guest_term = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy ); + if ( ! empty( $item->linked_account ) && $guest_term->count ) { $count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID ); } elseif ( $term ) { $count = $term->count; From 7617511e211dca80ed721cf67ce5a85566146f6c Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Fri, 8 Dec 2017 13:33:50 -0700 Subject: [PATCH 120/231] set $coauthors_loading --- js/co-authors-plus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 833e9a7c..88a5e328 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -11,7 +11,7 @@ jQuery( document ).ready(function () { return false; }; - var $coauthors_loading; + var $coauthors_loading = jQuery(""); function coauthors_delete( elem ) { From a1b3d43baa6f69cb141fd0a0d052e614c8f91433 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 21 Dec 2017 14:37:57 +0530 Subject: [PATCH 121/231] [#198] Fix guest authors with non-ASCII characters --- co-authors-plus.php | 9 ++- js/co-authors-plus.js | 13 ++-- tests/test-manage-coauthors.php | 104 ++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 8 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 66a0602c..188436a8 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -766,7 +766,10 @@ function coauthors_set_post_author_field( $data, $postarr ) { // This action happens when a post is saved while editing a post if ( isset( $_REQUEST['coauthors-nonce'] ) && isset( $_POST['coauthors'] ) && is_array( $_POST['coauthors'] ) ) { - $author = sanitize_text_field( $_POST['coauthors'][0] ); + + // urlencode() is for encoding coauthor name with special characters to compare names when getting coauthor. + $author = urlencode( sanitize_text_field( $_POST['coauthors'][0] ) ); + if ( $author ) { $author_data = $this->get_coauthor_by( 'user_nicename', $author ); // If it's a guest author and has a linked account, store that information in post_author @@ -812,7 +815,7 @@ function coauthors_update_post( $post_id, $post ) { check_admin_referer( 'coauthors-edit', 'coauthors-nonce' ); $coauthors = (array) $_POST['coauthors']; - $coauthors = array_map( 'sanitize_text_field', $coauthors ); + $coauthors = array_map( 'sanitize_title', $coauthors ); $this->add_coauthors( $post_id, $coauthors ); } } else { @@ -1134,7 +1137,7 @@ public function ajax_suggest() { if( empty( $authors ) ) echo apply_filters( 'coauthors_no_matching_authors_message', 'Sorry, no matching authors found.'); foreach ( $authors as $author ) { - echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . $author->user_nicename ) . "\n"; + echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . urldecode( $author->user_nicename ) ) . "\n"; } die(); diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 88a5e328..c0ff38bb 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -99,7 +99,8 @@ jQuery( document ).ready(function () { co.bind( 'blur', coauthors_stop_editing ); // Set the value for the auto-suggest box to the co-author's name and hide it - co.val( unescape( author.name ) ) + // unescape() is deprecated, so replacing it with decodeURIComponent() here and every places. + co.val( decodeURIComponent( author.name ) ) .hide() .unbind( 'focus' ) ; @@ -178,7 +179,7 @@ jQuery( document ).ready(function () { ; if ( authorName ) - $co.attr( 'value', unescape( authorName ) ); + $co.attr( 'value', decodeURIComponent( authorName ) ); else $co.attr( 'value', coAuthorsPlusStrings.search_box_text ) .focus( function(){ $co.val( '' ) } ) @@ -199,7 +200,9 @@ jQuery( document ).ready(function () { author.login = jQuery.trim( vals[1] ); author.name = jQuery.trim( vals[2] ); author.email = jQuery.trim( vals[3] ); - author.nicename = jQuery.trim( vals[4] ); + + // Decode user-nicename if it has special characters in it. + author.nicename = decodeURIComponent( jQuery.trim( vals[4] ) ); if ( author.id=='New' ) { coauthors_new_author_display( name ); @@ -240,7 +243,7 @@ jQuery( document ).ready(function () { function coauthors_create_author_tag( author ) { var $tag = jQuery( '' ) - .html( unescape( author.name ) ) + .html( decodeURIComponent( author.name ) ) .attr( 'title', coAuthorsPlusStrings.input_box_title ) .addClass( 'coauthor-tag' ) // Add Click event to edit @@ -287,7 +290,7 @@ jQuery( document ).ready(function () { 'type': 'hidden', 'id': 'coauthors_hidden_input', 'name': 'coauthors[]', - 'value': unescape( author.nicename ) + 'value': decodeURIComponent( author.nicename ) }) ; diff --git a/tests/test-manage-coauthors.php b/tests/test-manage-coauthors.php index fad2f9ca..0c5a0d33 100644 --- a/tests/test-manage-coauthors.php +++ b/tests/test-manage-coauthors.php @@ -5,6 +5,7 @@ class Test_Manage_CoAuthors extends CoAuthorsPlus_TestCase { public function setUp() { parent::setUp(); + $this->admin1 = $this->factory->user->create( array( 'role' => 'administrator', 'user_login' => 'admin1' ) ); $this->author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor2' ) ); @@ -145,4 +146,107 @@ public function test_post_publish_count_for_coauthor() { $this->assertEquals( 1, count_user_posts( $editor1->ID ) ); } + + /** + * When filtering post data before saving to db, post_author should be set appropriately + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + */ + public function test_wp_insert_post_data_set_post_author() { + + global $coauthors_plus; + + $this->assertEquals( 10, has_filter( 'wp_insert_post_data', array( + $coauthors_plus, + 'coauthors_set_post_author_field', + ) ) ); + + wp_set_current_user( $this->author1 ); + + $author1 = get_user_by( 'id', $this->author1 ); + $author1_post1 = get_post( $this->author1_post1 ); + $data = array( + 'post_type' => $author1_post1->post_type, + 'post_author' => $author1_post1->post_author, + ); + + // Check post type is enabled or not. + $this->assertTrue( $coauthors_plus->is_post_type_enabled( $data['post_type'] ) ); + + // Encoding user nicename if it has any special characters in it. + $author = urlencode( sanitize_text_field( $author1->user_nicename ) ); + $this->assertNotEmpty( $author ); + + // Create guest author with linked account with user. + $coauthors_plus->guest_authors = new CoAuthors_Guest_Authors; + $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1 ); + + $editor1 = get_user_by( 'id', $this->editor1 ); + $editor1_data = $coauthors_plus->get_coauthor_by( 'user_nicename', $editor1->user_nicename ); + + $this->assertEquals( 'guest-author', $editor1_data->type ); + $this->assertNotEmpty( $editor1_data->linked_account ); + + // Main WP user. + $author_data = $coauthors_plus->get_coauthor_by( 'user_nicename', $author ); + $this->assertEquals( 'wpuser', $author_data->type ); + + // Checks if post_author is unset somehow and it is available from wp_get_current_user(). + unset( $data['post_author'] ); + + $user = wp_get_current_user(); + + $this->assertNotEmpty( $user->ID ); + $this->assertGreaterThan( 0, $user->ID ); + } + + /** + * Adding coauthors when saving post. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + */ + public function test_save_post_to_update_post_coauthor() { + + global $coauthors_plus; + + $this->assertEquals( 10, has_filter( 'wp_insert_post_data', array( + $coauthors_plus, + 'coauthors_set_post_author_field' + ) ) ); + + $author1_post1 = get_post( $this->author1_post1 ); + + // Check post type is enabled or not. + $this->assertTrue( $coauthors_plus->is_post_type_enabled( $author1_post1->post_type ) ); + + // If post does not have author terms. + $post_id = $this->factory->post->create(); + $post = get_post( $post_id ); + $user = get_userdata( $post->post_author ); + + $this->assertFalse( $coauthors_plus->has_author_terms( $post_id ) ); + $this->assertFalse( $user ); + + // If current user is not allowed to set authors. + wp_set_current_user( $this->author1 ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors( $author1_post1 ) ); + $this->assertTrue( $coauthors_plus->has_author_terms( $this->author1_post1 ) ); + + // If current user is allowed to set authors. + wp_set_current_user( $this->admin1 ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors( $author1_post1 ) ); + + $editor1 = get_user_by( 'id', $this->editor1 ); + + $coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ), true ); + + $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' ); + $_POST['coauthors'] = get_coauthors( $this->author1_post1 ); + + $this->assertNotEmpty( $_REQUEST['coauthors-nonce'] ); + $this->assertNotEmpty( $_POST['coauthors'] ); + $this->assertNotEmpty( check_admin_referer( 'coauthors-edit', 'coauthors-nonce' ) ); + } } From 3fb9b3398e11eeb5bf8a4dded7a0da4a0d71f7b6 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 21 Dec 2017 16:04:25 +0530 Subject: [PATCH 122/231] [#198] Replace .html() with .text() for simple string in js --- js/co-authors-plus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index c0ff38bb..55e9e582 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -243,7 +243,7 @@ jQuery( document ).ready(function () { function coauthors_create_author_tag( author ) { var $tag = jQuery( '' ) - .html( decodeURIComponent( author.name ) ) + .text( decodeURIComponent( author.name ) ) .attr( 'title', coAuthorsPlusStrings.input_box_title ) .addClass( 'coauthor-tag' ) // Add Click event to edit From 4037ea0178bed043443fac7f6eee48bbaf57e6b3 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 21 Dec 2017 19:41:09 +0530 Subject: [PATCH 123/231] [#279] Fix duplicate name display issue - When `coauthors_auto_apply_template_tags` is set to true, `coauthors_posts_links()` or `the_author_posts_link()` methods displays duplicate names if post has multiple authors. --- template-tags.php | 36 +++++++++--- tests/test-template-tags.php | 106 +++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 tests/test-template-tags.php diff --git a/template-tags.php b/template-tags.php index f3883b56..e548b1fb 100644 --- a/template-tags.php +++ b/template-tags.php @@ -236,12 +236,22 @@ function coauthors( $between = null, $betweenLast = null, $before = null, $after * @param bool $echo Whether the co-authors should be echoed or returned. Defaults to true. */ function coauthors_posts_links( $between = null, $betweenLast = null, $before = null, $after = null, $echo = true ) { - return coauthors__echo('coauthors_posts_links_single', 'callback', array( - 'between' => $between, + + global $coauthors_plus_template_filters; + + // Removing "the_author" filter so that it won't get called in loop and append names for each author. + remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + + $coauthors_posts_links = coauthors__echo( 'coauthors_posts_links_single', 'callback', array( + 'between' => $between, 'betweenLast' => $betweenLast, - 'before' => $before, - 'after' => $after, + 'before' => $before, + 'after' => $after, ), null, $echo ); + + add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + + return $coauthors_posts_links; } /** @@ -345,12 +355,22 @@ function coauthors_nicknames( $between = null, $betweenLast = null, $before = nu * @param bool $echo Whether the co-authors should be echoed or returned. Defaults to true. */ function coauthors_links( $between = null, $betweenLast = null, $before = null, $after = null, $echo = true ) { - return coauthors__echo( 'coauthors_links_single', 'callback', array( - 'between' => $between, + + global $coauthors_plus_template_filters; + + // Removing "the_author" filter so that it won't get called in loop and append names for each author. + remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + + $coauthors_links = coauthors__echo( 'coauthors_links_single', 'callback', array( + 'between' => $between, 'betweenLast' => $betweenLast, - 'before' => $before, - 'after' => $after, + 'before' => $before, + 'after' => $after, ), null, $echo ); + + add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + + return $coauthors_links; } /** diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php new file mode 100644 index 00000000..729d3da2 --- /dev/null +++ b/tests/test-template-tags.php @@ -0,0 +1,106 @@ +author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); + + $this->post_id = wp_insert_post( array( + 'post_author' => $this->author1, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'post', + ) ); + } + + /** + * Tests for co-authors display names, with links to their posts. + * + * @see : https://github.com/Automattic/Co-Authors-Plus/issues/279 + * + * @covers :: coauthors_posts_links() + */ + public function test_coauthors_posts_links() { + + global $coauthors_plus; + + $GLOBALS['post'] = get_post( $this->post_id ); + + // Checks for single post author. + $author1 = get_user_by( 'id', $this->author1 ); + $single_cpl = coauthors_posts_links( null, null, null, null, false ); + $expected_href = 'display_name . ''; + + $this->assertContains( $expected_href, $single_cpl ); + $this->assertContains( $expected_name, $single_cpl ); + + // Checks for multiple post author. + $editor1 = get_user_by( 'id', $this->editor1 ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $multiple_cpl = coauthors_posts_links( null, null, null, null, false ); + $expected_first_href = 'display_name . ' and '; + $expected_second_href = 'display_name . ''; + + $this->assertContains( $expected_first_href, $multiple_cpl ); + $this->assertContains( $expected_first_name, $multiple_cpl ); + $this->assertContains( $expected_second_href, $multiple_cpl ); + $this->assertContains( $expected_second_name, $multiple_cpl ); + + $multiple_cpl = coauthors_links( null, ' or ', null, null, false ); + $expected_first_name = '>' . $author1->display_name . ' or '; + + $this->assertContains( $expected_first_name, $multiple_cpl ); + + $this->assertEquals( 10, has_filter( 'the_author') ); + } + + /** + * Tests for co-authors display names. + * + * @see : https://github.com/Automattic/Co-Authors-Plus/issues/279 + * + * @covers :: coauthors_links() + */ + public function test_coauthors_links() { + + global $coauthors_plus; + + $GLOBALS['post'] = get_post( $this->post_id ); + + // Checks for single post author. + $author1 = get_user_by( 'id', $this->author1 ); + $single_cpl = coauthors_links( null, null, null, null, false ); + $expected_name = $author1->display_name; + + $this->assertEquals( $expected_name, $single_cpl ); + + // Checks for multiple post author. + $editor1 = get_user_by( 'id', $this->editor1 ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $multiple_cpl = coauthors_links( null, null, null, null, false ); + $expected_first_name = $author1->display_name; + $expected_second_name = $editor1->display_name; + + $this->assertContains( $expected_first_name, $multiple_cpl ); + $this->assertContains( ' and ', $multiple_cpl ); + $this->assertContains( $expected_second_name, $multiple_cpl ); + + $multiple_cpl = coauthors_links( null, ' or ', null, null, false ); + + $this->assertContains( ' or ', $multiple_cpl ); + + $this->assertEquals( 10, has_filter( 'the_author' ) ); + } +} From 8f4f7c3fd8256bb3610f9dec7ecd2fb267705b8c Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 22 Dec 2017 11:00:40 +0530 Subject: [PATCH 124/231] [#198] Improve unit testing for non-ASCII character issue --- tests/test-manage-coauthors.php | 234 +++++++++++++++++++++++++------- 1 file changed, 184 insertions(+), 50 deletions(-) diff --git a/tests/test-manage-coauthors.php b/tests/test-manage-coauthors.php index 0c5a0d33..66be8324 100644 --- a/tests/test-manage-coauthors.php +++ b/tests/test-manage-coauthors.php @@ -48,6 +48,10 @@ public function setUp() { ); $this->author1_page2 = wp_insert_post( $page ); + + $this->post_array = array( + 'ID' => $this->author1, + ); } public function tearDown() { @@ -148,11 +152,13 @@ public function test_post_publish_count_for_coauthor() { } /** - * When filtering post data before saving to db, post_author should be set appropriately + * Returns data as it is when post type is not allowed. * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_set_post_author_field() */ - public function test_wp_insert_post_data_set_post_author() { + public function test_coauthors_set_post_author_field_when_post_type_is_attachment() { global $coauthors_plus; @@ -161,92 +167,220 @@ public function test_wp_insert_post_data_set_post_author() { 'coauthors_set_post_author_field', ) ) ); - wp_set_current_user( $this->author1 ); + $post_id = $this->factory->post->create( array( + 'post_author' => $this->author1, + 'post_type' => 'attachment', + ) ); + + $post = get_post( $post_id ); + + $data = array( + 'post_type' => $post->post_type, + 'post_author' => $post->post_author, + ); + + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + + $this->assertEquals( $data, $new_data ); + } + + /** + * Compares data when coauthor is not set in the post array. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_set_post_author_field() + */ + public function test_coauthors_set_post_author_field_when_coauthor_is_not_set() { + + global $coauthors_plus; - $author1 = get_user_by( 'id', $this->author1 ); $author1_post1 = get_post( $this->author1_post1 ); - $data = array( + + $data = array( 'post_type' => $author1_post1->post_type, 'post_author' => $author1_post1->post_author, ); - // Check post type is enabled or not. - $this->assertTrue( $coauthors_plus->is_post_type_enabled( $data['post_type'] ) ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + + $this->assertEquals( $data, $new_data ); + } + + /** + * Compares data when coauthor is set in the post array. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_set_post_author_field() + */ + public function test_coauthors_set_post_author_field_when_coauthor_is_set() { + + global $coauthors_plus; + + $user_id = $this->factory->user->create( array( + 'user_login' => 'test_admin', + 'user_nicename' => 'test_admiи', + ) ); + + $user = get_user_by( 'id', $user_id ); + + $_REQUEST['coauthors-nonce'] = ''; + $_POST['coauthors'] = array( + $user->user_nicename, + ); + + $post_id = $this->factory->post->create( array( + 'post_author' => $user_id, + ) ); + + $post = get_post( $post_id ); + + $data = array( + 'post_type' => $post->post_type, + 'post_author' => $post->post_author, + ); + + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + + $this->assertEquals( $data, $new_data ); + } + + /** + * Compares data when coauthor is set and it is linked with main wp user. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_set_post_author_field() + */ + public function test_coauthors_set_post_author_field_when_guest_author_is_linked_with_wp_user() { + + global $coauthors_plus; + + $author1 = get_user_by( 'id', $this->author1 ); + + $author1_post1 = get_post( $this->author1_post1 ); - // Encoding user nicename if it has any special characters in it. - $author = urlencode( sanitize_text_field( $author1->user_nicename ) ); - $this->assertNotEmpty( $author ); + $data = array( + 'post_type' => $author1_post1->post_type, + 'post_author' => $author1_post1->post_author, + ); + + $_REQUEST['coauthors-nonce'] = ''; + $_POST['coauthors'] = array( + $author1->user_nicename, + ); // Create guest author with linked account with user. $coauthors_plus->guest_authors = new CoAuthors_Guest_Authors; - $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1 ); + $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); - $editor1_data = $coauthors_plus->get_coauthor_by( 'user_nicename', $editor1->user_nicename ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); - $this->assertEquals( 'guest-author', $editor1_data->type ); - $this->assertNotEmpty( $editor1_data->linked_account ); + $this->assertEquals( $data, $new_data ); + } + + /** + * Compares post author when it is not set in the main data array somehow. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_set_post_author_field() + */ + public function test_coauthors_set_post_author_field_when_post_author_is_not_set() { - // Main WP user. - $author_data = $coauthors_plus->get_coauthor_by( 'user_nicename', $author ); - $this->assertEquals( 'wpuser', $author_data->type ); + global $coauthors_plus; - // Checks if post_author is unset somehow and it is available from wp_get_current_user(). - unset( $data['post_author'] ); + wp_set_current_user( $this->author1 ); - $user = wp_get_current_user(); + $_REQUEST = $_POST = array(); + $data = array( 'post_type' => 'post' ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); - $this->assertNotEmpty( $user->ID ); - $this->assertGreaterThan( 0, $user->ID ); + $this->assertEquals( $this->author1, $new_data['post_author'] ); } /** - * Adding coauthors when saving post. + * Bypass coauthors_update_post() when post type is not allowed. * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_update_post() */ - public function test_save_post_to_update_post_coauthor() { + public function test_coauthors_update_post_when_post_type_is_attachment() { global $coauthors_plus; - $this->assertEquals( 10, has_filter( 'wp_insert_post_data', array( + $this->assertEquals( 10, has_action( 'save_post', array( $coauthors_plus, - 'coauthors_set_post_author_field' + 'coauthors_update_post', ) ) ); - $author1_post1 = get_post( $this->author1_post1 ); + $post_id = $this->factory->post->create( array( + 'post_author' => $this->author1, + 'post_type' => 'attachment', + ) ); - // Check post type is enabled or not. - $this->assertTrue( $coauthors_plus->is_post_type_enabled( $author1_post1->post_type ) ); + $post = get_post( $post_id ); + $return = $coauthors_plus->coauthors_update_post( $post_id, $post ); - // If post does not have author terms. - $post_id = $this->factory->post->create(); - $post = get_post( $post_id ); - $user = get_userdata( $post->post_author ); - - $this->assertFalse( $coauthors_plus->has_author_terms( $post_id ) ); - $this->assertFalse( $user ); + $this->assertNull( $return ); + } - // If current user is not allowed to set authors. - wp_set_current_user( $this->author1 ); + /** + * Checks coauthors when current user cal set authors. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_update_post() + */ + public function test_coauthors_update_post_when_current_user_can_set_authors() { - $this->assertFalse( $coauthors_plus->current_user_can_set_authors( $author1_post1 ) ); - $this->assertTrue( $coauthors_plus->has_author_terms( $this->author1_post1 ) ); + global $coauthors_plus; - // If current user is allowed to set authors. wp_set_current_user( $this->admin1 ); - $this->assertTrue( $coauthors_plus->current_user_can_set_authors( $author1_post1 ) ); + $admin1 = get_user_by( 'id', $this->admin1 ); + $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post_id = $this->factory->post->create( array( + 'post_author' => $this->admin1, + ) ); - $coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ), true ); + $post = get_post( $post_id ); + + $_POST['coauthors-nonce'] = $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' ); + $_POST['coauthors'] = array( + $admin1->user_nicename, + $author1->user_nicename, + ); + + $coauthors_plus->coauthors_update_post( $post_id, $post ); + + $coauthors = get_coauthors( $this->author1_post1 ); + + $this->assertEquals( array( $this->author1 ), wp_list_pluck( $coauthors, 'ID' ) ); + } + + /** + * Coauthors should be empty if post does not have any author terms + * and current user can not set authors for the post. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 + * + * @covers :: coauthors_update_post() + */ + public function test_coauthors_update_post_when_post_has_not_author_terms() { + + global $coauthors_plus; + + $post_id = $this->factory->post->create(); + $post = get_post( $post_id ); + + $coauthors_plus->coauthors_update_post( $post_id, $post ); - $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' ); - $_POST['coauthors'] = get_coauthors( $this->author1_post1 ); + $coauthors = get_coauthors( $post_id ); - $this->assertNotEmpty( $_REQUEST['coauthors-nonce'] ); - $this->assertNotEmpty( $_POST['coauthors'] ); - $this->assertNotEmpty( check_admin_referer( 'coauthors-edit', 'coauthors-nonce' ) ); + $this->assertEmpty( $coauthors ); } } From 8bf7a9a370dfa8c0295184e5cee944b706befbe0 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 22 Dec 2017 18:45:04 +0530 Subject: [PATCH 125/231] [#198] Improve phpunit test cases + cosmetic changes --- tests/test-manage-coauthors.php | 92 ++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/tests/test-manage-coauthors.php b/tests/test-manage-coauthors.php index 66be8324..13da59ca 100644 --- a/tests/test-manage-coauthors.php +++ b/tests/test-manage-coauthors.php @@ -48,10 +48,6 @@ public function setUp() { ); $this->author1_page2 = wp_insert_post( $page ); - - $this->post_array = array( - 'ID' => $this->author1, - ); } public function tearDown() { @@ -156,7 +152,7 @@ public function test_post_publish_count_for_coauthor() { * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_set_post_author_field() + * @covers ::coauthors_set_post_author_field() */ public function test_coauthors_set_post_author_field_when_post_type_is_attachment() { @@ -174,12 +170,13 @@ public function test_coauthors_set_post_author_field_when_post_type_is_attachmen $post = get_post( $post_id ); - $data = array( + $data = $post_array = array( + 'ID' => $post->ID, 'post_type' => $post->post_type, 'post_author' => $post->post_author, ); - $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array ); $this->assertEquals( $data, $new_data ); } @@ -189,7 +186,7 @@ public function test_coauthors_set_post_author_field_when_post_type_is_attachmen * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_set_post_author_field() + * @covers ::coauthors_set_post_author_field() */ public function test_coauthors_set_post_author_field_when_coauthor_is_not_set() { @@ -197,12 +194,13 @@ public function test_coauthors_set_post_author_field_when_coauthor_is_not_set() $author1_post1 = get_post( $this->author1_post1 ); - $data = array( + $data = $post_array = array( + 'ID' => $author1_post1->ID, 'post_type' => $author1_post1->post_type, 'post_author' => $author1_post1->post_author, ); - $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array ); $this->assertEquals( $data, $new_data ); } @@ -212,7 +210,7 @@ public function test_coauthors_set_post_author_field_when_coauthor_is_not_set() * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_set_post_author_field() + * @covers ::coauthors_set_post_author_field() */ public function test_coauthors_set_post_author_field_when_coauthor_is_set() { @@ -225,6 +223,10 @@ public function test_coauthors_set_post_author_field_when_coauthor_is_set() { $user = get_user_by( 'id', $user_id ); + // Backing up global variables. + $post_backup = $_POST; + $request_backup = $_REQUEST; + $_REQUEST['coauthors-nonce'] = ''; $_POST['coauthors'] = array( $user->user_nicename, @@ -236,14 +238,19 @@ public function test_coauthors_set_post_author_field_when_coauthor_is_set() { $post = get_post( $post_id ); - $data = array( + $data = $post_array = array( + 'ID' => $post->ID, 'post_type' => $post->post_type, 'post_author' => $post->post_author, ); - $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array ); $this->assertEquals( $data, $new_data ); + + // Store global variables from backup. + $_POST = $post_backup; + $_REQUEST = $request_backup; } /** @@ -251,7 +258,7 @@ public function test_coauthors_set_post_author_field_when_coauthor_is_set() { * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_set_post_author_field() + * @covers ::coauthors_set_post_author_field() */ public function test_coauthors_set_post_author_field_when_guest_author_is_linked_with_wp_user() { @@ -261,11 +268,16 @@ public function test_coauthors_set_post_author_field_when_guest_author_is_linked $author1_post1 = get_post( $this->author1_post1 ); - $data = array( + $data = $post_array = array( + 'ID' => $author1_post1->ID, 'post_type' => $author1_post1->post_type, 'post_author' => $author1_post1->post_author, ); + // Backing up global variables. + $post_backup = $_POST; + $request_backup = $_REQUEST; + $_REQUEST['coauthors-nonce'] = ''; $_POST['coauthors'] = array( $author1->user_nicename, @@ -275,9 +287,13 @@ public function test_coauthors_set_post_author_field_when_guest_author_is_linked $coauthors_plus->guest_authors = new CoAuthors_Guest_Authors; $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->author1 ); - $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array ); $this->assertEquals( $data, $new_data ); + + // Store global variables from backup. + $_POST = $post_backup; + $_REQUEST = $request_backup; } /** @@ -285,7 +301,7 @@ public function test_coauthors_set_post_author_field_when_guest_author_is_linked * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_set_post_author_field() + * @covers ::coauthors_set_post_author_field() */ public function test_coauthors_set_post_author_field_when_post_author_is_not_set() { @@ -293,11 +309,29 @@ public function test_coauthors_set_post_author_field_when_post_author_is_not_set wp_set_current_user( $this->author1 ); + // Backing up global variables. + $post_backup = $_POST; + $request_backup = $_REQUEST; + $_REQUEST = $_POST = array(); - $data = array( 'post_type' => 'post' ); - $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $this->post_array ); + + $author1_post1 = get_post( $this->author1_post1 ); + + $data = $post_array = array( + 'ID' => $author1_post1->ID, + 'post_type' => $author1_post1->post_type, + 'post_author' => $author1_post1->post_author, + ); + + unset( $data['post_author'] ); + + $new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array ); $this->assertEquals( $this->author1, $new_data['post_author'] ); + + // Store global variables from backup. + $_POST = $post_backup; + $_REQUEST = $request_backup; } /** @@ -305,7 +339,7 @@ public function test_coauthors_set_post_author_field_when_post_author_is_not_set * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_update_post() + * @covers ::coauthors_update_post() */ public function test_coauthors_update_post_when_post_type_is_attachment() { @@ -328,11 +362,11 @@ public function test_coauthors_update_post_when_post_type_is_attachment() { } /** - * Checks coauthors when current user cal set authors. + * Checks coauthors when current user can set authors. * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_update_post() + * @covers ::coauthors_update_post() */ public function test_coauthors_update_post_when_current_user_can_set_authors() { @@ -349,6 +383,10 @@ public function test_coauthors_update_post_when_current_user_can_set_authors() { $post = get_post( $post_id ); + // Backing up global variables. + $post_backup = $_POST; + $request_backup = $_REQUEST; + $_POST['coauthors-nonce'] = $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' ); $_POST['coauthors'] = array( $admin1->user_nicename, @@ -357,9 +395,13 @@ public function test_coauthors_update_post_when_current_user_can_set_authors() { $coauthors_plus->coauthors_update_post( $post_id, $post ); - $coauthors = get_coauthors( $this->author1_post1 ); + $coauthors = get_coauthors( $post_id ); + + $this->assertEquals( array( $this->admin1, $this->author1 ), wp_list_pluck( $coauthors, 'ID' ) ); - $this->assertEquals( array( $this->author1 ), wp_list_pluck( $coauthors, 'ID' ) ); + // Store global variables from backup. + $_POST = $post_backup; + $_REQUEST = $request_backup; } /** @@ -368,7 +410,7 @@ public function test_coauthors_update_post_when_current_user_can_set_authors() { * * @see https://github.com/Automattic/Co-Authors-Plus/issues/198 * - * @covers :: coauthors_update_post() + * @covers ::coauthors_update_post() */ public function test_coauthors_update_post_when_post_has_not_author_terms() { From cc36104a5bbab64048d60c0f8b2fdf174d15f183 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 22 Dec 2017 18:47:56 +0530 Subject: [PATCH 126/231] [#198] Assign values to variables instead of keeping empty for test cases --- tests/test-manage-coauthors.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-manage-coauthors.php b/tests/test-manage-coauthors.php index 13da59ca..0bc9954c 100644 --- a/tests/test-manage-coauthors.php +++ b/tests/test-manage-coauthors.php @@ -227,7 +227,7 @@ public function test_coauthors_set_post_author_field_when_coauthor_is_set() { $post_backup = $_POST; $request_backup = $_REQUEST; - $_REQUEST['coauthors-nonce'] = ''; + $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' );; $_POST['coauthors'] = array( $user->user_nicename, ); @@ -278,7 +278,7 @@ public function test_coauthors_set_post_author_field_when_guest_author_is_linked $post_backup = $_POST; $request_backup = $_REQUEST; - $_REQUEST['coauthors-nonce'] = ''; + $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' );; $_POST['coauthors'] = array( $author1->user_nicename, ); From 08b7b6682f49435065750ce048b777b8fecd91ed Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 11:37:23 +0530 Subject: [PATCH 127/231] [#184] Started unit tests for template tags - Added unit tests for get_coauthors() & is_coauthor_for_post() --- tests/test-template-tags.php | 193 +++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 tests/test-template-tags.php diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php new file mode 100644 index 00000000..75b1b866 --- /dev/null +++ b/tests/test-template-tags.php @@ -0,0 +1,193 @@ +author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); + + $this->post_id = wp_insert_post( array( + 'post_author' => $this->author1, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'post', + ) ); + } + + /** + * Checks coauthors when post not exist. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::get_coauthors() + */ + public function test_get_coauthors_when_post_not_exists() { + + $this->assertEmpty( get_coauthors() ); + } + + /** + * Checks coauthors when post exist (not global). + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::get_coauthors() + */ + public function test_get_coauthors_when_post_exists() { + + global $coauthors_plus; + + // Compare single author. + $coauthors = get_coauthors( $this->post_id ); + $this->assertEquals( array( $this->author1 ), wp_list_pluck( $coauthors, 'ID' ) ); + + // Compare multiple authors. + $editor1 = get_user_by( 'id', $this->editor1 ); + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $coauthors = get_coauthors( $this->post_id ); + $this->assertEquals( array( $this->author1, $this->editor1 ), wp_list_pluck( $coauthors, 'ID' ) ); + } + + /** + * Checks coauthors when terms for post not exist. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::get_coauthors() + */ + public function test_get_coauthors_when_terms_for_post_not_exists() { + + $post_id = $this->factory->post->create(); + $this->assertEmpty( get_coauthors( $post_id ) ); + } + + /** + * Checks coauthors when post not exist. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::get_coauthors() + */ + public function test_get_coauthors_when_global_post_exists() { + + global $post; + + // Backing up global post. + $post_backup = $post; + + $post_id = $this->factory->post->create(); + $post = get_post( $post_id ); + + $this->assertEmpty( get_coauthors( $post_id ) ); + + $user_id = $this->factory->user->create(); + $post_id = $this->factory->post->create( array( + 'post_author' => $user_id, + ) ); + $post = get_post( $post_id ); + $coauthors = get_coauthors( $post_id ); + + $this->assertEquals( array( $user_id ), wp_list_pluck( $coauthors, 'ID' ) ); + + // Restore global post from backup. + $post = $post_backup; + } + + /** + * Checks whether user is a coauthor of the post when user or post not exists. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::is_coauthor_for_post() + */ + public function test_is_coauthor_for_post_when_user_or_post_not_exists() { + + global $post; + + // Backing up global post. + $post_backup = $post; + + $this->assertFalse( is_coauthor_for_post( '' ) ); + $this->assertFalse( is_coauthor_for_post( '', $this->post_id ) ); + $this->assertFalse( is_coauthor_for_post( $this->author1 ) ); + + $post = get_post( $this->post_id ); + + $this->assertFalse( is_coauthor_for_post( '' ) ); + + // Restore global post from backup. + $post = $post_backup; + } + + /** + * Checks whether user is a coauthor of the post when user is not expected as ID, + * or user_login is not set in user object. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::is_coauthor_for_post() + */ + public function test_is_coauthor_for_post_when_user_not_numeric_or_user_login_not_set() { + + $this->assertFalse( is_coauthor_for_post( 'test' ) ); + } + + /** + * Checks whether user is a coauthor of the post when user is set in either way, + * as user_id or user object but he/she is not coauthor of the post. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::is_coauthor_for_post() + */ + public function test_is_coauthor_for_post_when_user_numeric_or_user_login_set_but_no_coauthor() { + + $this->assertFalse( is_coauthor_for_post( $this->editor1, $this->post_id ) ); + + $editor1 = get_user_by( 'id', $this->editor1 ); + + $this->assertFalse( is_coauthor_for_post( $editor1, $this->post_id ) ); + } + + /** + * Checks whether user is a coauthor of the post. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::is_coauthor_for_post() + */ + public function test_is_coauthor_for_post_when_user_is_coauthor() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $this->assertTrue( is_coauthor_for_post( $this->author1, $this->post_id ) ); + $this->assertTrue( is_coauthor_for_post( $author1, $this->post_id ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $this->assertTrue( is_coauthor_for_post( $this->editor1, $this->post_id ) ); + $this->assertTrue( is_coauthor_for_post( $editor1, $this->post_id ) ); + + $post = get_post( $this->post_id ); + + $this->assertTrue( is_coauthor_for_post( $this->author1 ) ); + $this->assertTrue( is_coauthor_for_post( $author1 ) ); + + $this->assertTrue( is_coauthor_for_post( $this->editor1 ) ); + $this->assertTrue( is_coauthor_for_post( $editor1 ) ); + + // Restore global post from backup. + $post = $post_backup; + } +} From 18ece5b116b1aa21e4d4b50e92aadc6747f0c62b Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 13:02:48 +0530 Subject: [PATCH 128/231] [#184] Unit tests for coauthors() for template tags --- tests/test-template-tags.php | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 75b1b866..ce78f02a 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -190,4 +190,42 @@ public function test_is_coauthor_for_post_when_user_is_coauthor() { // Restore global post from backup. $post = $post_backup; } + + /** + * Tests for co-authors display names, without links to their posts. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors() + **/ + public function test_coauthors() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $post = get_post( $this->post_id ); + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + // Checks for single post author. + $coauthors = coauthors( null, null, null, null, false ); + + $this->assertEquals( $author1->display_name, $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); + $this->assertEquals( 0, substr_count( $coauthors, $editor1->display_name ) ); + + // Checks for multiple post author. + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $coauthors = coauthors( null, null, null, null, false ); + + $this->assertEquals( $author1->display_name . ' and ' . $editor1->display_name, $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); + $this->assertEquals( 1, substr_count( $coauthors, $editor1->display_name ) ); + + // Restore global post from backup. + $post = $post_backup; + } } From 892cd226e686da8170b372b8c7ba6363906adc75 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 14:35:14 +0530 Subject: [PATCH 129/231] [#184] Unit tests for coauthors_posts_links_single() for template tags --- tests/test-template-tags.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index ce78f02a..1fa776a5 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -228,4 +228,24 @@ public function test_coauthors() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks single co-author linked to their post archive. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_posts_links_single() + */ + public function test_coauthors_posts_links_single() { + + $author1 = get_user_by( 'id', $this->author1 ); + $author_link = coauthors_posts_links_single( $author1 ); + + $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $author_link, 'Author link not found.' ); + $this->assertContains( $author1->display_name, $author_link, 'Author name not found.' ); + + // Here we are checking author name should not be more then one time. + // Asserting ">{$author1->display_name}<" because "$author1->display_name" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $author_link, ">{$author1->display_name}<" ) ); + } } From 7fa2a4be3ef2e47d95faf3d456a08f9f07e2b5d4 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 15:12:11 +0530 Subject: [PATCH 130/231] [#184] Unit tests for coauthors_firstnames() for template tags --- tests/test-template-tags.php | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 1fa776a5..96f3391f 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -248,4 +248,46 @@ public function test_coauthors_posts_links_single() { // Asserting ">{$author1->display_name}<" because "$author1->display_name" can be multiple times like in href, title, etc. $this->assertEquals( 1, substr_count( $author_link, ">{$author1->display_name}<" ) ); } + + public function test_coauthors_firstnames() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $post = get_post( $this->post_id ); + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $first_names = coauthors_firstnames( null, null, null, null, false ); + + $this->assertEquals( $author1->user_login, $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $first_names = coauthors_firstnames( null, null, null, null, false ); + + $this->assertEquals( $author1->user_login . ' and ' . $editor1->user_login, $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + $this->assertEquals( 1, substr_count( $first_names, $editor1->user_login ) ); + + $first_name = 'Test'; + $user_id = $this->factory->user->create( array( + 'first_name' => $first_name, + ) ); + $post_id = $this->factory->post->create( array( + 'post_author' => $user_id, + ) ); + $post = get_post( $post_id ); + + $first_names = coauthors_firstnames( null, null, null, null, false ); + + $this->assertEquals( $first_name, $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $first_name ) ); + + // Restore global post from backup. + $post = $post_backup; + } } From 79e9fc10b2dc7883d00197ce8d6c22bfdb7fc1f7 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 15:19:01 +0530 Subject: [PATCH 131/231] [#184] Method description for coauthors_firstnames() for template tags --- tests/test-template-tags.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 96f3391f..0b08a457 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -249,6 +249,13 @@ public function test_coauthors_posts_links_single() { $this->assertEquals( 1, substr_count( $author_link, ">{$author1->display_name}<" ) ); } + /** + * Checks co-authors first names, without links to their posts. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_firstnames() + */ public function test_coauthors_firstnames() { global $post, $coauthors_plus; From cde4e0b518ec2ee535b4a1685d9ecf372d7e6058 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 15:24:44 +0530 Subject: [PATCH 132/231] [#184] Unit tests for coauthors_lastnames() for template tags --- tests/test-template-tags.php | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 0b08a457..b0a60e44 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -297,4 +297,53 @@ public function test_coauthors_firstnames() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks co-authors last names, without links to their posts. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_lastnames() + */ + public function test_coauthors_lastnames() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $post = get_post( $this->post_id ); + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $last_names = coauthors_lastnames( null, null, null, null, false ); + + $this->assertEquals( $author1->user_login, $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $last_names = coauthors_lastnames( null, null, null, null, false ); + + $this->assertEquals( $author1->user_login . ' and ' . $editor1->user_login, $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + $this->assertEquals( 1, substr_count( $last_names, $editor1->user_login ) ); + + $last_name = 'Test'; + $user_id = $this->factory->user->create( array( + 'last_name' => $last_name, + ) ); + $post_id = $this->factory->post->create( array( + 'post_author' => $user_id, + ) ); + $post = get_post( $post_id ); + + $last_names = coauthors_lastnames( null, null, null, null, false ); + + $this->assertEquals( $last_name, $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $last_name ) ); + + // Restore global post from backup. + $post = $post_backup; + } } From 238f08213f3a7819f9814dc76250ceb224bf0e8a Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 16:00:28 +0530 Subject: [PATCH 133/231] [#184] Unit tests for coauthors_nicknames() for template tags --- tests/test-template-tags.php | 94 +++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index b0a60e44..7b19efb1 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -214,7 +214,11 @@ public function test_coauthors() { $this->assertEquals( $author1->display_name, $coauthors ); $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); - $this->assertEquals( 0, substr_count( $coauthors, $editor1->display_name ) ); + + $coauthors = coauthors( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->display_name . '', $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); // Checks for multiple post author. $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); @@ -225,6 +229,12 @@ public function test_coauthors() { $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); $this->assertEquals( 1, substr_count( $coauthors, $editor1->display_name ) ); + $coauthors = coauthors( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->display_name . '' . $editor1->display_name . '', $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); + $this->assertEquals( 1, substr_count( $coauthors, $editor1->display_name ) ); + // Restore global post from backup. $post = $post_backup; } @@ -272,6 +282,11 @@ public function test_coauthors_firstnames() { $this->assertEquals( $author1->user_login, $first_names ); $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + $first_names = coauthors_firstnames( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_login . '', $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); $first_names = coauthors_firstnames( null, null, null, null, false ); @@ -280,6 +295,12 @@ public function test_coauthors_firstnames() { $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); $this->assertEquals( 1, substr_count( $first_names, $editor1->user_login ) ); + $first_names = coauthors_firstnames( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_login . '' . $editor1->user_login . '', $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + $this->assertEquals( 1, substr_count( $first_names, $editor1->user_login ) ); + $first_name = 'Test'; $user_id = $this->factory->user->create( array( 'first_name' => $first_name, @@ -321,6 +342,11 @@ public function test_coauthors_lastnames() { $this->assertEquals( $author1->user_login, $last_names ); $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + $last_names = coauthors_lastnames( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_login . '', $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); $last_names = coauthors_lastnames( null, null, null, null, false ); @@ -329,6 +355,12 @@ public function test_coauthors_lastnames() { $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); $this->assertEquals( 1, substr_count( $last_names, $editor1->user_login ) ); + $last_names = coauthors_lastnames( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_login . '' . $editor1->user_login . '', $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + $this->assertEquals( 1, substr_count( $last_names, $editor1->user_login ) ); + $last_name = 'Test'; $user_id = $this->factory->user->create( array( 'last_name' => $last_name, @@ -346,4 +378,64 @@ public function test_coauthors_lastnames() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks co-authors nicknames, without links to their posts. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_nicknames() + */ + public function test_coauthors_nicknames() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $post = get_post( $this->post_id ); + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $nick_names = coauthors_nicknames( null, null, null, null, false ); + + $this->assertEquals( $author1->user_login, $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); + + $nick_names = coauthors_nicknames( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_login . '', $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $nick_names = coauthors_nicknames( null, null, null, null, false ); + + $this->assertEquals( $author1->user_login . ' and ' . $editor1->user_login, $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); + $this->assertEquals( 1, substr_count( $nick_names, $editor1->user_login ) ); + + $nick_names = coauthors_nicknames( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_login . '' . $editor1->user_login . '', $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); + $this->assertEquals( 1, substr_count( $nick_names, $editor1->user_login ) ); + + $nick_name = 'Test'; + $user_id = $this->factory->user->create( array( + 'nickname' => $nick_name, + ) ); + $post_id = $this->factory->post->create( array( + 'post_author' => $user_id, + ) ); + $post = get_post( $post_id ); + + $nick_names = coauthors_nicknames( null, null, null, null, false ); + + $this->assertEquals( $nick_name, $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $nick_name ) ); + + // Restore global post from backup. + $post = $post_backup; + } } From 25679f8f248854abb43fcb2e206ff17907524a6f Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 16:21:39 +0530 Subject: [PATCH 134/231] [#184] Unit tests for coauthors_emails() for template tags --- tests/test-template-tags.php | 66 ++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 7b19efb1..41e8ef7b 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -362,13 +362,13 @@ public function test_coauthors_lastnames() { $this->assertEquals( 1, substr_count( $last_names, $editor1->user_login ) ); $last_name = 'Test'; - $user_id = $this->factory->user->create( array( + $user_id = $this->factory->user->create( array( 'last_name' => $last_name, ) ); - $post_id = $this->factory->post->create( array( + $post_id = $this->factory->post->create( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); + $post = get_post( $post_id ); $last_names = coauthors_lastnames( null, null, null, null, false ); @@ -438,4 +438,64 @@ public function test_coauthors_nicknames() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks co-authors email addresses. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_emails() + */ + public function test_coauthors_emails() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $post = get_post( $this->post_id ); + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $emails = coauthors_emails( null, null, null, null, false ); + + $this->assertEquals( $author1->user_email, $emails ); + $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); + + $emails = coauthors_emails( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_email . '', $emails ); + $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $emails = coauthors_emails( null, null, null, null, false ); + + $this->assertEquals( $author1->user_email . ' and ' . $editor1->user_email, $emails ); + $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); + $this->assertEquals( 1, substr_count( $emails, $editor1->user_email ) ); + + $emails = coauthors_emails( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->user_email . '' . $editor1->user_email . '', $emails ); + $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); + $this->assertEquals( 1, substr_count( $emails, $editor1->user_email ) ); + + $email = 'test@example.org'; + $user_id = $this->factory->user->create( array( + 'user_email' => $email, + ) ); + $post_id = $this->factory->post->create( array( + 'post_author' => $user_id, + ) ); + $post = get_post( $post_id ); + + $emails = coauthors_emails( null, null, null, null, false ); + + $this->assertEquals( $email, $emails ); + $this->assertEquals( 1, substr_count( $emails, $email ) ); + + // Restore global post from backup. + $post = $post_backup; + } } From 991a65b8ac3fe40ca65fa6b67abf4f30fedd0365 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 17:57:44 +0530 Subject: [PATCH 135/231] [#184] Unit tests for coauthors_links_single() for template tags --- tests/test-template-tags.php | 101 +++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 41e8ef7b..de89829d 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -498,4 +498,105 @@ public function test_coauthors_emails() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks single co-author if he/she is a guest author. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_links_single() + */ + public function test_coauthors_links_single_when_guest_author() { + + global $authordata; + + // Backing up global author data. + $authordata_backup = $authordata; + + $author1 = get_user_by( 'id', $this->author1 ); + $author1->type = 'guest-author'; + $author_link = coauthors_links_single( $author1 ); + + $this->assertNull( $author_link ); + + update_user_meta( $this->author1, 'website', 'example.org' ); + + $author_link = coauthors_links_single( $author1 ); + + $this->assertNull( $author_link ); + + $authordata = $author1; + $author_link = coauthors_links_single( $author1 ); + + $this->assertContains( get_the_author_meta( 'website' ), $author_link, 'Author link not found.' ); + $this->assertContains( get_the_author(), $author_link, 'Author name not found.' ); + + // Here we are checking author name should not be more then one time. + // Asserting ">get_the_author()<" because "get_the_author()" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $author_link, '>' . get_the_author() . '<' ) ); + + // Restore global author data from backup. + $authordata = $authordata_backup; + } + + /** + * Checks single co-author when user's url is set and not a guest author. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_links_single() + */ + public function test_coauthors_links_single_author_url_is_set() { + + global $authordata; + + // Backing up global author data. + $authordata_backup = $authordata; + + $user_id = $this->factory->user->create( array( + 'user_url' => 'example.org', + ) ); + $user = get_user_by( 'id', $user_id ); + + $authordata = $user; + $author_link = coauthors_links_single( $user ); + + $this->assertContains( get_the_author_meta( 'url' ), $author_link, 'Author link not found.' ); + $this->assertContains( get_the_author(), $author_link, 'Author name not found.' ); + + // Here we are checking author name should not be more then one time. + // Asserting ">get_the_author()<" because "get_the_author()" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $author_link, '>' . get_the_author() . '<' ) ); + + // Restore global author data from backup. + $authordata = $authordata_backup; + } + + /** + * Checks single co-author when user's website/url not exist. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_links_single() + */ + public function test_coauthors_links_single_when_url_not_exist() { + + global $authordata; + + // Backing up global author data. + $authordata_backup = $authordata; + + $author1 = get_user_by( 'id', $this->author1 ); + $author_link = coauthors_links_single( $author1 ); + + $this->assertEmpty( $author_link ); + + $authordata = $author1; + $author_link = coauthors_links_single( $author1 ); + + $this->assertEquals( get_the_author(), $author_link ); + + // Restore global author data from backup. + $authordata = $authordata_backup; + } } From f42aa5a59ad10cdb6b718aa76e01b4033389cd91 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 18:09:14 +0530 Subject: [PATCH 136/231] [#184] Unit tests for coauthors_ids() for template tags --- tests/test-template-tags.php | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index de89829d..58328950 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -599,4 +599,50 @@ public function test_coauthors_links_single_when_url_not_exist() { // Restore global author data from backup. $authordata = $authordata_backup; } + + /** + * Checks co-authors IDs. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_ids() + */ + public function test_coauthors_ids() { + + global $post, $coauthors_plus; + + // Backing up global post. + $post_backup = $post; + + $post = get_post( $this->post_id ); + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $ids = coauthors_ids( null, null, null, null, false ); + + $this->assertEquals( $author1->ID, $ids ); + $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); + + $ids = coauthors_ids( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->ID . '', $ids ); + $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $ids = coauthors_ids( null, null, null, null, false ); + + $this->assertEquals( $author1->ID . ' and ' . $editor1->ID, $ids ); + $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); + $this->assertEquals( 1, substr_count( $ids, $editor1->ID ) ); + + $ids = coauthors_ids( '', '', '', '', false ); + + $this->assertEquals( '' . $author1->ID . '' . $editor1->ID . '', $ids ); + $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); + $this->assertEquals( 1, substr_count( $ids, $editor1->ID ) ); + + // Restore global post from backup. + $post = $post_backup; + } } From d1283ec81757cded7883a29fd8aca56c145c4bba Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 26 Dec 2017 18:22:12 +0530 Subject: [PATCH 137/231] [#184] Unit tests for get_the_coauthor_meta() for template tags --- tests/test-template-tags.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 58328950..7f57b6f2 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -645,4 +645,33 @@ public function test_coauthors_ids() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks co-authors meta. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::get_the_coauthor_meta() + */ + public function test_get_the_coauthor_meta() { + + global $post; + + // Backing up global post. + $post_backup = $post; + + $this->assertEmpty( get_the_coauthor_meta( '' ) ); + + update_user_meta( $this->author1, 'test_meta', 'test_meta' ); + + $this->assertEmpty( get_the_coauthor_meta( 'test_meta' ) ); + + $post = get_post( $this->post_id ); + $meta = get_the_coauthor_meta( 'test_meta' ); + + $this->assertEquals( 'test_meta', $meta[ $this->author1 ] ); + + // Restore global post from backup. + $post = $post_backup; + } } From ae0071fde2f36773cd34825ce2b6f7af6419673b Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 11:53:18 +0530 Subject: [PATCH 138/231] [#184] Unit tests for coauthors_wp_list_authors() for template tags --- tests/test-template-tags.php | 278 ++++++++++++++++++++++++++++++++--- 1 file changed, 259 insertions(+), 19 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 7f57b6f2..bb698a83 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -42,15 +42,12 @@ public function test_get_coauthors_when_post_exists() { global $coauthors_plus; // Compare single author. - $coauthors = get_coauthors( $this->post_id ); - $this->assertEquals( array( $this->author1 ), wp_list_pluck( $coauthors, 'ID' ) ); + $this->assertEquals( array( $this->author1 ), wp_list_pluck( get_coauthors( $this->post_id ), 'ID' ) ); // Compare multiple authors. $editor1 = get_user_by( 'id', $this->editor1 ); $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); - - $coauthors = get_coauthors( $this->post_id ); - $this->assertEquals( array( $this->author1, $this->editor1 ), wp_list_pluck( $coauthors, 'ID' ) ); + $this->assertEquals( array( $this->author1, $this->editor1 ), wp_list_pluck( get_coauthors( $this->post_id ), 'ID' ) ); } /** @@ -85,14 +82,13 @@ public function test_get_coauthors_when_global_post_exists() { $this->assertEmpty( get_coauthors( $post_id ) ); - $user_id = $this->factory->user->create(); - $post_id = $this->factory->post->create( array( + $user_id = $this->factory->user->create(); + $post_id = $this->factory->post->create( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); - $coauthors = get_coauthors( $post_id ); + $post = get_post( $post_id ); - $this->assertEquals( array( $user_id ), wp_list_pluck( $coauthors, 'ID' ) ); + $this->assertEquals( array( $user_id ), wp_list_pluck( get_coauthors( $post_id ), 'ID' ) ); // Restore global post from backup. $post = $post_backup; @@ -148,10 +144,7 @@ public function test_is_coauthor_for_post_when_user_not_numeric_or_user_login_no public function test_is_coauthor_for_post_when_user_numeric_or_user_login_set_but_no_coauthor() { $this->assertFalse( is_coauthor_for_post( $this->editor1, $this->post_id ) ); - - $editor1 = get_user_by( 'id', $this->editor1 ); - - $this->assertFalse( is_coauthor_for_post( $editor1, $this->post_id ) ); + $this->assertFalse( is_coauthor_for_post( get_user_by( 'id', $this->editor1 ), $this->post_id ) ); } /** @@ -515,15 +508,12 @@ public function test_coauthors_links_single_when_guest_author() { $author1 = get_user_by( 'id', $this->author1 ); $author1->type = 'guest-author'; - $author_link = coauthors_links_single( $author1 ); - $this->assertNull( $author_link ); + $this->assertNull( coauthors_links_single( $author1 ) ); update_user_meta( $this->author1, 'website', 'example.org' ); - $author_link = coauthors_links_single( $author1 ); - - $this->assertNull( $author_link ); + $this->assertNull( coauthors_links_single( $author1 ) ); $authordata = $author1; $author_link = coauthors_links_single( $author1 ); @@ -674,4 +664,254 @@ public function test_get_the_coauthor_meta() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks all the co-authors of the blog with default args. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_default_args() { + + global $coauthors_plus; + + $args = array( + 'echo' => false, + ); + + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + $coauthors = coauthors_wp_list_authors( $args ); + + $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $coauthors, 'Author link not found.' ); + $this->assertContains( $author1->display_name, $coauthors, 'Author name not found.' ); + + $coauthors = coauthors_wp_list_authors( $args ); + + $this->assertNotContains( 'href="' . get_author_posts_url( $editor1->ID, $editor1->user_nicename ) . '"', $coauthors ); + $this->assertNotContains( $editor1->display_name, $coauthors ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $coauthors = coauthors_wp_list_authors( $args ); + + $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $coauthors, 'Main author link not found.' ); + $this->assertContains( $author1->display_name, $coauthors, 'Main author name not found.' ); + + // Here we are checking author name should not be more then one time. + // Asserting ">{$author1->display_name}<" because "$author1->display_name" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $coauthors, ">{$author1->display_name}<" ) ); + + $this->assertContains( '
  • ', $coauthors, 'Coauthors name separator is not matched.' ); + $this->assertContains( 'href="' . get_author_posts_url( $editor1->ID, $editor1->user_nicename ) . '"', $coauthors, 'Coauthor link not found.' ); + $this->assertContains( $editor1->display_name, $coauthors, 'Coauthor name not found.' ); + + // Here we are checking editor name should not be more then one time. + // Asserting ">{$editor1->display_name}<" because "$editor1->display_name" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $coauthors, ">{$editor1->display_name}<" ) ); + } + + /** + * Checks all the co-authors of the blog with optioncount option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_optioncount() { + + $this->assertContains( '(' . count_user_posts( $this->author1 ) . ')', coauthors_wp_list_authors( array( + 'echo' => false, + 'optioncount' => true, + ) ) ); + } + + /** + * Checks all the co-authors of the blog with show_fullname option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_show_fullname() { + + $args = array( + 'echo' => false, + 'show_fullname' => true, + ); + + $author1 = get_user_by( 'id', $this->author1 ); + + $this->assertContains( $author1->display_name, coauthors_wp_list_authors( $args ) ); + + $user = $this->factory->user->create_and_get( array( + 'first_name' => 'First', + 'last_name' => 'Last', + ) ); + + $this->factory->post->create( array( + 'post_author' => $user->ID, + ) ); + + $this->assertContains( "{$user->user_firstname} {$user->user_lastname}", coauthors_wp_list_authors( $args ) ); + } + + /** + * Checks all the co-authors of the blog with hide_empty option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_hide_empty() { + + global $coauthors_plus; + + $coauthors_plus->guest_authors->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + + $this->assertContains( 'author2', coauthors_wp_list_authors( array( + 'echo' => false, + 'hide_empty' => false, + ) ) ); + } + + /** + * Checks all the co-authors of the blog with feed option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_feed() { + + $feed_text = 'link to feed'; + $coauthors = coauthors_wp_list_authors( array( + 'echo' => false, + 'feed' => $feed_text, + ) ); + + $this->assertContains( get_author_feed_link( $this->author1 ), $coauthors ); + $this->assertContains( $feed_text, $coauthors ); + } + + /** + * Checks all the co-authors of the blog with feed_image option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_feed_image() { + + $feed_image = WP_TESTS_DOMAIN . '/path/to/a/graphic.png'; + $coauthors = coauthors_wp_list_authors( array( + 'echo' => false, + 'feed_image' => $feed_image, + ) ); + + $this->assertContains( get_author_feed_link( $this->author1 ), $coauthors ); + $this->assertContains( $feed_image, $coauthors ); + } + + /** + * Checks all the co-authors of the blog with feed_type option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_feed_type() { + + $feed_type = 'atom'; + $feed_text = 'link to feed'; + $coauthors = coauthors_wp_list_authors( array( + 'echo' => false, + 'feed_type' => $feed_type, + 'feed' => $feed_text, + ) ); + + $this->assertContains( get_author_feed_link( $this->author1, $feed_type ), $coauthors ); + $this->assertContains( $feed_type, $coauthors ); + $this->assertContains( $feed_text, $coauthors ); + } + + /** + * Checks all the co-authors of the blog with style option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_style() { + + $coauthors = coauthors_wp_list_authors( array( + 'echo' => false, + 'style' => 'none', + ) ); + + $this->assertNotContains( '
  • ', $coauthors ); + $this->assertNotContains( '
  • ', $coauthors ); + } + + /** + * Checks all the co-authors of the blog with html option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_html() { + + global $coauthors_plus; + + $args = array( + 'echo' => false, + 'html' => false, + ); + + $author1 = get_user_by( 'id', $this->author1 ); + $editor1 = get_user_by( 'id', $this->editor1 ); + + $this->assertEquals( $author1->display_name, coauthors_wp_list_authors( $args ) ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + + $this->assertEquals( "$author1->display_name, $editor1->display_name", coauthors_wp_list_authors( $args ) ); + } + + /** + * Checks all the co-authors of the blog with guest_authors_only option. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_wp_list_authors() + */ + public function test_coauthors_wp_list_authors_for_guest_authors_only() { + + global $coauthors_plus; + + $args = array( + 'echo' => false, + 'guest_authors_only' => true, + ); + + $this->assertEmpty( coauthors_wp_list_authors( $args ) ); + + $guest_author_id = $coauthors_plus->guest_authors->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + + $this->assertEmpty( coauthors_wp_list_authors( $args ) ); + + $guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id ); + + $coauthors_plus->add_coauthors( $this->post_id, array( $guest_author->user_login ), true ); + + $this->assertEquals( $guest_author->display_name, coauthors_wp_list_authors( $args ) ); + } } From 83412ce0d520ba5b4e7e1d5b0a5927c08f14583a Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 12:56:13 +0530 Subject: [PATCH 139/231] [#184] Unit tests for coauthors_get_avatar() for template tags --- tests/test-template-tags.php | 108 ++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index bb698a83..13121816 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -912,6 +912,112 @@ public function test_coauthors_wp_list_authors_for_guest_authors_only() { $coauthors_plus->add_coauthors( $this->post_id, array( $guest_author->user_login ), true ); - $this->assertEquals( $guest_author->display_name, coauthors_wp_list_authors( $args ) ); + $this->assertContains( $guest_author->display_name, coauthors_wp_list_authors( $args ) ); + } + + /** + * Checks co-author's avatar. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_get_avatar() + */ + public function test_coauthors_get_avatar_default() { + + $this->assertEmpty( coauthors_get_avatar( $this->author1 ) ); + + $author1 = get_user_by( 'id', $this->author1 ); + + $this->assertEquals( preg_match( "|^[^$|", coauthors_get_avatar( $author1 ) ), 1 ); + } + + /** + * Checks co-author's avatar when author is a guest author. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_get_avatar() + */ + public function test_coauthors_get_avatar_when_guest_author() { + + global $coauthors_plus; + + $guest_author_id = $coauthors_plus->guest_authors->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + + $guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id ); + + $this->assertEquals( preg_match( "|^[^$|", coauthors_get_avatar( $guest_author ) ), 1 ); + + $filename = rand_str() . '.jpg'; + $contents = rand_str(); + $upload = wp_upload_bits( $filename, null, $contents ); + + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + set_post_thumbnail( $guest_author->ID, $attachment_id ); + + $avatar = coauthors_get_avatar( $guest_author ); + $attachment_url = wp_get_attachment_url( $attachment_id ); + + $this->assertContains( $filename, $avatar ); + $this->assertContains( 'src="' . $attachment_url . '"', $avatar ); + } + + /** + * Checks co-author's avatar when user's email is not set somehow. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_get_avatar() + */ + public function test_coauthors_get_avatar_when_user_email_not_set() { + + global $coauthors_plus; + + $guest_author_id = $coauthors_plus->guest_authors->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + + $guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id ); + + unset( $guest_author->user_email ); + + $this->assertEmpty( coauthors_get_avatar( $guest_author ) ); + } + + /** + * Checks co-author's avatar with size. + * + * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 + * + * @covers ::coauthors_get_avatar() + */ + public function test_coauthors_get_avatar_size() { + + $size = '100'; + $author1 = get_user_by( 'id', $this->author1 ); + + $this->assertEquals( preg_match( "|^author1 ); + + $this->assertEquals( preg_match( "|^$alt Date: Wed, 27 Dec 2017 14:20:25 +0530 Subject: [PATCH 140/231] [#184] Fix undefined variable warnings and add feed_type for feed link --- template-tags.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/template-tags.php b/template-tags.php index f3883b56..8c841bb7 100644 --- a/template-tags.php +++ b/template-tags.php @@ -537,12 +537,16 @@ function coauthors_wp_list_authors( $args = array() ) { if ( empty( $args['feed_image'] ) ) { $link .= '('; } - $link .= 'ID, $args['feed_type'] ) . '"'; + + $alt = ''; + $title = ''; if ( ! empty( $args['feed'] ) ) { + $title = ' title="' . esc_attr( $args['feed'] ) . '"'; - $alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; - $name = $feed; + $alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; + $name = $args['feed']; $link .= $title; } From 4c4c23df318308f6364c00a68cdfff223b6b941b Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 14:56:47 +0530 Subject: [PATCH 141/231] [#388] Unit tests for is_guest_authors_enabled() method --- tests/test-coauthors-plus.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/test-coauthors-plus.php diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php new file mode 100644 index 00000000..35f08aaf --- /dev/null +++ b/tests/test-coauthors-plus.php @@ -0,0 +1,26 @@ +assertTrue( $coauthors_plus->is_guest_authors_enabled() ); + + tests_add_filter( 'coauthors_guest_authors_enabled', '__return_false' ); + + $this->assertFalse( $coauthors_plus->is_guest_authors_enabled() ); + } +} From 0057e72009e47b2e2f3ac161680eddbf55332edf Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 16:36:56 +0530 Subject: [PATCH 142/231] [#388] Unit tests for get_coauthor_by() method --- tests/test-coauthors-plus.php | 87 ++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 35f08aaf..07ac5870 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -3,14 +3,24 @@ class Test_CoAuthors_Plus extends CoAuthorsPlus_TestCase { public function setUp() { + parent::setUp(); + + $this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); + + $this->post_id = wp_insert_post( array( + 'post_author' => $this->author1->ID, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'post', + ) ); } /** * Checks whether the guest authors functionality is enabled or not. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/388 - * * @covers ::is_guest_authors_enabled() */ public function test_is_guest_authors_enabled() { @@ -23,4 +33,77 @@ public function test_is_guest_authors_enabled() { $this->assertFalse( $coauthors_plus->is_guest_authors_enabled() ); } + + /** + * Checks coauthor object when he/she is a guest author. + * + * @covers ::get_coauthor_by() + */ + public function test_get_coauthor_by_when_guest_author() { + + global $coauthors_plus; + + $guest_author_id = $coauthors_plus->guest_authors->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + + $coauthor = $coauthors_plus->get_coauthor_by( 'id', $guest_author_id ); + + $this->assertInternalType( 'object', $coauthor ); + $this->assertInstanceOf( stdClass::class, $coauthor ); + $this->assertObjectHasAttribute( 'ID', $coauthor ); + $this->assertEquals( $guest_author_id, $coauthor->ID ); + $this->assertEquals( 'guest-author', $coauthor->type ); + } + + /** + * Checks coauthor object when he/she is a wp author. + * + * @covers ::get_coauthor_by() + */ + public function test_get_coauthor_by_when_wp_user() { + + global $coauthors_plus; + + $this->assertFalse( $coauthors_plus->get_coauthor_by( '', '' ) ); + + $coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->author1->ID ); + + $this->assertInternalType( 'object', $coauthor ); + $this->assertInstanceOf( WP_User::class, $coauthor ); + $this->assertObjectHasAttribute( 'ID', $coauthor ); + $this->assertEquals( $this->author1->ID, $coauthor->ID ); + $this->assertEquals( 'wpuser', $coauthor->type ); + + $coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $this->author1->user_login ); + + $this->assertInternalType( 'object', $coauthor ); + $this->assertInstanceOf( WP_User::class, $coauthor ); + $this->assertObjectHasAttribute( 'user_login', $coauthor->data ); + $this->assertEquals( $this->author1->user_login, $coauthor->user_login ); + + $coauthor = $coauthors_plus->get_coauthor_by( 'user_nicename', $this->author1->user_nicename ); + + $this->assertInternalType( 'object', $coauthor ); + $this->assertInstanceOf( WP_User::class, $coauthor ); + $this->assertObjectHasAttribute( 'user_nicename', $coauthor->data ); + $this->assertEquals( $this->author1->user_nicename, $coauthor->user_nicename ); + + $coauthor = $coauthors_plus->get_coauthor_by( 'user_email', $this->author1->user_email ); + + $this->assertInternalType( 'object', $coauthor ); + $this->assertInstanceOf( WP_User::class, $coauthor ); + $this->assertObjectHasAttribute( 'user_email', $coauthor->data ); + $this->assertEquals( $this->author1->user_email, $coauthor->user_email ); + + $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1->ID ); + + $coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->editor1->ID ); + + $this->assertInternalType( 'object', $coauthor ); + $this->assertInstanceOf( stdClass::class, $coauthor ); + $this->assertObjectHasAttribute( 'linked_account', $coauthor ); + $this->assertEquals( $this->editor1->user_login, $coauthor->linked_account ); + } } From 5423d3ee5c21de5dc54ad4a28e0a3c1ce46b8000 Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 17:30:56 +0530 Subject: [PATCH 143/231] [#184] Improve unit tests --- template-tags.php | 2 +- tests/test-template-tags.php | 414 ++++++++++++++--------------------- 2 files changed, 160 insertions(+), 256 deletions(-) diff --git a/template-tags.php b/template-tags.php index 8c841bb7..efd59f69 100644 --- a/template-tags.php +++ b/template-tags.php @@ -537,7 +537,7 @@ function coauthors_wp_list_authors( $args = array() ) { if ( empty( $args['feed_image'] ) ) { $link .= '('; } - $link .= 'ID, $args['feed_type'] ) ) . '"'; $alt = ''; $title = ''; diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 13121816..dde8a3dd 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -6,11 +6,11 @@ public function setUp() { parent::setUp(); - $this->author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); - $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); + $this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); - $this->post_id = wp_insert_post( array( - 'post_author' => $this->author1, + $this->post = $this->factory->post->create_and_get( array( + 'post_author' => $this->author1->ID, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), @@ -21,8 +21,6 @@ public function setUp() { /** * Checks coauthors when post not exist. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::get_coauthors() */ public function test_get_coauthors_when_post_not_exists() { @@ -33,8 +31,6 @@ public function test_get_coauthors_when_post_not_exists() { /** * Checks coauthors when post exist (not global). * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::get_coauthors() */ public function test_get_coauthors_when_post_exists() { @@ -42,19 +38,19 @@ public function test_get_coauthors_when_post_exists() { global $coauthors_plus; // Compare single author. - $this->assertEquals( array( $this->author1 ), wp_list_pluck( get_coauthors( $this->post_id ), 'ID' ) ); + $this->assertEquals( array( $this->author1->ID ), wp_list_pluck( get_coauthors( $this->post->ID ), 'ID' ) ); // Compare multiple authors. - $editor1 = get_user_by( 'id', $this->editor1 ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); - $this->assertEquals( array( $this->author1, $this->editor1 ), wp_list_pluck( get_coauthors( $this->post_id ), 'ID' ) ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); + $this->assertEquals( array( + $this->author1->ID, + $this->editor1->ID, + ), wp_list_pluck( get_coauthors( $this->post->ID ), 'ID' ) ); } /** * Checks coauthors when terms for post not exist. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::get_coauthors() */ public function test_get_coauthors_when_terms_for_post_not_exists() { @@ -66,8 +62,6 @@ public function test_get_coauthors_when_terms_for_post_not_exists() { /** * Checks coauthors when post not exist. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::get_coauthors() */ public function test_get_coauthors_when_global_post_exists() { @@ -77,18 +71,16 @@ public function test_get_coauthors_when_global_post_exists() { // Backing up global post. $post_backup = $post; - $post_id = $this->factory->post->create(); - $post = get_post( $post_id ); + $post = $this->factory->post->create_and_get(); - $this->assertEmpty( get_coauthors( $post_id ) ); + $this->assertEmpty( get_coauthors() ); $user_id = $this->factory->user->create(); - $post_id = $this->factory->post->create( array( + $post = $this->factory->post->create_and_get( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); - $this->assertEquals( array( $user_id ), wp_list_pluck( get_coauthors( $post_id ), 'ID' ) ); + $this->assertEquals( array( $user_id ), wp_list_pluck( get_coauthors(), 'ID' ) ); // Restore global post from backup. $post = $post_backup; @@ -97,8 +89,6 @@ public function test_get_coauthors_when_global_post_exists() { /** * Checks whether user is a coauthor of the post when user or post not exists. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::is_coauthor_for_post() */ public function test_is_coauthor_for_post_when_user_or_post_not_exists() { @@ -109,10 +99,10 @@ public function test_is_coauthor_for_post_when_user_or_post_not_exists() { $post_backup = $post; $this->assertFalse( is_coauthor_for_post( '' ) ); - $this->assertFalse( is_coauthor_for_post( '', $this->post_id ) ); - $this->assertFalse( is_coauthor_for_post( $this->author1 ) ); + $this->assertFalse( is_coauthor_for_post( '', $this->post->ID ) ); + $this->assertFalse( is_coauthor_for_post( $this->author1->ID ) ); - $post = get_post( $this->post_id ); + $post = $this->post; $this->assertFalse( is_coauthor_for_post( '' ) ); @@ -124,8 +114,6 @@ public function test_is_coauthor_for_post_when_user_or_post_not_exists() { * Checks whether user is a coauthor of the post when user is not expected as ID, * or user_login is not set in user object. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::is_coauthor_for_post() */ public function test_is_coauthor_for_post_when_user_not_numeric_or_user_login_not_set() { @@ -137,21 +125,17 @@ public function test_is_coauthor_for_post_when_user_not_numeric_or_user_login_no * Checks whether user is a coauthor of the post when user is set in either way, * as user_id or user object but he/she is not coauthor of the post. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::is_coauthor_for_post() */ - public function test_is_coauthor_for_post_when_user_numeric_or_user_login_set_but_no_coauthor() { + public function test_is_coauthor_for_post_when_user_numeric_or_user_login_set_but_not_coauthor() { - $this->assertFalse( is_coauthor_for_post( $this->editor1, $this->post_id ) ); - $this->assertFalse( is_coauthor_for_post( get_user_by( 'id', $this->editor1 ), $this->post_id ) ); + $this->assertFalse( is_coauthor_for_post( $this->editor1->ID, $this->post->ID ) ); + $this->assertFalse( is_coauthor_for_post( $this->editor1, $this->post->ID ) ); } /** * Checks whether user is a coauthor of the post. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::is_coauthor_for_post() */ public function test_is_coauthor_for_post_when_user_is_coauthor() { @@ -161,24 +145,23 @@ public function test_is_coauthor_for_post_when_user_is_coauthor() { // Backing up global post. $post_backup = $post; - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + // Checking with specific post and user_id as well ass user object. + $this->assertTrue( is_coauthor_for_post( $this->author1->ID, $this->post->ID ) ); + $this->assertTrue( is_coauthor_for_post( $this->author1, $this->post->ID ) ); - $this->assertTrue( is_coauthor_for_post( $this->author1, $this->post_id ) ); - $this->assertTrue( is_coauthor_for_post( $author1, $this->post_id ) ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $this->assertTrue( is_coauthor_for_post( $this->editor1->ID, $this->post->ID ) ); + $this->assertTrue( is_coauthor_for_post( $this->editor1, $this->post->ID ) ); - $this->assertTrue( is_coauthor_for_post( $this->editor1, $this->post_id ) ); - $this->assertTrue( is_coauthor_for_post( $editor1, $this->post_id ) ); - - $post = get_post( $this->post_id ); + // Now checking with global post and user_id as well ass user object. + $post = $this->post; + $this->assertTrue( is_coauthor_for_post( $this->author1->ID ) ); $this->assertTrue( is_coauthor_for_post( $this->author1 ) ); - $this->assertTrue( is_coauthor_for_post( $author1 ) ); + $this->assertTrue( is_coauthor_for_post( $this->editor1->ID ) ); $this->assertTrue( is_coauthor_for_post( $this->editor1 ) ); - $this->assertTrue( is_coauthor_for_post( $editor1 ) ); // Restore global post from backup. $post = $post_backup; @@ -187,9 +170,8 @@ public function test_is_coauthor_for_post_when_user_is_coauthor() { /** * Tests for co-authors display names, without links to their posts. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors() + * @covers ::coauthors__echo() **/ public function test_coauthors() { @@ -198,35 +180,33 @@ public function test_coauthors() { // Backing up global post. $post_backup = $post; - $post = get_post( $this->post_id ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post = $this->post; // Checks for single post author. $coauthors = coauthors( null, null, null, null, false ); - $this->assertEquals( $author1->display_name, $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); + $this->assertEquals( $this->author1->display_name, $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); $coauthors = coauthors( '
    ', '', '', '', false ); - $this->assertEquals( '' . $author1->display_name . '', $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); + $this->assertEquals( '' . $this->author1->display_name . '', $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); // Checks for multiple post author. - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $coauthors = coauthors( null, null, null, null, false ); - $this->assertEquals( $author1->display_name . ' and ' . $editor1->display_name, $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); - $this->assertEquals( 1, substr_count( $coauthors, $editor1->display_name ) ); + $this->assertEquals( $this->author1->display_name . ' and ' . $this->editor1->display_name, $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); + $this->assertEquals( 1, substr_count( $coauthors, $this->editor1->display_name ) ); $coauthors = coauthors( '', '', '', '', false ); - $this->assertEquals( '' . $author1->display_name . '' . $editor1->display_name . '', $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $author1->display_name ) ); - $this->assertEquals( 1, substr_count( $coauthors, $editor1->display_name ) ); + $this->assertEquals( '' . $this->author1->display_name . '' . $this->editor1->display_name . '', $coauthors ); + $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); + $this->assertEquals( 1, substr_count( $coauthors, $this->editor1->display_name ) ); // Restore global post from backup. $post = $post_backup; @@ -235,29 +215,25 @@ public function test_coauthors() { /** * Checks single co-author linked to their post archive. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_posts_links_single() */ public function test_coauthors_posts_links_single() { - $author1 = get_user_by( 'id', $this->author1 ); - $author_link = coauthors_posts_links_single( $author1 ); + $author_link = coauthors_posts_links_single( $this->author1 ); - $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $author_link, 'Author link not found.' ); - $this->assertContains( $author1->display_name, $author_link, 'Author name not found.' ); + $this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $author_link, 'Author link not found.' ); + $this->assertContains( $this->author1->display_name, $author_link, 'Author name not found.' ); // Here we are checking author name should not be more then one time. - // Asserting ">{$author1->display_name}<" because "$author1->display_name" can be multiple times like in href, title, etc. - $this->assertEquals( 1, substr_count( $author_link, ">{$author1->display_name}<" ) ); + // Asserting ">{$this->author1->display_name}<" because "$this->author1->display_name" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $author_link, ">{$this->author1->display_name}<" ) ); } /** * Checks co-authors first names, without links to their posts. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_firstnames() + * @covers ::coauthors__echo() */ public function test_coauthors_firstnames() { @@ -266,42 +242,39 @@ public function test_coauthors_firstnames() { // Backing up global post. $post_backup = $post; - $post = get_post( $this->post_id ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post = $this->post; $first_names = coauthors_firstnames( null, null, null, null, false ); - $this->assertEquals( $author1->user_login, $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + $this->assertEquals( $this->author1->user_login, $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); $first_names = coauthors_firstnames( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_login . '', $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); + $this->assertEquals( '' . $this->author1->user_login . '', $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $first_names = coauthors_firstnames( null, null, null, null, false ); - $this->assertEquals( $author1->user_login . ' and ' . $editor1->user_login, $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); - $this->assertEquals( 1, substr_count( $first_names, $editor1->user_login ) ); + $this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); + $this->assertEquals( 1, substr_count( $first_names, $this->editor1->user_login ) ); $first_names = coauthors_firstnames( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_login . '' . $editor1->user_login . '', $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $author1->user_login ) ); - $this->assertEquals( 1, substr_count( $first_names, $editor1->user_login ) ); + $this->assertEquals( '' . $this->author1->user_login . '' . $this->editor1->user_login . '', $first_names ); + $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); + $this->assertEquals( 1, substr_count( $first_names, $this->editor1->user_login ) ); $first_name = 'Test'; $user_id = $this->factory->user->create( array( 'first_name' => $first_name, ) ); - $post_id = $this->factory->post->create( array( + $post = $this->factory->post->create_and_get( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); $first_names = coauthors_firstnames( null, null, null, null, false ); @@ -315,9 +288,8 @@ public function test_coauthors_firstnames() { /** * Checks co-authors last names, without links to their posts. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_lastnames() + * @covers ::coauthors__echo() */ public function test_coauthors_lastnames() { @@ -326,42 +298,39 @@ public function test_coauthors_lastnames() { // Backing up global post. $post_backup = $post; - $post = get_post( $this->post_id ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post = $this->post; $last_names = coauthors_lastnames( null, null, null, null, false ); - $this->assertEquals( $author1->user_login, $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + $this->assertEquals( $this->author1->user_login, $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); $last_names = coauthors_lastnames( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_login . '', $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); + $this->assertEquals( '' . $this->author1->user_login . '', $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $last_names = coauthors_lastnames( null, null, null, null, false ); - $this->assertEquals( $author1->user_login . ' and ' . $editor1->user_login, $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); - $this->assertEquals( 1, substr_count( $last_names, $editor1->user_login ) ); + $this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); + $this->assertEquals( 1, substr_count( $last_names, $this->editor1->user_login ) ); $last_names = coauthors_lastnames( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_login . '' . $editor1->user_login . '', $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $author1->user_login ) ); - $this->assertEquals( 1, substr_count( $last_names, $editor1->user_login ) ); + $this->assertEquals( '' . $this->author1->user_login . '' . $this->editor1->user_login . '', $last_names ); + $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); + $this->assertEquals( 1, substr_count( $last_names, $this->editor1->user_login ) ); $last_name = 'Test'; $user_id = $this->factory->user->create( array( 'last_name' => $last_name, ) ); - $post_id = $this->factory->post->create( array( + $post = $this->factory->post->create_and_get( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); $last_names = coauthors_lastnames( null, null, null, null, false ); @@ -375,9 +344,8 @@ public function test_coauthors_lastnames() { /** * Checks co-authors nicknames, without links to their posts. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_nicknames() + * @covers ::coauthors__echo() */ public function test_coauthors_nicknames() { @@ -386,42 +354,39 @@ public function test_coauthors_nicknames() { // Backing up global post. $post_backup = $post; - $post = get_post( $this->post_id ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post = $this->post; $nick_names = coauthors_nicknames( null, null, null, null, false ); - $this->assertEquals( $author1->user_login, $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); + $this->assertEquals( $this->author1->user_login, $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); $nick_names = coauthors_nicknames( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_login . '', $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); + $this->assertEquals( '' . $this->author1->user_login . '', $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $nick_names = coauthors_nicknames( null, null, null, null, false ); - $this->assertEquals( $author1->user_login . ' and ' . $editor1->user_login, $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); - $this->assertEquals( 1, substr_count( $nick_names, $editor1->user_login ) ); + $this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); + $this->assertEquals( 1, substr_count( $nick_names, $this->editor1->user_login ) ); $nick_names = coauthors_nicknames( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_login . '' . $editor1->user_login . '', $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $author1->user_login ) ); - $this->assertEquals( 1, substr_count( $nick_names, $editor1->user_login ) ); + $this->assertEquals( '' . $this->author1->user_login . '' . $this->editor1->user_login . '', $nick_names ); + $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); + $this->assertEquals( 1, substr_count( $nick_names, $this->editor1->user_login ) ); $nick_name = 'Test'; $user_id = $this->factory->user->create( array( 'nickname' => $nick_name, ) ); - $post_id = $this->factory->post->create( array( + $post = $this->factory->post->create_and_get( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); $nick_names = coauthors_nicknames( null, null, null, null, false ); @@ -435,9 +400,8 @@ public function test_coauthors_nicknames() { /** * Checks co-authors email addresses. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_emails() + * @covers ::coauthors__echo() */ public function test_coauthors_emails() { @@ -446,42 +410,39 @@ public function test_coauthors_emails() { // Backing up global post. $post_backup = $post; - $post = get_post( $this->post_id ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post = $this->post; $emails = coauthors_emails( null, null, null, null, false ); - $this->assertEquals( $author1->user_email, $emails ); - $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); + $this->assertEquals( $this->author1->user_email, $emails ); + $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); $emails = coauthors_emails( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_email . '', $emails ); - $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); + $this->assertEquals( '' . $this->author1->user_email . '', $emails ); + $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $emails = coauthors_emails( null, null, null, null, false ); - $this->assertEquals( $author1->user_email . ' and ' . $editor1->user_email, $emails ); - $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); - $this->assertEquals( 1, substr_count( $emails, $editor1->user_email ) ); + $this->assertEquals( $this->author1->user_email . ' and ' . $this->editor1->user_email, $emails ); + $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); + $this->assertEquals( 1, substr_count( $emails, $this->editor1->user_email ) ); $emails = coauthors_emails( '', '', '', '', false ); - $this->assertEquals( '' . $author1->user_email . '' . $editor1->user_email . '', $emails ); - $this->assertEquals( 1, substr_count( $emails, $author1->user_email ) ); - $this->assertEquals( 1, substr_count( $emails, $editor1->user_email ) ); + $this->assertEquals( '' . $this->author1->user_email . '' . $this->editor1->user_email . '', $emails ); + $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); + $this->assertEquals( 1, substr_count( $emails, $this->editor1->user_email ) ); $email = 'test@example.org'; $user_id = $this->factory->user->create( array( 'user_email' => $email, ) ); - $post_id = $this->factory->post->create( array( + $post = $this->factory->post->create_and_get( array( 'post_author' => $user_id, ) ); - $post = get_post( $post_id ); $emails = coauthors_emails( null, null, null, null, false ); @@ -495,8 +456,6 @@ public function test_coauthors_emails() { /** * Checks single co-author if he/she is a guest author. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_links_single() */ public function test_coauthors_links_single_when_guest_author() { @@ -506,17 +465,16 @@ public function test_coauthors_links_single_when_guest_author() { // Backing up global author data. $authordata_backup = $authordata; - $author1 = get_user_by( 'id', $this->author1 ); - $author1->type = 'guest-author'; + $this->author1->type = 'guest-author'; - $this->assertNull( coauthors_links_single( $author1 ) ); + $this->assertNull( coauthors_links_single( $this->author1 ) ); - update_user_meta( $this->author1, 'website', 'example.org' ); + update_user_meta( $this->author1->ID, 'website', 'example.org' ); - $this->assertNull( coauthors_links_single( $author1 ) ); + $this->assertNull( coauthors_links_single( $this->author1 ) ); - $authordata = $author1; - $author_link = coauthors_links_single( $author1 ); + $authordata = $this->author1; + $author_link = coauthors_links_single( $this->author1 ); $this->assertContains( get_the_author_meta( 'website' ), $author_link, 'Author link not found.' ); $this->assertContains( get_the_author(), $author_link, 'Author name not found.' ); @@ -532,8 +490,6 @@ public function test_coauthors_links_single_when_guest_author() { /** * Checks single co-author when user's url is set and not a guest author. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_links_single() */ public function test_coauthors_links_single_author_url_is_set() { @@ -565,8 +521,6 @@ public function test_coauthors_links_single_author_url_is_set() { /** * Checks single co-author when user's website/url not exist. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_links_single() */ public function test_coauthors_links_single_when_url_not_exist() { @@ -576,13 +530,12 @@ public function test_coauthors_links_single_when_url_not_exist() { // Backing up global author data. $authordata_backup = $authordata; - $author1 = get_user_by( 'id', $this->author1 ); - $author_link = coauthors_links_single( $author1 ); + $author_link = coauthors_links_single( $this->author1 ); $this->assertEmpty( $author_link ); - $authordata = $author1; - $author_link = coauthors_links_single( $author1 ); + $authordata = $this->author1; + $author_link = coauthors_links_single( $this->author1 ); $this->assertEquals( get_the_author(), $author_link ); @@ -593,9 +546,8 @@ public function test_coauthors_links_single_when_url_not_exist() { /** * Checks co-authors IDs. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_ids() + * @covers ::coauthors__echo() */ public function test_coauthors_ids() { @@ -604,33 +556,31 @@ public function test_coauthors_ids() { // Backing up global post. $post_backup = $post; - $post = get_post( $this->post_id ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $post = $this->post; $ids = coauthors_ids( null, null, null, null, false ); - $this->assertEquals( $author1->ID, $ids ); - $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); + $this->assertEquals( $this->author1->ID, $ids ); + $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); $ids = coauthors_ids( '', '', '', '', false ); - $this->assertEquals( '' . $author1->ID . '', $ids ); - $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); + $this->assertEquals( '' . $this->author1->ID . '', $ids ); + $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $ids = coauthors_ids( null, null, null, null, false ); - $this->assertEquals( $author1->ID . ' and ' . $editor1->ID, $ids ); - $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); - $this->assertEquals( 1, substr_count( $ids, $editor1->ID ) ); + $this->assertEquals( $this->author1->ID . ' and ' . $this->editor1->ID, $ids ); + $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); + $this->assertEquals( 1, substr_count( $ids, $this->editor1->ID ) ); $ids = coauthors_ids( '', '', '', '', false ); - $this->assertEquals( '' . $author1->ID . '' . $editor1->ID . '', $ids ); - $this->assertEquals( 1, substr_count( $ids, $author1->ID ) ); - $this->assertEquals( 1, substr_count( $ids, $editor1->ID ) ); + $this->assertEquals( '' . $this->author1->ID . '' . $this->editor1->ID . '', $ids ); + $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); + $this->assertEquals( 1, substr_count( $ids, $this->editor1->ID ) ); // Restore global post from backup. $post = $post_backup; @@ -639,8 +589,6 @@ public function test_coauthors_ids() { /** * Checks co-authors meta. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::get_the_coauthor_meta() */ public function test_get_the_coauthor_meta() { @@ -652,14 +600,14 @@ public function test_get_the_coauthor_meta() { $this->assertEmpty( get_the_coauthor_meta( '' ) ); - update_user_meta( $this->author1, 'test_meta', 'test_meta' ); + update_user_meta( $this->author1->ID, 'meta_key', 'meta_value' ); - $this->assertEmpty( get_the_coauthor_meta( 'test_meta' ) ); + $this->assertEmpty( get_the_coauthor_meta( 'meta_key' ) ); - $post = get_post( $this->post_id ); - $meta = get_the_coauthor_meta( 'test_meta' ); + $post = $this->post; + $meta = get_the_coauthor_meta( 'meta_key' ); - $this->assertEquals( 'test_meta', $meta[ $this->author1 ] ); + $this->assertEquals( 'meta_value', $meta[ $this->author1->ID ] ); // Restore global post from backup. $post = $post_backup; @@ -668,8 +616,6 @@ public function test_get_the_coauthor_meta() { /** * Checks all the co-authors of the blog with default args. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_default_args() { @@ -680,48 +626,44 @@ public function test_coauthors_wp_list_authors_for_default_args() { 'echo' => false, ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); $coauthors = coauthors_wp_list_authors( $args ); - $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $coauthors, 'Author link not found.' ); - $this->assertContains( $author1->display_name, $coauthors, 'Author name not found.' ); + $this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $coauthors, 'Author link not found.' ); + $this->assertContains( $this->author1->display_name, $coauthors, 'Author name not found.' ); $coauthors = coauthors_wp_list_authors( $args ); - $this->assertNotContains( 'href="' . get_author_posts_url( $editor1->ID, $editor1->user_nicename ) . '"', $coauthors ); - $this->assertNotContains( $editor1->display_name, $coauthors ); + $this->assertNotContains( 'href="' . get_author_posts_url( $this->editor1->ID, $this->editor1->user_nicename ) . '"', $coauthors ); + $this->assertNotContains( $this->editor1->display_name, $coauthors ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $coauthors = coauthors_wp_list_authors( $args ); - $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $coauthors, 'Main author link not found.' ); - $this->assertContains( $author1->display_name, $coauthors, 'Main author name not found.' ); + $this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $coauthors, 'Main author link not found.' ); + $this->assertContains( $this->author1->display_name, $coauthors, 'Main author name not found.' ); // Here we are checking author name should not be more then one time. - // Asserting ">{$author1->display_name}<" because "$author1->display_name" can be multiple times like in href, title, etc. - $this->assertEquals( 1, substr_count( $coauthors, ">{$author1->display_name}<" ) ); + // Asserting ">{$this->author1->display_name}<" because "$this->author1->display_name" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $coauthors, ">{$this->author1->display_name}<" ) ); $this->assertContains( '
  • ', $coauthors, 'Coauthors name separator is not matched.' ); - $this->assertContains( 'href="' . get_author_posts_url( $editor1->ID, $editor1->user_nicename ) . '"', $coauthors, 'Coauthor link not found.' ); - $this->assertContains( $editor1->display_name, $coauthors, 'Coauthor name not found.' ); + $this->assertContains( 'href="' . get_author_posts_url( $this->editor1->ID, $this->editor1->user_nicename ) . '"', $coauthors, 'Coauthor link not found.' ); + $this->assertContains( $this->editor1->display_name, $coauthors, 'Coauthor name not found.' ); // Here we are checking editor name should not be more then one time. - // Asserting ">{$editor1->display_name}<" because "$editor1->display_name" can be multiple times like in href, title, etc. - $this->assertEquals( 1, substr_count( $coauthors, ">{$editor1->display_name}<" ) ); + // Asserting ">{$this->editor1->display_name}<" because "$this->editor1->display_name" can be multiple times like in href, title, etc. + $this->assertEquals( 1, substr_count( $coauthors, ">{$this->editor1->display_name}<" ) ); } /** * Checks all the co-authors of the blog with optioncount option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_optioncount() { - $this->assertContains( '(' . count_user_posts( $this->author1 ) . ')', coauthors_wp_list_authors( array( + $this->assertContains( '(' . count_user_posts( $this->author1->ID ) . ')', coauthors_wp_list_authors( array( 'echo' => false, 'optioncount' => true, ) ) ); @@ -730,8 +672,6 @@ public function test_coauthors_wp_list_authors_for_optioncount() { /** * Checks all the co-authors of the blog with show_fullname option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_show_fullname() { @@ -741,9 +681,7 @@ public function test_coauthors_wp_list_authors_for_show_fullname() { 'show_fullname' => true, ); - $author1 = get_user_by( 'id', $this->author1 ); - - $this->assertContains( $author1->display_name, coauthors_wp_list_authors( $args ) ); + $this->assertContains( $this->author1->display_name, coauthors_wp_list_authors( $args ) ); $user = $this->factory->user->create_and_get( array( 'first_name' => 'First', @@ -760,8 +698,6 @@ public function test_coauthors_wp_list_authors_for_show_fullname() { /** * Checks all the co-authors of the blog with hide_empty option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_hide_empty() { @@ -782,8 +718,6 @@ public function test_coauthors_wp_list_authors_for_hide_empty() { /** * Checks all the co-authors of the blog with feed option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_feed() { @@ -794,15 +728,13 @@ public function test_coauthors_wp_list_authors_for_feed() { 'feed' => $feed_text, ) ); - $this->assertContains( get_author_feed_link( $this->author1 ), $coauthors ); + $this->assertContains( esc_url( get_author_feed_link( $this->author1->ID ) ), $coauthors ); $this->assertContains( $feed_text, $coauthors ); } /** * Checks all the co-authors of the blog with feed_image option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_feed_image() { @@ -813,15 +745,13 @@ public function test_coauthors_wp_list_authors_for_feed_image() { 'feed_image' => $feed_image, ) ); - $this->assertContains( get_author_feed_link( $this->author1 ), $coauthors ); + $this->assertContains( esc_url( get_author_feed_link( $this->author1->ID ) ), $coauthors ); $this->assertContains( $feed_image, $coauthors ); } /** * Checks all the co-authors of the blog with feed_type option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_feed_type() { @@ -834,7 +764,7 @@ public function test_coauthors_wp_list_authors_for_feed_type() { 'feed' => $feed_text, ) ); - $this->assertContains( get_author_feed_link( $this->author1, $feed_type ), $coauthors ); + $this->assertContains( esc_url( get_author_feed_link( $this->author1->ID, $feed_type ) ), $coauthors ); $this->assertContains( $feed_type, $coauthors ); $this->assertContains( $feed_text, $coauthors ); } @@ -842,8 +772,6 @@ public function test_coauthors_wp_list_authors_for_feed_type() { /** * Checks all the co-authors of the blog with style option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_style() { @@ -860,8 +788,6 @@ public function test_coauthors_wp_list_authors_for_style() { /** * Checks all the co-authors of the blog with html option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_html() { @@ -873,21 +799,16 @@ public function test_coauthors_wp_list_authors_for_html() { 'html' => false, ); - $author1 = get_user_by( 'id', $this->author1 ); - $editor1 = get_user_by( 'id', $this->editor1 ); + $this->assertEquals( $this->author1->display_name, coauthors_wp_list_authors( $args ) ); - $this->assertEquals( $author1->display_name, coauthors_wp_list_authors( $args ) ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); - $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); - - $this->assertEquals( "$author1->display_name, $editor1->display_name", coauthors_wp_list_authors( $args ) ); + $this->assertEquals( "{$this->author1->display_name}, {$this->editor1->display_name}", coauthors_wp_list_authors( $args ) ); } /** * Checks all the co-authors of the blog with guest_authors_only option. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_wp_list_authors() */ public function test_coauthors_wp_list_authors_for_guest_authors_only() { @@ -910,7 +831,7 @@ public function test_coauthors_wp_list_authors_for_guest_authors_only() { $guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id ); - $coauthors_plus->add_coauthors( $this->post_id, array( $guest_author->user_login ), true ); + $coauthors_plus->add_coauthors( $this->post->ID, array( $guest_author->user_login ), true ); $this->assertContains( $guest_author->display_name, coauthors_wp_list_authors( $args ) ); } @@ -918,24 +839,17 @@ public function test_coauthors_wp_list_authors_for_guest_authors_only() { /** * Checks co-author's avatar. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_get_avatar() */ public function test_coauthors_get_avatar_default() { - $this->assertEmpty( coauthors_get_avatar( $this->author1 ) ); - - $author1 = get_user_by( 'id', $this->author1 ); - - $this->assertEquals( preg_match( "|^[^$|", coauthors_get_avatar( $author1 ) ), 1 ); + $this->assertEmpty( coauthors_get_avatar( $this->author1->ID ) ); + $this->assertEquals( preg_match( "|^[^$|", coauthors_get_avatar( $this->author1 ) ), 1 ); } /** * Checks co-author's avatar when author is a guest author. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_get_avatar() */ public function test_coauthors_get_avatar_when_guest_author() { @@ -971,8 +885,6 @@ public function test_coauthors_get_avatar_when_guest_author() { /** * Checks co-author's avatar when user's email is not set somehow. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_get_avatar() */ public function test_coauthors_get_avatar_when_user_email_not_set() { @@ -994,30 +906,22 @@ public function test_coauthors_get_avatar_when_user_email_not_set() { /** * Checks co-author's avatar with size. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_get_avatar() */ public function test_coauthors_get_avatar_size() { - $size = '100'; - $author1 = get_user_by( 'id', $this->author1 ); - - $this->assertEquals( preg_match( "|^assertEquals( preg_match( "|^author1, $size ) ), 1 ); } /** * Checks co-author's avatar with alt. * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/184 - * * @covers ::coauthors_get_avatar() */ public function test_coauthors_get_avatar_alt() { - $alt = 'Test'; - $author1 = get_user_by( 'id', $this->author1 ); - - $this->assertEquals( preg_match( "|^$altassertEquals( preg_match( "|^$altauthor1, 96, '', $alt ) ), 1 ); } } From c90d7e8f939206d2a87141c704266348a9e03624 Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 17:58:26 +0530 Subject: [PATCH 144/231] [#388] Unit tests for is_post_type_enabled() method --- tests/test-coauthors-plus.php | 47 ++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 07ac5870..448a5d3d 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -9,7 +9,7 @@ public function setUp() { $this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); - $this->post_id = wp_insert_post( array( + $this->post = $this->factory->post->create_and_get( array( 'post_author' => $this->author1->ID, 'post_status' => 'publish', 'post_content' => rand_str(), @@ -106,4 +106,49 @@ public function test_get_coauthor_by_when_wp_user() { $this->assertObjectHasAttribute( 'linked_account', $coauthor ); $this->assertEquals( $this->editor1->user_login, $coauthor->linked_account ); } + + /** + * Checks coauthors plus is enabled for this post type. + * + * @covers ::is_post_type_enabled() + */ + public function test_is_post_type_enabled() { + + global $coauthors_plus, $post; + + // Backing up global post. + $post_backup = $post; + + // Checks when post type is null. + $this->assertFalse( $coauthors_plus->is_post_type_enabled() ); + + // Checks when post type is post. + $this->assertTrue( $coauthors_plus->is_post_type_enabled( 'post' ) ); + + // Checks when post type is page. + $this->assertTrue( $coauthors_plus->is_post_type_enabled( 'page' ) ); + + // Checks when post type is attachment. + $this->assertFalse( $coauthors_plus->is_post_type_enabled( 'attachment' ) ); + + // Checks when post type is revision. + $this->assertFalse( $coauthors_plus->is_post_type_enabled( 'revision' ) ); + + $post = $this->post; + + // Checks when post type set using global post. + $this->assertTrue( $coauthors_plus->is_post_type_enabled() ); + + $post = ''; + + // Set the edit post current screen. + set_current_screen( 'edit-post' ); + $this->assertTrue( $coauthors_plus->is_post_type_enabled() ); + + set_current_screen( 'edit' ); + $this->assertFalse( $coauthors_plus->is_post_type_enabled() ); + + // Restore global post from backup. + $post = $post_backup; + } } From 6a05c8b313c395ed04fcf4587becbcaa0c7a031b Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 18:05:26 +0530 Subject: [PATCH 145/231] [#388] Fix unit tests for is_post_type_enabled() method using current screen --- tests/test-coauthors-plus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 448a5d3d..7c480741 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -139,14 +139,14 @@ public function test_is_post_type_enabled() { // Checks when post type set using global post. $this->assertTrue( $coauthors_plus->is_post_type_enabled() ); - $post = ''; + $post = ''; + $screen = get_current_screen(); // Set the edit post current screen. set_current_screen( 'edit-post' ); $this->assertTrue( $coauthors_plus->is_post_type_enabled() ); - set_current_screen( 'edit' ); - $this->assertFalse( $coauthors_plus->is_post_type_enabled() ); + $GLOBALS['current_screen'] = $screen; // Restore global post from backup. $post = $post_backup; From a072306fa9b0bfd8b085ebabbd055031bbe89f64 Mon Sep 17 00:00:00 2001 From: sanketio Date: Wed, 27 Dec 2017 19:07:32 +0530 Subject: [PATCH 146/231] [#184] Remove not needed assertions and add proper commenting --- tests/test-template-tags.php | 46 +++++------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index dde8a3dd..4d14420e 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -186,12 +186,10 @@ public function test_coauthors() { $coauthors = coauthors( null, null, null, null, false ); $this->assertEquals( $this->author1->display_name, $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); $coauthors = coauthors( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->display_name . '', $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); // Checks for multiple post author. $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); @@ -199,14 +197,10 @@ public function test_coauthors() { $coauthors = coauthors( null, null, null, null, false ); $this->assertEquals( $this->author1->display_name . ' and ' . $this->editor1->display_name, $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); - $this->assertEquals( 1, substr_count( $coauthors, $this->editor1->display_name ) ); $coauthors = coauthors( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->display_name . '' . $this->editor1->display_name . '', $coauthors ); - $this->assertEquals( 1, substr_count( $coauthors, $this->author1->display_name ) ); - $this->assertEquals( 1, substr_count( $coauthors, $this->editor1->display_name ) ); // Restore global post from backup. $post = $post_backup; @@ -244,30 +238,26 @@ public function test_coauthors_firstnames() { $post = $this->post; + // Checking when first name is not set for user, so it should match with user_login. $first_names = coauthors_firstnames( null, null, null, null, false ); $this->assertEquals( $this->author1->user_login, $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); $first_names = coauthors_firstnames( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_login . '', $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $first_names = coauthors_firstnames( null, null, null, null, false ); $this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); - $this->assertEquals( 1, substr_count( $first_names, $this->editor1->user_login ) ); $first_names = coauthors_firstnames( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_login . '' . $this->editor1->user_login . '', $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $this->author1->user_login ) ); - $this->assertEquals( 1, substr_count( $first_names, $this->editor1->user_login ) ); + // Checking when first name is set for user. $first_name = 'Test'; $user_id = $this->factory->user->create( array( 'first_name' => $first_name, @@ -279,7 +269,6 @@ public function test_coauthors_firstnames() { $first_names = coauthors_firstnames( null, null, null, null, false ); $this->assertEquals( $first_name, $first_names ); - $this->assertEquals( 1, substr_count( $first_names, $first_name ) ); // Restore global post from backup. $post = $post_backup; @@ -300,30 +289,26 @@ public function test_coauthors_lastnames() { $post = $this->post; + // Checking when last name is not set for user, so it should match with user_login. $last_names = coauthors_lastnames( null, null, null, null, false ); $this->assertEquals( $this->author1->user_login, $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); $last_names = coauthors_lastnames( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_login . '', $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $last_names = coauthors_lastnames( null, null, null, null, false ); $this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); - $this->assertEquals( 1, substr_count( $last_names, $this->editor1->user_login ) ); $last_names = coauthors_lastnames( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_login . '' . $this->editor1->user_login . '', $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $this->author1->user_login ) ); - $this->assertEquals( 1, substr_count( $last_names, $this->editor1->user_login ) ); + // Checking when last name is set for user. $last_name = 'Test'; $user_id = $this->factory->user->create( array( 'last_name' => $last_name, @@ -335,7 +320,6 @@ public function test_coauthors_lastnames() { $last_names = coauthors_lastnames( null, null, null, null, false ); $this->assertEquals( $last_name, $last_names ); - $this->assertEquals( 1, substr_count( $last_names, $last_name ) ); // Restore global post from backup. $post = $post_backup; @@ -356,30 +340,26 @@ public function test_coauthors_nicknames() { $post = $this->post; + // Checking when nickname is not set for user, so it should match with user_login. $nick_names = coauthors_nicknames( null, null, null, null, false ); $this->assertEquals( $this->author1->user_login, $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); $nick_names = coauthors_nicknames( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_login . '', $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $nick_names = coauthors_nicknames( null, null, null, null, false ); $this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); - $this->assertEquals( 1, substr_count( $nick_names, $this->editor1->user_login ) ); $nick_names = coauthors_nicknames( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_login . '' . $this->editor1->user_login . '', $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $this->author1->user_login ) ); - $this->assertEquals( 1, substr_count( $nick_names, $this->editor1->user_login ) ); + // Checking when nickname is set for user. $nick_name = 'Test'; $user_id = $this->factory->user->create( array( 'nickname' => $nick_name, @@ -391,7 +371,6 @@ public function test_coauthors_nicknames() { $nick_names = coauthors_nicknames( null, null, null, null, false ); $this->assertEquals( $nick_name, $nick_names ); - $this->assertEquals( 1, substr_count( $nick_names, $nick_name ) ); // Restore global post from backup. $post = $post_backup; @@ -415,26 +394,20 @@ public function test_coauthors_emails() { $emails = coauthors_emails( null, null, null, null, false ); $this->assertEquals( $this->author1->user_email, $emails ); - $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); $emails = coauthors_emails( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_email . '', $emails ); - $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $emails = coauthors_emails( null, null, null, null, false ); $this->assertEquals( $this->author1->user_email . ' and ' . $this->editor1->user_email, $emails ); - $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); - $this->assertEquals( 1, substr_count( $emails, $this->editor1->user_email ) ); $emails = coauthors_emails( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->user_email . '' . $this->editor1->user_email . '', $emails ); - $this->assertEquals( 1, substr_count( $emails, $this->author1->user_email ) ); - $this->assertEquals( 1, substr_count( $emails, $this->editor1->user_email ) ); $email = 'test@example.org'; $user_id = $this->factory->user->create( array( @@ -447,7 +420,6 @@ public function test_coauthors_emails() { $emails = coauthors_emails( null, null, null, null, false ); $this->assertEquals( $email, $emails ); - $this->assertEquals( 1, substr_count( $emails, $email ) ); // Restore global post from backup. $post = $post_backup; @@ -561,26 +533,20 @@ public function test_coauthors_ids() { $ids = coauthors_ids( null, null, null, null, false ); $this->assertEquals( $this->author1->ID, $ids ); - $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); $ids = coauthors_ids( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->ID . '', $ids ); - $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); $coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true ); $ids = coauthors_ids( null, null, null, null, false ); $this->assertEquals( $this->author1->ID . ' and ' . $this->editor1->ID, $ids ); - $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); - $this->assertEquals( 1, substr_count( $ids, $this->editor1->ID ) ); $ids = coauthors_ids( '', '', '', '', false ); $this->assertEquals( '' . $this->author1->ID . '' . $this->editor1->ID . '', $ids ); - $this->assertEquals( 1, substr_count( $ids, $this->author1->ID ) ); - $this->assertEquals( 1, substr_count( $ids, $this->editor1->ID ) ); // Restore global post from backup. $post = $post_backup; From 4bf67ecee8343169e40ee7cc1a4a12dcfe3e93e0 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 10:24:23 +0530 Subject: [PATCH 147/231] [#388] Unit tests for current_user_can_set_authors() method - Also fixed warning "Trying to get property of non-object" if post_type is not set in "get_current_screen()" on https://github.com/Automattic/Co-Authors-Plus/blob/master/co-authors-plus.php#L1014 --- co-authors-plus.php | 3 +- tests/test-coauthors-plus.php | 96 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 66a0602c..4a336047 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1011,7 +1011,8 @@ function current_user_can_set_authors( $post = null ) { $post = get_post(); if ( ! $post ) { // if user is on pages, you need to grab post type another way - $post_type = get_current_screen()->post_type; + $current_screen = get_current_screen(); + $post_type = ! empty( $current_screen->post_type ) ? $current_screen->post_type : ''; } else { $post_type = $post->post_type; diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 7c480741..6427a417 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -151,4 +151,100 @@ public function test_is_post_type_enabled() { // Restore global post from backup. $post = $post_backup; } + + /** + * Checks if the current user can set co-authors or not using current screen. + * + * @covers ::current_user_can_set_authors() + */ + public function test_current_user_can_set_authors_using_current_screen() { + + global $coauthors_plus; + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + } + + /** + * Checks if the current user can set co-authors or not using global post. + * + * @covers ::current_user_can_set_authors() + */ + public function test_current_user_can_set_authors_using_global_post() { + + global $coauthors_plus, $post; + + // Backing up global post. + $post_backup = $post; + + $post = $this->post; + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + // Backing up current user. + $current_user = get_current_user_id(); + + // Checks when current user is author. + wp_set_current_user( $this->author1->ID ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + // Checks when current user is editor. + wp_set_current_user( $this->editor1->ID ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors() ); + + // Checks when current user is super admin. + $admin1 = $this->factory->user->create_and_get( array( + 'role' => 'administrator', + ) ); + + grant_super_admin( $admin1->ID ); + wp_set_current_user( $admin1->ID ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore global post from backup. + $post = $post_backup; + } + + /** + * Checks if the current user can set co-authors or not using normal post. + * + * @covers ::current_user_can_set_authors() + */ + public function test_current_user_can_set_authors_using_normal_post() { + + global $coauthors_plus; + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + // Backing up current user. + $current_user = get_current_user_id(); + + // Checks when current user is author. + wp_set_current_user( $this->author1->ID ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + // Checks when current user is editor. + wp_set_current_user( $this->editor1->ID ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + // Checks when current user is super admin. + $admin1 = $this->factory->user->create_and_get( array( + 'role' => 'administrator', + ) ); + + grant_super_admin( $admin1->ID ); + wp_set_current_user( $admin1->ID ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + } } From f0e203d925d4b1da54a0ce48425f7b9d565694b2 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 12:18:16 +0530 Subject: [PATCH 148/231] [#388] Unit tests for search_authors() method --- tests/test-coauthors-plus.php | 153 ++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 6427a417..88032289 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -247,4 +247,157 @@ public function test_current_user_can_set_authors_using_normal_post() { // Restore current user from backup. wp_set_current_user( $current_user ); } + + /** + * Checks matching co-authors based on a search value when no arguments provided. + * + * @covers ::search_authors() + */ + public function test_search_authors_no_args() { + + global $coauthors_plus; + + // Checks when search term is empty. + $authors = $coauthors_plus->search_authors(); + + $this->assertNotEmpty( $authors ); + $this->assertArrayHasKey( 'admin', $authors ); + $this->assertArrayHasKey( $this->author1->user_login, $authors ); + $this->assertArrayHasKey( $this->editor1->user_login, $authors ); + + // Checks when search term is empty and any subscriber exists. + $subscriber1 = $this->factory->user->create_and_get( array( + 'role' => 'subscriber', + ) ); + + $authors = $coauthors_plus->search_authors(); + + $this->assertNotEmpty( $authors ); + $this->assertNotContains( $subscriber1->user_login, $authors ); + + // Checks when search term is empty and any contributor exists. + $contributor1 = $this->factory->user->create_and_get( array( + 'role' => 'contributor', + ) ); + + $authors = $coauthors_plus->search_authors(); + + $this->assertNotEmpty( $authors ); + $this->assertArrayHasKey( $contributor1->user_login, $authors ); + } + + /** + * Checks matching co-authors based on a search value when only search keyword is provided. + * + * @covers ::search_authors() + */ + public function test_search_authors_when_search_keyword_provided() { + + global $coauthors_plus; + + // Checks when author does not exist with searched term. + $this->assertEmpty( $coauthors_plus->search_authors( 'test' ) ); + + // Checks when author searched using ID. + $authors = $coauthors_plus->search_authors( $this->author1->ID ); + + $this->assertNotEmpty( $authors ); + $this->assertArrayHasKey( $this->author1->user_login, $authors ); + $this->assertNotContains( $this->editor1->user_login, $authors ); + $this->assertNotContains( 'admin', $authors ); + + // Checks when author searched using display_name. + $authors = $coauthors_plus->search_authors( $this->author1->display_name ); + + $this->assertNotEmpty( $authors ); + $this->assertArrayHasKey( $this->author1->user_login, $authors ); + $this->assertNotContains( $this->editor1->user_login, $authors ); + $this->assertNotContains( 'admin', $authors ); + + // Checks when author searched using user_email. + $authors = $coauthors_plus->search_authors( $this->author1->user_email ); + + $this->assertNotEmpty( $authors ); + $this->assertArrayHasKey( $this->author1->user_login, $authors ); + $this->assertNotContains( $this->editor1->user_login, $authors ); + $this->assertNotContains( 'admin', $authors ); + + // Checks when author searched using user_login. + $authors = $coauthors_plus->search_authors( $this->author1->user_login ); + + $this->assertNotEmpty( $authors ); + $this->assertArrayHasKey( $this->author1->user_login, $authors ); + $this->assertNotContains( $this->editor1->user_login, $authors ); + $this->assertNotContains( 'admin', $authors ); + + // Checks when any subscriber exists using ID but not author. + $subscriber1 = $this->factory->user->create_and_get( array( + 'role' => 'subscriber', + ) ); + + $this->assertEmpty( $coauthors_plus->search_authors( $subscriber1->ID ) ); + } + + /** + * Checks matching co-authors based on a search value when only ignore authors are provided. + * + * @covers ::search_authors() + */ + public function test_search_authors_when_ignored_authors_provided() { + + global $coauthors_plus; + + // Ignoring single author. + $ignored_authors = array( $this->author1->user_login ); + + $authors = $coauthors_plus->search_authors( '', $ignored_authors ); + + $this->assertNotEmpty( $authors ); + $this->assertNotContains( $this->author1->user_login, $authors ); + + // Checks when ignoring author1 but also exists one more author with similar kind of data. + $author2 = $this->factory->user->create_and_get( array( + 'role' => 'author', + ) ); + + $authors = $coauthors_plus->search_authors( '', $ignored_authors ); + + $this->assertNotEmpty( $authors ); + $this->assertNotContains( $this->author1->user_login, $authors ); + $this->assertArrayHasKey( $author2->user_login, $authors ); + + // Ignoring multiple authors. + $authors = $coauthors_plus->search_authors( '', array( $this->author1->user_login, $author2->user_login ) ); + + $this->assertNotEmpty( $authors ); + $this->assertNotContains( $this->author1->user_login, $authors ); + $this->assertNotContains( $author2->user_login, $authors ); + } + + /** + * Checks matching co-authors based on a search value when search keyword as well as ignore authors are provided. + * + * @covers ::search_authors() + */ + public function test_search_authors_when_search_keyword_and_ignored_authors_provided() { + + global $coauthors_plus; + + // Checks when ignoring author1. + $ignored_authors = array( $this->author1->user_login ); + + $this->assertEmpty( $coauthors_plus->search_authors( $this->author1->ID, $ignored_authors ) ); + + // Checks when ignoring author1 but also exists one more author with similar kind of data. + $author2 = $this->factory->user->create_and_get( array( + 'role' => 'author', + 'user_login' => 'author2', + ) ); + + $authors = $coauthors_plus->search_authors( 'author', $ignored_authors ); + + $this->assertNotEmpty( $authors ); + $this->assertNotContains( $this->author1->user_login, $authors ); + $this->assertArrayHasKey( $author2->user_login, $authors ); + } } From 2aa752b86e39e0331cce5ad0b436d2e45526b10b Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 14:21:53 +0530 Subject: [PATCH 149/231] [#388] Unit tests for get_author_term() method --- tests/test-coauthors-plus.php | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 88032289..cededed1 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -400,4 +400,92 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov $this->assertNotContains( $this->author1->user_login, $authors ); $this->assertArrayHasKey( $author2->user_login, $authors ); } + + /** + * Checks the author term for a given co-author when passed coauthor is not an object. + * + * @covers ::get_author_term() + */ + public function test_get_author_term_when_coauthor_is_not_object() { + + global $coauthors_plus; + + $this->assertEmpty( $coauthors_plus->get_author_term( '' ) ); + $this->assertEmpty( $coauthors_plus->get_author_term( $this->author1->ID ) ); + $this->assertEmpty( $coauthors_plus->get_author_term( (array) $this->author1 ) ); + } + + /** + * Checks the author term for a given co-author using cache. + * + * @covers ::get_author_term() + */ + public function test_get_author_term_using_caching() { + + global $coauthors_plus; + + $cache_key = 'author-term-' . $this->author1->user_nicename; + + // Checks when term does not exist in cache. + $this->assertFalse( wp_cache_get( $cache_key, 'co-authors-plus' ) ); + + // Checks when term exists in cache. + $author_term = $coauthors_plus->get_author_term( $this->author1 ); + $author_term_cached = wp_cache_get( $cache_key, 'co-authors-plus' ); + + $this->assertInternalType( 'object', $author_term ); + $this->assertInstanceOf( WP_Term::class, $author_term ); + $this->assertEquals( $author_term, $author_term_cached ); + } + + /** + * Checks the author term for a given co-author with having linked account. + * + * @covers ::get_author_term() + */ + public function test_get_author_term_when_author_has_linked_account() { + + global $coauthors_plus; + + // Checks when term exists using linked account. + $coauthor_id = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1->ID ); + $coauthor = $coauthors_plus->get_coauthor_by( 'id', $coauthor_id ); + + $author_term = $coauthors_plus->get_author_term( $coauthor ); + + $this->assertInternalType( 'object', $author_term ); + $this->assertInstanceOf( WP_Term::class, $author_term ); + + // Checks when term does not exist or deleted somehow. + wp_delete_term( $author_term->term_id, $author_term->taxonomy ); + + $this->assertFalse( $coauthors_plus->get_author_term( $coauthor ) ); + } + + /** + * Checks the author term for a given co-author without having linked account. + * + * @covers ::get_author_term() + */ + public function test_get_author_term_when_author_has_not_linked_account() { + + global $coauthors_plus; + + // Checks when term exists without linked account. + $coauthor_id = $coauthors_plus->guest_authors->create( array( + 'display_name' => 'guest', + 'user_login' => 'guest', + ) ); + $coauthor = $coauthors_plus->get_coauthor_by( 'id', $coauthor_id ); + + $author_term = $coauthors_plus->get_author_term( $coauthor ); + + $this->assertInternalType( 'object', $author_term ); + $this->assertInstanceOf( WP_Term::class, $author_term ); + + // Checks when term does not exist or deleted somehow. + wp_delete_term( $author_term->term_id, $author_term->taxonomy ); + + $this->assertFalse( $coauthors_plus->get_author_term( $coauthor ) ); + } } From a104f77a1ed335ff714d7eb4b7565fd4a83345af Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 15:27:04 +0530 Subject: [PATCH 150/231] [#388] Unit tests for update_author_term() method --- tests/test-coauthors-plus.php | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index cededed1..0304680d 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -488,4 +488,100 @@ public function test_get_author_term_when_author_has_not_linked_account() { $this->assertFalse( $coauthors_plus->get_author_term( $coauthor ) ); } + + /** + * Checks update author term when passed coauthor is not an object. + * + * @covers ::update_author_term() + */ + public function test_update_author_term_when_coauthor_is_not_object() { + + global $coauthors_plus; + + $this->assertEmpty( $coauthors_plus->update_author_term( '' ) ); + $this->assertEmpty( $coauthors_plus->update_author_term( $this->author1->ID ) ); + $this->assertEmpty( $coauthors_plus->update_author_term( (array) $this->author1 ) ); + } + + /** + * Checks update author term when author term exists for passed coauthor. + * + * @covers ::update_author_term() + */ + public function test_update_author_term_when_author_term_exists() { + + global $coauthors_plus; + + // Checks term description. + $author_term = $coauthors_plus->update_author_term( $this->author1 ); + + $this->assertEquals( $this->author1->display_name . ' ' . $this->author1->first_name . ' ' . $this->author1->last_name . ' ' . $this->author1->user_login . ' ' . $this->author1->ID . ' ' . $this->author1->user_email, $author_term->description ); + + // Checks term description after updating user. + wp_update_user( array( + 'ID' => $this->author1->ID, + 'first_name' => 'author1', + ) ); + + $author_term = $coauthors_plus->update_author_term( $this->author1 ); + + $this->assertEquals( $this->author1->display_name . ' ' . $this->author1->first_name . ' ' . $this->author1->last_name . ' ' . $this->author1->user_login . ' ' . $this->author1->ID . ' ' . $this->author1->user_email, $author_term->description ); + + // Backup coauthor taxonomy. + $taxonomy_backup = $coauthors_plus->coauthor_taxonomy; + + wp_update_user( array( + 'ID' => $this->author1->ID, + 'last_name' => 'author1', + ) ); + + // Checks with different taxonomy. + $coauthors_plus->coauthor_taxonomy = 'abcd'; + + $this->assertFalse( $coauthors_plus->update_author_term( $this->author1 ) ); + + // Restore coauthor taxonomy from backup. + $coauthors_plus->coauthor_taxonomy = $taxonomy_backup; + } + + /** + * Checks update author term when author term does not exist for passed coauthor. + * + * @covers ::update_author_term() + */ + public function test_update_author_term_when_author_term_not_exist() { + + global $coauthors_plus; + + // Checks term description. + $author_term = $coauthors_plus->update_author_term( $this->editor1 ); + + $this->assertEquals( $this->editor1->display_name . ' ' . $this->editor1->first_name . ' ' . $this->editor1->last_name . ' ' . $this->editor1->user_login . ' ' . $this->editor1->ID . ' ' . $this->editor1->user_email, $author_term->description ); + + // Checks term description after updating user. + wp_update_user( array( + 'ID' => $this->editor1->ID, + 'first_name' => 'editor1', + ) ); + + $author_term = $coauthors_plus->update_author_term( $this->editor1 ); + + $this->assertEquals( $this->editor1->display_name . ' ' . $this->editor1->first_name . ' ' . $this->editor1->last_name . ' ' . $this->editor1->user_login . ' ' . $this->editor1->ID . ' ' . $this->editor1->user_email, $author_term->description ); + + // Backup coauthor taxonomy. + $taxonomy_backup = $coauthors_plus->coauthor_taxonomy; + + wp_update_user( array( + 'ID' => $this->editor1->ID, + 'last_name' => 'editor1', + ) ); + + // Checks with different taxonomy. + $coauthors_plus->coauthor_taxonomy = 'abcd'; + + $this->assertFalse( $coauthors_plus->update_author_term( $this->editor1 ) ); + + // Restore coauthor taxonomy from backup. + $coauthors_plus->coauthor_taxonomy = $taxonomy_backup; + } } From 4c9675c8e9c329f7a2cb1954ceb0797920025f93 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 16:57:09 +0530 Subject: [PATCH 151/231] [#388] Unit tests for get_guest_author_by() method --- tests/test-coauthors-guest-authors.php | 103 +++++++++++++++++++++++++ tests/test-coauthors-plus.php | 36 ++++----- 2 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 tests/test-coauthors-guest-authors.php diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php new file mode 100644 index 00000000..fffddb1f --- /dev/null +++ b/tests/test-coauthors-guest-authors.php @@ -0,0 +1,103 @@ +author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); + + $this->post = $this->factory->post->create_and_get( array( + 'post_author' => $this->author1->ID, + 'post_status' => 'publish', + 'post_content' => rand_str(), + 'post_title' => rand_str(), + 'post_type' => 'post', + ) ); + } + + /** + * Checks a simulated WP_User object based on the post ID when key or value is empty. + * + * @covers CoAuthors_Guest_Authors::get_guest_author_by() + */ + public function test_get_guest_author_by_with_empty_key_or_value() { + + global $coauthors_plus; + + // Fetch guest author without forcefully. + $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', '' ) ); + $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( 'ID', '' ) ); + $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', $this->author1->ID ) ); + + // Fetch guest author forcefully. + $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', '', true ) ); + $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( 'ID', '', true ) ); + $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', $this->author1->ID, true ) ); + } + + /** + * Checks a simulated WP_User object based on the post ID using cache. + * + * @covers CoAuthors_Guest_Authors::get_guest_author_by() + */ + public function test_get_guest_author_by_using_cache() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + + $cache_key = $guest_author_obj->get_cache_key( 'ID', $guest_author_id ); + + // Checks when guest author does not exist in cache. + $this->assertFalse( wp_cache_get( $cache_key, $guest_author_obj::$cache_group ) ); + + // Checks when guest author exists in cache. + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + $guest_author_cached = wp_cache_get( $cache_key, $guest_author_obj::$cache_group ); + + $this->assertInternalType( 'object', $guest_author ); + $this->assertEquals( $guest_author, $guest_author_cached ); + } + + /** + * Checks a simulated WP_User object based on the post ID using different key/value. + * + * @covers CoAuthors_Guest_Authors::get_guest_author_by() + */ + public function test_get_guest_author_by_with_different_keys() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Checks when user is not a guest author. + $this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', $this->author1->ID ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', $this->author1->ID, true ) ); + + // Checks guest author using ID. + $guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + + $this->assertInternalType( 'object', $guest_author ); + $this->assertEquals( $guest_author_id, $guest_author->ID ); + $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); + + // Checks guest author using user_nicename. + $guest_author = $guest_author_obj->get_guest_author_by( 'user_nicename', $this->editor1->user_nicename ); + + $this->assertInternalType( 'object', $guest_author ); + $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); + + // Checks guest author using linked_account. + $guest_author = $guest_author_obj->get_guest_author_by( 'linked_account', $this->editor1->user_login ); + + $this->assertInternalType( 'object', $guest_author ); + $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); + } +} diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 0304680d..beb755b5 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -21,7 +21,7 @@ public function setUp() { /** * Checks whether the guest authors functionality is enabled or not. * - * @covers ::is_guest_authors_enabled() + * @covers CoAuthors_Plus::is_guest_authors_enabled() */ public function test_is_guest_authors_enabled() { @@ -37,7 +37,7 @@ public function test_is_guest_authors_enabled() { /** * Checks coauthor object when he/she is a guest author. * - * @covers ::get_coauthor_by() + * @covers CoAuthors_Plus::get_coauthor_by() */ public function test_get_coauthor_by_when_guest_author() { @@ -60,7 +60,7 @@ public function test_get_coauthor_by_when_guest_author() { /** * Checks coauthor object when he/she is a wp author. * - * @covers ::get_coauthor_by() + * @covers CoAuthors_Plus::get_coauthor_by() */ public function test_get_coauthor_by_when_wp_user() { @@ -110,7 +110,7 @@ public function test_get_coauthor_by_when_wp_user() { /** * Checks coauthors plus is enabled for this post type. * - * @covers ::is_post_type_enabled() + * @covers CoAuthors_Plus::is_post_type_enabled() */ public function test_is_post_type_enabled() { @@ -155,7 +155,7 @@ public function test_is_post_type_enabled() { /** * Checks if the current user can set co-authors or not using current screen. * - * @covers ::current_user_can_set_authors() + * @covers CoAuthors_Plus::current_user_can_set_authors() */ public function test_current_user_can_set_authors_using_current_screen() { @@ -167,7 +167,7 @@ public function test_current_user_can_set_authors_using_current_screen() { /** * Checks if the current user can set co-authors or not using global post. * - * @covers ::current_user_can_set_authors() + * @covers CoAuthors_Plus::current_user_can_set_authors() */ public function test_current_user_can_set_authors_using_global_post() { @@ -213,7 +213,7 @@ public function test_current_user_can_set_authors_using_global_post() { /** * Checks if the current user can set co-authors or not using normal post. * - * @covers ::current_user_can_set_authors() + * @covers CoAuthors_Plus::current_user_can_set_authors() */ public function test_current_user_can_set_authors_using_normal_post() { @@ -251,7 +251,7 @@ public function test_current_user_can_set_authors_using_normal_post() { /** * Checks matching co-authors based on a search value when no arguments provided. * - * @covers ::search_authors() + * @covers CoAuthors_Plus::search_authors() */ public function test_search_authors_no_args() { @@ -289,7 +289,7 @@ public function test_search_authors_no_args() { /** * Checks matching co-authors based on a search value when only search keyword is provided. * - * @covers ::search_authors() + * @covers CoAuthors_Plus::search_authors() */ public function test_search_authors_when_search_keyword_provided() { @@ -341,7 +341,7 @@ public function test_search_authors_when_search_keyword_provided() { /** * Checks matching co-authors based on a search value when only ignore authors are provided. * - * @covers ::search_authors() + * @covers CoAuthors_Plus::search_authors() */ public function test_search_authors_when_ignored_authors_provided() { @@ -377,7 +377,7 @@ public function test_search_authors_when_ignored_authors_provided() { /** * Checks matching co-authors based on a search value when search keyword as well as ignore authors are provided. * - * @covers ::search_authors() + * @covers CoAuthors_Plus::search_authors() */ public function test_search_authors_when_search_keyword_and_ignored_authors_provided() { @@ -404,7 +404,7 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov /** * Checks the author term for a given co-author when passed coauthor is not an object. * - * @covers ::get_author_term() + * @covers CoAuthors_Plus::get_author_term() */ public function test_get_author_term_when_coauthor_is_not_object() { @@ -418,7 +418,7 @@ public function test_get_author_term_when_coauthor_is_not_object() { /** * Checks the author term for a given co-author using cache. * - * @covers ::get_author_term() + * @covers CoAuthors_Plus::get_author_term() */ public function test_get_author_term_using_caching() { @@ -441,7 +441,7 @@ public function test_get_author_term_using_caching() { /** * Checks the author term for a given co-author with having linked account. * - * @covers ::get_author_term() + * @covers CoAuthors_Plus::get_author_term() */ public function test_get_author_term_when_author_has_linked_account() { @@ -465,7 +465,7 @@ public function test_get_author_term_when_author_has_linked_account() { /** * Checks the author term for a given co-author without having linked account. * - * @covers ::get_author_term() + * @covers CoAuthors_Plus::get_author_term() */ public function test_get_author_term_when_author_has_not_linked_account() { @@ -492,7 +492,7 @@ public function test_get_author_term_when_author_has_not_linked_account() { /** * Checks update author term when passed coauthor is not an object. * - * @covers ::update_author_term() + * @covers CoAuthors_Plus::update_author_term() */ public function test_update_author_term_when_coauthor_is_not_object() { @@ -506,7 +506,7 @@ public function test_update_author_term_when_coauthor_is_not_object() { /** * Checks update author term when author term exists for passed coauthor. * - * @covers ::update_author_term() + * @covers CoAuthors_Plus::update_author_term() */ public function test_update_author_term_when_author_term_exists() { @@ -547,7 +547,7 @@ public function test_update_author_term_when_author_term_exists() { /** * Checks update author term when author term does not exist for passed coauthor. * - * @covers ::update_author_term() + * @covers CoAuthors_Plus::update_author_term() */ public function test_update_author_term_when_author_term_not_exist() { From 5b73757a3a1cf83b36e305830d20bf57eb6b13e2 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 19:17:09 +0530 Subject: [PATCH 152/231] [#388] Unit tests for get_guest_author_thumbnail() method --- tests/test-coauthors-guest-authors.php | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index fffddb1f..c2f865bf 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -100,4 +100,42 @@ public function test_get_guest_author_by_with_different_keys() { $this->assertInternalType( 'object', $guest_author ); $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); } + + /** + * Checks thumbnail for a guest author object. + * + * @covers CoAuthors_Guest_Authors::get_guest_author_thumbnail() + */ + public function test_get_guest_author_thumbnail() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Checks when guest author does not have any thumbnail. + $guest_author_id = $guest_author_obj->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + + $this->assertNull( $guest_author_obj->get_guest_author_thumbnail( $guest_author, 0 ) ); + + // Checks when guest author has thumbnail. + $filename = rand_str() . '.jpg'; + $contents = rand_str(); + $upload = wp_upload_bits( $filename, null, $contents ); + + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + set_post_thumbnail( $guest_author->ID, $attachment_id ); + + $thumbnail = $guest_author_obj->get_guest_author_thumbnail( $guest_author, 0 ); + + $this->assertContains( 'avatar-0', $thumbnail ); + $this->assertContains( $filename, $thumbnail ); + $this->assertContains( 'src="' . wp_get_attachment_url( $attachment_id ) . '"', $thumbnail ); + } } From 513d3e053804b46ade628be3468f8c439f73be78 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 21:46:49 +0530 Subject: [PATCH 153/231] [#388] Unit tests for get_guest_author_fields() method --- tests/test-coauthors-guest-authors.php | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index c2f865bf..3c474aad 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -138,4 +138,69 @@ public function test_get_guest_author_thumbnail() { $this->assertContains( $filename, $thumbnail ); $this->assertContains( 'src="' . wp_get_attachment_url( $attachment_id ) . '"', $thumbnail ); } + + /** + * Checks all of the meta fields that can be associated with a guest author. + * + * @covers CoAuthors_Guest_Authors::get_guest_author_fields() + */ + public function test_get_guest_author_fields() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Checks all the meta fields. + $fields = $guest_author_obj->get_guest_author_fields(); + + $this->assertNotEmpty( $fields ); + $this->assertInternalType( 'array', $fields ); + + $keys = wp_list_pluck( $fields, 'key' ); + + $global_fields = array( + 'display_name', + 'first_name', + 'last_name', + 'user_login', + 'user_email', + 'linked_account', + 'website', + 'aim', + 'yahooim', + 'jabber', + 'description' + ); + + $this->assertEquals( $global_fields, $keys ); + + // Checks all the meta fields with group that does not exist. + $fields = $guest_author_obj->get_guest_author_fields( 'test' ); + + $this->assertEmpty( $fields ); + + // Checks all the meta fields with group "name". + $fields = $guest_author_obj->get_guest_author_fields( 'name' ); + $keys = wp_list_pluck( $fields, 'key' ); + + $this->assertEquals( array( 'display_name', 'first_name', 'last_name' ), $keys ); + + // Checks all the meta fields with group "slug". + $fields = $guest_author_obj->get_guest_author_fields( 'slug' ); + $keys = wp_list_pluck( $fields, 'key' ); + + $this->assertEquals( array( 'user_login', 'linked_account' ), $keys ); + + // Checks all the meta fields with group "contact-info". + $fields = $guest_author_obj->get_guest_author_fields( 'contact-info' ); + $keys = wp_list_pluck( $fields, 'key' ); + + $this->assertEquals( array( 'user_email', 'website', 'aim', 'yahooim', 'jabber' ), $keys ); + + // Checks all the meta fields with group "about". + $fields = $guest_author_obj->get_guest_author_fields( 'about' ); + $keys = wp_list_pluck( $fields, 'key' ); + + $this->assertEquals( array( 'description' ), $keys ); + } } From 900daabbddbea6693b4a9f5db46496935dc38a49 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 28 Dec 2017 22:33:00 +0530 Subject: [PATCH 154/231] [#388] Unit tests for get_all_linked_accounts() method --- tests/test-coauthors-guest-authors.php | 61 +++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index 3c474aad..7cd6d427 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -169,7 +169,7 @@ public function test_get_guest_author_fields() { 'aim', 'yahooim', 'jabber', - 'description' + 'description', ); $this->assertEquals( $global_fields, $keys ); @@ -181,7 +181,7 @@ public function test_get_guest_author_fields() { // Checks all the meta fields with group "name". $fields = $guest_author_obj->get_guest_author_fields( 'name' ); - $keys = wp_list_pluck( $fields, 'key' ); + $keys = wp_list_pluck( $fields, 'key' ); $this->assertEquals( array( 'display_name', 'first_name', 'last_name' ), $keys ); @@ -203,4 +203,61 @@ public function test_get_guest_author_fields() { $this->assertEquals( array( 'description' ), $keys ); } + + /** + * Checks all of the user accounts that have been linked. + * + * @covers CoAuthors_Guest_Authors::get_all_linked_accounts() + */ + public function test_get_all_linked_accounts() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $this->assertEmpty( $guest_author_obj->get_all_linked_accounts() ); + + // Checks when guest author ( not linked account ) exists. + $guest_author_obj->create( array( + 'user_login' => 'author2', + 'display_name' => 'author2', + ) ); + + $this->assertEmpty( $guest_author_obj->get_all_linked_accounts() ); + + // Create guest author from existing user and check. + $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + + $linked_accounts = $guest_author_obj->get_all_linked_accounts(); + $linked_account_ids = wp_list_pluck( $linked_accounts, 'ID' ); + + $this->assertNotEmpty( $linked_accounts ); + $this->assertInternalType( 'array', $linked_accounts ); + $this->assertTrue( in_array( $this->editor1->ID, $linked_account_ids, true ) ); + } + + /** + * Checks all of the user accounts that have been linked using cache. + * + * @covers CoAuthors_Guest_Authors::get_all_linked_accounts() + */ + public function test_get_all_linked_accounts_with_cache() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $cache_key = 'all-linked-accounts'; + + // Checks when guest author does not exist in cache. + $this->assertFalse( wp_cache_get( $cache_key, $guest_author_obj::$cache_group ) ); + + // Checks when guest author exists in cache. + $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + + $linked_accounts = $guest_author_obj->get_all_linked_accounts(); + $linked_accounts_cache = wp_cache_get( $cache_key, $guest_author_obj::$cache_group ); + + $this->assertEquals( $linked_accounts, $linked_accounts_cache ); + } } From ea5521664d92d9a5bd68ce11d972883e79576a5d Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 29 Dec 2017 10:20:21 +0530 Subject: [PATCH 155/231] [#388] Unit tests for create_guest_author_from_user_id() method --- tests/test-coauthors-guest-authors.php | 38 ++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index 7cd6d427..997432a8 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -27,15 +27,17 @@ public function test_get_guest_author_by_with_empty_key_or_value() { global $coauthors_plus; + $guest_author_obj = $coauthors_plus->guest_authors; + // Fetch guest author without forcefully. - $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', '' ) ); - $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( 'ID', '' ) ); - $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', $this->author1->ID ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( '', '' ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', '' ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( '', $this->author1->ID ) ); // Fetch guest author forcefully. - $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', '', true ) ); - $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( 'ID', '', true ) ); - $this->assertFalse( $coauthors_plus->guest_authors->get_guest_author_by( '', $this->author1->ID, true ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( '', '', true ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', '', true ) ); + $this->assertFalse( $guest_author_obj->get_guest_author_by( '', $this->author1->ID, true ) ); } /** @@ -260,4 +262,28 @@ public function test_get_all_linked_accounts_with_cache() { $this->assertEquals( $linked_accounts, $linked_accounts_cache ); } + + /** + * Checks guest author from an existing WordPress user. + * + * @covers CoAuthors_Guest_Authors::create_guest_author_from_user_id() + */ + public function test_create_guest_author_from_user_id() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Checks create guest author when user don't exist. + $response = $guest_author_obj->create_guest_author_from_user_id( 0 ); + + $this->assertInstanceOf( 'WP_Error', $response ); + $this->assertEquals( 'invalid-user', $response->get_error_code() ); + + // Checks create guest author when user exist. + $guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + + $this->assertInstanceOf( stdClass::class, $guest_author ); + } } From 341b36c24feea3efa9ff530b135b1ea22d0f9f37 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 29 Dec 2017 13:03:36 +0530 Subject: [PATCH 156/231] [#388] Unit tests for handle_delete_guest_author_action() method --- tests/test-coauthors-guest-authors.php | 385 +++++++++++++++++++++++++ 1 file changed, 385 insertions(+) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index 997432a8..3efc4fdc 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -6,6 +6,7 @@ public function setUp() { parent::setUp(); + $this->admin1 = $this->factory->user->create_and_get( array( 'role' => 'administrator', 'user_login' => 'admin1' ) ); $this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); @@ -286,4 +287,388 @@ public function test_create_guest_author_from_user_id() { $this->assertInstanceOf( stdClass::class, $guest_author ); } + + /** + * Checks delete guest author action when $_POST args are not set. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_when_post_args_not_as_expected() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Checks when nothing is set. + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Back up $_POST. + $_post_backup = $_POST; + + // Checks when action is set but not expected. + $_POST['action'] = 'test'; + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Checks when _wpnonce and id not set. + $_POST['action'] = 'delete-guest-author'; + $_POST['reassign'] = 'test'; + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Checks when id not set. + $_POST['action'] = 'delete-guest-author'; + $_POST['reassign'] = 'test'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' ); + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Checks when all args set for $_POST but action is not as expected. + $_POST['action'] = 'test'; + $_POST['reassign'] = 'test'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' ); + $_POST['id'] = '0'; + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action with nonce. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_nonce() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + $expected = __( "Doin' something fishy, huh?", 'co-authors-plus' ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['reassign'] = 'test'; + $_POST['id'] = '0'; + + // Checks when nonce is not as expected. + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' ); + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertInstanceOf( 'WPDieException', $exception ); + $this->assertContains( esc_html( $expected ), $exception->getMessage() ); + + // Checks when nonce is as expected. + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertNotContains( esc_html( $expected ), $exception->getMessage() ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action with list_author capability. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_list_users_capability() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + $expected = __( "You don't have permission to perform this action.", 'co-authors-plus' ); + + // Back up current user. + $current_user = get_current_user_id(); + + wp_set_current_user( $this->editor1->ID ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['reassign'] = 'test'; + + // Checks when current user can not have list_users capability. + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertInstanceOf( 'WPDieException', $exception ); + $this->assertContains( esc_html( $expected ), $exception->getMessage() ); + + // Checks when current user has list_users capability. + wp_set_current_user( $this->admin1->ID ); + + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertNotContains( esc_html( $expected ), $exception->getMessage() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action with guest author. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_guest_author_existence() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + $expected = sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $guest_author_obj->labels['singular'] ); + + // Back up current user. + $current_user = get_current_user_id(); + + wp_set_current_user( $this->admin1->ID ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['reassign'] = 'test'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $this->admin1->ID; + + // Checks when guest author does not exist. + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertInstanceOf( 'WPDieException', $exception ); + $this->assertContains( esc_html( $expected ), $exception->getMessage() ); + + // Checks when guest author exists. + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertNotContains( esc_html( $expected ), $exception->getMessage() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action with reassign not as expected. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_reassign_not_as_expected() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + $expected = __( 'Please make sure to pick an option.', 'co-authors-plus' ); + + // Back up current user. + $current_user = get_current_user_id(); + + wp_set_current_user( $this->admin1->ID ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + + // Checks when reassign is not as expected. + $_POST['reassign'] = 'test'; + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertInstanceOf( 'WPDieException', $exception ); + $this->assertContains( esc_html( $expected ), $exception->getMessage() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action when reassign is leave-assigned. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_reassign_is_leave_assigned() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + // Back up current user. + $current_user = get_current_user_id(); + + wp_set_current_user( $this->admin1->ID ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + $_POST['reassign'] = 'leave-assigned'; + + $redirect_to = add_query_arg( array_map( 'rawurlencode', array( + 'page' => 'view-guest-authors', + ) ), admin_url( $guest_author_obj->parent_page ) ); + + $this->go_to( $redirect_to ); + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action when reassign is reassign-another. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_reassign_is_reassign_another() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + // Back up current user. + $current_user = get_current_user_id(); + + $expected = __( 'Co-author does not exists. Try again?', 'co-authors-plus' ); + + wp_set_current_user( $this->admin1->ID ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + $_POST['reassign'] = 'reassign-another'; + + // When coauthor does not exist. + $_POST['leave-assigned-to'] = 'test'; + + try { + $guest_author_obj->handle_delete_guest_author_action(); + } catch ( Exception $e ) { + $exception = $e; + } + + $this->assertInstanceOf( 'WPDieException', $exception ); + $this->assertContains( esc_html( $expected ), $exception->getMessage() ); + + // When coauthor exists. + $_POST['leave-assigned-to'] = $this->author1->user_nicename; + + $redirect_to = add_query_arg( array_map( 'rawurlencode', array( + 'page' => 'view-guest-authors', + ) ), admin_url( $guest_author_obj->parent_page ) ); + + $this->go_to( $redirect_to ); + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } + + /** + * Checks delete guest author action when reassign is remove-byline. + * + * @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action() + */ + public function test_handle_delete_guest_author_action_with_reassign_is_remove_byline() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Back up $_POST. + $_post_backup = $_POST; + + // Back up current user. + $current_user = get_current_user_id(); + + wp_set_current_user( $this->admin1->ID ); + + $_POST['action'] = 'delete-guest-author'; + $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' ); + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + $_POST['reassign'] = 'remove-byline'; + + $redirect_to = add_query_arg( array_map( 'rawurlencode', array( + 'page' => 'view-guest-authors', + ) ), admin_url( $guest_author_obj->parent_page ) ); + + $this->go_to( $redirect_to ); + + $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + + // Restore $_POST from back up. + $_POST = $_post_backup; + } } From 6b394d21e769232cdc9ee4d3cea22b1775c99a4d Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 29 Dec 2017 15:07:17 +0530 Subject: [PATCH 157/231] [#388] Unit tests for CoAuthors_Guest_Authors::delete() method --- tests/test-coauthors-guest-authors.php | 163 +++++++++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index 3efc4fdc..948ed9eb 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -671,4 +671,167 @@ public function test_handle_delete_guest_author_action_with_reassign_is_remove_b // Restore $_POST from back up. $_POST = $_post_backup; } + + /** + * Checks delete guest author when he/she does not exist. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_when_guest_author_not_exist() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $response = $guest_author_obj->delete( $this->admin1->ID ); + + $this->assertInstanceOf( 'WP_Error', $response ); + $this->assertEquals( 'guest-author-missing', $response->get_error_code() ); + } + + /** + * Checks delete guest author without reassign author. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_without_reassign() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $author2 = $this->factory->user->create_and_get(); + $guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $author2->ID ); + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + $guest_author_term = $coauthors_plus->get_author_term( $guest_author ); + + $response = $guest_author_obj->delete( $guest_author_id ); + + $this->assertTrue( $response ); + $this->assertFalse( get_term_by( 'id', $guest_author_term->term_id, $coauthors_plus->coauthor_taxonomy ) ); + $this->assertNull( get_post( $guest_author_id ) ); + } + + /** + * Checks delete guest author with reassign author but he/she does not exist. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_with_reassign_author_not_exist() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + // Checks when reassign author is not exist. + $author2 = $this->factory->user->create_and_get(); + $guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $author2->ID ); + + $response = $guest_author_obj->delete( $guest_author_id, 'test' ); + + $this->assertInstanceOf( 'WP_Error', $response ); + $this->assertEquals( 'reassign-to-missing', $response->get_error_code() ); + } + + /** + * Checks delete guest author with reassign author and linked account and author is the same user. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_with_reassign_with_linked_account_and_author_is_same_user() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $author2 = $this->factory->user->create_and_get(); + $guest_author2_id = $guest_author_obj->create_guest_author_from_user_id( $author2->ID ); + $guest_author2 = $guest_author_obj->get_guest_author_by( 'ID', $guest_author2_id ); + $guest_author2_term = $coauthors_plus->get_author_term( $guest_author2 ); + + $response = $guest_author_obj->delete( $guest_author2_id, $guest_author2->linked_account ); + + $this->assertTrue( $response ); + $this->assertNotEmpty( get_term_by( 'id', $guest_author2_term->term_id, $coauthors_plus->coauthor_taxonomy ) ); + $this->assertNull( get_post( $guest_author2_id ) ); + } + + /** + * Checks delete guest author with reassign author and linked account and author is other user. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_with_reassign_with_linked_account_and_author_is_other_user() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $guest_admin_id = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + $guest_admin = $guest_author_obj->get_guest_author_by( 'ID', $guest_admin_id ); + + $author2 = $this->factory->user->create_and_get(); + $guest_author_id2 = $guest_author_obj->create_guest_author_from_user_id( $author2->ID ); + $guest_author2 = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id2 ); + $guest_author_term2 = $coauthors_plus->get_author_term( $guest_author2 ); + + $response = $guest_author_obj->delete( $guest_author_id2, $guest_admin->linked_account ); + + $this->assertTrue( $response ); + $this->assertFalse( get_term_by( 'id', $guest_author_term2->term_id, $coauthors_plus->coauthor_taxonomy ) ); + $this->assertNull( get_post( $guest_author_id2 ) ); + } + + /** + * Checks delete guest author with reassign author and without linked account and author is the same user. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_with_reassign_without_linked_account_and_author_is_same_user() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $guest_author_id = $guest_author_obj->create( array( + 'user_login' => 'guest_author', + 'display_name' => 'guest_author', + ) ); + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + $guest_author_term = $coauthors_plus->get_author_term( $guest_author ); + + $response = $guest_author_obj->delete( $guest_author_id, $guest_author->user_login ); + + $this->assertTrue( $response ); + $this->assertNotEmpty( get_term_by( 'id', $guest_author_term->term_id, $coauthors_plus->coauthor_taxonomy ) ); + $this->assertNull( get_post( $guest_author_id ) ); + } + + /** + * Checks delete guest author with reassign author and without linked account and author is other user. + * + * @covers CoAuthors_Guest_Authors::delete() + */ + public function test_delete_with_reassign_without_linked_account_and_author_is_other_user() { + + global $coauthors_plus; + + $guest_author_obj = $coauthors_plus->guest_authors; + + $guest_admin_id = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); + $guest_admin = $guest_author_obj->get_guest_author_by( 'ID', $guest_admin_id ); + + $guest_author_id = $guest_author_obj->create( array( + 'user_login' => 'guest_author', + 'display_name' => 'guest_author', + ) ); + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); + $guest_author_term = $coauthors_plus->get_author_term( $guest_author ); + + $response = $guest_author_obj->delete( $guest_author_id, $guest_admin->user_login ); + + $this->assertTrue( $response ); + $this->assertFalse( get_term_by( 'id', $guest_author_term->term_id, $coauthors_plus->coauthor_taxonomy ) ); + $this->assertNull( get_post( $guest_author_id ) ); + } } From c796f08c34a8cda1df09ef9733cb2a904c17289e Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 29 Dec 2017 16:14:07 +0530 Subject: [PATCH 158/231] [#388] Unit tests for coauthors orders --- tests/test-template-tags.php | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/test-template-tags.php diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php new file mode 100644 index 00000000..95b430ec --- /dev/null +++ b/tests/test-template-tags.php @@ -0,0 +1,45 @@ +author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); + $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); + } + + /** + * Checks coauthors order. + * + * @covers ::get_coauthors() + */ + public function test_coauthors_order() { + + global $coauthors_plus; + + $post_id = $this->factory->post->create(); + + // Checks when no author exist. + $this->assertEmpty( get_coauthors( $post_id ) ); + + // Checks coauthors order. + $coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true ); + $coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true ); + + $expected = array( $this->author1->user_login, $this->editor1->user_login ); + + $this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) ); + + // Checks coauthors order after modifying. + $post_id = $this->factory->post->create(); + + $coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true ); + + $expected = array( $this->editor1->user_login, $this->author1->user_login ); + + $this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) ); + } +} From ef1a6db12060bba697f950a7cd426ffdceb220da Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 1 Jan 2018 19:34:03 +0530 Subject: [PATCH 159/231] [#388] Improve unit tests --- co-authors-plus.php | 2 +- tests/test-coauthors-guest-authors.php | 44 ++++++---- tests/test-coauthors-plus.php | 113 ++++++++++++++++++++++--- 3 files changed, 133 insertions(+), 26 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 4a336047..3bb99eca 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1012,7 +1012,7 @@ function current_user_can_set_authors( $post = null ) { if ( ! $post ) { // if user is on pages, you need to grab post type another way $current_screen = get_current_screen(); - $post_type = ! empty( $current_screen->post_type ) ? $current_screen->post_type : ''; + $post_type = ( ! empty( $current_screen->post_type ) ) ? $current_screen->post_type : ''; } else { $post_type = $post->post_type; diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index 948ed9eb..ef242387 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -63,7 +63,7 @@ public function test_get_guest_author_by_using_cache() { $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); $guest_author_cached = wp_cache_get( $cache_key, $guest_author_obj::$cache_group ); - $this->assertInternalType( 'object', $guest_author ); + $this->assertInstanceOf( stdClass::class, $guest_author ); $this->assertEquals( $guest_author, $guest_author_cached ); } @@ -82,25 +82,25 @@ public function test_get_guest_author_by_with_different_keys() { $this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', $this->author1->ID ) ); $this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', $this->author1->ID, true ) ); - // Checks guest author using ID. $guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); + // Checks guest author using ID. $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id ); - $this->assertInternalType( 'object', $guest_author ); + $this->assertInstanceOf( stdClass::class, $guest_author ); $this->assertEquals( $guest_author_id, $guest_author->ID ); $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); // Checks guest author using user_nicename. $guest_author = $guest_author_obj->get_guest_author_by( 'user_nicename', $this->editor1->user_nicename ); - $this->assertInternalType( 'object', $guest_author ); + $this->assertInstanceOf( stdClass::class, $guest_author ); $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); // Checks guest author using linked_account. $guest_author = $guest_author_obj->get_guest_author_by( 'linked_account', $this->editor1->user_login ); - $this->assertInternalType( 'object', $guest_author ); + $this->assertInstanceOf( stdClass::class, $guest_author ); $this->assertEquals( $guest_author_obj->post_type, $guest_author->type ); } @@ -307,30 +307,38 @@ public function test_handle_delete_guest_author_action_when_post_args_not_as_exp // Checks when action is set but not expected. $_POST['action'] = 'test'; + $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID ); $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + // Get guest author and check that is should not be removed. + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $_POST['id'] ); + + $this->assertNotEmpty( $guest_author ); + // Checks when _wpnonce and id not set. $_POST['action'] = 'delete-guest-author'; $_POST['reassign'] = 'test'; $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); - // Checks when id not set. - $_POST['action'] = 'delete-guest-author'; - $_POST['reassign'] = 'test'; - $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' ); + // Get guest author and check that is should not be removed. + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $_POST['id'] ); - $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + $this->assertNotEmpty( $guest_author ); // Checks when all args set for $_POST but action is not as expected. $_POST['action'] = 'test'; $_POST['reassign'] = 'test'; $_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' ); - $_POST['id'] = '0'; $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + // Get guest author and check that is should not be removed. + $guest_author = $guest_author_obj->get_guest_author_by( 'ID', $_POST['id'] ); + + $this->assertNotEmpty( $guest_author ); + // Restore $_POST from back up. $_POST = $_post_backup; } @@ -734,11 +742,11 @@ public function test_delete_with_reassign_author_not_exist() { } /** - * Checks delete guest author with reassign author and linked account and author is the same user. + * Checks delete guest author with reassign author when linked account and author are same user. * * @covers CoAuthors_Guest_Authors::delete() */ - public function test_delete_with_reassign_with_linked_account_and_author_is_same_user() { + public function test_delete_with_reassign_when_linked_account_and_author_are_same_user() { global $coauthors_plus; @@ -757,11 +765,11 @@ public function test_delete_with_reassign_with_linked_account_and_author_is_same } /** - * Checks delete guest author with reassign author and linked account and author is other user. + * Checks delete guest author with reassign author when linked account and author are different user. * * @covers CoAuthors_Guest_Authors::delete() */ - public function test_delete_with_reassign_with_linked_account_and_author_is_other_user() { + public function test_delete_with_reassign_when_linked_account_and_author_are_different_user() { global $coauthors_plus; @@ -775,8 +783,14 @@ public function test_delete_with_reassign_with_linked_account_and_author_is_othe $guest_author2 = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id2 ); $guest_author_term2 = $coauthors_plus->get_author_term( $guest_author2 ); + $post = $this->factory->post->create_and_get( array( + 'post_author' => $author2->ID, + ) ); + $response = $guest_author_obj->delete( $guest_author_id2, $guest_admin->linked_account ); + // Checks post author, it should be reassigned to new author. + $this->assertEquals( array( $guest_admin->linked_account ), wp_list_pluck( get_coauthors( $post->ID ), 'linked_account' ) ); $this->assertTrue( $response ); $this->assertFalse( get_term_by( 'id', $guest_author_term2->term_id, $coauthors_plus->coauthor_taxonomy ) ); $this->assertNull( get_post( $guest_author_id2 ) ); diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index beb755b5..7f205781 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -29,9 +29,13 @@ public function test_is_guest_authors_enabled() { $this->assertTrue( $coauthors_plus->is_guest_authors_enabled() ); - tests_add_filter( 'coauthors_guest_authors_enabled', '__return_false' ); + add_filter( 'coauthors_guest_authors_enabled', '__return_false' ); $this->assertFalse( $coauthors_plus->is_guest_authors_enabled() ); + + remove_filter( 'coauthors_guest_authors_enabled', '__return_false' ); + + $this->assertTrue( $coauthors_plus->is_guest_authors_enabled() ); } /** @@ -50,7 +54,6 @@ public function test_get_coauthor_by_when_guest_author() { $coauthor = $coauthors_plus->get_coauthor_by( 'id', $guest_author_id ); - $this->assertInternalType( 'object', $coauthor ); $this->assertInstanceOf( stdClass::class, $coauthor ); $this->assertObjectHasAttribute( 'ID', $coauthor ); $this->assertEquals( $guest_author_id, $coauthor->ID ); @@ -66,11 +69,13 @@ public function test_get_coauthor_by_when_wp_user() { global $coauthors_plus; + // This test is only for wp_user so disabling guest authors. + add_filter( 'coauthors_guest_authors_enabled', '__return_false' ); + $this->assertFalse( $coauthors_plus->get_coauthor_by( '', '' ) ); $coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->author1->ID ); - $this->assertInternalType( 'object', $coauthor ); $this->assertInstanceOf( WP_User::class, $coauthor ); $this->assertObjectHasAttribute( 'ID', $coauthor ); $this->assertEquals( $this->author1->ID, $coauthor->ID ); @@ -78,21 +83,18 @@ public function test_get_coauthor_by_when_wp_user() { $coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $this->author1->user_login ); - $this->assertInternalType( 'object', $coauthor ); $this->assertInstanceOf( WP_User::class, $coauthor ); $this->assertObjectHasAttribute( 'user_login', $coauthor->data ); $this->assertEquals( $this->author1->user_login, $coauthor->user_login ); $coauthor = $coauthors_plus->get_coauthor_by( 'user_nicename', $this->author1->user_nicename ); - $this->assertInternalType( 'object', $coauthor ); $this->assertInstanceOf( WP_User::class, $coauthor ); $this->assertObjectHasAttribute( 'user_nicename', $coauthor->data ); $this->assertEquals( $this->author1->user_nicename, $coauthor->user_nicename ); $coauthor = $coauthors_plus->get_coauthor_by( 'user_email', $this->author1->user_email ); - $this->assertInternalType( 'object', $coauthor ); $this->assertInstanceOf( WP_User::class, $coauthor ); $this->assertObjectHasAttribute( 'user_email', $coauthor->data ); $this->assertEquals( $this->author1->user_email, $coauthor->user_email ); @@ -101,10 +103,11 @@ public function test_get_coauthor_by_when_wp_user() { $coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->editor1->ID ); - $this->assertInternalType( 'object', $coauthor ); $this->assertInstanceOf( stdClass::class, $coauthor ); $this->assertObjectHasAttribute( 'linked_account', $coauthor ); $this->assertEquals( $this->editor1->user_login, $coauthor->linked_account ); + + remove_filter( 'coauthors_guest_authors_enabled', '__return_false' ); } /** @@ -162,6 +165,58 @@ public function test_current_user_can_set_authors_using_current_screen() { global $coauthors_plus; $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + $screen = get_current_screen(); + + // Set the edit post current screen. + set_current_screen( 'edit-post' ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + $GLOBALS['current_screen'] = $screen; + + // Backing up current user. + $current_user = get_current_user_id(); + + // Checks when current user is author. + wp_set_current_user( $this->author1->ID ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + set_current_screen( 'edit-post' ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + $GLOBALS['current_screen'] = $screen; + + // Checks when current user is editor. + wp_set_current_user( $this->editor1->ID ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + set_current_screen( 'edit-post' ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors() ); + + $GLOBALS['current_screen'] = $screen; + + // Checks when current user is admin. + $admin1 = $this->factory->user->create_and_get( array( + 'role' => 'administrator', + ) ); + + wp_set_current_user( $admin1->ID ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors() ); + + set_current_screen( 'edit-post' ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors() ); + + $GLOBALS['current_screen'] = $screen; + + // Restore current user from backup. + wp_set_current_user( $current_user ); } /** @@ -248,6 +303,46 @@ public function test_current_user_can_set_authors_using_normal_post() { wp_set_current_user( $current_user ); } + /** + * Checks if the current user can set co-authors or not using coauthors_plus_edit_authors filter. + * + * @covers CoAuthors_Plus::current_user_can_set_authors() + */ + public function test_current_user_can_set_authors_using_coauthors_plus_edit_authors_filter() { + + global $coauthors_plus; + + // Backing up current user. + $current_user = get_current_user_id(); + + // Checking when current user is subscriber and filter is true/false. + $subscriber1 = $this->factory->user->create_and_get( array( + 'role' => 'subscriber', + ) ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + add_filter( 'coauthors_plus_edit_authors', '__return_true' ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + remove_filter( 'coauthors_plus_edit_authors', '__return_true' ); + + // Checks when current user is editor. + wp_set_current_user( $this->editor1->ID ); + + $this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + add_filter( 'coauthors_plus_edit_authors', '__return_false' ); + + $this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) ); + + remove_filter( 'coauthors_plus_edit_authors', '__return_false' ); + + // Restore current user from backup. + wp_set_current_user( $current_user ); + } + /** * Checks matching co-authors based on a search value when no arguments provided. * @@ -433,7 +528,6 @@ public function test_get_author_term_using_caching() { $author_term = $coauthors_plus->get_author_term( $this->author1 ); $author_term_cached = wp_cache_get( $cache_key, 'co-authors-plus' ); - $this->assertInternalType( 'object', $author_term ); $this->assertInstanceOf( WP_Term::class, $author_term ); $this->assertEquals( $author_term, $author_term_cached ); } @@ -453,7 +547,6 @@ public function test_get_author_term_when_author_has_linked_account() { $author_term = $coauthors_plus->get_author_term( $coauthor ); - $this->assertInternalType( 'object', $author_term ); $this->assertInstanceOf( WP_Term::class, $author_term ); // Checks when term does not exist or deleted somehow. @@ -480,7 +573,6 @@ public function test_get_author_term_when_author_has_not_linked_account() { $author_term = $coauthors_plus->get_author_term( $coauthor ); - $this->assertInternalType( 'object', $author_term ); $this->assertInstanceOf( WP_Term::class, $author_term ); // Checks when term does not exist or deleted somehow. @@ -515,6 +607,7 @@ public function test_update_author_term_when_author_term_exists() { // Checks term description. $author_term = $coauthors_plus->update_author_term( $this->author1 ); + // In "update_author_term()", only description is being updated, so asserting that only ( here and everywhere ). $this->assertEquals( $this->author1->display_name . ' ' . $this->author1->first_name . ' ' . $this->author1->last_name . ' ' . $this->author1->user_login . ' ' . $this->author1->ID . ' ' . $this->author1->user_email, $author_term->description ); // Checks term description after updating user. From 417b6f23180902ff87064ae04a2b865fad30a598 Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 1 Jan 2018 19:37:30 +0530 Subject: [PATCH 160/231] [#184] Unit tests for coauthors orders --- tests/test-template-tags.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 4d14420e..e3fc2ee5 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -86,6 +86,39 @@ public function test_get_coauthors_when_global_post_exists() { $post = $post_backup; } + /** + * Checks coauthors order. + * + * @covers ::get_coauthors() + */ + public function test_coauthors_order() { + + global $coauthors_plus; + + $post_id = $this->factory->post->create(); + + // Checks when no author exist. + $this->assertEmpty( get_coauthors( $post_id ) ); + + // Checks coauthors order. + $coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true ); + $coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true ); + + $expected = array( $this->author1->user_login, $this->editor1->user_login ); + + $this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) ); + + // Checks coauthors order after modifying. + $post_id = $this->factory->post->create(); + + $coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true ); + $coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true ); + + $expected = array( $this->editor1->user_login, $this->author1->user_login ); + + $this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) ); + } + /** * Checks whether user is a coauthor of the post when user or post not exists. * From b5a21447e8d5177db5015e5d0dc1206f33e23a32 Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 1 Jan 2018 19:43:44 +0530 Subject: [PATCH 161/231] [#388] Remove unit tests for coauthors orders --- tests/test-template-tags.php | 45 ------------------------------------ 1 file changed, 45 deletions(-) delete mode 100644 tests/test-template-tags.php diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php deleted file mode 100644 index 95b430ec..00000000 --- a/tests/test-template-tags.php +++ /dev/null @@ -1,45 +0,0 @@ -author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) ); - $this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); - } - - /** - * Checks coauthors order. - * - * @covers ::get_coauthors() - */ - public function test_coauthors_order() { - - global $coauthors_plus; - - $post_id = $this->factory->post->create(); - - // Checks when no author exist. - $this->assertEmpty( get_coauthors( $post_id ) ); - - // Checks coauthors order. - $coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true ); - $coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true ); - - $expected = array( $this->author1->user_login, $this->editor1->user_login ); - - $this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) ); - - // Checks coauthors order after modifying. - $post_id = $this->factory->post->create(); - - $coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true ); - $coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true ); - - $expected = array( $this->editor1->user_login, $this->author1->user_login ); - - $this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) ); - } -} From bfd7436a63d448c7fd270cc763ca76f28933cba5 Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 1 Jan 2018 20:36:40 +0530 Subject: [PATCH 162/231] [#388] Improve unit tests --- tests/test-coauthors-guest-authors.php | 69 ++++++++++++++++++++------ tests/test-coauthors-plus.php | 7 ++- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/tests/test-coauthors-guest-authors.php b/tests/test-coauthors-guest-authors.php index ef242387..3cc920e9 100644 --- a/tests/test-coauthors-guest-authors.php +++ b/tests/test-coauthors-guest-authors.php @@ -570,13 +570,20 @@ public function test_handle_delete_guest_author_action_with_reassign_is_leave_as $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); $_POST['reassign'] = 'leave-assigned'; - $redirect_to = add_query_arg( array_map( 'rawurlencode', array( - 'page' => 'view-guest-authors', - ) ), admin_url( $guest_author_obj->parent_page ) ); + add_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99, 2 ); - $this->go_to( $redirect_to ); + try { - $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + $guest_author_obj->handle_delete_guest_author_action(); + + } catch( Exception $e ) { + + $this->assertContains( $guest_author_obj->parent_page, $e->getMessage() ); + $this->assertContains( 'page=view-guest-authors', $e->getMessage() ); + $this->assertContains( 'message=guest-author-deleted', $e->getMessage() ); + } + + remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 ); // Restore current user from backup. wp_set_current_user( $current_user ); @@ -626,13 +633,20 @@ public function test_handle_delete_guest_author_action_with_reassign_is_reassign // When coauthor exists. $_POST['leave-assigned-to'] = $this->author1->user_nicename; - $redirect_to = add_query_arg( array_map( 'rawurlencode', array( - 'page' => 'view-guest-authors', - ) ), admin_url( $guest_author_obj->parent_page ) ); + add_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99, 2 ); + + try { - $this->go_to( $redirect_to ); + $guest_author_obj->handle_delete_guest_author_action(); - $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + } catch ( Exception $e ) { + + //$this->assertContains( $guest_author_obj->parent_page, $e->getMessage() ); + $this->assertContains( 'page=view-guest-authors', $e->getMessage() ); + $this->assertContains( 'message=guest-author-deleted', $e->getMessage() ); + } + + remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 ); // Restore current user from backup. wp_set_current_user( $current_user ); @@ -665,13 +679,20 @@ public function test_handle_delete_guest_author_action_with_reassign_is_remove_b $_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID ); $_POST['reassign'] = 'remove-byline'; - $redirect_to = add_query_arg( array_map( 'rawurlencode', array( - 'page' => 'view-guest-authors', - ) ), admin_url( $guest_author_obj->parent_page ) ); + add_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99, 2 ); - $this->go_to( $redirect_to ); + try { - $this->assertNull( $guest_author_obj->handle_delete_guest_author_action() ); + $guest_author_obj->handle_delete_guest_author_action(); + + } catch ( Exception $e ) { + + $this->assertContains( $guest_author_obj->parent_page, $e->getMessage() ); + $this->assertContains( 'page=view-guest-authors', $e->getMessage() ); + $this->assertContains( 'message=guest-author-deleted', $e->getMessage() ); + } + + remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 ); // Restore current user from backup. wp_set_current_user( $current_user ); @@ -680,6 +701,24 @@ public function test_handle_delete_guest_author_action_with_reassign_is_remove_b $_POST = $_post_backup; } + /** + * To catch any redirection and throw location and status in Exception. + * + * Note : Destination location can be get from Exception Message and + * status can be get from Exception code. + * + * @param string $location Redirected location. + * @param int $status Status. + * + * @throws \Exception Redirection data. + * + * @return void + **/ + public function catch_redirect_destination( $location, $status ) { + + throw new Exception( $location, $status ); + } + /** * Checks delete guest author when he/she does not exist. * diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 7f205781..68d7ecb6 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -65,11 +65,10 @@ public function test_get_coauthor_by_when_guest_author() { * * @covers CoAuthors_Plus::get_coauthor_by() */ - public function test_get_coauthor_by_when_wp_user() { + public function test_get_coauthor_by_when_guest_authors_not_enabled() { global $coauthors_plus; - // This test is only for wp_user so disabling guest authors. add_filter( 'coauthors_guest_authors_enabled', '__return_false' ); $this->assertFalse( $coauthors_plus->get_coauthor_by( '', '' ) ); @@ -99,6 +98,8 @@ public function test_get_coauthor_by_when_wp_user() { $this->assertObjectHasAttribute( 'user_email', $coauthor->data ); $this->assertEquals( $this->author1->user_email, $coauthor->user_email ); + remove_filter( 'coauthors_guest_authors_enabled', '__return_false' ); + $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1->ID ); $coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->editor1->ID ); @@ -106,8 +107,6 @@ public function test_get_coauthor_by_when_wp_user() { $this->assertInstanceOf( stdClass::class, $coauthor ); $this->assertObjectHasAttribute( 'linked_account', $coauthor ); $this->assertEquals( $this->editor1->user_login, $coauthor->linked_account ); - - remove_filter( 'coauthors_guest_authors_enabled', '__return_false' ); } /** From 639355063b31de70e3827f77481f09b535758be6 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 22 Dec 2017 14:13:03 +0530 Subject: [PATCH 163/231] [#279] Add issue link as ref --- template-tags.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/template-tags.php b/template-tags.php index e548b1fb..647078a8 100644 --- a/template-tags.php +++ b/template-tags.php @@ -239,7 +239,11 @@ function coauthors_posts_links( $between = null, $betweenLast = null, $before = global $coauthors_plus_template_filters; - // Removing "the_author" filter so that it won't get called in loop and append names for each author. + /** + * Removing "the_author" filter so that it won't get called in loop and append names for each author. + * + * Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279 + */ remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); $coauthors_posts_links = coauthors__echo( 'coauthors_posts_links_single', 'callback', array( @@ -358,7 +362,11 @@ function coauthors_links( $between = null, $betweenLast = null, $before = null, global $coauthors_plus_template_filters; - // Removing "the_author" filter so that it won't get called in loop and append names for each author. + /** + * Removing "the_author" filter so that it won't get called in loop and append names for each author. + * + * Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279 + */ remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); $coauthors_links = coauthors__echo( 'coauthors_links_single', 'callback', array( From b2375f572c9e1354cd0f095defdeda58f5d4ced8 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 22 Dec 2017 18:16:46 +0530 Subject: [PATCH 164/231] [#279] Improve phpunit test cases --- tests/test-template-tags.php | 86 ++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 729d3da2..4385e997 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -6,6 +6,13 @@ public function setUp() { parent::setUp(); + /** + * When `coauthors_auto_apply_template_tags` is set to true, + * we need CoAuthors_Template_Filters object to check `the_author` filter. + */ + global $coauthors_plus_template_filters; + $coauthors_plus_template_filters = new CoAuthors_Template_Filters; + $this->author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) ); $this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor1' ) ); @@ -21,86 +28,91 @@ public function setUp() { /** * Tests for co-authors display names, with links to their posts. * - * @see : https://github.com/Automattic/Co-Authors-Plus/issues/279 + * @see https://github.com/Automattic/Co-Authors-Plus/issues/279 * - * @covers :: coauthors_posts_links() + * @covers ::coauthors_posts_links() */ public function test_coauthors_posts_links() { - global $coauthors_plus; + global $coauthors_plus, $coauthors_plus_template_filters; $GLOBALS['post'] = get_post( $this->post_id ); // Checks for single post author. - $author1 = get_user_by( 'id', $this->author1 ); - $single_cpl = coauthors_posts_links( null, null, null, null, false ); - $expected_href = 'display_name . ''; + $author1 = get_user_by( 'id', $this->author1 ); + $single_cpl = coauthors_posts_links( null, null, null, null, false ); - $this->assertContains( $expected_href, $single_cpl ); - $this->assertContains( $expected_name, $single_cpl ); + $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $single_cpl, 'Author link not found.' ); + $this->assertContains( $author1->display_name, $single_cpl, 'Author name not found.' ); // Checks for multiple post author. $editor1 = get_user_by( 'id', $this->editor1 ); $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); - $multiple_cpl = coauthors_posts_links( null, null, null, null, false ); - $expected_first_href = 'display_name . ' and '; - $expected_second_href = 'display_name . ''; + $multiple_cpl = coauthors_posts_links( null, null, null, null, false ); + + $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $multiple_cpl, 'Main author link not found.' ); + $this->assertContains( $author1->display_name, $multiple_cpl, 'Main author name not found.' ); + $this->assertEquals( 1, substr_count( $multiple_cpl, ">{$author1->display_name}<" ) ); + $this->assertContains( ' and ', $multiple_cpl, 'Coauthors name separator is not matched.' ); + $this->assertContains( 'href="' . get_author_posts_url( $editor1->ID, $editor1->user_nicename ) . '"', $multiple_cpl, 'Coauthor link not found.' ); + $this->assertContains( $editor1->display_name, $multiple_cpl, 'Coauthor name not found.' ); + $this->assertEquals( 1, substr_count( $multiple_cpl, ">{$editor1->display_name}<" ) ); - $this->assertContains( $expected_first_href, $multiple_cpl ); - $this->assertContains( $expected_first_name, $multiple_cpl ); - $this->assertContains( $expected_second_href, $multiple_cpl ); - $this->assertContains( $expected_second_name, $multiple_cpl ); + $multiple_cpl = coauthors_links( null, ' or ', null, null, false ); - $multiple_cpl = coauthors_links( null, ' or ', null, null, false ); - $expected_first_name = '>' . $author1->display_name . ' or '; + $this->assertContains( ' or ', $multiple_cpl, 'Coauthors name separator is not matched.' ); - $this->assertContains( $expected_first_name, $multiple_cpl ); + $this->assertEquals( 10, has_filter( 'the_author', array( + $coauthors_plus_template_filters, + 'filter_the_author', + ) ) ); - $this->assertEquals( 10, has_filter( 'the_author') ); + unset( $coauthors_plus_template_filters ); } /** * Tests for co-authors display names. * - * @see : https://github.com/Automattic/Co-Authors-Plus/issues/279 + * @see https://github.com/Automattic/Co-Authors-Plus/issues/279 * - * @covers :: coauthors_links() + * @covers ::coauthors_links() */ public function test_coauthors_links() { - global $coauthors_plus; + global $coauthors_plus, $coauthors_plus_template_filters; $GLOBALS['post'] = get_post( $this->post_id ); // Checks for single post author. - $author1 = get_user_by( 'id', $this->author1 ); - $single_cpl = coauthors_links( null, null, null, null, false ); - $expected_name = $author1->display_name; + $author1 = get_user_by( 'id', $this->author1 ); + $single_cpl = coauthors_links( null, null, null, null, false ); - $this->assertEquals( $expected_name, $single_cpl ); + $this->assertEquals( $author1->display_name, $single_cpl, 'Author name not found.' ); // Checks for multiple post author. $editor1 = get_user_by( 'id', $this->editor1 ); $coauthors_plus->add_coauthors( $this->post_id, array( $editor1->user_login ), true ); - $multiple_cpl = coauthors_links( null, null, null, null, false ); - $expected_first_name = $author1->display_name; - $expected_second_name = $editor1->display_name; + $multiple_cpl = coauthors_links( null, null, null, null, false ); - $this->assertContains( $expected_first_name, $multiple_cpl ); - $this->assertContains( ' and ', $multiple_cpl ); - $this->assertContains( $expected_second_name, $multiple_cpl ); + $this->assertContains( $author1->display_name, $multiple_cpl, 'Main author name not found.' ); + $this->assertEquals( 1, substr_count( $multiple_cpl, $author1->display_name ) ); + $this->assertContains( ' and ', $multiple_cpl, 'Coauthors name separator is not matched.' ); + $this->assertContains( $editor1->display_name, $multiple_cpl, 'Coauthor name not found.' ); + $this->assertEquals( 1, substr_count( $multiple_cpl, $editor1->display_name ) ); $multiple_cpl = coauthors_links( null, ' or ', null, null, false ); - $this->assertContains( ' or ', $multiple_cpl ); + $this->assertContains( ' or ', $multiple_cpl, 'Coauthors name separator is not matched.' ); + + $this->assertEquals( 10, has_filter( 'the_author', array( + $coauthors_plus_template_filters, + 'filter_the_author', + ) ) ); - $this->assertEquals( 10, has_filter( 'the_author' ) ); + unset( $coauthors_plus_template_filters ); } } From 8863cc12fc7b133c86c5d0f9525a736b2241ec77 Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 25 Dec 2017 15:39:26 +0530 Subject: [PATCH 165/231] [#279] Improve condition checking for unit test cases --- template-tags.php | 38 +++++++++++++++++++++++------------- tests/test-template-tags.php | 18 +++++++++++++++-- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/template-tags.php b/template-tags.php index 647078a8..3b25616d 100644 --- a/template-tags.php +++ b/template-tags.php @@ -239,12 +239,15 @@ function coauthors_posts_links( $between = null, $betweenLast = null, $before = global $coauthors_plus_template_filters; - /** - * Removing "the_author" filter so that it won't get called in loop and append names for each author. - * - * Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279 - */ - remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + + /** + * Removing "the_author" filter so that it won't get called in loop and append names for each author. + * + * Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279 + */ + remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + } $coauthors_posts_links = coauthors__echo( 'coauthors_posts_links_single', 'callback', array( 'between' => $between, @@ -253,7 +256,9 @@ function coauthors_posts_links( $between = null, $betweenLast = null, $before = 'after' => $after, ), null, $echo ); - add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + } return $coauthors_posts_links; } @@ -362,12 +367,15 @@ function coauthors_links( $between = null, $betweenLast = null, $before = null, global $coauthors_plus_template_filters; - /** - * Removing "the_author" filter so that it won't get called in loop and append names for each author. - * - * Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279 - */ - remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + + /** + * Removing "the_author" filter so that it won't get called in loop and append names for each author. + * + * Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279 + */ + remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + } $coauthors_links = coauthors__echo( 'coauthors_links_single', 'callback', array( 'between' => $between, @@ -376,7 +384,9 @@ function coauthors_links( $between = null, $betweenLast = null, $before = null, 'after' => $after, ), null, $echo ); - add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); + } return $coauthors_links; } diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 4385e997..7155b43b 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -36,6 +36,9 @@ public function test_coauthors_posts_links() { global $coauthors_plus, $coauthors_plus_template_filters; + // Backing up global post. + $post_backup = $GLOBALS['post']; + $GLOBALS['post'] = get_post( $this->post_id ); // Checks for single post author. @@ -54,10 +57,16 @@ public function test_coauthors_posts_links() { $this->assertContains( 'href="' . get_author_posts_url( $author1->ID, $author1->user_nicename ) . '"', $multiple_cpl, 'Main author link not found.' ); $this->assertContains( $author1->display_name, $multiple_cpl, 'Main author name not found.' ); + + // Here we are checking author name should not be more then one time. + // Asserting ">{$author1->display_name}<" because "$author1->display_name" can be multiple times like in href, title, etc. $this->assertEquals( 1, substr_count( $multiple_cpl, ">{$author1->display_name}<" ) ); $this->assertContains( ' and ', $multiple_cpl, 'Coauthors name separator is not matched.' ); $this->assertContains( 'href="' . get_author_posts_url( $editor1->ID, $editor1->user_nicename ) . '"', $multiple_cpl, 'Coauthor link not found.' ); $this->assertContains( $editor1->display_name, $multiple_cpl, 'Coauthor name not found.' ); + + // Here we are checking editor name should not be more then one time. + // Asserting ">{$editor1->display_name}<" because "$editor1->display_name" can be multiple times like in href, title, etc. $this->assertEquals( 1, substr_count( $multiple_cpl, ">{$editor1->display_name}<" ) ); $multiple_cpl = coauthors_links( null, ' or ', null, null, false ); @@ -69,7 +78,8 @@ public function test_coauthors_posts_links() { 'filter_the_author', ) ) ); - unset( $coauthors_plus_template_filters ); + // Restore backed up post to global. + $GLOBALS['post'] = $post_backup; } /** @@ -83,6 +93,9 @@ public function test_coauthors_links() { global $coauthors_plus, $coauthors_plus_template_filters; + // Backing up global post. + $post_backup = $GLOBALS['post']; + $GLOBALS['post'] = get_post( $this->post_id ); // Checks for single post author. @@ -113,6 +126,7 @@ public function test_coauthors_links() { 'filter_the_author', ) ) ); - unset( $coauthors_plus_template_filters ); + // Restore backed up post to global. + $GLOBALS['post'] = $post_backup; } } From e75c52857713afb17ec2a69ad1f561724d5e6abf Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 25 Dec 2017 15:41:07 +0530 Subject: [PATCH 166/231] [#279] Refactor comments for test cases --- tests/test-template-tags.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 7155b43b..2be77d8b 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -7,8 +7,8 @@ public function setUp() { parent::setUp(); /** - * When `coauthors_auto_apply_template_tags` is set to true, - * we need CoAuthors_Template_Filters object to check `the_author` filter. + * When 'coauthors_auto_apply_template_tags' is set to true, + * we need CoAuthors_Template_Filters object to check 'the_author' filter. */ global $coauthors_plus_template_filters; $coauthors_plus_template_filters = new CoAuthors_Template_Filters; From 2902cdb028cc66fa8cff65147873e5649b08ca88 Mon Sep 17 00:00:00 2001 From: Meghan Hannon Date: Fri, 5 Jan 2018 18:33:37 -0500 Subject: [PATCH 167/231] Update class-wp-cli.php fix #472 --- php/class-wp-cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index c44ca8f8..7a3c936f 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -735,7 +735,7 @@ public function create_guest_authors_from_wxr( $args, $assoc_args ) { } if ( ! class_exists( 'WXR_Parser' ) ) { - require_once( WP_CONTENT_DIR . '/admin-plugins/wordpress-importer/parsers.php' ); + require_once( WP_CONTENT_DIR . '/plugins/wordpress-importer/parsers.php' ); } $parser = new WXR_Parser(); From 9806b14f6e2169a50b43082e73aa9445f2ce1ea3 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 30 Jan 2018 10:26:19 +0530 Subject: [PATCH 168/231] [#198] Replace urlencode/urldecode with rawurlencode/rawurldecode --- co-authors-plus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 188436a8..6a5c736c 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -767,8 +767,8 @@ function coauthors_set_post_author_field( $data, $postarr ) { // This action happens when a post is saved while editing a post if ( isset( $_REQUEST['coauthors-nonce'] ) && isset( $_POST['coauthors'] ) && is_array( $_POST['coauthors'] ) ) { - // urlencode() is for encoding coauthor name with special characters to compare names when getting coauthor. - $author = urlencode( sanitize_text_field( $_POST['coauthors'][0] ) ); + // rawurlencode() is for encoding coauthor name with special characters to compare names when getting coauthor. + $author = rawurlencode( sanitize_text_field( $_POST['coauthors'][0] ) ); if ( $author ) { $author_data = $this->get_coauthor_by( 'user_nicename', $author ); @@ -1137,7 +1137,7 @@ public function ajax_suggest() { if( empty( $authors ) ) echo apply_filters( 'coauthors_no_matching_authors_message', 'Sorry, no matching authors found.'); foreach ( $authors as $author ) { - echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . urldecode( $author->user_nicename ) ) . "\n"; + echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . rawurldecode( $author->user_nicename ) ) . "\n"; } die(); From c8539e637f511590f4e178ab77a6c6676cfdc073 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 30 Jan 2018 10:36:32 +0530 Subject: [PATCH 169/231] [#279] Code cleanup - Convert duplicate conditions into variables and use those variables. --- template-tags.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/template-tags.php b/template-tags.php index 3b25616d..2483c998 100644 --- a/template-tags.php +++ b/template-tags.php @@ -239,7 +239,9 @@ function coauthors_posts_links( $between = null, $betweenLast = null, $before = global $coauthors_plus_template_filters; - if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + $modify_filter = ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters; + + if ( $modify_filter ) { /** * Removing "the_author" filter so that it won't get called in loop and append names for each author. @@ -256,7 +258,7 @@ function coauthors_posts_links( $between = null, $betweenLast = null, $before = 'after' => $after, ), null, $echo ); - if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + if ( $modify_filter ) { add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); } @@ -367,7 +369,9 @@ function coauthors_links( $between = null, $betweenLast = null, $before = null, global $coauthors_plus_template_filters; - if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + $modify_filter = ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters; + + if ( $modify_filter ) { /** * Removing "the_author" filter so that it won't get called in loop and append names for each author. @@ -384,7 +388,7 @@ function coauthors_links( $between = null, $betweenLast = null, $before = null, 'after' => $after, ), null, $echo ); - if ( ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters ) { + if ( $modify_filter ) { add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) ); } From fd08f52a97fe63dbc6b7a25dd7be1b94c25b4b53 Mon Sep 17 00:00:00 2001 From: sanketio Date: Tue, 30 Jan 2018 10:57:14 +0530 Subject: [PATCH 170/231] [#388] Modify where condition when WordPress generates `post_author IN (id)` in query --- co-authors-plus.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 3bb99eca..5a4cb959 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -703,9 +703,18 @@ function posts_where_filter( $where, $query ) { } $terms_implode = rtrim( $terms_implode, ' OR' ); - $id = is_author() ? get_queried_object_id() : '\d'; + $id = is_author() ? get_queried_object_id() : '\d+'; - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . $id . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + // When WordPress generates query as 'post_author IN (id)'. + if ( false !== strpos( $where, "{$wpdb->posts}.post_author IN " ) ) { + + $maybe_both_query = $maybe_both ? '$0 OR' : ''; + + $where = preg_replace( '/\s\b(?:' . $wpdb->posts . '\.)?post_author\s*IN\s*(.*' . $id . '.)/', ' (' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + + } else { + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . $id . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + } // the block targets the private posts clause (if it exists) if ( From 930129fbbc2ab63cf935d4698fcb257116ff8b44 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 1 Feb 2018 17:49:34 +0530 Subject: [PATCH 171/231] [#458] Update travis file --- .travis.yml | 58 +++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 28765d3b..4f8b4015 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,29 @@ language: php -php: - - 7.1 +matrix: + include: + # aliased to a recent 5.6.x version + - php: '5.6' + env: + - WP_VERSION=latest + #- SNIFF=1 + - WP_MULTISITE=0 -env: - - WP_VERSION=latest + - php: '5.6' + env: + - WP_VERSION=latest + #- SNIFF=1 + - WP_MULTISITE=1 -matrix: -matrix: - include: - - php: "5.2" - env: WP_VERSION=latest - - php: "5.2" - env: WP_VERSION=4.6 - - php: "5.6" - env: - - WP_VERSION=latest - - SNIFF=1 - - php: "5.6" - env: WP_VERSION=4.6 - - php: "7.0" - env: WP_VERSION=latest - - php: "7.0" - env: WP_VERSION=4.6 - # 7.1 / latest already included above as first build. - - php: "7.1" - env: WP_VERSION=4.6 + # aliased to a recent 7.x version + - php: '7.0' + env: WP_VERSION=latest + + - php: '7.1' + env: WP_VERSION=latest before_script: - - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - # PHPCS + # Set up CodeSniffer - export PHPCS_DIR=/tmp/phpcs - export SNIFFS_DIR=/tmp/sniffs # Install CodeSniffer for WordPress Coding Standards checks. @@ -43,14 +37,8 @@ before_script: - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $SNIFFS_DIR; fi # After CodeSniffer install you should refresh your path. - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi - # Properly handle PHPunit versions - - export PATH="$HOME/.composer/vendor/bin:$PATH" - - | - if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then - composer global require "phpunit/phpunit=5.7.*" - elif [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then - composer global require "phpunit/phpunit=4.8.*" - fi + # Set up unit tests + - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - phpunit --version script: @@ -66,5 +54,5 @@ script: # --standard: Use WordPress as the standard. # --extensions: Only sniff PHP files. - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p -s -v -n . --standard="WordPress-VIP" --extensions=php; fi - # Unit tests + # Run unit tests - phpunit From 156c719cde016fd03f3f09412adb634ffb3e0b3c Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Fri, 2 Feb 2018 15:43:11 -0500 Subject: [PATCH 172/231] Changes to resolve issue #332 about missing coauthor meta in get_the_coauthor_meta function --- template-tags.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/template-tags.php b/template-tags.php index f3883b56..baca86f3 100644 --- a/template-tags.php +++ b/template-tags.php @@ -417,15 +417,37 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a ), null, $echo ); } +/** + * Outputs the co-authors Meta Data + * + * @param string $field Required The user field to retrieve.[login, email, nicename, display_name, url, type] + */ function get_the_coauthor_meta( $field ) { global $wp_query, $post; $coauthors = get_coauthors(); $meta = array(); - + foreach ( $coauthors as $coauthor ) { $user_id = $coauthor->ID; - $meta[ $user_id ] = get_the_author_meta( $field, $user_id ); + if (isset( $coauthor->data) ){ + $coauthor_data = $coauthor->data; + } else { + $coauthor_data = $coauthor; + } + + $coauthor_meta['login'] = $coauthor_data->user_login; + $coauthor_meta['email'] = $coauthor_data->user_email; + $coauthor_meta['nicename'] = $coauthor_data->user_nicename; + $coauthor_meta['display_name'] = $coauthor_data->display_name; + if ( $coauthor_data->type == 'wpuser' ) { + $coauthor_meta['url'] = $coauthor_data->user_url; + } else { + $coauthor_meta['url'] = $coauthor_data->website; + } + $coauthor_meta['type'] = $coauthor_data->type; + + $meta[ $user_id ] = $coauthor_meta[$field]; } return $meta; } From 57851b7fa11bc95d1482ffc9f8119649c2d68c95 Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Thu, 8 Feb 2018 15:42:01 -0500 Subject: [PATCH 173/231] Changes to resolve issue #332. Updated funtion resolve error generated while fetching 'type' field. --- template-tags.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/template-tags.php b/template-tags.php index baca86f3..f1a2a8af 100644 --- a/template-tags.php +++ b/template-tags.php @@ -422,36 +422,40 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a * * @param string $field Required The user field to retrieve.[login, email, nicename, display_name, url, type] */ -function get_the_coauthor_meta( $field ) { +function get_the_coauthor_meta( $field ) { global $wp_query, $post; $coauthors = get_coauthors(); $meta = array(); foreach ( $coauthors as $coauthor ) { + $user_id = $coauthor->ID; - if (isset( $coauthor->data) ){ - $coauthor_data = $coauthor->data; - } else { - $coauthor_data = $coauthor; + if ( isset($coauthor->data) ){ + $coauthor = $coauthor->data; } - $coauthor_meta['login'] = $coauthor_data->user_login; - $coauthor_meta['email'] = $coauthor_data->user_email; - $coauthor_meta['nicename'] = $coauthor_data->user_nicename; - $coauthor_meta['display_name'] = $coauthor_data->display_name; - if ( $coauthor_data->type == 'wpuser' ) { - $coauthor_meta['url'] = $coauthor_data->user_url; - } else { - $coauthor_meta['url'] = $coauthor_data->website; - } - $coauthor_meta['type'] = $coauthor_data->type; + if( $field == 'url' && isset ($coauthor->website) ) + $field = 'website'; - $meta[ $user_id ] = $coauthor_meta[$field]; + if( $field == 'website' && isset ($coauthor->user_url) ) + $field = 'user_url'; + + if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) + $field = 'user_' . $field; + + if ( isset( $coauthor->$field ) ){ + $meta[ $user_id ] = $coauthor->$field; + } else { + $meta[ $user_id ] = ''; + } + } + return $meta; } + function the_coauthor_meta( $field, $user_id = 0 ) { // TODO: need before after options echo get_the_coauthor_meta( $field, $user_id ); From d522c09a9eee28b314435ec00b17a053538a7ab0 Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Wed, 14 Feb 2018 14:38:53 -0500 Subject: [PATCH 174/231] Changes for optimizing code of get_the_coauthor_meta function --- template-tags.php | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/template-tags.php b/template-tags.php index f1a2a8af..7c7b1f42 100644 --- a/template-tags.php +++ b/template-tags.php @@ -428,30 +428,26 @@ function get_the_coauthor_meta( $field ) { $coauthors = get_coauthors(); $meta = array(); - foreach ( $coauthors as $coauthor ) { - + if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) + $field = 'user_' . $field; + + foreach ( $coauthors as $coauthor ) { $user_id = $coauthor->ID; - if ( isset($coauthor->data) ){ - $coauthor = $coauthor->data; - } - - if( $field == 'url' && isset ($coauthor->website) ) - $field = 'website'; - if( $field == 'website' && isset ($coauthor->user_url) ) - $field = 'user_url'; + if ( isset( $coauthor->type ) && 'user_url' === $field ) { + if ( 'guest-author' === $coauthor->type) { + $field = 'website'; + } + } else if ( 'website' === $field ) { + $field = 'user_url'; + } - if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) - $field = 'user_' . $field; - - if ( isset( $coauthor->$field ) ){ - $meta[ $user_id ] = $coauthor->$field; + if ( isset( $coauthor->$field ) ) { + $meta[ $user_id ] = $coauthor->$field; } else { - $meta[ $user_id ] = ''; - } - - } - + $meta[ $user_id ] = ''; + } + } return $meta; } From 6aa05fdd7dadb87daa33e9b6a5692ae0b2a3ce54 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 2 Mar 2018 11:17:38 +0530 Subject: [PATCH 175/231] [#458] Include WP 4.6 env in travis file --- .travis.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f8b4015..8c2ca7c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: php matrix: include: # aliased to a recent 5.6.x version + - php: "5.6" + env: WP_VERSION=4.6 + - php: '5.6' env: - WP_VERSION=latest @@ -16,9 +19,15 @@ matrix: - WP_MULTISITE=1 # aliased to a recent 7.x version + - php: '7.0' + env: WP_VERSION=4.6 + - php: '7.0' env: WP_VERSION=latest + - php: '7.1' + env: WP_VERSION=4.6 + - php: '7.1' env: WP_VERSION=latest @@ -39,7 +48,20 @@ before_script: - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi # Set up unit tests - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - - phpunit --version + # Properly handle PHPUnit versions + - export PATH="$HOME/.composer/vendor/bin:$PATH" + - | + if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then + composer global require "phpunit/phpunit=4.8.*" + elif [[ ${TRAVIS_PHP_VERSION:0:2} == "7." && ${WP_VERSION} == "4.6" ]]; then + composer global require "phpunit/phpunit=5.7.*" + fi + - | + if [[ -n $COMPOSER_BIN_DIR && -x $COMPOSER_BIN_DIR/phpunit ]]; then + $COMPOSER_BIN_DIR/phpunit --version + else + phpunit --version + fi script: # Search for PHP syntax errors. @@ -55,4 +77,9 @@ script: # --extensions: Only sniff PHP files. - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p -s -v -n . --standard="WordPress-VIP" --extensions=php; fi # Run unit tests - - phpunit + - | + if [[ -n $COMPOSER_BIN_DIR && -x $COMPOSER_BIN_DIR/phpunit ]]; then + $COMPOSER_BIN_DIR/phpunit + else + phpunit + fi From 539db915cdd152e7f4430afac5e26c3eff4fa96f Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Fri, 2 Mar 2018 14:18:04 -0500 Subject: [PATCH 176/231] Updating function to allow fetching meta data based on user_id to support the_coauthor_meta function --- template-tags.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/template-tags.php b/template-tags.php index 7c7b1f42..228b6caa 100644 --- a/template-tags.php +++ b/template-tags.php @@ -421,18 +421,28 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a * Outputs the co-authors Meta Data * * @param string $field Required The user field to retrieve.[login, email, nicename, display_name, url, type] + * @param string $user_id Optional The user ID for meta */ -function get_the_coauthor_meta( $field ) { - global $wp_query, $post; +function get_the_coauthor_meta( $field, $user_id = false ) { + global $wp_query, $post, $coauthors_plus; + + if ( ! $user_id ) { + $coauthors = get_coauthors(); + } else { + $coauthor_data = $coauthors_plus->get_coauthor_by( 'id', $user_id ); + $coauthors = array(); + if ( ! empty( $coauthor_data ) ) { + $coauthors[] = $coauthor_data; + } + } - $coauthors = get_coauthors(); $meta = array(); if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) $field = 'user_' . $field; foreach ( $coauthors as $coauthor ) { - $user_id = $coauthor->ID; + $user_id = $coauthor->ID; if ( isset( $coauthor->type ) && 'user_url' === $field ) { if ( 'guest-author' === $coauthor->type) { @@ -448,13 +458,17 @@ function get_the_coauthor_meta( $field ) { $meta[ $user_id ] = ''; } } + return $meta; } function the_coauthor_meta( $field, $user_id = 0 ) { // TODO: need before after options - echo get_the_coauthor_meta( $field, $user_id ); + $coauthor_meta = get_the_coauthor_meta( $field, $user_id ); + foreach ( $coauthor_meta as $meta ) { + echo $meta; + } } /** From 96330a6b8346d1610d38b60cf72b59cd45446ad7 Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Wed, 7 Mar 2018 11:07:45 -0500 Subject: [PATCH 177/231] Removing unused global variables --- template-tags.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-tags.php b/template-tags.php index 228b6caa..88522405 100644 --- a/template-tags.php +++ b/template-tags.php @@ -424,7 +424,7 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a * @param string $user_id Optional The user ID for meta */ function get_the_coauthor_meta( $field, $user_id = false ) { - global $wp_query, $post, $coauthors_plus; + global $coauthors_plus; if ( ! $user_id ) { $coauthors = get_coauthors(); From 61be1963a231d2ef0d603ee934d71f2231ee27f0 Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Wed, 14 Mar 2018 09:57:47 -0400 Subject: [PATCH 178/231] Formatting in my changes as per PHPCS --- template-tags.php | 67 +++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/template-tags.php b/template-tags.php index 88522405..e8ab5e26 100644 --- a/template-tags.php +++ b/template-tags.php @@ -422,43 +422,46 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a * * @param string $field Required The user field to retrieve.[login, email, nicename, display_name, url, type] * @param string $user_id Optional The user ID for meta + * + * @return array $meta Value of the user field */ -function get_the_coauthor_meta( $field, $user_id = false ) { +function get_the_coauthor_meta( $field, $user_id = false ) { global $coauthors_plus; if ( ! $user_id ) { $coauthors = get_coauthors(); - } else { - $coauthor_data = $coauthors_plus->get_coauthor_by( 'id', $user_id ); - $coauthors = array(); - if ( ! empty( $coauthor_data ) ) { - $coauthors[] = $coauthor_data; - } + } else { + $coauthor_data = $coauthors_plus->get_coauthor_by( 'id', $user_id ); + $coauthors = array(); + if ( ! empty( $coauthor_data ) ) { + $coauthors[] = $coauthor_data; } + } $meta = array(); - - if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) - $field = 'user_' . $field; - - foreach ( $coauthors as $coauthor ) { - $user_id = $coauthor->ID; - - if ( isset( $coauthor->type ) && 'user_url' === $field ) { - if ( 'guest-author' === $coauthor->type) { - $field = 'website'; - } - } else if ( 'website' === $field ) { - $field = 'user_url'; - } - - if ( isset( $coauthor->$field ) ) { - $meta[ $user_id ] = $coauthor->$field; - } else { - $meta[ $user_id ] = ''; - } - } - + + if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) { + $field = 'user_' . $field; + } + + foreach ( $coauthors as $coauthor ) { + $user_id = $coauthor->ID; + + if ( isset( $coauthor->type ) && 'user_url' === $field ) { + if ( 'guest-author' === $coauthor->type) { + $field = 'website'; + } + } else if ( 'website' === $field ) { + $field = 'user_url'; + } + + if ( isset( $coauthor->$field ) ) { + $meta[ $user_id ] = $coauthor->$field; + } else { + $meta[ $user_id ] = ''; + } + } + return $meta; } @@ -466,9 +469,9 @@ function get_the_coauthor_meta( $field, $user_id = false ) { function the_coauthor_meta( $field, $user_id = 0 ) { // TODO: need before after options $coauthor_meta = get_the_coauthor_meta( $field, $user_id ); - foreach ( $coauthor_meta as $meta ) { - echo $meta; - } + foreach ( $coauthor_meta as $meta ) { + echo $meta; + } } /** From 010d2d11da6cb422d596beb12bada48dbce52402 Mon Sep 17 00:00:00 2001 From: Nilzari Mehta Date: Wed, 21 Mar 2018 14:07:53 -0400 Subject: [PATCH 179/231] Space alignment and adding escape to output --- template-tags.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/template-tags.php b/template-tags.php index e8ab5e26..fb20d9bd 100644 --- a/template-tags.php +++ b/template-tags.php @@ -426,11 +426,12 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a * @return array $meta Value of the user field */ function get_the_coauthor_meta( $field, $user_id = false ) { - global $coauthors_plus; + global $coauthors_plus; - if ( ! $user_id ) { - $coauthors = get_coauthors(); - } else { + if ( ! $user_id ) { + $coauthors = get_coauthors(); + } + else { $coauthor_data = $coauthors_plus->get_coauthor_by( 'id', $user_id ); $coauthors = array(); if ( ! empty( $coauthor_data ) ) { @@ -438,39 +439,41 @@ function get_the_coauthor_meta( $field, $user_id = false ) { } } - $meta = array(); + $meta = array(); if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) { $field = 'user_' . $field; } - foreach ( $coauthors as $coauthor ) { - $user_id = $coauthor->ID; + foreach ( $coauthors as $coauthor ) { + $user_id = $coauthor->ID; - if ( isset( $coauthor->type ) && 'user_url' === $field ) { - if ( 'guest-author' === $coauthor->type) { + if ( isset( $coauthor->type ) && 'user_url' === $field ) { + if ( 'guest-author' === $coauthor->type ) { $field = 'website'; } - } else if ( 'website' === $field ) { + } + else if ( 'website' === $field ) { $field = 'user_url'; } if ( isset( $coauthor->$field ) ) { $meta[ $user_id ] = $coauthor->$field; - } else { + } + else { $meta[ $user_id ] = ''; } - } + } - return $meta; + return $meta; } function the_coauthor_meta( $field, $user_id = 0 ) { - // TODO: need before after options - $coauthor_meta = get_the_coauthor_meta( $field, $user_id ); + // TODO: need before after options + $coauthor_meta = get_the_coauthor_meta( $field, $user_id ); foreach ( $coauthor_meta as $meta ) { - echo $meta; + echo esc_html( $meta ); } } From da40f56bd9d90c540519281449d04ca7a446564d Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 7 Apr 2018 17:35:36 +0100 Subject: [PATCH 180/231] Release v3.2: Update version numbers etc --- README.md | 14 +++++++------- co-authors-plus.php | 6 +++--- readme.txt | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 43f8e09d..16e9979a 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ * Contributors: batmoo, danielbachhuber, automattic * Tags: authors, users, multiple authors, coauthors, multi-author, publishing -* Tested up to: 4.8 +* Tested up to: 4.9.5 * Requires at least: 4.1 -* Stable tag: 3.2.2 +* Stable tag: 3.3.0 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box -## Description +## Description Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box. Co-authored posts appear on a co-author's archive page and in their feed. Co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is core behavior). @@ -18,7 +18,7 @@ On the frontend, use the [Co-Authors Plus template tags](http://vip.wordpress.co This plugin is an almost complete rewrite of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/) (2007). The original plugin was inspired by the 'Multiple Authors' plugin by Mark Jaquith (2005). -## Frequently Asked Questions +## Frequently Asked Questions * How do I add Co-Authors Plus support to my theme? @@ -28,17 +28,17 @@ If you've just installed Co-Authors Plus, you might notice that the bylines are When a user is deleted from WordPress, they will be removed from all posts for which they are co-authors. If you chose to reassign their posts to another user, that user will be set as the coauthor instead. -* Can I use Co-Authors Plus with WordPress multisite? +* Can I use Co-Authors Plus with WordPress multisite? Yep! Co-Authors Plus can be activated on a site-by-site basis, or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. -* Who needs permission to do what? +* Who needs permission to do what? To assign co-authors to posts, a WordPress user will need the `edit_others_posts` capability. This is typically granted to the Editor role, but can be altered with the `coauthors_plus_edit_authors` filter. To create new guest author profiles, a WordPress will need the `list_users` capability. This is typically granted to the Administrator role, but can be altered with the `coauthors_guest_author_manage_cap` filter. -* Can I easily create a list of all co-authors? +* Can I easily create a list of all co-authors? Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. diff --git a/co-authors-plus.php b/co-authors-plus.php index 939b98f8..fe9aba89 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -3,7 +3,7 @@ Plugin Name: Co-Authors Plus Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/ Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter. -Version: 3.2.2 +Version: 3.3.0 Author: Mohammad Jangda, Daniel Bachhuber, Automattic Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter @@ -32,7 +32,7 @@ Author - user with the role of author */ -define( 'COAUTHORS_PLUS_VERSION', '3.2.2' ); +define( 'COAUTHORS_PLUS_VERSION', '3.3.0' ); require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); @@ -1409,7 +1409,7 @@ public function get_author_term( $coauthor ) { if ( false !== ( $term = wp_cache_get( $cache_key, 'co-authors-plus' ) ) ) { return $term; } - + // use linked user for accurate post count if ( ! empty ( $coauthor->linked_account ) ) { $term = get_term_by( 'slug', 'cap-' . $coauthor->linked_account, $this->coauthor_taxonomy ); diff --git a/readme.txt b/readme.txt index bfe56edf..848eb4bd 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Co-Authors Plus === Contributors: batmoo, danielbachhuber, automattic Tags: authors, users, multiple authors, coauthors, multi-author, publishing -Tested up to: 4.8 +Tested up to: 4.9.5 Requires at least: 4.1 -Stable tag: 3.2.2 +Stable tag: 3.3.0 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box From 492aee6768af0b5d34d140e3f2e117812b5dd9ca Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 7 Apr 2018 18:20:08 +0100 Subject: [PATCH 181/231] Release v3.3: Changelog and props --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ readme.txt | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/README.md b/README.md index 16e9979a..fec0d5c5 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,45 @@ $ wp --url=example.com co-authors-plus create-terms-for-posts ## Changelog ## +**3.3.0 ("Rebecca")** +* Fix private post viewing on front-end #386 +* Reduce amount of sleep #400 +* Author search UX issues #407 +* Remove associated guest user when mapped user id deleted. #414 +* Removed double left join on posts_join_filter #419 +* Fixed WP CLI create-terms-for-posts if no co-authors found #420 +* Pages archive now displays coauthors and quick edit works #422 +* Terminology updated throughout #423 +* Replace hardcoded 'author' with $this->$coauthor_taxonomy #426 +* Move parenthesis to fix esc_html and sprintf #430 +* Added progress to create-guest-authors so users have an idea of how long it will take #431 +* Deleting guest authors is less confusing #432 +* Guest author's featured image is avatar now #433 +* Removed extra image sizing #434 +* Remove duplicated byline #435 +* coauthors_wp_list_authors() has option to list only guest authors now #436 +* remove duplicates from linked accounts on coauthors_wp_list_authors() #437 +* Accurate Guest Author post count on linked accounts #438 +* New README.md #439 +* Filter author archive #441 +* Fix coauthors_links_single() #444 +* Added guest author hooks for create/delete #446 +* Fixes logic for DOING_AUTOSAVE check #450 +* user_login spaces problem when using add_coauthors #453 +* Adding details of filter for slow performance #456 +* Remove redundant test for 404 on Author Archive #457 +* Guest Author Counts are more accurate #461 +* Set $coauthors_loading #468 +* Fix the issue where guest authors with non-ASCII characters can't be used as co-authors #473 +* Fix the issue where incompatibility when `coauthors_auto_apply_template_tags` set to true #474 +* Unit tests/Fix warnings for template tags #475 +* Review and improve test coverage #476 +* Update class-wp-cli.php #480 +* Update .travis.yml file for PHPUnit tests #482 +* Changes to resolve issue #332 about missing coauthor meta #484 + +Props to the many people who helped make this release possible: [catchmyfame](https://github.com/catchmyfame), [danielbachhuber](https://github.com/danielbachhuber), [david-binda](https://github.com/david-binda), [douglas-johnson](https://github.com/douglas-johnson), [castlehouse](https://github.com/castlehouse), [frankar](https://github.com/frankar), [haleeben](https://github.com/haleeben), [jjeaton](https://github.com/jjeaton), [johnbillion](https://github.com/johnbillion), [kevinlisota](https://github.com/kevinlisota), [mattoperry](https://github.com/mattoperry), [mdbitz](https://github.com/mdbitz), [mdchiragpatel](https://github.com/mdchiragpatel), [megfh](https://github.com/megfh), [mjangda](https://github.com/mjangda), [mslinnea](https://github.com/mslinnea), [natebot](https://github.com/natebot), [nickdaugherty](https://github.com/nickdaugherty), [nilzari](https://github.com/nilzari), [philipjohn](https://github.com/philipjohn), [pkevan](https://github.com/pkevan), [rebeccahum](https://github.com/rebeccahum), [ryanmarkel](https://github.com/ryanmarkel), [sanketio](https://github.com/sanketio), [sboisvert](https://github.com/sboisvert), [Spongsta](https://github.com/Spongsta), [srguglielmo](https://github.com/srguglielmo), [timburden](https://github.com/timburden), [trepmal](https://github.com/trepmal), [TylerDurdon](https://github.com/TylerDurdon) + **3.2.2** * Fix broken author ordering in 4.7+ (props mslinnea) * Fix no moderation e-mail bug (props RobjS) diff --git a/readme.txt b/readme.txt index 848eb4bd..5ff5a7ed 100644 --- a/readme.txt +++ b/readme.txt @@ -57,6 +57,43 @@ Bug fixes and minor enhancements == Changelog == += 3.3.0 ("Rebecca") = +* Fix private post viewing on front-end +* Reduce amount of sleep +* Author search UX issues +* Remove associated guest user when mapped user id deleted. +* Removed double left join on posts_join_filter +* Fixed WP CLI create-terms-for-posts if no co-authors found +* Pages archive now displays coauthors and quick edit works +* Terminology updated throughout +* Replace hardcoded 'author' with $this->$coauthor_taxonomy +* Move parenthesis to fix esc_html and sprintf +* Added progress to create-guest-authors so users have an idea of how long it will take +* Deleting guest authors is less confusing +* Guest author's featured image is avatar now +* Removed extra image sizing +* Remove duplicated byline +* coauthors_wp_list_authors() has option to list only guest authors now +* remove duplicates from linked accounts on coauthors_wp_list_authors() +* Accurate Guest Author post count on linked accounts +* New README.md +* Filter author archive +* Fix coauthors_links_single() +* Added guest author hooks for create/delete +* Fixes logic for DOING_AUTOSAVE check +* user_login spaces problem when using add_coauthors +* Adding details of filter for slow performance +* Remove redundant test for 404 on Author Archive +* Guest Author Counts are more accurate +* Set $coauthors_loading +* Fix the issue where guest authors with non-ASCII characters can't be used as co-authors +* Fix the issue where incompatibility when `coauthors_auto_apply_template_tags` set to true +* Unit tests/Fix warnings for template tags +* Review and improve test coverage +* Update class-wp-cli.php +* Update .travis.yml file for PHPUnit tests +* Changes to resolve issue #332 about missing coauthor meta + = 3.2.2 = * Fix broken author ordering in 4.7+ (props mslinnea) * Fix no moderation e-mail bug (props RobjS) From cdb725c77ed5d45a00fec64a018829199e51bada Mon Sep 17 00:00:00 2001 From: sanketio Date: Mon, 9 Apr 2018 22:29:17 +0530 Subject: [PATCH 182/231] Fix failing test cases --- co-authors-plus.php | 2 +- tests/test-template-tags.php | 44 ++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 939b98f8..f7ad5bd2 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1224,7 +1224,7 @@ public function search_authors( $search = '', $ignored_authors = array() ) { /** * Modify get_users() to search display_name instead of user_nicename */ - function action_pre_user_query( &$user_query ) { + function action_pre_user_query( $user_query ) { if ( is_object( $user_query ) ) { $user_query->query_where = str_replace( 'user_nicename LIKE', 'display_name LIKE', $user_query->query_where ); diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 35c1266c..cb02a461 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -352,6 +352,13 @@ public function test_coauthors() { */ public function test_coauthors_posts_links_single() { + global $post; + + // Backing up global post. + $post_backup = $post; + + $post = $this->post; + $author_link = coauthors_posts_links_single( $this->author1 ); $this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $author_link, 'Author link not found.' ); @@ -360,6 +367,9 @@ public function test_coauthors_posts_links_single() { // Here we are checking author name should not be more then one time. // Asserting ">{$this->author1->display_name}<" because "$this->author1->display_name" can be multiple times like in href, title, etc. $this->assertEquals( 1, substr_count( $author_link, ">{$this->author1->display_name}<" ) ); + + // Restore global post from backup. + $post = $post_backup; } /** @@ -571,7 +581,12 @@ public function test_coauthors_emails() { */ public function test_coauthors_links_single_when_guest_author() { - global $authordata; + global $post, $authordata; + + // Backing up global post. + $post_backup = $post; + + $post = $this->post; // Backing up global author data. $authordata_backup = $authordata; @@ -596,6 +611,9 @@ public function test_coauthors_links_single_when_guest_author() { // Restore global author data from backup. $authordata = $authordata_backup; + + // Restore global post from backup. + $post = $post_backup; } /** @@ -605,7 +623,12 @@ public function test_coauthors_links_single_when_guest_author() { */ public function test_coauthors_links_single_author_url_is_set() { - global $authordata; + global $post, $authordata; + + // Backing up global post. + $post_backup = $post; + + $post = $this->post; // Backing up global author data. $authordata_backup = $authordata; @@ -627,6 +650,9 @@ public function test_coauthors_links_single_author_url_is_set() { // Restore global author data from backup. $authordata = $authordata_backup; + + // Restore global post from backup. + $post = $post_backup; } /** @@ -636,12 +662,19 @@ public function test_coauthors_links_single_author_url_is_set() { */ public function test_coauthors_links_single_when_url_not_exist() { - global $authordata; + global $post, $authordata; + + // Backing up global post. + $post_backup = $post; + + $post = $this->post; // Backing up global author data. $authordata_backup = $authordata; - $author_link = coauthors_links_single( $this->author1 ); + $this->editor1->type = 'guest-author'; + + $author_link = coauthors_links_single( $this->editor1 ); $this->assertEmpty( $author_link ); @@ -652,6 +685,9 @@ public function test_coauthors_links_single_when_url_not_exist() { // Restore global author data from backup. $authordata = $authordata_backup; + + // Restore global post from backup. + $post = $post_backup; } /** From 2755efc708de856388b5b136e2499a0ee5602e53 Mon Sep 17 00:00:00 2001 From: Binod Kalathil Date: Sat, 14 Apr 2018 16:06:33 +0530 Subject: [PATCH 183/231] Unexpected output of template tag 'coauthors_links' is resolved by updating conditions The template tag was outputting usernames of guest authors when they do not have a website set in their profile. It will now output guest authors display names as expected. --- template-tags.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/template-tags.php b/template-tags.php index 794c7150..6c3b1576 100644 --- a/template-tags.php +++ b/template-tags.php @@ -420,14 +420,12 @@ function coauthors_emails( $between = null, $betweenLast = null, $before = null, * @return string */ function coauthors_links_single( $author ) { - if ( 'guest-author' === $author->type ) { - if ( get_the_author_meta( 'website' ) ) { - return sprintf( '%s', - esc_url( get_the_author_meta( 'website' ) ), - esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ), - esc_html( get_the_author() ) - ); - } + if ( 'guest-author' === $author->type && get_the_author_meta( 'website' ) ) { + return sprintf( '%s', + esc_url( get_the_author_meta( 'website' ) ), + esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ), + esc_html( get_the_author() ) + ); } elseif ( get_the_author_meta( 'url' ) ) { return sprintf( '%s', From 889f422676ee5593dc0e7e045a023eb37cad7493 Mon Sep 17 00:00:00 2001 From: Binod Kalathil Date: Sun, 15 Apr 2018 16:33:09 +0530 Subject: [PATCH 184/231] Corrected PHPUnit test cases to work with the udpated code A couple of test cases were failing as the return value of a function has changed as per the modifications done for fixing the issue(Issue #469) --- tests/test-template-tags.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index cb02a461..96db23d6 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -593,11 +593,11 @@ public function test_coauthors_links_single_when_guest_author() { $this->author1->type = 'guest-author'; - $this->assertNull( coauthors_links_single( $this->author1 ) ); + $this->assertEquals( get_the_author(), coauthors_links_single( $this->author1 ) ); update_user_meta( $this->author1->ID, 'website', 'example.org' ); - $this->assertNull( coauthors_links_single( $this->author1 ) ); + $this->assertEquals( get_the_author(), coauthors_links_single( $this->author1 ) ); $authordata = $this->author1; $author_link = coauthors_links_single( $this->author1 ); @@ -676,7 +676,7 @@ public function test_coauthors_links_single_when_url_not_exist() { $author_link = coauthors_links_single( $this->editor1 ); - $this->assertEmpty( $author_link ); + $this->assertEquals( get_the_author(), $author_link ); $authordata = $this->author1; $author_link = coauthors_links_single( $this->author1 ); From 533449d2e05678db7947be44b83e44c0067565eb Mon Sep 17 00:00:00 2001 From: Paul Kevan Date: Mon, 16 Apr 2018 11:15:36 +0100 Subject: [PATCH 185/231] Bump last version of WP to 4.8 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c2ca7c6..a0ff2ae8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ matrix: include: # aliased to a recent 5.6.x version - php: "5.6" - env: WP_VERSION=4.6 + env: WP_VERSION=4.8 - php: '5.6' env: @@ -20,13 +20,13 @@ matrix: # aliased to a recent 7.x version - php: '7.0' - env: WP_VERSION=4.6 + env: WP_VERSION=4.8 - php: '7.0' env: WP_VERSION=latest - php: '7.1' - env: WP_VERSION=4.6 + env: WP_VERSION=4.8 - php: '7.1' env: WP_VERSION=latest @@ -53,7 +53,7 @@ before_script: - | if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then composer global require "phpunit/phpunit=4.8.*" - elif [[ ${TRAVIS_PHP_VERSION:0:2} == "7." && ${WP_VERSION} == "4.6" ]]; then + elif [[ ${TRAVIS_PHP_VERSION:0:2} == "7." && ${WP_VERSION} == "4.8" ]]; then composer global require "phpunit/phpunit=5.7.*" fi - | From 869e0601953357c9da7ef7856060ec8eb3442966 Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Tue, 22 May 2018 16:36:26 -0600 Subject: [PATCH 186/231] Revert "Merge pull request #438 from rebeccahum/accurate_guest_post_count" This reverts commit 2953a4cc26ab9d1d46ad25b726b355ab00e39943, reversing changes made to 32c7f09e4aac73c9b59962c21f3a02b4640e96f4. --- co-authors-plus.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c3261ad4..e3c054aa 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1410,19 +1410,10 @@ public function get_author_term( $coauthor ) { return $term; } - // use linked user for accurate post count - if ( ! empty ( $coauthor->linked_account ) ) { - $term = get_term_by( 'slug', 'cap-' . $coauthor->linked_account, $this->coauthor_taxonomy ); - if ( ! $term ) { - $term = get_term_by( 'slug', $coauthor->linked_account, $this->coauthor_taxonomy ); - } - } - else { - // See if the prefixed term is available, otherwise default to just the nicename - $term = get_term_by( 'slug', 'cap-' . $coauthor->user_nicename, $this->coauthor_taxonomy ); - if ( ! $term ) { - $term = get_term_by( 'slug', $coauthor->user_nicename, $this->coauthor_taxonomy ); - } + // See if the prefixed term is available, otherwise default to just the nicename + $term = get_term_by( 'slug', 'cap-' . $coauthor->user_nicename, $this->coauthor_taxonomy ); + if ( ! $term ) { + $term = get_term_by( 'slug', $coauthor->user_nicename, $this->coauthor_taxonomy ); } wp_cache_set( $cache_key, $term, 'co-authors-plus' ); return $term; From fcc1d50551f38fcda429ed322483ed629a8796d7 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Fri, 25 May 2018 11:06:47 -0600 Subject: [PATCH 187/231] Added i18n support to Author title and name for author archive --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e3c054aa..2c139b4a 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1612,7 +1612,7 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy public function filter_author_archive_title() { if ( is_author() ) { $author = sanitize_user( get_query_var( 'author_name' ) ); - return "Author: ". $author; + return sprintf( __( 'Author: %s'), $author); } } } From 9161eb274148662d650c93c99714c8e71d5ad9a0 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Fri, 25 May 2018 12:59:16 -0600 Subject: [PATCH 188/231] changed author display name on author archive page to be Full Name rather than slug --- co-authors-plus.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 2c139b4a..dfa9d77a 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1611,8 +1611,9 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy */ public function filter_author_archive_title() { if ( is_author() ) { - $author = sanitize_user( get_query_var( 'author_name' ) ); - return sprintf( __( 'Author: %s'), $author); + $author_slug = sanitize_user( get_query_var( 'author_name' ) ); + $author = $this->get_coauthor_by( 'user_nicename', $author_slug ); + return sprintf( __( 'Author: %s' ), $author->display_name ); } } } From ec1718fa2d3600c66e6af8adb26cfe1c35e64864 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Sat, 26 May 2018 11:07:43 -0600 Subject: [PATCH 189/231] added check for before using it in query --- co-authors-plus.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e3c054aa..c2771fde 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -725,10 +725,12 @@ function posts_where_filter( $where, $query ) { $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); $current_coauthor_term = $this->get_author_term( $current_coauthor ); - $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\''; - $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR '; + if ( $current_coauthor_term ) { + $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\''; + $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR '; - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + } } $this->having_terms = rtrim( $this->having_terms, ' OR' ); From 65da6c479a1aececcffc7cbd7cc6555459d8ee5d Mon Sep 17 00:00:00 2001 From: blunce24 Date: Mon, 28 May 2018 13:33:17 -0600 Subject: [PATCH 190/231] updated truthiness check for current_coauthor_term object --- co-authors-plus.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c2771fde..c07eb9da 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -725,11 +725,11 @@ function posts_where_filter( $where, $query ) { $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); $current_coauthor_term = $this->get_author_term( $current_coauthor ); - if ( $current_coauthor_term ) { - $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\''; - $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR '; + if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { + $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\''; + $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR '; - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND } } From 2f9c4a1cf44f3af7768adcda8663046149c9fa97 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Mon, 28 May 2018 13:34:57 -0600 Subject: [PATCH 191/231] formatting adjustments --- co-authors-plus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c07eb9da..64c7dc85 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -726,10 +726,10 @@ function posts_where_filter( $where, $query ) { $current_coauthor_term = $this->get_author_term( $current_coauthor ); if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { - $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\''; - $this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR '; + $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \'' . $this->coauthor_taxonomy . '\' AND ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\''; + $this->having_terms .= ' ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\' OR '; - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + $where = preg_replace('/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND } } From 0fd073476d5116ab7d61f08f88bd9b0254a30fb3 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Mon, 28 May 2018 14:00:00 -0600 Subject: [PATCH 192/231] formatting updates --- co-authors-plus.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 64c7dc85..9a46f658 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1,4 +1,4 @@ -get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); - $current_coauthor_term = $this->get_author_term( $current_coauthor ); + $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); + $current_coauthor_term = $this->get_author_term( $current_coauthor ); - if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { - $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \'' . $this->coauthor_taxonomy . '\' AND ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\''; - $this->having_terms .= ' ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\' OR '; + if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { + $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \'' . $this->coauthor_taxonomy . '\' AND ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\''; + $this->having_terms .= ' ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\' OR '; - $where = preg_replace('/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND - } + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, - 1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + } } $this->having_terms = rtrim( $this->having_terms, ' OR' ); From a29b9bda579d3227295b4a688b852dd6543b82f1 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Mon, 28 May 2018 14:07:10 -0600 Subject: [PATCH 193/231] allow PHPCS inspection of file --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 9a46f658..e2e0b145 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1,4 +1,4 @@ - Date: Tue, 29 May 2018 11:22:18 +0200 Subject: [PATCH 194/231] Replacing search_fields argument (non-existent) in get_users() call with search_columns. --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e3c054aa..a6cb816d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1166,7 +1166,7 @@ public function search_authors( $search = '', $ignored_authors = array() ) { $args = array( 'count_total' => false, 'search' => sprintf( '*%s*', $search ), - 'search_fields' => array( + 'search_columns' => array( 'ID', 'display_name', 'user_email', From dece50b89a9859cc48a7e25ae5f11da7cfe473ac Mon Sep 17 00:00:00 2001 From: blunce24 Date: Tue, 29 May 2018 13:51:25 -0600 Subject: [PATCH 195/231] fixed tab issue --- co-authors-plus.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e2e0b145..279687a3 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -722,15 +722,15 @@ function posts_where_filter( $where, $query ) { is_author() && get_queried_object_id() != get_current_user_id() ) { - $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); - $current_coauthor_term = $this->get_author_term( $current_coauthor ); + $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); + $current_coauthor_term = $this->get_author_term( $current_coauthor ); - if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { - $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \'' . $this->coauthor_taxonomy . '\' AND ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\''; - $this->having_terms .= ' ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\' OR '; + if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { + $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \'' . $this->coauthor_taxonomy . '\' AND ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\''; + $this->having_terms .= ' ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\' OR '; + } - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, - 1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND - } + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, - 1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND} } $this->having_terms = rtrim( $this->having_terms, ' OR' ); From 8d585bfb418a292602e7e55ccbf8a01adb90d8d2 Mon Sep 17 00:00:00 2001 From: blunce24 Date: Tue, 29 May 2018 14:10:03 -0600 Subject: [PATCH 196/231] changed check on coauthor term to be more concise --- co-authors-plus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 279687a3..3e9de717 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -725,12 +725,12 @@ function posts_where_filter( $where, $query ) { $current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename ); $current_coauthor_term = $this->get_author_term( $current_coauthor ); - if ( is_object( $current_coauthor_term ) && wpcom_vip_term_exists( $current_coauthor_term->term_id ) ) { + if ( is_a( $current_coauthor_term, 'WP_Term' ) ) { $current_user_query = $wpdb->term_taxonomy . '.taxonomy = \'' . $this->coauthor_taxonomy . '\' AND ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\''; $this->having_terms .= ' ' . $wpdb->term_taxonomy . '.term_id = \'' . $current_coauthor_term->term_id . '\' OR '; - } - $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, - 1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND} + $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, - 1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND} + } } $this->having_terms = rtrim( $this->having_terms, ' OR' ); From 39da33cd28a5e7aa2331ee79afc6f2b12ce040a4 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Wed, 30 May 2018 15:51:10 -0400 Subject: [PATCH 197/231] Add isset() checkes to post registration --- php/class-coauthors-guest-authors.php | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 82e455a5..20fef889 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -95,25 +95,25 @@ function __construct() { 'remove_featured_image' => __( 'Remove Avatar', 'co-authors-plus' ), ) ); - // Register a post type to store our guest authors + // Register a post type to store our guest authors $args = array( 'label' => $this->labels['singular'], 'labels' => array( - 'name' => $this->labels['plural'], - 'singular_name' => $this->labels['singular'], - 'add_new' => _x( 'Add New', 'guest author', 'co-authors-plus' ), - 'all_items' => $this->labels['all_items'], - 'add_new_item' => $this->labels['add_new_item'], - 'edit_item' => $this->labels['edit_item'], - 'new_item' => $this->labels['new_item'], - 'view_item' => $this->labels['view_item'], - 'search_items' => $this->labels['search_items'], - 'not_found' => $this->labels['not_found'], - 'not_found_in_trash' => $this->labels['not_found_in_trash'], - 'featured_image' => $this->labels['featured_image'], - 'set_featured_image' => $this->labels['set_featured_image'], - 'use_featured_image' => $this->labels['use_featured_image'], - 'remove_featured_image' => $this->labels['remove_featured_image'] + 'name' => isset( $this->labels['plural'] ) ? $this->labels['plural'] : '', + 'singular_name' => isset( $this->labels['singular'] ) ? $this->labels['singular'] : '', + 'add_new' => _x( 'Add New', 'guest author', 'co-authors-plus' ), + 'all_items' => isset( $this->labels['all_items'] ) ? $this->labels['all_items'] : '', + 'add_new_item' => isset( $this->labels['add_new_item'] ) ? $this->labels['add_new_item'] : '', + 'edit_item' => isset( $this->labels['edit_item'] ) ? $this->labels['edit_item'] : '', + 'new_item' => isset( $this->labels['new_item'] ) ? $this->labels['new_item'] : '', + 'view_item' => isset( $this->labels['view_item'] ) ? $this->labels['view_item'] : '', + 'search_items' => isset( $this->labels['search_items'] ) ? $this->labels['search_items'] : '', + 'not_found' => isset( $this->labels['not_found'] ) ? $this->labels['not_found'] : '', + 'not_found_in_trash' => isset( $this->labels['not_found_in_trash'] ) ? $this->labels['not_found_in_trash'] : '', + 'featured_image' => isset( $this->labels['featured_image'] ) ? $this->labels['featured_image'] : '', + 'set_featured_image' => isset( $this->labels['set_featured_image'] ) ? $this->labels['set_featured_image'] : '', + 'use_featured_image' => isset( $this->labels['use_featured_image'] ) ? $this->labels['use_featured_image'] : '', + 'remove_featured_image' => isset( $this->labels['remove_featured_image'] ) ? $this->labels['remove_featured_image'] : '', ), 'public' => true, 'publicly_queryable' => false, From 290b18e4d9a3c41608ac4778d0ea9423a78e2f86 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Wed, 30 May 2018 15:51:21 -0400 Subject: [PATCH 198/231] remove trailing whitespace --- php/class-coauthors-guest-authors.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 20fef889..2bcf3aae 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -493,9 +493,9 @@ function view_guest_authors_list() { } $post_count_message .= $note; } - $allowed_html = array( - 'p' => array( - 'class' => array(), + $allowed_html = array( + 'p' => array( + 'class' => array(), ), ); echo wp_kses( $post_count_message, $allowed_html ); From a8ad96926e61f3d3c464055a27c18ee305557dc7 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Thu, 31 May 2018 11:59:21 +0200 Subject: [PATCH 199/231] Updated readme with FAQ on how to disable Guest Authors. Fix #122. --- readme.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.txt b/readme.txt index 5ff5a7ed..fcc56a8c 100644 --- a/readme.txt +++ b/readme.txt @@ -41,6 +41,11 @@ To create new guest author profiles, a WordPress will need the 'list_users' capa Yep! There's a template tag called `coauthors_wp_list_authors()` that accepts many of the same arguments as `wp_list_authors()`. Look in template-tags.php for more details. += Can I disable Guest Authors? + +Yep! Guest authors can be disabled entirely through an apt filter. Having the following line load on `init` will do the trick: +`add_filter( 'coauthors_guest_authors_enabled', '__return_false' )` + == Upgrade Notice == = 3.1 = From 70a56466fb6e494fbf8ec508dfd38843fecee7a4 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Mon, 4 Jun 2018 08:53:34 +0200 Subject: [PATCH 200/231] Fix test_coauthors_links_single_when_guets_author(), which was wrongly passing. The test passed because was updating a postmeta instead of the user record in wp_users, thus subsequent assertions all passed simply because no real edit had been done. When making the edit for real, the test would fail in several places, so tweaks were needed to fix its behavior. --- tests/test-template-tags.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/test-template-tags.php b/tests/test-template-tags.php index 96db23d6..db04488c 100644 --- a/tests/test-template-tags.php +++ b/tests/test-template-tags.php @@ -590,20 +590,23 @@ public function test_coauthors_links_single_when_guest_author() { // Backing up global author data. $authordata_backup = $authordata; + $authordata = $this->author1; + // Shows that it's necessary to set $authordata to $this->author1 + $this->assertEquals( $authordata, $this->author1, 'Global $authordata not matching expected $this->author1.' ); + $this->author1->type = 'guest-author'; - $this->assertEquals( get_the_author(), coauthors_links_single( $this->author1 ) ); + $this->assertEquals( get_the_author_link(), coauthors_links_single( $this->author1 ), 'Co-Author link generation differs from Core author link one (without user_url)' ); + + wp_update_user( array( 'ID' => $this->author1->ID, 'user_url' => 'example.org' ) ); + $authordata = get_userdata( $this->author1->ID ); // Because wp_update_user flushes cache, but does not update global var + + $this->assertEquals( get_the_author_link(), coauthors_links_single( $this->author1 ), 'Co-Author link generation differs from Core author link one (with user_url)' ); - update_user_meta( $this->author1->ID, 'website', 'example.org' ); - - $this->assertEquals( get_the_author(), coauthors_links_single( $this->author1 ) ); - - $authordata = $this->author1; $author_link = coauthors_links_single( $this->author1 ); - - $this->assertContains( get_the_author_meta( 'website' ), $author_link, 'Author link not found.' ); - $this->assertContains( get_the_author(), $author_link, 'Author name not found.' ); + $this->assertContains( get_the_author_meta( 'url' ), $author_link, 'Author url not found in link.' ); + $this->assertContains( get_the_author(), $author_link, 'Author name not found in link.' ); // Here we are checking author name should not be more then one time. // Asserting ">get_the_author()<" because "get_the_author()" can be multiple times like in href, title, etc. From c7f573a11a8ffa243e16c52de029aefe1898aedf Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Mon, 4 Jun 2018 09:12:08 +0200 Subject: [PATCH 201/231] Updated coauthors_links_single so that CAP coauthor link matches Core author link structure. --- template-tags.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template-tags.php b/template-tags.php index 6c3b1576..43d11be2 100644 --- a/template-tags.php +++ b/template-tags.php @@ -421,14 +421,14 @@ function coauthors_emails( $between = null, $betweenLast = null, $before = null, */ function coauthors_links_single( $author ) { if ( 'guest-author' === $author->type && get_the_author_meta( 'website' ) ) { - return sprintf( '%s', + return sprintf( '%s', esc_url( get_the_author_meta( 'website' ) ), esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ), esc_html( get_the_author() ) ); } elseif ( get_the_author_meta( 'url' ) ) { - return sprintf( '%s', + return sprintf( '%s', esc_url( get_the_author_meta( 'url' ) ), esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ), esc_html( get_the_author() ) From c5c9d43d1bfb52458ba5e04a8831f30c474d5c8c Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Tue, 5 Jun 2018 08:34:11 +0200 Subject: [PATCH 202/231] Removed function action_pre_user_query and its hooks, as it was obsolete --- co-authors-plus.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e3c054aa..58ac8912 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1174,9 +1174,7 @@ public function search_authors( $search = '', $ignored_authors = array() ) { ), 'fields' => 'all_with_meta', ); - add_action( 'pre_user_query', array( $this, 'action_pre_user_query' ) ); $found_users = get_users( $args ); - remove_action( 'pre_user_query', array( $this, 'action_pre_user_query' ) ); foreach ( $found_users as $found_user ) { $term = $this->get_author_term( $found_user ); @@ -1221,17 +1219,6 @@ public function search_authors( $search = '', $ignored_authors = array() ) { return (array) $found_users; } - /** - * Modify get_users() to search display_name instead of user_nicename - */ - function action_pre_user_query( $user_query ) { - - if ( is_object( $user_query ) ) { - $user_query->query_where = str_replace( 'user_nicename LIKE', 'display_name LIKE', $user_query->query_where ); - } - - } - /** * Modify get_terms() to LIKE against the term description instead of the term name * From 14c25211456028014b9b30b924b1ba4d1c7510df Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Tue, 5 Jun 2018 09:36:20 +0200 Subject: [PATCH 203/231] Fix possible discrepancy in author search due to mismatched use of user_login and user_nicename. --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index e3c054aa..387a7936 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1212,7 +1212,7 @@ public function search_authors( $search = '', $ignored_authors = array() ) { $ignored_authors = apply_filters( 'coauthors_edit_ignored_authors', $ignored_authors ); foreach ( $found_users as $key => $found_user ) { // Make sure the user is contributor and above (or a custom cap) - if ( in_array( $found_user->user_login, $ignored_authors ) ) { + if ( in_array( $found_user->user_nicename, $ignored_authors ) ) { //AJAX sends a list of already present *users_nicenames* unset( $found_users[ $key ] ); } else if ( 'wpuser' === $found_user->type && false === $found_user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { unset( $found_users[ $key ] ); From 5684a261ebe9f40e160525a07172a19ed4abfa19 Mon Sep 17 00:00:00 2001 From: Jacob Arriola Date: Tue, 5 Jun 2018 14:13:11 -0700 Subject: [PATCH 204/231] Only filter author template for title Repro steps: - in `archive.php`, use `the_archive_title()` method - load a category archive page Expected results: "Category: category_name" Actual results: null Notes: The `filter_author_archive_title()` function is hooked to the `get_the_archive_title` filter, which can run in other archive templates such as `category` or `tag`. When run in such a template, the function does not return the `$title` parameter, resulting in `null`. --- co-authors-plus.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index dde170db..cf8afb17 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1610,13 +1610,22 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy /** * Filter of the header of author archive pages to correctly display author. + * + * @param $title + * + * @return string */ - public function filter_author_archive_title() { - if ( is_author() ) { - $author_slug = sanitize_user( get_query_var( 'author_name' ) ); - $author = $this->get_coauthor_by( 'user_nicename', $author_slug ); - return sprintf( __( 'Author: %s' ), $author->display_name ); + public function filter_author_archive_title( $title ) { + + // Bail if not an author archive template + if ( ! is_author() ) { + return $title; } + + $author_slug = sanitize_user( get_query_var( 'author_name' ) ); + $author = $this->get_coauthor_by( 'user_nicename', $author_slug ); + + return sprintf( __( 'Author: %s' ), $author->display_name ); } } From 8b5ad373973151bc5d6f83cf52b1593742206987 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 8 Jun 2018 11:33:38 +0200 Subject: [PATCH 205/231] Removed whole setUp function, which contained the two filters that made WP queries non-TEMPORARY --- tests/test-author-queried-object.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/test-author-queried-object.php b/tests/test-author-queried-object.php index bba21db9..3ae86c50 100644 --- a/tests/test-author-queried-object.php +++ b/tests/test-author-queried-object.php @@ -5,20 +5,6 @@ class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase { - /** - * Set up for test - * - * Don't create tables as 'temporary'. - * - * @see https://github.com/Automattic/Co-Authors-Plus/issues/398 - */ - function setUp() { - parent::setUp(); - - remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); - remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); - } - /** * On author pages, the queried object should only be set * to a user that's not a member of the blog if they From 0c623dcb0adf1d4b7eb534d94eb85e5ca8142d03 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 8 Jun 2018 16:25:04 +0200 Subject: [PATCH 206/231] Skipping irrelevant cap checks through list of allowed caps. --- co-authors-plus.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index e3c054aa..3f29bc86 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -64,6 +64,8 @@ class CoAuthors_Plus { var $having_terms = ''; + var $to_be_filtered_caps = array(); + /** * __construct() */ @@ -1349,6 +1351,31 @@ public function is_valid_page() { return (bool) in_array( $pagenow, $this->_pages_whitelist ); } + /** + * Builds list of capabilities that CAP should filter. + * + * Will only work after $this->supported_post_types has been populated. + * Will only run once per request, and then cache the result. + * + * @return array caps that CAP should filter + */ + public function get_to_be_filtered_caps() { + if( ! empty( $this->supported_post_types ) && empty( $this->to_be_filtered_caps ) ) { + $this->to_be_filtered_caps[] = 'edit_post'; // Need to filter this too, unfortunately: http://core.trac.wordpress.org/ticket/22415 + + foreach( $this->supported_post_types as $single ) { + $obj = get_post_type_object( $single ); + + $this->to_be_filtered_caps[] = $obj->cap->edit_post; + $this->to_be_filtered_caps[] = $obj->cap->edit_others_posts; // This as well: http://core.trac.wordpress.org/ticket/22417 + } + + $this->to_be_filtered_caps = array_unique( $this->to_be_filtered_caps ); + } + + return $this->to_be_filtered_caps; + } + /** * Allows guest authors to edit the post they're co-authors of */ @@ -1358,11 +1385,16 @@ function filter_user_has_cap( $allcaps, $caps, $args ) { $user_id = isset( $args[1] ) ? $args[1] : 0; $post_id = isset( $args[2] ) ? $args[2] : 0; + if( ! in_array( $cap, $this->get_to_be_filtered_caps(), true ) ) { + return $allcaps; + } + $obj = get_post_type_object( get_post_type( $post_id ) ); if ( ! $obj || 'revision' == $obj->name ) { return $allcaps; } + //Even though we bail if cap is not among the to_be_filtered ones, there is a time in early request processing in which that list is not yet available, so the following block is needed $caps_to_modify = array( $obj->cap->edit_post, 'edit_post', // Need to filter this too, unfortunately: http://core.trac.wordpress.org/ticket/22415 From 2026d4c72856e59b6ecc887324f8ca822bcff445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Valney?= Date: Wed, 13 Jun 2018 12:21:31 -0300 Subject: [PATCH 207/231] Allow guest authors have personal data exported (#528) * [Style] Identation changed to tab * [Feat] Added personal data exporter to guest authors * [Feat] Added a filter to allow third part plugins add guest author data * [Style] WPCS fixes * [Fix] Filter name changed * [Style] WPCS fixes * [Fix] Filter name changed --- co-authors-plus.php | 20 +++--- php/class-coauthors-guest-authors.php | 94 +++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 10 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 0f7cfb30..8e68045d 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1595,16 +1595,16 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy } - /** - * Filter of the header of author archive pages to correctly display author. - */ - public function filter_author_archive_title() { - if ( is_author() ) { - $author_slug = sanitize_user( get_query_var( 'author_name' ) ); - $author = $this->get_coauthor_by( 'user_nicename', $author_slug ); - return sprintf( __( 'Author: %s' ), $author->display_name ); - } - } + /** + * Filter of the header of author archive pages to correctly display author. + */ + public function filter_author_archive_title() { + if ( is_author() ) { + $author_slug = sanitize_user( get_query_var( 'author_name' ) ); + $author = $this->get_coauthor_by( 'user_nicename', $author_slug ); + return sprintf( __( 'Author: %s' ), $author->display_name ); + } + } } global $coauthors_plus; diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 2bcf3aae..fbdf7c31 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -69,6 +69,9 @@ function __construct() { // Add support for featured thumbnails that we can use for guest author avatars add_filter( 'get_avatar', array( $this, 'filter_get_avatar' ),10 ,5 ); + // Add a Personal Data Exporter to guest authors + add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_personal_data_exporter' ), 1 ); + // Allow users to change where this is placed in the WordPress admin $this->parent_page = apply_filters( 'coauthors_guest_author_parent_page', $this->parent_page ); @@ -1503,4 +1506,95 @@ public function filter_author_feed_link( $feed_link, $feed ) { return $link; } + + /** + * Filter Personal Data Exporters to add Guest Author exporter + * + * @since 3.3.1 + */ + public function filter_personal_data_exporter( $exporters ) { + $exporters['cap-guest-author'] = array( + 'exporter_friendly_name' => __( 'Guest Author', 'co-authors-plus' ), + 'callback' => array( $this, 'personal_data_exporter' ), + ); + + return $exporters; + } + + /** + * Finds and exports personal data associated with an email address for guest authors + * + * @since 3.3.1 + * + * @param string $email_address The guest author email address. + * @return array An array of personal data. + */ + public function personal_data_exporter( $email_address ) { + $email_address = trim( $email_address ); + + $data_to_export = array(); + + $author = $this->get_guest_author_by( 'user_email', $email_address ); + + if ( ! $author ) { + return array( + 'data' => array(), + 'done' => true, + ); + } + + $author_data = array( + 'ID' => __( 'ID', 'co-authors-plus' ), + 'user_login' => __( 'Login Name', 'co-authors-plus' ), + 'display_name' => __( 'Display Name', 'co-authors-plus' ), + 'user_email' => __( 'Email', 'co-authors-plus' ), + 'first_name' => __( 'First Name', 'co-authors-plus' ), + 'last_name' => __( 'Last Name', 'co-authors-plus' ), + 'website' => __( 'Website', 'co-authors-plus' ), + 'aim' => __( 'AIM', 'co-authors-plus' ), + 'yahooim' => __( 'Yahoo IM', 'co-authors-plus' ), + 'jabber' => __( 'Jabber / Google Talk', 'co-authors-plus' ), + 'description' => __( 'Biographical Info', 'co-authors-plus' ), + ); + + $author_data_to_export = array(); + + foreach ( $author_data as $key => $name ) { + if ( empty( $author->$key ) ) { + continue; + } + + $author_data_to_export[] = array( + 'name' => $name, + 'value' => $author->$key, + ); + } + + /** + * Filters extra data to allow plugins add data related to guest author + * + * @since 3.3.1 + * + * @param array $extra_data A empty array to be populated with extra data + * @param int $author->ID The guest author ID + * @param string $email_address The guest author email address + */ + $extra_data = apply_filters( 'coauthors_guest_author_personal_export_extra_data', [], $author->ID, $email_address ); + + if ( is_array( $extra_data ) && ! empty( $extra_data ) ) { + $author_data_to_export = array_merge( $author_data_to_export, $extra_data ); + } + + $data_to_export[] = array( + 'group_id' => 'cap-guest-author', + 'group_label' => __( 'Guest Author', 'co-authors-plus' ), + 'item_id' => "cap-guest-author-{$author->ID}", + 'data' => $author_data_to_export, + ); + + return array( + 'data' => $data_to_export, + 'done' => true, + ); + } } From 79388530749428514b2049ed3a40b7ea5aaa989c Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Thu, 14 Jun 2018 11:25:31 +0200 Subject: [PATCH 208/231] Updated tests to search_authors() to use assertArrayNotHasKey instead of assertNotContains --- tests/test-coauthors-plus.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 68d7ecb6..caa3d5c4 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -367,7 +367,7 @@ public function test_search_authors_no_args() { $authors = $coauthors_plus->search_authors(); $this->assertNotEmpty( $authors ); - $this->assertNotContains( $subscriber1->user_login, $authors ); + $this->assertArrayNotHasKey( $subscriber1->user_login, $authors ); // Checks when search term is empty and any contributor exists. $contributor1 = $this->factory->user->create_and_get( array( @@ -397,32 +397,32 @@ public function test_search_authors_when_search_keyword_provided() { $this->assertNotEmpty( $authors ); $this->assertArrayHasKey( $this->author1->user_login, $authors ); - $this->assertNotContains( $this->editor1->user_login, $authors ); - $this->assertNotContains( 'admin', $authors ); + $this->assertArrayNotHasKey( $this->editor1->user_login, $authors ); + $this->assertArrayNotHasKey( 'admin', $authors ); // Checks when author searched using display_name. $authors = $coauthors_plus->search_authors( $this->author1->display_name ); $this->assertNotEmpty( $authors ); $this->assertArrayHasKey( $this->author1->user_login, $authors ); - $this->assertNotContains( $this->editor1->user_login, $authors ); - $this->assertNotContains( 'admin', $authors ); + $this->assertArrayNotHasKey( $this->editor1->user_login, $authors ); + $this->assertArrayNotHasKey( 'admin', $authors ); // Checks when author searched using user_email. $authors = $coauthors_plus->search_authors( $this->author1->user_email ); $this->assertNotEmpty( $authors ); $this->assertArrayHasKey( $this->author1->user_login, $authors ); - $this->assertNotContains( $this->editor1->user_login, $authors ); - $this->assertNotContains( 'admin', $authors ); + $this->assertArrayNotHasKey( $this->editor1->user_login, $authors ); + $this->assertArrayNotHasKey( 'admin', $authors ); // Checks when author searched using user_login. $authors = $coauthors_plus->search_authors( $this->author1->user_login ); $this->assertNotEmpty( $authors ); $this->assertArrayHasKey( $this->author1->user_login, $authors ); - $this->assertNotContains( $this->editor1->user_login, $authors ); - $this->assertNotContains( 'admin', $authors ); + $this->assertArrayNotHasKey( $this->editor1->user_login, $authors ); + $this->assertArrayNotHasKey( 'admin', $authors ); // Checks when any subscriber exists using ID but not author. $subscriber1 = $this->factory->user->create_and_get( array( @@ -447,7 +447,7 @@ public function test_search_authors_when_ignored_authors_provided() { $authors = $coauthors_plus->search_authors( '', $ignored_authors ); $this->assertNotEmpty( $authors ); - $this->assertNotContains( $this->author1->user_login, $authors ); + $this->assertArrayNotHasKey( $this->author1->user_login, $authors ); // Checks when ignoring author1 but also exists one more author with similar kind of data. $author2 = $this->factory->user->create_and_get( array( @@ -457,15 +457,15 @@ public function test_search_authors_when_ignored_authors_provided() { $authors = $coauthors_plus->search_authors( '', $ignored_authors ); $this->assertNotEmpty( $authors ); - $this->assertNotContains( $this->author1->user_login, $authors ); + $this->assertArrayNotHasKey( $this->author1->user_login, $authors ); $this->assertArrayHasKey( $author2->user_login, $authors ); // Ignoring multiple authors. $authors = $coauthors_plus->search_authors( '', array( $this->author1->user_login, $author2->user_login ) ); $this->assertNotEmpty( $authors ); - $this->assertNotContains( $this->author1->user_login, $authors ); - $this->assertNotContains( $author2->user_login, $authors ); + $this->assertArrayNotHasKey( $this->author1->user_login, $authors ); + $this->assertArrayNotHasKey( $author2->user_login, $authors ); } /** @@ -491,7 +491,7 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov $authors = $coauthors_plus->search_authors( 'author', $ignored_authors ); $this->assertNotEmpty( $authors ); - $this->assertNotContains( $this->author1->user_login, $authors ); + $this->assertArrayNotHasKey( $this->author1->user_login, $authors ); $this->assertArrayHasKey( $author2->user_login, $authors ); } From 2be4599b7123114be77a03ab3b5ec673e2ed6782 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 15 Jun 2018 15:42:48 +0200 Subject: [PATCH 209/231] Re-enabled Test_Author_Queries->test__author_arg__user_is_coauthor__author_arg() --- tests/test-author-queries.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-author-queries.php b/tests/test-author-queries.php index d6d58c7a..2f50f418 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queries.php @@ -60,8 +60,6 @@ public function test__author_name_arg__user_is_coauthor() { } public function test__author_arg__user_is_coauthor__author_arg() { - return; // TODO: re-enable; fails currently because WordPress generates query as `post_author IN (id)` which doesn't match our regex in the posts_where filter. - $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); $author1 = get_userdata( $author1_id ); $author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) ); From d55979987d528689c462f452e9de5e60e3a0a727 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 15 Jun 2018 15:43:41 +0200 Subject: [PATCH 210/231] Re-enabled Test_Author_Queries->tests__author_name_arg_plus_tax_query__is_coauthor() --- tests/test-author-queries.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-author-queries.php b/tests/test-author-queries.php index 2f50f418..7d0453ba 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queries.php @@ -101,8 +101,6 @@ public function test__author_name_arg_plus_tax_query__user_is_post_author() { } public function tests__author_name_arg_plus_tax_query__is_coauthor() { - return; // TODO: re-enable; fails currently because our posts_join_filter doesn't add an exclusive JOIN on relationships + taxonomy to match the query mods we make. We'd need aliased JOINs on relationships + taxonomy on top of the JOIN that the tax query already adds. - $author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) ); $author1 = get_userdata( $author1_id ); $author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) ); From 08902e5f8ad3d8503f53dff09a86f39c70b37d8c Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Mon, 18 Jun 2018 07:57:11 +0200 Subject: [PATCH 211/231] Improved inline doc --- co-authors-plus.php | 1 + 1 file changed, 1 insertion(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index e7d972dc..d34101c9 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1345,6 +1345,7 @@ public function is_valid_page() { * * Will only work after $this->supported_post_types has been populated. * Will only run once per request, and then cache the result. + * The result is cached in $this->to_be_filtered_caps since CoAuthors_Plus is only instantiated once and stored as a global. * * @return array caps that CAP should filter */ From 96a0efa50a27893ba282d3cacb0947455833cb46 Mon Sep 17 00:00:00 2001 From: Pete DeMarte Date: Mon, 18 Jun 2018 14:08:41 -0400 Subject: [PATCH 212/231] Add post type parameter to the Mine link, so it works for Pages --- co-authors-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 8e68045d..2a681dd5 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1287,7 +1287,7 @@ function filter_views( $views ) { 'author_name' => wp_get_current_user()->user_nicename, ); if ( 'post' != get_post_type() ) { - $mine_args['post_type'] = get_post_type(); + $mine_args['post_type'] = get_current_screen()->post_type; } if ( ! empty( $_REQUEST['author_name'] ) && wp_get_current_user()->user_nicename == $_REQUEST['author_name'] ) { $class = ' class="current"'; From 7a702bdc9815c05d1c310d3f4a8f32d682793460 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 6 Jul 2018 13:00:36 +0200 Subject: [PATCH 213/231] Changed get_user_by('slug' to get_user_by('login' when using linked_account --- php/class-coauthors-wp-list-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index a1f5046b..8c1f9773 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -253,7 +253,7 @@ function column_posts( $item ) { $term = $coauthors_plus->get_author_term( $item ); $guest_term = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy ); if ( ! empty( $item->linked_account ) && $guest_term->count ) { - $count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID ); + $count = count_user_posts( get_user_by( 'login', $item->linked_account )->ID ); } elseif ( $term ) { $count = $term->count; } else { From ecf869994b79e2e90976aa293bc3f7a861509358 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Tue, 17 Jul 2018 09:46:32 +0100 Subject: [PATCH 214/231] Only using new `cap-` prefixed term when counting user posts. --- co-authors-plus.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 4154a9c1..7f2c976c 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -994,23 +994,19 @@ function filter_wp_get_object_terms( $terms, $object_ids, $taxonomies, $args ) { } /** - * Filter the count_users_posts() core function to include our correct count + * Filter the count_users_posts() core function to include our correct count. + * + * @param int $count Post count + * @param int $user_id WP user ID + * @return int Post count */ function filter_count_user_posts( $count, $user_id ) { $user = get_userdata( $user_id ); - $user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename ); $term = $this->get_author_term( $user ); - $guest_term = get_term_by( 'slug', 'cap-' . $user->user_nicename, $this->coauthor_taxonomy ); - // Only modify the count if it has a linked account with posts or the author exists as a term - if ( $user->linked_account && $guest_term->count ) { - if ( $term && ! is_wp_error( $term )) { - $count = $guest_term->count + $term->count; - } else { - $count = $guest_term->count; - } - } elseif ( $term && ! is_wp_error( $term ) ) { + + if ( $term && ! is_wp_error( $term ) ) { $count = $term->count; } From f3e433357a657b7f4b5dbf8f4d58c91c927e90b5 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 18 Jul 2018 09:12:25 +0100 Subject: [PATCH 215/231] $ignored_authors in search should use user_nicename, not login. --- tests/test-coauthors-plus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index caa3d5c4..44b6f106 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -442,7 +442,7 @@ public function test_search_authors_when_ignored_authors_provided() { global $coauthors_plus; // Ignoring single author. - $ignored_authors = array( $this->author1->user_login ); + $ignored_authors = array( $this->author1->user_nicename ); $authors = $coauthors_plus->search_authors( '', $ignored_authors ); @@ -461,7 +461,7 @@ public function test_search_authors_when_ignored_authors_provided() { $this->assertArrayHasKey( $author2->user_login, $authors ); // Ignoring multiple authors. - $authors = $coauthors_plus->search_authors( '', array( $this->author1->user_login, $author2->user_login ) ); + $authors = $coauthors_plus->search_authors( '', array( $this->author1->user_nicename, $author2->user_nicename ) ); $this->assertNotEmpty( $authors ); $this->assertArrayNotHasKey( $this->author1->user_login, $authors ); @@ -478,7 +478,7 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov global $coauthors_plus; // Checks when ignoring author1. - $ignored_authors = array( $this->author1->user_login ); + $ignored_authors = array( $this->author1->user_nicename ); $this->assertEmpty( $coauthors_plus->search_authors( $this->author1->ID, $ignored_authors ) ); From c2e2df01a19012945367c590b152bd3c24eb2f90 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Thu, 26 Jul 2018 13:56:30 -0300 Subject: [PATCH 216/231] Added role whitelist to internals of wp-cli guest author generation command. Previously, as noted in https://github.com/Automattic/Co-Authors-Plus/issues/553, `wp co-authors-plus create-guest-authors` created a guest author for every user in the database. This was a massive performance suck, as well as being largely unnecessary. Adding a subscriber as a guest author is not a common use case. Now, only users having the role of administrator, editor, and author have guest authors generated for them. The query to filter users by role is a touch heavy (it performs LIKEs on meta values), but testing it on a site with 1000 users showed no major issues. It was also compared to simply querying all the users, and doing the filtering in PHP. Head to head, there was no significant difference in performance between the two approaches, and using the WordPress API is always a better bet than writing your own one-off custom filter algorithm. --- php/class-wp-cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 7a3c936f..5bd3391d 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -25,7 +25,7 @@ public function create_guest_authors( $args, $assoc_args ) { ); $this->args = wp_parse_args( $assoc_args, $defaults ); - $users = get_users(); + $users = get_users( array( 'role__in' => array( 'administrator', 'editor', 'author' ) ) ); $created = 0; $skipped = 0; $progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) ); From 579967e9f4bcc96c75872e7f44328017ccc0c88d Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Fri, 27 Jul 2018 14:37:52 -0300 Subject: [PATCH 217/231] Add cli option to allow users to set custom role whitelist. The option defaults to creating guest authors for administrators, editors, authors, and contributors. Roles are provided in a comma separated list such as `--roles=author,freelancer`. If the user provides a role that does not exist in their instance, execution is halted and an error is displayed such as `Role freelancer does not exist.`. This error message is made available for translation. --- languages/co-authors-plus.pot | 393 ++++++++++++++++++---------------- php/class-wp-cli.php | 36 +++- 2 files changed, 242 insertions(+), 187 deletions(-) mode change 100755 => 100644 languages/co-authors-plus.pot diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot old mode 100755 new mode 100644 index 2374c3d7..e3cfd99a --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -1,560 +1,587 @@ -# Copyright (C) 2014 Co-Authors Plus +# Copyright (C) 2018 Co-Authors Plus # This file is distributed under the same license as the Co-Authors Plus package. msgid "" msgstr "" -"Project-Id-Version: Co-Authors Plus 3.1-beta\n" -"Report-Msgid-Bugs-To: http://wordpress.org/tag/co-authors-plus\n" -"POT-Creation-Date: 2014-03-17 15:59:18+00:00\n" +"Project-Id-Version: Co-Authors Plus 3.3.0\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" +"POT-Creation-Date: 2018-07-27 17:27:25+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" -#: co-authors-plus.php:300 co-authors-plus.php:401 co-authors-plus.php:487 -#: co-authors-plus.php:1290 +#: co-authors-plus.php:335 co-authors-plus.php:439 co-authors-plus.php:527 +#: co-authors-plus.php:1496 msgid "Authors" msgstr "" -#: co-authors-plus.php:362 +#: co-authors-plus.php:398 msgid "" "Note: To edit post authors, please enable javascript or use " "a javascript-capable browser" msgstr "" -#: co-authors-plus.php:369 co-authors-plus.php:489 co-authors-plus.php:1095 +#: co-authors-plus.php:405 co-authors-plus.php:529 co-authors-plus.php:1254 msgid "" "Click on an author to change them. Drag to change their order. Click on " "Remove to remove them." msgstr "" -#: co-authors-plus.php:449 php/class-coauthors-wp-list-table.php:148 +#: co-authors-plus.php:490 php/class-coauthors-wp-list-table.php:156 msgid "Posts" msgstr "" -#: co-authors-plus.php:466 +#: co-authors-plus.php:509 msgid "View posts by this author" msgstr "" -#: co-authors-plus.php:531 co-authors-plus.php:548 +#: co-authors-plus.php:572 co-authors-plus.php:590 msgid "No co-author exists for that term" msgstr "" -#: co-authors-plus.php:1090 php/class-coauthors-wp-list-table.php:212 +#: co-authors-plus.php:1249 php/class-coauthors-wp-list-table.php:220 msgid "Edit" msgstr "" -#: co-authors-plus.php:1091 +#: co-authors-plus.php:1250 msgid "Remove" msgstr "" -#: co-authors-plus.php:1092 +#: co-authors-plus.php:1251 msgid "Are you sure you want to remove this author?" msgstr "" -#: co-authors-plus.php:1093 +#: co-authors-plus.php:1252 msgid "Click to change this author, or drag to change their position" msgstr "" -#: co-authors-plus.php:1094 +#: co-authors-plus.php:1253 msgid "Search for an author" msgstr "" -#: co-authors-plus.php:1132 +#: co-authors-plus.php:1295 msgid "Mine" msgstr "" -#: co-authors-plus.php:1402 +#: co-authors-plus.php:1644 +msgid "Author: %s" +msgstr "" + +#: co-authors-plus.php:1696 msgid "New comment on your post \"%s\"" msgstr "" #. translators: 1: comment author, 2: author IP, 3: author domain -#: co-authors-plus.php:1404 co-authors-plus.php:1521 +#: co-authors-plus.php:1698 msgid "Author : %1$s (IP: %2$s , %3$s)" msgstr "" -#: co-authors-plus.php:1405 co-authors-plus.php:1522 +#: co-authors-plus.php:1699 msgid "E-mail : %s" msgstr "" -#: co-authors-plus.php:1406 co-authors-plus.php:1416 co-authors-plus.php:1425 -#: co-authors-plus.php:1508 co-authors-plus.php:1515 co-authors-plus.php:1523 +#: co-authors-plus.php:1700 co-authors-plus.php:1710 co-authors-plus.php:1719 msgid "URL : %s" msgstr "" -#: co-authors-plus.php:1407 co-authors-plus.php:1524 +#: co-authors-plus.php:1701 msgid "Whois : http://whois.arin.net/rest/ip/%s" msgstr "" -#: co-authors-plus.php:1408 co-authors-plus.php:1525 +#: co-authors-plus.php:1702 msgid "Comment: " msgstr "" -#: co-authors-plus.php:1409 +#: co-authors-plus.php:1703 msgid "You can see all comments on this post here: " msgstr "" #. translators: 1: blog name, 2: post title -#: co-authors-plus.php:1411 +#: co-authors-plus.php:1705 msgid "[%1$s] Comment: \"%2$s\"" msgstr "" -#: co-authors-plus.php:1413 +#: co-authors-plus.php:1707 msgid "New trackback on your post \"%s\"" msgstr "" #. translators: 1: website name, 2: author IP, 3: author domain #. translators: 1: comment author, 2: author IP, 3: author domain -#: co-authors-plus.php:1415 co-authors-plus.php:1424 +#: co-authors-plus.php:1709 co-authors-plus.php:1718 msgid "Website: %1$s (IP: %2$s , %3$s)" msgstr "" -#: co-authors-plus.php:1417 co-authors-plus.php:1426 +#: co-authors-plus.php:1711 co-authors-plus.php:1720 msgid "Excerpt: " msgstr "" -#: co-authors-plus.php:1418 +#: co-authors-plus.php:1712 msgid "You can see all trackbacks on this post here: " msgstr "" #. translators: 1: blog name, 2: post title -#: co-authors-plus.php:1420 +#: co-authors-plus.php:1714 msgid "[%1$s] Trackback: \"%2$s\"" msgstr "" -#: co-authors-plus.php:1422 +#: co-authors-plus.php:1716 msgid "New pingback on your post \"%s\"" msgstr "" -#: co-authors-plus.php:1427 +#: co-authors-plus.php:1721 msgid "You can see all pingbacks on this post here: " msgstr "" #. translators: 1: blog name, 2: post title -#: co-authors-plus.php:1429 +#: co-authors-plus.php:1723 msgid "[%1$s] Pingback: \"%2$s\"" msgstr "" -#: co-authors-plus.php:1432 +#: co-authors-plus.php:1726 msgid "Permalink: %s" msgstr "" -#: co-authors-plus.php:1434 co-authors-plus.php:1531 +#: co-authors-plus.php:1728 msgid "Trash it: %s" msgstr "" -#: co-authors-plus.php:1436 co-authors-plus.php:1533 +#: co-authors-plus.php:1730 msgid "Delete it: %s" msgstr "" -#: co-authors-plus.php:1437 co-authors-plus.php:1534 +#: co-authors-plus.php:1732 msgid "Spam it: %s" msgstr "" -#: co-authors-plus.php:1505 -msgid "A new trackback on the post \"%s\" is waiting for your approval" -msgstr "" - -#: co-authors-plus.php:1507 co-authors-plus.php:1514 -msgid "Website : %1$s (IP: %2$s , %3$s)" -msgstr "" - -#: co-authors-plus.php:1509 -msgid "Trackback excerpt: " -msgstr "" - -#: co-authors-plus.php:1512 -msgid "A new pingback on the post \"%s\" is waiting for your approval" -msgstr "" - -#: co-authors-plus.php:1516 -msgid "Pingback excerpt: " -msgstr "" - -#: co-authors-plus.php:1519 -msgid "A new comment on the post \"%s\" is waiting for your approval" -msgstr "" - -#: co-authors-plus.php:1529 -msgid "Approve it: %s" -msgstr "" - -#: co-authors-plus.php:1536 -msgid "" -"Currently %s comment is waiting for approval. Please visit the moderation " -"panel:" -msgid_plural "" -"Currently %s comments are waiting for approval. Please visit the moderation " -"panel:" -msgstr[0] "" -msgstr[1] "" - -#: co-authors-plus.php:1540 -msgid "[%1$s] Please moderate: \"%2$s\"" -msgstr "" - -#: php/class-coauthors-guest-authors.php:80 +#: php/class-coauthors-guest-authors.php:83 +#: php/class-coauthors-guest-authors.php:1517 +#: php/class-coauthors-guest-authors.php:1590 msgid "Guest Author" msgstr "" -#: php/class-coauthors-guest-authors.php:81 +#: php/class-coauthors-guest-authors.php:84 msgid "Guest Authors" msgstr "" -#: php/class-coauthors-guest-authors.php:82 +#: php/class-coauthors-guest-authors.php:85 msgid "All Guest Authors" msgstr "" -#: php/class-coauthors-guest-authors.php:83 +#: php/class-coauthors-guest-authors.php:86 msgid "Add New Guest Author" msgstr "" -#: php/class-coauthors-guest-authors.php:84 +#: php/class-coauthors-guest-authors.php:87 msgid "Edit Guest Author" msgstr "" -#: php/class-coauthors-guest-authors.php:85 +#: php/class-coauthors-guest-authors.php:88 msgid "New Guest Author" msgstr "" -#: php/class-coauthors-guest-authors.php:86 +#: php/class-coauthors-guest-authors.php:89 msgid "View Guest Author" msgstr "" -#: php/class-coauthors-guest-authors.php:87 +#: php/class-coauthors-guest-authors.php:90 msgid "Search Guest Authors" msgstr "" -#: php/class-coauthors-guest-authors.php:88 +#: php/class-coauthors-guest-authors.php:91 msgid "No guest authors found" msgstr "" -#: php/class-coauthors-guest-authors.php:89 +#: php/class-coauthors-guest-authors.php:92 msgid "No guest authors found in Trash" msgstr "" -#: php/class-coauthors-guest-authors.php:90 +#: php/class-coauthors-guest-authors.php:93 msgid "Update Guest Author" msgstr "" -#: php/class-coauthors-guest-authors.php:91 +#: php/class-coauthors-guest-authors.php:94 msgid "About the guest author" msgstr "" -#: php/class-coauthors-guest-authors.php:100 +#: php/class-coauthors-guest-authors.php:95 +msgid "Avatar" +msgstr "" + +#: php/class-coauthors-guest-authors.php:96 +msgid "Set Avatar" +msgstr "" + +#: php/class-coauthors-guest-authors.php:97 +msgid "Use Avatar" +msgstr "" + +#: php/class-coauthors-guest-authors.php:98 +msgid "Remove Avatar" +msgstr "" + +#: php/class-coauthors-guest-authors.php:107 msgctxt "guest author" msgid "Add New" msgstr "" -#: php/class-coauthors-guest-authors.php:156 #: php/class-coauthors-guest-authors.php:162 +#: php/class-coauthors-guest-authors.php:168 msgid "Guest author updated. View profile" msgstr "" -#: php/class-coauthors-guest-authors.php:157 +#: php/class-coauthors-guest-authors.php:163 msgid "Custom field updated." msgstr "" -#: php/class-coauthors-guest-authors.php:158 +#: php/class-coauthors-guest-authors.php:164 msgid "Custom field deleted." msgstr "" -#: php/class-coauthors-guest-authors.php:159 +#: php/class-coauthors-guest-authors.php:165 msgid "Guest author updated." msgstr "" #. translators: %s: date and time of the revision -#: php/class-coauthors-guest-authors.php:161 +#: php/class-coauthors-guest-authors.php:167 msgid "Guest author restored to revision from %s" msgstr "" -#: php/class-coauthors-guest-authors.php:163 +#: php/class-coauthors-guest-authors.php:169 msgid "Guest author saved." msgstr "" -#: php/class-coauthors-guest-authors.php:164 +#: php/class-coauthors-guest-authors.php:170 msgid "" "Guest author submitted. Preview profile" msgstr "" -#: php/class-coauthors-guest-authors.php:165 +#: php/class-coauthors-guest-authors.php:171 msgid "" "Guest author scheduled for: %1$s. Preview profile" msgstr "" -#. translators: Publish box date format, see http:php.net/date -#: php/class-coauthors-guest-authors.php:167 +#. translators: Publish box date format, see http://php.net/date +#: php/class-coauthors-guest-authors.php:173 msgid "M j, Y @ G:i" msgstr "" -#: php/class-coauthors-guest-authors.php:168 +#: php/class-coauthors-guest-authors.php:174 msgid "" "Guest author updated. Preview profile" msgstr "" -#: php/class-coauthors-guest-authors.php:185 -#: php/class-coauthors-guest-authors.php:218 -#: php/class-coauthors-guest-authors.php:437 +#: php/class-coauthors-guest-authors.php:192 +#: php/class-coauthors-guest-authors.php:231 +#: php/class-coauthors-guest-authors.php:462 +#: tests/test-coauthors-guest-authors.php:360 msgid "Doin' something fishy, huh?" msgstr "" -#: php/class-coauthors-guest-authors.php:188 -#: php/class-coauthors-guest-authors.php:222 +#: php/class-coauthors-guest-authors.php:196 +#: php/class-coauthors-guest-authors.php:236 +#: tests/test-coauthors-guest-authors.php:407 msgid "You don't have permission to perform this action." msgstr "" -#: php/class-coauthors-guest-authors.php:227 -#: php/class-coauthors-guest-authors.php:442 -msgid "Guest author can't be deleted because it doesn't exist." +#: php/class-coauthors-guest-authors.php:242 +#: php/class-coauthors-guest-authors.php:468 +#: tests/test-coauthors-guest-authors.php:465 +msgid "%s can't be deleted because it doesn't exist." msgstr "" -#: php/class-coauthors-guest-authors.php:241 +#: php/class-coauthors-guest-authors.php:257 +#: tests/test-coauthors-guest-authors.php:612 msgid "Co-author does not exists. Try again?" msgstr "" -#: php/class-coauthors-guest-authors.php:249 +#: php/class-coauthors-guest-authors.php:266 +#: tests/test-coauthors-guest-authors.php:519 msgid "Please make sure to pick an option." msgstr "" -#: php/class-coauthors-guest-authors.php:393 +#: php/class-coauthors-guest-authors.php:418 msgid "Guest author deleted." msgstr "" -#: php/class-coauthors-guest-authors.php:417 +#: php/class-coauthors-guest-authors.php:442 msgid "Save" msgstr "" -#: php/class-coauthors-guest-authors.php:418 +#: php/class-coauthors-guest-authors.php:443 msgid "Unique Slug" msgstr "" -#: php/class-coauthors-guest-authors.php:420 +#: php/class-coauthors-guest-authors.php:445 msgid "Name" msgstr "" -#: php/class-coauthors-guest-authors.php:421 +#: php/class-coauthors-guest-authors.php:446 msgid "Contact Info" msgstr "" -#: php/class-coauthors-guest-authors.php:446 +#: php/class-coauthors-guest-authors.php:482 msgid "Delete %s" msgstr "" -#: php/class-coauthors-guest-authors.php:447 -msgid "You have specified this guest author for deletion:" +#: php/class-coauthors-guest-authors.php:483 +msgid "You have specified this %s for deletion:" +msgstr "" + +#: php/class-coauthors-guest-authors.php:487 +msgid "There are no posts associated with this guest author." +msgstr "" + +#: php/class-coauthors-guest-authors.php:490 +msgid "" +"Note: If you'd like to delete the %s and all of their posts, you should " +"delete their posts first and then come back to delete the %s." msgstr "" -#: php/class-coauthors-guest-authors.php:449 -msgid "What should be done with posts assigned to this guest author?" +#: php/class-coauthors-guest-authors.php:492 +msgid "" +"There is %d post associated with this guest author. What should be done with " +"the post assigned to this %s?" msgstr "" -#: php/class-coauthors-guest-authors.php:450 +#: php/class-coauthors-guest-authors.php:495 msgid "" -"Note: If you'd like to delete the guest author and all of their posts, you " -"should delete their posts first and then come back to delete the guest " -"author." +"There are %d posts associated with this guest author. What should be done " +"with the posts assigned to this %s?" msgstr "" -#: php/class-coauthors-guest-authors.php:459 +#: php/class-coauthors-guest-authors.php:515 msgid "Reassign to another co-author:" msgstr "" -#: php/class-coauthors-guest-authors.php:465 +#: php/class-coauthors-guest-authors.php:521 msgid "Leave posts assigned to the mapped user, %s." msgstr "" -#: php/class-coauthors-guest-authors.php:470 +#: php/class-coauthors-guest-authors.php:526 msgid "Remove byline from posts (but leave each post in its current status)." msgstr "" -#: php/class-coauthors-guest-authors.php:473 +#: php/class-coauthors-guest-authors.php:535 +#: php/class-coauthors-guest-authors.php:538 msgid "Confirm Deletion" msgstr "" -#: php/class-coauthors-guest-authors.php:482 +#: php/class-coauthors-guest-authors.php:548 msgid "Add New" msgstr "" -#: php/class-coauthors-guest-authors.php:543 +#: php/class-coauthors-guest-authors.php:613 msgid "WordPress User Mapping" msgstr "" -#: php/class-coauthors-guest-authors.php:545 +#: php/class-coauthors-guest-authors.php:615 msgid "-- Not mapped --" msgstr "" -#: php/class-coauthors-guest-authors.php:679 -#: php/class-coauthors-guest-authors.php:688 +#: php/class-coauthors-guest-authors.php:762 +#: php/class-coauthors-guest-authors.php:773 msgid "Guest authors cannot be created without display names." msgstr "" -#: php/class-coauthors-guest-authors.php:697 +#: php/class-coauthors-guest-authors.php:783 msgid "" "Guest authors cannot be created with the same user_login value as a user. " "Try creating a profile from the user on the Manage Users listing instead." msgstr "" -#: php/class-coauthors-guest-authors.php:702 +#: php/class-coauthors-guest-authors.php:789 msgid "Display name conflicts with another guest author display name." msgstr "" -#: php/class-coauthors-guest-authors.php:896 +#: php/class-coauthors-guest-authors.php:999 +#: php/class-coauthors-guest-authors.php:1547 msgid "ID" msgstr "" -#: php/class-coauthors-guest-authors.php:903 -#: php/class-coauthors-wp-list-table.php:143 +#: php/class-coauthors-guest-authors.php:1006 +#: php/class-coauthors-guest-authors.php:1549 +#: php/class-coauthors-wp-list-table.php:151 msgid "Display Name" msgstr "" -#: php/class-coauthors-guest-authors.php:909 -#: php/class-coauthors-wp-list-table.php:144 +#: php/class-coauthors-guest-authors.php:1012 +#: php/class-coauthors-guest-authors.php:1551 +#: php/class-coauthors-wp-list-table.php:152 msgid "First Name" msgstr "" -#: php/class-coauthors-guest-authors.php:914 -#: php/class-coauthors-wp-list-table.php:145 +#: php/class-coauthors-guest-authors.php:1017 +#: php/class-coauthors-guest-authors.php:1552 +#: php/class-coauthors-wp-list-table.php:153 msgid "Last Name" msgstr "" -#: php/class-coauthors-guest-authors.php:919 +#: php/class-coauthors-guest-authors.php:1022 msgid "Slug" msgstr "" -#: php/class-coauthors-guest-authors.php:926 -#: php/class-coauthors-wp-list-table.php:146 +#: php/class-coauthors-guest-authors.php:1029 +#: php/class-coauthors-wp-list-table.php:154 msgid "E-mail" msgstr "" -#: php/class-coauthors-guest-authors.php:932 -#: php/class-coauthors-wp-list-table.php:147 +#: php/class-coauthors-guest-authors.php:1035 +#: php/class-coauthors-wp-list-table.php:155 msgid "Linked Account" msgstr "" -#: php/class-coauthors-guest-authors.php:937 +#: php/class-coauthors-guest-authors.php:1040 +#: php/class-coauthors-guest-authors.php:1553 msgid "Website" msgstr "" -#: php/class-coauthors-guest-authors.php:943 +#: php/class-coauthors-guest-authors.php:1046 +#: php/class-coauthors-guest-authors.php:1554 msgid "AIM" msgstr "" -#: php/class-coauthors-guest-authors.php:948 +#: php/class-coauthors-guest-authors.php:1051 +#: php/class-coauthors-guest-authors.php:1555 msgid "Yahoo IM" msgstr "" -#: php/class-coauthors-guest-authors.php:953 +#: php/class-coauthors-guest-authors.php:1056 +#: php/class-coauthors-guest-authors.php:1556 msgid "Jabber / Google Talk" msgstr "" -#: php/class-coauthors-guest-authors.php:958 +#: php/class-coauthors-guest-authors.php:1061 +#: php/class-coauthors-guest-authors.php:1557 msgid "Biographical Info" msgstr "" -#: php/class-coauthors-guest-authors.php:1122 +#: php/class-coauthors-guest-authors.php:1232 msgid "%s is a required field" msgstr "" -#: php/class-coauthors-guest-authors.php:1128 +#: php/class-coauthors-guest-authors.php:1238 msgid "user_login cannot duplicate existing guest author or mapped user" msgstr "" -#: php/class-coauthors-guest-authors.php:1173 +#: php/class-coauthors-guest-authors.php:1289 msgid "Guest author does not exist" msgstr "" -#: php/class-coauthors-guest-authors.php:1185 +#: php/class-coauthors-guest-authors.php:1304 msgid "Reassignment co-author does not exist" msgstr "" -#: php/class-coauthors-guest-authors.php:1217 +#: php/class-coauthors-guest-authors.php:1337 msgid "No user exists with that ID" msgstr "" -#: php/class-coauthors-guest-authors.php:1275 +#: php/class-coauthors-guest-authors.php:1400 msgid "Edit Profile" msgstr "" -#: php/class-coauthors-guest-authors.php:1284 +#: php/class-coauthors-guest-authors.php:1409 msgid "Create Profile" msgstr "" -#: php/class-coauthors-wp-list-table.php:19 -msgid "Co-Authors" +#: php/class-coauthors-guest-authors.php:1548 +msgid "Login Name" +msgstr "" + +#: php/class-coauthors-guest-authors.php:1550 +msgid "Email" msgstr "" #: php/class-coauthors-wp-list-table.php:20 +msgid "Co-Authors" +msgstr "" + +#: php/class-coauthors-wp-list-table.php:21 msgid "Co-Author" msgstr "" -#: php/class-coauthors-wp-list-table.php:81 +#: php/class-coauthors-wp-list-table.php:86 msgid "Show all" msgstr "" -#: php/class-coauthors-wp-list-table.php:82 +#: php/class-coauthors-wp-list-table.php:87 msgid "With linked account" msgstr "" -#: php/class-coauthors-wp-list-table.php:83 +#: php/class-coauthors-wp-list-table.php:88 msgid "Without linked account" msgstr "" -#: php/class-coauthors-wp-list-table.php:135 -msgid "No matching guest authors were found." +#: php/class-coauthors-wp-list-table.php:143 +msgid "No matching co-authors were found." msgstr "" -#: php/class-coauthors-wp-list-table.php:215 +#: php/class-coauthors-wp-list-table.php:223 msgid "Delete" msgstr "" -#: php/class-coauthors-wp-list-table.php:217 +#: php/class-coauthors-wp-list-table.php:225 msgid "View Posts" msgstr "" -#: php/class-coauthors-wp-list-table.php:267 +#: php/class-coauthors-wp-list-table.php:279 msgid "Filter" msgstr "" -#: php/class-wp-cli.php:220 +#: php/class-wp-cli.php:52 +msgid "Role " +msgstr "" + +#: php/class-wp-cli.php:52 +msgid " does not exist." +msgstr "" + +#: php/class-wp-cli.php:256 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:223 +#: php/class-wp-cli.php:260 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:230 +#: php/class-wp-cli.php:270 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:235 +#: php/class-wp-cli.php:278 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:240 +#: php/class-wp-cli.php:284 msgid "All done! %d posts were affected." msgstr "" -#: template-tags.php:79 +#: template-tags.php:96 msgid "" "No post ID provided for CoAuthorsIterator constructor. Are you not in a loop " "or is $post not set?" msgstr "" -#: template-tags.php:133 +#: template-tags.php:153 msgid " and " msgstr "" -#: template-tags.php:233 template-tags.php:468 +#: template-tags.php:288 template-tags.php:615 msgid "Posts by %s" msgstr "" -#: template-tags.php:350 +#: template-tags.php:426 template-tags.php:433 msgid "Visit %s’s website" msgstr "" +#: wpcom-helper.php:40 +msgid "" +"Co-Authors Plus isn't yet integrated with your theme. Please contact support " +"to make it happen." +msgstr "" + #. Plugin Name of the plugin/theme msgid "Co-Authors Plus" msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 5bd3391d..92d80d95 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -11,7 +11,22 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { /** - * Subcommand to create guest authors based on users + * Subcommand to create guest authors for all users. + * + * ## OPTIONS + * + * --roles + * Provide a comma-separated list of roles to generate guest authors for. + * + * Defaults to: administrator,editor,author,contributor. + * + * ## EXAMPLES + * + * wp co-authors-plus create-guest-authors + * Generate guest authors for administrators, editors, authors, and contributors. + * + * wp co-authors-plus create-guest-authors --roles=author,freelancer + * Generate guest authors only for authors and freelancers. * * @since 3.0 * @@ -21,11 +36,24 @@ public function create_guest_authors( $args, $assoc_args ) { global $coauthors_plus; $defaults = array( - // There are no arguments at this time - ); + 'roles' => array( 'administrator', 'editor', 'author', 'contributor' ), + ); $this->args = wp_parse_args( $assoc_args, $defaults ); - $users = get_users( array( 'role__in' => array( 'administrator', 'editor', 'author' ) ) ); + if ( is_array( $this->args['roles'] ) ) { + $role_whitelist = $this->args['roles']; + } else { + $role_whitelist = explode( ',', $this->args['roles'] ); + } + + foreach ( $role_whitelist as $role ) { + // Does this role exist in this instance? + if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { + WP_CLI::error( __( 'Role ', 'co-authors-plus' ) . $role . __( ' does not exist.', 'co-authors-plus' ) ); + } + } + + $users = get_users( array( 'role__in' => $role_whitelist ) ); $created = 0; $skipped = 0; $progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) ); From f6326ff0c5a17e03a56f3f7fbf0c23b239c5f0bf Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Fri, 27 Jul 2018 14:39:57 -0300 Subject: [PATCH 218/231] Reset pot file permissions to 755 from 644 --- languages/co-authors-plus.pot | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 languages/co-authors-plus.pot diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot old mode 100644 new mode 100755 From 8a0dd367fdeb5dfe4a804626af1a549cea4bde37 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Sun, 29 Jul 2018 21:23:00 -0300 Subject: [PATCH 219/231] Ban subscribers from being made guest authors via wp-cli. Some sites can have millions of subscribers. Querying for that many users presents a serious potential performance challenge. Rather than take the risk of having an end user specify them in the --roles flag, they have now been explicitly banned. --- languages/co-authors-plus.pot | 18 ++++++++++++------ php/class-wp-cli.php | 8 ++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot index e3cfd99a..a127dbaa 100755 --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Co-Authors Plus 3.3.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" -"POT-Creation-Date: 2018-07-27 17:27:25+00:00\n" +"POT-Creation-Date: 2018-07-30 00:14:51+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -538,23 +538,29 @@ msgstr "" msgid " does not exist." msgstr "" -#: php/class-wp-cli.php:256 +#: php/class-wp-cli.php:58 +msgid "" +"For performance reasons, subscribers cannot be made guest authors via wp-" +"cli. Please use the admin interface." +msgstr "" + +#: php/class-wp-cli.php:262 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:260 +#: php/class-wp-cli.php:266 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:270 +#: php/class-wp-cli.php:276 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:278 +#: php/class-wp-cli.php:284 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:284 +#: php/class-wp-cli.php:290 msgid "All done! %d posts were affected." msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 92d80d95..94436b8c 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -20,6 +20,8 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * * Defaults to: administrator,editor,author,contributor. * + * For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface. + * * ## EXAMPLES * * wp co-authors-plus create-guest-authors @@ -51,6 +53,12 @@ public function create_guest_authors( $args, $assoc_args ) { if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { WP_CLI::error( __( 'Role ', 'co-authors-plus' ) . $role . __( ' does not exist.', 'co-authors-plus' ) ); } + + // Subscribers cannot be made guest authors en masse + // due to potential performance issues (sites can have millions of subscribers). + if ( 'subscriber' === $role ) { + WP_CLI::error( __( 'For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface.', 'co-authors-plus' ) ); + } } $users = get_users( array( 'role__in' => $role_whitelist ) ); From f14541290bda3b4e82db45bbce5e6f40a3f210d2 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Mon, 30 Jul 2018 08:42:07 -0300 Subject: [PATCH 220/231] Modify user filtering algorithm. Filtering users by role on the database has the potential to make for a very expensive query, as it performs a LIKE on an unindexed field. But if the users were all brought over at once, unfiltered, the potential exists for an array with millions of elements, straining the application server's memory limit. So the compromise is: batching. Users are fetched from the database, unfiltered, in batches of user-defined size. They are then filtered, and a new batch is brought in. This algorithm looks to strike a balance between load on the database server, and memory limits on the application server. --- languages/co-authors-plus.pot | 22 +++++++------ php/class-wp-cli.php | 59 ++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot index a127dbaa..23b1d5dd 100755 --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Co-Authors Plus 3.3.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" -"POT-Creation-Date: 2018-07-30 00:14:51+00:00\n" +"POT-Creation-Date: 2018-07-30 11:31:18+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -530,37 +530,41 @@ msgstr "" msgid "Filter" msgstr "" -#: php/class-wp-cli.php:52 +#: php/class-wp-cli.php:55 +msgid "Batch size must be an integer greater than zero." +msgstr "" + +#: php/class-wp-cli.php:61 msgid "Role " msgstr "" -#: php/class-wp-cli.php:52 +#: php/class-wp-cli.php:61 msgid " does not exist." msgstr "" -#: php/class-wp-cli.php:58 +#: php/class-wp-cli.php:67 msgid "" "For performance reasons, subscribers cannot be made guest authors via wp-" "cli. Please use the admin interface." msgstr "" -#: php/class-wp-cli.php:262 +#: php/class-wp-cli.php:311 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:266 +#: php/class-wp-cli.php:315 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:276 +#: php/class-wp-cli.php:325 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:284 +#: php/class-wp-cli.php:333 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:290 +#: php/class-wp-cli.php:339 msgid "All done! %d posts were affected." msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 94436b8c..ec9c0840 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -22,6 +22,13 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * * For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface. * + * --batch-size + * Many sites have a large user list, which could cause troubles when filtering roles prior to guest author generation. This allows you to set a batch size appropriate for your server's memory limit. + * + * Defaults to: 1000. + * + * Must be an integer greater than 0. Decimals (e.g. 500.5) will be rounded down, exponents (e.g. 10e6) will be ignored. + * * ## EXAMPLES * * wp co-authors-plus create-guest-authors @@ -30,6 +37,9 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * wp co-authors-plus create-guest-authors --roles=author,freelancer * Generate guest authors only for authors and freelancers. * + * wp co-authors-plus create-guest-authors --batch-size=5000 + * Generate guest authors, filtering in batches of 5000. + * * @since 3.0 * * @subcommand create-guest-authors @@ -39,6 +49,7 @@ public function create_guest_authors( $args, $assoc_args ) { $defaults = array( 'roles' => array( 'administrator', 'editor', 'author', 'contributor' ), + 'batch-size' => 1000, ); $this->args = wp_parse_args( $assoc_args, $defaults ); @@ -48,6 +59,12 @@ public function create_guest_authors( $args, $assoc_args ) { $role_whitelist = explode( ',', $this->args['roles'] ); } + if ( $this->args['batch-size'] > 0 && is_numeric( $this->args['batch-size'] ) ) { + $batch_size = (int) $this->args['batch-size']; + } else { + WP_CLI::error( __( 'Batch size must be an integer greater than zero.', 'co-authors-plus' ) ); + } + foreach ( $role_whitelist as $role ) { // Does this role exist in this instance? if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { @@ -61,7 +78,47 @@ public function create_guest_authors( $args, $assoc_args ) { } } - $users = get_users( array( 'role__in' => $role_whitelist ) ); + $users_unfiltered_query = new WP_User_Query( array( 'number' => $batch_size ) ); + $users_count = $users_unfiltered_query->get_total(); + $users_unfiltered = $users_unfiltered_query->get_results(); + $users = array(); + + // Process the first batch retrieved while checking the table size. + foreach ( $users_unfiltered as $user ) { + foreach ( $user->roles as $role ) { + if ( in_array( $role, $role_whitelist, true ) ) { + // Using the user ID ensures that users that would otherwise + // be in the list twice overwrite each other. + $users[ $user->ID ] = $user; + } + } + } + + $num_batches = ceil( $users_count / $batch_size ); + + // Process the remaining batches. + for ( $i = 1; $i < $num_batches; $i++ ) { + $users_unfiltered_query = new WP_User_Query( + array( + 'number' => $batch_size, + 'offset' => $batch_size * $i, + ) + ); + + $users_unfiltered = $users_unfiltered_query->get_results(); + + foreach ( $users_unfiltered as $user ) { + foreach ( $user->roles as $role ) { + if ( in_array( $role, $role_whitelist, true ) ) { + $users[ $user->ID ] = $user; + } + } + } + } + + // Discard user ID indices, rebase to 0. + $users = array_values( $users ); + $created = 0; $skipped = 0; $progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) ); From 98ea1501aed7d46f4e694d515a758332f5d07185 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Tue, 31 Jul 2018 19:05:42 -0300 Subject: [PATCH 221/231] Change method of translating invalid role error message. Previously, the translated string was broken up into two fragments, with the $role variable concatenated in between. To enable easier translation, the string is now generated in one piece via sprintf (interpolated variables inside double quotes are not allowed). --- languages/co-authors-plus.pot | 25 +++++++++++-------------- php/class-wp-cli.php | 6 +++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot index 23b1d5dd..e8c4140b 100755 --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Co-Authors Plus 3.3.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" -"POT-Creation-Date: 2018-07-30 11:31:18+00:00\n" +"POT-Creation-Date: 2018-07-31 22:02:38+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -530,41 +530,38 @@ msgstr "" msgid "Filter" msgstr "" -#: php/class-wp-cli.php:55 +#: php/class-wp-cli.php:65 msgid "Batch size must be an integer greater than zero." msgstr "" -#: php/class-wp-cli.php:61 -msgid "Role " +#. translators: %s: User role +#: php/class-wp-cli.php:73 +msgid "Role %s does not exist." msgstr "" -#: php/class-wp-cli.php:61 -msgid " does not exist." -msgstr "" - -#: php/class-wp-cli.php:67 +#: php/class-wp-cli.php:81 msgid "" "For performance reasons, subscribers cannot be made guest authors via wp-" "cli. Please use the admin interface." msgstr "" -#: php/class-wp-cli.php:311 +#: php/class-wp-cli.php:325 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:315 +#: php/class-wp-cli.php:329 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:325 +#: php/class-wp-cli.php:339 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:333 +#: php/class-wp-cli.php:347 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:339 +#: php/class-wp-cli.php:353 msgid "All done! %d posts were affected." msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index ec9c0840..699a08f5 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -68,7 +68,11 @@ public function create_guest_authors( $args, $assoc_args ) { foreach ( $role_whitelist as $role ) { // Does this role exist in this instance? if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { - WP_CLI::error( __( 'Role ', 'co-authors-plus' ) . $role . __( ' does not exist.', 'co-authors-plus' ) ); + WP_CLI::error( sprintf( + /* translators: %s: User role */ + __( 'Role %s does not exist.', 'co-authors-plus' ), + $role + ) ); } // Subscribers cannot be made guest authors en masse From f6181189faa983ab0398a897be443402bcaaebe9 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Tue, 31 Jul 2018 19:32:28 -0300 Subject: [PATCH 222/231] Add --force-subscribers flag to enable users to mass-generate subscriber guest authors. In the event that an end user accepts the performance hit of generating guest authors for all their subscribers, this flag allows them to do so. Named --force-subscribers instead of --force to allow for future development. --- php/class-wp-cli.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 699a08f5..8da5304a 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -20,8 +20,6 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * * Defaults to: administrator,editor,author,contributor. * - * For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface. - * * --batch-size * Many sites have a large user list, which could cause troubles when filtering roles prior to guest author generation. This allows you to set a batch size appropriate for your server's memory limit. * @@ -29,6 +27,9 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * * Must be an integer greater than 0. Decimals (e.g. 500.5) will be rounded down, exponents (e.g. 10e6) will be ignored. * + * --force-subscribers + * For performance reasons, it is not recommended you include subscribers in your automatic generation. Using the admin interface to generate one-off subscriber guest authors is likely to be a better alternative. However, you can pass this flag to include them. + * * ## EXAMPLES * * wp co-authors-plus create-guest-authors @@ -40,6 +41,12 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * wp co-authors-plus create-guest-authors --batch-size=5000 * Generate guest authors, filtering in batches of 5000. * + * wp co-authors-plus create-guest-authors --roles=author,subscriber + * This command will fail. + * + * wp co-authors-plus create-guest-authors --roles=author,subscriber --force-subscribers + * This command will succeed. NOTE: Your site may have many subscribers, which may make the command take a long time to run. + * * @since 3.0 * * @subcommand create-guest-authors @@ -48,9 +55,11 @@ public function create_guest_authors( $args, $assoc_args ) { global $coauthors_plus; $defaults = array( - 'roles' => array( 'administrator', 'editor', 'author', 'contributor' ), - 'batch-size' => 1000, + 'roles' => array( 'administrator', 'editor', 'author', 'contributor' ), + 'batch-size' => 1000, + 'force-subscribers' => false, ); + $this->args = wp_parse_args( $assoc_args, $defaults ); if ( is_array( $this->args['roles'] ) ) { @@ -65,6 +74,12 @@ public function create_guest_authors( $args, $assoc_args ) { WP_CLI::error( __( 'Batch size must be an integer greater than zero.', 'co-authors-plus' ) ); } + if ( is_bool( $this->args['force-subscribers'] ) && true === $this->args['force-subscribers'] ) { + $force_subscribers = true; + } else { + $force_subscribers = false; + } + foreach ( $role_whitelist as $role ) { // Does this role exist in this instance? if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { @@ -77,7 +92,7 @@ public function create_guest_authors( $args, $assoc_args ) { // Subscribers cannot be made guest authors en masse // due to potential performance issues (sites can have millions of subscribers). - if ( 'subscriber' === $role ) { + if ( 'subscriber' === $role && false === $force_subscribers ) { WP_CLI::error( __( 'For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface.', 'co-authors-plus' ) ); } } From c4f096826300be1925a7cf07b5f5ff4a3f38ae6a Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Tue, 31 Jul 2018 20:05:46 -0300 Subject: [PATCH 223/231] Add --not-a-dry-run flag controlling whether or not the command performs data modifications. By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. Passing in the --not-a-dry-run flag tells the code to actually make the attempts. Props sboisvert for the idea to make this command dry by default. --- languages/co-authors-plus.pot | 27 ++++++++++++------ php/class-wp-cli.php | 53 +++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot index e8c4140b..53d86ed9 100755 --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Co-Authors Plus 3.3.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" -"POT-Creation-Date: 2018-07-31 22:02:38+00:00\n" +"POT-Creation-Date: 2018-07-31 22:56:36+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -530,38 +530,47 @@ msgstr "" msgid "Filter" msgstr "" -#: php/class-wp-cli.php:65 +#: php/class-wp-cli.php:85 msgid "Batch size must be an integer greater than zero." msgstr "" #. translators: %s: User role -#: php/class-wp-cli.php:73 +#: php/class-wp-cli.php:105 msgid "Role %s does not exist." msgstr "" -#: php/class-wp-cli.php:81 +#: php/class-wp-cli.php:113 msgid "" "For performance reasons, subscribers cannot be made guest authors via wp-" "cli. Please use the admin interface." msgstr "" -#: php/class-wp-cli.php:325 +#: php/class-wp-cli.php:159 +msgid "DRY RUN" +msgstr "" + +#. translators: %d: User ID +#: php/class-wp-cli.php:163 +msgid "Attempting to generate guest author for user ID %d." +msgstr "" + +#: php/class-wp-cli.php:367 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:329 +#: php/class-wp-cli.php:371 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:339 +#: php/class-wp-cli.php:381 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:347 +#: php/class-wp-cli.php:389 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:353 +#: php/class-wp-cli.php:395 msgid "All done! %d posts were affected." msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 8da5304a..c74d24dc 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -30,6 +30,9 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * --force-subscribers * For performance reasons, it is not recommended you include subscribers in your automatic generation. Using the admin interface to generate one-off subscriber guest authors is likely to be a better alternative. However, you can pass this flag to include them. * + * --not-a-dry-run + * By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. When you are ready to modify data, pass this flag. + * * ## EXAMPLES * * wp co-authors-plus create-guest-authors @@ -47,6 +50,9 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * wp co-authors-plus create-guest-authors --roles=author,subscriber --force-subscribers * This command will succeed. NOTE: Your site may have many subscribers, which may make the command take a long time to run. * + * wp co-authors-plus create-guest-authors --not-a-dry-run + * Will actually modify your database and generate guest authors. + * * @since 3.0 * * @subcommand create-guest-authors @@ -58,6 +64,7 @@ public function create_guest_authors( $args, $assoc_args ) { 'roles' => array( 'administrator', 'editor', 'author', 'contributor' ), 'batch-size' => 1000, 'force-subscribers' => false, + 'not-a-dry-run' => false, ); $this->args = wp_parse_args( $assoc_args, $defaults ); @@ -80,6 +87,12 @@ public function create_guest_authors( $args, $assoc_args ) { $force_subscribers = false; } + if ( is_bool( $this->args['not-a-dry-run'] ) && true === $this->args['not-a-dry-run'] ) { + $dry_run = false; + } else { + $dry_run = true; + } + foreach ( $role_whitelist as $role ) { // Does this role exist in this instance? if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { @@ -138,23 +151,33 @@ public function create_guest_authors( $args, $assoc_args ) { // Discard user ID indices, rebase to 0. $users = array_values( $users ); - $created = 0; - $skipped = 0; - $progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) ); - foreach ( $users as $user ) { - - $result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID ); - if ( is_wp_error( $result ) ) { - $skipped++; - } else { - $created++; + if ( true === $dry_run ) { + WP_CLI::line( __( 'DRY RUN', 'co-authors-plus' ) ); + foreach ( $users as $user ) { + WP_CLI::line( sprintf( + /* translators: %d: User ID */ + __( 'Attempting to generate guest author for user ID %d.', 'co-authors-plus' ), + $user->ID + ) ); } - $progress->tick(); + } else { + $created = 0; + $skipped = 0; + $progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) ); + foreach ( $users as $user ) { + $result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID ); + if ( is_wp_error( $result ) ) { + $skipped++; + } else { + $created++; + } + $progress->tick(); + } + $progress->finish(); + WP_CLI::line( 'All done! Here are your results:' ); + WP_CLI::line( "- {$created} guest author profiles were created" ); + WP_CLI::line( "- {$skipped} users already had guest author profiles" ); } - $progress->finish(); - WP_CLI::line( 'All done! Here are your results:' ); - WP_CLI::line( "- {$created} guest author profiles were created" ); - WP_CLI::line( "- {$skipped} users already had guest author profiles" ); } /** From 90c83a147745e0dc2738e6e37483bc9799fb6b3e Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Tue, 31 Jul 2018 20:40:53 -0300 Subject: [PATCH 224/231] Add --log-output flag to toggle output of guest author creation attempt results. This flag results in one of two potential log messages: "User ID 1 is now linked to Guest Author 2" "Error while attempting to generate guest author for user ID 1: errormessagehere" The command logs to STDOUT by default, but can be easily redirected to the location of the end user's choice. --- languages/co-authors-plus.pot | 33 ++++++++++++++++++++++----------- php/class-wp-cli.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot index 53d86ed9..798197ff 100755 --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Co-Authors Plus 3.3.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" -"POT-Creation-Date: 2018-07-31 22:56:36+00:00\n" +"POT-Creation-Date: 2018-07-31 23:35:45+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -530,47 +530,58 @@ msgstr "" msgid "Filter" msgstr "" -#: php/class-wp-cli.php:85 +#: php/class-wp-cli.php:88 msgid "Batch size must be an integer greater than zero." msgstr "" #. translators: %s: User role -#: php/class-wp-cli.php:105 +#: php/class-wp-cli.php:114 msgid "Role %s does not exist." msgstr "" -#: php/class-wp-cli.php:113 +#: php/class-wp-cli.php:122 msgid "" "For performance reasons, subscribers cannot be made guest authors via wp-" "cli. Please use the admin interface." msgstr "" -#: php/class-wp-cli.php:159 +#: php/class-wp-cli.php:168 msgid "DRY RUN" msgstr "" #. translators: %d: User ID -#: php/class-wp-cli.php:163 +#: php/class-wp-cli.php:172 msgid "Attempting to generate guest author for user ID %d." msgstr "" -#: php/class-wp-cli.php:367 +#. translators: 1: User ID 2: Error message returned from guest author +#. generation attempt +#: php/class-wp-cli.php:188 +msgid "Error while attempting to generate guest author for user ID %1$d: %2$s" +msgstr "" + +#. translators: 1: User ID 2: Guest Author ID +#: php/class-wp-cli.php:199 +msgid "User ID %1$d is now linked to Guest Author %2$d" +msgstr "" + +#: php/class-wp-cli.php:395 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:371 +#: php/class-wp-cli.php:399 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:381 +#: php/class-wp-cli.php:409 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:389 +#: php/class-wp-cli.php:417 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:395 +#: php/class-wp-cli.php:423 msgid "All done! %d posts were affected." msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index c74d24dc..9080db4e 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -33,6 +33,9 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * --not-a-dry-run * By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. When you are ready to modify data, pass this flag. * + * --log-output + * Passing this flag will output the results of the attempts at guest author creation. It logs to STDOUT, but you can redirect it to a file if you wish. + * * ## EXAMPLES * * wp co-authors-plus create-guest-authors @@ -53,6 +56,9 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * wp co-authors-plus create-guest-authors --not-a-dry-run * Will actually modify your database and generate guest authors. * + * wp co-authors-plus create-guest-authors --log-output + * Show results of guest author creation attempts as they happen. + * * @since 3.0 * * @subcommand create-guest-authors @@ -65,6 +71,7 @@ public function create_guest_authors( $args, $assoc_args ) { 'batch-size' => 1000, 'force-subscribers' => false, 'not-a-dry-run' => false, + 'log-output' => false, ); $this->args = wp_parse_args( $assoc_args, $defaults ); @@ -93,6 +100,12 @@ public function create_guest_authors( $args, $assoc_args ) { $dry_run = true; } + if ( is_bool( $this->args['log-output'] ) && true === $this->args['log-output'] ) { + $log_output = true; + } else { + $log_output = false; + } + foreach ( $role_whitelist as $role ) { // Does this role exist in this instance? if ( ! $GLOBALS['wp_roles']->is_role( $role ) ) { @@ -168,10 +181,29 @@ public function create_guest_authors( $args, $assoc_args ) { $result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID ); if ( is_wp_error( $result ) ) { $skipped++; + if ( true === $log_output ) { + foreach ( $result->get_error_messages() as $error_message ) { + WP_CLI::line( sprintf( + /* translators: 1: User ID 2: Error message returned from guest author generation attempt */ + __( 'Error while attempting to generate guest author for user ID %1$d: %2$s', 'co-authors-plus' ), + $user->ID, + $error_message + ) ); + } + } } else { $created++; + if ( true === $log_output ) { + WP_CLI::line( sprintf( + /* translators: 1: User ID 2: Guest Author ID */ + __( 'User ID %1$d is now linked to Guest Author %2$d', 'co-authors-plus' ), + $user->ID, + $result + ) ); + } } $progress->tick(); + } $progress->finish(); WP_CLI::line( 'All done! Here are your results:' ); From 7d4726d2650271b6fbaa741e6c1c29e9e13a96d0 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 08:20:41 -0300 Subject: [PATCH 225/231] Change method of validating inputs --- php/class-wp-cli.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 9080db4e..580b4057 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -76,15 +76,14 @@ public function create_guest_authors( $args, $assoc_args ) { $this->args = wp_parse_args( $assoc_args, $defaults ); - if ( is_array( $this->args['roles'] ) ) { - $role_whitelist = $this->args['roles']; - } else { - $role_whitelist = explode( ',', $this->args['roles'] ); + $role_whitelist = $this->args['roles']; + + if ( ! is_array( $role_whitelist ) ) { + $role_whitelist = explode( ',', $role_whitelist ); } - if ( $this->args['batch-size'] > 0 && is_numeric( $this->args['batch-size'] ) ) { - $batch_size = (int) $this->args['batch-size']; - } else { + $batch_size = (int) $this->args['batch-size']; + if ( $batch_size <= 0 ) { WP_CLI::error( __( 'Batch size must be an integer greater than zero.', 'co-authors-plus' ) ); } From 683a9962c6321f14e9999decf97573c5bbd396ce Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 08:23:30 -0300 Subject: [PATCH 226/231] Add reference to new --force-subscribers flag in error message --- languages/co-authors-plus.pot | 29 +++++++++++++++-------------- php/class-wp-cli.php | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/languages/co-authors-plus.pot b/languages/co-authors-plus.pot index 798197ff..7a54b90c 100755 --- a/languages/co-authors-plus.pot +++ b/languages/co-authors-plus.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Co-Authors Plus 3.3.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Co-Authors-Plus\n" -"POT-Creation-Date: 2018-07-31 23:35:45+00:00\n" +"POT-Creation-Date: 2018-08-01 11:22:50+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -530,58 +530,59 @@ msgstr "" msgid "Filter" msgstr "" -#: php/class-wp-cli.php:88 +#: php/class-wp-cli.php:87 msgid "Batch size must be an integer greater than zero." msgstr "" #. translators: %s: User role -#: php/class-wp-cli.php:114 +#: php/class-wp-cli.php:113 msgid "Role %s does not exist." msgstr "" -#: php/class-wp-cli.php:122 +#: php/class-wp-cli.php:121 msgid "" "For performance reasons, subscribers cannot be made guest authors via wp-" -"cli. Please use the admin interface." +"cli. Please use the admin interface, or pass the argument --force-" +"subscribers." msgstr "" -#: php/class-wp-cli.php:168 +#: php/class-wp-cli.php:167 msgid "DRY RUN" msgstr "" #. translators: %d: User ID -#: php/class-wp-cli.php:172 +#: php/class-wp-cli.php:171 msgid "Attempting to generate guest author for user ID %d." msgstr "" #. translators: 1: User ID 2: Error message returned from guest author #. generation attempt -#: php/class-wp-cli.php:188 +#: php/class-wp-cli.php:187 msgid "Error while attempting to generate guest author for user ID %1$d: %2$s" msgstr "" #. translators: 1: User ID 2: Guest Author ID -#: php/class-wp-cli.php:199 +#: php/class-wp-cli.php:198 msgid "User ID %1$d is now linked to Guest Author %2$d" msgstr "" -#: php/class-wp-cli.php:395 +#: php/class-wp-cli.php:394 msgid "Please specify a valid user_login" msgstr "" -#: php/class-wp-cli.php:399 +#: php/class-wp-cli.php:398 msgid "Please specify a valid co-author login" msgstr "" -#: php/class-wp-cli.php:409 +#: php/class-wp-cli.php:408 msgid "Skipping - Post #%d already has co-authors assigned: %s" msgstr "" -#: php/class-wp-cli.php:417 +#: php/class-wp-cli.php:416 msgid "Updating - Adding %s's byline to post #%d" msgstr "" -#: php/class-wp-cli.php:423 +#: php/class-wp-cli.php:422 msgid "All done! %d posts were affected." msgstr "" diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 580b4057..1ff1e329 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -118,7 +118,7 @@ public function create_guest_authors( $args, $assoc_args ) { // Subscribers cannot be made guest authors en masse // due to potential performance issues (sites can have millions of subscribers). if ( 'subscriber' === $role && false === $force_subscribers ) { - WP_CLI::error( __( 'For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface.', 'co-authors-plus' ) ); + WP_CLI::error( __( 'For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface, or pass the argument --force-subscribers.', 'co-authors-plus' ) ); } } From 4c3c6ad8c261c2f64db30e085beb2a71d95b6bd3 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 09:07:15 -0300 Subject: [PATCH 227/231] Modifying documentation in accordance with the standard --- php/class-wp-cli.php | 74 ++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 1ff1e329..1f6c4950 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -15,53 +15,67 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * * ## OPTIONS * - * --roles - * Provide a comma-separated list of roles to generate guest authors for. + * [--roles=] + * : Provide a comma-separated list of roles to generate guest authors for. + * --- + * default: administrator,editor,author,contributor + * --- * - * Defaults to: administrator,editor,author,contributor. + * [--batch-size=] + * : Many sites have a large user list, which could cause troubles when filtering roles prior to guest author generation. This allows you to set a batch size appropriate for your server's memory limit. Any integer greater than 0. Decimals (e.g. 500.5) will be rounded down, exponents (e.g. 10e6) will be ignored. + * --- + * default: 1000 + * --- * - * --batch-size - * Many sites have a large user list, which could cause troubles when filtering roles prior to guest author generation. This allows you to set a batch size appropriate for your server's memory limit. + * [--force-subscribers] + * : For performance reasons, it is not recommended you include subscribers in your automatic generation. Using the admin interface to generate one-off subscriber guest authors is likely to be a better alternative. However, you can pass this flag to include them. * - * Defaults to: 1000. + * [--not-a-dry-run] + * : By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. When you are ready to modify data, pass this flag. * - * Must be an integer greater than 0. Decimals (e.g. 500.5) will be rounded down, exponents (e.g. 10e6) will be ignored. - * - * --force-subscribers - * For performance reasons, it is not recommended you include subscribers in your automatic generation. Using the admin interface to generate one-off subscriber guest authors is likely to be a better alternative. However, you can pass this flag to include them. - * - * --not-a-dry-run - * By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. When you are ready to modify data, pass this flag. - * - * --log-output - * Passing this flag will output the results of the attempts at guest author creation. It logs to STDOUT, but you can redirect it to a file if you wish. + * [--log-output] + * : Passing this flag will output the results of the attempts at guest author creation. It logs to STDOUT, but you can redirect it to a file if you wish. * * ## EXAMPLES * - * wp co-authors-plus create-guest-authors - * Generate guest authors for administrators, editors, authors, and contributors. + * # Simulate generating guest authors for administrators, editors, authors, and contributors. + * $ wp co-authors-plus create-guest-authors + * DRY RUN + * Attempting to generate guest author for user ID 1 + * + * # Generate guest authors for administrators, editors, authors, and contributors. + * $ wp co-authors-plus create-guest-authors --not-a-dry-run + * All done! Here are your results: * - * wp co-authors-plus create-guest-authors --roles=author,freelancer - * Generate guest authors only for authors and freelancers. + * # Generate guest authors only for authors and freelancers. + * $ wp co-authors-plus create-guest-authors --roles=author,freelancer + * All done! Here are your results: * - * wp co-authors-plus create-guest-authors --batch-size=5000 - * Generate guest authors, filtering in batches of 5000. + * # Generate guest authors, filtering in batches of 5000. + * $ wp co-authors-plus create-guest-authors --batch-size=5000 + * All done! Here are your results: * - * wp co-authors-plus create-guest-authors --roles=author,subscriber - * This command will fail. + * # This command will fail. + * $ wp co-authors-plus create-guest-authors --roles=author,subscriber + * For performance reasons, subscribers cannot be made guest authors via wp-cli. Please use the admin interface, or pass the argument --force-subscribers. * - * wp co-authors-plus create-guest-authors --roles=author,subscriber --force-subscribers - * This command will succeed. NOTE: Your site may have many subscribers, which may make the command take a long time to run. + * # This command will succeed. NOTE: Your site may have many subscribers, which may make the command take a long time to run. + * $ wp co-authors-plus create-guest-authors --roles=author,subscriber --force-subscribers + * All done! Here are your results: * - * wp co-authors-plus create-guest-authors --not-a-dry-run - * Will actually modify your database and generate guest authors. + * # Will actually modify your database and generate guest authors. + * $ wp co-authors-plus create-guest-authors --not-a-dry-run + * All done! Here are your results: * - * wp co-authors-plus create-guest-authors --log-output - * Show results of guest author creation attempts as they happen. + * # Show results of guest author creation attempts as they happen. + * $ wp co-authors-plus create-guest-authors --log-output + * User ID 1 is now linked to Guest Author 2. + * Error while attempting to generate guest author for user ID 3: (error message) * * @since 3.0 * * @subcommand create-guest-authors + * @synopsis [--roles=] [--batch-size=] [--force-subscribers] [--not-a-dry-run] [--log-output] */ public function create_guest_authors( $args, $assoc_args ) { global $coauthors_plus; From 5c4b1a76c3d3c55d8e75117dd776212fdf66e6a1 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 09:15:47 -0300 Subject: [PATCH 228/231] Modify name of --not-a-dry-run flag to --dry-run for greater clarity. The flag is now named --dry-run to take advantage of built-in command negation functionality, allowing users to pass --no-dry-run to turn it off. --- php/class-wp-cli.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 1f6c4950..703059d6 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -30,8 +30,8 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * [--force-subscribers] * : For performance reasons, it is not recommended you include subscribers in your automatic generation. Using the admin interface to generate one-off subscriber guest authors is likely to be a better alternative. However, you can pass this flag to include them. * - * [--not-a-dry-run] - * : By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. When you are ready to modify data, pass this flag. + * [--dry-run] + * : By default, the command outputs the IDs of the users it would have attempted to generate guest authors for, had this not been a dry run. When you are ready to modify data, pass --no-dry-run. * * [--log-output] * : Passing this flag will output the results of the attempts at guest author creation. It logs to STDOUT, but you can redirect it to a file if you wish. @@ -44,7 +44,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * Attempting to generate guest author for user ID 1 * * # Generate guest authors for administrators, editors, authors, and contributors. - * $ wp co-authors-plus create-guest-authors --not-a-dry-run + * $ wp co-authors-plus create-guest-authors --no-dry-run * All done! Here are your results: * * # Generate guest authors only for authors and freelancers. @@ -64,7 +64,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * All done! Here are your results: * * # Will actually modify your database and generate guest authors. - * $ wp co-authors-plus create-guest-authors --not-a-dry-run + * $ wp co-authors-plus create-guest-authors --no-dry-run * All done! Here are your results: * * # Show results of guest author creation attempts as they happen. @@ -75,7 +75,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command { * @since 3.0 * * @subcommand create-guest-authors - * @synopsis [--roles=] [--batch-size=] [--force-subscribers] [--not-a-dry-run] [--log-output] + * @synopsis [--roles=] [--batch-size=] [--force-subscribers] [--dry-run] [--log-output] */ public function create_guest_authors( $args, $assoc_args ) { global $coauthors_plus; @@ -84,7 +84,7 @@ public function create_guest_authors( $args, $assoc_args ) { 'roles' => array( 'administrator', 'editor', 'author', 'contributor' ), 'batch-size' => 1000, 'force-subscribers' => false, - 'not-a-dry-run' => false, + 'dry-run' => true, 'log-output' => false, ); @@ -101,16 +101,16 @@ public function create_guest_authors( $args, $assoc_args ) { WP_CLI::error( __( 'Batch size must be an integer greater than zero.', 'co-authors-plus' ) ); } - if ( is_bool( $this->args['force-subscribers'] ) && true === $this->args['force-subscribers'] ) { + if ( true === $this->args['force-subscribers'] ) { $force_subscribers = true; } else { $force_subscribers = false; } - if ( is_bool( $this->args['not-a-dry-run'] ) && true === $this->args['not-a-dry-run'] ) { - $dry_run = false; - } else { + if ( true === $this->args['dry-run'] ) { $dry_run = true; + } else { + $dry_run = false; } if ( is_bool( $this->args['log-output'] ) && true === $this->args['log-output'] ) { From 7231625d3d42c3b3680c3ba036baa430944a4f64 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 09:37:38 -0300 Subject: [PATCH 229/231] Change sort column for user query. Despite there being an index on the user_login column in wp_users, MySQL does not use it and instead performs a filesort. So now the query orders by ID. Props sboisvert for the subtle poke that something wasn't quite right with the query. --- php/class-wp-cli.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 703059d6..e3a34b41 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -136,7 +136,8 @@ public function create_guest_authors( $args, $assoc_args ) { } } - $users_unfiltered_query = new WP_User_Query( array( 'number' => $batch_size ) ); + // Ordering by ID because MySQL doesn't use the user_login array index for sorting. + $users_unfiltered_query = new WP_User_Query( array( 'number' => $batch_size, 'orderby' => 'ID' ) ); $users_count = $users_unfiltered_query->get_total(); $users_unfiltered = $users_unfiltered_query->get_results(); $users = array(); @@ -160,6 +161,7 @@ public function create_guest_authors( $args, $assoc_args ) { array( 'number' => $batch_size, 'offset' => $batch_size * $i, + 'orderby' => 'ID' ) ); From dd0b2fe0e0b07c439425e891c97a6d08c7fb8cf2 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 09:48:01 -0300 Subject: [PATCH 230/231] Spacing modifications in keeping with coding standards --- php/class-wp-cli.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index e3a34b41..9dd4e428 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -137,7 +137,12 @@ public function create_guest_authors( $args, $assoc_args ) { } // Ordering by ID because MySQL doesn't use the user_login array index for sorting. - $users_unfiltered_query = new WP_User_Query( array( 'number' => $batch_size, 'orderby' => 'ID' ) ); + $users_unfiltered_query = new WP_User_Query( + array( + 'number' => $batch_size, + 'orderby' => 'ID', + ) + ); $users_count = $users_unfiltered_query->get_total(); $users_unfiltered = $users_unfiltered_query->get_results(); $users = array(); @@ -159,8 +164,8 @@ public function create_guest_authors( $args, $assoc_args ) { for ( $i = 1; $i < $num_batches; $i++ ) { $users_unfiltered_query = new WP_User_Query( array( - 'number' => $batch_size, - 'offset' => $batch_size * $i, + 'number' => $batch_size, + 'offset' => $batch_size * $i, 'orderby' => 'ID' ) ); From 86eb916e5a904dfbe7d2f2ef3d5fce7d95ea9e92 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 1 Aug 2018 12:45:46 -0300 Subject: [PATCH 231/231] Condense assignment operations for cli flags. Due to changes in how the flags are read, we can now condense our checks into a series of oneliners. --- php/class-wp-cli.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 9dd4e428..541e87d3 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -101,23 +101,9 @@ public function create_guest_authors( $args, $assoc_args ) { WP_CLI::error( __( 'Batch size must be an integer greater than zero.', 'co-authors-plus' ) ); } - if ( true === $this->args['force-subscribers'] ) { - $force_subscribers = true; - } else { - $force_subscribers = false; - } - - if ( true === $this->args['dry-run'] ) { - $dry_run = true; - } else { - $dry_run = false; - } - - if ( is_bool( $this->args['log-output'] ) && true === $this->args['log-output'] ) { - $log_output = true; - } else { - $log_output = false; - } + $force_subscribers = $this->args['force-subscribers']; + $dry_run = $this->args['dry-run']; + $log_output = $this->args['log-output']; foreach ( $role_whitelist as $role ) { // Does this role exist in this instance?