Skip to content

Commit

Permalink
Merge pull request #723 from publishpress/release-v3.18.0
Browse files Browse the repository at this point in the history
Release v3.18.0
  • Loading branch information
ojopaul authored Jun 13, 2022
2 parents 0097308 + b2aff77 commit e8f3c89
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 145 deletions.
211 changes: 111 additions & 100 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 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_LOADED')) {
define('PP_AUTHORS_VERSION', '3.17.0');
define('PP_AUTHORS_VERSION', '3.18.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 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.17.0
* Version: 3.18.0
* Text Domain: publishpress-authors
*
* ------------------------------------------------------------------------------
Expand Down
15 changes: 14 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: 6.0
Stable tag: 3.17.0
Stable tag: 3.18.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

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

== Changelog ==

= [3.18.0] - 13 Jun 2022 =

* Fixed: Allow authors to have the same name, #682
* Added: Extend [publishpress_authors_data] shortcode to return authors user object, #697
* Fixed: Search box doesn't accept ' characters in username, #699
* Added: Add Authors important menu link to plugin row, #714
* Fixed: Author menu missing in admin menus, #715
* Fixed: PHP 7.2 compability, #711
* Added: Add [publishpress_authors_list] shortcode to the Free version, #706
* Fixed: Most important buttons should be yellow only, #704
* Fixed: Author Box shortcode is in the wrong place, #695
* Fixed: Small typo in shortcode, #693

= [3.17.0] - 30 May 2022 =

* Added: Option to enable/disable loading font awesome assets in frontend, #625
Expand Down
19 changes: 0 additions & 19 deletions src/assets/css/pressshack-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,6 @@
border-style: solid;
}

.pressshack-admin-wrapper .button-primary {
background-color: #FFB300;
border-color: #C58C07;
color: #754D26;
}

.pressshack-admin-wrapper .button-primary:hover,
.pressshack-admin-wrapper .button-primary:active,
.pressshack-admin-wrapper .button-primary:focus {
background-color: #F3AC04;
border-color: #C58C07;
color: #333;
outline: none;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
-o-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
}

.pressshack-admin-wrapper .button:not(.notice-dismiss):hover,
.pressshack-admin-wrapper .button:not(.notice-dismiss):active,
.pressshack-admin-wrapper .button:not(.notice-dismiss):focus {
Expand Down
35 changes: 35 additions & 0 deletions src/assets/js/multiple-authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,41 @@ jQuery(document).ready(function ($) {

});

//change submit button to enable slug generation on custom button click
if ($('body.taxonomy-author form#addtag #submit').length > 0) {
$('body.taxonomy-author form#addtag #submit').hide();
$('body.taxonomy-author form#addtag #submit').after('<input type="button" id="author-submit" class="button button-primary" value="' + $('body.taxonomy-author form#addtag #submit').val() + '">');
}

//generate author slug when adding author.
$(document).on('click', 'body.taxonomy-author form#addtag #author-submit', function (event) {

var $authorName = $('input[name="tag-name"]').val();
var $form = $(this).closest('form#addtag');

event.preventDefault();

//prepare ajax data
var data = {
action: "handle_author_slug_generation",
author_name: $authorName,
nonce: MultipleAuthorsStrings.generate_author_slug_nonce,
};

$form.find('.spinner').addClass('is-active');

$.post(ajaxurl, data, function (response) {
$form.find('.spinner').removeClass('is-active');
if (response.author_slug) {
$('input[name="slug"]').val(response.author_slug);
$('body.taxonomy-author form#addtag #submit').trigger('click');
} else {
$('body.taxonomy-author form#addtag #submit').trigger('click');
}
});

});

/**
* Settings shortcode copy to clipboard
*/
Expand Down
43 changes: 43 additions & 0 deletions src/core/Classes/Admin_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public static function get_possible_authors_for_search($search, $ignored = [], $
];

if (!empty($search)) {
$search = str_replace(['\"', "\'"], '', $search);
$term_args['search'] = $search;
}

Expand Down Expand Up @@ -315,4 +316,46 @@ public static function handle_mapped_author_validation()
wp_send_json($response);
exit;
}

