Skip to content

Commit

Permalink
Merge branch 'release/4.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobattocchi committed Jan 25, 2022
2 parents 5ae315f + b3ba782 commit 03991d8
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 101 deletions.
57 changes: 17 additions & 40 deletions admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ function duplicate_post_plugin_upgrade() {
$role->add_cap( 'copy_posts' );
}
}
add_option( 'duplicate_post_show_notice', 1 );
}
else {
update_option( 'duplicate_post_show_notice', 0 );
}

$show_links_in_defaults = [
Expand Down Expand Up @@ -163,11 +167,6 @@ function duplicate_post_plugin_upgrade() {
}
update_option( 'duplicate_post_blacklist', implode( ',', $meta_blacklist ) );

delete_option( 'duplicate_post_show_notice' );
if ( version_compare( $installed_version, '4.2.0' ) < 0 ) {
update_site_option( 'duplicate_post_show_notice', 1 );
}

if ( version_compare( $installed_version, '4.0.0' ) < 0 ) {
// Migrate the 'Show links in' options to the new array-based structure.
duplicate_post_migrate_show_links_in_options( $show_links_in_defaults );
Expand Down Expand Up @@ -203,7 +202,7 @@ function duplicate_post_migrate_show_links_in_options( $defaults ) {
}

/**
* Shows the update notice.
* Shows the welcome notice.
*
* @global string $wp_version The WordPress version string.
*/
Expand All @@ -220,43 +219,21 @@ function duplicate_post_show_update_notice() {
return;
}

$class = 'notice is-dismissible';
$message = '<p><strong>' . sprintf(
/* translators: %s: Yoast Duplicate Post version. */
__( "What's new in Yoast Duplicate Post version %s:", 'duplicate-post' ),
DUPLICATE_POST_CURRENT_VERSION
) . '</strong> ';
$message .= __( 'improved compatibility with PHP 8.0 and fixes for some bugs regarding translations and the Rewrite & Republish feature.', 'duplicate-post' )
. ' ';

$message .= '<a href="https://wordpress.org/plugins/duplicate-post/#developers">'
. sprintf(
/* translators: %s: Yoast Duplicate Post version. */
__( 'Read the changelog', 'duplicate-post' ),
DUPLICATE_POST_CURRENT_VERSION
)
. '</a></p>';

$message .= '<p>%%SIGNUP_FORM%%</p>';

$allowed_tags = [
'a' => [
'href' => [],
],
'br' => [],
'p' => [],
'strong' => [],
];

$sanitized_message = wp_kses( $message, $allowed_tags );
$sanitized_message = str_replace( '%%SIGNUP_FORM%%', Newsletter::newsletter_signup_form(), $sanitized_message );
$title = sprintf(
/* translators: %s: Yoast Duplicate Post. */
esc_html__( 'You\'ve successfully installed %s!', 'duplicate-post' ),
'Yoast Duplicate Post'
);

$img_path = plugins_url( '/duplicate_post_yoast_icon-125x125.png', __FILE__ );

echo '<div id="duplicate-post-notice" class="' . esc_attr( $class ) . '" style="display: flex; align-items: flex-start;">
<img src="' . esc_url( $img_path ) . '" alt="" style="margin: 1.5em 0.5em 1.5em 0;"/>
<div style="margin: 0.5em">' . $sanitized_message // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: escaped properly above.
. '</div></div>';
echo '<div id="duplicate-post-notice" class="notice is-dismissible" style="display: flex; align-items: flex-start;">
<img src="' . esc_url( $img_path ) . '" alt="" style="margin: 1em 1em 1em 0; width: 130px; align-self: center;"/>
<div stle="margin: 0.5em">
<h1 style="font-size: 14px; color: #a4286a; font-weight: 600; margin-top: 8px;">' . $title . '</h1>' // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: escaped properly above.
. Newsletter::newsletter_signup_form() // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: escaped in newsletter.php.
. '</div>
</div>';

echo "<script>
function duplicate_post_dismiss_notice(){
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"require": {
"php": ">=5.6",
"composer/installers": "^1.9.0"
"composer/installers": "^1.12.0"
},
"require-dev": {
"yoast/yoastcs": "^2.2.0",
Expand Down Expand Up @@ -58,6 +58,10 @@
]
},
"config": {
"classmap-authoritative": true
"classmap-authoritative": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/installers": true
}
}
}
4 changes: 2 additions & 2 deletions duplicate-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: Yoast Duplicate Post
* Plugin URI: https://yoast.com/wordpress/plugins/duplicate-post/
* Description: The go-to tool for cloning posts and pages, including the powerful Rewrite & Republish feature.
* Version: 4.3
* Version: 4.4-RC3
* Author: Enrico Battocchi & Team Yoast
* Author URI: https://yoast.com
* Text Domain: duplicate-post
Expand Down Expand Up @@ -45,7 +45,7 @@
define( 'DUPLICATE_POST_PATH', plugin_dir_path( __FILE__ ) );
}

