Skip to content

Commit bc28c23

Browse files
committed
- Extend [publishpress_authors_data] shortcode to return authors user object publishpress#697
1 parent 49a83a3 commit bc28c23

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/core/Plugin.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -1753,9 +1753,10 @@ public function shortcodeAuthorsBox($attributes)
17531753
*/
17541754
public function shortcodeAuthorsData($attributes)
17551755
{
1756-
$field = 'display_name';
1757-
$post_id = false;
1758-
$separator = ',';
1756+
$field = 'display_name';
1757+
$post_id = false;
1758+
$separator = ',';
1759+
$user_objects = false;
17591760

17601761

17611762
if (isset($attributes['post_id'])) {
@@ -1772,7 +1773,11 @@ public function shortcodeAuthorsData($attributes)
17721773
$field = $attributes['field'];
17731774
}
17741775

1775-
return $this->get_authors_data($post_id, $field, $separator);
1776+
if (isset($attributes['user_objects'])) {
1777+
$user_objects = $attributes['user_objects'] === 'true' || (int)$attributes['user_objects'] === 1;
1778+
}
1779+
1780+
return $this->get_authors_data($post_id, $field, $separator, $user_objects);
17761781
}
17771782

17781783
/**

src/core/Traits/Author_box.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,15 @@ protected function get_author_box_markup(
270270
* @param int $post_id
271271
* @param string $field
272272
* @param mixed $separator
273+
* @param mixed $user_objects
273274
*
274275
* @return string
275276
*/
276277
protected function get_authors_data(
277278
$post_id = false,
278279
$field = 'display_name',
279-
$separator = ','
280+
$separator = ',',
281+
$user_objects = false
280282
) {
281283
global $post;
282284

@@ -294,13 +296,16 @@ protected function get_authors_data(
294296

295297
$authors = get_post_authors($post_id, true, false);
296298

297-
if (!empty($authors)) {
298-
foreach ($authors as $author) {
299-
$author = Author::get_by_term_id($author->term_id);
300-
$output[] = isset($author->$field) ? $author->$field : $author->display_name;
299+
if (!$user_objects) {
300+
if (!empty($authors)) {
301+
foreach ($authors as $author) {
302+
$output[] = isset($author->$field) ? $author->$field : $author->display_name;
303+
}
301304
}
305+
$output = array_filter($output);
306+
$authors = join($separator, $output);
302307
}
303308

304-
return join($separator, $output);
309+
return $authors;
305310
}
306311
}

src/modules/multiple-authors/multiple-authors.php

+12
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,18 @@ private function settings_ppma_shortcodes($shortcodes = []) {
901901
'publishpress-authors'
902902
),
903903
],
904+
'option_5' => [
905+
'shortcode' => '[publishpress_authors_data user_objects="true"]',
906+
'description' => sprintf(
907+
esc_html__(
908+
'You can also decide to return array lists of authors for custom use or formatting by using %1s which will return all authors object data as array. You can check full details and sample usage %2s in this guide %3s',
909+
'publishpress-authors'
910+
),
911+
'<code class="color-red">user_objects="true"</code>',
912+
'<a href="https://publishpress.com/knowledge-base/authors-data-backup/">',
913+
'</a>'
914+
),
915+
],
904916
],
905917
];
906918

0 commit comments

Comments
 (0)