Skip to content

Commit

Permalink
Fixes #108 and fixes #111
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevalk committed Jan 1, 2024
1 parent 59f0c88 commit fb4df11
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 46 deletions.
20 changes: 13 additions & 7 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use WP_Comment;
use WP_Post;
use JoostBlog\WP\Comment\Inc\Hacks;
use Yoast_I18n_WordPressOrg_v3;
use JoostBlog\WP\Comment\Inc\Comment_Parent;

/**
* Admin handling class.
Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct() {

// Filter the comment notification recipients.
\add_action( 'add_meta_boxes', [ $this, 'register_meta_boxes' ] );
\add_action( 'save_post', [ $this, 'save_reroute_comment_emails' ] );
\add_action( 'pre_post_update', [ $this, 'save_reroute_comment_emails' ] );

\add_filter( 'comment_row_actions', [ $this, 'forward_to_support_action_link' ], 10, 2 );
\add_action( 'admin_head', [ $this, 'forward_comment' ] );
Expand Down Expand Up @@ -177,6 +177,7 @@ public function register_meta_boxes(): void {
* @param WP_Post $post Current post object.
*/
public function meta_box_callback( $post ): void {
echo '<input type="hidden" name="comment_notification_recipient_nonce" value="' . \esc_attr( \wp_create_nonce( 'comment_notification_recipient_nonce' ) ) . '" />';
echo '<label for="comment_notification_recipient">' . \esc_html__( 'Comment notification recipients:', 'yoast-comment-hacks' ) . '</label><br/>';

/**
Expand Down Expand Up @@ -224,7 +225,7 @@ public function meta_box_callback( $post ): void {
}

/**
* Register the text domain and the options array along with the validation function.
* Register the options array along with the validation function.
*/
public function init(): void {
// Register our option array.
Expand Down Expand Up @@ -269,13 +270,17 @@ public function enqueue(): void {

/**
* Saves the comment email recipients post meta.
*
* @param int $post_id The post ID.
*/
public function save_reroute_comment_emails(): void {
public function save_reroute_comment_emails( $post_id ): void {

$post_id = \filter_input( \INPUT_POST, 'ID', \FILTER_VALIDATE_INT );
$recipient_id = \filter_input( \INPUT_POST, 'comment_notification_recipient', \FILTER_VALIDATE_INT );
if ( ! isset( $_POST['comment_notification_recipient'] ) || ! \wp_verify_nonce( \filter_input( \INPUT_POST, 'comment_notification_recipient_nonce' ), 'comment_notification_recipient_nonce' ) ) {
return;
}

if ( $recipient_id && $post_id ) {
$recipient_id = (int) \sanitize_key( \wp_unslash( $_POST['comment_notification_recipient'] ) );
if ( $recipient_id > 0 ) {
\update_post_meta( $post_id, self::NOTIFICATION_RECIPIENT_KEY, $recipient_id );
}
}
Expand Down Expand Up @@ -303,6 +308,7 @@ public function options_validate( array $input ): array {
break;
case 'comment_policy':
case 'clean_emails':
case 'disable_email_all_commenters':

Check failure on line 311 in admin/admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Spaces must be used for mid-line alignment; tabs are not allowed

Check failure on line 311 in admin/admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Whitespace found at end of line
$input[ $key ] = $this->sanitize_bool( $value );
break;
case 'email_subject':
Expand Down
18 changes: 18 additions & 0 deletions admin/views/config-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
href="#top#clean-emails"><?php esc_html_e( 'Clean emails', 'yoast-comment-hacks' ); ?></a>
<a class="nav-tab" id="forward-emails-tab"
href="#top#forward-emails"><?php esc_html_e( 'Forward emails', 'yoast-comment-hacks' ); ?></a>
<a class="nav-tab" id="email-all-tab"
href="#top#email-all"><?php esc_html_e( 'Email all commenters', 'yoast-comment-hacks' ); ?></a>
</h2>

<form action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" id="yoast-ch-conf" method="post">
Expand Down Expand Up @@ -287,6 +289,22 @@
</tr>
</table>
</div>

<div id="email-all" class="yoasttab">
<h3><?php esc_html_e( 'Email all commenters', 'yoast-comment-hacks' ); ?></h3>

<p><?php esc_html_e( 'This plugin comes with an "Email all commenters" admin bar button. You can disable it here.', 'yoast-comment-hacks' ); ?></p>
<table class="form-table">
<tr>
<th scope="row">
<label for="disable_email_all_commenters"><?php esc_html_e( 'Disable "Email all commenters" button', 'yoast-comment-hacks' ); ?></label>
</th>
<td><input type="checkbox" id="disable_email_all_commenters"
name="<?php echo esc_attr( $yoast_comment_option_name . '[disable_email_all_commenters]' ); ?>" <?php checked( $this->options['disable_email_all_commenters'] ); ?> />
</td>
</tr>
</table>
</div>
<?php submit_button(); ?>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"php": "7.4"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/installers": true
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"minimum-stability": "dev",
Expand Down
52 changes: 38 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inc/email-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function init(): void {
* Adds an email link to the admin bar to email all commenters.
*/
public function admin_bar_comment_link(): void {
if ( ! \is_singular() ) {
if ( ! \is_singular() || $this->options['disable_email_all_commenters'] ) {
return;
}

Expand Down
41 changes: 23 additions & 18 deletions inc/hacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct() {
new Clean_Emails();
}

if ( \is_admin() ) {
if ( \is_admin() || \wp_doing_ajax() ) {
new Admin();
}

Expand Down Expand Up @@ -173,6 +173,10 @@ private function upgrade(): void {
$this->options['version'] = \JOOST_COMMENT_HACKS_VERSION;
}

if ( ! isset( $this->options['disable_email_all_commenters'] ) ) {
$this->options['disable_email_all_commenters'] = false;
}

\update_option( self::$option_name, $this->options );
}

Expand All @@ -181,27 +185,28 @@ private function upgrade(): void {
*/
public static function get_defaults(): array {
return [
'clean_emails' => true,
'comment_policy' => false,
'comment_policy_text' => __( 'I agree to the comment policy.', 'yoast-comment-hacks' ),
'comment_policy_error' => __( 'You have to agree to the comment policy.', 'yoast-comment-hacks' ),
'comment_policy_page' => 0,
'clean_emails' => true,
'comment_policy' => false,
'comment_policy_text' => __( 'I agree to the comment policy.', 'yoast-comment-hacks' ),
'comment_policy_error' => __( 'You have to agree to the comment policy.', 'yoast-comment-hacks' ),
'comment_policy_page' => 0,
'disable_email_all_commenters' => false,
/* translators: %s expands to the post title */
'email_subject' => \sprintf( \__( 'RE: %s', 'yoast-comment-hacks' ), '%title%' ),
'email_subject' => \sprintf( \__( 'RE: %s', 'yoast-comment-hacks' ), '%title%' ),
/* translators: %1$s expands to the commenters first name, %2$s to the post tittle, %3$s to the post permalink, %4$s expands to a double line break. */
'email_body' => \sprintf( \__( 'Hi %1$s,%4$sI\'m emailing you because you commented on my post "%2$s" - %3$s', 'yoast-comment-hacks' ), '%firstname%', '%title%', '%permalink%', "\r\n\r\n" ) . "\r\n",
'email_body' => \sprintf( \__( 'Hi %1$s,%4$sI\'m emailing you because you commented on my post "%2$s" - %3$s', 'yoast-comment-hacks' ), '%firstname%', '%title%', '%permalink%', "\r\n\r\n" ) . "\r\n",
/* translators: %1$s expands to the post tittle, %2$s to the post permalink, %3$s expands to a double line break. */
'mass_email_body' => \sprintf( \__( 'Hi,%3$sI\'m sending you all this email because you commented on my post "%1$s" - %2$s', 'yoast-comment-hacks' ), '%title%', '%permalink%', "\r\n\r\n" ) . "\r\n",
'mincomlength' => 15,
'mincomlengtherror' => \__( 'Error: Your comment is too short. Please try to say something useful.', 'yoast-comment-hacks' ),
'maxcomlength' => 1500,
'maxcomlengtherror' => \__( 'Error: Your comment is too long. Please try to be more concise.', 'yoast-comment-hacks' ),
'redirect_page' => 0,
'forward_email' => '',
'forward_name' => \__( 'Support', 'yoast-comment-hacks' ),
'mass_email_body' => \sprintf( \__( 'Hi,%3$sI\'m sending you all this email because you commented on my post "%1$s" - %2$s', 'yoast-comment-hacks' ), '%title%', '%permalink%', "\r\n\r\n" ) . "\r\n",
'mincomlength' => 15,
'mincomlengtherror' => \__( 'Error: Your comment is too short. Please try to say something useful.', 'yoast-comment-hacks' ),
'maxcomlength' => 1500,
'maxcomlengtherror' => \__( 'Error: Your comment is too long. Please try to be more concise.', 'yoast-comment-hacks' ),
'redirect_page' => 0,
'forward_email' => '',
'forward_name' => \__( 'Support', 'yoast-comment-hacks' ),
/* translators: %1$s is replaced by the blog's name. */
'forward_subject' => \sprintf( \__( 'Comment forwarded from %1$s', 'yoast-comment-hacks' ), \get_bloginfo( 'name' ) ),
'forward_from_email' => self::get_from_email_default(),
'forward_subject' => \sprintf( \__( 'Comment forwarded from %1$s', 'yoast-comment-hacks' ), \get_bloginfo( 'name' ) ),
'forward_from_email' => self::get_from_email_default(),
];
}

Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: joostdevalk
Tags: comments, spam, emails
Text Domain: yoast-comment-hacks
Requires at least: 5.9
Tested up to: 6.1
Stable tag: 1.9.2
Tested up to: 6.4
Stable tag: 2.0
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Requires PHP: 7.4
Expand Down Expand Up @@ -59,6 +59,11 @@ If you have bugs to report, please go to [the plugin's GitHub repository](https:

== Changelog ==

= 1.9.3 =

* Fix bug where comment reroute recipient would not save.
* Added an option to disable the "Email all commenters" admin bar button.

= 1.9.2 =

* Fix missing autoloader
Expand Down
4 changes: 2 additions & 2 deletions yoast-comment-hacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @wordpress-plugin
* Plugin Name: Comment Hacks
* Version: 1.9.2
* Version: 1.9.3
* Plugin URI: https://joost.blog/plugins/comment-hacks/
* Description: Make comments management easier by applying the simple hacks Joost has gathered over the years.
* Requires PHP: 7.4
Expand Down Expand Up @@ -34,7 +34,7 @@
/**
* Used for version checks.
*/
define( 'JOOST_COMMENT_HACKS_VERSION', '1.9.2' );
define( 'JOOST_COMMENT_HACKS_VERSION', '1.9.3' );

/**
* Used for asset embedding.
Expand Down

0 comments on commit fb4df11

Please sign in to comment.