Skip to content

Commit

Permalink
Merge pull request #451 from publishpress/release-v3.14.0
Browse files Browse the repository at this point in the history
Release v3.14.0
  • Loading branch information
andergmartins authored May 27, 2021
2 parents ca51d0a + e44d1e0 commit 369f0fb
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 227 deletions.
429 changes: 220 additions & 209 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
defined('ABSPATH') or die('No direct script access allowed.');

if (!defined('PP_AUTHORS_VERSION')) {
define('PP_AUTHORS_VERSION', '3.13.1');
define('PP_AUTHORS_VERSION', '3.14.0');
define('PP_AUTHORS_FILE', 'publishpress-authors/publishpress-authors.php');
define('PP_AUTHORS_BASE_PATH', plugin_dir_path(__DIR__ . '/publishpress-authors.php'));
define('PP_AUTHORS_MODULES_PATH', PP_AUTHORS_BASE_PATH . 'src/modules/');
Expand All @@ -26,6 +26,10 @@
define('PUBLISHPRESS_AUTHORS_LOAD_DEPRECATED_LEGACY_CODE', true);
}

if (!defined('PUBLISHPRESS_AUTHORS_LOAD_LEGACY_SHORTCODES')) {
define('PUBLISHPRESS_AUTHORS_LOAD_LEGACY_SHORTCODES', true);
}

if (!defined('PUBLISHPRESS_AUTHORS_LOAD_COAUTHORS_FUNCTIONS')) {
define('PUBLISHPRESS_AUTHORS_LOAD_COAUTHORS_FUNCTIONS', true);
}
Expand Down
2 changes: 1 addition & 1 deletion publishpress-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: PublishPress Authors allows you to add multiple authors and guest authors to WordPress posts
* Author: PublishPress
* Author URI: https://publishpress.com
* Version: 3.13.1
* Version: 3.14.0
* Text Domain: publishpress-authors
*
* ------------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tags: multiple authors, authors, guest authors, author fields, author layouts
Requires at least: 4.7
Requires PHP: 5.6
Tested up to: 5.7
Stable tag: 3.13.1
Stable tag: 3.14.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -114,6 +114,15 @@ There are two ways to install the PublishPress Authors plugin:

== Changelog ==

= [3.14.0] - 2021-05-26 =

* Added: Added new setting for selecting multiple post types to display in the author page, #436;
* Added: Added new function "get_by_id" to the Author class, accepting positive integer for User ID, and negative integer for term ID, #423;
* Changed: Shortcode [author_box] was renamed to [publishpress_authors_box], #426;
* Changed: Shortcode [ppma_test] was renamed to [publishpress_authors_test], #426;
* Changed: Legacy shortcodes are loaded by default, but defining the constant PUBLISHPRESS_AUTHORS_LOAD_LEGACY_SHORTCODES = false will prevent to load them, #426;
* Fixed: Fix the Author::get_avatar_url method returning the avatar URL, #443;

= [3.13.1] - 2021-04-22 =

* Fixed: Fix the color scheme for the Pro plugin, #411;
Expand Down
23 changes: 19 additions & 4 deletions src/core/Classes/Objects/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,7 @@ public function __get($attribute)
$return = false;
}

$return = apply_filters('publishpress_authors_author_attribute', $return, $this->term_id, $attribute);

return $return;
return apply_filters('publishpress_authors_author_attribute', $return, $this->term_id, $attribute, $this);
}

