Plugin Directory

Changeset 3807202


Ignore:
Timestamp:
11/17/2026 11:07:55 AM (11 hours ago)
Author:
progressplanner
Message:

Update to version 2.1.8 from GitHub

Location:
yoast-comment-hacks
Files:
2 added
36 edited
1 copied

Legend:

Unmodified
Added
Removed
  • yoast-comment-hacks/tags/2.1.8/admin/admin.php

    r3438581 r3807202  
    33namespace EmiliaProjects\WP\Comment\Admin;
    44
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
     9
    510use EmiliaProjects\WP\Comment\Inc\Hacks;
     11use EmiliaProjects\WP\Comment\Inc\Notifications;
    612use WP_Comment;
    713use WP_Post;
    … …  
    6369
    6470                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_discussion_settings_script' ] );
     71
     72                \add_action( 'wp_ajax_ch_search_users', [ $this, 'ajax_search_users' ] );
    6573
    6674                new Comment_Parent();
    … …  
    135143                        && isset( $_GET['comment_id'] )
    136144                        && $_GET['ch_action'] === 'forward_comment'
    137                         && \wp_verify_nonce( \wp_strip_all_tags( \wp_unslash( $_GET['nonce'] ) ), 'comment-hacks-forward' )
    138145                ) {
    139146                        $comment_id = (int) $_GET['comment_id'];
    140                         $comment    = \get_comment( $comment_id );
     147                        if ( $comment_id <= 0 || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_GET['nonce'] ) ), 'comment-hacks-forward_' . $comment_id ) ) {
     148                                return;
     149                        }
     150
     151                        $comment = \get_comment( $comment_id );
     152                        if ( ! $comment || ! \current_user_can( 'edit_comment', $comment_id ) ) {
     153                                return;
     154                        }
    141155
    142156                        echo '<div class="msg updated"><p>';
    … …  
    157171
    158172                        if ( ! empty( $this->options['forward_extra'] ) ) {
    159                                 $intro .= $this->options['forward_extra'] . "\n\n";
     173                                $intro .= \esc_html( $this->options['forward_extra'] ) . "\n\n";
    160174                        }
    161175
    … …  
    167181                        $intro .= "\n\n";
    168182
    169                         $content = \nl2br( $intro . $comment->comment_content );
     183                        $content = \nl2br( $intro . \esc_html( $comment->comment_content ) );
    170184
    171185                        $headers = [
    … …  
    192206         */
    193207        public function forward_to_support_action_link( $actions, $comment ): array {
    194                 if ( empty( $this->options['forward_email'] ) ) {
     208                if ( empty( $this->options['forward_email'] ) || ! \current_user_can( 'edit_comment', (int) $comment->comment_ID ) ) {
    195209                        return $actions;
    196210                }
    … …  
    205219                }
    206220
    207                 $actions['ch_forward'] = '<a href="' . \esc_url( \admin_url( 'edit-comments.php' ) . '?comment_id=' . $comment->comment_ID . '&ch_action=forward_comment&nonce=' . \wp_create_nonce( 'comment-hacks-forward' ) ) . '">' . \esc_html( $label ) . '</a>';
     221                $actions['ch_forward'] = '<a href="' . \esc_url( \admin_url( 'edit-comments.php' ) . '?comment_id=' . $comment->comment_ID . '&ch_action=forward_comment&nonce=' . \wp_create_nonce( 'comment-hacks-forward_' . $comment->comment_ID ) ) . '">' . \esc_html( $label ) . '</a>';
    208222
    209223                return $actions;
    … …  
    236250         */
    237251        public function meta_box_callback( $post ): void {
     252                $selected_id   = (int) \get_post_meta( $post->ID, self::NOTIFICATION_RECIPIENT_KEY, true );
     253                $selected_name = '';
     254
     255                if ( $selected_id > 0 ) {
     256                        $user = \get_userdata( $selected_id );
     257                        if ( $user ) {
     258                                $selected_name = $user->display_name;
     259                        }
     260                }
     261
    238262                ?>
    239263                <input
    … …  
    242266                        value="<?php echo \esc_attr( \wp_create_nonce( 'comment_notification_recipient_nonce' ) ); ?>"
    243267                />
    244                 <label for="comment_notification_recipient">
     268                <label for="comment_notification_recipient_search">
    245269                        <?php \esc_html_e( 'Comment notification recipients:', 'yoast-comment-hacks' ); ?>
    246270                </label>
    247271                <br/>
     272                <input
     273                        type="hidden"
     274                        name="comment_notification_recipient"
     275                        id="comment_notification_recipient"
     276                        value="<?php echo \esc_attr( (string) $selected_id ); ?>"
     277                />
     278                <input
     279                        type="text"
     280                        id="comment_notification_recipient_search"
     281                        value="<?php echo \esc_attr( $selected_name ); ?>"
     282                        placeholder="<?php \esc_attr_e( 'Search for a user...', 'yoast-comment-hacks' ); ?>"
     283                        class="widefat"
     284                        autocomplete="off"
     285                />
     286                <ul id="comment_notification_recipient_results" style="display:none;margin:0;padding:0;list-style:none;border:1px solid #ddd;background:#fff;max-height:150px;overflow-y:auto;"></ul>
     287                <?php if ( $selected_id > 0 ) : ?>
     288                <a href="#" id="comment_notification_recipient_clear" style="display:inline;">
     289                        <?php \esc_html_e( 'Reset to post author', 'yoast-comment-hacks' ); ?>
     290                </a>
     291                <?php else : ?>
     292                <a href="#" id="comment_notification_recipient_clear" style="display:none;">
     293                        <?php \esc_html_e( 'Reset to post author', 'yoast-comment-hacks' ); ?>
     294                </a>
     295                <?php endif; ?>
     296                <p class="description"><?php \esc_html_e( 'Leave empty to use post author.', 'yoast-comment-hacks' ); ?></p>
    248297                <?php
    249 
    250                 /**
    251                  * This filter allows filtering which roles should be shown in the dropdown for notifications.
    252                  * Defaults to contributor and up.
    253                  *
    254                  * @param array $roles Array with user roles.
    255                  *
    256                  * @since 1.6.0
    257                  */
    258                 $roles = \apply_filters(
    259                         'comment_experience\notification_roles',
    260                         [ 'contributor', 'author', 'editor', 'administrator', 'super-admin' ]
    261                 );
    262 
    263                 \wp_dropdown_users(
     298        }
     299
     300        /**
     301         * AJAX handler for searching users.
     302         *
     303         * @return void
     304         */
     305        public function ajax_search_users(): void {
     306                \check_ajax_referer( 'ch_search_users_nonce', 'nonce' );
     307
     308                if ( ! \current_user_can( 'edit_posts' ) ) {
     309                        \wp_send_json_error( 'Unauthorized' );
     310                }
     311
     312                $search = isset( $_GET['search'] ) ? \sanitize_text_field( \wp_unslash( $_GET['search'] ) ) : '';
     313
     314                if ( \strlen( $search ) < 2 ) {
     315                        \wp_send_json_success( [] );
     316                }
     317
     318                $users = \get_users(
    264319                        [
    265                                 'selected'          => \get_post_meta( $post->ID, self::NOTIFICATION_RECIPIENT_KEY, true ),
    266                                 'show_option_none'  => 'Post author',
    267                                 'name'              => 'comment_notification_recipient',
    268                                 'id'                => 'comment_notification_recipient',
    269                                 'role__in'          => $roles,
    270                                 'option_none_value' => 0,
     320                                'search'         => '*' . $search . '*',
     321                                'search_columns' => [ 'display_name', 'user_nicename' ],
     322                                'role__in'       => Notifications::get_allowed_roles(),
     323                                'number'         => 20,
     324                                'orderby'        => 'display_name',
     325                                'order'          => 'ASC',
    271326                        ]
    272327                );
     328
     329                $results = [];
     330                foreach ( $users as $user ) {
     331                        $results[] = [
     332                                'id'   => $user->ID,
     333                                'name' => $user->display_name,
     334                        ];
     335                }
     336
     337                \wp_send_json_success( $results );
    273338        }
    274339
    … …  
    293358         * Enqueue our admin script.
    294359         *
    295          * @return void
    296          */
    297         public function enqueue(): void {
     360         * @param string $hook_suffix The current admin page.
     361         *
     362         * @return void
     363         */
     364        public function enqueue( $hook_suffix ): void {
    298365                $page = \filter_input( \INPUT_GET, 'page' );
    299366
    … …  
    314381                        );
    315382                }
     383
     384                if ( $hook_suffix === 'post.php' || $hook_suffix === 'post-new.php' ) {
     385                        \wp_enqueue_script(
     386                                'emiliaprojects-comment-hacks-user-search',
     387                                \plugins_url( 'admin/assets/js/user-search.js', \EMILIA_COMMENT_HACKS_FILE ),
     388                                [ 'jquery' ],
     389                                \EMILIA_COMMENT_HACKS_VERSION,
     390                                true
     391                        );
     392
     393                        \wp_localize_script(
     394                                'emiliaprojects-comment-hacks-user-search',
     395                                'chUserSearch',
     396                                [
     397                                        'ajax_url' => \admin_url( 'admin-ajax.php' ),
     398                                        'nonce'    => \wp_create_nonce( 'ch_search_users_nonce' ),
     399                                ]
     400                        );
     401
     402                        \wp_add_inline_style(
     403                                'wp-admin',
     404                                '#comment_notification_recipient_results li { padding: 5px; margin: 0; cursor: pointer; } #comment_notification_recipient_results li:hover { background: #f0f0f1; }'
     405                        );
     406                }
    316407        }
    317408
    … …  
    325416        public function save_reroute_comment_emails( $post_id ): void {
    326417
    327                 if ( ! isset( $_POST['comment_notification_recipient'] ) || ! \wp_verify_nonce( \filter_input( \INPUT_POST, 'comment_notification_recipient_nonce' ), 'comment_notification_recipient_nonce' ) ) {
     418                if (
     419                        ! isset( $_POST['comment_notification_recipient'], $_POST['comment_notification_recipient_nonce'] )
     420                        || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['comment_notification_recipient_nonce'] ) ), 'comment_notification_recipient_nonce' )
     421                        || ! \current_user_can( 'edit_post', $post_id )
     422                ) {
    328423                        return;
    329424                }
    330425
    331                 $recipient_id = (int) \sanitize_key( \wp_unslash( $_POST['comment_notification_recipient'] ) );
    332                 if ( $recipient_id > 0 ) {
     426                $recipient_id = \filter_var( \wp_unslash( $_POST['comment_notification_recipient'] ), \FILTER_VALIDATE_INT );
     427                if ( $recipient_id === 0 ) {
     428                        \delete_post_meta( $post_id, self::NOTIFICATION_RECIPIENT_KEY );
     429                }
     430                elseif ( $recipient_id > 0 && Notifications::is_allowed_recipient( $recipient_id ) ) {
    333431                        \update_post_meta( $post_id, self::NOTIFICATION_RECIPIENT_KEY, $recipient_id );
    334432                }
    … …  
    402500         */
    403501        private function sanitize_bool( $value ): bool {
    404                 return ( $value || ! empty( $value ) );
     502                return (bool) $value;
    405503        }
    406504
    … …  
    478576                                        '<code style="background-color: #eee; margin: 0; padding: 0;">',
    479577                                        // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode.
    480                                         \highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true ),
    481                                         $num
     578                                        \highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true )
    482579                                );
    483580                                ?>
  • yoast-comment-hacks/tags/2.1.8/admin/comment-parent.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Admin;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
    … …  
    3439         */
    3540        public function load_comment_parent_box() {
    36                 if ( \function_exists( 'add_meta_box' ) ) {
    37                         \add_meta_box(
    38                                 'comment_parent',
    39                                 \esc_html__( 'Comment Parent', 'yoast-comment-hacks' ),
    40                                 [
    41                                         $this,
    42                                         'comment_parent_box',
    43                                 ],
    44                                 'comment',
    45                                 'normal'
    46                         );
    47                 }
     41                \add_meta_box(
     42                        'comment_parent',
     43                        \esc_html__( 'Comment Parent', 'yoast-comment-hacks' ),
     44                        [
     45                                $this,
     46                                'comment_parent_box',
     47                        ],
     48                        'comment',
     49                        'normal'
     50                );
    4851        }
    4952
    … …  
    5154         * Updates the comment parent field.
    5255         *
     56         * @param int $comment_id The comment ID supplied by the edit_comment hook.
     57         *
    5358         * @return void
    5459         */
    55         public function update_comment_parent() {
    56                 $comment_parent = \filter_input( \INPUT_POST, 'epch_comment_parent', \FILTER_VALIDATE_INT );
    57                 $comment_id     = \filter_input( \INPUT_POST, 'comment_ID', \FILTER_VALIDATE_INT );
    58                 $action         = \filter_input( \INPUT_POST, 'action' );
    59 
    60                 if ( $action === 'edit-comment' ) {
    61                         return; // We're on the quick edit screen. As the comment parent isn't sent along here, we might lose it if we do anything.
     60        public function update_comment_parent( $comment_id ) {
     61                if (
     62                        ! \is_admin() || \wp_doing_ajax()
     63                        || ! isset( $_POST['action'], $_POST['comment_ID'], $_POST['epch_comment_parent'], $_POST['_wpnonce'] )
     64                        || $_POST['action'] !== 'editedcomment'
     65                        || (int) $_POST['comment_ID'] !== (int) $comment_id
     66                        || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['_wpnonce'] ) ), 'update-comment_' . $comment_id )
     67                        || ! \current_user_can( 'edit_comment', $comment_id )
     68                ) {
     69                        return;
    6270                }
    6371
    64                 if ( empty( $comment_id ) && empty( $comment_parent ) ) {
    65                         return; // There might be another reason for a comment to be updated.
     72                if ( ! \is_string( $_POST['epch_comment_parent'] ) ) {
     73                        return;
    6674                }
    6775
    68                 if ( \function_exists( 'wp_doing_ajax' ) && \wp_doing_ajax() ) {
    69                         \check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
     76                // An emptied field means "no parent", as it did before this field was validated.
     77                $raw_parent     = \sanitize_text_field( \wp_unslash( $_POST['epch_comment_parent'] ) );
     78                $comment_parent = ( $raw_parent === '' ) ? 0 : \filter_var( $raw_parent, \FILTER_VALIDATE_INT );
     79                $comment        = \get_comment( $comment_id );
     80                if ( $comment_parent === false || $comment_parent < 0 || ! $comment || $comment_parent === (int) $comment_id ) {
     81                        return;
    7082                }
    7183
    72                 if ( ! \function_exists( 'wp_doing_ajax' ) || ! \wp_doing_ajax() ) {
    73                         \check_admin_referer( 'update-comment_' . $comment_id );
     84                // Reject missing parents, parents on other posts, and circular threads.
     85                $ancestor_id = $comment_parent;
     86                $seen        = [ (int) $comment_id ];
     87                while ( $ancestor_id > 0 ) {
     88                        $parent = \get_comment( $ancestor_id );
     89                        if ( ! $parent || (int) $parent->comment_post_ID !== (int) $comment->comment_post_ID || \in_array( $ancestor_id, $seen, true ) ) {
     90                                return;
     91                        }
     92                        $seen[]      = $ancestor_id;
     93                        $ancestor_id = (int) $parent->comment_parent;
    7494                }
    7595
    76                 if ( ! isset( $comment_parent ) ) {
    77                         $comment_parent = 0;
    78                 }
    79 
    80                 if ( $comment_id ) {
    81                         $comment                 = \get_comment( $comment_id );
    82                         $comment->comment_parent = $comment_parent;
    83 
    84                         // Remove our filter, or we'll keep looping.
    85                         \remove_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
    86                         \wp_update_comment( (array) $comment );
    87 
    88                         // Add our filter back.
    89                         \add_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
    90                 }
     96                // Remove our filter, or we'll keep looping.
     97                \remove_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
     98                \wp_update_comment(
     99                        [
     100                                'comment_ID'     => $comment_id,
     101                                'comment_parent' => $comment_parent,
     102                        ]
     103                );
     104                \add_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
    91105        }
    92106}
  • yoast-comment-hacks/tags/2.1.8/admin/views/comment-parent-box.php

    r3438581 r3807202  
    11<?php
     2
     3if ( ! defined( 'ABSPATH' ) ) {
     4        exit;
     5}
     6
    27/**
    38 * Parent Box view.
  • yoast-comment-hacks/tags/2.1.8/admin/views/config-page.php

    r3438581 r3807202  
    11<?php
     2
     3if ( ! defined( 'ABSPATH' ) ) {
     4        exit;
     5}
     6
     7// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
     8
    29/**
    310 * Config page admin view.
    411 *
    5  * @var Admin $this
     12 * @var \EmiliaProjects\WP\Comment\Admin\Admin $this
    613 */
    714
    8 use EmiliaProjects\WP\Comment\Admin\Admin;
    915use EmiliaProjects\WP\Comment\Inc\Hacks;
    1016
  • yoast-comment-hacks/tags/2.1.8/comment-hacks.php

    r3438581 r3807202  
    55 * @wordpress-plugin
    66 * Plugin Name:  Comment Experience
    7  * Version:      2.1.7
     7 * Version:      2.1.8
    88 * Plugin URI:   https://progressplanner.com/plugins/comment-experience/
    99 * Description:  Improve the comment experience on your site. Adds lots of features to make commenting easier and more engaging.
    … …  
    3131 */
    3232
     33if ( ! defined( 'ABSPATH' ) ) {
     34        exit;
     35}
     36
    3337use EmiliaProjects\WP\Comment\Inc\Autoload;
    3438use EmiliaProjects\WP\Comment\Inc\Hacks;
    … …  
    3741 * Used for version checks.
    3842 */
    39 define( 'EMILIA_COMMENT_HACKS_VERSION', '2.1.6' );
     43define( 'EMILIA_COMMENT_HACKS_VERSION', '2.1.8' );
    4044
    4145/**
  • yoast-comment-hacks/tags/2.1.8/inc/autoload.php

    r3265034 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
  • yoast-comment-hacks/tags/2.1.8/inc/clean-emails.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510use WP_Comment;
    … …  
    1015 */
    1116class Clean_Emails {
    12 
    13         /**
    14          * Holds the current comment's ID.
    15          */
    16         private int $comment_id = 0;
    1717
    1818        /**
    … …  
    148148                $this->comment_moderation_actions();
    149149                $this->message .= ' | ' . \sprintf(
    150                         '<a href="http://ip-lookup.net/index.php?ip=%1$s">%2$s</a>',
    151                         $this->comment->comment_author_IP,
     150                        '<a href="%1$s">%2$s</a>',
     151                        \esc_url( 'https://ip-lookup.net/index.php?ip=' . \rawurlencode( $this->comment->comment_author_IP ) ),
    152152                        \esc_html__( 'Whois', 'yoast-comment-hacks' )
    153153                );
    … …  
    177177         */
    178178        private function add_author_line(): void {
    179                 if ( $this->comment->comment_type === 'comment' ) {
     179                if ( $this->comment->comment_type !== 'pingback' && $this->comment->comment_type !== 'trackback' ) {
    180180                        /* translators: %1$s is replaced with the comment author's name, %2$s is replaced with the comment author's email */
    181181                        $this->message .= \sprintf( \esc_html__( 'Author: %1$s (%2$s)', 'yoast-comment-hacks' ), \esc_html( $this->comment->comment_author ), '<a href="' . \esc_url( 'mailto:' . $this->comment->comment_author_email ) . '">' . \esc_html( $this->comment->comment_author_email ) . '</a>' ) . '<br />';
    … …  
    193193         */
    194194        private function add_content_line(): void {
    195                 if ( $this->comment->comment_type === 'comment' ) {
     195                if ( $this->comment->comment_type !== 'pingback' && $this->comment->comment_type !== 'trackback' ) {
    196196                        $this->message .= \esc_html__( 'Comment:', 'yoast-comment-hacks' );
    197197                }
    … …  
    200200                }
    201201
    202                 $this->message .= '<br />' . \wpautop( $this->comment->comment_content ) . '<br />';
     202                $this->message .= '<br />' . \wpautop( \esc_html( $this->comment->comment_content ) ) . '<br />';
    203203        }
    204204
    … …  
    232232         */
    233233        private function setup_data( int $comment_id ): void {
    234                 $this->comment_id = $comment_id;
    235                 $this->comment    = \get_comment( $this->comment_id );
    236                 $this->post       = \get_post( (int) $this->comment->comment_post_ID );
     234                $this->comment = \get_comment( $comment_id );
     235                $this->post    = \get_post( (int) $this->comment->comment_post_ID );
    237236        }
    238237
    … …  
    300299         */
    301300        private function comment_action_links( array $actions ): void {
    302                 $links = '';
     301                $links = [];
    303302                foreach ( $actions as $action => $label ) {
    304                         $links .= $this->comment_action_link( $label, $action ) . ' | ';
    305                 }
    306 
    307                 $links = \rtrim( $links, '| ' );
    308 
    309                 $this->message .= $links;
     303                        $links[] = $this->comment_action_link( $label, $action );
     304                }
     305
     306                $this->message .= \implode( ' | ', $links );
    310307        }
    311308
    … …  
    319316         */
    320317        private function comment_action_link( string $label, string $action ): string {
    321                 $url = \admin_url( \sprintf( 'comment.php?action=%s&c=%d', $action, $this->comment_id ) );
     318                $url = \admin_url( \sprintf( 'comment.php?action=%s&c=%d', $action, $this->comment->comment_ID ) );
    322319
    323320                return '<a href="' . \esc_url( $url ) . '">' . \esc_html( $label ) . '</a>';
  • yoast-comment-hacks/tags/2.1.8/inc/email-links.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
    … …  
    4651         */
    4752        public function admin_bar_comment_link(): void {
    48                 if ( ! \is_singular() || $this->options['disable_email_all_commenters'] ) {
     53                if ( ! \current_user_can( 'moderate_comments' ) || ! \is_singular() || $this->options['disable_email_all_commenters'] ) {
    4954                        return;
    5055                }
  • yoast-comment-hacks/tags/2.1.8/inc/forms.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5use WP_Error;
     6use WP_REST_Request;
     7
     8// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     9if ( ! defined( 'ABSPATH' ) ) {
     10        exit;
     11}
    412
    513/**
    … …  
    3139        public function init() {
    3240                $this->options = Hacks::get_options();
    33                 Hacks::get_defaults();
    3441
    3542                if ( $this->options['comment_policy'] ) {
    3643                        \add_action( 'comment_form_after_fields', [ $this, 'comment_form_fields' ] );
     44                        \add_action( 'comment_form_logged_in_after', [ $this, 'comment_form_fields' ] );
    3745                        \add_filter( 'preprocess_comment', [ $this, 'check_comment_policy' ] );
     46                        \add_filter( 'rest_pre_insert_comment', [ $this, 'check_rest_comment_policy' ], 10, 2 );
    3847                }
    3948        }
    … …  
    7281                return $comment_data;
    7382        }
     83
     84        /**
     85         * Require explicit policy acceptance for new REST comments.
     86         *
     87         * @param array<string, string|int>|WP_Error $comment_data Prepared comment data.
     88         * @param WP_REST_Request                    $request      The REST request.
     89         *
     90         * @return array<string, string|int>|WP_Error
     91         */
     92        public function check_rest_comment_policy( $comment_data, WP_REST_Request $request ) {
     93                if ( \is_wp_error( $comment_data ) || \current_user_can( 'moderate_comments' ) ) {
     94                        return $comment_data;
     95                }
     96
     97                $accepted = $request->get_param( 'comment_policy' );
     98                if ( $accepted !== 'on' && $accepted !== true ) {
     99                        return new WP_Error( 'comment_experience_policy', $this->options['comment_policy_error'], [ 'status' => 400 ] );
     100                }
     101
     102                return $comment_data;
     103        }
    74104}
  • yoast-comment-hacks/tags/2.1.8/inc/hacks.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510use EmiliaProjects\WP\Comment\Admin\Admin;
    … …  
    161166                $comment = \get_comment( $comment_id );
    162167
    163                 if ( isset( $comment ) && $comment instanceof WP_Comment && ! empty( $comment->comment_author_url ) ) {
     168                if ( $comment instanceof WP_Comment && ! empty( $comment->comment_author_url ) ) {
    164169                        return \sprintf(
    165170                                '<a href="#" class="comment-remove-url" data-comment-id="%d" aria-label="%s">%s</a>',
    … …  
    251256                        }
    252257                }
    253 
    254258                // Only change $url when the page option is actually set and not zero.
    255                 if ( isset( $this->options['redirect_repeat_page'] ) && (int) $this->options['redirect_repeat_page'] !== 0 ) {
     259                elseif ( isset( $this->options['redirect_repeat_page'] ) && (int) $this->options['redirect_repeat_page'] !== 0 ) {
    256260                        $url = \get_permalink( (int) $this->options['redirect_repeat_page'] );
    257261
    … …  
    283287        private function get_option_from_cache( string $option ) {
    284288                $options = \wp_load_alloptions();
    285                 return isset( $options[ $option ] ) ? $option : false;
     289                return isset( $options[ $option ] ) ? $options[ $option ] : false;
    286290        }
    287291
  • yoast-comment-hacks/tags/2.1.8/inc/length.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5use WP_Error;
     6
     7// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     8if ( ! defined( 'ABSPATH' ) ) {
     9        exit;
     10}
    411
    512/**
    … …  
    2330                // Process the comment and check it for length.
    2431                \add_filter( 'preprocess_comment', [ $this, 'check_comment_length' ] );
     32                \add_filter( 'rest_pre_insert_comment', [ $this, 'check_rest_comment_length' ] );
    2533
    2634                // Add a message to the comment form, before the comment textarea, to inform the user about the allowed comment length.
    … …  
    3846         */
    3947        public function check_comment_length( $comment_data ): array {
    40                 // Bail early for editors and admins, they can leave short or long comments if they want.
    41                 if ( \current_user_can( 'edit_posts' ) ) {
     48                $error = $this->get_length_error( $comment_data['comment_content'] );
     49                if ( $error !== '' ) {
     50                        \wp_die( \esc_html( $error ) . '<br /><a href="javascript:history.go(-1);">' . \esc_html__( 'Go back and try again.', 'yoast-comment-hacks' ) . '</a>' );
     51                }
     52                return $comment_data;
     53        }
     54
     55        /**
     56         * Apply the same length limits to new REST comments.
     57         *
     58         * @param array<string, string|int>|WP_Error $comment_data Prepared comment data.
     59         *
     60         * @return array<string, string|int>|WP_Error
     61         */
     62        public function check_rest_comment_length( $comment_data ) {
     63                if ( \is_wp_error( $comment_data ) ) {
    4264                        return $comment_data;
    4365                }
    4466
    45                 $length = $this->get_comment_length( $comment_data['comment_content'] );
     67                $error = $this->get_length_error( ( $comment_data['comment_content'] ?? '' ) );
     68                if ( $error !== '' ) {
     69                        return new WP_Error( 'comment_experience_length', $error, [ 'status' => 400 ] );
     70                }
     71                return $comment_data;
     72        }
     73
     74        /**
     75         * Get a validation message for a comment's length.
     76         *
     77         * @param string $content Comment content.
     78         *
     79         * @return string
     80         */
     81        private function get_length_error( string $content ): string {
     82                // Preserve the existing exemption for users who can edit posts.
     83                if ( \current_user_can( 'edit_posts' ) ) {
     84                        return '';
     85                }
     86
     87                $length = $this->get_comment_length( $content );
    4688
    4789                // Check for comment length and die if too short or too long.
    48                 $error = false;
     90                $error = '';
    4991                if ( $length < $this->options['mincomlength'] ) {
    5092                        $error = $this->options['mincomlengtherror'];
    … …  
    5496                }
    5597
    56                 if ( $error ) {
    57                         \wp_die( \esc_html( $error ) . '<br /><a href="javascript:history.go(-1);">' . \esc_html__( 'Go back and try again.', 'yoast-comment-hacks' ) . '</a>' );
    58                 }
    59                 return $comment_data;
     98                return $error;
    6099        }
    61100
  • yoast-comment-hacks/tags/2.1.8/inc/notifications.php

    r3218529 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
    … …  
    1924
    2025        /**
     26         * Get the roles eligible to receive comment notifications.
     27         *
     28         * @return string[]
     29         */
     30        public static function get_allowed_roles(): array {
     31                /**
     32                 * Filter which roles may receive notifications. Defaults to contributor and up.
     33                 *
     34                 * @param string[] $roles Array with user roles.
     35                 *
     36                 * @since 1.6.0
     37                 */
     38                return \apply_filters(
     39                        'comment_experience\notification_roles',
     40                        [ 'contributor', 'author', 'editor', 'administrator', 'super-admin' ]
     41                );
     42        }
     43
     44        /**
     45         * Check recipient eligibility when saving and sending notifications.
     46         *
     47         * @param int $user_id The proposed recipient.
     48         *
     49         * @return bool
     50         */
     51        public static function is_allowed_recipient( int $user_id ): bool {
     52                $user = \get_userdata( $user_id );
     53
     54                return $user && $user->user_email !== '' && \array_intersect( $user->roles, self::get_allowed_roles() ) !== [];
     55        }
     56
     57        /**
    2158         * Filter the recipients of the comment notification.
    2259         *
    … …  
    2865        public function filter_notification_recipients( $recipients, $comment_id ): array {
    2966                $comment = \get_comment( $comment_id );
     67                if ( ! $comment ) {
     68                        return $recipients;
     69                }
    3070
    3171                $new_recipient = \get_post_meta( (int) $comment->comment_post_ID, '_comment_notification_recipient', true );
    3272
    33                 if ( ! empty( $new_recipient ) ) {
     73                if ( ! empty( $new_recipient ) && self::is_allowed_recipient( (int) $new_recipient ) ) {
    3474                        $user = \get_userdata( $new_recipient );
    3575
    36                         return [ $user->user_email ];
     76                        if ( $user ) {
     77                                return [ $user->user_email ];
     78                        }
    3779                }
    3880
    … …  
    5193                $comment = \get_comment( $comment_id );
    5294
    53                 if ( $comment->comment_author !== '' && $comment->comment_author_email !== '' ) {
    54                         $name             = \esc_html( $comment->comment_author );
    55                         $message_headers .= "\nReply-To: $name <$comment->comment_author_email>\n";
    56 
     95                if ( $comment->comment_author_email === '' ) {
    5796                        return $message_headers;
    5897                }
    5998
    60                 if ( $comment->comment_author_email !== '' ) {
    61                         $message_headers .= "\nReply-To: $comment->comment_author_email <$comment->comment_author_email>\n";
     99                $name = ( $comment->comment_author !== '' ) ? \esc_html( $comment->comment_author ) : $comment->comment_author_email;
    62100
    63                         return $message_headers;
    64                 }
     101                $message_headers .= "\nReply-To: $name <$comment->comment_author_email>\n";
    65102
    66103                return $message_headers;
  • yoast-comment-hacks/tags/2.1.8/inc/progress-planner-tasks.php

    r3290299 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510use Progress_Planner\Suggested_Tasks\Tasks\Providers\Provider;
  • yoast-comment-hacks/tags/2.1.8/inc/progress-planner/comment-moderation.php

    r3438581 r3807202  
    44
    55use Progress_Planner\Suggested_Tasks\Providers\Tasks;
     6
     7// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     8if ( ! defined( 'ABSPATH' ) ) {
     9        exit;
     10}
    611
    712if ( ! \class_exists( '\Progress_Planner\Suggested_Tasks\Providers\Tasks' ) ) {
    … …  
    8691                );
    8792
    88                 return $comments > 0; // @phpstan-ignore-line
     93                return $comments > 0;
    8994        }
    9095
  • yoast-comment-hacks/tags/2.1.8/inc/progress-planner/comment-policy.php

    r3438581 r3807202  
    55use EmiliaProjects\WP\Comment\Inc\Hacks;
    66use Progress_Planner\Suggested_Tasks\Providers\Tasks;
     7
     8// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     9if ( ! defined( 'ABSPATH' ) ) {
     10        exit;
     11}
    712
    813if ( ! \class_exists( '\Progress_Planner\Suggested_Tasks\Providers\Tasks' ) ) {
    … …  
    7984         */
    8085        public function should_add_task() {
    81                 if ( ! (int) $this->options['comment_policy_page'] || ! (int) $this->options['comment_policy'] ) {
    82                         return true;
    83                 }
    84 
    85                 return false;
     86                return ! (int) $this->options['comment_policy_page'] || ! (int) $this->options['comment_policy'];
    8687        }
    8788
  • yoast-comment-hacks/tags/2.1.8/inc/progress-planner/comment-redirect.php

    r3438581 r3807202  
    55use EmiliaProjects\WP\Comment\Inc\Hacks;
    66use Progress_Planner\Suggested_Tasks\Providers\Tasks;
     7
     8// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     9if ( ! defined( 'ABSPATH' ) ) {
     10        exit;
     11}
    712
    813if ( ! \class_exists( '\Progress_Planner\Suggested_Tasks\Providers\Tasks' ) ) {
    … …  
    7883         */
    7984        public function should_add_task() {
    80                 if ( ! $this->options['redirect_page'] ) {
    81                         return true;
    82                 }
    83 
    84                 return false;
     85                return ! $this->options['redirect_page'];
    8586        }
    8687
  • yoast-comment-hacks/tags/2.1.8/readme.md

    r3438581 r3807202  
    1010[![Test](https://github.com/ProgressPlanner/comment-hacks/actions/workflows/test.yml/badge.svg)](https://github.com/ProgressPlanner/comment-hacks/actions/workflows/test.yml)
    1111
     12![Comment Experience banner](.wordpress-org/github_banner_comment_experience_pp.png)
     13
    1214# Comment Experience
    1315
    14 Improve the comment experience on your site. Adds lots of features to make commenting easier and more engaging.
     16Make WordPress comments easier to manage with cleaner moderation emails, better routing, comment policy controls, length limits, and tools for following up with commenters.
    1517
    16 ## Description
     18## Why this plugin exists
    1719
    18 This plugin adds many small improvements around core WordPress comments to make them more bearable:
     20Core WordPress comments work, but moderation and follow-up can feel clunky. Comment Experience adds practical improvements for site owners and editors who want a cleaner, more manageable comment workflow without replacing the native comments system.
    1921
    20 * Cleaner comment notification emails.
    21 * The option to enforce a comment policy.
    22 * The option to forward comments to an email address (for instance for your support team) and then trash them.
    23 * The option to disallow comments below a certain length.
    24 * The option to redirect first time commenters to a "thank you" page.
    25 * An input field on the comment edit screen to change the comment parent ID.
    26 * Links in the admin comments section to email individual commenters.
    27 * A button in the WP toolbar to email all the commenters on a post.
     22## What it helps you do
     23
     24- Clean up comment notification emails so moderation is easier.
     25- Require acceptance of a comment policy before submission.
     26- Forward comments to another email address and optionally trash them.
     27- Set minimum and maximum comment lengths.
     28- Redirect first-time commenters to a thank-you page.
     29- Change a comment's parent ID from the comment edit screen.
     30- Email an individual commenter from the comments screen.
     31- Email all commenters on a post from the admin bar.
     32- Route comment emails to another user from a post's discussion settings.
     33
     34## Installation
     35
     36### From WordPress admin
     37
     381. In your WordPress dashboard, go to **Plugins → Add New**.
     392. Search for **Comment Experience** or **comment hacks**.
     403. Install and activate the plugin.
     414. Go to **Settings → Comment Experience** to configure the available options.
     42
     43### Manual installation
     44
     451. Download the plugin zip.
     462. Upload the `comment-hacks` folder to `/wp-content/plugins/`.
     473. Activate the plugin in **Plugins**.
     484. Go to **Settings → Comment Experience** to configure the available options.
    2849
    2950## Screenshots
    3051
    31 Screenshot of a clean comment notification email:<br>
    32 ![Screenshot of a clean comment notification email](.wordpress-org/screenshot-1.png)<br>
    33 <br>
    34 The comment parent edit box:<br>
    35 ![The comment parent edit box](.wordpress-org/screenshot-2.png)<br>
    36 <br>
    37 The plugins admin settings:<br>
    38 ![The plugins admin settings](.wordpress-org/screenshot-3.png)<br>
    39 <br>
    40 The button on the frontend to email all the commenters on a post:<br>
    41 ![The button to email all commenters](.wordpress-org/screenshot-4.png)<br>
    42 <br>
    43 The link in the backend to email an individual commenters on a post:<br>
    44 ![The button to email all commenters](.wordpress-org/screenshot-5.png)<br><br>
     52### Cleaner comment notification emails
     53![Cleaner comment notification emails](.wordpress-org/screenshot-1.png)
     54
     55### Edit a comment's parent directly from the comment screen
     56![Edit a comment's parent directly from the comment screen](.wordpress-org/screenshot-2.png)
     57
     58### Configure comment length, policy, redirects, email links, and forwarding from one settings screen
     59![Configure comment settings](.wordpress-org/screenshot-3.png)
     60
     61### Email all commenters on a post from the WordPress admin bar
     62![Email all commenters on a post from the WordPress admin bar](.wordpress-org/screenshot-4.png)
     63
     64### Contact an individual commenter from the comments list table
     65![Contact an individual commenter from the comments list table](.wordpress-org/screenshot-5.png)
     66
     67## Support, issues, and security
     68
     69- Questions or support: [WordPress.org support forum](https://wordpress.org/support/plugin/yoast-comment-hacks/)
     70- Bug reports and feature requests: [GitHub issues](https://github.com/ProgressPlanner/comment-hacks/issues)
     71- Security reports: [Patchstack VDP](https://patchstack.com/database/vdp/comment-hacks)
     72
     73## Contributing
     74
     75Contributions are welcome. Please read [`.github/CONTRIBUTING.md`](.github/CONTRIBUTING.md) before opening an issue or pull request.
     76
     77## Links
     78
     79- [Plugin page on WordPress.org](https://wordpress.org/plugins/yoast-comment-hacks/)
     80- [Progress Planner](https://progressplanner.com/)
  • yoast-comment-hacks/tags/2.1.8/readme.txt

    r3438581 r3807202  
    11=== Comment Experience ===
    2 Contributors: joostdevalk
    3 Tags: comments, spam, emails
    4 Text Domain: comment-hacks
    5 Requires at least: 6.6
    6 Tested up to: 6.8
    7 Stable tag: 2.1.7
     2Contributors: joostdevalk, aristath, filipi, progressplanner
     3Tags: comments, comment moderation, comment emails, discussion, comment policy
     4Text Domain: yoast-comment-hacks
     5Stable tag: 2.1.8
    86Requires at least: 6.7
    9 Tested up to: 6.9
     7Tested up to: 7.1
    108Requires PHP: 7.4
    11 Stable tag: 2.1.6
    12 License: GPLv3
     9License: GPL-3.0-or-later
    1310License URI: https://www.gnu.org/licenses/gpl-3.0.html
    14 Requires PHP: 7.4
    15 
    16 Make comments management easier by applying the simple hacks Joost has gathered over the years.
     11
     12Improve WordPress comment moderation with cleaner emails, comment policy checks, routing, redirects, and length controls.
    1713
    1814== Description ==
    1915
    20 Make comments management easier by applying the simple hacks Joost has gathered over the years.
    21 
    22 This plugin adds some small hacks around core WordPress comments to make them more bearable:
    23 
    24 * Cleaner comment notification emails.
    25 * The option to enforce a comment policy: just create a comment policy page, toggle the option on and select it, and
    26 commenters will have to accept your comment policy before being able to comment.
    27 * The option to forward comments to an email address (for instance for your support team) and then trash them.
    28 * The option to disallow comments below and above a certain length.
    29 * The option to redirect first time commenters to a "thank you" page.
    30 * An input field on the comment edit screen to change the comment parent ID.
    31 * Links in the admin comments section to email individual commenters.
    32 * A button in the WP toolbar to email all the commenters on a post.
    33 * Adds a comment routing option. This adds a dropdown in a post's discussion settings, allowing the routing of comment emails to another user.
    34 
    35 See the screenshots to get an even better idea of the plugins' functionality.
    36 
    37 === Have you found an issue? ===
    38 
    39 If you have bugs to report, please go to [the plugin's GitHub repository](https://github.com/emilia-capital/comment-hacks). For security issues, please use our [vulnerability disclosure program](https://patchstack.com/database/vdp/comment-hacks), which is managed by PatchStack. They will assist you with verification, CVE assignment, and, of course, notify us.
    40 
     16Comment Experience helps you manage WordPress comments more efficiently without replacing the native comments system.
     17
     18If you moderate comments regularly, this plugin gives you practical improvements that make follow-up easier, keep discussions clearer, and reduce repetitive admin work.
     19
     20= Features that improve comment moderation =
     21
     22* Clean up comment notification emails so important details are easier to scan.
     23* Require commenters to accept a comment policy before submitting.
     24* Forward comments to another email address and optionally trash them after forwarding.
     25* Set minimum and maximum comment lengths.
     26* Redirect first-time commenters to a thank-you page.
     27* Change a comment's parent ID from the comment edit screen.
     28* Email an individual commenter directly from the comments list.
     29* Email all commenters on a post from the WordPress admin bar.
     30* Route comment emails to another user from a post's discussion settings.
     31
     32= Who this plugin is for =
     33
     34Comment Experience is useful for site owners, editors, community managers, and support teams who rely on WordPress comments and want a smoother moderation workflow.
     35
     36= Need help or want to report something? =
     37
     38For support, visit the [WordPress.org support forum](https://wordpress.org/support/plugin/yoast-comment-hacks/).
     39
     40For bugs or feature requests, use the [GitHub repository](https://github.com/ProgressPlanner/comment-hacks).
     41
     42For security issues, please use our [vulnerability disclosure program](https://patchstack.com/database/vdp/comment-hacks), managed by Patchstack.
    4143
    4244== Installation ==
    4345
    44 **Install through your backend**
    45 
    46 1. Search for "comment hacks", click install.
    47 1. You're done.
    48 
    49 **Install manually**
     46= Install from your WordPress dashboard =
     47
     481. Go to **Plugins > Add New Plugin**.
     492. Search for **Comment Experience** or **comment hacks**.
     503. Click **Install Now** and then **Activate**.
     514. Go to **Settings > Comment Experience** to configure the plugin.
     52
     53= Install manually =
    5054
    51551. Download and unzip the plugin.
    52 1. Upload the `comment-hacks` directory to the `/wp-content/plugins/` directory.
    53 1. Activate the plugin through the 'Plugins' menu in WordPress.
    54 1. Configure your settings on the Settings &rarr; Comment Experience screen.
     562. Upload the `comment-hacks` directory to the `/wp-content/plugins/` directory.
     573. Activate the plugin through the **Plugins** menu in WordPress.
     584. Go to **Settings > Comment Experience** to configure the plugin.
     59
     60== Frequently Asked Questions ==
     61
     62= What does Comment Experience do? =
     63
     64Comment Experience improves WordPress comment moderation with cleaner notification emails, comment policy options, comment routing, redirects, and comment length controls.
     65
     66= Does it replace the default WordPress comments system? =
     67
     68No. It enhances core WordPress comments with extra moderation and workflow features.
     69
     70= Can I require visitors to accept a comment policy? =
     71
     72Yes. You can create a comment policy page, enable the option, and require acceptance before a comment can be submitted.
     73
     74= Can I limit how short or long comments can be? =
     75
     76Yes. The plugin lets you configure both minimum and maximum comment length limits.
     77
     78= Can I send comment notifications to someone else? =
     79
     80Yes. You can forward comments to another email address, and you can also route comment emails to another user from a post's discussion settings.
    5581
    5682== Screenshots ==
    5783
    58 1. Screenshot of a clean comment notification email.
    59 2. The comment parent edit box.
    60 3. The plugins admin settings.
    61 4. The button on the frontend to email all the commenters on a post.
    62 5. The link in the backend to email an individual commenters on a post.
     841. Cleaner WordPress comment notification email that is easier to scan while moderating.
     852. Comment parent field on the comment edit screen for fixing comment thread hierarchy.
     863. Comment Experience settings for comment length limits, comment policy, email links, redirects, clean emails, and forwarding.
     874. Admin bar button for emailing all commenters on a post.
     885. Comments list action link for emailing an individual commenter.
    6389
    6490== Changelog ==
    6591
     92= 2.1.8 =
     93* Security: strengthen permission checks for comment actions and notification recipients.
     94* Security: escape comment content in notification emails and restrict user searches to public names.
     95* Apply comment length limits and comment policy acceptance to REST API comment creation.
     96* Replace the notification recipient dropdown with an AJAX-powered user search.
     97* Fix first-time commenter redirects, cached option values, and email formatting for older comments.
     98* Preserve the ability to remove a comment's parent by clearing the parent field.
     99* Update compatibility information for WordPress 7.1.
     100
    66101= 2.1.7 =
    67 
    68 * Minor updates, name change mostly.
     102* Maintenance release with minor updates and the Comment Experience name change.
    69103
    70104= 2.1.6 =
    71 
    72 * Compatibility with Progress Planner v1.9
     105* Compatibility with Progress Planner v1.9.
    73106
    74107= 2.1.5 =
    75 
    76 * Compatibility with Progress Planner v1.8
     108* Compatibility with Progress Planner v1.8.
    77109
    78110= 2.1.4 =
    79 
    80111* Add compatibility with WordPress 6.8.
    81112* Save proper values for Redirect page settings when no selection is made.
    82 * Run upgrade routine only when plugin version is increased
    83 * Migrate PHPUnit XML schema
    84 * Compatibility with Progress Planner v1.4
     113* Run the upgrade routine only when the plugin version increases.
     114* Migrate PHPUnit XML schema.
     115* Compatibility with Progress Planner v1.4.
    85116
    86117= 2.1.3 =
    87 
    88 * Add necessary compatibility to Progress Planner integration for the upcoming WordPress 6.8.
     118* Add compatibility for the upcoming WordPress 6.8 release in Progress Planner integration.
    89119
    90120= 2.1.2 =
    91 
    92121* Rename the plugin from "Comment Hacks" to "Comment Experience".
    93 * Bring up to date with changes in Progress Planner
     122* Bring the plugin up to date with changes in Progress Planner.
    94123
    95124= 2.1.1 =
    96 
    97125* Don't enqueue the remove URL script on the frontend for logged out users or users without the `edit_posts` capability.
    98126
    99127= 2.1 =
    100 
    101 * Added a link to remove the author's URL from the comment from the frontend.
    102 * Fix comment policy function for admins and editors.
     128* Add a link to remove the author's URL from the comment from the frontend.
     129* Fix the comment policy function for admins and editors.
    103130
    104131= 1.9.4 =
    105 
    106132* Fix fatal due to wrong class import, props [@andizer](https://profiles.wordpress.org/andizer/).
    107133
    108134= 1.9.3 =
    109 
    110 * Fix bug where comment reroute recipient would not save.
    111 * Added an option to disable the "Email all commenters" admin bar button.
     135* Fix bug where the comment reroute recipient would not save.
     136* Add an option to disable the "Email all commenters" admin bar button.
    112137
    113138= 1.9.2 =
    114 
    115139* Fix missing autoloader.
    116140
    117141= 1.9 =
    118 
    119 * Introduces a new option to the plugin: adding a comment policy was never easier than this: just create a comment
    120 policy page, toggle the option on and select it, and commenters will have to accept your comment policy before being
    121 able to comment.
    122 * Fixes a bug where editing a comment on the quick edit screen would cause that comment to lose its parent.
    123 * Enhances performance by preventing too frequent option updates.
    124 * Remove all direct DB queries in favor of using WordPress core functions.
     142* Add a comment policy option so commenters must accept your policy before commenting.
     143* Fix a bug where editing a comment on the quick edit screen would cause that comment to lose its parent.
     144* Improve performance by preventing too frequent option updates.
     145* Remove all direct database queries in favor of WordPress core functions.
    125146
    126147= 1.8.1 =
    127 
    128 * Fixed a couple of PHP 7.4 related issues.
     148* Fix a couple of PHP 7.4 related issues.
    129149
    130150= 1.8 =
    131 
    132 * Changed namespace to `JoostBlog`.
    133 * Removed Yoast branding.
    134 * Updated plugin to require PHP 7.4.
     151* Change namespace to `JoostBlog`.
     152* Remove Yoast branding.
     153* Update the plugin to require PHP 7.4.
    135154
    136155= 1.7 =
    137 
    138 * Bugfixes:
    139     * Fixed: the "Email commenters" link would not be displayed in the WordPress admin bar and in the Comments list.
    140     * Fixed: the "Email commenters" link in the front end admin bar wouldn't work when jQuery wasn't enqueued.
    141     * Fixed: the notification emails for new comments would have incorrect content for the Author line and the text displayed before the comment.
     156* Fix the "Email commenters" link not displaying in the WordPress admin bar and comments list.
     157* Fix the frontend admin bar email commenters link when jQuery was not enqueued.
     158* Fix incorrect author line and comment intro text in notification emails.
    142159
    143160= 1.6 =
    144 
    145161* Fix language packs.
    146162
    147163= 1.5 =
    148 
    149 * Bugfixes:
    150     * Fixed: comment recipient dropdown would reset on reload of the page.
    151     * Fixed: admin bar CSS showing when no admin bar is showing.
     164* Fix the comment recipient dropdown resetting on page reload.
     165* Fix admin bar CSS showing when the admin bar is not visible.
    152166
    153167= 1.4 =
    154 
    155 * Enhancements:
    156     * Limit the roles shown in the comment notifications dropdown to roles that normally exist and can write. Introduces a new filter to allow expanding them.
     168* Limit the roles shown in the comment notifications dropdown to roles that normally exist and can write.
     169* Introduce a new filter to allow expanding those roles.
    157170
    158171= 1.3 =
    159 
    160 * Enhancements:
    161     * Add option to restrict comments that are too long, next to too small.
    162     * Add `reply-to` header to comment notification and moderation emails, pointing to the post author.
    163     * Preserve the active tab when saving settings.
    164     * Remove `[...]` from pingback / trackback excerpt in cleaned emails as that's already included by core.
    165     * Replace link to ARIN with link to [ip-lookup.net](http://ip-lookup.net) for details about the IP.
    166     * Refactored code for readability and code quality.
    167     * Refactor upgrade routine to do less DB queries.
     172* Add an option to restrict comments that are too long, next to comments that are too short.
     173* Add a `reply-to` header to comment notification and moderation emails that points to the post author.
     174* Preserve the active tab when saving settings.
     175* Remove `[...]` from pingback and trackback excerpts in cleaned emails because core already includes it.
     176* Replace the ARIN link with [ip-lookup.net](http://ip-lookup.net) for IP details.
     177* Refactor code for readability and code quality.
     178* Refactor the upgrade routine to do fewer database queries.
    168179
    169180= 1.2 =
    170 
    171 Fixes several issues:
    172 
    173 * Differentiate between AJAX request and normal POST for nonce checking, fixes #7.
    174 * Make sure comment type isn't empty in cleaned email, fixes #8.
    175 * Allow setting the comment parent to 0, fixes #10.
    176 * Prevents defaults from being reinstated, fixes #14.
    177 
    178 Also:
    179 
    180 * Adds translator comments to all strings with `sprintf` / `printf`.
    181 * Updates to new version of Yoast i18n, in the process switching from `translate.yoast.com` to `translate.wordpress.org` and removing packaged translations.
    182 * Added `yarn.lock` and removed no longer needed i18n grunt tasks.
     181* Differentiate between AJAX requests and normal POST requests for nonce checking, fixing #7.
     182* Make sure the comment type is not empty in cleaned emails, fixing #8.
     183* Allow setting the comment parent to 0, fixing #10.
     184* Prevent defaults from being reinstated, fixing #14.
     185* Add translator comments to all strings with `sprintf` / `printf`.
     186* Update to a new version of Yoast i18n, switching from `translate.yoast.com` to `translate.wordpress.org` and removing packaged translations.
     187* Add `yarn.lock` and remove no longer needed i18n grunt tasks.
    183188
    184189= 1.1.1 =
    185 
    186 * Add text domain so the plugin can be translated.
     190* Add a text domain so the plugin can be translated.
    187191
    188192= 1.1 =
    189 
    190 * Add comment routing option, adds a dropdown in a post's discussion settings, allowing the routing of comment emails to another user.
     193* Add a comment routing option with a dropdown in a post's discussion settings for routing comment emails to another user.
    191194
    192195= 1.0 =
    193 
    194196* Initial version.
     197
     198== Upgrade Notice ==
     199
     200= 2.1.8 =
     201Security and reliability improvements. REST clients must send comment_policy: true or comment_policy: "on" when comment policy acceptance is enabled.
     202
     203= 2.1.7 =
     204This maintenance release keeps Comment Experience current and aligned with its updated branding.
  • yoast-comment-hacks/trunk/admin/admin.php

    r3438581 r3807202  
    33namespace EmiliaProjects\WP\Comment\Admin;
    44
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
     9
    510use EmiliaProjects\WP\Comment\Inc\Hacks;
     11use EmiliaProjects\WP\Comment\Inc\Notifications;
    612use WP_Comment;
    713use WP_Post;
    … …  
    6369
    6470                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_discussion_settings_script' ] );
     71
     72                \add_action( 'wp_ajax_ch_search_users', [ $this, 'ajax_search_users' ] );
    6573
    6674                new Comment_Parent();
    … …  
    135143                        && isset( $_GET['comment_id'] )
    136144                        && $_GET['ch_action'] === 'forward_comment'
    137                         && \wp_verify_nonce( \wp_strip_all_tags( \wp_unslash( $_GET['nonce'] ) ), 'comment-hacks-forward' )
    138145                ) {
    139146                        $comment_id = (int) $_GET['comment_id'];
    140                         $comment    = \get_comment( $comment_id );
     147                        if ( $comment_id <= 0 || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_GET['nonce'] ) ), 'comment-hacks-forward_' . $comment_id ) ) {
     148                                return;
     149                        }
     150
     151                        $comment = \get_comment( $comment_id );
     152                        if ( ! $comment || ! \current_user_can( 'edit_comment', $comment_id ) ) {
     153                                return;
     154                        }
    141155
    142156                        echo '<div class="msg updated"><p>';
    … …  
    157171
    158172                        if ( ! empty( $this->options['forward_extra'] ) ) {
    159                                 $intro .= $this->options['forward_extra'] . "\n\n";
     173                                $intro .= \esc_html( $this->options['forward_extra'] ) . "\n\n";
    160174                        }
    161175
    … …  
    167181                        $intro .= "\n\n";
    168182
    169                         $content = \nl2br( $intro . $comment->comment_content );
     183                        $content = \nl2br( $intro . \esc_html( $comment->comment_content ) );
    170184
    171185                        $headers = [
    … …  
    192206         */
    193207        public function forward_to_support_action_link( $actions, $comment ): array {
    194                 if ( empty( $this->options['forward_email'] ) ) {
     208                if ( empty( $this->options['forward_email'] ) || ! \current_user_can( 'edit_comment', (int) $comment->comment_ID ) ) {
    195209                        return $actions;
    196210                }
    … …  
    205219                }
    206220
    207                 $actions['ch_forward'] = '<a href="' . \esc_url( \admin_url( 'edit-comments.php' ) . '?comment_id=' . $comment->comment_ID . '&ch_action=forward_comment&nonce=' . \wp_create_nonce( 'comment-hacks-forward' ) ) . '">' . \esc_html( $label ) . '</a>';
     221                $actions['ch_forward'] = '<a href="' . \esc_url( \admin_url( 'edit-comments.php' ) . '?comment_id=' . $comment->comment_ID . '&ch_action=forward_comment&nonce=' . \wp_create_nonce( 'comment-hacks-forward_' . $comment->comment_ID ) ) . '">' . \esc_html( $label ) . '</a>';
    208222
    209223                return $actions;
    … …  
    236250         */
    237251        public function meta_box_callback( $post ): void {
     252                $selected_id   = (int) \get_post_meta( $post->ID, self::NOTIFICATION_RECIPIENT_KEY, true );
     253                $selected_name = '';
     254
     255                if ( $selected_id > 0 ) {
     256                        $user = \get_userdata( $selected_id );
     257                        if ( $user ) {
     258                                $selected_name = $user->display_name;
     259                        }
     260                }
     261
    238262                ?>
    239263                <input
    … …  
    242266                        value="<?php echo \esc_attr( \wp_create_nonce( 'comment_notification_recipient_nonce' ) ); ?>"
    243267                />
    244                 <label for="comment_notification_recipient">
     268                <label for="comment_notification_recipient_search">
    245269                        <?php \esc_html_e( 'Comment notification recipients:', 'yoast-comment-hacks' ); ?>
    246270                </label>
    247271                <br/>
     272                <input
     273                        type="hidden"
     274                        name="comment_notification_recipient"
     275                        id="comment_notification_recipient"
     276                        value="<?php echo \esc_attr( (string) $selected_id ); ?>"
     277                />
     278                <input
     279                        type="text"
     280                        id="comment_notification_recipient_search"
     281                        value="<?php echo \esc_attr( $selected_name ); ?>"
     282                        placeholder="<?php \esc_attr_e( 'Search for a user...', 'yoast-comment-hacks' ); ?>"
     283                        class="widefat"
     284                        autocomplete="off"
     285                />
     286                <ul id="comment_notification_recipient_results" style="display:none;margin:0;padding:0;list-style:none;border:1px solid #ddd;background:#fff;max-height:150px;overflow-y:auto;"></ul>
     287                <?php if ( $selected_id > 0 ) : ?>
     288                <a href="#" id="comment_notification_recipient_clear" style="display:inline;">
     289                        <?php \esc_html_e( 'Reset to post author', 'yoast-comment-hacks' ); ?>
     290                </a>
     291                <?php else : ?>
     292                <a href="#" id="comment_notification_recipient_clear" style="display:none;">
     293                        <?php \esc_html_e( 'Reset to post author', 'yoast-comment-hacks' ); ?>
     294                </a>
     295                <?php endif; ?>
     296                <p class="description"><?php \esc_html_e( 'Leave empty to use post author.', 'yoast-comment-hacks' ); ?></p>
    248297                <?php
    249 
    250                 /**
    251                  * This filter allows filtering which roles should be shown in the dropdown for notifications.
    252                  * Defaults to contributor and up.
    253                  *
    254                  * @param array $roles Array with user roles.
    255                  *
    256                  * @since 1.6.0
    257                  */
    258                 $roles = \apply_filters(
    259                         'comment_experience\notification_roles',
    260                         [ 'contributor', 'author', 'editor', 'administrator', 'super-admin' ]
    261                 );
    262 
    263                 \wp_dropdown_users(
     298        }
     299
     300        /**
     301         * AJAX handler for searching users.
     302         *
     303         * @return void
     304         */
     305        public function ajax_search_users(): void {
     306                \check_ajax_referer( 'ch_search_users_nonce', 'nonce' );
     307
     308                if ( ! \current_user_can( 'edit_posts' ) ) {
     309                        \wp_send_json_error( 'Unauthorized' );
     310                }
     311
     312                $search = isset( $_GET['search'] ) ? \sanitize_text_field( \wp_unslash( $_GET['search'] ) ) : '';
     313
     314                if ( \strlen( $search ) < 2 ) {
     315                        \wp_send_json_success( [] );
     316                }
     317
     318                $users = \get_users(
    264319                        [
    265                                 'selected'          => \get_post_meta( $post->ID, self::NOTIFICATION_RECIPIENT_KEY, true ),
    266                                 'show_option_none'  => 'Post author',
    267                                 'name'              => 'comment_notification_recipient',
    268                                 'id'                => 'comment_notification_recipient',
    269                                 'role__in'          => $roles,
    270                                 'option_none_value' => 0,
     320                                'search'         => '*' . $search . '*',
     321                                'search_columns' => [ 'display_name', 'user_nicename' ],
     322                                'role__in'       => Notifications::get_allowed_roles(),
     323                                'number'         => 20,
     324                                'orderby'        => 'display_name',
     325                                'order'          => 'ASC',
    271326                        ]
    272327                );
     328
     329                $results = [];
     330                foreach ( $users as $user ) {
     331                        $results[] = [
     332                                'id'   => $user->ID,
     333                                'name' => $user->display_name,
     334                        ];
     335                }
     336
     337                \wp_send_json_success( $results );
    273338        }
    274339
    … …  
    293358         * Enqueue our admin script.
    294359         *
    295          * @return void
    296          */
    297         public function enqueue(): void {
     360         * @param string $hook_suffix The current admin page.
     361         *
     362         * @return void
     363         */
     364        public function enqueue( $hook_suffix ): void {
    298365                $page = \filter_input( \INPUT_GET, 'page' );
    299366
    … …  
    314381                        );
    315382                }
     383
     384                if ( $hook_suffix === 'post.php' || $hook_suffix === 'post-new.php' ) {
     385                        \wp_enqueue_script(
     386                                'emiliaprojects-comment-hacks-user-search',
     387                                \plugins_url( 'admin/assets/js/user-search.js', \EMILIA_COMMENT_HACKS_FILE ),
     388                                [ 'jquery' ],
     389                                \EMILIA_COMMENT_HACKS_VERSION,
     390                                true
     391                        );
     392
     393                        \wp_localize_script(
     394                                'emiliaprojects-comment-hacks-user-search',
     395                                'chUserSearch',
     396                                [
     397                                        'ajax_url' => \admin_url( 'admin-ajax.php' ),
     398                                        'nonce'    => \wp_create_nonce( 'ch_search_users_nonce' ),
     399                                ]
     400                        );
     401
     402                        \wp_add_inline_style(
     403                                'wp-admin',
     404                                '#comment_notification_recipient_results li { padding: 5px; margin: 0; cursor: pointer; } #comment_notification_recipient_results li:hover { background: #f0f0f1; }'
     405                        );
     406                }
    316407        }
    317408
    … …  
    325416        public function save_reroute_comment_emails( $post_id ): void {
    326417
    327                 if ( ! isset( $_POST['comment_notification_recipient'] ) || ! \wp_verify_nonce( \filter_input( \INPUT_POST, 'comment_notification_recipient_nonce' ), 'comment_notification_recipient_nonce' ) ) {
     418                if (
     419                        ! isset( $_POST['comment_notification_recipient'], $_POST['comment_notification_recipient_nonce'] )
     420                        || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['comment_notification_recipient_nonce'] ) ), 'comment_notification_recipient_nonce' )
     421                        || ! \current_user_can( 'edit_post', $post_id )
     422                ) {
    328423                        return;
    329424                }
    330425
    331                 $recipient_id = (int) \sanitize_key( \wp_unslash( $_POST['comment_notification_recipient'] ) );
    332                 if ( $recipient_id > 0 ) {
     426                $recipient_id = \filter_var( \wp_unslash( $_POST['comment_notification_recipient'] ), \FILTER_VALIDATE_INT );
     427                if ( $recipient_id === 0 ) {
     428                        \delete_post_meta( $post_id, self::NOTIFICATION_RECIPIENT_KEY );
     429                }
     430                elseif ( $recipient_id > 0 && Notifications::is_allowed_recipient( $recipient_id ) ) {
    333431                        \update_post_meta( $post_id, self::NOTIFICATION_RECIPIENT_KEY, $recipient_id );
    334432                }
    … …  
    402500         */
    403501        private function sanitize_bool( $value ): bool {
    404                 return ( $value || ! empty( $value ) );
     502                return (bool) $value;
    405503        }
    406504
    … …  
    478576                                        '<code style="background-color: #eee; margin: 0; padding: 0;">',
    479577                                        // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode.
    480                                         \highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true ),
    481                                         $num
     578                                        \highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true )
    482579                                );
    483580                                ?>
  • yoast-comment-hacks/trunk/admin/comment-parent.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Admin;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
    … …  
    3439         */
    3540        public function load_comment_parent_box() {
    36                 if ( \function_exists( 'add_meta_box' ) ) {
    37                         \add_meta_box(
    38                                 'comment_parent',
    39                                 \esc_html__( 'Comment Parent', 'yoast-comment-hacks' ),
    40                                 [
    41                                         $this,
    42                                         'comment_parent_box',
    43                                 ],
    44                                 'comment',
    45                                 'normal'
    46                         );
    47                 }
     41                \add_meta_box(
     42                        'comment_parent',
     43                        \esc_html__( 'Comment Parent', 'yoast-comment-hacks' ),
     44                        [
     45                                $this,
     46                                'comment_parent_box',
     47                        ],
     48                        'comment',
     49                        'normal'
     50                );
    4851        }
    4952
    … …  
    5154         * Updates the comment parent field.
    5255         *
     56         * @param int $comment_id The comment ID supplied by the edit_comment hook.
     57         *
    5358         * @return void
    5459         */
    55         public function update_comment_parent() {
    56                 $comment_parent = \filter_input( \INPUT_POST, 'epch_comment_parent', \FILTER_VALIDATE_INT );
    57                 $comment_id     = \filter_input( \INPUT_POST, 'comment_ID', \FILTER_VALIDATE_INT );
    58                 $action         = \filter_input( \INPUT_POST, 'action' );
    59 
    60                 if ( $action === 'edit-comment' ) {
    61                         return; // We're on the quick edit screen. As the comment parent isn't sent along here, we might lose it if we do anything.
     60        public function update_comment_parent( $comment_id ) {
     61                if (
     62                        ! \is_admin() || \wp_doing_ajax()
     63                        || ! isset( $_POST['action'], $_POST['comment_ID'], $_POST['epch_comment_parent'], $_POST['_wpnonce'] )
     64                        || $_POST['action'] !== 'editedcomment'
     65                        || (int) $_POST['comment_ID'] !== (int) $comment_id
     66                        || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['_wpnonce'] ) ), 'update-comment_' . $comment_id )
     67                        || ! \current_user_can( 'edit_comment', $comment_id )
     68                ) {
     69                        return;
    6270                }
    6371
    64                 if ( empty( $comment_id ) && empty( $comment_parent ) ) {
    65                         return; // There might be another reason for a comment to be updated.
     72                if ( ! \is_string( $_POST['epch_comment_parent'] ) ) {
     73                        return;
    6674                }
    6775
    68                 if ( \function_exists( 'wp_doing_ajax' ) && \wp_doing_ajax() ) {
    69                         \check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
     76                // An emptied field means "no parent", as it did before this field was validated.
     77                $raw_parent     = \sanitize_text_field( \wp_unslash( $_POST['epch_comment_parent'] ) );
     78                $comment_parent = ( $raw_parent === '' ) ? 0 : \filter_var( $raw_parent, \FILTER_VALIDATE_INT );
     79                $comment        = \get_comment( $comment_id );
     80                if ( $comment_parent === false || $comment_parent < 0 || ! $comment || $comment_parent === (int) $comment_id ) {
     81                        return;
    7082                }
    7183
    72                 if ( ! \function_exists( 'wp_doing_ajax' ) || ! \wp_doing_ajax() ) {
    73                         \check_admin_referer( 'update-comment_' . $comment_id );
     84                // Reject missing parents, parents on other posts, and circular threads.
     85                $ancestor_id = $comment_parent;
     86                $seen        = [ (int) $comment_id ];
     87                while ( $ancestor_id > 0 ) {
     88                        $parent = \get_comment( $ancestor_id );
     89                        if ( ! $parent || (int) $parent->comment_post_ID !== (int) $comment->comment_post_ID || \in_array( $ancestor_id, $seen, true ) ) {
     90                                return;
     91                        }
     92                        $seen[]      = $ancestor_id;
     93                        $ancestor_id = (int) $parent->comment_parent;
    7494                }
    7595
    76                 if ( ! isset( $comment_parent ) ) {
    77                         $comment_parent = 0;
    78                 }
    79 
    80                 if ( $comment_id ) {
    81                         $comment                 = \get_comment( $comment_id );
    82                         $comment->comment_parent = $comment_parent;
    83 
    84                         // Remove our filter, or we'll keep looping.
    85                         \remove_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
    86                         \wp_update_comment( (array) $comment );
    87 
    88                         // Add our filter back.
    89                         \add_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
    90                 }
     96                // Remove our filter, or we'll keep looping.
     97                \remove_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
     98                \wp_update_comment(
     99                        [
     100                                'comment_ID'     => $comment_id,
     101                                'comment_parent' => $comment_parent,
     102                        ]
     103                );
     104                \add_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
    91105        }
    92106}
  • yoast-comment-hacks/trunk/admin/views/comment-parent-box.php

    r3438581 r3807202  
    11<?php
     2
     3if ( ! defined( 'ABSPATH' ) ) {
     4        exit;
     5}
     6
    27/**
    38 * Parent Box view.
  • yoast-comment-hacks/trunk/admin/views/config-page.php

    r3438581 r3807202  
    11<?php
     2
     3if ( ! defined( 'ABSPATH' ) ) {
     4        exit;
     5}
     6
     7// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
     8
    29/**
    310 * Config page admin view.
    411 *
    5  * @var Admin $this
     12 * @var \EmiliaProjects\WP\Comment\Admin\Admin $this
    613 */
    714
    8 use EmiliaProjects\WP\Comment\Admin\Admin;
    915use EmiliaProjects\WP\Comment\Inc\Hacks;
    1016
  • yoast-comment-hacks/trunk/comment-hacks.php

    r3438581 r3807202  
    55 * @wordpress-plugin
    66 * Plugin Name:  Comment Experience
    7  * Version:      2.1.7
     7 * Version:      2.1.8
    88 * Plugin URI:   https://progressplanner.com/plugins/comment-experience/
    99 * Description:  Improve the comment experience on your site. Adds lots of features to make commenting easier and more engaging.
    … …  
    3131 */
    3232
     33if ( ! defined( 'ABSPATH' ) ) {
     34        exit;
     35}
     36
    3337use EmiliaProjects\WP\Comment\Inc\Autoload;
    3438use EmiliaProjects\WP\Comment\Inc\Hacks;
    … …  
    3741 * Used for version checks.
    3842 */
    39 define( 'EMILIA_COMMENT_HACKS_VERSION', '2.1.6' );
     43define( 'EMILIA_COMMENT_HACKS_VERSION', '2.1.8' );
    4044
    4145/**
  • yoast-comment-hacks/trunk/inc/autoload.php

    r3265034 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
  • yoast-comment-hacks/trunk/inc/clean-emails.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510use WP_Comment;
    … …  
    1015 */
    1116class Clean_Emails {
    12 
    13         /**
    14          * Holds the current comment's ID.
    15          */
    16         private int $comment_id = 0;
    1717
    1818        /**
    … …  
    148148                $this->comment_moderation_actions();
    149149                $this->message .= ' | ' . \sprintf(
    150                         '<a href="http://ip-lookup.net/index.php?ip=%1$s">%2$s</a>',
    151                         $this->comment->comment_author_IP,
     150                        '<a href="%1$s">%2$s</a>',
     151                        \esc_url( 'https://ip-lookup.net/index.php?ip=' . \rawurlencode( $this->comment->comment_author_IP ) ),
    152152                        \esc_html__( 'Whois', 'yoast-comment-hacks' )
    153153                );
    … …  
    177177         */
    178178        private function add_author_line(): void {
    179                 if ( $this->comment->comment_type === 'comment' ) {
     179                if ( $this->comment->comment_type !== 'pingback' && $this->comment->comment_type !== 'trackback' ) {
    180180                        /* translators: %1$s is replaced with the comment author's name, %2$s is replaced with the comment author's email */
    181181                        $this->message .= \sprintf( \esc_html__( 'Author: %1$s (%2$s)', 'yoast-comment-hacks' ), \esc_html( $this->comment->comment_author ), '<a href="' . \esc_url( 'mailto:' . $this->comment->comment_author_email ) . '">' . \esc_html( $this->comment->comment_author_email ) . '</a>' ) . '<br />';
    … …  
    193193         */
    194194        private function add_content_line(): void {
    195                 if ( $this->comment->comment_type === 'comment' ) {
     195                if ( $this->comment->comment_type !== 'pingback' && $this->comment->comment_type !== 'trackback' ) {
    196196                        $this->message .= \esc_html__( 'Comment:', 'yoast-comment-hacks' );
    197197                }
    … …  
    200200                }
    201201
    202                 $this->message .= '<br />' . \wpautop( $this->comment->comment_content ) . '<br />';
     202                $this->message .= '<br />' . \wpautop( \esc_html( $this->comment->comment_content ) ) . '<br />';
    203203        }
    204204
    … …  
    232232         */
    233233        private function setup_data( int $comment_id ): void {
    234                 $this->comment_id = $comment_id;
    235                 $this->comment    = \get_comment( $this->comment_id );
    236                 $this->post       = \get_post( (int) $this->comment->comment_post_ID );
     234                $this->comment = \get_comment( $comment_id );
     235                $this->post    = \get_post( (int) $this->comment->comment_post_ID );
    237236        }
    238237
    … …  
    300299         */
    301300        private function comment_action_links( array $actions ): void {
    302                 $links = '';
     301                $links = [];
    303302                foreach ( $actions as $action => $label ) {
    304                         $links .= $this->comment_action_link( $label, $action ) . ' | ';
    305                 }
    306 
    307                 $links = \rtrim( $links, '| ' );
    308 
    309                 $this->message .= $links;
     303                        $links[] = $this->comment_action_link( $label, $action );
     304                }
     305
     306                $this->message .= \implode( ' | ', $links );
    310307        }
    311308
    … …  
    319316         */
    320317        private function comment_action_link( string $label, string $action ): string {
    321                 $url = \admin_url( \sprintf( 'comment.php?action=%s&c=%d', $action, $this->comment_id ) );
     318                $url = \admin_url( \sprintf( 'comment.php?action=%s&c=%d', $action, $this->comment->comment_ID ) );
    322319
    323320                return '<a href="' . \esc_url( $url ) . '">' . \esc_html( $label ) . '</a>';
  • yoast-comment-hacks/trunk/inc/email-links.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
    … …  
    4651         */
    4752        public function admin_bar_comment_link(): void {
    48                 if ( ! \is_singular() || $this->options['disable_email_all_commenters'] ) {
     53                if ( ! \current_user_can( 'moderate_comments' ) || ! \is_singular() || $this->options['disable_email_all_commenters'] ) {
    4954                        return;
    5055                }
  • yoast-comment-hacks/trunk/inc/forms.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5use WP_Error;
     6use WP_REST_Request;
     7
     8// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     9if ( ! defined( 'ABSPATH' ) ) {
     10        exit;
     11}
    412
    513/**
    … …  
    3139        public function init() {
    3240                $this->options = Hacks::get_options();
    33                 Hacks::get_defaults();
    3441
    3542                if ( $this->options['comment_policy'] ) {
    3643                        \add_action( 'comment_form_after_fields', [ $this, 'comment_form_fields' ] );
     44                        \add_action( 'comment_form_logged_in_after', [ $this, 'comment_form_fields' ] );
    3745                        \add_filter( 'preprocess_comment', [ $this, 'check_comment_policy' ] );
     46                        \add_filter( 'rest_pre_insert_comment', [ $this, 'check_rest_comment_policy' ], 10, 2 );
    3847                }
    3948        }
    … …  
    7281                return $comment_data;
    7382        }
     83
     84        /**
     85         * Require explicit policy acceptance for new REST comments.
     86         *
     87         * @param array<string, string|int>|WP_Error $comment_data Prepared comment data.
     88         * @param WP_REST_Request                    $request      The REST request.
     89         *
     90         * @return array<string, string|int>|WP_Error
     91         */
     92        public function check_rest_comment_policy( $comment_data, WP_REST_Request $request ) {
     93                if ( \is_wp_error( $comment_data ) || \current_user_can( 'moderate_comments' ) ) {
     94                        return $comment_data;
     95                }
     96
     97                $accepted = $request->get_param( 'comment_policy' );
     98                if ( $accepted !== 'on' && $accepted !== true ) {
     99                        return new WP_Error( 'comment_experience_policy', $this->options['comment_policy_error'], [ 'status' => 400 ] );
     100                }
     101
     102                return $comment_data;
     103        }
    74104}
  • yoast-comment-hacks/trunk/inc/hacks.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510use EmiliaProjects\WP\Comment\Admin\Admin;
    … …  
    161166                $comment = \get_comment( $comment_id );
    162167
    163                 if ( isset( $comment ) && $comment instanceof WP_Comment && ! empty( $comment->comment_author_url ) ) {
     168                if ( $comment instanceof WP_Comment && ! empty( $comment->comment_author_url ) ) {
    164169                        return \sprintf(
    165170                                '<a href="#" class="comment-remove-url" data-comment-id="%d" aria-label="%s">%s</a>',
    … …  
    251256                        }
    252257                }
    253 
    254258                // Only change $url when the page option is actually set and not zero.
    255                 if ( isset( $this->options['redirect_repeat_page'] ) && (int) $this->options['redirect_repeat_page'] !== 0 ) {
     259                elseif ( isset( $this->options['redirect_repeat_page'] ) && (int) $this->options['redirect_repeat_page'] !== 0 ) {
    256260                        $url = \get_permalink( (int) $this->options['redirect_repeat_page'] );
    257261
    … …  
    283287        private function get_option_from_cache( string $option ) {
    284288                $options = \wp_load_alloptions();
    285                 return isset( $options[ $option ] ) ? $option : false;
     289                return isset( $options[ $option ] ) ? $options[ $option ] : false;
    286290        }
    287291
  • yoast-comment-hacks/trunk/inc/length.php

    r3438581 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5use WP_Error;
     6
     7// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     8if ( ! defined( 'ABSPATH' ) ) {
     9        exit;
     10}
    411
    512/**
    … …  
    2330                // Process the comment and check it for length.
    2431                \add_filter( 'preprocess_comment', [ $this, 'check_comment_length' ] );
     32                \add_filter( 'rest_pre_insert_comment', [ $this, 'check_rest_comment_length' ] );
    2533
    2634                // Add a message to the comment form, before the comment textarea, to inform the user about the allowed comment length.
    … …  
    3846         */
    3947        public function check_comment_length( $comment_data ): array {
    40                 // Bail early for editors and admins, they can leave short or long comments if they want.
    41                 if ( \current_user_can( 'edit_posts' ) ) {
     48                $error = $this->get_length_error( $comment_data['comment_content'] );
     49                if ( $error !== '' ) {
     50                        \wp_die( \esc_html( $error ) . '<br /><a href="javascript:history.go(-1);">' . \esc_html__( 'Go back and try again.', 'yoast-comment-hacks' ) . '</a>' );
     51                }
     52                return $comment_data;
     53        }
     54
     55        /**
     56         * Apply the same length limits to new REST comments.
     57         *
     58         * @param array<string, string|int>|WP_Error $comment_data Prepared comment data.
     59         *
     60         * @return array<string, string|int>|WP_Error
     61         */
     62        public function check_rest_comment_length( $comment_data ) {
     63                if ( \is_wp_error( $comment_data ) ) {
    4264                        return $comment_data;
    4365                }
    4466
    45                 $length = $this->get_comment_length( $comment_data['comment_content'] );
     67                $error = $this->get_length_error( ( $comment_data['comment_content'] ?? '' ) );
     68                if ( $error !== '' ) {
     69                        return new WP_Error( 'comment_experience_length', $error, [ 'status' => 400 ] );
     70                }
     71                return $comment_data;
     72        }
     73
     74        /**
     75         * Get a validation message for a comment's length.
     76         *
     77         * @param string $content Comment content.
     78         *
     79         * @return string
     80         */
     81        private function get_length_error( string $content ): string {
     82                // Preserve the existing exemption for users who can edit posts.
     83                if ( \current_user_can( 'edit_posts' ) ) {
     84                        return '';
     85                }
     86
     87                $length = $this->get_comment_length( $content );
    4688
    4789                // Check for comment length and die if too short or too long.
    48                 $error = false;
     90                $error = '';
    4991                if ( $length < $this->options['mincomlength'] ) {
    5092                        $error = $this->options['mincomlengtherror'];
    … …  
    5496                }
    5597
    56                 if ( $error ) {
    57                         \wp_die( \esc_html( $error ) . '<br /><a href="javascript:history.go(-1);">' . \esc_html__( 'Go back and try again.', 'yoast-comment-hacks' ) . '</a>' );
    58                 }
    59                 return $comment_data;
     98                return $error;
    6099        }
    61100
  • yoast-comment-hacks/trunk/inc/notifications.php

    r3218529 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510/**
    … …  
    1924
    2025        /**
     26         * Get the roles eligible to receive comment notifications.
     27         *
     28         * @return string[]
     29         */
     30        public static function get_allowed_roles(): array {
     31                /**
     32                 * Filter which roles may receive notifications. Defaults to contributor and up.
     33                 *
     34                 * @param string[] $roles Array with user roles.
     35                 *
     36                 * @since 1.6.0
     37                 */
     38                return \apply_filters(
     39                        'comment_experience\notification_roles',
     40                        [ 'contributor', 'author', 'editor', 'administrator', 'super-admin' ]
     41                );
     42        }
     43
     44        /**
     45         * Check recipient eligibility when saving and sending notifications.
     46         *
     47         * @param int $user_id The proposed recipient.
     48         *
     49         * @return bool
     50         */
     51        public static function is_allowed_recipient( int $user_id ): bool {
     52                $user = \get_userdata( $user_id );
     53
     54                return $user && $user->user_email !== '' && \array_intersect( $user->roles, self::get_allowed_roles() ) !== [];
     55        }
     56
     57        /**
    2158         * Filter the recipients of the comment notification.
    2259         *
    … …  
    2865        public function filter_notification_recipients( $recipients, $comment_id ): array {
    2966                $comment = \get_comment( $comment_id );
     67                if ( ! $comment ) {
     68                        return $recipients;
     69                }
    3070
    3171                $new_recipient = \get_post_meta( (int) $comment->comment_post_ID, '_comment_notification_recipient', true );
    3272
    33                 if ( ! empty( $new_recipient ) ) {
     73                if ( ! empty( $new_recipient ) && self::is_allowed_recipient( (int) $new_recipient ) ) {
    3474                        $user = \get_userdata( $new_recipient );
    3575
    36                         return [ $user->user_email ];
     76                        if ( $user ) {
     77                                return [ $user->user_email ];
     78                        }
    3779                }
    3880
    … …  
    5193                $comment = \get_comment( $comment_id );
    5294
    53                 if ( $comment->comment_author !== '' && $comment->comment_author_email !== '' ) {
    54                         $name             = \esc_html( $comment->comment_author );
    55                         $message_headers .= "\nReply-To: $name <$comment->comment_author_email>\n";
    56 
     95                if ( $comment->comment_author_email === '' ) {
    5796                        return $message_headers;
    5897                }
    5998
    60                 if ( $comment->comment_author_email !== '' ) {
    61                         $message_headers .= "\nReply-To: $comment->comment_author_email <$comment->comment_author_email>\n";
     99                $name = ( $comment->comment_author !== '' ) ? \esc_html( $comment->comment_author ) : $comment->comment_author_email;
    62100
    63                         return $message_headers;
    64                 }
     101                $message_headers .= "\nReply-To: $name <$comment->comment_author_email>\n";
    65102
    66103                return $message_headers;
  • yoast-comment-hacks/trunk/inc/progress-planner-tasks.php

    r3290299 r3807202  
    22
    33namespace EmiliaProjects\WP\Comment\Inc;
     4
     5// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     6if ( ! defined( 'ABSPATH' ) ) {
     7        exit;
     8}
    49
    510use Progress_Planner\Suggested_Tasks\Tasks\Providers\Provider;
  • yoast-comment-hacks/trunk/inc/progress-planner/comment-moderation.php

    r3438581 r3807202  
    44
    55use Progress_Planner\Suggested_Tasks\Providers\Tasks;
     6
     7// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     8if ( ! defined( 'ABSPATH' ) ) {
     9        exit;
     10}
    611
    712if ( ! \class_exists( '\Progress_Planner\Suggested_Tasks\Providers\Tasks' ) ) {
    … …  
    8691                );
    8792
    88                 return $comments > 0; // @phpstan-ignore-line
     93                return $comments > 0;
    8994        }
    9095
  • yoast-comment-hacks/trunk/inc/progress-planner/comment-policy.php

    r3438581 r3807202  
    55use EmiliaProjects\WP\Comment\Inc\Hacks;
    66use Progress_Planner\Suggested_Tasks\Providers\Tasks;
     7
     8// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     9if ( ! defined( 'ABSPATH' ) ) {
     10        exit;
     11}
    712
    813if ( ! \class_exists( '\Progress_Planner\Suggested_Tasks\Providers\Tasks' ) ) {
    … …  
    7984         */
    8085        public function should_add_task() {
    81                 if ( ! (int) $this->options['comment_policy_page'] || ! (int) $this->options['comment_policy'] ) {
    82                         return true;
    83                 }
    84 
    85                 return false;
     86                return ! (int) $this->options['comment_policy_page'] || ! (int) $this->options['comment_policy'];
    8687        }
    8788
  • yoast-comment-hacks/trunk/inc/progress-planner/comment-redirect.php

    r3438581 r3807202  
    55use EmiliaProjects\WP\Comment\Inc\Hacks;
    66use Progress_Planner\Suggested_Tasks\Providers\Tasks;
     7
     8// phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified -- Plugin Check requires defined() without backslash.
     9if ( ! defined( 'ABSPATH' ) ) {
     10        exit;
     11}
    712
    813if ( ! \class_exists( '\Progress_Planner\Suggested_Tasks\Providers\Tasks' ) ) {
    … …  
    7883         */
    7984        public function should_add_task() {
    80                 if ( ! $this->options['redirect_page'] ) {
    81                         return true;
    82                 }
    83 
    84                 return false;
     85                return ! $this->options['redirect_page'];
    8586        }
    8687
  • yoast-comment-hacks/trunk/readme.md

    r3438581 r3807202  
    1010[![Test](https://github.com/ProgressPlanner/comment-hacks/actions/workflows/test.yml/badge.svg)](https://github.com/ProgressPlanner/comment-hacks/actions/workflows/test.yml)
    1111
     12![Comment Experience banner](.wordpress-org/github_banner_comment_experience_pp.png)
     13
    1214# Comment Experience
    1315
    14 Improve the comment experience on your site. Adds lots of features to make commenting easier and more engaging.
     16Make WordPress comments easier to manage with cleaner moderation emails, better routing, comment policy controls, length limits, and tools for following up with commenters.
    1517
    16 ## Description
     18## Why this plugin exists
    1719
    18 This plugin adds many small improvements around core WordPress comments to make them more bearable:
     20Core WordPress comments work, but moderation and follow-up can feel clunky. Comment Experience adds practical improvements for site owners and editors who want a cleaner, more manageable comment workflow without replacing the native comments system.
    1921
    20 * Cleaner comment notification emails.
    21 * The option to enforce a comment policy.
    22 * The option to forward comments to an email address (for instance for your support team) and then trash them.
    23 * The option to disallow comments below a certain length.
    24 * The option to redirect first time commenters to a "thank you" page.
    25 * An input field on the comment edit screen to change the comment parent ID.
    26 * Links in the admin comments section to email individual commenters.
    27 * A button in the WP toolbar to email all the commenters on a post.
     22## What it helps you do
     23
     24- Clean up comment notification emails so moderation is easier.
     25- Require acceptance of a comment policy before submission.
     26- Forward comments to another email address and optionally trash them.
     27- Set minimum and maximum comment lengths.
     28- Redirect first-time commenters to a thank-you page.
     29- Change a comment's parent ID from the comment edit screen.
     30- Email an individual commenter from the comments screen.
     31- Email all commenters on a post from the admin bar.
     32- Route comment emails to another user from a post's discussion settings.
     33
     34## Installation
     35
     36### From WordPress admin
     37
     381. In your WordPress dashboard, go to **Plugins → Add New**.
     392. Search for **Comment Experience** or **comment hacks**.
     403. Install and activate the plugin.
     414. Go to **Settings → Comment Experience** to configure the available options.
     42
     43### Manual installation
     44
     451. Download the plugin zip.
     462. Upload the `comment-hacks` folder to `/wp-content/plugins/`.
     473. Activate the plugin in **Plugins**.
     484. Go to **Settings → Comment Experience** to configure the available options.
    2849
    2950## Screenshots
    3051
    31 Screenshot of a clean comment notification email:<br>
    32 ![Screenshot of a clean comment notification email](.wordpress-org/screenshot-1.png)<br>
    33 <br>
    34 The comment parent edit box:<br>
    35 ![The comment parent edit box](.wordpress-org/screenshot-2.png)<br>
    36 <br>
    37 The plugins admin settings:<br>
    38 ![The plugins admin settings](.wordpress-org/screenshot-3.png)<br>
    39 <br>
    40 The button on the frontend to email all the commenters on a post:<br>
    41 ![The button to email all commenters](.wordpress-org/screenshot-4.png)<br>
    42 <br>
    43 The link in the backend to email an individual commenters on a post:<br>
    44 ![The button to email all commenters](.wordpress-org/screenshot-5.png)<br><br>
     52### Cleaner comment notification emails
     53![Cleaner comment notification emails](.wordpress-org/screenshot-1.png)
     54
     55### Edit a comment's parent directly from the comment screen
     56![Edit a comment's parent directly from the comment screen](.wordpress-org/screenshot-2.png)
     57
     58### Configure comment length, policy, redirects, email links, and forwarding from one settings screen
     59![Configure comment settings](.wordpress-org/screenshot-3.png)
     60
     61### Email all commenters on a post from the WordPress admin bar
     62![Email all commenters on a post from the WordPress admin bar](.wordpress-org/screenshot-4.png)
     63
     64### Contact an individual commenter from the comments list table
     65![Contact an individual commenter from the comments list table](.wordpress-org/screenshot-5.png)
     66
     67## Support, issues, and security
     68
     69- Questions or support: [WordPress.org support forum](https://wordpress.org/support/plugin/yoast-comment-hacks/)
     70- Bug reports and feature requests: [GitHub issues](https://github.com/ProgressPlanner/comment-hacks/issues)
     71- Security reports: [Patchstack VDP](https://patchstack.com/database/vdp/comment-hacks)
     72
     73## Contributing
     74
     75Contributions are welcome. Please read [`.github/CONTRIBUTING.md`](.github/CONTRIBUTING.md) before opening an issue or pull request.
     76
     77## Links
     78
     79- [Plugin page on WordPress.org](https://wordpress.org/plugins/yoast-comment-hacks/)
     80- [Progress Planner](https://progressplanner.com/)
  • yoast-comment-hacks/trunk/readme.txt

    r3438581 r3807202  
    11=== Comment Experience ===
    2 Contributors: joostdevalk
    3 Tags: comments, spam, emails
    4 Text Domain: comment-hacks
    5 Requires at least: 6.6
    6 Tested up to: 6.8
    7 Stable tag: 2.1.7
     2Contributors: joostdevalk, aristath, filipi, progressplanner
     3Tags: comments, comment moderation, comment emails, discussion, comment policy
     4Text Domain: yoast-comment-hacks
     5Stable tag: 2.1.8
    86Requires at least: 6.7
    9 Tested up to: 6.9
     7Tested up to: 7.1
    108Requires PHP: 7.4
    11 Stable tag: 2.1.6
    12 License: GPLv3
     9License: GPL-3.0-or-later
    1310License URI: https://www.gnu.org/licenses/gpl-3.0.html
    14 Requires PHP: 7.4
    15 
    16 Make comments management easier by applying the simple hacks Joost has gathered over the years.
     11
     12Improve WordPress comment moderation with cleaner emails, comment policy checks, routing, redirects, and length controls.
    1713
    1814== Description ==
    1915
    20 Make comments management easier by applying the simple hacks Joost has gathered over the years.
    21 
    22 This plugin adds some small hacks around core WordPress comments to make them more bearable:
    23 
    24 * Cleaner comment notification emails.
    25 * The option to enforce a comment policy: just create a comment policy page, toggle the option on and select it, and
    26 commenters will have to accept your comment policy before being able to comment.
    27 * The option to forward comments to an email address (for instance for your support team) and then trash them.
    28 * The option to disallow comments below and above a certain length.
    29 * The option to redirect first time commenters to a "thank you" page.
    30 * An input field on the comment edit screen to change the comment parent ID.
    31 * Links in the admin comments section to email individual commenters.
    32 * A button in the WP toolbar to email all the commenters on a post.
    33 * Adds a comment routing option. This adds a dropdown in a post's discussion settings, allowing the routing of comment emails to another user.
    34 
    35 See the screenshots to get an even better idea of the plugins' functionality.
    36 
    37 === Have you found an issue? ===
    38 
    39 If you have bugs to report, please go to [the plugin's GitHub repository](https://github.com/emilia-capital/comment-hacks). For security issues, please use our [vulnerability disclosure program](https://patchstack.com/database/vdp/comment-hacks), which is managed by PatchStack. They will assist you with verification, CVE assignment, and, of course, notify us.
    40 
     16Comment Experience helps you manage WordPress comments more efficiently without replacing the native comments system.
     17
     18If you moderate comments regularly, this plugin gives you practical improvements that make follow-up easier, keep discussions clearer, and reduce repetitive admin work.
     19
     20= Features that improve comment moderation =
     21
     22* Clean up comment notification emails so important details are easier to scan.
     23* Require commenters to accept a comment policy before submitting.
     24* Forward comments to another email address and optionally trash them after forwarding.
     25* Set minimum and maximum comment lengths.
     26* Redirect first-time commenters to a thank-you page.
     27* Change a comment's parent ID from the comment edit screen.
     28* Email an individual commenter directly from the comments list.
     29* Email all commenters on a post from the WordPress admin bar.
     30* Route comment emails to another user from a post's discussion settings.
     31
     32= Who this plugin is for =
     33
     34Comment Experience is useful for site owners, editors, community managers, and support teams who rely on WordPress comments and want a smoother moderation workflow.
     35
     36= Need help or want to report something? =
     37
     38For support, visit the [WordPress.org support forum](https://wordpress.org/support/plugin/yoast-comment-hacks/).
     39
     40For bugs or feature requests, use the [GitHub repository](https://github.com/ProgressPlanner/comment-hacks).
     41
     42For security issues, please use our [vulnerability disclosure program](https://patchstack.com/database/vdp/comment-hacks), managed by Patchstack.
    4143
    4244== Installation ==
    4345
    44 **Install through your backend**
    45 
    46 1. Search for "comment hacks", click install.
    47 1. You're done.
    48 
    49 **Install manually**
     46= Install from your WordPress dashboard =
     47
     481. Go to **Plugins > Add New Plugin**.
     492. Search for **Comment Experience** or **comment hacks**.
     503. Click **Install Now** and then **Activate**.
     514. Go to **Settings > Comment Experience** to configure the plugin.
     52
     53= Install manually =
    5054
    51551. Download and unzip the plugin.
    52 1. Upload the `comment-hacks` directory to the `/wp-content/plugins/` directory.
    53 1. Activate the plugin through the 'Plugins' menu in WordPress.
    54 1. Configure your settings on the Settings &rarr; Comment Experience screen.
     562. Upload the `comment-hacks` directory to the `/wp-content/plugins/` directory.
     573. Activate the plugin through the **Plugins** menu in WordPress.
     584. Go to **Settings > Comment Experience** to configure the plugin.
     59
     60== Frequently Asked Questions ==
     61
     62= What does Comment Experience do? =
     63
     64Comment Experience improves WordPress comment moderation with cleaner notification emails, comment policy options, comment routing, redirects, and comment length controls.
     65
     66= Does it replace the default WordPress comments system? =
     67
     68No. It enhances core WordPress comments with extra moderation and workflow features.
     69
     70= Can I require visitors to accept a comment policy? =
     71
     72Yes. You can create a comment policy page, enable the option, and require acceptance before a comment can be submitted.
     73
     74= Can I limit how short or long comments can be? =
     75
     76Yes. The plugin lets you configure both minimum and maximum comment length limits.
     77
     78= Can I send comment notifications to someone else? =
     79
     80Yes. You can forward comments to another email address, and you can also route comment emails to another user from a post's discussion settings.
    5581
    5682== Screenshots ==
    5783
    58 1. Screenshot of a clean comment notification email.
    59 2. The comment parent edit box.
    60 3. The plugins admin settings.
    61 4. The button on the frontend to email all the commenters on a post.
    62 5. The link in the backend to email an individual commenters on a post.
     841. Cleaner WordPress comment notification email that is easier to scan while moderating.
     852. Comment parent field on the comment edit screen for fixing comment thread hierarchy.
     863. Comment Experience settings for comment length limits, comment policy, email links, redirects, clean emails, and forwarding.
     874. Admin bar button for emailing all commenters on a post.
     885. Comments list action link for emailing an individual commenter.
    6389
    6490== Changelog ==
    6591
     92= 2.1.8 =
     93* Security: strengthen permission checks for comment actions and notification recipients.
     94* Security: escape comment content in notification emails and restrict user searches to public names.
     95* Apply comment length limits and comment policy acceptance to REST API comment creation.
     96* Replace the notification recipient dropdown with an AJAX-powered user search.
     97* Fix first-time commenter redirects, cached option values, and email formatting for older comments.
     98* Preserve the ability to remove a comment's parent by clearing the parent field.
     99* Update compatibility information for WordPress 7.1.
     100
    66101= 2.1.7 =
    67 
    68 * Minor updates, name change mostly.
     102* Maintenance release with minor updates and the Comment Experience name change.
    69103
    70104= 2.1.6 =
    71 
    72 * Compatibility with Progress Planner v1.9
     105* Compatibility with Progress Planner v1.9.
    73106
    74107= 2.1.5 =
    75 
    76 * Compatibility with Progress Planner v1.8
     108* Compatibility with Progress Planner v1.8.
    77109
    78110= 2.1.4 =
    79 
    80111* Add compatibility with WordPress 6.8.
    81112* Save proper values for Redirect page settings when no selection is made.
    82 * Run upgrade routine only when plugin version is increased
    83 * Migrate PHPUnit XML schema
    84 * Compatibility with Progress Planner v1.4
     113* Run the upgrade routine only when the plugin version increases.
     114* Migrate PHPUnit XML schema.
     115* Compatibility with Progress Planner v1.4.
    85116
    86117= 2.1.3 =
    87 
    88 * Add necessary compatibility to Progress Planner integration for the upcoming WordPress 6.8.
     118* Add compatibility for the upcoming WordPress 6.8 release in Progress Planner integration.
    89119
    90120= 2.1.2 =
    91 
    92121* Rename the plugin from "Comment Hacks" to "Comment Experience".
    93 * Bring up to date with changes in Progress Planner
     122* Bring the plugin up to date with changes in Progress Planner.
    94123
    95124= 2.1.1 =
    96 
    97125* Don't enqueue the remove URL script on the frontend for logged out users or users without the `edit_posts` capability.
    98126
    99127= 2.1 =
    100 
    101 * Added a link to remove the author's URL from the comment from the frontend.
    102 * Fix comment policy function for admins and editors.
     128* Add a link to remove the author's URL from the comment from the frontend.
     129* Fix the comment policy function for admins and editors.
    103130
    104131= 1.9.4 =
    105 
    106132* Fix fatal due to wrong class import, props [@andizer](https://profiles.wordpress.org/andizer/).
    107133
    108134= 1.9.3 =
    109 
    110 * Fix bug where comment reroute recipient would not save.
    111 * Added an option to disable the "Email all commenters" admin bar button.
     135* Fix bug where the comment reroute recipient would not save.
     136* Add an option to disable the "Email all commenters" admin bar button.
    112137
    113138= 1.9.2 =
    114 
    115139* Fix missing autoloader.
    116140
    117141= 1.9 =
    118 
    119 * Introduces a new option to the plugin: adding a comment policy was never easier than this: just create a comment
    120 policy page, toggle the option on and select it, and commenters will have to accept your comment policy before being
    121 able to comment.
    122 * Fixes a bug where editing a comment on the quick edit screen would cause that comment to lose its parent.
    123 * Enhances performance by preventing too frequent option updates.
    124 * Remove all direct DB queries in favor of using WordPress core functions.
     142* Add a comment policy option so commenters must accept your policy before commenting.
     143* Fix a bug where editing a comment on the quick edit screen would cause that comment to lose its parent.
     144* Improve performance by preventing too frequent option updates.
     145* Remove all direct database queries in favor of WordPress core functions.
    125146
    126147= 1.8.1 =
    127 
    128 * Fixed a couple of PHP 7.4 related issues.
     148* Fix a couple of PHP 7.4 related issues.
    129149
    130150= 1.8 =
    131 
    132 * Changed namespace to `JoostBlog`.
    133 * Removed Yoast branding.
    134 * Updated plugin to require PHP 7.4.
     151* Change namespace to `JoostBlog`.
     152* Remove Yoast branding.
     153* Update the plugin to require PHP 7.4.
    135154
    136155= 1.7 =
    137 
    138 * Bugfixes:
    139     * Fixed: the "Email commenters" link would not be displayed in the WordPress admin bar and in the Comments list.
    140     * Fixed: the "Email commenters" link in the front end admin bar wouldn't work when jQuery wasn't enqueued.
    141     * Fixed: the notification emails for new comments would have incorrect content for the Author line and the text displayed before the comment.
     156* Fix the "Email commenters" link not displaying in the WordPress admin bar and comments list.
     157* Fix the frontend admin bar email commenters link when jQuery was not enqueued.
     158* Fix incorrect author line and comment intro text in notification emails.
    142159
    143160= 1.6 =
    144 
    145161* Fix language packs.
    146162
    147163= 1.5 =
    148 
    149 * Bugfixes:
    150     * Fixed: comment recipient dropdown would reset on reload of the page.
    151     * Fixed: admin bar CSS showing when no admin bar is showing.
     164* Fix the comment recipient dropdown resetting on page reload.
     165* Fix admin bar CSS showing when the admin bar is not visible.
    152166
    153167= 1.4 =
    154 
    155 * Enhancements:
    156     * Limit the roles shown in the comment notifications dropdown to roles that normally exist and can write. Introduces a new filter to allow expanding them.
     168* Limit the roles shown in the comment notifications dropdown to roles that normally exist and can write.
     169* Introduce a new filter to allow expanding those roles.
    157170
    158171= 1.3 =
    159 
    160 * Enhancements:
    161     * Add option to restrict comments that are too long, next to too small.
    162     * Add `reply-to` header to comment notification and moderation emails, pointing to the post author.
    163     * Preserve the active tab when saving settings.
    164     * Remove `[...]` from pingback / trackback excerpt in cleaned emails as that's already included by core.
    165     * Replace link to ARIN with link to [ip-lookup.net](http://ip-lookup.net) for details about the IP.
    166     * Refactored code for readability and code quality.
    167     * Refactor upgrade routine to do less DB queries.
     172* Add an option to restrict comments that are too long, next to comments that are too short.
     173* Add a `reply-to` header to comment notification and moderation emails that points to the post author.
     174* Preserve the active tab when saving settings.
     175* Remove `[...]` from pingback and trackback excerpts in cleaned emails because core already includes it.
     176* Replace the ARIN link with [ip-lookup.net](http://ip-lookup.net) for IP details.
     177* Refactor code for readability and code quality.
     178* Refactor the upgrade routine to do fewer database queries.
    168179
    169180= 1.2 =
    170 
    171 Fixes several issues:
    172 
    173 * Differentiate between AJAX request and normal POST for nonce checking, fixes #7.
    174 * Make sure comment type isn't empty in cleaned email, fixes #8.
    175 * Allow setting the comment parent to 0, fixes #10.
    176 * Prevents defaults from being reinstated, fixes #14.
    177 
    178 Also:
    179 
    180 * Adds translator comments to all strings with `sprintf` / `printf`.
    181 * Updates to new version of Yoast i18n, in the process switching from `translate.yoast.com` to `translate.wordpress.org` and removing packaged translations.
    182 * Added `yarn.lock` and removed no longer needed i18n grunt tasks.
     181* Differentiate between AJAX requests and normal POST requests for nonce checking, fixing #7.
     182* Make sure the comment type is not empty in cleaned emails, fixing #8.
     183* Allow setting the comment parent to 0, fixing #10.
     184* Prevent defaults from being reinstated, fixing #14.
     185* Add translator comments to all strings with `sprintf` / `printf`.
     186* Update to a new version of Yoast i18n, switching from `translate.yoast.com` to `translate.wordpress.org` and removing packaged translations.
     187* Add `yarn.lock` and remove no longer needed i18n grunt tasks.
    183188
    184189= 1.1.1 =
    185 
    186 * Add text domain so the plugin can be translated.
     190* Add a text domain so the plugin can be translated.
    187191
    188192= 1.1 =
    189 
    190 * Add comment routing option, adds a dropdown in a post's discussion settings, allowing the routing of comment emails to another user.
     193* Add a comment routing option with a dropdown in a post's discussion settings for routing comment emails to another user.
    191194
    192195= 1.0 =
    193 
    194196* Initial version.
     197
     198== Upgrade Notice ==
     199
     200= 2.1.8 =
     201Security and reliability improvements. REST clients must send comment_policy: true or comment_policy: "on" when comment policy acceptance is enabled.
     202
     203= 2.1.7 =
     204This maintenance release keeps Comment Experience current and aligned with its updated branding.
Note: See TracChangeset for help on using the changeset viewer.