Version Description
("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
Release Info
Developer | philipjohn |
Plugin | ![]() |
Version | 3.3.0 |
Comparing to | |
See all releases |
Code changes from version 3.2.2 to 3.3.0
- co-authors-plus.php +168 -79
- css/co-authors-plus.css +3 -2
- js/co-authors-plus.js +31 -28
- php/class-coauthors-guest-authors.php +75 -36
- php/class-coauthors-wp-list-table.php +6 -3
- php/class-wp-cli.php +11 -10
- readme.txt +39 -2
- template-tags.php +156 -42
- tests/test-author-queried-object.php +0 -7
- tests/test-coauthors-guest-authors.php +890 -0
- tests/test-coauthors-plus.php +679 -0
- tests/test-manage-coauthors.php +280 -0
- tests/test-template-tags.php +1068 -0
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Co-Authors Plus
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/
|
5 |
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.
|
6 |
-
Version: 3.
|
7 |
Author: Mohammad Jangda, Daniel Bachhuber, Automattic
|
8 |
Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter
|
9 |
|
@@ -22,9 +22,17 @@ You should have received a copy of the GNU General Public License
|
|
22 |
along with this program; if not, write to the Free Software
|
23 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
*/
|
26 |
|
27 |
-
define( 'COAUTHORS_PLUS_VERSION', '3.
|
28 |
|
29 |
require_once( dirname( __FILE__ ) . '/template-tags.php' );
|
30 |
require_once( dirname( __FILE__ ) . '/deprecated.php' );
|
@@ -39,7 +47,7 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
|
39 |
class CoAuthors_Plus {
|
40 |
|
41 |
// Name for the taxonomy we're using to store relationships
|
42 |
-
// and the post type we're using to store
|
43 |
var $coauthor_taxonomy = 'author';
|
44 |
|
45 |
var $coreauthors_meta_box_name = 'authordiv';
|
@@ -68,38 +76,38 @@ class CoAuthors_Plus {
|
|
68 |
// Load admin_init function
|
69 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
70 |
|
71 |
-
// Modify SQL queries to include
|
72 |
add_filter( 'posts_where', array( $this, 'posts_where_filter' ), 10, 2 );
|
73 |
add_filter( 'posts_join', array( $this, 'posts_join_filter' ), 10, 2 );
|
74 |
add_filter( 'posts_groupby', array( $this, 'posts_groupby_filter' ), 10, 2 );
|
75 |
|
76 |
-
// Action to set
|
77 |
add_action( 'save_post', array( $this, 'coauthors_update_post' ), 10, 2 );
|
78 |
// Filter to set the post_author field when wp_insert_post is called
|
79 |
add_filter( 'wp_insert_post_data', array( $this, 'coauthors_set_post_author_field' ), 10, 2 );
|
80 |
|
81 |
-
// Action to reassign posts when a
|
82 |
add_action( 'delete_user', array( $this, 'delete_user_action' ) );
|
83 |
|
84 |
add_filter( 'get_usernumposts', array( $this, 'filter_count_user_posts' ), 10, 2 );
|
85 |
|
86 |
-
// Action to set up author auto-suggest
|
87 |
add_action( 'wp_ajax_coauthors_ajax_suggest', array( $this, 'ajax_suggest' ) );
|
88 |
|
89 |
-
// Filter to allow
|
90 |
add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10, 3 );
|
91 |
|
92 |
-
// Handle the custom author meta box
|
93 |
add_action( 'add_meta_boxes', array( $this, 'add_coauthors_box' ) );
|
94 |
add_action( 'add_meta_boxes', array( $this, 'remove_authors_box' ) );
|
95 |
|
96 |
-
// Removes the author dropdown from the post quick edit
|
97 |
add_action( 'admin_head', array( $this, 'remove_quick_edit_authors_box' ) );
|
98 |
|
99 |
// Restricts WordPress from blowing away term order on bulk edit
|
100 |
add_filter( 'wp_get_object_terms', array( $this, 'filter_wp_get_object_terms' ), 10, 4 );
|
101 |
|
102 |
-
// Make sure we've correctly set
|
103 |
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
|
104 |
add_action( 'the_post', array( $this, 'fix_author_page' ) );
|
105 |
|
@@ -110,16 +118,19 @@ class CoAuthors_Plus {
|
|
110 |
// Support Jetpack Open Graph Tags
|
111 |
add_filter( 'jetpack_open_graph_tags', array( $this, 'filter_jetpack_open_graph_tags' ), 10, 2 );
|
112 |
|
113 |
-
// Filter to send comment moderation notification e-mail to multiple authors
|
114 |
add_filter( 'comment_moderation_recipients', 'cap_filter_comment_moderation_email_recipients', 10, 2 );
|
115 |
|
116 |
// Support infinite scroll for Guest Authors on author pages
|
117 |
add_filter( 'infinite_scroll_js_settings', array( $this, 'filter_infinite_scroll_js_settings' ), 10, 2 );
|
118 |
|
119 |
-
// Delete
|
120 |
add_action( 'save_post', array( $this, 'clear_cache') );
|
121 |
add_action( 'delete_post', array( $this, 'clear_cache') );
|
122 |
add_action( 'set_object_terms', array( $this, 'clear_cache_on_terms_set' ), 10, 6 );
|
|
|
|
|
|
|
123 |
}
|
124 |
|
125 |
/**
|
@@ -174,7 +185,7 @@ class CoAuthors_Plus {
|
|
174 |
|
175 |
$post_types_with_authors = array_values( get_post_types() );
|
176 |
foreach ( $post_types_with_authors as $key => $name ) {
|
177 |
-
if ( ! post_type_supports( $name,
|
178 |
unset( $post_types_with_authors[ $key ] );
|
179 |
}
|
180 |
}
|
@@ -193,13 +204,13 @@ class CoAuthors_Plus {
|
|
193 |
// Add necessary JS variables
|
194 |
add_action( 'admin_head', array( $this, 'js_vars' ) );
|
195 |
|
196 |
-
// Hooks to add additional
|
197 |
add_filter( 'manage_posts_columns', array( $this, '_filter_manage_posts_columns' ) );
|
198 |
add_filter( 'manage_pages_columns', array( $this, '_filter_manage_posts_columns' ) );
|
199 |
add_action( 'manage_posts_custom_column', array( $this, '_filter_manage_posts_custom_column' ) );
|
200 |
add_action( 'manage_pages_custom_column', array( $this, '_filter_manage_posts_custom_column' ) );
|
201 |
|
202 |
-
// Add quick-edit author select field
|
203 |
add_action( 'quick_edit_custom_box', array( $this, '_action_quick_edit_custom_box' ), 10, 2 );
|
204 |
|
205 |
// Hooks to modify the published post number count on the Users WP List Table
|
@@ -225,7 +236,7 @@ class CoAuthors_Plus {
|
|
225 |
}
|
226 |
|
227 |
/**
|
228 |
-
* Get a
|
229 |
*
|
230 |
* @param string $key Key to search by (slug,email)
|
231 |
* @param string $value Value to search for
|
@@ -294,14 +305,17 @@ class CoAuthors_Plus {
|
|
294 |
|
295 |
if ( ! $post_type ) {
|
296 |
$post_type = get_post_type();
|
|
|
|
|
|
|
297 |
}
|
298 |
|
299 |
return (bool) in_array( $post_type, $this->supported_post_types );
|
300 |
}
|
301 |
|
302 |
/**
|
303 |
-
* Removes the standard WordPress Author box.
|
304 |
-
* We don't need it because the Co-Authors one is way cooler.
|
305 |
*/
|
306 |
public function remove_authors_box() {
|
307 |
|
@@ -311,7 +325,7 @@ class CoAuthors_Plus {
|
|
311 |
}
|
312 |
|
313 |
/**
|
314 |
-
* Adds a custom Authors box
|
315 |
*/
|
316 |
public function add_coauthors_box() {
|
317 |
|
@@ -321,7 +335,7 @@ class CoAuthors_Plus {
|
|
321 |
}
|
322 |
|
323 |
/**
|
324 |
-
* Callback for adding the custom
|
325 |
*/
|
326 |
public function coauthors_meta_box( $post ) {
|
327 |
global $post, $coauthors_plus, $current_screen;
|
@@ -395,18 +409,18 @@ class CoAuthors_Plus {
|
|
395 |
}
|
396 |
|
397 |
/**
|
398 |
-
* Removes the author dropdown from
|
399 |
*/
|
400 |
function remove_quick_edit_authors_box() {
|
401 |
global $pagenow;
|
402 |
|
403 |
if ( 'edit.php' == $pagenow && $this->is_post_type_enabled() ) {
|
404 |
-
remove_post_type_support( get_post_type(),
|
405 |
}
|
406 |
}
|
407 |
|
408 |
/**
|
409 |
-
* Add
|
410 |
*
|
411 |
* @param array $post_columns
|
412 |
*/
|
@@ -423,7 +437,7 @@ class CoAuthors_Plus {
|
|
423 |
$new_columns['coauthors'] = __( 'Authors', 'co-authors-plus' );
|
424 |
}
|
425 |
|
426 |
-
if (
|
427 |
unset( $new_columns[ $key ] );
|
428 |
}
|
429 |
}
|
@@ -431,7 +445,7 @@ class CoAuthors_Plus {
|
|
431 |
}
|
432 |
|
433 |
/**
|
434 |
-
* Insert
|
435 |
*
|
436 |
* @param string $column_name
|
437 |
*/
|
@@ -518,7 +532,7 @@ class CoAuthors_Plus {
|
|
518 |
}
|
519 |
|
520 |
/**
|
521 |
-
* When we update the terms at all, we should update the published post count for each
|
522 |
*/
|
523 |
function _update_users_posts_count( $tt_ids, $taxonomy ) {
|
524 |
global $wpdb;
|
@@ -616,10 +630,9 @@ class CoAuthors_Plus {
|
|
616 |
|
617 |
// Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley
|
618 |
$term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
|
619 |
-
$term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID =
|
620 |
|
621 |
-
$term_taxonomy_join
|
622 |
-
$term_taxonomy_join .= " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )";
|
623 |
|
624 |
// 4.6+ uses a LEFT JOIN for tax queries so we need to check for both
|
625 |
if ( false === strpos( $join, trim( $term_relationship_inner_join ) )
|
@@ -650,7 +663,7 @@ class CoAuthors_Plus {
|
|
650 |
if ( $query->get( 'author_name' ) ) {
|
651 |
$author_name = sanitize_title( $query->get( 'author_name' ) );
|
652 |
} else {
|
653 |
-
$author_data = get_userdata( $query->get(
|
654 |
if ( is_object( $author_data ) ) {
|
655 |
$author_name = $author_data->user_nicename;
|
656 |
} else {
|
@@ -663,7 +676,7 @@ class CoAuthors_Plus {
|
|
663 |
if ( $author_term = $this->get_author_term( $coauthor ) ) {
|
664 |
$terms[] = $author_term;
|
665 |
}
|
666 |
-
// If this
|
667 |
if ( ! empty( $coauthor->linked_account ) ) {
|
668 |
$linked_account = get_user_by( 'login', $coauthor->linked_account );
|
669 |
if ( $guest_author_term = $this->get_author_term( $linked_account ) ) {
|
@@ -689,8 +702,37 @@ class CoAuthors_Plus {
|
|
689 |
$this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $term->term_id .'\' OR ';
|
690 |
}
|
691 |
$terms_implode = rtrim( $terms_implode, ' OR' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
692 |
$this->having_terms = rtrim( $this->having_terms, ' OR' );
|
693 |
-
|
694 |
}
|
695 |
}
|
696 |
return $where;
|
@@ -722,7 +764,7 @@ class CoAuthors_Plus {
|
|
722 |
function coauthors_set_post_author_field( $data, $postarr ) {
|
723 |
|
724 |
// Bail on autosave
|
725 |
-
if ( defined( 'DOING_AUTOSAVE' ) &&
|
726 |
return $data;
|
727 |
}
|
728 |
|
@@ -733,7 +775,10 @@ class CoAuthors_Plus {
|
|
733 |
|
734 |
// This action happens when a post is saved while editing a post
|
735 |
if ( isset( $_REQUEST['coauthors-nonce'] ) && isset( $_POST['coauthors'] ) && is_array( $_POST['coauthors'] ) ) {
|
736 |
-
|
|
|
|
|
|
|
737 |
if ( $author ) {
|
738 |
$author_data = $this->get_coauthor_by( 'user_nicename', $author );
|
739 |
// If it's a guest author and has a linked account, store that information in post_author
|
@@ -746,7 +791,7 @@ class CoAuthors_Plus {
|
|
746 |
}
|
747 |
}
|
748 |
|
749 |
-
// If for some reason we don't have the
|
750 |
if ( ! isset( $data['post_author'] ) ) {
|
751 |
$user = wp_get_current_user();
|
752 |
$data['post_author'] = $user->ID;
|
@@ -765,7 +810,7 @@ class CoAuthors_Plus {
|
|
765 |
*/
|
766 |
function coauthors_update_post( $post_id, $post ) {
|
767 |
|
768 |
-
if ( defined( 'DOING_AUTOSAVE' ) &&
|
769 |
return;
|
770 |
}
|
771 |
|
@@ -779,7 +824,7 @@ class CoAuthors_Plus {
|
|
779 |
check_admin_referer( 'coauthors-edit', 'coauthors-nonce' );
|
780 |
|
781 |
$coauthors = (array) $_POST['coauthors'];
|
782 |
-
$coauthors = array_map( '
|
783 |
$this->add_coauthors( $post_id, $coauthors );
|
784 |
}
|
785 |
} else {
|
@@ -787,7 +832,7 @@ class CoAuthors_Plus {
|
|
787 |
if ( ! $this->has_author_terms( $post_id ) ) {
|
788 |
$user = get_userdata( $post->post_author );
|
789 |
if ( $user ) {
|
790 |
-
$this->add_coauthors( $post_id, array( $user->
|
791 |
}
|
792 |
}
|
793 |
}
|
@@ -823,7 +868,7 @@ class CoAuthors_Plus {
|
|
823 |
$coauthors = array( $current_user->user_login );
|
824 |
}
|
825 |
|
826 |
-
// Set the
|
827 |
$coauthors = array_unique( array_merge( $existing_coauthors, $coauthors ) );
|
828 |
$coauthor_objects = array();
|
829 |
foreach ( $coauthors as &$author_name ) {
|
@@ -859,9 +904,9 @@ class CoAuthors_Plus {
|
|
859 |
}
|
860 |
|
861 |
/**
|
862 |
-
* Action taken when
|
863 |
-
* -
|
864 |
-
* - Option to specify alternate
|
865 |
* @param delete_id
|
866 |
*/
|
867 |
function delete_user_action( $delete_id ) {
|
@@ -873,13 +918,13 @@ class CoAuthors_Plus {
|
|
873 |
if ( $reassign_id ) {
|
874 |
// Get posts belonging to deleted author
|
875 |
$reassign_user = get_user_by( 'id', $reassign_id );
|
876 |
-
// Set to new author
|
877 |
if ( is_object( $reassign_user ) ) {
|
878 |
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $delete_id ) );
|
879 |
|
880 |
if ( $post_ids ) {
|
881 |
foreach ( $post_ids as $post_id ) {
|
882 |
-
$this->add_coauthors( $post_id, array( $reassign_user->
|
883 |
}
|
884 |
}
|
885 |
}
|
@@ -890,17 +935,27 @@ class CoAuthors_Plus {
|
|
890 |
// Delete term
|
891 |
wp_delete_term( $delete_user->user_login, $this->coauthor_taxonomy );
|
892 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
893 |
}
|
894 |
|
895 |
/**
|
896 |
-
* Restrict WordPress from blowing away author order when bulk editing terms
|
897 |
*
|
898 |
* @since 2.6
|
899 |
* @props kingkool68, http://wordpress.org/support/topic/plugin-co-authors-plus-making-authors-sortable
|
900 |
*/
|
901 |
function filter_wp_get_object_terms( $terms, $object_ids, $taxonomies, $args ) {
|
902 |
-
|
903 |
-
if ( ! isset( $_REQUEST['bulk_edit'] ) || "'author'" !== $taxonomies ) {
|
904 |
return $terms;
|
905 |
}
|
906 |
|
@@ -943,8 +998,15 @@ class CoAuthors_Plus {
|
|
943 |
$user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename );
|
944 |
|
945 |
$term = $this->get_author_term( $user );
|
946 |
-
|
947 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
948 |
$count = $term->count;
|
949 |
}
|
950 |
|
@@ -952,7 +1014,7 @@ class CoAuthors_Plus {
|
|
952 |
}
|
953 |
|
954 |
/**
|
955 |
-
* Checks to see if the current user can set authors or not
|
956 |
*/
|
957 |
function current_user_can_set_authors( $post = null ) {
|
958 |
global $typenow;
|
@@ -960,11 +1022,17 @@ class CoAuthors_Plus {
|
|
960 |
if ( ! $post ) {
|
961 |
$post = get_post();
|
962 |
if ( ! $post ) {
|
963 |
-
|
|
|
|
|
|
|
|
|
|
|
964 |
}
|
965 |
}
|
966 |
-
|
967 |
-
|
|
|
968 |
|
969 |
// TODO: need to fix this; shouldn't just say no if don't have post_type
|
970 |
if ( ! $post_type ) {
|
@@ -989,12 +1057,12 @@ class CoAuthors_Plus {
|
|
989 |
/**
|
990 |
* Fix for author pages 404ing or not properly displaying on author pages
|
991 |
*
|
992 |
-
* If
|
993 |
-
* the author if they're a
|
994 |
*
|
995 |
-
* If the author does have posts, it doesn't matter that they're not an author.
|
996 |
*
|
997 |
-
* Alternatively, on an author archive, if the first story has
|
998 |
* the first author is NOT the same as the author for the archive,
|
999 |
* the query_var is changed.
|
1000 |
*
|
@@ -1020,10 +1088,10 @@ class CoAuthors_Plus {
|
|
1020 |
$term = $this->get_author_term( $authordata );
|
1021 |
}
|
1022 |
|
1023 |
-
if (
|
1024 |
-
|| ( ! empty( $term ) && $term->count ) ) {
|
1025 |
$wp_query->queried_object = $authordata;
|
1026 |
$wp_query->queried_object_id = $authordata->ID;
|
|
|
1027 |
} else {
|
1028 |
$wp_query->queried_object = $wp_query->queried_object_id = null;
|
1029 |
$wp_query->is_author = $wp_query->is_archive = false;
|
@@ -1049,7 +1117,7 @@ class CoAuthors_Plus {
|
|
1049 |
$author = get_queried_object();
|
1050 |
|
1051 |
if ( $author && 'guest-author' == $author->type ) {
|
1052 |
-
unset( $settings['query_args
|
1053 |
|
1054 |
$settings['query_args']['author_name'] = $author->user_nicename;
|
1055 |
}
|
@@ -1058,7 +1126,7 @@ class CoAuthors_Plus {
|
|
1058 |
}
|
1059 |
|
1060 |
/**
|
1061 |
-
* Main function that handles search-as-you-type for adding authors
|
1062 |
*/
|
1063 |
public function ajax_suggest() {
|
1064 |
|
@@ -1075,8 +1143,11 @@ class CoAuthors_Plus {
|
|
1075 |
|
1076 |
$authors = $this->search_authors( $search, $ignore );
|
1077 |
|
|
|
|
|
|
|
1078 |
foreach ( $authors as $author ) {
|
1079 |
-
echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . $author->user_nicename ) . "\n";
|
1080 |
}
|
1081 |
|
1082 |
die();
|
@@ -1084,7 +1155,7 @@ class CoAuthors_Plus {
|
|
1084 |
}
|
1085 |
|
1086 |
/**
|
1087 |
-
* Get matching authors based on a search value
|
1088 |
*/
|
1089 |
public function search_authors( $search = '', $ignored_authors = array() ) {
|
1090 |
|
@@ -1128,7 +1199,7 @@ class CoAuthors_Plus {
|
|
1128 |
return array();
|
1129 |
}
|
1130 |
|
1131 |
-
// Get the
|
1132 |
$found_users = array();
|
1133 |
foreach ( $found_terms as $found_term ) {
|
1134 |
$found_user = $this->get_coauthor_by( 'user_nicename', $found_term->slug );
|
@@ -1153,7 +1224,7 @@ class CoAuthors_Plus {
|
|
1153 |
/**
|
1154 |
* Modify get_users() to search display_name instead of user_nicename
|
1155 |
*/
|
1156 |
-
function action_pre_user_query(
|
1157 |
|
1158 |
if ( is_object( $user_query ) ) {
|
1159 |
$user_query->query_where = str_replace( 'user_nicename LIKE', 'display_name LIKE', $user_query->query_where );
|
@@ -1279,7 +1350,7 @@ class CoAuthors_Plus {
|
|
1279 |
}
|
1280 |
|
1281 |
/**
|
1282 |
-
* Allows
|
1283 |
*/
|
1284 |
function filter_user_has_cap( $allcaps, $caps, $args ) {
|
1285 |
|
@@ -1339,10 +1410,19 @@ class CoAuthors_Plus {
|
|
1339 |
return $term;
|
1340 |
}
|
1341 |
|
1342 |
-
//
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1346 |
}
|
1347 |
wp_cache_set( $cache_key, $term, 'co-authors-plus' );
|
1348 |
return $term;
|
@@ -1398,19 +1478,19 @@ class CoAuthors_Plus {
|
|
1398 |
function filter_ef_calendar_item_information_fields( $information_fields, $post_id ) {
|
1399 |
|
1400 |
// Don't add the author row again if another plugin has removed
|
1401 |
-
if ( ! array_key_exists(
|
1402 |
return $information_fields;
|
1403 |
}
|
1404 |
|
1405 |
$co_authors = get_coauthors( $post_id );
|
1406 |
if ( count( $co_authors ) > 1 ) {
|
1407 |
-
$information_fields
|
1408 |
}
|
1409 |
$co_authors_names = '';
|
1410 |
foreach ( $co_authors as $co_author ) {
|
1411 |
$co_authors_names .= $co_author->display_name . ', ';
|
1412 |
}
|
1413 |
-
$information_fields
|
1414 |
return $information_fields;
|
1415 |
}
|
1416 |
|
@@ -1427,7 +1507,7 @@ class CoAuthors_Plus {
|
|
1427 |
function filter_ef_story_budget_term_column_value( $column_name, $post, $parent_term ) {
|
1428 |
|
1429 |
// We only want to modify the 'author' column
|
1430 |
-
if (
|
1431 |
return $column_name;
|
1432 |
}
|
1433 |
|
@@ -1475,12 +1555,12 @@ class CoAuthors_Plus {
|
|
1475 |
}
|
1476 |
|
1477 |
/**
|
1478 |
-
* Retrieve a list of
|
1479 |
*
|
1480 |
-
* Grabs a correctly ordered list of authors for a single post, appropriately
|
1481 |
* cached because it requires `wp_get_object_terms()` to succeed.
|
1482 |
*
|
1483 |
-
* @param int $post_id ID of the post for which to retrieve authors.
|
1484 |
* @return array Array of coauthor WP_Term objects
|
1485 |
*/
|
1486 |
public function get_coauthor_terms_for_post( $post_id ) {
|
@@ -1535,6 +1615,15 @@ class CoAuthors_Plus {
|
|
1535 |
|
1536 |
}
|
1537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1538 |
}
|
1539 |
|
1540 |
global $coauthors_plus;
|
@@ -1680,7 +1769,7 @@ function cap_filter_comment_moderation_email_recipients( $recipients, $comment_i
|
|
1680 |
}
|
1681 |
|
1682 |
/**
|
1683 |
-
* Retrieve a list of
|
1684 |
*
|
1685 |
* Grabs a correctly ordered list of authors for a single post, appropriately
|
1686 |
* cached because it requires `wp_get_object_terms()` to succeed.
|
3 |
Plugin Name: Co-Authors Plus
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/
|
5 |
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.
|
6 |
+
Version: 3.3.0
|
7 |
Author: Mohammad Jangda, Daniel Bachhuber, Automattic
|
8 |
Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter
|
9 |
|
22 |
along with this program; if not, write to the Free Software
|
23 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24 |
|
25 |
+
-----------------
|
26 |
+
|
27 |
+
Glossary:
|
28 |
+
|
29 |
+
User - a WordPress user account
|
30 |
+
Guest author - a CAP-created co-author
|
31 |
+
Co-author - in the context of a single post, a guest author or user assigned to the post alongside others
|
32 |
+
Author - user with the role of author
|
33 |
*/
|
34 |
|
35 |
+
define( 'COAUTHORS_PLUS_VERSION', '3.3.0' );
|
36 |
|
37 |
require_once( dirname( __FILE__ ) . '/template-tags.php' );
|
38 |
require_once( dirname( __FILE__ ) . '/deprecated.php' );
|
47 |
class CoAuthors_Plus {
|
48 |
|
49 |
// Name for the taxonomy we're using to store relationships
|
50 |
+
// and the post type we're using to store guest authors
|
51 |
var $coauthor_taxonomy = 'author';
|
52 |
|
53 |
var $coreauthors_meta_box_name = 'authordiv';
|
76 |
// Load admin_init function
|
77 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
78 |
|
79 |
+
// Modify SQL queries to include guest authors
|
80 |
add_filter( 'posts_where', array( $this, 'posts_where_filter' ), 10, 2 );
|
81 |
add_filter( 'posts_join', array( $this, 'posts_join_filter' ), 10, 2 );
|
82 |
add_filter( 'posts_groupby', array( $this, 'posts_groupby_filter' ), 10, 2 );
|
83 |
|
84 |
+
// Action to set co-authors when a post is saved
|
85 |
add_action( 'save_post', array( $this, 'coauthors_update_post' ), 10, 2 );
|
86 |
// Filter to set the post_author field when wp_insert_post is called
|
87 |
add_filter( 'wp_insert_post_data', array( $this, 'coauthors_set_post_author_field' ), 10, 2 );
|
88 |
|
89 |
+
// Action to reassign posts when a guest author is deleted
|
90 |
add_action( 'delete_user', array( $this, 'delete_user_action' ) );
|
91 |
|
92 |
add_filter( 'get_usernumposts', array( $this, 'filter_count_user_posts' ), 10, 2 );
|
93 |
|
94 |
+
// Action to set up co-author auto-suggest
|
95 |
add_action( 'wp_ajax_coauthors_ajax_suggest', array( $this, 'ajax_suggest' ) );
|
96 |
|
97 |
+
// Filter to allow co-authors to edit posts
|
98 |
add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10, 3 );
|
99 |
|
100 |
+
// Handle the custom co-author meta box
|
101 |
add_action( 'add_meta_boxes', array( $this, 'add_coauthors_box' ) );
|
102 |
add_action( 'add_meta_boxes', array( $this, 'remove_authors_box' ) );
|
103 |
|
104 |
+
// Removes the co-author dropdown from the post quick edit
|
105 |
add_action( 'admin_head', array( $this, 'remove_quick_edit_authors_box' ) );
|
106 |
|
107 |
// Restricts WordPress from blowing away term order on bulk edit
|
108 |
add_filter( 'wp_get_object_terms', array( $this, 'filter_wp_get_object_terms' ), 10, 4 );
|
109 |
|
110 |
+
// Make sure we've correctly set data on guest author pages
|
111 |
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
|
112 |
add_action( 'the_post', array( $this, 'fix_author_page' ) );
|
113 |
|
118 |
// Support Jetpack Open Graph Tags
|
119 |
add_filter( 'jetpack_open_graph_tags', array( $this, 'filter_jetpack_open_graph_tags' ), 10, 2 );
|
120 |
|
121 |
+
// Filter to send comment moderation notification e-mail to multiple co-authors
|
122 |
add_filter( 'comment_moderation_recipients', 'cap_filter_comment_moderation_email_recipients', 10, 2 );
|
123 |
|
124 |
// Support infinite scroll for Guest Authors on author pages
|
125 |
add_filter( 'infinite_scroll_js_settings', array( $this, 'filter_infinite_scroll_js_settings' ), 10, 2 );
|
126 |
|
127 |
+
// Delete Co-Author Cache on Post Save & Post Delete
|
128 |
add_action( 'save_post', array( $this, 'clear_cache') );
|
129 |
add_action( 'delete_post', array( $this, 'clear_cache') );
|
130 |
add_action( 'set_object_terms', array( $this, 'clear_cache_on_terms_set' ), 10, 6 );
|
131 |
+
|
132 |
+
// Filter to correct author on author archive page
|
133 |
+
add_filter( 'get_the_archive_title', array( $this, 'filter_author_archive_title'), 10, 2 );
|
134 |
}
|
135 |
|
136 |
/**
|
185 |
|
186 |
$post_types_with_authors = array_values( get_post_types() );
|
187 |
foreach ( $post_types_with_authors as $key => $name ) {
|
188 |
+
if ( ! post_type_supports( $name, $this->coauthor_taxonomy ) || in_array( $name, array( 'revision', 'attachment' ) ) ) {
|
189 |
unset( $post_types_with_authors[ $key ] );
|
190 |
}
|
191 |
}
|
204 |
// Add necessary JS variables
|
205 |
add_action( 'admin_head', array( $this, 'js_vars' ) );
|
206 |
|
207 |
+
// Hooks to add additional co-authors to 'authors' column to edit page
|
208 |
add_filter( 'manage_posts_columns', array( $this, '_filter_manage_posts_columns' ) );
|
209 |
add_filter( 'manage_pages_columns', array( $this, '_filter_manage_posts_columns' ) );
|
210 |
add_action( 'manage_posts_custom_column', array( $this, '_filter_manage_posts_custom_column' ) );
|
211 |
add_action( 'manage_pages_custom_column', array( $this, '_filter_manage_posts_custom_column' ) );
|
212 |
|
213 |
+
// Add quick-edit co-author select field
|
214 |
add_action( 'quick_edit_custom_box', array( $this, '_action_quick_edit_custom_box' ), 10, 2 );
|
215 |
|
216 |
// Hooks to modify the published post number count on the Users WP List Table
|
236 |
}
|
237 |
|
238 |
/**
|
239 |
+
* Get a guest author object by a specific type of key
|
240 |
*
|
241 |
* @param string $key Key to search by (slug,email)
|
242 |
* @param string $value Value to search for
|
305 |
|
306 |
if ( ! $post_type ) {
|
307 |
$post_type = get_post_type();
|
308 |
+
if ( is_admin() && ! $post_type) {
|
309 |
+
$post_type = get_current_screen()->post_type;
|
310 |
+
}
|
311 |
}
|
312 |
|
313 |
return (bool) in_array( $post_type, $this->supported_post_types );
|
314 |
}
|
315 |
|
316 |
/**
|
317 |
+
* Removes the standard WordPress 'Author' box.
|
318 |
+
* We don't need it because the Co-Authors Plus one is way cooler.
|
319 |
*/
|
320 |
public function remove_authors_box() {
|
321 |
|
325 |
}
|
326 |
|
327 |
/**
|
328 |
+
* Adds a custom 'Authors' box
|
329 |
*/
|
330 |
public function add_coauthors_box() {
|
331 |
|
335 |
}
|
336 |
|
337 |
/**
|
338 |
+
* Callback for adding the custom 'Authors' box
|
339 |
*/
|
340 |
public function coauthors_meta_box( $post ) {
|
341 |
global $post, $coauthors_plus, $current_screen;
|
409 |
}
|
410 |
|
411 |
/**
|
412 |
+
* Removes the default 'author' dropdown from quick edit
|
413 |
*/
|
414 |
function remove_quick_edit_authors_box() {
|
415 |
global $pagenow;
|
416 |
|
417 |
if ( 'edit.php' == $pagenow && $this->is_post_type_enabled() ) {
|
418 |
+
remove_post_type_support( get_post_type(), $this->coauthor_taxonomy );
|
419 |
}
|
420 |
}
|
421 |
|
422 |
/**
|
423 |
+
* Add co-authors to 'authors' column on edit pages
|
424 |
*
|
425 |
* @param array $post_columns
|
426 |
*/
|
437 |
$new_columns['coauthors'] = __( 'Authors', 'co-authors-plus' );
|
438 |
}
|
439 |
|
440 |
+
if ( $this->coauthor_taxonomy === $key ) {
|
441 |
unset( $new_columns[ $key ] );
|
442 |
}
|
443 |
}
|
445 |
}
|
446 |
|
447 |
/**
|
448 |
+
* Insert co-authors into post rows on Edit Page
|
449 |
*
|
450 |
* @param string $column_name
|
451 |
*/
|
532 |
}
|
533 |
|
534 |
/**
|
535 |
+
* When we update the terms at all, we should update the published post count for each user
|
536 |
*/
|
537 |
function _update_users_posts_count( $tt_ids, $taxonomy ) {
|
538 |
global $wpdb;
|
630 |
|
631 |
// Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley
|
632 |
$term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
|
633 |
+
$term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} AS tr1 ON ({$wpdb->posts}.ID = tr1.object_id)";
|
634 |
|
635 |
+
$term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( tr1.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )";
|
|
|
636 |
|
637 |
// 4.6+ uses a LEFT JOIN for tax queries so we need to check for both
|
638 |
if ( false === strpos( $join, trim( $term_relationship_inner_join ) )
|
663 |
if ( $query->get( 'author_name' ) ) {
|
664 |
$author_name = sanitize_title( $query->get( 'author_name' ) );
|
665 |
} else {
|
666 |
+
$author_data = get_userdata( $query->get( $this->coauthor_taxonomy ) );
|
667 |
if ( is_object( $author_data ) ) {
|
668 |
$author_name = $author_data->user_nicename;
|
669 |
} else {
|
676 |
if ( $author_term = $this->get_author_term( $coauthor ) ) {
|
677 |
$terms[] = $author_term;
|
678 |
}
|
679 |
+
// If this co-author has a linked account, we also need to get posts with those terms
|
680 |
if ( ! empty( $coauthor->linked_account ) ) {
|
681 |
$linked_account = get_user_by( 'login', $coauthor->linked_account );
|
682 |
if ( $guest_author_term = $this->get_author_term( $linked_account ) ) {
|
702 |
$this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $term->term_id .'\' OR ';
|
703 |
}
|
704 |
$terms_implode = rtrim( $terms_implode, ' OR' );
|
705 |
+
|
706 |
+
$id = is_author() ? get_queried_object_id() : '\d+';
|
707 |
+
|
708 |
+
// When WordPress generates query as 'post_author IN (id)'.
|
709 |
+
if ( false !== strpos( $where, "{$wpdb->posts}.post_author IN " ) ) {
|
710 |
+
|
711 |
+
$maybe_both_query = $maybe_both ? '$0 OR' : '';
|
712 |
+
|
713 |
+
$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
|
714 |
+
|
715 |
+
} else {
|
716 |
+
$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
|
717 |
+
}
|
718 |
+
|
719 |
+
// the block targets the private posts clause (if it exists)
|
720 |
+
if (
|
721 |
+
is_user_logged_in() &&
|
722 |
+
is_author() &&
|
723 |
+
get_queried_object_id() != get_current_user_id()
|
724 |
+
) {
|
725 |
+
$current_coauthor = $this->get_coauthor_by( 'user_nicename', wp_get_current_user()->user_nicename );
|
726 |
+
$current_coauthor_term = $this->get_author_term( $current_coauthor );
|
727 |
+
|
728 |
+
$current_user_query = $wpdb->term_taxonomy . '.taxonomy = \''. $this->coauthor_taxonomy.'\' AND '. $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\'';
|
729 |
+
$this->having_terms .= ' ' . $wpdb->term_taxonomy .'.term_id = \''. $current_coauthor_term->term_id .'\' OR ';
|
730 |
+
|
731 |
+
$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
|
732 |
+
}
|
733 |
+
|
734 |
$this->having_terms = rtrim( $this->having_terms, ' OR' );
|
735 |
+
|
736 |
}
|
737 |
}
|
738 |
return $where;
|
764 |
function coauthors_set_post_author_field( $data, $postarr ) {
|
765 |
|
766 |
// Bail on autosave
|
767 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
768 |
return $data;
|
769 |
}
|
770 |
|
775 |
|
776 |
// This action happens when a post is saved while editing a post
|
777 |
if ( isset( $_REQUEST['coauthors-nonce'] ) && isset( $_POST['coauthors'] ) && is_array( $_POST['coauthors'] ) ) {
|
778 |
+
|
779 |
+
// rawurlencode() is for encoding coauthor name with special characters to compare names when getting coauthor.
|
780 |
+
$author = rawurlencode( sanitize_text_field( $_POST['coauthors'][0] ) );
|
781 |
+
|
782 |
if ( $author ) {
|
783 |
$author_data = $this->get_coauthor_by( 'user_nicename', $author );
|
784 |
// If it's a guest author and has a linked account, store that information in post_author
|
791 |
}
|
792 |
}
|
793 |
|
794 |
+
// If for some reason we don't have the co-authors fields set
|
795 |
if ( ! isset( $data['post_author'] ) ) {
|
796 |
$user = wp_get_current_user();
|
797 |
$data['post_author'] = $user->ID;
|
810 |
*/
|
811 |
function coauthors_update_post( $post_id, $post ) {
|
812 |
|
813 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
814 |
return;
|
815 |
}
|
816 |
|
824 |
check_admin_referer( 'coauthors-edit', 'coauthors-nonce' );
|
825 |
|
826 |
$coauthors = (array) $_POST['coauthors'];
|
827 |
+
$coauthors = array_map( 'sanitize_title', $coauthors );
|
828 |
$this->add_coauthors( $post_id, $coauthors );
|
829 |
}
|
830 |
} else {
|
832 |
if ( ! $this->has_author_terms( $post_id ) ) {
|
833 |
$user = get_userdata( $post->post_author );
|
834 |
if ( $user ) {
|
835 |
+
$this->add_coauthors( $post_id, array( $user->user_nicename ) );
|
836 |
}
|
837 |
}
|
838 |
}
|
868 |
$coauthors = array( $current_user->user_login );
|
869 |
}
|
870 |
|
871 |
+
// Set the co-authors
|
872 |
$coauthors = array_unique( array_merge( $existing_coauthors, $coauthors ) );
|
873 |
$coauthor_objects = array();
|
874 |
foreach ( $coauthors as &$author_name ) {
|
904 |
}
|
905 |
|
906 |
/**
|
907 |
+
* Action taken when co-author is deleted.
|
908 |
+
* - Co-Author term is removed from all associated posts
|
909 |
+
* - Option to specify alternate co-author in place for each post
|
910 |
* @param delete_id
|
911 |
*/
|
912 |
function delete_user_action( $delete_id ) {
|
918 |
if ( $reassign_id ) {
|
919 |
// Get posts belonging to deleted author
|
920 |
$reassign_user = get_user_by( 'id', $reassign_id );
|
921 |
+
// Set to new guest author
|
922 |
if ( is_object( $reassign_user ) ) {
|
923 |
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $delete_id ) );
|
924 |
|
925 |
if ( $post_ids ) {
|
926 |
foreach ( $post_ids as $post_id ) {
|
927 |
+
$this->add_coauthors( $post_id, array( $reassign_user->user_nicename ), true );
|
928 |
}
|
929 |
}
|
930 |
}
|
935 |
// Delete term
|
936 |
wp_delete_term( $delete_user->user_login, $this->coauthor_taxonomy );
|
937 |
}
|
938 |
+
|
939 |
+
// Get the deleted user data by user id.
|
940 |
+
$user_data = get_user_by( 'id', $delete_id );
|
941 |
+
|
942 |
+
// Get the associated user.
|
943 |
+
$associated_user = $this->guest_authors->get_guest_author_by( 'linked_account', $user_data->data->user_login );
|
944 |
+
|
945 |
+
if ( isset( $associated_user->ID ) ) {
|
946 |
+
// Delete associated guest user.
|
947 |
+
$this->guest_authors->delete( $associated_user->ID );
|
948 |
+
}
|
949 |
}
|
950 |
|
951 |
/**
|
952 |
+
* Restrict WordPress from blowing away co-author order when bulk editing terms
|
953 |
*
|
954 |
* @since 2.6
|
955 |
* @props kingkool68, http://wordpress.org/support/topic/plugin-co-authors-plus-making-authors-sortable
|
956 |
*/
|
957 |
function filter_wp_get_object_terms( $terms, $object_ids, $taxonomies, $args ) {
|
958 |
+
if ( ! isset( $_REQUEST['bulk_edit'] ) || $this->coauthor_taxonomy !== $taxonomies ) {
|
|
|
959 |
return $terms;
|
960 |
}
|
961 |
|
998 |
$user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename );
|
999 |
|
1000 |
$term = $this->get_author_term( $user );
|
1001 |
+
$guest_term = get_term_by( 'slug', 'cap-' . $user->user_nicename, $this->coauthor_taxonomy );
|
1002 |
+
// Only modify the count if it has a linked account with posts or the author exists as a term
|
1003 |
+
if ( $user->linked_account && $guest_term->count ) {
|
1004 |
+
if ( $term && ! is_wp_error( $term )) {
|
1005 |
+
$count = $guest_term->count + $term->count;
|
1006 |
+
} else {
|
1007 |
+
$count = $guest_term->count;
|
1008 |
+
}
|
1009 |
+
} elseif ( $term && ! is_wp_error( $term ) ) {
|
1010 |
$count = $term->count;
|
1011 |
}
|
1012 |
|
1014 |
}
|
1015 |
|
1016 |
/**
|
1017 |
+
* Checks to see if the current user can set co-authors or not
|
1018 |
*/
|
1019 |
function current_user_can_set_authors( $post = null ) {
|
1020 |
global $typenow;
|
1022 |
if ( ! $post ) {
|
1023 |
$post = get_post();
|
1024 |
if ( ! $post ) {
|
1025 |
+
// if user is on pages, you need to grab post type another way
|
1026 |
+
$current_screen = get_current_screen();
|
1027 |
+
$post_type = ( ! empty( $current_screen->post_type ) ) ? $current_screen->post_type : '';
|
1028 |
+
}
|
1029 |
+
else {
|
1030 |
+
$post_type = $post->post_type;
|
1031 |
}
|
1032 |
}
|
1033 |
+
else {
|
1034 |
+
$post_type = $post->post_type;
|
1035 |
+
}
|
1036 |
|
1037 |
// TODO: need to fix this; shouldn't just say no if don't have post_type
|
1038 |
if ( ! $post_type ) {
|
1057 |
/**
|
1058 |
* Fix for author pages 404ing or not properly displaying on author pages
|
1059 |
*
|
1060 |
+
* If a guest author has no posts, we only want to force the queried object to be
|
1061 |
+
* the author if they're a user.
|
1062 |
*
|
1063 |
+
* If the guest author does have posts, it doesn't matter that they're not an author.
|
1064 |
*
|
1065 |
+
* Alternatively, on an author archive, if the first story has co-authors and
|
1066 |
* the first author is NOT the same as the author for the archive,
|
1067 |
* the query_var is changed.
|
1068 |
*
|
1088 |
$term = $this->get_author_term( $authordata );
|
1089 |
}
|
1090 |
|
1091 |
+
if ( is_object( $authordata ) || ! empty( $term ) ) {
|
|
|
1092 |
$wp_query->queried_object = $authordata;
|
1093 |
$wp_query->queried_object_id = $authordata->ID;
|
1094 |
+
add_filter( 'pre_handle_404', '__return_true' );
|
1095 |
} else {
|
1096 |
$wp_query->queried_object = $wp_query->queried_object_id = null;
|
1097 |
$wp_query->is_author = $wp_query->is_archive = false;
|
1117 |
$author = get_queried_object();
|
1118 |
|
1119 |
if ( $author && 'guest-author' == $author->type ) {
|
1120 |
+
unset( $settings['query_args'][$this->coauthor_taxonomy] );
|
1121 |
|
1122 |
$settings['query_args']['author_name'] = $author->user_nicename;
|
1123 |
}
|
1126 |
}
|
1127 |
|
1128 |
/**
|
1129 |
+
* Main function that handles search-as-you-type for adding co-authors
|
1130 |
*/
|
1131 |
public function ajax_suggest() {
|
1132 |
|
1143 |
|
1144 |
$authors = $this->search_authors( $search, $ignore );
|
1145 |
|
1146 |
+
// Return message if no authors found
|
1147 |
+
if( empty( $authors ) ) echo apply_filters( 'coauthors_no_matching_authors_message', 'Sorry, no matching authors found.');
|
1148 |
+
|
1149 |
foreach ( $authors as $author ) {
|
1150 |
+
echo esc_html( $author->ID . ' | ' . $author->user_login . ' | ' . $author->display_name . ' | ' . $author->user_email . ' | ' . rawurldecode( $author->user_nicename ) ) . "\n";
|
1151 |
}
|
1152 |
|
1153 |
die();
|
1155 |
}
|
1156 |
|
1157 |
/**
|
1158 |
+
* Get matching co-authors based on a search value
|
1159 |
*/
|
1160 |
public function search_authors( $search = '', $ignored_authors = array() ) {
|
1161 |
|
1199 |
return array();
|
1200 |
}
|
1201 |
|
1202 |
+
// Get the guest author objects
|
1203 |
$found_users = array();
|
1204 |
foreach ( $found_terms as $found_term ) {
|
1205 |
$found_user = $this->get_coauthor_by( 'user_nicename', $found_term->slug );
|
1224 |
/**
|
1225 |
* Modify get_users() to search display_name instead of user_nicename
|
1226 |
*/
|
1227 |
+
function action_pre_user_query( $user_query ) {
|
1228 |
|
1229 |
if ( is_object( $user_query ) ) {
|
1230 |
$user_query->query_where = str_replace( 'user_nicename LIKE', 'display_name LIKE', $user_query->query_where );
|
1350 |
}
|
1351 |
|
1352 |
/**
|
1353 |
+
* Allows guest authors to edit the post they're co-authors of
|
1354 |
*/
|
1355 |
function filter_user_has_cap( $allcaps, $caps, $args ) {
|
1356 |
|
1410 |
return $term;
|
1411 |
}
|
1412 |
|
1413 |
+
// use linked user for accurate post count
|
1414 |
+
if ( ! empty ( $coauthor->linked_account ) ) {
|
1415 |
+
$term = get_term_by( 'slug', 'cap-' . $coauthor->linked_account, $this->coauthor_taxonomy );
|
1416 |
+
if ( ! $term ) {
|
1417 |
+
$term = get_term_by( 'slug', $coauthor->linked_account, $this->coauthor_taxonomy );
|
1418 |
+
}
|
1419 |
+
}
|
1420 |
+
else {
|
1421 |
+
// See if the prefixed term is available, otherwise default to just the nicename
|
1422 |
+
$term = get_term_by( 'slug', 'cap-' . $coauthor->user_nicename, $this->coauthor_taxonomy );
|
1423 |
+
if ( ! $term ) {
|
1424 |
+
$term = get_term_by( 'slug', $coauthor->user_nicename, $this->coauthor_taxonomy );
|
1425 |
+
}
|
1426 |
}
|
1427 |
wp_cache_set( $cache_key, $term, 'co-authors-plus' );
|
1428 |
return $term;
|
1478 |
function filter_ef_calendar_item_information_fields( $information_fields, $post_id ) {
|
1479 |
|
1480 |
// Don't add the author row again if another plugin has removed
|
1481 |
+
if ( ! array_key_exists( $this->coauthor_taxonomy, $information_fields ) ) {
|
1482 |
return $information_fields;
|
1483 |
}
|
1484 |
|
1485 |
$co_authors = get_coauthors( $post_id );
|
1486 |
if ( count( $co_authors ) > 1 ) {
|
1487 |
+
$information_fields[$this->coauthor_taxonomy]['label'] = __( 'Authors', 'co-authors-plus' );
|
1488 |
}
|
1489 |
$co_authors_names = '';
|
1490 |
foreach ( $co_authors as $co_author ) {
|
1491 |
$co_authors_names .= $co_author->display_name . ', ';
|
1492 |
}
|
1493 |
+
$information_fields[$this->coauthor_taxonomy]['value'] = rtrim( $co_authors_names, ', ' );
|
1494 |
return $information_fields;
|
1495 |
}
|
1496 |
|
1507 |
function filter_ef_story_budget_term_column_value( $column_name, $post, $parent_term ) {
|
1508 |
|
1509 |
// We only want to modify the 'author' column
|
1510 |
+
if ( $this->coauthor_taxonomy != $column_name ) {
|
1511 |
return $column_name;
|
1512 |
}
|
1513 |
|
1555 |
}
|
1556 |
|
1557 |
/**
|
1558 |
+
* Retrieve a list of author terms for a single post.
|
1559 |
*
|
1560 |
+
* Grabs a correctly ordered list of co-authors for a single post, appropriately
|
1561 |
* cached because it requires `wp_get_object_terms()` to succeed.
|
1562 |
*
|
1563 |
+
* @param int $post_id ID of the post for which to retrieve co-authors.
|
1564 |
* @return array Array of coauthor WP_Term objects
|
1565 |
*/
|
1566 |
public function get_coauthor_terms_for_post( $post_id ) {
|
1615 |
|
1616 |
}
|
1617 |
|
1618 |
+
/**
|
1619 |
+
* Filter of the header of author archive pages to correctly display author.
|
1620 |
+
*/
|
1621 |
+
public function filter_author_archive_title() {
|
1622 |
+
if ( is_author() ) {
|
1623 |
+
$author = sanitize_user( get_query_var( 'author_name' ) );
|
1624 |
+
return "Author: ". $author;
|
1625 |
+
}
|
1626 |
+
}
|
1627 |
}
|
1628 |
|
1629 |
global $coauthors_plus;
|
1769 |
}
|
1770 |
|
1771 |
/**
|
1772 |
+
* Retrieve a list of co-author terms for a single post.
|
1773 |
*
|
1774 |
* Grabs a correctly ordered list of authors for a single post, appropriately
|
1775 |
* cached because it requires `wp_get_object_terms()` to succeed.
|
@@ -42,7 +42,7 @@
|
|
42 |
width:200px;
|
43 |
}
|
44 |
#coauthors-list .ui-sortable-helper .coauthor-tag {
|
45 |
-
cursor:
|
46 |
cursor:-moz-grabbing;
|
47 |
cursor:-webkit-grabbing;
|
48 |
}
|
@@ -88,6 +88,7 @@
|
|
88 |
}
|
89 |
#coauthors-loading {
|
90 |
margin: 10px 0px 5px 10px;
|
|
|
91 |
}
|
92 |
|
93 |
#coauthors-readonly {
|
@@ -107,4 +108,4 @@
|
|
107 |
padding: 5px 3px;
|
108 |
margin-left: 30px;
|
109 |
font-size: 13px;
|
110 |
-
}
|
42 |
width:200px;
|
43 |
}
|
44 |
#coauthors-list .ui-sortable-helper .coauthor-tag {
|
45 |
+
cursor: grabbing;
|
46 |
cursor:-moz-grabbing;
|
47 |
cursor:-webkit-grabbing;
|
48 |
}
|
88 |
}
|
89 |
#coauthors-loading {
|
90 |
margin: 10px 0px 5px 10px;
|
91 |
+
float: left;
|
92 |
}
|
93 |
|
94 |
#coauthors-readonly {
|
108 |
padding: 5px 3px;
|
109 |
margin-left: 30px;
|
110 |
font-size: 13px;
|
111 |
+
}
|
@@ -11,7 +11,7 @@ jQuery( document ).ready(function () {
|
|
11 |
return false;
|
12 |
};
|
13 |
|
14 |
-
var $coauthors_loading
|
15 |
|
16 |
function coauthors_delete( elem ) {
|
17 |
|
@@ -39,9 +39,9 @@ jQuery( document ).ready(function () {
|
|
39 |
}
|
40 |
|
41 |
/*
|
42 |
-
* Save
|
43 |
-
* @param int Author ID
|
44 |
-
* @param string Author Name
|
45 |
* @param object The autosuggest input box
|
46 |
*/
|
47 |
function coauthors_save_coauthor( author, co ) {
|
@@ -59,8 +59,8 @@ jQuery( document ).ready(function () {
|
|
59 |
|
60 |
|
61 |
/*
|
62 |
-
* Add
|
63 |
-
* @param string Author Name
|
64 |
* @param object The autosuggest input box
|
65 |
* @param boolean Initial set up or not?
|
66 |
*/
|
@@ -70,11 +70,11 @@ jQuery( document ).ready(function () {
|
|
70 |
if ( co && co.siblings( '.coauthor-tag' ).length ) {
|
71 |
coauthors_save_coauthor( author, co );
|
72 |
} else {
|
73 |
-
// Not editing, so we create a new author entry
|
74 |
if ( count == 0 ) {
|
75 |
var coName = ( count == 0 ) ? 'coauthors-main' : '';
|
76 |
-
// Add new author to <select>
|
77 |
-
//coauthors_select_author( author );
|
78 |
}
|
79 |
var options = { addDelete: true, addEdit: false };
|
80 |
|
@@ -98,8 +98,9 @@ jQuery( document ).ready(function () {
|
|
98 |
|
99 |
co.bind( 'blur', coauthors_stop_editing );
|
100 |
|
101 |
-
// Set the value for the auto-suggest box to the
|
102 |
-
|
|
|
103 |
.hide()
|
104 |
.unbind( 'focus' )
|
105 |
;
|
@@ -132,8 +133,8 @@ jQuery( document ).ready(function () {
|
|
132 |
}
|
133 |
|
134 |
/*
|
135 |
-
* Adds a delete and edit button next to
|
136 |
-
* @param object The row to which the new author should be added
|
137 |
*/
|
138 |
function coauthors_insert_author_edit_cells( $div, options ){
|
139 |
|
@@ -156,7 +157,7 @@ jQuery( document ).ready(function () {
|
|
156 |
|
157 |
/*
|
158 |
* Creates autosuggest input box
|
159 |
-
* @param string [optional] Name of the author
|
160 |
* @param string [optional] Name to be applied to the input box
|
161 |
*/
|
162 |
function coauthors_create_autosuggest( authorName, inputName ) {
|
@@ -178,7 +179,7 @@ jQuery( document ).ready(function () {
|
|
178 |
;
|
179 |
|
180 |
if ( authorName )
|
181 |
-
$co.attr( 'value',
|
182 |
else
|
183 |
$co.attr( 'value', coAuthorsPlusStrings.search_box_text )
|
184 |
.focus( function(){ $co.val( '' ) } )
|
@@ -189,7 +190,7 @@ jQuery( document ).ready(function () {
|
|
189 |
|
190 |
}
|
191 |
|
192 |
-
// Callback for when a user selects
|
193 |
function coauthors_autosuggest_select() {
|
194 |
$this = jQuery( this );
|
195 |
var vals = this.value.split( '|' );
|
@@ -199,7 +200,9 @@ jQuery( document ).ready(function () {
|
|
199 |
author.login = jQuery.trim( vals[1] );
|
200 |
author.name = jQuery.trim( vals[2] );
|
201 |
author.email = jQuery.trim( vals[3] );
|
202 |
-
|
|
|
|
|
203 |
|
204 |
if ( author.id=='New' ) {
|
205 |
coauthors_new_author_display( name );
|
@@ -234,13 +237,13 @@ jQuery( document ).ready(function () {
|
|
234 |
}
|
235 |
|
236 |
/*
|
237 |
-
* Creates the text tag for
|
238 |
-
* @param string Name of the author
|
239 |
*/
|
240 |
function coauthors_create_author_tag( author ) {
|
241 |
|
242 |
var $tag = jQuery( '<span></span>' )
|
243 |
-
.
|
244 |
.attr( 'title', coAuthorsPlusStrings.input_box_title )
|
245 |
.addClass( 'coauthor-tag' )
|
246 |
// Add Click event to edit
|
@@ -278,8 +281,8 @@ jQuery( document ).ready(function () {
|
|
278 |
}
|
279 |
|
280 |
/*
|
281 |
-
* Creates the text tag for
|
282 |
-
* @param string Name of the author
|
283 |
*/
|
284 |
function coauthors_create_author_hidden_input ( author ) {
|
285 |
var input = jQuery( '<input />' )
|
@@ -287,7 +290,7 @@ jQuery( document ).ready(function () {
|
|
287 |
'type': 'hidden',
|
288 |
'id': 'coauthors_hidden_input',
|
289 |
'name': 'coauthors[]',
|
290 |
-
'value':
|
291 |
})
|
292 |
;
|
293 |
|
@@ -319,7 +322,7 @@ jQuery( document ).ready(function () {
|
|
319 |
$coauthors_div.append( table );
|
320 |
}
|
321 |
|
322 |
-
// Select authors already added to the post
|
323 |
var addedAlready = [];
|
324 |
//jQuery('#the-list tr').each(function(){
|
325 |
var count = 0;
|
@@ -337,11 +340,11 @@ jQuery( document ).ready(function () {
|
|
337 |
var newCO = coauthors_create_autosuggest( '', false );
|
338 |
coauthors_add_to_table( newCO );
|
339 |
|
340 |
-
$coauthors_loading = jQuery( '#
|
341 |
move_loading( newCO );
|
342 |
|
343 |
|
344 |
-
// Make co-authors sortable so an editor can control the order of the authors
|
345 |
jQuery( '#coauthors-edit' ).ready(function( $ ) {
|
346 |
$( '#coauthors-list' ).sortable({
|
347 |
axis: 'y',
|
@@ -398,7 +401,7 @@ jQuery( document ).ready(function () {
|
|
398 |
});
|
399 |
}
|
400 |
|
401 |
-
// Remove the read-only
|
402 |
jQuery( '#coauthors-readonly' ).remove();
|
403 |
coauthors_initialize( post_coauthors );
|
404 |
}
|
@@ -425,7 +428,7 @@ jQuery( document ).ready(function () {
|
|
425 |
var el = jQuery( '.inline-edit-group.inline-edit-coauthors', '#edit-' + postId );
|
426 |
el.detach().appendTo( '.quick-edit-row .inline-edit-col-left .inline-edit-col' ).show();
|
427 |
|
428 |
-
// initialize
|
429 |
var post_coauthors = jQuery.map( jQuery( '.column-coauthors a', $postRow ), function( el ) {
|
430 |
return {
|
431 |
login: jQuery( el ).data( 'user_login' ),
|
11 |
return false;
|
12 |
};
|
13 |
|
14 |
+
var $coauthors_loading = jQuery("<span id='ajax-loading'></span>");
|
15 |
|
16 |
function coauthors_delete( elem ) {
|
17 |
|
39 |
}
|
40 |
|
41 |
/*
|
42 |
+
* Save co-author
|
43 |
+
* @param int Co-Author ID
|
44 |
+
* @param string Co-Author Name
|
45 |
* @param object The autosuggest input box
|
46 |
*/
|
47 |
function coauthors_save_coauthor( author, co ) {
|
59 |
|
60 |
|
61 |
/*
|
62 |
+
* Add co-author
|
63 |
+
* @param string Co-Author Name
|
64 |
* @param object The autosuggest input box
|
65 |
* @param boolean Initial set up or not?
|
66 |
*/
|
70 |
if ( co && co.siblings( '.coauthor-tag' ).length ) {
|
71 |
coauthors_save_coauthor( author, co );
|
72 |
} else {
|
73 |
+
// Not editing, so we create a new co-author entry
|
74 |
if ( count == 0 ) {
|
75 |
var coName = ( count == 0 ) ? 'coauthors-main' : '';
|
76 |
+
// Add new co-author to <select>
|
77 |
+
//coauthors_select_author( co-author );
|
78 |
}
|
79 |
var options = { addDelete: true, addEdit: false };
|
80 |
|
98 |
|
99 |
co.bind( 'blur', coauthors_stop_editing );
|
100 |
|
101 |
+
// Set the value for the auto-suggest box to the co-author's name and hide it
|
102 |
+
// unescape() is deprecated, so replacing it with decodeURIComponent() here and every places.
|
103 |
+
co.val( decodeURIComponent( author.name ) )
|
104 |
.hide()
|
105 |
.unbind( 'focus' )
|
106 |
;
|
133 |
}
|
134 |
|
135 |
/*
|
136 |
+
* Adds a delete and edit button next to a co-author
|
137 |
+
* @param object The row to which the new co-author should be added
|
138 |
*/
|
139 |
function coauthors_insert_author_edit_cells( $div, options ){
|
140 |
|
157 |
|
158 |
/*
|
159 |
* Creates autosuggest input box
|
160 |
+
* @param string [optional] Name of the co-author
|
161 |
* @param string [optional] Name to be applied to the input box
|
162 |
*/
|
163 |
function coauthors_create_autosuggest( authorName, inputName ) {
|
179 |
;
|
180 |
|
181 |
if ( authorName )
|
182 |
+
$co.attr( 'value', decodeURIComponent( authorName ) );
|
183 |
else
|
184 |
$co.attr( 'value', coAuthorsPlusStrings.search_box_text )
|
185 |
.focus( function(){ $co.val( '' ) } )
|
190 |
|
191 |
}
|
192 |
|
193 |
+
// Callback for when a user selects a co-author
|
194 |
function coauthors_autosuggest_select() {
|
195 |
$this = jQuery( this );
|
196 |
var vals = this.value.split( '|' );
|
200 |
author.login = jQuery.trim( vals[1] );
|
201 |
author.name = jQuery.trim( vals[2] );
|
202 |
author.email = jQuery.trim( vals[3] );
|
203 |
+
|
204 |
+
// Decode user-nicename if it has special characters in it.
|
205 |
+
author.nicename = decodeURIComponent( jQuery.trim( vals[4] ) );
|
206 |
|
207 |
if ( author.id=='New' ) {
|
208 |
coauthors_new_author_display( name );
|
237 |
}
|
238 |
|
239 |
/*
|
240 |
+
* Creates the text tag for a co-author
|
241 |
+
* @param string Name of the co-author
|
242 |
*/
|
243 |
function coauthors_create_author_tag( author ) {
|
244 |
|
245 |
var $tag = jQuery( '<span></span>' )
|
246 |
+
.text( decodeURIComponent( author.name ) )
|
247 |
.attr( 'title', coAuthorsPlusStrings.input_box_title )
|
248 |
.addClass( 'coauthor-tag' )
|
249 |
// Add Click event to edit
|
281 |
}
|
282 |
|
283 |
/*
|
284 |
+
* Creates the text tag for a co-author
|
285 |
+
* @param string Name of the co-author
|
286 |
*/
|
287 |
function coauthors_create_author_hidden_input ( author ) {
|
288 |
var input = jQuery( '<input />' )
|
290 |
'type': 'hidden',
|
291 |
'id': 'coauthors_hidden_input',
|
292 |
'name': 'coauthors[]',
|
293 |
+
'value': decodeURIComponent( author.nicename )
|
294 |
})
|
295 |
;
|
296 |
|
322 |
$coauthors_div.append( table );
|
323 |
}
|
324 |
|
325 |
+
// Select co-authors already added to the post
|
326 |
var addedAlready = [];
|
327 |
//jQuery('#the-list tr').each(function(){
|
328 |
var count = 0;
|
340 |
var newCO = coauthors_create_autosuggest( '', false );
|
341 |
coauthors_add_to_table( newCO );
|
342 |
|
343 |
+
$coauthors_loading = jQuery( '#publishing-action .spinner' ).clone().attr( 'id', 'coauthors-loading' );
|
344 |
move_loading( newCO );
|
345 |
|
346 |
|
347 |
+
// Make co-authors sortable so an editor can control the order of the co-authors
|
348 |
jQuery( '#coauthors-edit' ).ready(function( $ ) {
|
349 |
$( '#coauthors-list' ).sortable({
|
350 |
axis: 'y',
|
401 |
});
|
402 |
}
|
403 |
|
404 |
+
// Remove the read-only co-authors so we don't get craziness
|
405 |
jQuery( '#coauthors-readonly' ).remove();
|
406 |
coauthors_initialize( post_coauthors );
|
407 |
}
|
428 |
var el = jQuery( '.inline-edit-group.inline-edit-coauthors', '#edit-' + postId );
|
429 |
el.detach().appendTo( '.quick-edit-row .inline-edit-col-left .inline-edit-col' ).show();
|
430 |
|
431 |
+
// initialize co-authors
|
432 |
var post_coauthors = jQuery.map( jQuery( '.column-coauthors a', $postRow ), function( el ) {
|
433 |
return {
|
434 |
login: jQuery( el ).data( 'user_login' ),
|
@@ -89,9 +89,13 @@ class CoAuthors_Guest_Authors
|
|
89 |
'not_found_in_trash' => __( 'No guest authors found in Trash', 'co-authors-plus' ),
|
90 |
'update_item' => __( 'Update Guest Author', 'co-authors-plus' ),
|
91 |
'metabox_about' => __( 'About the guest author', 'co-authors-plus' ),
|
|
|
|
|
|
|
|
|
92 |
) );
|
93 |
|
94 |
-
// Register a post type to store our authors
|
95 |
$args = array(
|
96 |
'label' => $this->labels['singular'],
|
97 |
'labels' => array(
|
@@ -106,6 +110,10 @@ class CoAuthors_Guest_Authors
|
|
106 |
'search_items' => $this->labels['search_items'],
|
107 |
'not_found' => $this->labels['not_found'],
|
108 |
'not_found_in_trash' => $this->labels['not_found_in_trash'],
|
|
|
|
|
|
|
|
|
109 |
),
|
110 |
'public' => true,
|
111 |
'publicly_queryable' => false,
|
@@ -123,17 +131,7 @@ class CoAuthors_Guest_Authors
|
|
123 |
register_post_type( $this->post_type, $args );
|
124 |
|
125 |
// Some of the common sizes used by get_avatar
|
126 |
-
$this->avatar_sizes = array
|
127 |
-
32,
|
128 |
-
50,
|
129 |
-
64,
|
130 |
-
96,
|
131 |
-
128,
|
132 |
-
);
|
133 |
-
$this->avatar_sizes = apply_filters( 'coauthors_guest_author_avatar_sizes', $this->avatar_sizes );
|
134 |
-
foreach ( $this->avatar_sizes as $size ) {
|
135 |
-
add_image_size( 'guest-author-' . $size, $size, $size, true );
|
136 |
-
}
|
137 |
|
138 |
// Hacky way to remove the title and the editor
|
139 |
remove_post_type_support( $this->post_type, 'title' );
|
@@ -177,7 +175,7 @@ class CoAuthors_Guest_Authors
|
|
177 |
|
178 |
/**
|
179 |
* Handle the admin action to create a guest author based
|
180 |
-
* on an existing
|
181 |
*
|
182 |
* @since 3.0
|
183 |
*/
|
@@ -203,6 +201,8 @@ class CoAuthors_Guest_Authors
|
|
203 |
wp_die( esc_html( $post_id->get_error_message() ) );
|
204 |
}
|
205 |
|
|
|
|
|
206 |
// Redirect to the edit Guest Author screen
|
207 |
$edit_link = get_edit_post_link( $post_id, 'redirect' );
|
208 |
$redirect_to = add_query_arg( 'message', 'guest-author-created', $edit_link );
|
@@ -273,6 +273,8 @@ class CoAuthors_Guest_Authors
|
|
273 |
$args['message'] = 'delete-error';
|
274 |
} else {
|
275 |
$args['message'] = 'guest-author-deleted';
|
|
|
|
|
276 |
}
|
277 |
|
278 |
// Redirect to safety
|
@@ -463,36 +465,75 @@ class CoAuthors_Guest_Authors
|
|
463 |
wp_die( esc_html( sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $this->labels['singular'] ) ) );
|
464 |
}
|
465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
echo '<div class="wrap">';
|
467 |
echo '<div class="icon32" id="icon-users"><br/></div>';
|
468 |
echo '<h2>' . esc_html( sprintf( __( 'Delete %s', 'co-authors-plus ' ), $this->labels['plural'] ) ) . '</h2>';
|
469 |
echo '<p>' . esc_html( sprintf( __( 'You have specified this %s for deletion:', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
|
470 |
echo '<p>#' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '</p>';
|
471 |
-
|
472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
echo '<form method="POST" action="' . esc_url( add_query_arg( 'page', 'view-guest-authors', admin_url( $this->parent_page ) ) ) . '">';
|
474 |
// Hidden stuffs
|
475 |
echo '<input type="hidden" name="action" value="delete-guest-author" />';
|
476 |
wp_nonce_field( 'delete-guest-author' );
|
477 |
echo '<input type="hidden" id="id" name="id" value="' . esc_attr( (int) $_GET['id'] ) . '" />';
|
478 |
echo '<fieldset><ul style="list-style-type:none;">';
|
479 |
-
//
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
echo '</label></li>';
|
489 |
}
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
echo '</label></li>';
|
494 |
echo '</ul></fieldset>';
|
495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
echo '</form>';
|
497 |
echo '</div>';
|
498 |
} else {
|
@@ -592,7 +633,7 @@ class CoAuthors_Guest_Authors
|
|
592 |
}
|
593 |
|
594 |
/**
|
595 |
-
* Metabox to display all of the pertient names for a Guest Author
|
596 |
*
|
597 |
* @since 3.0
|
598 |
*/
|
@@ -627,7 +668,8 @@ class CoAuthors_Guest_Authors
|
|
627 |
}
|
628 |
|
629 |
/**
|
630 |
-
* Metabox to display all of the pertient contact details for a Guest Author
|
|
|
631 |
*
|
632 |
* @since 3.0
|
633 |
*/
|
@@ -931,11 +973,8 @@ class CoAuthors_Guest_Authors
|
|
931 |
$args = array(
|
932 |
'class' => "avatar avatar-{$size} photo",
|
933 |
);
|
934 |
-
|
935 |
-
|
936 |
-
} else {
|
937 |
-
$size = array( $size, $size );
|
938 |
-
}
|
939 |
|
940 |
$thumbnail = get_the_post_thumbnail( $guest_author->ID, $size, $args );
|
941 |
|
89 |
'not_found_in_trash' => __( 'No guest authors found in Trash', 'co-authors-plus' ),
|
90 |
'update_item' => __( 'Update Guest Author', 'co-authors-plus' ),
|
91 |
'metabox_about' => __( 'About the guest author', 'co-authors-plus' ),
|
92 |
+
'featured_image' => __( 'Avatar', 'co-authors-plus' ),
|
93 |
+
'set_featured_image' => __( 'Set Avatar', 'co-authors-plus' ),
|
94 |
+
'use_featured_image' => __( 'Use Avatar', 'co-authors-plus' ),
|
95 |
+
'remove_featured_image' => __( 'Remove Avatar', 'co-authors-plus' ),
|
96 |
) );
|
97 |
|
98 |
+
// Register a post type to store our guest authors
|
99 |
$args = array(
|
100 |
'label' => $this->labels['singular'],
|
101 |
'labels' => array(
|
110 |
'search_items' => $this->labels['search_items'],
|
111 |
'not_found' => $this->labels['not_found'],
|
112 |
'not_found_in_trash' => $this->labels['not_found_in_trash'],
|
113 |
+
'featured_image' => $this->labels['featured_image'],
|
114 |
+
'set_featured_image' => $this->labels['set_featured_image'],
|
115 |
+
'use_featured_image' => $this->labels['use_featured_image'],
|
116 |
+
'remove_featured_image' => $this->labels['remove_featured_image']
|
117 |
),
|
118 |
'public' => true,
|
119 |
'publicly_queryable' => false,
|
131 |
register_post_type( $this->post_type, $args );
|
132 |
|
133 |
// Some of the common sizes used by get_avatar
|
134 |
+
$this->avatar_sizes = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
// Hacky way to remove the title and the editor
|
137 |
remove_post_type_support( $this->post_type, 'title' );
|
175 |
|
176 |
/**
|
177 |
* Handle the admin action to create a guest author based
|
178 |
+
* on an existing user
|
179 |
*
|
180 |
* @since 3.0
|
181 |
*/
|
201 |
wp_die( esc_html( $post_id->get_error_message() ) );
|
202 |
}
|
203 |
|
204 |
+
do_action( 'cap_guest_author_create' );
|
205 |
+
|
206 |
// Redirect to the edit Guest Author screen
|
207 |
$edit_link = get_edit_post_link( $post_id, 'redirect' );
|
208 |
$redirect_to = add_query_arg( 'message', 'guest-author-created', $edit_link );
|
273 |
$args['message'] = 'delete-error';
|
274 |
} else {
|
275 |
$args['message'] = 'guest-author-deleted';
|
276 |
+
|
277 |
+
do_action( 'cap_guest_author_del' );
|
278 |
}
|
279 |
|
280 |
// Redirect to safety
|
465 |
wp_die( esc_html( sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $this->labels['singular'] ) ) );
|
466 |
}
|
467 |
|
468 |
+
// get post count
|
469 |
+
global $coauthors_plus;
|
470 |
+
$term = $coauthors_plus->get_author_term( $guest_author );
|
471 |
+
if ( $term ) {
|
472 |
+
$count = $term->count;
|
473 |
+
} else {
|
474 |
+
$count = 0;
|
475 |
+
}
|
476 |
+
|
477 |
echo '<div class="wrap">';
|
478 |
echo '<div class="icon32" id="icon-users"><br/></div>';
|
479 |
echo '<h2>' . esc_html( sprintf( __( 'Delete %s', 'co-authors-plus ' ), $this->labels['plural'] ) ) . '</h2>';
|
480 |
echo '<p>' . esc_html( sprintf( __( 'You have specified this %s for deletion:', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
|
481 |
echo '<p>#' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '</p>';
|
482 |
+
// display wording differently per post count
|
483 |
+
if ( 0 === $count ) {
|
484 |
+
$post_count_message = '<p>' . sprintf( __( 'There are no posts associated with this guest author.', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) . '</p>';
|
485 |
+
}
|
486 |
+
else {
|
487 |
+
$note = '<p class="description">' . 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'] ) ) . '</p>';
|
488 |
+
if ( 1 === $count ) {
|
489 |
+
$post_count_message = '<p>' . 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'] ) ) . '</p>';
|
490 |
+
}
|
491 |
+
else {
|
492 |
+
$post_count_message = '<p>' . 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'] ) ) . '</p>';
|
493 |
+
}
|
494 |
+
$post_count_message .= $note;
|
495 |
+
}
|
496 |
+
$allowed_html = array(
|
497 |
+
'p' => array(
|
498 |
+
'class' => array(),
|
499 |
+
),
|
500 |
+
);
|
501 |
+
echo wp_kses( $post_count_message, $allowed_html );
|
502 |
echo '<form method="POST" action="' . esc_url( add_query_arg( 'page', 'view-guest-authors', admin_url( $this->parent_page ) ) ) . '">';
|
503 |
// Hidden stuffs
|
504 |
echo '<input type="hidden" name="action" value="delete-guest-author" />';
|
505 |
wp_nonce_field( 'delete-guest-author' );
|
506 |
echo '<input type="hidden" id="id" name="id" value="' . esc_attr( (int) $_GET['id'] ) . '" />';
|
507 |
echo '<fieldset><ul style="list-style-type:none;">';
|
508 |
+
// only show delete options if post count > 0
|
509 |
+
if ( $count > 0 ) {
|
510 |
+
// Reassign to another user
|
511 |
+
echo '<li class="hide-if-no-js"><label for="reassign-another">';
|
512 |
+
echo '<input type="radio" id="reassign-another" name="reassign" class="reassign-option" value="reassign-another" /> ' . esc_html__( 'Reassign to another co-author:', 'co-authors-plus' ) . ' </label>';
|
513 |
+
echo '<input type="hidden" id="leave-assigned-to" name="leave-assigned-to" style="width:200px;" />';
|
514 |
+
echo '</li>';
|
515 |
+
// Leave mapped to a linked account
|
516 |
+
if ( get_user_by( 'login', $guest_author->linked_account ) ) {
|
517 |
+
echo '<li><label for="leave-assigned">';
|
518 |
+
echo '<input type="radio" id="leave-assigned" class="reassign-option" name="reassign" value="leave-assigned" /> ' . esc_html( sprintf( __( 'Leave posts assigned to the mapped user, %s.', 'co-authors-plus' ), $guest_author->linked_account ) );
|
519 |
+
echo '</label></li>';
|
520 |
+
}
|
521 |
+
// Remove bylines from the posts
|
522 |
+
echo '<li><label for="remove-byline">';
|
523 |
+
echo '<input type="radio" id="remove-byline" class="reassign-option" name="reassign" value="remove-byline" /> ' . esc_html__( 'Remove byline from posts (but leave each post in its current status).', 'co-authors-plus' );
|
524 |
echo '</label></li>';
|
525 |
}
|
526 |
+
else {
|
527 |
+
echo '<input type="hidden" id="remove-byline" class="reassign-option" name="reassign" value="remove-byline" checked="checked" />';
|
528 |
+
}
|
|
|
529 |
echo '</ul></fieldset>';
|
530 |
+
// disable disabled submit button for 0 post count
|
531 |
+
if ( 0 === $count ) {
|
532 |
+
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true );
|
533 |
+
}
|
534 |
+
else {
|
535 |
+
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) );
|
536 |
+
}
|
537 |
echo '</form>';
|
538 |
echo '</div>';
|
539 |
} else {
|
633 |
}
|
634 |
|
635 |
/**
|
636 |
+
* Metabox to display all of the pertient names for a Guest Author not linked to user account
|
637 |
*
|
638 |
* @since 3.0
|
639 |
*/
|
668 |
}
|
669 |
|
670 |
/**
|
671 |
+
* Metabox to display all of the pertient contact details for a Guest Author not linked to
|
672 |
+
* user account
|
673 |
*
|
674 |
* @since 3.0
|
675 |
*/
|
973 |
$args = array(
|
974 |
'class' => "avatar avatar-{$size} photo",
|
975 |
);
|
976 |
+
|
977 |
+
$size = array( $size, $size );
|
|
|
|
|
|
|
978 |
|
979 |
$thumbnail = get_the_post_thumbnail( $guest_author->ID, $size, $args );
|
980 |
|
@@ -137,10 +137,10 @@ class CoAuthors_WP_List_Table extends WP_List_Table {
|
|
137 |
}
|
138 |
|
139 |
/**
|
140 |
-
* Either there are no
|
141 |
*/
|
142 |
function no_items() {
|
143 |
-
esc_html_e( 'No matching
|
144 |
}
|
145 |
|
146 |
/**
|
@@ -251,7 +251,10 @@ class CoAuthors_WP_List_Table extends WP_List_Table {
|
|
251 |
function column_posts( $item ) {
|
252 |
global $coauthors_plus;
|
253 |
$term = $coauthors_plus->get_author_term( $item );
|
254 |
-
|
|
|
|
|
|
|
255 |
$count = $term->count;
|
256 |
} else {
|
257 |
$count = 0;
|
137 |
}
|
138 |
|
139 |
/**
|
140 |
+
* Either there are no co-authors, or the search doesn't match any
|
141 |
*/
|
142 |
function no_items() {
|
143 |
+
esc_html_e( 'No matching co-authors were found.', 'co-authors-plus' );
|
144 |
}
|
145 |
|
146 |
/**
|
251 |
function column_posts( $item ) {
|
252 |
global $coauthors_plus;
|
253 |
$term = $coauthors_plus->get_author_term( $item );
|
254 |
+
$guest_term = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy );
|
255 |
+
if ( ! empty( $item->linked_account ) && $guest_term->count ) {
|
256 |
+
$count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID );
|
257 |
+
} elseif ( $term ) {
|
258 |
$count = $term->count;
|
259 |
} else {
|
260 |
$count = 0;
|
@@ -28,6 +28,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
28 |
$users = get_users();
|
29 |
$created = 0;
|
30 |
$skipped = 0;
|
|
|
31 |
foreach ( $users as $user ) {
|
32 |
|
33 |
$result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID );
|
@@ -36,12 +37,12 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
36 |
} else {
|
37 |
$created++;
|
38 |
}
|
|
|
39 |
}
|
40 |
-
|
41 |
WP_CLI::line( 'All done! Here are your results:' );
|
42 |
WP_CLI::line( "- {$created} guest author profiles were created" );
|
43 |
WP_CLI::line( "- {$skipped} users already had guest author profiles" );
|
44 |
-
|
45 |
}
|
46 |
|
47 |
/**
|
@@ -78,7 +79,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
78 |
|
79 |
$terms = cap_get_coauthor_terms_for_post( $single_post->ID );
|
80 |
if ( empty( $terms ) ) {
|
81 |
-
WP_CLI::
|
82 |
}
|
83 |
|
84 |
if ( ! empty( $terms ) ) {
|
@@ -115,7 +116,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
115 |
}
|
116 |
|
117 |
/**
|
118 |
-
* Subcommand to assign
|
119 |
*
|
120 |
* @since 3.0
|
121 |
*
|
@@ -248,8 +249,8 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
248 |
$coauthors_plus->add_coauthors( $post_id, array( $coauthor->user_login ) );
|
249 |
WP_CLI::line( sprintf( __( "Updating - Adding %s's byline to post #%d", 'co-authors-plus' ), $coauthor->user_login, $post_id ) );
|
250 |
$affected++;
|
251 |
-
if ( $affected && 0 === $affected %
|
252 |
-
sleep(
|
253 |
}
|
254 |
}
|
255 |
WP_CLI::success( sprintf( __( 'All done! %d posts were affected.', 'co-authors-plus' ), $affected ) );
|
@@ -408,8 +409,8 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
408 |
}
|
409 |
|
410 |
/**
|
411 |
-
* Swap one
|
412 |
-
* this leaves the original
|
413 |
*
|
414 |
* @subcommand swap-coauthors
|
415 |
* @synopsis --from=<user-login> --to=<user-login> [--post_type=<ptype>] [--dry=<dry>]
|
@@ -611,7 +612,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
611 |
}
|
612 |
|
613 |
/**
|
614 |
-
* Update the post count and description for each author
|
615 |
*
|
616 |
* @since 3.0
|
617 |
*
|
@@ -734,7 +735,7 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
|
|
734 |
}
|
735 |
|
736 |
if ( ! class_exists( 'WXR_Parser' ) ) {
|
737 |
-
require_once( WP_CONTENT_DIR . '/
|
738 |
}
|
739 |
|
740 |
$parser = new WXR_Parser();
|
28 |
$users = get_users();
|
29 |
$created = 0;
|
30 |
$skipped = 0;
|
31 |
+
$progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) );
|
32 |
foreach ( $users as $user ) {
|
33 |
|
34 |
$result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID );
|
37 |
} else {
|
38 |
$created++;
|
39 |
}
|
40 |
+
$progress->tick();
|
41 |
}
|
42 |
+
$progress->finish();
|
43 |
WP_CLI::line( 'All done! Here are your results:' );
|
44 |
WP_CLI::line( "- {$created} guest author profiles were created" );
|
45 |
WP_CLI::line( "- {$skipped} users already had guest author profiles" );
|
|
|
46 |
}
|
47 |
|
48 |
/**
|
79 |
|
80 |
$terms = cap_get_coauthor_terms_for_post( $single_post->ID );
|
81 |
if ( empty( $terms ) ) {
|
82 |
+
WP_CLI::line( sprintf( 'No co-authors found for post #%d.', $single_post->ID ) );
|
83 |
}
|
84 |
|
85 |
if ( ! empty( $terms ) ) {
|
116 |
}
|
117 |
|
118 |
/**
|
119 |
+
* Subcommand to assign co-authors to a post based on a given meta key
|
120 |
*
|
121 |
* @since 3.0
|
122 |
*
|
249 |
$coauthors_plus->add_coauthors( $post_id, array( $coauthor->user_login ) );
|
250 |
WP_CLI::line( sprintf( __( "Updating - Adding %s's byline to post #%d", 'co-authors-plus' ), $coauthor->user_login, $post_id ) );
|
251 |
$affected++;
|
252 |
+
if ( $affected && 0 === $affected % 100 ) {
|
253 |
+
sleep( 2 );
|
254 |
}
|
255 |
}
|
256 |
WP_CLI::success( sprintf( __( 'All done! %d posts were affected.', 'co-authors-plus' ), $affected ) );
|
409 |
}
|
410 |
|
411 |
/**
|
412 |
+
* Swap one co-author with another on all posts for which they are a co-author. Unlike rename-coauthor,
|
413 |
+
* this leaves the original co-author term intact and works when the 'to' user already has a co-author term.
|
414 |
*
|
415 |
* @subcommand swap-coauthors
|
416 |
* @synopsis --from=<user-login> --to=<user-login> [--post_type=<ptype>] [--dry=<dry>]
|
612 |
}
|
613 |
|
614 |
/**
|
615 |
+
* Update the post count and description for each author and guest author
|
616 |
*
|
617 |
* @since 3.0
|
618 |
*
|
735 |
}
|
736 |
|
737 |
if ( ! class_exists( 'WXR_Parser' ) ) {
|
738 |
+
require_once( WP_CONTENT_DIR . '/plugins/wordpress-importer/parsers.php' );
|
739 |
}
|
740 |
|
741 |
$parser = new WXR_Parser();
|
@@ -1,9 +1,9 @@
|
|
1 |
=== Co-Authors Plus ===
|
2 |
Contributors: batmoo, danielbachhuber, automattic
|
3 |
Tags: authors, users, multiple authors, coauthors, multi-author, publishing
|
4 |
-
Tested up to: 4.
|
5 |
Requires at least: 4.1
|
6 |
-
Stable tag: 3.
|
7 |
|
8 |
Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box
|
9 |
|
@@ -57,6 +57,43 @@ Bug fixes and minor enhancements
|
|
57 |
|
58 |
== Changelog ==
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
= 3.2.2 =
|
61 |
* Fix broken author ordering in 4.7+ (props mslinnea)
|
62 |
* Fix no moderation e-mail bug (props RobjS)
|
1 |
=== Co-Authors Plus ===
|
2 |
Contributors: batmoo, danielbachhuber, automattic
|
3 |
Tags: authors, users, multiple authors, coauthors, multi-author, publishing
|
4 |
+
Tested up to: 4.9.5
|
5 |
Requires at least: 4.1
|
6 |
+
Stable tag: 3.3.0
|
7 |
|
8 |
Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box
|
9 |
|
57 |
|
58 |
== Changelog ==
|
59 |
|
60 |
+
= 3.3.0 ("Rebecca") =
|
61 |
+
* Fix private post viewing on front-end
|
62 |
+
* Reduce amount of sleep
|
63 |
+
* Author search UX issues
|
64 |
+
* Remove associated guest user when mapped user id deleted.
|
65 |
+
* Removed double left join on posts_join_filter
|
66 |
+
* Fixed WP CLI create-terms-for-posts if no co-authors found
|
67 |
+
* Pages archive now displays coauthors and quick edit works
|
68 |
+
* Terminology updated throughout
|
69 |
+
* Replace hardcoded 'author' with $this->$coauthor_taxonomy
|
70 |
+
* Move parenthesis to fix esc_html and sprintf
|
71 |
+
* Added progress to create-guest-authors so users have an idea of how long it will take
|
72 |
+
* Deleting guest authors is less confusing
|
73 |
+
* Guest author's featured image is avatar now
|
74 |
+
* Removed extra image sizing
|
75 |
+
* Remove duplicated byline
|
76 |
+
* coauthors_wp_list_authors() has option to list only guest authors now
|
77 |
+
* remove duplicates from linked accounts on coauthors_wp_list_authors()
|
78 |
+
* Accurate Guest Author post count on linked accounts
|
79 |
+
* New README.md
|
80 |
+
* Filter author archive
|
81 |
+
* Fix coauthors_links_single()
|
82 |
+
* Added guest author hooks for create/delete
|
83 |
+
* Fixes logic for DOING_AUTOSAVE check
|
84 |
+
* user_login spaces problem when using add_coauthors
|
85 |
+
* Adding details of filter for slow performance
|
86 |
+
* Remove redundant test for 404 on Author Archive
|
87 |
+
* Guest Author Counts are more accurate
|
88 |
+
* Set $coauthors_loading
|
89 |
+
* Fix the issue where guest authors with non-ASCII characters can't be used as co-authors
|
90 |
+
* Fix the issue where incompatibility when `coauthors_auto_apply_template_tags` set to true
|
91 |
+
* Unit tests/Fix warnings for template tags
|
92 |
+
* Review and improve test coverage
|
93 |
+
* Update class-wp-cli.php
|
94 |
+
* Update .travis.yml file for PHPUnit tests
|
95 |
+
* Changes to resolve issue #332 about missing coauthor meta
|
96 |
+
|
97 |
= 3.2.2 =
|
98 |
* Fix broken author ordering in 4.7+ (props mslinnea)
|
99 |
* Fix no moderation e-mail bug (props RobjS)
|
@@ -35,6 +35,8 @@ function get_coauthors( $post_id = 0 ) {
|
|
35 |
}
|
36 |
} // the empty else case is because if we force guest authors, we don't ever care what value wp_posts.post_author has.
|
37 |
}
|
|
|
|
|
38 |
return $coauthors;
|
39 |
}
|
40 |
|
@@ -234,12 +236,33 @@ function coauthors( $between = null, $betweenLast = null, $before = null, $after
|
|
234 |
* @param bool $echo Whether the co-authors should be echoed or returned. Defaults to true.
|
235 |
*/
|
236 |
function coauthors_posts_links( $between = null, $betweenLast = null, $before = null, $after = null, $echo = true ) {
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
'betweenLast' => $betweenLast,
|
240 |
-
'before'
|
241 |
-
'after'
|
242 |
), null, $echo );
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
}
|
244 |
|
245 |
/**
|
@@ -343,12 +366,33 @@ function coauthors_nicknames( $between = null, $betweenLast = null, $before = nu
|
|
343 |
* @param bool $echo Whether the co-authors should be echoed or returned. Defaults to true.
|
344 |
*/
|
345 |
function coauthors_links( $between = null, $betweenLast = null, $before = null, $after = null, $echo = true ) {
|
346 |
-
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
'betweenLast' => $betweenLast,
|
349 |
-
'before'
|
350 |
-
'after'
|
351 |
), null, $echo );
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
}
|
353 |
|
354 |
/**
|
@@ -376,14 +420,24 @@ function coauthors_emails( $between = null, $betweenLast = null, $before = null,
|
|
376 |
* @return string
|
377 |
*/
|
378 |
function coauthors_links_single( $author ) {
|
379 |
-
if (
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
);
|
385 |
-
}
|
386 |
-
|
|
|
387 |
}
|
388 |
}
|
389 |
|
@@ -405,22 +459,64 @@ function coauthors_ids( $between = null, $betweenLast = null, $before = null, $a
|
|
405 |
), null, $echo );
|
406 |
}
|
407 |
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
}
|
420 |
|
|
|
421 |
function the_coauthor_meta( $field, $user_id = 0 ) {
|
422 |
-
|
423 |
-
|
|
|
|
|
|
|
424 |
}
|
425 |
|
426 |
/**
|
@@ -438,16 +534,17 @@ function coauthors_wp_list_authors( $args = array() ) {
|
|
438 |
global $coauthors_plus;
|
439 |
|
440 |
$defaults = array(
|
441 |
-
'optioncount'
|
442 |
-
'show_fullname'
|
443 |
-
'hide_empty'
|
444 |
-
'feed'
|
445 |
-
'feed_image'
|
446 |
-
'feed_type'
|
447 |
-
'echo'
|
448 |
-
'style'
|
449 |
-
'html'
|
450 |
-
'number'
|
|
|
451 |
);
|
452 |
|
453 |
$args = wp_parse_args( $args, $defaults );
|
@@ -459,6 +556,7 @@ function coauthors_wp_list_authors( $args = array() ) {
|
|
459 |
'number' => (int) $args['number'],
|
460 |
);
|
461 |
$author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args );
|
|
|
462 |
$authors = array();
|
463 |
foreach ( $author_terms as $author_term ) {
|
464 |
// Something's wrong in the state of Denmark
|
@@ -468,11 +566,23 @@ function coauthors_wp_list_authors( $args = array() ) {
|
|
468 |
|
469 |
$authors[ $author_term->name ] = $coauthor;
|
470 |
|
471 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
}
|
473 |
|
474 |
$authors = apply_filters( 'coauthors_wp_list_authors_array', $authors );
|
475 |
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
foreach ( (array) $authors as $author ) {
|
477 |
|
478 |
$link = '';
|
@@ -511,12 +621,16 @@ function coauthors_wp_list_authors( $args = array() ) {
|
|
511 |
if ( empty( $args['feed_image'] ) ) {
|
512 |
$link .= '(';
|
513 |
}
|
514 |
-
$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
|
|
|
|
|
|
|
515 |
|
516 |
if ( ! empty( $args['feed'] ) ) {
|
|
|
517 |
$title = ' title="' . esc_attr( $args['feed'] ) . '"';
|
518 |
-
$alt
|
519 |
-
$name
|
520 |
$link .= $title;
|
521 |
}
|
522 |
|
35 |
}
|
36 |
} // the empty else case is because if we force guest authors, we don't ever care what value wp_posts.post_author has.
|
37 |
}
|
38 |
+
// remove duplicate $coauthors objects from mapping user accounts to guest authors accounts
|
39 |
+
$coauthors = array_unique( $coauthors, SORT_REGULAR );
|
40 |
return $coauthors;
|
41 |
}
|
42 |
|
236 |
* @param bool $echo Whether the co-authors should be echoed or returned. Defaults to true.
|
237 |
*/
|
238 |
function coauthors_posts_links( $between = null, $betweenLast = null, $before = null, $after = null, $echo = true ) {
|
239 |
+
|
240 |
+
global $coauthors_plus_template_filters;
|
241 |
+
|
242 |
+
$modify_filter = ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters;
|
243 |
+
|
244 |
+
if ( $modify_filter ) {
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Removing "the_author" filter so that it won't get called in loop and append names for each author.
|
248 |
+
*
|
249 |
+
* Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279
|
250 |
+
*/
|
251 |
+
remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) );
|
252 |
+
}
|
253 |
+
|
254 |
+
$coauthors_posts_links = coauthors__echo( 'coauthors_posts_links_single', 'callback', array(
|
255 |
+
'between' => $between,
|
256 |
'betweenLast' => $betweenLast,
|
257 |
+
'before' => $before,
|
258 |
+
'after' => $after,
|
259 |
), null, $echo );
|
260 |
+
|
261 |
+
if ( $modify_filter ) {
|
262 |
+
add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) );
|
263 |
+
}
|
264 |
+
|
265 |
+
return $coauthors_posts_links;
|
266 |
}
|
267 |
|
268 |
/**
|
366 |
* @param bool $echo Whether the co-authors should be echoed or returned. Defaults to true.
|
367 |
*/
|
368 |
function coauthors_links( $between = null, $betweenLast = null, $before = null, $after = null, $echo = true ) {
|
369 |
+
|
370 |
+
global $coauthors_plus_template_filters;
|
371 |
+
|
372 |
+
$modify_filter = ! empty( $coauthors_plus_template_filters ) && $coauthors_plus_template_filters instanceof CoAuthors_Template_Filters;
|
373 |
+
|
374 |
+
if ( $modify_filter ) {
|
375 |
+
|
376 |
+
/**
|
377 |
+
* Removing "the_author" filter so that it won't get called in loop and append names for each author.
|
378 |
+
*
|
379 |
+
* Ref : https://github.com/Automattic/Co-Authors-Plus/issues/279
|
380 |
+
*/
|
381 |
+
remove_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) );
|
382 |
+
}
|
383 |
+
|
384 |
+
$coauthors_links = coauthors__echo( 'coauthors_links_single', 'callback', array(
|
385 |
+
'between' => $between,
|
386 |
'betweenLast' => $betweenLast,
|
387 |
+
'before' => $before,
|
388 |
+
'after' => $after,
|
389 |
), null, $echo );
|
390 |
+
|
391 |
+
if ( $modify_filter ) {
|
392 |
+
add_filter( 'the_author', array( $coauthors_plus_template_filters, 'filter_the_author' ) );
|
393 |
+
}
|
394 |
+
|
395 |
+
return $coauthors_links;
|
396 |
}
|
397 |
|
398 |
/**
|
420 |
* @return string
|
421 |
*/
|
422 |
function coauthors_links_single( $author ) {
|
423 |
+
if ( 'guest-author' === $author->type ) {
|
424 |
+
if ( get_the_author_meta( 'website' ) ) {
|
425 |
+
return sprintf( '<a href="%s" title="%s" rel="external" target="_blank">%s</a>',
|
426 |
+
esc_url( get_the_author_meta( 'website' ) ),
|
427 |
+
esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ),
|
428 |
+
esc_html( get_the_author() )
|
429 |
+
);
|
430 |
+
}
|
431 |
+
}
|
432 |
+
elseif ( get_the_author_meta( 'url' ) ) {
|
433 |
+
return sprintf( '<a href="%s" title="%s" rel="external" target="_blank">%s</a>',
|
434 |
+
esc_url( get_the_author_meta( 'url' ) ),
|
435 |
+
esc_attr( sprintf( __( 'Visit %s’s website' ), esc_html( get_the_author() ) ) ),
|
436 |
+
esc_html( get_the_author() )
|
437 |
);
|
438 |
+
}
|
439 |
+
else {
|
440 |
+
return esc_html( get_the_author() );
|
441 |
}
|
442 |
}
|
443 |
|
459 |
), null, $echo );
|
460 |
}
|
461 |
|
462 |
+
/**
|
463 |
+
* Outputs the co-authors Meta Data
|
464 |
+
*
|
465 |
+
* @param string $field Required The user field to retrieve.[login, email, nicename, display_name, url, type]
|
466 |
+
* @param string $user_id Optional The user ID for meta
|
467 |
+
*
|
468 |
+
* @return array $meta Value of the user field
|
469 |
+
*/
|
470 |
+
function get_the_coauthor_meta( $field, $user_id = false ) {
|
471 |
+
global $coauthors_plus;
|
472 |
+
|
473 |
+
if ( ! $user_id ) {
|
474 |
+
$coauthors = get_coauthors();
|
475 |
+
}
|
476 |
+
else {
|
477 |
+
$coauthor_data = $coauthors_plus->get_coauthor_by( 'id', $user_id );
|
478 |
+
$coauthors = array();
|
479 |
+
if ( ! empty( $coauthor_data ) ) {
|
480 |
+
$coauthors[] = $coauthor_data;
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
$meta = array();
|
485 |
+
|
486 |
+
if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) {
|
487 |
+
$field = 'user_' . $field;
|
488 |
+
}
|
489 |
+
|
490 |
+
foreach ( $coauthors as $coauthor ) {
|
491 |
+
$user_id = $coauthor->ID;
|
492 |
+
|
493 |
+
if ( isset( $coauthor->type ) && 'user_url' === $field ) {
|
494 |
+
if ( 'guest-author' === $coauthor->type ) {
|
495 |
+
$field = 'website';
|
496 |
+
}
|
497 |
+
}
|
498 |
+
else if ( 'website' === $field ) {
|
499 |
+
$field = 'user_url';
|
500 |
+
}
|
501 |
+
|
502 |
+
if ( isset( $coauthor->$field ) ) {
|
503 |
+
$meta[ $user_id ] = $coauthor->$field;
|
504 |
+
}
|
505 |
+
else {
|
506 |
+
$meta[ $user_id ] = '';
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
return $meta;
|
511 |
}
|
512 |
|
513 |
+
|
514 |
function the_coauthor_meta( $field, $user_id = 0 ) {
|
515 |
+
// TODO: need before after options
|
516 |
+
$coauthor_meta = get_the_coauthor_meta( $field, $user_id );
|
517 |
+
foreach ( $coauthor_meta as $meta ) {
|
518 |
+
echo esc_html( $meta );
|
519 |
+
}
|
520 |
}
|
521 |
|
522 |
/**
|
534 |
global $coauthors_plus;
|
535 |
|
536 |
$defaults = array(
|
537 |
+
'optioncount' => false,
|
538 |
+
'show_fullname' => false,
|
539 |
+
'hide_empty' => true,
|
540 |
+
'feed' => '',
|
541 |
+
'feed_image' => '',
|
542 |
+
'feed_type' => '',
|
543 |
+
'echo' => true,
|
544 |
+
'style' => 'list',
|
545 |
+
'html' => true,
|
546 |
+
'number' => 20, // A sane limit to start to avoid breaking all the things
|
547 |
+
'guest_authors_only' => false
|
548 |
);
|
549 |
|
550 |
$args = wp_parse_args( $args, $defaults );
|
556 |
'number' => (int) $args['number'],
|
557 |
);
|
558 |
$author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args );
|
559 |
+
|
560 |
$authors = array();
|
561 |
foreach ( $author_terms as $author_term ) {
|
562 |
// Something's wrong in the state of Denmark
|
566 |
|
567 |
$authors[ $author_term->name ] = $coauthor;
|
568 |
|
569 |
+
// only show guest authors if the $args is set to true
|
570 |
+
if ( ! $args['guest_authors_only'] || $authors[ $author_term->name ]->type === 'guest-author' ) {
|
571 |
+
$authors[ $author_term->name ]->post_count = $author_term->count;
|
572 |
+
}
|
573 |
+
else {
|
574 |
+
unset( $authors[ $author_term->name ] );
|
575 |
+
}
|
576 |
}
|
577 |
|
578 |
$authors = apply_filters( 'coauthors_wp_list_authors_array', $authors );
|
579 |
|
580 |
+
// remove duplicates from linked accounts
|
581 |
+
$linked_accounts = array_unique( array_column( $authors, 'linked_account' ) );
|
582 |
+
foreach ( $linked_accounts as $linked_account ) {
|
583 |
+
unset( $authors[$linked_account] );
|
584 |
+
}
|
585 |
+
|
586 |
foreach ( (array) $authors as $author ) {
|
587 |
|
588 |
$link = '';
|
621 |
if ( empty( $args['feed_image'] ) ) {
|
622 |
$link .= '(';
|
623 |
}
|
624 |
+
$link .= '<a href="' . esc_url( get_author_feed_link( $author->ID, $args['feed_type'] ) ) . '"';
|
625 |
+
|
626 |
+
$alt = '';
|
627 |
+
$title = '';
|
628 |
|
629 |
if ( ! empty( $args['feed'] ) ) {
|
630 |
+
|
631 |
$title = ' title="' . esc_attr( $args['feed'] ) . '"';
|
632 |
+
$alt = ' alt="' . esc_attr( $args['feed'] ) . '"';
|
633 |
+
$name = $args['feed'];
|
634 |
$link .= $title;
|
635 |
}
|
636 |
|
@@ -52,12 +52,6 @@ class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase {
|
|
52 |
$this->go_to( get_author_posts_url( $author1 ) );
|
53 |
$this->assertQueryTrue( 'is_author', 'is_archive' );
|
54 |
|
55 |
-
/**
|
56 |
-
* Author 2 is not yet an author on the blog
|
57 |
-
*/
|
58 |
-
$this->go_to( get_author_posts_url( $author2 ) );
|
59 |
-
$this->assertQueryTrue( 'is_404' );
|
60 |
-
|
61 |
// Add the user to the blog
|
62 |
add_user_to_blog( $blog2, $author2, 'author' );
|
63 |
|
@@ -93,7 +87,6 @@ class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase {
|
|
93 |
* Author 2 is no more
|
94 |
*/
|
95 |
$this->go_to( get_author_posts_url( $author2 ) );
|
96 |
-
$this->assertQueryTrue( 'is_404' );
|
97 |
$this->assertEquals( false, get_user_by( 'id', $author2 ) );
|
98 |
|
99 |
restore_current_blog();
|
52 |
$this->go_to( get_author_posts_url( $author1 ) );
|
53 |
$this->assertQueryTrue( 'is_author', 'is_archive' );
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
// Add the user to the blog
|
56 |
add_user_to_blog( $blog2, $author2, 'author' );
|
57 |
|
87 |
* Author 2 is no more
|
88 |
*/
|
89 |
$this->go_to( get_author_posts_url( $author2 ) );
|
|
|
90 |
$this->assertEquals( false, get_user_by( 'id', $author2 ) );
|
91 |
|
92 |
restore_current_blog();
|
@@ -0,0 +1,890 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Test_CoAuthors_Guest_Authors extends CoAuthorsPlus_TestCase {
|
4 |
+
|
5 |
+
public function setUp() {
|
6 |
+
|
7 |
+
parent::setUp();
|
8 |
+
|
9 |
+
$this->admin1 = $this->factory->user->create_and_get( array( 'role' => 'administrator', 'user_login' => 'admin1' ) );
|
10 |
+
$this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) );
|
11 |
+
$this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) );
|
12 |
+
|
13 |
+
$this->post = $this->factory->post->create_and_get( array(
|
14 |
+
'post_author' => $this->author1->ID,
|
15 |
+
'post_status' => 'publish',
|
16 |
+
'post_content' => rand_str(),
|
17 |
+
'post_title' => rand_str(),
|
18 |
+
'post_type' => 'post',
|
19 |
+
) );
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Checks a simulated WP_User object based on the post ID when key or value is empty.
|
24 |
+
*
|
25 |
+
* @covers CoAuthors_Guest_Authors::get_guest_author_by()
|
26 |
+
*/
|
27 |
+
public function test_get_guest_author_by_with_empty_key_or_value() {
|
28 |
+
|
29 |
+
global $coauthors_plus;
|
30 |
+
|
31 |
+
$guest_author_obj = $coauthors_plus->guest_authors;
|
32 |
+
|
33 |
+
// Fetch guest author without forcefully.
|
34 |
+
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', '' ) );
|
35 |
+
$this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', '' ) );
|
36 |
+
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', $this->author1->ID ) );
|
37 |
+
|
38 |
+
// Fetch guest author forcefully.
|
39 |
+
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', '', true ) );
|
40 |
+
$this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', '', true ) );
|
41 |
+
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', $this->author1->ID, true ) );
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Checks a simulated WP_User object based on the post ID using cache.
|
46 |
+
*
|
47 |
+
* @covers CoAuthors_Guest_Authors::get_guest_author_by()
|
48 |
+
*/
|
49 |
+
public function test_get_guest_author_by_using_cache() {
|
50 |
+
|
51 |
+
global $coauthors_plus;
|
52 |
+
|
53 |
+
$guest_author_obj = $coauthors_plus->guest_authors;
|
54 |
+
|
55 |
+
$guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
56 |
+
|
57 |
+
$cache_key = $guest_author_obj->get_cache_key( 'ID', $guest_author_id );
|
58 |
+
|
59 |
+
// Checks when guest author does not exist in cache.
|
60 |
+
$this->assertFalse( wp_cache_get( $cache_key, $guest_author_obj::$cache_group ) );
|
61 |
+
|
62 |
+
// Checks when guest author exists in cache.
|
63 |
+
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
64 |
+
$guest_author_cached = wp_cache_get( $cache_key, $guest_author_obj::$cache_group );
|
65 |
+
|
66 |
+
$this->assertInstanceOf( stdClass::class, $guest_author );
|
67 |
+
$this->assertEquals( $guest_author, $guest_author_cached );
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Checks a simulated WP_User object based on the post ID using different key/value.
|
72 |
+
*
|
73 |
+
* @covers CoAuthors_Guest_Authors::get_guest_author_by()
|
74 |
+
*/
|
75 |
+
public function test_get_guest_author_by_with_different_keys() {
|
76 |
+
|
77 |
+
global $coauthors_plus;
|
78 |
+
|
79 |
+
$guest_author_obj = $coauthors_plus->guest_authors;
|
80 |
+
|
81 |
+
// Checks when user is not a guest author.
|