From 461e0ca70af0d83e845c26b99bc164a6fe6934d6 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 12 May 2016 11:28:36 +0100 Subject: [PATCH 001/269] 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/269] 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/269] 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/269] 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/269] 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/269] 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 caed548640cd4fd63a895f3d6a83fd31a92276df Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 13 Jul 2016 15:49:56 -0600 Subject: [PATCH 007/269] Add filter to get_coauthors Adds a filter to get_coauthors to allow hooking in and providing coauthor objects that might not exist in the db. Use case: we have several places in our site where we output authors based on get_coauthors (templates, some custom POST requests we send out to some API's, etc). We have the need to "fake" some coauthors in some instances, and want to be able to dynamically insert them in when a post meets certain criteria. Being able to filter the data that gets returned when calling get_coauthors will allow us to take advantage of all existing code where we use get_coauthors, but will allow us to dynamically inject "fake" authors when needed. --- template-tags.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-tags.php b/template-tags.php index 725fc47f..b9b06567 100644 --- a/template-tags.php +++ b/template-tags.php @@ -36,7 +36,7 @@ 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. } - return $coauthors; + return apply_filters( 'get_coauthors', $coauthors, $post_id ); } /** From e0b8abce254ea63f0288542e8c786a4c3783d454 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 19 Jul 2016 09:56:50 -0600 Subject: [PATCH 008/269] 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 009/269] 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 010/269] 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 011/269] 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 012/269] 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 013/269] 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 014/269] 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 015/269] 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 016/269] 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 017/269] 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 018/269] 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 019/269] 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 020/269] 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 021/269] 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 022/269] 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 023/269] 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 024/269] 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 025/269] 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 026/269] 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 027/269] 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 028/269] 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 029/269] 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 030/269] 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 031/269] 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 032/269] 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 033/269] 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 034/269] 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 035/269] 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 036/269] 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 037/269] 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 038/269] 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 039/269] 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 040/269] 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 041/269] 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 042/269] 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 043/269] 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 044/269] 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 045/269] 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 046/269] 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 047/269] 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 048/269] 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 049/269] 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 050/269] 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 051/269] 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 052/269] 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 053/269] 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 054/269] 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 055/269] 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 056/269] 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 057/269] 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 058/269] 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 059/269] 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 060/269] 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 061/269] 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 062/269] 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 063/269] 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 064/269] 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 065/269] 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 066/269] 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 067/269] 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 068/269] 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 069/269] 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 070/269] 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 071/269] 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 072/269] 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 073/269] 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 074/269] 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 075/269] 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 076/269] 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 077/269] 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 078/269] 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 079/269] 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 080/269] 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 081/269] 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 082/269] 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 083/269] 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 084/269] 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 085/269] 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 086/269] 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 087/269] 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 088/269] 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 089/269] 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 090/269] 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 091/269] 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 092/269] 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 093/269] 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 094/269] 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 095/269] 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 096/269] 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 097/269] 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 098/269] 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 099/269] 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 100/269] 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 101/269] 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 102/269] 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 103/269] 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 104/269] 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 105/269] 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 106/269] 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 107/269] 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 108/269] 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 109/269] 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 110/269] 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 111/269] 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 112/269] 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 113/269] 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 114/269] 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 115/269] 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 116/269] 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 117/269] 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 118/269] 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 119/269] 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 120/269] 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 121/269] 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 122/269] [#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 123/269] [#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 124/269] [#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 125/269] [#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 fc6d1cfaadf5934e7afd7f59cb0174c260b11776 Mon Sep 17 00:00:00 2001 From: RoyTheRoyalBoy Date: Fri, 22 Dec 2017 04:29:10 -0500 Subject: [PATCH 126/269] Delete is_array() condition Since our function already defines/declares all_posts as an array in line 18, we shouldn't need to check it it's an array since we're guaranteed that it'll be an array. --- upgrade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upgrade.php b/upgrade.php index f061cedd..b4c52952 100644 --- a/upgrade.php +++ b/upgrade.php @@ -17,7 +17,7 @@ function coauthors_plus_upgrade_20() { // Get all posts with meta_key _coauthor $all_posts = get_posts( array( 'numberposts' => '-1', 'meta_key' => '_coauthor' ) ); - if ( is_array( $all_posts ) ) { + //if ( is_array( $all_posts ) ) { Perhaps we don't need to check if it's an array, we're already done so in our get_posts function foreach ( $all_posts as $single_post ) { // reset execution time limit @@ -44,5 +44,5 @@ function coauthors_plus_upgrade_20() { $coauthors_plus->add_coauthors( $single_post->ID, $coauthors ); } - } + //} } From 8bf7a9a370dfa8c0295184e5cee944b706befbe0 Mon Sep 17 00:00:00 2001 From: sanketio Date: Fri, 22 Dec 2017 18:45:04 +0530 Subject: [PATCH 127/269] [#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 128/269] [#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 129/269] [#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 130/269] [#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 131/269] [#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 132/269] [#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 133/269] [#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 134/269] [#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 135/269] [#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 136/269] [#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 137/269] [#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 138/269] [#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 139/269] [#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 140/269] [#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 141/269] [#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 142/269] [#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 143/269] [#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 144/269] [#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 145/269] [#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 146/269] [#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 147/269] [#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 148/269] [#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 149/269] [#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 150/269] [#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 151/269] [#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 152/269] [#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 153/269] [#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 154/269] [#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 155/269] [#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 156/269] [#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 157/269] [#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 158/269] [#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 159/269] [#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 160/269] [#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 161/269] [#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 162/269] [#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 163/269] [#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 164/269] [#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 165/269] [#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 166/269] [#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 167/269] [#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 168/269] [#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 169/269] 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 170/269] [#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 171/269] [#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 172/269] [#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 790c1b24214e5542a6419a79219d7b7c60eb3c7d Mon Sep 17 00:00:00 2001 From: RoyTheRoyalBoy Date: Wed, 31 Jan 2018 15:10:56 -0500 Subject: [PATCH 173/269] Update upgrade.php --- upgrade.php | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/upgrade.php b/upgrade.php index b4c52952..c06f8651 100644 --- a/upgrade.php +++ b/upgrade.php @@ -17,32 +17,29 @@ function coauthors_plus_upgrade_20() { // Get all posts with meta_key _coauthor $all_posts = get_posts( array( 'numberposts' => '-1', 'meta_key' => '_coauthor' ) ); - //if ( is_array( $all_posts ) ) { Perhaps we don't need to check if it's an array, we're already done so in our get_posts function - foreach ( $all_posts as $single_post ) { - - // reset execution time limit - set_time_limit( 60 ); - - // create new array - $coauthors = array(); - // get author id -- try to use get_profile - $coauthor = get_user_by( 'id', (int) $single_post->post_author ); - if ( is_object( $coauthor ) ) { - $coauthors[] = $coauthor->user_login; - } - // get coauthors id - $legacy_coauthors = get_post_meta( $single_post->ID, '_coauthor' ); - - if ( is_array( $legacy_coauthors ) ) { - foreach ( $legacy_coauthors as $legacy_coauthor ) { - $legacy_coauthor_login = get_user_by( 'id', (int) $legacy_coauthor ); - if ( is_object( $legacy_coauthor_login ) && ! in_array( $legacy_coauthor_login->user_login, $coauthors ) ) { - $coauthors[] = $legacy_coauthor_login->user_login; - } + + foreach ( $all_posts as $single_post ) { + // reset execution time limit + set_time_limit( 60 ); + + // create new array + $coauthors = array(); + // get author id -- try to use get_profile + $coauthor = get_user_by( 'id', (int) $single_post->post_author ); + if ( is_object( $coauthor ) ) { + $coauthors[] = $coauthor->user_login; + } + // get coauthors id + $legacy_coauthors = get_post_meta( $single_post->ID, '_coauthor' ); + + if ( is_array( $legacy_coauthors ) ) { + foreach ( $legacy_coauthors as $legacy_coauthor ) { + $legacy_coauthor_login = get_user_by( 'id', (int) $legacy_coauthor ); + if ( is_object( $legacy_coauthor_login ) && ! in_array( $legacy_coauthor_login->user_login, $coauthors ) ) { + $coauthors[] = $legacy_coauthor_login->user_login; } } - $coauthors_plus->add_coauthors( $single_post->ID, $coauthors ); - } - //} + $coauthors_plus->add_coauthors( $single_post->ID, $coauthors ); + } } From 930129fbbc2ab63cf935d4698fcb257116ff8b44 Mon Sep 17 00:00:00 2001 From: sanketio Date: Thu, 1 Feb 2018 17:49:34 +0530 Subject: [PATCH 174/269] [#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 175/269] 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 176/269] 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 177/269] 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 178/269] [#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 179/269] 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 180/269] 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 181/269] 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 182/269] 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 7c9287b5422c9ca124f8051358304fc46aece5f5 Mon Sep 17 00:00:00 2001 From: Norris Date: Thu, 29 Mar 2018 16:37:00 +0300 Subject: [PATCH 183/269] Allow `coauthors_wp_list_authors` to only query authors with posts --- template-tags.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/template-tags.php b/template-tags.php index efd59f69..30b8d271 100644 --- a/template-tags.php +++ b/template-tags.php @@ -443,6 +443,7 @@ function the_coauthor_meta( $field, $user_id = 0 ) { * feed (string) (''): If isn't empty, show links to author's feeds. * feed_image (string) (''): If isn't empty, use this image to link to feeds. * echo (boolean) (true): Set to false to return the output, instead of echoing. + * authors_with_posts_only (boolean) (false): If true, don't query for authors with no posts. * @param array $args The argument array. * @return null|string The output, if echo is set to false. */ @@ -460,7 +461,8 @@ 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 + 'guest_authors_only' => false, + 'authors_with_posts_only' => false, ); $args = wp_parse_args( $args, $defaults ); @@ -468,8 +470,12 @@ function coauthors_wp_list_authors( $args = array() ) { $term_args = array( 'orderby' => 'name', - 'hide_empty' => 0, 'number' => (int) $args['number'], + /* + * Historically, this was set to always be `0` ignoring `$args['hide_empty']` value + * To avoid any backwards incompatibility, inventing `authors_with_posts_only` that defaults to false + */ + 'hide_empty' => (boolean) $args['authors_with_posts_only'], ); $author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args ); From da40f56bd9d90c540519281449d04ca7a446564d Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 7 Apr 2018 17:35:36 +0100 Subject: [PATCH 184/269] 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 185/269] 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 186/269] 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 d336233dbcd5b32256828e9c0bac12fd4b366cb3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 10 Apr 2018 09:27:01 -0700 Subject: [PATCH 187/269] Update credits with added links to previous plugin and removal of broken link --- README.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fec0d5c5..8c309a34 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add writers as bylines without creating WordPress user accounts. Simply [create 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). +This plugin is an almost complete rewrite of the [Co-Authors](https://wordpress.org/plugins/co-authors/) plugin originally developed by Weston Ruter (2007). The original plugin was inspired by the '[Multiple Authors](https://txfx.net/2005/08/16/new-plugin-multiple-authors/)' plugin by Mark Jaquith (2005). ## Frequently Asked Questions diff --git a/readme.txt b/readme.txt index 5ff5a7ed..12354a2f 100644 --- a/readme.txt +++ b/readme.txt @@ -15,7 +15,7 @@ Add writers as bylines without creating WordPress user accounts. Simply [create 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). +This plugin is an almost complete rewrite of the [Co-Authors](https://wordpress.org/plugins/co-authors/) plugin originally developed by Weston Ruter (2007). The original plugin was inspired by the '[Multiple Authors](https://txfx.net/2005/08/16/new-plugin-multiple-authors/)' plugin by Mark Jaquith (2005). == Frequently Asked Questions == From 2755efc708de856388b5b136e2499a0ee5602e53 Mon Sep 17 00:00:00 2001 From: Binod Kalathil Date: Sat, 14 Apr 2018 16:06:33 +0530 Subject: [PATCH 188/269] 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 189/269] 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 190/269] 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 fbde64c6207a16fc2e6c4db0a15c46d3745c1283 Mon Sep 17 00:00:00 2001 From: Norris Date: Thu, 29 Mar 2018 16:37:00 +0300 Subject: [PATCH 191/269] Allow `coauthors_wp_list_authors` to only query authors with posts --- template-tags.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/template-tags.php b/template-tags.php index 794c7150..9bb11fdb 100644 --- a/template-tags.php +++ b/template-tags.php @@ -527,6 +527,7 @@ function the_coauthor_meta( $field, $user_id = 0 ) { * feed (string) (''): If isn't empty, show links to author's feeds. * feed_image (string) (''): If isn't empty, use this image to link to feeds. * echo (boolean) (true): Set to false to return the output, instead of echoing. + * authors_with_posts_only (boolean) (false): If true, don't query for authors with no posts. * @param array $args The argument array. * @return null|string The output, if echo is set to false. */ @@ -544,7 +545,8 @@ 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 + 'guest_authors_only' => false, + 'authors_with_posts_only' => false, ); $args = wp_parse_args( $args, $defaults ); @@ -552,8 +554,12 @@ function coauthors_wp_list_authors( $args = array() ) { $term_args = array( 'orderby' => 'name', - 'hide_empty' => 0, 'number' => (int) $args['number'], + /* + * Historically, this was set to always be `0` ignoring `$args['hide_empty']` value + * To avoid any backwards incompatibility, inventing `authors_with_posts_only` that defaults to false + */ + 'hide_empty' => (boolean) $args['authors_with_posts_only'], ); $author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args ); From 869e0601953357c9da7ef7856060ec8eb3442966 Mon Sep 17 00:00:00 2001 From: rebeccahum Date: Tue, 22 May 2018 16:36:26 -0600 Subject: [PATCH 192/269] 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 193/269] 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 194/269] 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 195/269] 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 196/269] 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 197/269] 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 198/269] 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 199/269] 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 200/269] 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 201/269] 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 202/269] 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 203/269] 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 204/269] 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 205/269] 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 206/269] 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 207/269] 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 208/269] 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 209/269] 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 210/269] 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 211/269] 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 212/269] 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 29ef164db778945f7acbaefafa2f85725746396f Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 13 Jun 2018 15:34:36 +0200 Subject: [PATCH 213/269] Added functions to import existing authors on plugin activation through WP-Cron. Added function to update author term on WP user profile update. --- co-authors-plus.php | 28 +++++++++++++++++++ php/coauthors-install.php | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 php/coauthors-install.php diff --git a/co-authors-plus.php b/co-authors-plus.php index 0f7cfb30..ca6ef227 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -37,6 +37,7 @@ require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); +require_once( dirname( __FILE__ ) . '/php/coauthors-install.php' ); require_once( dirname( __FILE__ ) . '/php/class-coauthors-template-filters.php' ); require_once( dirname( __FILE__ ) . '/php/integrations/amp.php' ); @@ -68,6 +69,8 @@ class CoAuthors_Plus { * __construct() */ function __construct() { + //Set up on activation + register_activation_hook( __FILE__, 'cap_install_setup' ); // Register our models add_action( 'init', array( $this, 'action_init' ) ); @@ -131,6 +134,10 @@ function __construct() { // Filter to correct author on author archive page add_filter( 'get_the_archive_title', array( $this, 'filter_author_archive_title'), 10, 2 ); + + // Update author term on user update + add_action( 'user_register', array( $this, 'action_user_profile_update' ) ); + add_action( 'profile_update', array( $this, 'action_user_profile_update' ) ); } /** @@ -1221,6 +1228,7 @@ public function search_authors( $search = '', $ignored_authors = array() ) { return (array) $found_users; } + /** * Modify get_terms() to LIKE against the term description instead of the term name * @@ -1446,6 +1454,26 @@ public function update_author_term( $coauthor ) { return $this->get_author_term( $coauthor ); } + /** + * Update author term when user profile is updated. + * + * @param int $userid + */ + function action_user_profile_update( $userid ) { + global $coauthors_plus; + + if( ! current_user_can( 'manage_options' ) ) { + return; + } + + $user = get_userdata( $userid ); + + // Update author term only if user can be added as coauthor + if( $user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { + $coauthors_plus->update_author_term( $user ); + } + } + /** * Filter Edit Flow's 'ef_calendar_item_information_fields' to add co-authors * diff --git a/php/coauthors-install.php b/php/coauthors-install.php new file mode 100644 index 00000000..5519adc9 --- /dev/null +++ b/php/coauthors-install.php @@ -0,0 +1,57 @@ + 'registered', + 'order' => 'ASC', + 'offset' => $imported_count, + 'number' => $number_to_update, + 'fields' => 'all_with_meta', + ); + $found_users = get_users( $args ); + + if ( empty( $found_users ) ) { + return; + } + + foreach ( $found_users as $found_user ) { + //Check that user has permission to be added as coauthor + if( ! $found_user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { + continue; + } + + $coauthors_plus->update_author_term( $found_user ); + } + + $imported_count += $number_to_update; + + wp_schedule_single_event( time(), 'cap_import_existing_users', array( $imported_count ) ); +} +add_action( 'cap_import_existing_users', 'cap_create_author_terms' ); \ No newline at end of file From 64221e0f6b3f0718f4d7326dfa8d5c5f5884d62e Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 13 Jun 2018 15:56:23 +0200 Subject: [PATCH 214/269] Updated search_authors() removing querying for WP users and related term updating. Also deleting user term if user does not have permission to be added as coauthor but has an author term (and shows up in search). Updated tests for search_authors() to work with the edits - they need to create author terms when they create test users, before calling search_authors(). --- co-authors-plus.php | 22 +++++++++++----------- tests/test-coauthors-plus.php | 8 ++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index ca6ef227..79dbeeac 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1165,13 +1165,12 @@ public function ajax_suggest() { /** * Get matching co-authors based on a search value + * + * @param string $search + * @param array $ignored_authors array + * @return array found users */ public function search_authors( $search = '', $ignored_authors = array() ) { - - // Since 2.7, we're searching against the term description for the fields - // instead of the user details. If the term is missing, we probably need to - // backfill with user details. Let's do this first... easier than running - // an upgrade script that could break on a lot of users $args = array( 'count_total' => false, 'search' => sprintf( '*%s*', $search ), @@ -1193,10 +1192,10 @@ public function search_authors( $search = '', $ignored_authors = array() ) { } $args = array( - 'search' => $search, - 'get' => 'all', - 'number' => 10, - ); + 'search' => $search, + 'get' => 'all', + 'number' => 10, + ); $args = apply_filters( 'coauthors_search_authors_get_terms_args', $args ); add_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) ); $found_terms = get_terms( $this->coauthor_taxonomy, $args ); @@ -1218,17 +1217,18 @@ public function search_authors( $search = '', $ignored_authors = array() ) { // Allow users to always filter out certain users if needed (e.g. administrators) $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 ) ) { unset( $found_users[ $key ] ); + + //If user does not have permission, they should not have a term in the first place } else if ( 'wpuser' === $found_user->type && false === $found_user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { unset( $found_users[ $key ] ); + wp_delete_term( $term->term_id, $this->coauthor_taxonomy ); } } return (array) $found_users; } - /** * Modify get_terms() to LIKE against the term description instead of the term name * diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 68d7ecb6..159642ab 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -3,12 +3,15 @@ class Test_CoAuthors_Plus extends CoAuthorsPlus_TestCase { public function setUp() { + global $coauthors_plus; 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' ) ); + cap_create_user_terms(); //users without terms don't exist for CAP + $this->post = $this->factory->post->create_and_get( array( 'post_author' => $this->author1->ID, 'post_status' => 'publish', @@ -363,6 +366,7 @@ public function test_search_authors_no_args() { $subscriber1 = $this->factory->user->create_and_get( array( 'role' => 'subscriber', ) ); + cap_create_user_terms(); $authors = $coauthors_plus->search_authors(); @@ -373,6 +377,7 @@ public function test_search_authors_no_args() { $contributor1 = $this->factory->user->create_and_get( array( 'role' => 'contributor', ) ); + cap_create_user_terms(); $authors = $coauthors_plus->search_authors(); @@ -428,6 +433,7 @@ public function test_search_authors_when_search_keyword_provided() { $subscriber1 = $this->factory->user->create_and_get( array( 'role' => 'subscriber', ) ); + cap_create_user_terms(); $this->assertEmpty( $coauthors_plus->search_authors( $subscriber1->ID ) ); } @@ -453,6 +459,7 @@ public function test_search_authors_when_ignored_authors_provided() { $author2 = $this->factory->user->create_and_get( array( 'role' => 'author', ) ); + cap_create_user_terms(); $authors = $coauthors_plus->search_authors( '', $ignored_authors ); @@ -487,6 +494,7 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov 'role' => 'author', 'user_login' => 'author2', ) ); + cap_create_user_terms(); $authors = $coauthors_plus->search_authors( 'author', $ignored_authors ); From 4295a432b6d69ac82d6773450114ef2d386409a9 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 13 Jun 2018 16:03:06 +0200 Subject: [PATCH 215/269] NOW removing querying WP Users from search_authors(). Missed the save in the editor, ouch! --- co-authors-plus.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 79dbeeac..8cd1c933 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1171,26 +1171,6 @@ public function ajax_suggest() { * @return array found users */ public function search_authors( $search = '', $ignored_authors = array() ) { - $args = array( - 'count_total' => false, - 'search' => sprintf( '*%s*', $search ), - 'search_columns' => array( - 'ID', - 'display_name', - 'user_email', - 'user_login', - ), - 'fields' => 'all_with_meta', - ); - $found_users = get_users( $args ); - - foreach ( $found_users as $found_user ) { - $term = $this->get_author_term( $found_user ); - if ( empty( $term ) || empty( $term->description ) ) { - $this->update_author_term( $found_user ); - } - } - $args = array( 'search' => $search, 'get' => 'all', From 92f50adfc0f8ed4db4b1d44783e2196ec02ec3e9 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 13 Jun 2018 16:05:36 +0200 Subject: [PATCH 216/269] Fixed tests calling a function with wrong name. --- tests/test-coauthors-plus.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 159642ab..59a89315 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -10,7 +10,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' ) ); - cap_create_user_terms(); //users without terms don't exist for CAP + cap_create_author_terms(); //users without terms don't exist for CAP $this->post = $this->factory->post->create_and_get( array( 'post_author' => $this->author1->ID, @@ -366,7 +366,7 @@ public function test_search_authors_no_args() { $subscriber1 = $this->factory->user->create_and_get( array( 'role' => 'subscriber', ) ); - cap_create_user_terms(); + cap_create_author_terms(); $authors = $coauthors_plus->search_authors(); @@ -377,7 +377,7 @@ public function test_search_authors_no_args() { $contributor1 = $this->factory->user->create_and_get( array( 'role' => 'contributor', ) ); - cap_create_user_terms(); + cap_create_author_terms(); $authors = $coauthors_plus->search_authors(); @@ -433,7 +433,7 @@ public function test_search_authors_when_search_keyword_provided() { $subscriber1 = $this->factory->user->create_and_get( array( 'role' => 'subscriber', ) ); - cap_create_user_terms(); + cap_create_author_terms(); $this->assertEmpty( $coauthors_plus->search_authors( $subscriber1->ID ) ); } @@ -459,7 +459,7 @@ public function test_search_authors_when_ignored_authors_provided() { $author2 = $this->factory->user->create_and_get( array( 'role' => 'author', ) ); - cap_create_user_terms(); + cap_create_author_terms(); $authors = $coauthors_plus->search_authors( '', $ignored_authors ); @@ -494,7 +494,7 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov 'role' => 'author', 'user_login' => 'author2', ) ); - cap_create_user_terms(); + cap_create_author_terms(); $authors = $coauthors_plus->search_authors( 'author', $ignored_authors ); 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 217/269] 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 218/269] 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 771be16da1afcb5fddaedcae3900e35b18e1f616 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Thu, 14 Jun 2018 12:52:58 +0200 Subject: [PATCH 219/269] Making sure no coauthors are already assigned to a post before overwriting them in case of empty array --- co-authors-plus.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 0f7cfb30..47bf93c5 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -866,8 +866,13 @@ public function add_coauthors( $post_id, $coauthors, $append = false ) { } // A co-author is always required + // If no coauthor is provided AND no coauthors are currently set, assign to current user - retain old ones otherwise. if ( empty( $coauthors ) ) { - $coauthors = array( $current_user->user_login ); + if( empty( $existing_coauthors ) ) { + $coauthors = array( $current_user->user_login ); + } else { + $coauthors = $existing_coauthors; + } } // Set the co-authors From f62e827ebb9737ba3c1980d381e70520c0a394f5 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 15 Jun 2018 10:59:25 +0200 Subject: [PATCH 220/269] Removed permission check in action_user_profile_update --- co-authors-plus.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 8cd1c933..66356401 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1442,10 +1442,6 @@ public function update_author_term( $coauthor ) { function action_user_profile_update( $userid ) { global $coauthors_plus; - if( ! current_user_can( 'manage_options' ) ) { - return; - } - $user = get_userdata( $userid ); // Update author term only if user can be added as coauthor From b6262b7ade18525625ed0a93905b7d550d673172 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 15 Jun 2018 11:01:04 +0200 Subject: [PATCH 221/269] Changed orderby from `registered` to `user_nicename` in cap_create_author_terms() --- php/coauthors-install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/coauthors-install.php b/php/coauthors-install.php index 5519adc9..e2ee63e8 100644 --- a/php/coauthors-install.php +++ b/php/coauthors-install.php @@ -29,7 +29,7 @@ function cap_create_author_terms( $imported_count = 0, $number_to_update = 100 ) global $coauthors_plus; $args = array( - 'orderby' => 'registered', + 'orderby' => 'user_nicename', 'order' => 'ASC', 'offset' => $imported_count, 'number' => $number_to_update, From 2be4599b7123114be77a03ab3b5ec673e2ed6782 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 15 Jun 2018 15:42:48 +0200 Subject: [PATCH 222/269] 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 223/269] 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 224/269] 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 225/269] 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 6509556c2b62e2832bed8ba06c33895e808650bf Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 4 Jul 2018 15:11:32 +0200 Subject: [PATCH 226/269] Using CoAuthors_Guest_Authors->create_guest_author_from_user_id() instead of only CoAuthors_Plus->update_author_term(). Renamed function and updated comment. --- php/coauthors-install.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/php/coauthors-install.php b/php/coauthors-install.php index e2ee63e8..66712ed9 100644 --- a/php/coauthors-install.php +++ b/php/coauthors-install.php @@ -15,17 +15,17 @@ function cap_install_setup() { /** - * Creates author terms for existing users. + * Creates guest author profiles for existing users. * * Since CAP 2.7, we're searching against the term description for the fields instead of the user details. - * When CAP is first installed, terms are missing for all existing users. - * This function take care of creating terms for all users who have permission to be added as coauthors. + * When CAP is first installed, guest authors are missing for all existing users. + * This function take care of creating them for all users who have permission to be added as coauthors. * Uses a WP-Cron event that gets rescheduled until all users have been processed. * * @param int $imported_count number of users already processed (used as `offset` in get_users) * @param int $number_to_update number of users to process per each cron event */ -function cap_create_author_terms( $imported_count = 0, $number_to_update = 100 ) { +function cap_create_guest_authors( $imported_count = 0, $number_to_update = 100 ) { global $coauthors_plus; $args = array( @@ -47,11 +47,11 @@ function cap_create_author_terms( $imported_count = 0, $number_to_update = 100 ) continue; } - $coauthors_plus->update_author_term( $found_user ); + $coauthors_plus->guest_authors->create_guest_author_from_user_id( $found_user->ID ); } $imported_count += $number_to_update; wp_schedule_single_event( time(), 'cap_import_existing_users', array( $imported_count ) ); } -add_action( 'cap_import_existing_users', 'cap_create_author_terms' ); \ No newline at end of file +add_action( 'cap_import_existing_users', 'cap_create_guest_authors' ); \ No newline at end of file From 7a702bdc9815c05d1c310d3f4a8f32d682793460 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Fri, 6 Jul 2018 13:00:36 +0200 Subject: [PATCH 227/269] 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 d84d39d99cd69dfc223cc44a268f02bea0ece554 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Sun, 15 Jul 2018 21:17:59 +0100 Subject: [PATCH 228/269] Changed posts_selection from filter to action. Improved function doc and prototype --- co-authors-plus.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 4154a9c1..28b9790c 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -110,7 +110,7 @@ function __construct() { add_filter( 'wp_get_object_terms', array( $this, 'filter_wp_get_object_terms' ), 10, 4 ); // 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( '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' ) ); // Support for Edit Flow's calendar and story budget @@ -1071,8 +1071,11 @@ function current_user_can_set_authors( $post = null ) { * the query_var is changed. * * Also, we have to do some hacky WP_Query modification for guest authors + * + * @param string $selection The assembled selection query + * @void */ - public function fix_author_page() { + public function fix_author_page( $selection ) { if ( ! is_author() ) { return; From ecf869994b79e2e90976aa293bc3f7a861509358 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Tue, 17 Jul 2018 09:46:32 +0100 Subject: [PATCH 229/269] 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 230/269] $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 8e2df320af0073cbbd74ab5b11f6f3e43daa2067 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 25 Jul 2018 09:44:58 +0100 Subject: [PATCH 231/269] On user update, not only update author term but also create guest author if needed --- co-authors-plus.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 78c115b2..dcc4b23f 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1466,7 +1466,7 @@ public function update_author_term( $coauthor ) { } /** - * Update author term when user profile is updated. + * Create guest author profile when WP user profile is updated. * * @param int $userid */ @@ -1475,10 +1475,17 @@ function action_user_profile_update( $userid ) { $user = get_userdata( $userid ); - // Update author term only if user can be added as coauthor - if( $user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { - $coauthors_plus->update_author_term( $user ); + // Continue only if user can be added as coauthor + if ( $user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) === false ) { + return; } + + + if ( ( $guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'login', $user->user_login ) ) === false ) { + $coauthors_plus->guest_authors->create_guest_author_from_user_id( $userid ); + } + + $coauthors_plus->update_author_term( $user ); // when user is updated, we want to update its term so that the search results show up-to-date info } /** From 1c88a825d8a153acf0a7e3663142a54c69b6e93b Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Thu, 26 Jul 2018 13:43:43 -0300 Subject: [PATCH 232/269] Modified query filter regex. This code is meant to append a conditional statement to the WHERE clause of a query. But because the regex mistakenly believed that the statement should be appended after a user ID, and not after 'private', we ended up with queries like this: ``` OR wp_posts.post_author = 3 OR ( wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '8' ) AND wp_posts.post_status = 'private' ``` instead of this: ``` OR wp_posts.post_author = 3 AND wp_posts.post_status = 'private' OR ( wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '8' ) ``` Those are two very different queries: One returns posts including those private posts that belong to user 3, the other excludes all posts that are not private posts belonging to user 3. The modified regex now allows the query to be constructed appropriately. I've run unit tests on the code and no regressions were reported. You can also review my process of solving the problem here: https://github.com/Automattic/Co-Authors-Plus/issues/508 --- 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 7f2c976c..6997f6a9 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -712,7 +712,7 @@ function posts_where_filter( $where, $query ) { $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 + $where = preg_replace( '/\s\b(?:' . $wpdb->posts . '\.)?post_author\s*IN\s*(.*private\'.)/', ' (' . $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 From d7503a890c59c151a1ed13a71b8eca8059b00386 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Fri, 27 Jul 2018 09:55:31 -0300 Subject: [PATCH 233/269] Modify query regex. The previous modification worked, but failed testing due to not *all* queries having a 'private' clause attached to them. It has been moved to an optional non-capturing group. --- 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 6997f6a9..5554c226 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -712,7 +712,7 @@ function posts_where_filter( $where, $query ) { $maybe_both_query = $maybe_both ? '$0 OR' : ''; - $where = preg_replace( '/\s\b(?:' . $wpdb->posts . '\.)?post_author\s*IN\s*(.*private\'.)/', ' (' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND + $where = preg_replace( '/\s\b(?:' . $wpdb->posts . '\.)?post_author\s*IN\s*(.*' . $id . '(?:.*private\')?.)/', ' (' . $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 From 40790e8c7e6deea54f8281c6bf794e716752dd1c Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Sun, 29 Jul 2018 21:03:37 -0300 Subject: [PATCH 234/269] Modify test so that query is run as post author, not as admin. An issue was raised (https://github.com/Automattic/Co-Authors-Plus/issues/508) that was not caught by existing unit tests because it only presented itself when the query was performed as an author. The existing unit test performed the query as an admin, which caused the issue to not appear, and the test to pass. Changing the test to run the query in the context of the post author should prevent this from happening again. --- 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 7d0453ba..13efaef3 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queries.php @@ -12,6 +12,8 @@ public function test__author_arg__user_is_post_author() { ) ); $this->_cap->add_coauthors( $post_id, array( $author->user_login ) ); + wp_set_current_user( $author_id ); + $query = new WP_Query( array( 'author' => $author_id, ) ); From d10586804ec6f3bb38113a0e8cb3759615acfdce Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Mon, 30 Jul 2018 07:34:16 -0300 Subject: [PATCH 235/269] Add new test to query for just-created post as post author. The test suite now queries for a just-created post two ways: as an admin, and as the user who just created the post. This is to remove the possibility of missing issues that don't appear to admins, such as https://github.com/Automattic/Co-Authors-Plus/issues/508. --- tests/test-author-queries.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test-author-queries.php b/tests/test-author-queries.php index 13efaef3..04fbe6e8 100644 --- a/tests/test-author-queries.php +++ b/tests/test-author-queries.php @@ -2,7 +2,7 @@ class Test_Author_Queries extends CoAuthorsPlus_TestCase { - public function test__author_arg__user_is_post_author() { + public function test__author_arg__user_is_post_author_query_as_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( @@ -22,6 +22,24 @@ public function test__author_arg__user_is_post_author() { $this->assertEquals( $post_id, $query->posts[ 0 ]->ID ); } + 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, + ) ); + + $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 ); From e2bde4e9e923a4df75b00f3abcd7ec399a5ef663 Mon Sep 17 00:00:00 2001 From: codemacherUG Date: Tue, 31 Jul 2018 14:10:52 +0200 Subject: [PATCH 236/269] BUGFIX according issue 573 (https://github.com/Automattic/Co-Authors-Plus/issues/573) , bug in regular expression fixed Signed-off-by: codemacherUG --- 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 7f2c976c..111774f0 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -731,7 +731,7 @@ function posts_where_filter( $where, $query ) { $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 863cf311fd79dc81b7941e91cf875dafce4c7b3b Mon Sep 17 00:00:00 2001 From: philipjohn Date: Wed, 15 Aug 2018 13:53:27 +0100 Subject: [PATCH 237/269] Revert "Stop handling wp_terms in search_authors, do it in install and profile update" --- co-authors-plus.php | 71 ++++++++++++++--------------------- php/coauthors-install.php | 57 ---------------------------- tests/test-coauthors-plus.php | 8 ---- 3 files changed, 29 insertions(+), 107 deletions(-) delete mode 100644 php/coauthors-install.php diff --git a/co-authors-plus.php b/co-authors-plus.php index dcc4b23f..7f2c976c 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -37,7 +37,6 @@ require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); -require_once( dirname( __FILE__ ) . '/php/coauthors-install.php' ); require_once( dirname( __FILE__ ) . '/php/class-coauthors-template-filters.php' ); require_once( dirname( __FILE__ ) . '/php/integrations/amp.php' ); @@ -71,8 +70,6 @@ class CoAuthors_Plus { * __construct() */ function __construct() { - //Set up on activation - register_activation_hook( __FILE__, 'cap_install_setup' ); // Register our models add_action( 'init', array( $this, 'action_init' ) ); @@ -136,10 +133,6 @@ function __construct() { // Filter to correct author on author archive page add_filter( 'get_the_archive_title', array( $this, 'filter_author_archive_title'), 10, 2 ); - - // Update author term on user update - add_action( 'user_register', array( $this, 'action_user_profile_update' ) ); - add_action( 'profile_update', array( $this, 'action_user_profile_update' ) ); } /** @@ -1163,17 +1156,38 @@ public function ajax_suggest() { /** * Get matching co-authors based on a search value - * - * @param string $search - * @param array $ignored_authors array - * @return array found users */ public function search_authors( $search = '', $ignored_authors = array() ) { + + // Since 2.7, we're searching against the term description for the fields + // instead of the user details. If the term is missing, we probably need to + // backfill with user details. Let's do this first... easier than running + // an upgrade script that could break on a lot of users $args = array( - 'search' => $search, - 'get' => 'all', - 'number' => 10, - ); + 'count_total' => false, + 'search' => sprintf( '*%s*', $search ), + 'search_columns' => array( + 'ID', + 'display_name', + 'user_email', + 'user_login', + ), + 'fields' => 'all_with_meta', + ); + $found_users = get_users( $args ); + + foreach ( $found_users as $found_user ) { + $term = $this->get_author_term( $found_user ); + if ( empty( $term ) || empty( $term->description ) ) { + $this->update_author_term( $found_user ); + } + } + + $args = array( + 'search' => $search, + 'get' => 'all', + 'number' => 10, + ); $args = apply_filters( 'coauthors_search_authors_get_terms_args', $args ); add_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) ); $found_terms = get_terms( $this->coauthor_taxonomy, $args ); @@ -1195,15 +1209,11 @@ public function search_authors( $search = '', $ignored_authors = array() ) { // Allow users to always filter out certain users if needed (e.g. administrators) $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_nicename, $ignored_authors ) ) { //AJAX sends a list of already present *users_nicenames* unset( $found_users[ $key ] ); - - //If user does not have permission, they should not have a term in the first place } else if ( 'wpuser' === $found_user->type && false === $found_user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { unset( $found_users[ $key ] ); - wp_delete_term( $term->term_id, $this->coauthor_taxonomy ); } } return (array) $found_users; @@ -1465,29 +1475,6 @@ public function update_author_term( $coauthor ) { return $this->get_author_term( $coauthor ); } - /** - * Create guest author profile when WP user profile is updated. - * - * @param int $userid - */ - function action_user_profile_update( $userid ) { - global $coauthors_plus; - - $user = get_userdata( $userid ); - - // Continue only if user can be added as coauthor - if ( $user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) === false ) { - return; - } - - - if ( ( $guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'login', $user->user_login ) ) === false ) { - $coauthors_plus->guest_authors->create_guest_author_from_user_id( $userid ); - } - - $coauthors_plus->update_author_term( $user ); // when user is updated, we want to update its term so that the search results show up-to-date info - } - /** * Filter Edit Flow's 'ef_calendar_item_information_fields' to add co-authors * diff --git a/php/coauthors-install.php b/php/coauthors-install.php deleted file mode 100644 index 66712ed9..00000000 --- a/php/coauthors-install.php +++ /dev/null @@ -1,57 +0,0 @@ - 'user_nicename', - 'order' => 'ASC', - 'offset' => $imported_count, - 'number' => $number_to_update, - 'fields' => 'all_with_meta', - ); - $found_users = get_users( $args ); - - if ( empty( $found_users ) ) { - return; - } - - foreach ( $found_users as $found_user ) { - //Check that user has permission to be added as coauthor - if( ! $found_user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) { - continue; - } - - $coauthors_plus->guest_authors->create_guest_author_from_user_id( $found_user->ID ); - } - - $imported_count += $number_to_update; - - wp_schedule_single_event( time(), 'cap_import_existing_users', array( $imported_count ) ); -} -add_action( 'cap_import_existing_users', 'cap_create_guest_authors' ); \ No newline at end of file diff --git a/tests/test-coauthors-plus.php b/tests/test-coauthors-plus.php index 683a195d..44b6f106 100644 --- a/tests/test-coauthors-plus.php +++ b/tests/test-coauthors-plus.php @@ -3,15 +3,12 @@ class Test_CoAuthors_Plus extends CoAuthorsPlus_TestCase { public function setUp() { - global $coauthors_plus; 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' ) ); - cap_create_author_terms(); //users without terms don't exist for CAP - $this->post = $this->factory->post->create_and_get( array( 'post_author' => $this->author1->ID, 'post_status' => 'publish', @@ -366,7 +363,6 @@ public function test_search_authors_no_args() { $subscriber1 = $this->factory->user->create_and_get( array( 'role' => 'subscriber', ) ); - cap_create_author_terms(); $authors = $coauthors_plus->search_authors(); @@ -377,7 +373,6 @@ public function test_search_authors_no_args() { $contributor1 = $this->factory->user->create_and_get( array( 'role' => 'contributor', ) ); - cap_create_author_terms(); $authors = $coauthors_plus->search_authors(); @@ -433,7 +428,6 @@ public function test_search_authors_when_search_keyword_provided() { $subscriber1 = $this->factory->user->create_and_get( array( 'role' => 'subscriber', ) ); - cap_create_author_terms(); $this->assertEmpty( $coauthors_plus->search_authors( $subscriber1->ID ) ); } @@ -459,7 +453,6 @@ public function test_search_authors_when_ignored_authors_provided() { $author2 = $this->factory->user->create_and_get( array( 'role' => 'author', ) ); - cap_create_author_terms(); $authors = $coauthors_plus->search_authors( '', $ignored_authors ); @@ -494,7 +487,6 @@ public function test_search_authors_when_search_keyword_and_ignored_authors_prov 'role' => 'author', 'user_login' => 'author2', ) ); - cap_create_author_terms(); $authors = $coauthors_plus->search_authors( 'author', $ignored_authors ); From 639928635075c5a9acea8982db267c77e2e3c407 Mon Sep 17 00:00:00 2001 From: scofennell Date: Tue, 21 Aug 2018 14:47:18 -0400 Subject: [PATCH 238/269] fix issue 592 --- 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 7f2c976c..31b89933 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -731,7 +731,8 @@ function posts_where_filter( $where, $query ) { $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 ); + } } From c28fe4230745e1b6bfaeab954a14b4998ea65faf Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Tue, 4 Sep 2018 22:03:53 -0500 Subject: [PATCH 239/269] Add CLI argument to assign_coauthors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This argument is used in the code already, but isn’t allowed to be passed down since it’s not in the synopsis. --- 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..358727b7 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -121,7 +121,7 @@ public function create_terms_for_posts() { * @since 3.0 * * @subcommand assign-coauthors - * @synopsis [--meta_key=] [--post_type=] + * @synopsis [--meta_key=] [--post_type=] [--append_coauthors=] */ public function assign_coauthors( $args, $assoc_args ) { global $coauthors_plus; From 961a924c62b75d87224da40271e03c558c63e294 Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Wed, 5 Sep 2018 10:42:47 +0200 Subject: [PATCH 240/269] Making sure guest authors are enabled before calling related functions to avoid Fatal. --- co-authors-plus.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 7f2c976c..d0696cd7 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -940,15 +940,17 @@ function delete_user_action( $delete_id ) { 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 ( $this->is_guest_authors_enabled() ) { + // 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 ); + if ( isset( $associated_user->ID ) ) { + // Delete associated guest user. + $this->guest_authors->delete( $associated_user->ID ); + } } } From 34dfc910917a53a3ea3d2e692a6c21bf763c8734 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Wed, 5 Sep 2018 14:27:22 -0500 Subject: [PATCH 241/269] Remove unecessary boolean marker in assoc_args --- 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 358727b7..c07c4874 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -121,7 +121,7 @@ public function create_terms_for_posts() { * @since 3.0 * * @subcommand assign-coauthors - * @synopsis [--meta_key=] [--post_type=] [--append_coauthors=] + * @synopsis [--meta_key=] [--post_type=] [--append_coauthors] */ public function assign_coauthors( $args, $assoc_args ) { global $coauthors_plus; From 62fa2e08d5d1ac5dcf53dcb8316e3180a216b011 Mon Sep 17 00:00:00 2001 From: Andrew Fleming Date: Tue, 11 Sep 2018 13:45:25 +1000 Subject: [PATCH 242/269] Import 'website' and 'description' fields to co-author if they're present in the .csv. Fixes #599 --- php/class-wp-cli.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index c07c4874..6df5b6e6 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -823,6 +823,8 @@ public function create_guest_authors_from_csv( $args, $assoc_args ) { 'display_name' => sanitize_text_field( $author['display_name'] ), 'user_login' => sanitize_user( $author['user_login'] ), 'user_email' => sanitize_email( $author['user_email'] ), + 'website' => esc_url_raw( $author['website'] ), + 'description' => wp_filter_post_kses( $author['description'] ) ); $display_name_space_pos = strpos( $author['display_name'], ' ' ); @@ -861,6 +863,8 @@ private function create_guest_author( $author ) { 'user_email' => $author['user_email'], 'first_name' => $author['first_name'], 'last_name' => $author['last_name'], + 'website' => $author['website'], + 'description' => $author['description'] ) ); if ( $guest_author_id ) { From 0da7b5e8258d1d62a3a41692f78008d7c7452c3e Mon Sep 17 00:00:00 2001 From: Shantanu Date: Tue, 18 Sep 2018 11:45:15 +0530 Subject: [PATCH 243/269] Extract the post count logic into a separate method --- php/class-coauthors-wp-list-table.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index 8c1f9773..026aaa59 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -249,17 +249,28 @@ function column_linked_account( $item ) { * Render the published post count column */ function column_posts( $item ) { + $count = $this->get_post_count( $item ); + return '' . $count . ''; + } + + /** + * Get the post count for the guest author + * + * @global oebject $coauthors_plus + * @param object $item guest-author object. + * @return int post count for the guest author + */ + function get_post_count( $item ) { global $coauthors_plus; - $term = $coauthors_plus->get_author_term( $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( 'login', $item->linked_account )->ID ); + return count_user_posts( get_user_by( 'login', $item->linked_account )->ID ); } elseif ( $term ) { - $count = $term->count; + return $term->count; } else { - $count = 0; + return 0; } - return '' . $count . ''; } /** From d63a6ef3271a48de96fd54487236da7dc5385f11 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Tue, 18 Sep 2018 12:16:23 +0530 Subject: [PATCH 244/269] Create and use the wrapper function get_guest_author_post_count --- php/class-coauthors-guest-authors.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index fbdf7c31..e8032698 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -469,13 +469,7 @@ function view_guest_authors_list() { } // get post count - global $coauthors_plus; - $term = $coauthors_plus->get_author_term( $guest_author ); - if ( $term ) { - $count = $term->count; - } else { - $count = 0; - } + $count = $this->get_guest_author_post_count( $guest_author ); echo '
    '; echo '

    '; @@ -558,6 +552,21 @@ function view_guest_authors_list() { } + /** + * Fetch the post count for a guest author + * + * @param object $guest_author guest-author object. + * @return int post count. + */ + function get_guest_author_post_count( $guest_author ) { + if ( ! is_object( $guest_author ) ) { + return; + } else { + $cap_list_table = new CoAuthors_WP_List_Table(); + return $cap_list_table->get_post_count( $guest_author ); + } + } + /** * Metabox for saving or updating a Guest Author * From 14d69dee7247321944e12f78127516bbd26cb6b9 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Wed, 19 Sep 2018 12:17:55 +0530 Subject: [PATCH 245/269] Address feedback --- co-authors-plus.php | 20 ++++++++++++++++++++ php/class-coauthors-guest-authors.php | 18 ++---------------- php/class-coauthors-wp-list-table.php | 23 ++--------------------- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index d0696cd7..c7b7ffa1 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1644,8 +1644,28 @@ public function filter_author_archive_title( $title ) { $author = $this->get_coauthor_by( 'user_nicename', $author_slug ); return sprintf( __( 'Author: %s' ), $author->display_name ); + } + + /** + * Get the post count for the guest author + * + * @global oebject $coauthors_plus + * @param object $item guest-author object. + * @return int post count for the guest author + */ + public function get_guest_author_post_count( $item ) { + $term = $this->get_author_term( $item ); + $guest_term = get_term_by( 'slug', 'cap-' . $item->user_nicename, $this->coauthor_taxonomy ); + if ( ! empty( $item->linked_account ) && $guest_term->count ) { + return count_user_posts( get_user_by( 'login', $item->linked_account )->ID ); + } elseif ( $term ) { + return $term->count; + } else { + return 0; + } } + } global $coauthors_plus; diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index e8032698..c5420852 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -469,7 +469,8 @@ function view_guest_authors_list() { } // get post count - $count = $this->get_guest_author_post_count( $guest_author ); + global $coauthors_plus; + $count = $coauthors_plus->get_guest_author_post_count( $guest_author ); echo '
    '; echo '

    '; @@ -552,21 +553,6 @@ function view_guest_authors_list() { } - /** - * Fetch the post count for a guest author - * - * @param object $guest_author guest-author object. - * @return int post count. - */ - function get_guest_author_post_count( $guest_author ) { - if ( ! is_object( $guest_author ) ) { - return; - } else { - $cap_list_table = new CoAuthors_WP_List_Table(); - return $cap_list_table->get_post_count( $guest_author ); - } - } - /** * Metabox for saving or updating a Guest Author * diff --git a/php/class-coauthors-wp-list-table.php b/php/class-coauthors-wp-list-table.php index 026aaa59..d8585779 100644 --- a/php/class-coauthors-wp-list-table.php +++ b/php/class-coauthors-wp-list-table.php @@ -249,28 +249,9 @@ function column_linked_account( $item ) { * Render the published post count column */ function column_posts( $item ) { - $count = $this->get_post_count( $item ); - return '' . $count . ''; - } - - /** - * Get the post count for the guest author - * - * @global oebject $coauthors_plus - * @param object $item guest-author object. - * @return int post count for the guest author - */ - function get_post_count( $item ) { global $coauthors_plus; - $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 ) { - return count_user_posts( get_user_by( 'login', $item->linked_account )->ID ); - } elseif ( $term ) { - return $term->count; - } else { - return 0; - } + $count = $coauthors_plus->get_guest_author_post_count( $item ); + return '' . $count . ''; } /** From f2453db24f5221f642d6422d4138085fc69cd658 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Fri, 21 Sep 2018 11:44:21 +0530 Subject: [PATCH 246/269] Add defensive checks in get_guest_author_post_count --- co-authors-plus.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c7b7ffa1..17706bb1 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1649,15 +1649,23 @@ public function filter_author_archive_title( $title ) { /** * Get the post count for the guest author * - * @global oebject $coauthors_plus - * @param object $item guest-author object. + * @param object $guest_author guest-author object. * @return int post count for the guest author */ - public function get_guest_author_post_count( $item ) { - $term = $this->get_author_term( $item ); - $guest_term = get_term_by( 'slug', 'cap-' . $item->user_nicename, $this->coauthor_taxonomy ); - if ( ! empty( $item->linked_account ) && $guest_term->count ) { - return count_user_posts( get_user_by( 'login', $item->linked_account )->ID ); + public function get_guest_author_post_count( $guest_author ) { + if ( ! is_object( $guest_author ) ) { + return; + } + + $term = $this->get_author_term( $guest_author ); + $guest_term = get_term_by( 'slug', 'cap-' . $guest_author->user_nicename, $this->coauthor_taxonomy ); + + if ( ! $term || ! $guest_term ) { + return false; + } + + if ( ! empty( $guest_author->linked_account ) && $guest_term->count ) { + return count_user_posts( get_user_by( 'login', $guest_author->linked_account )->ID ); } elseif ( $term ) { return $term->count; } else { @@ -1665,7 +1673,6 @@ public function get_guest_author_post_count( $item ) { } } - } global $coauthors_plus; From e2758e58acb84bc230ba9b4ba5eb2bf8c40dfdfc Mon Sep 17 00:00:00 2001 From: Shantanu Date: Fri, 28 Sep 2018 14:00:52 +0530 Subject: [PATCH 247/269] Add an is_object check for --- co-authors-plus.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 17706bb1..08aee8ed 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -1657,14 +1657,12 @@ public function get_guest_author_post_count( $guest_author ) { return; } - $term = $this->get_author_term( $guest_author ); + $term = $this->get_author_term( $guest_author ); $guest_term = get_term_by( 'slug', 'cap-' . $guest_author->user_nicename, $this->coauthor_taxonomy ); - if ( ! $term || ! $guest_term ) { - return false; - } - - if ( ! empty( $guest_author->linked_account ) && $guest_term->count ) { + if ( is_object( $guest_term ) + && ! empty( $guest_author->linked_account ) + && $guest_term->count ) { return count_user_posts( get_user_by( 'login', $guest_author->linked_account )->ID ); } elseif ( $term ) { return $term->count; From 3d9f360618069ce1f6e838d8cd1ed23cbaecd989 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 1 Oct 2018 23:25:55 +0530 Subject: [PATCH 248/269] Add class arguement to get_guest_author_thumbnail --- php/class-coauthors-guest-authors.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index c5420852..8be2e507 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -958,11 +958,12 @@ function get_guest_author_by( $key, $value, $force = false ) { /** * Get an thumbnail for a Guest Author object * - * @param object The Guest Author object for which to retrieve the thumbnail - * @param int The desired image size - * @return string The thumbnail image tag, or null if one doesn't exist + * @param object The Guest Author object for which to retrieve the thumbnail. + * @param int The desired image size. + * @param string String of additional classes. Default null. + * @return string The thumbnail image tag, or null if one doesn't exist. */ - function get_guest_author_thumbnail( $guest_author, $size ) { + function get_guest_author_thumbnail( $guest_author, $size, $class = null ) { // See if the guest author has an avatar if ( ! has_post_thumbnail( $guest_author->ID ) ) { return null; @@ -971,6 +972,9 @@ function get_guest_author_thumbnail( $guest_author, $size ) { $args = array( 'class' => "avatar avatar-{$size} photo", ); + if ( ! empty( $class ) ) { + $args['class'] += " $class"; + } $size = array( $size, $size ); From 21c4c17e71840c9e701edd6eb9d7d7e9c1ae50ba Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 1 Oct 2018 23:28:34 +0530 Subject: [PATCH 249/269] Add an additional class arg to coauthors_get_avatar --- template-tags.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/template-tags.php b/template-tags.php index 43d11be2..ef7fc13b 100644 --- a/template-tags.php +++ b/template-tags.php @@ -676,19 +676,31 @@ function coauthors_wp_list_authors( $args = array() ) { * This is a replacement for using get_avatar(), which only operates on email addresses and cannot differentiate * between Guest Authors (who may share an email) and regular user accounts * - * @param object $coauthor The Co Author or Guest Author object - * @param int $size The desired size - * @return string The image tag for the avatar, or an empty string if none could be determined + * @param object $coauthor The Co Author or Guest Author object. + * @param int $size The desired size. + * @param string $default Optional. URL for the default image or a default type. Accepts '404' + * (return a 404 instead of a default image), 'retro' (8bit), 'monsterid' + * (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"), + * 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), + * or 'gravatar_default' (the Gravatar logo). Default is the value of the + * 'avatar_default' option, with a fallback of 'mystery'. + * @param string $alt Optional. Alternative text to use in <img> tag. Default false. + * @param array|string $class Array or string of additional classes to add to the <img> element. Default null. + * @return string The image tag for the avatar, or an empty string if none could be determined. */ -function coauthors_get_avatar( $coauthor, $size = 32, $default = '', $alt = false ) { +function coauthors_get_avatar( $coauthor, $size = 32, $default = '', $alt = false, $class = null ) { global $coauthors_plus; if ( ! is_object( $coauthor ) ) { return ''; } + if ( ! empty( $class ) && is_array( $class ) ) { + $class = implode( ' ', $class ); + } + if ( isset( $coauthor->type ) && 'guest-author' == $coauthor->type ) { - $guest_author_thumbnail = $coauthors_plus->guest_authors->get_guest_author_thumbnail( $coauthor, $size ); + $guest_author_thumbnail = $coauthors_plus->guest_authors->get_guest_author_thumbnail( $coauthor, $size, $class ); if ( $guest_author_thumbnail ) { return $guest_author_thumbnail; @@ -697,7 +709,7 @@ function coauthors_get_avatar( $coauthor, $size = 32, $default = '', $alt = fals // Make sure we're dealing with an object for which we can retrieve an email if ( isset( $coauthor->user_email ) ) { - return get_avatar( $coauthor->user_email, $size, $default, $alt ); + return get_avatar( $coauthor->user_email, $size, $default, $alt, array( 'class' => $class ) ); } // Nothing matched, an invalid object was passed. From 8c7451fc95e35da59f77ba238f6398599ae5a66d Mon Sep 17 00:00:00 2001 From: Shantanu Date: Wed, 3 Oct 2018 18:32:37 +0530 Subject: [PATCH 250/269] Move the array check to get_guest_author_thumbnail --- php/class-coauthors-guest-authors.php | 11 +++++++---- template-tags.php | 6 +----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 8be2e507..1dcda90e 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -958,10 +958,10 @@ function get_guest_author_by( $key, $value, $force = false ) { /** * Get an thumbnail for a Guest Author object * - * @param object The Guest Author object for which to retrieve the thumbnail. - * @param int The desired image size. - * @param string String of additional classes. Default null. - * @return string The thumbnail image tag, or null if one doesn't exist. + * @param object The Guest Author object for which to retrieve the thumbnail. + * @param int The desired image size. + * @param array|string Optional. An array or string of additional classes. Default null. + * @return string The thumbnail image tag, or null if one doesn't exist. */ function get_guest_author_thumbnail( $guest_author, $size, $class = null ) { // See if the guest author has an avatar @@ -973,6 +973,9 @@ function get_guest_author_thumbnail( $guest_author, $size, $class = null ) { 'class' => "avatar avatar-{$size} photo", ); if ( ! empty( $class ) ) { + if ( is_array( $class ) ) { + $class = implode( ' ', $class ); + } $args['class'] += " $class"; } diff --git a/template-tags.php b/template-tags.php index ef7fc13b..8092f550 100644 --- a/template-tags.php +++ b/template-tags.php @@ -685,7 +685,7 @@ function coauthors_wp_list_authors( $args = array() ) { * or 'gravatar_default' (the Gravatar logo). Default is the value of the * 'avatar_default' option, with a fallback of 'mystery'. * @param string $alt Optional. Alternative text to use in <img> tag. Default false. - * @param array|string $class Array or string of additional classes to add to the <img> element. Default null. + * @param array|string $class Optional. Array or string of additional classes to add to the <img> element. Default null. * @return string The image tag for the avatar, or an empty string if none could be determined. */ function coauthors_get_avatar( $coauthor, $size = 32, $default = '', $alt = false, $class = null ) { @@ -695,10 +695,6 @@ function coauthors_get_avatar( $coauthor, $size = 32, $default = '', $alt = fals return ''; } - if ( ! empty( $class ) && is_array( $class ) ) { - $class = implode( ' ', $class ); - } - if ( isset( $coauthor->type ) && 'guest-author' == $coauthor->type ) { $guest_author_thumbnail = $coauthors_plus->guest_authors->get_guest_author_thumbnail( $coauthor, $size, $class ); From 8b99c4424db529ec0c5561ecfcda803facbbb76a Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Mon, 5 Nov 2018 12:49:48 -0700 Subject: [PATCH 251/269] Apply patch D10216 --- co-authors-plus.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index c9380039..b4555764 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -621,8 +621,12 @@ function posts_join_filter( $join, $query ) { global $wpdb; if ( $query->is_author() ) { + $post_type = $query->query_vars['post_type']; + if ( 'any' === $post_type ) { + $post_type = get_post_types( array( 'exclude_from_search' => false ) ); + } - if ( ! empty( $query->query_vars['post_type'] ) && ! is_object_in_taxonomy( $query->query_vars['post_type'], $this->coauthor_taxonomy ) ) { + if ( ! empty( $post_type ) && ! is_object_in_taxonomy( $post_type, $this->coauthor_taxonomy ) ) { return $join; } @@ -657,8 +661,12 @@ function posts_where_filter( $where, $query ) { global $wpdb; if ( $query->is_author() ) { + $post_type = $query->query_vars['post_type']; + if ( 'any' === $post_type ) { + $post_type = get_post_types( array( 'exclude_from_search' => false ) ); + } - if ( ! empty( $query->query_vars['post_type'] ) && ! is_object_in_taxonomy( $query->query_vars['post_type'], $this->coauthor_taxonomy ) ) { + if ( ! empty( $post_type ) && ! is_object_in_taxonomy( $post_type, $this->coauthor_taxonomy ) ) { return $where; } @@ -749,8 +757,11 @@ function posts_groupby_filter( $groupby, $query ) { global $wpdb; if ( $query->is_author() ) { - - if ( ! empty( $query->query_vars['post_type'] ) && ! is_object_in_taxonomy( $query->query_vars['post_type'], $this->coauthor_taxonomy ) ) { + $post_type = $query->query_vars['post_type']; + if ( 'any' === $post_type ) { + $post_type = get_post_types( array( 'exclude_from_search' => false ) ); + } + if ( ! empty( $post_type ) && ! is_object_in_taxonomy( $post_type, $this->coauthor_taxonomy ) ) { return $groupby; } From 8aff7801b9fd3155bbdac3b06e04693660687995 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 5 Nov 2018 22:37:23 -0500 Subject: [PATCH 252/269] Allow avatars to be imported by ID --- php/class-coauthors-guest-authors.php | 5 +++++ php/class-wp-cli.php | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 1dcda90e..caa8bc2e 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -1263,6 +1263,11 @@ function create( $args ) { update_post_meta( $post_id, $pm_key, $args[ $key ] ); } + // Attach the avatar / featured image. + if ( ! empty( $args[ 'avatar' ] ) ) { + set_post_thumbnail( $post_id, $args[ 'avatar' ] ); + } + // Make sure the author term exists and that we're assigning it to this post type $author_term = $coauthors_plus->update_author_term( $this->get_guest_author_by( 'ID', $post_id ) ); wp_set_post_terms( $post_id, array( $author_term->slug ), $coauthors_plus->coauthor_taxonomy, false ); diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 6df5b6e6..b5123c15 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -824,7 +824,8 @@ public function create_guest_authors_from_csv( $args, $assoc_args ) { 'user_login' => sanitize_user( $author['user_login'] ), 'user_email' => sanitize_email( $author['user_email'] ), 'website' => esc_url_raw( $author['website'] ), - 'description' => wp_filter_post_kses( $author['description'] ) + 'description' => wp_filter_post_kses( $author['description'] ), + 'avatar' => absint( $author['avatar'] ), ); $display_name_space_pos = strpos( $author['display_name'], ' ' ); @@ -864,7 +865,8 @@ private function create_guest_author( $author ) { 'first_name' => $author['first_name'], 'last_name' => $author['last_name'], 'website' => $author['website'], - 'description' => $author['description'] + 'description' => $author['description'], + 'avatar' => $author['avatar'], ) ); if ( $guest_author_id ) { From ec0bc0dcf92016dcfa326e7dda0f5a830ffd1ac0 Mon Sep 17 00:00:00 2001 From: mostafaabd Date: Sat, 10 Nov 2018 14:47:18 +0200 Subject: [PATCH 253/269] fix --- co-authors-plus.php | 11 ++++++++++- js/co-authors-plus.js | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 784239db..74e63ea1 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -380,6 +380,10 @@ public function coauthors_meta_box( $post ) { ID ) ) { + $avatar_url = get_the_post_thumbnail_url( $coauthor->ID, $this->gravatar_size ); + } ?>
  • user_email, $this->gravatar_size ); ?> @@ -388,6 +392,7 @@ public function coauthors_meta_box( $post ) { +
  • ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . rawurldecode( $author->user_nicename ) ) . "\n"; + $avatar_url = ''; + if ( has_post_thumbnail( $author->ID ) ) { + $avatar_url = get_the_post_thumbnail_url($author->ID, $this->gravatar_size ); + } + echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . rawurldecode( $author->user_nicename ) ) . ' | ' . esc_url( $avatar_url ) . "\n"; } die(); diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 55e9e582..7d818f65 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -200,6 +200,9 @@ jQuery( document ).ready(function () { author.login = jQuery.trim( vals[1] ); author.name = jQuery.trim( vals[2] ); author.email = jQuery.trim( vals[3] ); + if( author.avatar !== '' ){ + author.avatar = jQuery.trim( vals[5] ); + } // Decode user-nicename if it has special characters in it. author.nicename = decodeURIComponent( jQuery.trim( vals[4] ) ); @@ -252,8 +255,12 @@ jQuery( document ).ready(function () { } function coauthors_create_author_gravatar( author, size ) { - - var gravatar_link = get_gravatar_link( author.email, size ); + if( author.avatar ) { + var gravatar_link = author.avatar; + } else { + var gravatar_link = get_gravatar_link( author.email, size ); + } + var $gravatar = jQuery( '' ) .attr( 'alt', author.name ) @@ -389,6 +396,7 @@ jQuery( document ).ready(function () { var $post_coauthor_names = jQuery( 'input[name="coauthorsinput[]"]' ); var $post_coauthor_emails = jQuery( 'input[name="coauthorsemails[]"]' ); var $post_coauthor_nicenames = jQuery( 'input[name="coauthorsnicenames[]"]' ); + var $post_coauthoravatar = jQuery( 'input[name="coauthorsavaters[]"]' ); var post_coauthors = []; @@ -397,7 +405,8 @@ jQuery( document ).ready(function () { login: $post_coauthor_logins[i].value, name: $post_coauthor_names[i].value, email: $post_coauthor_emails[i].value, - nicename: $post_coauthor_nicenames[i].value + nicename: $post_coauthor_nicenames[i].value, + avatar: $post_coauthoravatar[i].value, }); } From 89d3cf78220633eb62f634d1f4424cf07a92d51b Mon Sep 17 00:00:00 2001 From: Maeve Lander <4695433+maevelander@users.noreply.github.com> Date: Thu, 22 Nov 2018 10:55:22 +0800 Subject: [PATCH 254/269] Update readme for 5.0 compatibility --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c309a34..544d9962 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ * Contributors: batmoo, danielbachhuber, automattic * Tags: authors, users, multiple authors, coauthors, multi-author, publishing -* Tested up to: 4.9.5 +* Tested up to: 5.0 * Requires at least: 4.1 * Stable tag: 3.3.0 From f7bd19bdac93f4925806959058c8772cb67709be Mon Sep 17 00:00:00 2001 From: Maeve Lander <4695433+maevelander@users.noreply.github.com> Date: Thu, 22 Nov 2018 10:55:46 +0800 Subject: [PATCH 255/269] Update readme for 5.0 compatibility --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 0c50628c..ef246776 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.9.5 +Tested up to: 5.0 Requires at least: 4.1 Stable tag: 3.3.0 From 7be5251421c6a431be540d4470be6fd11c7cb997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane?= Date: Thu, 22 Nov 2018 17:15:26 -0500 Subject: [PATCH 256/269] Don't search and replace with co-author post_id If the posts_where_filter has already been run (For example is wp_query::get_posts() is run twice). The second time around it will try to replace the co-author's post id inside the query, leading it to not replace the 'wp_posts.post_author = 0' part of the query. This fixes a compatability issue with Yoast wp-seo Internal ticket id:85217 --- co-authors-plus.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/co-authors-plus.php b/co-authors-plus.php index 784239db..64723c09 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -715,6 +715,12 @@ function posts_where_filter( $where, $query ) { $id = is_author() ? get_queried_object_id() : '\d+'; + //If we have an ID but it's not a "real" ID that means that this isn't the first time the filter has fired and the object_id has already been replaced by a previous run of this filter. We therefore need to replace the 0 + // This happens when wp_query::get_posts() is run multiple times. + if ( false === get_user_by( 'id', $id ) ){ + $id = 0; + } + // When WordPress generates query as 'post_author IN (id)'. if ( false !== strpos( $where, "{$wpdb->posts}.post_author IN " ) ) { From 25b53d0e2ab6920dcdeb110808ac5d399eba40e8 Mon Sep 17 00:00:00 2001 From: James R Whitehead Date: Tue, 27 Nov 2018 11:37:06 +0000 Subject: [PATCH 257/269] Fix for issue #625 from the original plugin. A previous change broke the regEx which then broke the SQL which then broke the front end. --- co-authors-plus.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 64723c09..87520bf7 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -654,15 +654,19 @@ function posts_join_filter( $join, $query ) { return $join; } - /** - * Modify the author query posts SQL to include posts co-authored - */ + /** + * Modify the author query posts SQL to include posts co-authored + * + * @param string $where + * @param WP_Query $query + * + * @return string|string[]|null + */ function posts_where_filter( $where, $query ) { global $wpdb; if ( $query->is_author() ) { $post_type = $query->query_vars['post_type']; - if ( 'any' === $post_type ) { $post_type = get_post_types( array( 'exclude_from_search' => false ) ); } @@ -713,12 +717,12 @@ function posts_where_filter( $where, $query ) { } $terms_implode = rtrim( $terms_implode, ' OR' ); - $id = is_author() ? get_queried_object_id() : '\d+'; + $id = is_author() && $query->is_main_query() ? get_queried_object_id() : '\d+'; //If we have an ID but it's not a "real" ID that means that this isn't the first time the filter has fired and the object_id has already been replaced by a previous run of this filter. We therefore need to replace the 0 // This happens when wp_query::get_posts() is run multiple times. - if ( false === get_user_by( 'id', $id ) ){ - $id = 0; + if ( $id !== '\d+' && false === get_user_by( 'id', $id ) ){ + $id = '\d+'; } // When WordPress generates query as 'post_author IN (id)'. From f6aa38befc1b5426c3c0ee63b5f326143b9d0429 Mon Sep 17 00:00:00 2001 From: James R Whitehead Date: Thu, 29 Nov 2018 11:08:43 +0000 Subject: [PATCH 258/269] Fix for issue #625 Added some comments and fixed a wonky commit. --- co-authors-plus.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 87520bf7..9f8146c3 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -660,13 +660,14 @@ function posts_join_filter( $join, $query ) { * @param string $where * @param WP_Query $query * - * @return string|string[]|null + * @return string */ function posts_where_filter( $where, $query ) { global $wpdb; if ( $query->is_author() ) { $post_type = $query->query_vars['post_type']; + if ( 'any' === $post_type ) { $post_type = get_post_types( array( 'exclude_from_search' => false ) ); } @@ -717,14 +718,16 @@ function posts_where_filter( $where, $query ) { } $terms_implode = rtrim( $terms_implode, ' OR' ); - $id = is_author() && $query->is_main_query() ? get_queried_object_id() : '\d+'; + // We need to check the query is the main query as a new query object would result in the wrong ID + $id = $query->is_main_query() && is_author() ? get_queried_object_id() : '\d+'; //If we have an ID but it's not a "real" ID that means that this isn't the first time the filter has fired and the object_id has already been replaced by a previous run of this filter. We therefore need to replace the 0 // This happens when wp_query::get_posts() is run multiple times. + // If previous condition resulted in this being a string there's no point wasting a db query looking for a user. if ( $id !== '\d+' && false === get_user_by( 'id', $id ) ){ $id = '\d+'; } - + // When WordPress generates query as 'post_author IN (id)'. if ( false !== strpos( $where, "{$wpdb->posts}.post_author IN " ) ) { @@ -969,7 +972,7 @@ function delete_user_action( $delete_id ) { if ( $this->is_guest_authors_enabled() ) { // 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 ); @@ -1033,7 +1036,7 @@ function filter_count_user_posts( $count, $user_id ) { $user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename ); $term = $this->get_author_term( $user ); - + if ( $term && ! is_wp_error( $term ) ) { $count = $term->count; } @@ -1663,17 +1666,17 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy * @return string Archive Page Title */ 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 ); - } + } /** * Get the post count for the guest author From f08c020f8c344f20cdc5e520ba701eed5031ccd6 Mon Sep 17 00:00:00 2001 From: James R Whitehead Date: Thu, 29 Nov 2018 11:25:39 +0000 Subject: [PATCH 259/269] Fix for issue #625 Changing the order to match previous commit. --- 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 9f8146c3..2e84732f 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -719,7 +719,7 @@ function posts_where_filter( $where, $query ) { $terms_implode = rtrim( $terms_implode, ' OR' ); // We need to check the query is the main query as a new query object would result in the wrong ID - $id = $query->is_main_query() && is_author() ? get_queried_object_id() : '\d+'; + $id = is_author() && $query->is_main_query() ? get_queried_object_id() : '\d+'; //If we have an ID but it's not a "real" ID that means that this isn't the first time the filter has fired and the object_id has already been replaced by a previous run of this filter. We therefore need to replace the 0 // This happens when wp_query::get_posts() is run multiple times. From 5f063004796359ec01d8abd02eb3ef5e3ec65c93 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Fri, 7 Dec 2018 09:56:09 -0500 Subject: [PATCH 260/269] Use CSS to hide Core's Author label + select This is a pretty big hack :) It would be better to remove the inputs completely rather than hiding them (via javascript or hooking directly into Gutenberg) but this is a good start. --- css/co-authors-plus.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/css/co-authors-plus.css b/css/co-authors-plus.css index e0ea462f..758bb567 100644 --- a/css/co-authors-plus.css +++ b/css/co-authors-plus.css @@ -109,3 +109,9 @@ margin-left: 30px; font-size: 13px; } + +/** Block Editor Hack for 5.0: Hide the core author input **/ +.block-editor label[for^="post-author-selector-"], +.block-editor select[id^="post-author-selector-"] { + display: none; +} From c53fbc31b329b8371844d84510e49074a9984d9b Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Fri, 7 Dec 2018 11:43:23 -0700 Subject: [PATCH 261/269] Revert "BUGFIX regular expression in posts_where_filter()" --- 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 2e84732f..4d449c18 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -752,7 +752,7 @@ function posts_where_filter( $where, $query ) { $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 b7105cb0e67a1f470c9a450b5d5038de952a9b48 Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Fri, 7 Dec 2018 09:56:09 -0500 Subject: [PATCH 262/269] Use CSS to hide Core's Author label + select This is a pretty big hack :) It would be better to remove the inputs completely rather than hiding them (via javascript or hooking directly into Gutenberg) but this is a good start. --- css/co-authors-plus.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/css/co-authors-plus.css b/css/co-authors-plus.css index e0ea462f..758bb567 100644 --- a/css/co-authors-plus.css +++ b/css/co-authors-plus.css @@ -109,3 +109,9 @@ margin-left: 30px; font-size: 13px; } + +/** Block Editor Hack for 5.0: Hide the core author input **/ +.block-editor label[for^="post-author-selector-"], +.block-editor select[id^="post-author-selector-"] { + display: none; +} From 65eabade2332a32deee0f7666876e19e9eb8b6cf Mon Sep 17 00:00:00 2001 From: Mohammad Jangda Date: Fri, 7 Dec 2018 16:21:47 -0500 Subject: [PATCH 263/269] Bump to 3.3.1 --- README.md | 7 +++++-- co-authors-plus.php | 4 ++-- readme.txt | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fec0d5c5..6f191f42 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ * Contributors: batmoo, danielbachhuber, automattic * Tags: authors, users, multiple authors, coauthors, multi-author, publishing -* Tested up to: 4.9.5 +* Tested up to: 5.0 * Requires at least: 4.1 -* Stable tag: 3.3.0 +* Stable tag: 3.3.1 Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box @@ -60,6 +60,9 @@ $ wp --url=example.com co-authors-plus create-terms-for-posts ## Changelog ## +**3.3.1 ("Gutentag")** +* 5.0 Compat: Hide core author inputs when using the Block Editor to limit confusion (h/t jonathanstegall). + **3.3.0 ("Rebecca")** * Fix private post viewing on front-end #386 * Reduce amount of sleep #400 diff --git a/co-authors-plus.php b/co-authors-plus.php index c3261ad4..75d77712 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.3.0 +Version: 3.3.1 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.3.0' ); +define( 'COAUTHORS_PLUS_VERSION', '3.3.1' ); require_once( dirname( __FILE__ ) . '/template-tags.php' ); require_once( dirname( __FILE__ ) . '/deprecated.php' ); diff --git a/readme.txt b/readme.txt index 5ff5a7ed..5577925b 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.9.5 +Tested up to: 5.0 Requires at least: 4.1 -Stable tag: 3.3.0 +Stable tag: 3.3.1 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.3.1 ("Gutentag") = +* 5.0 Compat: Hide core author inputs when using the Block Editor to limit confusion (h/t jonathanstegall). + = 3.3.0 ("Rebecca") = * Fix private post viewing on front-end * Reduce amount of sleep From e915b986a0579c82c3e7f91825ce4ead8975ccc0 Mon Sep 17 00:00:00 2001 From: mostafaabd Date: Sat, 5 Jan 2019 17:52:10 +0200 Subject: [PATCH 264/269] Fix issue display author image in author metabox (#452) --- co-authors-plus.php | 1 - 1 file changed, 1 deletion(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 74e63ea1..29029a60 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -386,7 +386,6 @@ public function coauthors_meta_box( $post ) { } ?>
  • - user_email, $this->gravatar_size ); ?> From 0318f061ae815f22995d3e518d92e77c55ff7f8c Mon Sep 17 00:00:00 2001 From: mostafaabd Date: Tue, 8 Jan 2019 10:26:13 +0200 Subject: [PATCH 265/269] Fix issue display author image if exists instead of avatar (#452) --- co-authors-plus.php | 33 ++++++++++++++++++++++----------- js/co-authors-plus.js | 29 +++-------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/co-authors-plus.php b/co-authors-plus.php index 29029a60..9f259f2b 100644 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -133,6 +133,9 @@ function __construct() { // Filter to correct author on author archive page add_filter( 'get_the_archive_title', array( $this, 'filter_author_archive_title'), 10, 2 ); + + // Filter to display author image if exists instead of avatar + add_filter( 'get_avatar_url', array( $this, 'filter_get_avatar_url' ), 10, 2 ); } /** @@ -221,7 +224,7 @@ public function admin_init() { // Apply some targeted filters add_action( 'load-edit.php', array( $this, 'load_edit' ) ); - + } /** @@ -380,10 +383,7 @@ public function coauthors_meta_box( $post ) { ID ) ) { - $avatar_url = get_the_post_thumbnail_url( $coauthor->ID, $this->gravatar_size ); - } + $avatar_url = get_avatar_url( $coauthor->ID, array( 'default' => 'gravatar_default' ) ); ?>
  • @@ -1172,10 +1172,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 ) { - $avatar_url = ''; - if ( has_post_thumbnail( $author->ID ) ) { - $avatar_url = get_the_post_thumbnail_url($author->ID, $this->gravatar_size ); - } + $avatar_url = get_avatar_url( $author->ID, array( 'default' => 'gravatar_default' ) ); echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . rawurldecode( $author->user_nicename ) ) . ' | ' . esc_url( $avatar_url ) . "\n"; } @@ -1697,7 +1694,21 @@ public function get_guest_author_post_count( $guest_author ) { return 0; } } - + + /** + * Filter to display author image if exists instead of avatar. + * + * @param $url string Avatar URL + * @param $id int Author ID + * + * @return string Avatar URL + */ + public function filter_get_avatar_url( $url, $id ) { + if ( has_post_thumbnail( $id ) ) { + $url = get_the_post_thumbnail_url( $id, $this->gravatar_size ); + } + return esc_url( $url ); + } } global $coauthors_plus; @@ -1854,4 +1865,4 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i function cap_get_coauthor_terms_for_post( $post_id ) { global $coauthors_plus; return $coauthors_plus->get_coauthor_terms_for_post( $post_id ); -} +} \ No newline at end of file diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 7d818f65..9c951756 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -82,7 +82,7 @@ jQuery( document ).ready(function () { if ( ! co ) var co = coauthors_create_autosuggest( author.name, coName ) var tag = coauthors_create_author_tag( author ); var input = coauthors_create_author_hidden_input( author ); - var $gravatar = coauthors_create_author_gravatar( author, 25 ); + var $gravatar = coauthors_create_author_gravatar( author ); tag.append( $gravatar ); @@ -254,39 +254,16 @@ jQuery( document ).ready(function () { return $tag; } - function coauthors_create_author_gravatar( author, size ) { - if( author.avatar ) { - var gravatar_link = author.avatar; - } else { - var gravatar_link = get_gravatar_link( author.email, size ); - } - + function coauthors_create_author_gravatar( author ) { var $gravatar = jQuery( '' ) .attr( 'alt', author.name ) - .attr( 'src', gravatar_link ) + .attr( 'src', author.avatar ) .addClass( 'coauthor-gravatar' ) ; return $gravatar; } - // MD5 (Message-Digest Algorithm) by WebToolkit -- needed for gravatars - // http://www.webtoolkit.info/javascript-md5.html - function MD5(s){function L(k,d){return(k<>>(32-d))}function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=(k&2147483648);I=(G&1073741824);d=(k&1073741824);x=(G&1073741823)+(k&1073741823);if(I&d){return(x^2147483648^F^H)}if(I|d){if(x&1073741824){return(x^3221225472^F^H)}else{return(x^1073741824^F^H)}}else{return(x^F^H)}}function r(d,F,k){return(d&F)|((~d)&k)}function q(d,F,k){return(d&k)|(F&(~k))}function p(d,F,k){return(d^F^k)}function n(d,F,k){return(F^(d|(~k)))}function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}function D(G,F,aa,Z,k,H,I){G=K(G,K(K(p(F,aa,Z),k),I));return K(L(G,H),F)}function t(G,F,aa,Z,k,H,I){G=K(G,K(K(n(F,aa,Z),k),I));return K(L(G,H),F)}function e(G){var Z;var F=G.length;var x=F+8;var k=(x-(x%64))/64;var I=(k+1)*16;var aa=Array(I-1);var d=0;var H=0;while(H>>29;return aa}function B(x){var k="",F="",G,d;for(d=0;d<=3;d++){G=(x>>>(d*8))&255;F="0"+G.toString(16);k=k+F.substr(F.length-2,2)}return k}function J(k){k=k.replace(/\r\n/g,"\n");var d="";for(var F=0;F127)&&(x<2048)){d+=String.fromCharCode((x>>6)|192);d+=String.fromCharCode((x&63)|128)}else{d+=String.fromCharCode((x>>12)|224);d+=String.fromCharCode(((x>>6)&63)|128);d+=String.fromCharCode((x&63)|128)}}}return d}var C=Array();var P,h,E,v,g,Y,X,W,V;var S=7,Q=12,N=17,M=22;var A=5,z=9,y=14,w=20;var o=4,m=11,l=16,j=23;var U=6,T=10,R=15,O=21;s=J(s);C=e(s);Y=1732584193;X=4023233417;W=2562383102;V=271733878;for(P=0;PID, array( 'default' => 'gravatar_default' ) ); ?>
  • + ID, $this->gravatar_size ); ?> - +
  • gravatar_size ); } - return esc_url( $url ); + return $url; } } diff --git a/js/co-authors-plus.js b/js/co-authors-plus.js index 9c951756..1ebffba1 100755 --- a/js/co-authors-plus.js +++ b/js/co-authors-plus.js @@ -373,7 +373,7 @@ jQuery( document ).ready(function () { var $post_coauthor_names = jQuery( 'input[name="coauthorsinput[]"]' ); var $post_coauthor_emails = jQuery( 'input[name="coauthorsemails[]"]' ); var $post_coauthor_nicenames = jQuery( 'input[name="coauthorsnicenames[]"]' ); - var $post_coauthoravatar = jQuery( 'input[name="coauthorsavaters[]"]' ); + var $post_coauthoravatars = jQuery( 'input[name="coauthorsavatars[]"]' ); var post_coauthors = []; @@ -383,7 +383,7 @@ jQuery( document ).ready(function () { name: $post_coauthor_names[i].value, email: $post_coauthor_emails[i].value, nicename: $post_coauthor_nicenames[i].value, - avatar: $post_coauthoravatar[i].value, + avatar: $post_coauthoravatars[i].value, }); } From dd6e31fa8d0462f8d083f46f14106727a531fcb6 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Sat, 9 Feb 2019 12:00:16 -0700 Subject: [PATCH 267/269] - fix merge conflicts --- template-tags.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/template-tags.php b/template-tags.php index b9b06567..e33d0ca3 100644 --- a/template-tags.php +++ b/template-tags.php @@ -36,6 +36,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 apply_filters( 'get_coauthors', $coauthors, $post_id ); } From d158558c8404935ea2c065d0d219828122569727 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Sat, 9 Feb 2019 12:01:31 -0700 Subject: [PATCH 268/269] - fix merge conflicts --- template-tags.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template-tags.php b/template-tags.php index e33d0ca3..d8b37f68 100644 --- a/template-tags.php +++ b/template-tags.php @@ -38,7 +38,8 @@ function get_coauthors( $post_id = 0 ) { } // remove duplicate $coauthors objects from mapping user accounts to guest authors accounts $coauthors = array_unique( $coauthors, SORT_REGULAR ); - return apply_filters( 'get_coauthors', $coauthors, $post_id ); + $coauthors = apply_filters( 'get_coauthors', $coauthors, $post_id ); + return $coauthors; } /** From 48945619091133eddabee2b6fc0191cee54ae98c Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 11 Mar 2019 23:19:25 +0530 Subject: [PATCH 269/269] VIP: Enable co-authors plus filter that disabled the querying by post_author on VIP Go This speeds up the SQL query. This filter has been enabled on WordPress.com VIP. This filter is active on WordPress.com VIP but not on VIP Go. --- vipgo-helper.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 vipgo-helper.php diff --git a/vipgo-helper.php b/vipgo-helper.php new file mode 100644 index 00000000..8debac77 --- /dev/null +++ b/vipgo-helper.php @@ -0,0 +1,9 @@ +