/**
Expand All @@ -497,7 +495,7 @@ public function __get($attribute)
*/
public function get_avatar_url($size = 96)
{
if (!is_null($this->avatarUrl)) {
if (is_null($this->avatarUrl)) {
if ($this->has_custom_avatar()) {
$url = $this->get_custom_avatar_url($size);
} else {
Expand Down Expand Up @@ -749,4 +747,21 @@ public static function get_by_email($emailAddress)

return isset(self::$authorsByEmailCache[$emailAddress]) ? self::$authorsByEmailCache[$emailAddress] : false;
}

/**
* Get an author by the provided ID.
*
* This ID can either be the WP_User ID (positive integer) or guest author ID (negative integer).
*
* @param $id
*
* @return Author|false
*/
public static function get_by_id( $id ) {
if ( intval( $id ) > -1 ) {
return self::get_by_user_id( $id );
}
return self::get_by_term_id( $id );
}

}
56 changes: 52 additions & 4 deletions src/core/Classes/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace MultipleAuthors\Classes;

use MultipleAuthors\Classes\Objects\Author;
use MultipleAuthors\Factory;

/**
* Modifications to the main query, and helper query methods
Expand All @@ -36,7 +37,7 @@ public static function fix_query_pre_get_posts($wp_query)
global $wp_query;
}

if (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === 'ppmacf_field') {
if (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === 'ppmacf_field') {
return;
}

Expand Down Expand Up @@ -86,7 +87,7 @@ public static function fix_query_pre_get_posts($wp_query)
*
* @return string
*/
public static function filter_posts_where($where, $query)
public static function filter_author_posts_where($where, $query)
{
global $wpdb;

Expand Down Expand Up @@ -144,7 +145,9 @@ public static function filter_posts_where($where, $query)
-1
);

return $where;
$where = static::add_custom_post_types_to_query($where);

return apply_filters('publishpress_authors_filter_posts_list_where', $where, $query, $term);
}

/**
Expand Down Expand Up @@ -211,7 +214,7 @@ public static function filter_posts_groupby($groupby, $query)
*
* @return string
*/
public static function filter_posts_list_where($where, $query)
public static function filter_admin_posts_list_where($where, $query)
{
global $wpdb;

Expand Down Expand Up @@ -251,6 +254,51 @@ public static function filter_posts_list_where($where, $query)
-1
);

return apply_filters('publishpress_authors_filter_posts_list_where', $where, $query, $author);
}

public static function getSelectedPostTypesForAuthorsPage()
{
$legacyPlugin = Factory::getLegacyPlugin();
$moduleOptions = $legacyPlugin->multiple_authors->module->options;

$enabledPostTypes = Utils::get_enabled_post_types();
$selectedPostTypesForAuthorsPage = apply_filters('publishpress_authors_posts_query_post_types', []);

if (empty($selectedPostTypesForAuthorsPage)) {
foreach ($moduleOptions->author_page_post_types as $postType => $status) {
if ($status !== 'on') {
continue;
}

if (in_array($postType, $enabledPostTypes)) {
$selectedPostTypesForAuthorsPage[] = esc_sql($postType);
}
}

return $selectedPostTypesForAuthorsPage;
}

return [];
}

private static function add_custom_post_types_to_query($where)
{
$legacyPlugin = Factory::getLegacyPlugin();
$moduleOptions = $legacyPlugin->multiple_authors->module->options;

if (!isset($moduleOptions->author_page_post_types)) {
return $where;
}

$selectedPostTypesForAuthorsPage = static::getSelectedPostTypesForAuthorsPage();

if (!empty($selectedPostTypesForAuthorsPage)) {
$postTypesString = implode('\', \'', $selectedPostTypesForAuthorsPage);

return str_replace(".post_type = 'post'", ".post_type IN ('" . $postTypesString . "')", $where);
}

return $where;
}

Expand Down
20 changes: 13 additions & 7 deletions src/core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ public function __construct()
// Author box to the content
add_filter('the_content', [$this, 'filter_the_content']);

// Shortcodes
add_shortcode('author_box', [$this, 'shortcode_author_box']);
/**
* @deprecated Since 3.13.2. Use publishpress_authors_box instead.
*/
if (PUBLISHPRESS_AUTHORS_LOAD_LEGACY_SHORTCODES) {
add_shortcode('author_box', [$this, 'shortcodeAuthorsBox']);
}

add_shortcode('publishpress_authors_box', [$this, 'shortcodeAuthorsBox']);

// Action to display the author box
add_action('pp_multiple_authors_show_author_box', [$this, 'action_echo_author_box'], 10, 5);
Expand Down Expand Up @@ -253,7 +259,7 @@ public function __construct()
);
add_filter(
'posts_where',
['MultipleAuthors\\Classes\\Query', 'filter_posts_where'],
['MultipleAuthors\\Classes\\Query', 'filter_author_posts_where'],
10,
2
);
Expand Down Expand Up @@ -284,7 +290,7 @@ public function __construct()
// Query modifications for the admin posts lists
add_filter(
'posts_where',
['MultipleAuthors\\Classes\\Query', 'filter_posts_list_where'],
['MultipleAuthors\\Classes\\Query', 'filter_admin_posts_list_where'],
10,
2
);
Expand Down Expand Up @@ -372,10 +378,10 @@ public function __construct()

private function addTestShortcode()
{
add_shortcode('ppma_test', [$this, 'ppma_test']);
add_shortcode('publishpress_authors_test', [$this, 'shortcodeTest']);
}