define( 'DUPLICATE_POST_CURRENT_VERSION', '4.3' );
define( 'DUPLICATE_POST_CURRENT_VERSION', '4.4-RC3' );

$duplicate_post_autoload_file = DUPLICATE_POST_PATH . 'vendor/autoload.php';

Expand Down
5 changes: 5 additions & 0 deletions js/src/duplicate-post-edit-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class DuplicatePost {
* @returns {JSX.Element} The rendered links.
*/
render() {
// Don't try to render anything if there is no store.
if ( ! select( 'core/editor' ) || ! ( wp.editPost && wp.editPost.PluginPostStatusInfo ) ) {
return null;
}

const currentPostStatus = select( 'core/editor' ).getEditedPostAttribute( 'status' );

return (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
"@wordpress/plugins": "^2.23.0"
},
"yoast": {
"pluginVersion": "4.3"
"pluginVersion": "4.4"
}
}
17 changes: 16 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: yoast, lopo
Donate link: https://yoast.com/wordpress/plugins/duplicate-post/
Tags: duplicate post, copy, clone
Requires at least: 5.6
Tested up to: 5.8
Tested up to: 5.9
Stable tag: 4.3
Requires PHP: 5.6.20
License: GPLv2 or later
Expand Down Expand Up @@ -151,6 +151,21 @@ New features and customization, WP 3.0 compatibility: you should upgrade if you

== Changelog ==

= 4.4 (2022-01-25) =

Enhancements:

* Converts the upgrade notice into a welcome notice for first-time users.

Bugfixes:

* Fixes a bug where HTML tags in a Custom HTML block would be removed when republishing a scheduled Rewrite & Republish copy.
* Fixes a bug where the button style would be broken in the Classic Editor.
* Fixes a bug where a fatal error would be triggered in the Widgets page in combination with some themes or plugins.

Other:
* Sets the WordPress tested up to version to 5.9.

= 4.3 (2021-12-14) =

Bugfixes:
Expand Down
2 changes: 1 addition & 1 deletion src/admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function get_options() {
'duplicate_post_show_notice' => [
'tab' => 'display',
'type' => 'checkbox',
'label' => \__( 'Show update notice', 'duplicate-post' ),
'label' => \__( 'Show welcome notice', 'duplicate-post' ),
'value' => 1,
],
'duplicate_post_show_link' => [
Expand Down
2 changes: 1 addition & 1 deletion src/admin/views/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class="nav-tab"
</td>
</tr>
<tr>
<th scope="row"><?php \esc_html_e( 'Update notice', 'duplicate-post' ); ?></th>
<th scope="row"><?php \esc_html_e( 'Welcome notice', 'duplicate-post' ); ?></th>
<td>
<?php
// phpcs:ignore WordPress.Security.EscapeOutput -- Already escapes correctly.
Expand Down
4 changes: 3 additions & 1 deletion src/post-republisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ public function republish_scheduled_post( $copy ) {
return;
}

\kses_remove_filters();
$this->republish( $copy, $original_post );
\kses_init_filters();
$this->delete_copy( $copy->ID, $original_post->ID );
}

Expand Down Expand Up @@ -324,7 +326,7 @@ protected function republish_post_elements( $post, $original_post ) {
$_POST['ID'] = $original_post->ID;

// Republish the original post.
$rewritten_post_id = \wp_update_post( \wp_slash( $post_to_be_rewritten ) );
$rewritten_post_id = \wp_update_post( $post_to_be_rewritten );

if ( $rewritten_post_id === 0 ) {
\wp_die( \esc_html__( 'An error occurred while republishing the post.', 'duplicate-post' ) );
Expand Down
4 changes: 4 additions & 0 deletions src/ui/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public function should_previously_used_keyword_assessment_run() {
* @return void
*/
public function enqueue_block_editor_scripts() {
if ( ! $this->permissions_helper->is_edit_post_screen() && ! $this->permissions_helper->is_new_post_screen() ) {
return;
}

$post = \get_post();

if ( ! $post instanceof WP_Post ) {
Expand Down
9 changes: 7 additions & 2 deletions src/ui/classic-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public function register_hooks() {
\add_filter( 'post_updated_messages', [ $this, 'change_scheduled_notice_classic_editor' ], 10, 1 );

\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_classic_editor_scripts' ] );
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_classic_editor_styles' ] );
if ( \intval( Utils::get_option( 'duplicate_post_show_link_in', 'submitbox' ) ) === 1 ) {
if ( \intval( Utils::get_option( 'duplicate_post_show_link', 'new_draft' ) ) === 1
|| \intval( Utils::get_option( 'duplicate_post_show_link', 'rewrite_republish' ) ) === 1 ) {
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_classic_editor_styles' ] );
}
}

// Remove slug editing from Classic Editor.
\add_action( 'add_meta_boxes', [ $this, 'remove_slug_meta_box' ], 10, 2 );
Expand Down Expand Up @@ -102,7 +107,7 @@ public function enqueue_classic_editor_styles() {
$id = \intval( \wp_unslash( $_GET['post'] ) );
$post = \get_post( $id );

if ( ! \is_null( $post ) && $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
if ( ! \is_null( $post ) && $this->permissions_helper->should_links_be_displayed( $post ) ) {
$this->asset_manager->enqueue_styles();
}
}
Expand Down
51 changes: 32 additions & 19 deletions src/ui/newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@ public static function newsletter_signup_form() {
$newsletter_form_response = self::newsletter_handle_form();


$copy = sprintf(
$copy = \sprintf(
/* translators: 1: Yoast */
esc_html__(
\esc_html__(
'If you want to stay up to date about all the exciting developments around Duplicate Post, subscribe to the %1$s newsletter!',
'duplicate-post'
),
'Yoast'
);

$email_label = esc_html__( 'Email Address', 'duplicate-post' );
$email_label = \esc_html__( 'Email address', 'duplicate-post' );

$copy_privacy_policy = sprintf(
// translators: %1$s and %2$s are replaced by opening and closing anchor tags.
\esc_html__(
'Yoast respects your privacy. Read %1$sour privacy policy%2$s on how we handle your personal information.',
'duplicate-post'
),
'<a href="https://yoa.st/4jf" target="_blank">',
'</a>'
);

$response_html = '';
if ( is_array( $newsletter_form_response ) ) {
if ( \is_array( $newsletter_form_response ) ) {
$response_status = $newsletter_form_response['status'];
$response_message = $newsletter_form_response['message'];

Expand All @@ -39,12 +49,15 @@ public static function newsletter_signup_form() {
$html = '
<!-- Begin Newsletter Signup Form -->
<form method="post" id="newsletter-subscribe-form" name="newsletter-subscribe-form" novalidate>
' . wp_nonce_field( 'newsletter', 'newsletter_nonce' ) . '
' . \wp_nonce_field( 'newsletter', 'newsletter_nonce' ) . '
<p>' . $copy . '</p>
<div class="newsletter-field-group" style="display: flex; align-items: center;">
<label for="newsletter-email" style="margin-right: 4px;"><strong>' . $email_label . '</strong></label>
<input type="email" value="" name="EMAIL" class="required email" id="newsletter-email" style="margin-right: 4px;">
<input type="submit" value="' . esc_attr__( 'Subscribe', 'duplicate-post' ) . '" name="subscribe" id="newsletter-subscribe" class="button">
<div class="newsletter-field-group" style="display: flex; flex-direction: column">
<label for="newsletter-email" style="margin: 0 0 4px 0;"><strong>' . $email_label . '</strong></label>
<div>
<input type="email" value="" name="EMAIL" class="required email" id="newsletter-email" style="margin-right: 4px;">
<input type="submit" value="' . \esc_attr__( 'Subscribe', 'duplicate-post' ) . '" name="subscribe" id="newsletter-subscribe" class="button">
</div>
<p style="font-size: 10px;">' . $copy_privacy_policy . '</p>
</div>
' . $response_html . '
</form>
Expand All @@ -57,31 +70,31 @@ public static function newsletter_signup_form() {
/**
* Handles and validates Newsletter form.
*
* @return null|array.
* @return array|null
*/
private static function newsletter_handle_form() {

//phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Already sanitized.
if ( isset( $_POST['newsletter_nonce'] ) && ! wp_verify_nonce( wp_unslash( $_POST['newsletter_nonce'] ), 'newsletter' ) ) {
if ( isset( $_POST['newsletter_nonce'] ) && ! \wp_verify_nonce( \wp_unslash( $_POST['newsletter_nonce'] ), 'newsletter' ) ) {
return [
'status' => 'error',
'message' => esc_html__( 'Something went wrong. Please try again later.', 'duplicate-post' ),
'message' => \esc_html__( 'Something went wrong. Please try again later.', 'duplicate-post' ),
];
}

$email = null;
if ( isset( $_POST['EMAIL'] ) ) {
$email = sanitize_email( wp_unslash( $_POST['EMAIL'] ) );
$email = \sanitize_email( \wp_unslash( $_POST['EMAIL'] ) );
}

if ( $email === null ) {
return null;
}

if ( ! is_email( $email ) ) {
if ( ! \is_email( $email ) ) {
return [
'status' => 'error',
'message' => esc_html__( 'Please enter valid e-mail address.', 'duplicate-post' ),
'message' => \esc_html__( 'Please enter valid e-mail address.', 'duplicate-post' ),
];
}

Expand All @@ -96,7 +109,7 @@ private static function newsletter_handle_form() {
* @return array Feedback response.
*/
private static function newsletter_subscribe_to_mailblue( $email ) {
$response = wp_remote_post(
$response = \wp_remote_post(
'https://my.yoast.com/api/Mailing-list/subscribe',
[
'method' => 'POST',
Expand All @@ -110,18 +123,18 @@ private static function newsletter_subscribe_to_mailblue( $email ) {
]
);

$wp_remote_retrieve_response_code = wp_remote_retrieve_response_code( $response );
$wp_remote_retrieve_response_code = \wp_remote_retrieve_response_code( $response );

if ( $wp_remote_retrieve_response_code <= 200 || $wp_remote_retrieve_response_code >= 300 ) {
return [
'status' => 'error',
'message' => esc_html__( 'Something went wrong. Please try again later.', 'duplicate-post' ),
'message' => \esc_html__( 'Something went wrong. Please try again later.', 'duplicate-post' ),
];
}

return [
'status' => 'success',
'message' => esc_html__( 'You have successfully subscribed to the newsletter. Please check your inbox.', 'duplicate-post' ),
'message' => \esc_html__( 'You have successfully subscribed to the newsletter. Please check your inbox.', 'duplicate-post' ),
];
}
}
Loading

0 comments on commit 03991d8

Please sign in to comment.