Skip to content

Commit fa97678

Browse files
committed
Add get_post_authors and get_archive_author replacing get_multiple_authors
Fix issue publishpress#593 where secondary authors were dropped from the first post of an author displayed on its author page. After visiting the author page the post author was reset to only the first author. The function get_multiple_authors is deprecated now, and was replaced by two new functions: get_post_authors, which returns the list of authors of a post (similar behavior when $archive was false). get_archive_author, which returns the author of the current author page if on an author archive page. If not, returns false. It returns similar result as the $archive argument was true.
1 parent 4b228f5 commit fa97678

29 files changed

+735
-148
lines changed

publishpress-authors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function wp_notify_postauthor($comment_id, $comment_type = '')
7979
{
8080
$comment = get_comment($comment_id);
8181
$post = get_post($comment->comment_post_ID);
82-
$coauthors = get_multiple_authors($post->ID);
82+
$coauthors = get_post_authors($post->ID);
8383
foreach ($coauthors as $author) {
8484
// The comment was left by the co-author
8585
if ($comment->user_id == $author->ID) {

src/core/Classes/Authors_Iterator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public function __construct($postID = 0, $archive = false)
6363
}
6464

6565
$this->original_authordata = $this->current_author = $authordata;
66-
$this->authordata_array = get_multiple_authors($postID, true, $archive);
66+
if ($archive) {
67+
$this->authordata_array = [get_archive_author()];
68+
} else {
69+
$this->authordata_array = get_post_authors($postID, $archive);
70+
}
6771

6872
$this->count = count($this->authordata_array);
6973
}

src/core/Classes/Content_Model.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static function filter_author_link($link, $author_id)
120120
public static function filter_author_display_name($author_meta, $user_id)
121121
{
122122
if (empty($author_meta) && empty($user_id)) {
123-
$authors = get_multiple_authors();
123+
$authors = get_post_authors();
124124

125125
if (!empty($authors)) {
126126
// Even for multiple authors, if not specified one, we will always get the first author.
@@ -199,7 +199,7 @@ public static function action_parse_request($query)
199199

200200
public static function filter_ma_get_author_data($data, $field, $post)
201201
{
202-
$authors = get_multiple_authors($post);
202+
$authors = get_post_authors($post);
203203

204204
if (empty($authors)) {
205205
return $data;

src/core/Classes/Post_Editor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static function action_manage_posts_custom_column($column, $post_id)
106106
if ('authors' === $column) {
107107
// We need to ignore the cache for following call when this method were called after saved the post in a
108108
// quick edit operation, otherwise the authors column will show old values.
109-
$authors = get_multiple_authors($post_id, false, false, true);
109+
$authors = get_post_authors($post_id, true);
110110

111111
$post_type = get_post_type($post_id);
112112
$post = get_post($post_id);
@@ -207,7 +207,7 @@ public static function render_authors_metabox()
207207
return;
208208
}
209209

210-
$authors = get_multiple_authors();
210+
$authors = get_post_authors();
211211

212212
echo self::get_rendered_authors_selection($authors, false); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
213213
}

src/core/Classes/Utils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ public static function isTheSEOFrameworkInstalled()
774774

775775
public static function isAuthorOfPost($postId, $author)
776776
{
777-
$postAuthors = get_multiple_authors($postId);
777+
$postAuthors = get_post_authors($postId);
778778
if (empty($postAuthors)) {
779779
return false;
780780
}

src/core/Plugin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ public function add_coauthors($post_id, $coauthors, $append = false)
860860

861861
// Best way to persist order
862862
if ($append) {
863-
$existing_coauthors = wp_list_pluck(get_multiple_authors($post_id), 'user_login');
863+
$existing_coauthors = wp_list_pluck(get_post_authors($post_id), 'user_login');
864864
} else {
865865
$existing_coauthors = [];
866866
}
@@ -1157,7 +1157,7 @@ public function filter_the_author($authorDisplayName)
11571157
! defined('PUBLISHPRESS_AUTHORS_DISABLE_FILTER_THE_AUTHOR')
11581158
|| PUBLISHPRESS_AUTHORS_DISABLE_FILTER_THE_AUTHOR !== true
11591159
) {
1160-
$authors = get_multiple_authors(get_post());
1160+
$authors = get_post_authors(get_post());
11611161
if (! empty($authors) && isset($authors[0]) && isset($authors[0]->display_name)) {
11621162
return $authors[0]->display_name;
11631163
}
@@ -1530,7 +1530,7 @@ public function filter_jetpack_open_graph_tags($og_tags, $image_dimensions)
15301530
}
15311531
} else {
15321532
if (is_singular() && Utils::is_post_type_enabled()) {
1533-
$authors = get_multiple_authors();
1533+
$authors = get_post_authors();
15341534
if (!empty($authors)) {
15351535
$author = array_shift($authors);
15361536
if (isset($og_tags['article:author'])) {

src/core/Traits/Author_box.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ protected function get_author_box_markup(
134134
$post = $this->postCache[$post_id];
135135
}
136136

137-
$authorsList = get_multiple_authors($post_id, true, $archive);
137+
if ($archive) {
138+
$authorsList = [get_archive_author()];
139+
} else {
140+
$authorsList = get_post_authors($post_id, true, $archive);
141+
}
138142

139143
$this->authorsCount = count($authorsList);
140144

src/core/WP_Cli.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function assign_author_by_meta_key($args, $assocArgs)
148148

149149
// See if the value in the post meta field is the same as any of the existing coauthors
150150
$originalAuthor = get_post_meta($singlePost->ID, $this->args['meta_key'], true);
151-
$existingCoauthors = get_multiple_authors($singlePost->ID);
151+
$existingCoauthors = get_post_authors($singlePost->ID);
152152
$isAlreadyAssociated = false;
153153
foreach ($existingCoauthors as $existingCoauthor) {
154154
if ($originalAuthor == $existingCoauthor->user_nicename) {

src/functions/amp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function cap_add_amp_actions()
1111

1212
function cap_update_amp_json_metadata($metadata, $post)
1313
{
14-
$authors = get_multiple_authors($post->ID);
14+
$authors = get_post_authors($post->ID);
1515

1616
$authors_json = [];
1717
foreach ($authors as $author) {

src/functions/amp/meta-author.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php $coauthors = get_multiple_authors($this->get('post_id')); ?>
1+
<?php $coauthors = get_post_authors($this->get('post_id')); ?>
22
<li class="amp-wp-byline">
33
<?php multiple_authors(); ?>
44
</li>

src/functions/bylines-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
function get_bylines($post = null)
1919
{
20-
return get_multiple_authors($post);
20+
return get_post_authors($post);
2121
}
2222
}
2323

src/functions/coauthors-functions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if (!function_exists('get_coauthors')) {
1313
function get_coauthors($post_id = 0)
1414
{
15-
return get_multiple_authors($post_id);
15+
return get_post_authors($post_id);
1616
}
1717
}
1818

@@ -155,7 +155,7 @@ function cap_filter_comment_moderation_email_recipients($recipients, $comment_id
155155
$post_id = $comment->comment_post_ID;
156156

157157
if (isset($post_id)) {
158-
$coauthors = get_multiple_authors($post_id);
158+
$coauthors = get_post_authors($post_id);
159159
$extra_recipients = [];
160160
foreach ($coauthors as $user) {
161161
if (!empty($user->user_email)) {

0 commit comments

Comments
 (0)