Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
language: php

php:
- 5.3
- 5.5
- "nightly"

env:
- WP_VERSION=latest
- WP_VERSION=4.1
- WP_VERSION=4.0

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
- php: "5.6"
env: WP_VERSION=4.5

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
16 changes: 11 additions & 5 deletions co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.1
Author: Mohammad Jangda, Daniel Bachhuber, Automattic
Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter

Expand All @@ -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' );
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -1595,6 +1600,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;
Expand Down
20 changes: 15 additions & 5 deletions php/class-coauthors-guest-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<tr><th>';
echo '<label for="' . esc_attr( $pm_key . '">' ) . esc_html( $field['label'] ) . '</label>';
echo '</th><td>';
echo '<textarea style="width:300px;margin-bottom:6px;" name="' . esc_attr( $pm_key ) . '">' . esc_textarea( $value ) . '</textarea>';
echo '</td></tr>';
printf( '
<tr>
<th>
<label for="%s">%s</label>
</th>
<td>
<textarea style="width:300px;margin-bottom:6px;" name="%s">%s</textarea>
</td>
</tr>
',
esc_attr( $pm_key ),
esc_html( $field['label'] ),
esc_attr( $pm_key ),
esc_textarea( $value )
);
}
echo '</tbody></table>';

Expand Down
20 changes: 14 additions & 6 deletions php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function create_guest_authors( $args, $assoc_args ) {
$users = get_users();
$created = 0;
$skipped = 0;
$count = count( $users );

WP_CLI::line( "Attempting to create guest author profiles for {$count} users" );
$progress = \WP_CLI\Utils\make_progress_bar( 'Creating Profiles', $count );
foreach ( $users as $user ) {

$result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID );
Expand All @@ -36,7 +40,10 @@ public function create_guest_authors( $args, $assoc_args ) {
} else {
$created++;
}

$progress->tick();
}
$progress->finish();

WP_CLI::line( 'All done! Here are your results:' );
WP_CLI::line( "- {$created} guest author profiles were created" );
Expand Down Expand Up @@ -76,7 +83,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() );
}
Expand Down Expand Up @@ -235,7 +243,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;
}
Expand Down Expand Up @@ -544,8 +552,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,
Expand Down Expand Up @@ -697,8 +705,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;
}
Expand Down
12 changes: 8 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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.6
Requires at least: 4.1
Stable tag: 3.1.1
Stable tag: 3.2.1

Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box

Expand Down Expand Up @@ -57,11 +57,15 @@ Bug fixes and minor enhancements

== Changelog ==

= 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) =
Expand Down
58 changes: 2 additions & 56 deletions tests/coauthorsplus-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,11 @@
/**
* 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 );
global $coauthors_plus;
$this->_cap = $coauthors_plus;
}
}
88 changes: 88 additions & 0 deletions tests/test-author-queried-object.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* Test Co-Authors Plus' modifications of author queries
*/

class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase {

/**
* On author pages, the queried object should only be set
* to a user that's not a member of the blog if they
* have at least one published post. This matches core behavior.
*
* @see https://core.trac.wordpress.org/changeset/27290
*/
function test__author_queried_object_fix() {
global $wp_rewrite, $coauthors_plus;

/**
* Set up
*/
$author1 = $this->factory->user->create( array( 'user_login' => 'msauthor1' ) );
$author2 = $this->factory->user->create( array( 'user_login' => 'msauthor2' ) );
$blog2 = $this->factory->blog->create( array( 'user_id' => $author1 ) );

switch_to_blog( $blog2 );
$wp_rewrite->init();

$blog2_post1 = $this->factory->post->create( array(
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
'post_author' => $author1,
) );

/**
* Author 1 is an author on the blog
*/
$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' );

/**
* Author 2 is now on the blog, but not yet published
*/
$this->go_to( get_author_posts_url( $author2 ) );
$this->assertQueryTrue( 'is_author', 'is_archive' );

// Add the user as an author on the original post
$author2_obj = get_user_by( 'id', $author2 );
$coauthors_plus->add_coauthors( $blog2_post1, array( $author2_obj->user_login ), true );

/**
* Author 2 is now on the blog, and published
*/
$this->go_to( get_author_posts_url( $author2 ) );
$this->assertQueryTrue( 'is_author', 'is_archive' );

// Remove the user from the blog
remove_user_from_blog( $author2, $blog2 );

/**
* Author 2 was removed from the blog, but still a published author
*/
$this->go_to( get_author_posts_url( $author2 ) );
$this->assertQueryTrue( 'is_author', 'is_archive' );

// Delete the user from the network
wpmu_delete_user( $author2 );

/**
* 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();

}
}
Loading