/**
* Handle a request to generate author slug.
*/
public static function handle_author_slug_generation()
{

$response['status'] = 'success';
$response['content'] = esc_html__('Request status.', 'publishpress-authors');

//do not process request if nonce validation failed
if (empty($_POST['nonce'])
|| !wp_verify_nonce(sanitize_key($_POST['nonce']), 'generate_author_slug_nonce')
) {
$response['status'] = 'error';
$response['content'] = esc_html__(
'Security error. Kindly reload this page and try again',
'publishpress-authors'
);
} elseif (empty($_POST['author_name'])) {
$response['status'] = 'error';
$response['content'] = esc_html__('Author name is required', 'publishpress-authors');
} else {
$author_slug = !empty($_POST['author_name']) ? sanitize_title($_POST['author_name']) : '';
$generated_slug = $author_slug;
$generated_slug_n = '';

$new_slug = $generated_slug;
while (get_term_by('slug', $new_slug, 'author')) {
if ($generated_slug_n == '') {
$generated_slug_n = 1;
} else {
$generated_slug_n++;
}
$new_slug = $generated_slug .'-' . $generated_slug_n;
}
$response['author_slug'] = $new_slug;
}

wp_send_json($response);
exit;
}
}
40 changes: 34 additions & 6 deletions src/core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function __construct()

add_shortcode('publishpress_authors_box', [$this, 'shortcodeAuthorsBox']);
add_shortcode('publishpress_authors_data', [$this, 'shortcodeAuthorsData']);
add_shortcode('publishpress_authors_list', [$this, 'shortcodeAuthorsList']);

// 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 @@ -270,6 +271,10 @@ public function __construct()
'wp_ajax_mapped_author_validation',
['MultipleAuthors\\Classes\\Admin_Ajax', 'handle_mapped_author_validation']
);
add_action(
'wp_ajax_handle_author_slug_generation',
['MultipleAuthors\\Classes\\Admin_Ajax', 'handle_author_slug_generation']
);

add_filter('admin_footer_text', [$this, 'update_footer_admin']);
}
Expand Down Expand Up @@ -1456,6 +1461,7 @@ public function enqueue_scripts($hook_suffix)
'publishpress-authors'
),
'mapped_author_nonce' => wp_create_nonce("mapped_author_nonce"),
'generate_author_slug_nonce' => wp_create_nonce("generate_author_slug_nonce"),
'term_author_link' => esc_url_raw($term_author_link),
'view_text' => esc_html__('View', 'publishpress-authors'),
];
Expand Down Expand Up @@ -1744,6 +1750,21 @@ public function shortcodeAuthorsBox($attributes)
return $this->get_author_box_markup('shortcode', $show_title, $layout, $archive, $post_id);
}

public function shortcodeAuthorsList($attributes)
{
$widget = new Authors_Widget('authors_list_shortcode', 'authors_list_shortcode');

$defaults = [
'show_title' => true
];

$attributes = wp_parse_args($attributes, $defaults);

ob_start();
$widget->widget([], $attributes);
return ob_get_clean();
}

/**
* Shortcode to get the authors data
*
Expand All @@ -1753,24 +1774,31 @@ public function shortcodeAuthorsBox($attributes)
*/
public function shortcodeAuthorsData($attributes)
{
$field = 'display_name';
$post_id = false;
$seperator = ',';
$field = 'display_name';
$post_id = false;
$separator = ',';
$user_objects = false;


if (isset($attributes['post_id'])) {
$post_id = $attributes['post_id'];
}

if (isset($attributes['seperator'])) {
$seperator = $attributes['seperator'];
if (isset($attributes['separator'])) {
$separator = $attributes['separator'];
} elseif (isset($attributes['seperator'])) {
$separator = $attributes['seperator'];
}

if (isset($attributes['field'])) {
$field = $attributes['field'];
}

return $this->get_authors_data($post_id, $field, $seperator);
if (isset($attributes['user_objects'])) {
$user_objects = $attributes['user_objects'] === 'true' || (int)$attributes['user_objects'] === 1;
}

return $this->get_authors_data($post_id, $field, $separator, $user_objects);
}

/**
Expand Down
19 changes: 12 additions & 7 deletions src/core/Traits/Author_box.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,16 @@ protected function get_author_box_markup(
*
* @param int $post_id
* @param string $field
* @param mixed $seperator
* @param mixed $separator
* @param mixed $user_objects
*
* @return string
*/
protected function get_authors_data(
$post_id = false,
$field = 'display_name',
$seperator = ','
$separator = ',',
$user_objects = false
) {
global $post;

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

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

if (!empty($authors)) {
foreach ($authors as $author) {
$author = Author::get_by_term_id($author->term_id);
$output[] = isset($author->$field) ? $author->$field : $author->display_name;
if (!$user_objects) {
if (!empty($authors)) {
foreach ($authors as $author) {
$output[] = isset($author->$field) ? $author->$field : $author->display_name;
}
}
$output = array_filter($output);
$authors = join($separator, $output);
}

return join($seperator, $output);
return $authors;
}
}
Loading

0 comments on commit e8f3c89

Please sign in to comment.