public function ppma_test()
public function shortcodeTest()
{
echo '<b>PublishPress Authors:</b> shortcode rendered successfully!';
}
Expand Down Expand Up @@ -1633,7 +1639,7 @@ public function filter_the_content($content)
*
* @return string
*/
public function shortcode_author_box($attributes)
public function shortcodeAuthorsBox($attributes)
{
$show_title = true;
$layout = null;
Expand Down
58 changes: 58 additions & 0 deletions src/modules/multiple-authors/multiple-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function __construct()
'force_empty_author' => 'no',
'username_in_search_field' => 'no',
'default_author_for_new_posts' => null,
'author_page_post_types' => [],
],
'options_page' => false,
'autoload' => true,
Expand Down Expand Up @@ -460,6 +461,14 @@ public function register_settings()
$this->module->options_group_name . '_general'
);

add_settings_field(
'author_page_post_types',
__('Post types to display on the author\'s profile page:', 'publishpress-authors'),
[$this, 'settings_author_page_post_types_option'],
$this->module->options_group_name,
$this->module->options_group_name . '_general'
);

add_settings_field(
'author_for_new_users',
__(
Expand Down Expand Up @@ -602,6 +611,51 @@ public function settings_post_types_option()
$legacyPlugin->settings->helper_option_custom_post_type($this->module);
}

public function settings_author_page_post_types_option()
{
$post_types = [
'post' => __('Posts'),
'page' => __('Pages'),
];
$custom_post_types = $this->get_supported_post_types_for_module();
if (count($custom_post_types)) {
foreach ($custom_post_types as $custom_post_type => $args) {
$post_types[$custom_post_type] = $args->label;
}
}

$checkedOption = is_array($this->module->options->author_page_post_types) ?
array_filter(
$this->module->options->author_page_post_types,
function ($value, $key) {
return $value === 'on';
},
ARRAY_FILTER_USE_BOTH
)
: false;

$checkPostByDefault = empty($checkedOption);

foreach ($post_types as $post_type => $title) {
echo '<label for="author_page_post_type_' . esc_attr($post_type) . '-' . $this->module->slug . '">';
echo '<input id="author_page_post_type_' . esc_attr($post_type) . '-' . $this->module->slug . '" name="'
. $this->module->options_group_name . '[author_page_post_types][' . esc_attr($post_type) . ']"';

if (isset($this->module->options->author_page_post_types[$post_type]) || ($checkPostByDefault && $post_type === 'post')) {
checked($this->module->options->author_page_post_types[$post_type], 'on');
}

// Defining post_type_supports in the functions.php file or similar should disable the checkbox
disabled(post_type_supports($post_type, $this->module->post_type_support), true);
echo ' type="checkbox" value="on" />&nbsp;&nbsp;&nbsp;' . esc_html($title) . '</label>';
// Leave a note to the admin as a reminder that add_post_type_support has been used somewhere in their code
if (post_type_supports($post_type, $this->module->post_type_support)) {
echo '&nbsp&nbsp;&nbsp;<span class="description">' . sprintf(__('Disabled because add_post_type_support(\'%1$s\', \'%2$s\') is included in a loaded file.', 'publishpress-authors'), $post_type, $this->module->post_type_support) . '</span>';
}
echo '<br />';
}
}

/**
* Displays the field to choose display or not the author box at the
* end of the content
Expand Down Expand Up @@ -978,6 +1032,10 @@ public function validate_module_settings($new_options, $module_name)
}
}

if (!isset($new_options['author_page_post_types']) || empty($new_options['author_page_post_types'])) {
$new_options['author_page_post_types'] = ['post' => 'on'];
}

/**
* @param array $newOptions
* @param string $moduleName
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/core/Classes/Objects/AuthorCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,23 @@ public function tryToGetSlugForGuestAuthors(WpunitTester $I)
$author->slug
);
}

public function tryToGetAvatarURLWithoutCustomAvatar(WpunitTester $I)
{
$authorSlug = sprintf('guest_author_%d', rand(1, PHP_INT_MAX));
$author = Author::create(
[
'slug' => $authorSlug,
'display_name' => strtoupper($authorSlug),
]
);

$avatarUrl = $author->get_avatar_url();

$I->assertFalse(is_null($avatarUrl), 'The avatar URL should not be null');
$I->assertRegExp(
'#http[s]?://[0-9]{1,2}\.gravatar\.com/avatar/\?s=96&d=mm&r=g#',
$avatarUrl
);
}
}

0 comments on commit 369f0fb

Please sign in to comment.