Make WordPress Core

Ticket #5130: 5130.diff

File 5130.diff, 4.3 KB (added by dshanske, 9 years ago)

Add Support to Existing Functions to Rate Limit Differently Based on Pingback

  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index f579e95..a78d4bc 100644
    function wp_allow_comment( $commentdata ) { 
    645645         * Allows checking for comment flooding.
    646646         *
    647647         * @since 2.3.0
     648         * @since 4.6.0 $commentdata was added
    648649         *
    649650         * @param string $comment_author_IP    Comment author's IP address.
    650651         * @param string $comment_author_email Comment author's email.
    651652         * @param string $comment_date_gmt     GMT date the comment was posted.
     653         * @param array  $commentdata          Comment Data.
    652654         */
    653655        do_action(
    654656                'check_comment_flood',
    655657                $commentdata['comment_author_IP'],
    656658                $commentdata['comment_author_email'],
    657                 $commentdata['comment_date_gmt']
     659                $commentdata['comment_date_gmt'],
     660                $commentdata
    658661        );
    659662
    660663        if ( ! empty( $commentdata['user_id'] ) ) {
    function wp_allow_comment( $commentdata ) { 
    715718 * administrators.
    716719 *
    717720 * @since 2.3.0
     721 * @since 4.6.0 $commentdata parameter added
    718722 *
    719723 * @global wpdb $wpdb WordPress database abstraction object.
    720724 *
    721725 * @param string $ip Comment IP.
    722726 * @param string $email Comment author email address.
    723727 * @param string $date MySQL time string.
     728 * @param array  $commentdata Full Comment Data.
    724729 */
    725 function check_comment_flood_db( $ip, $email, $date ) {
     730function check_comment_flood_db( $ip, $email, $date, $commentdata ) {
    726731        global $wpdb;
     732        $comment_type = ! isset( $commentdata['comment_type'] ) ? '' : $commentdata['comment_type'];
     733
    727734        // don't throttle admins or moderators
    728735        if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) {
    729736                return;
    function check_comment_flood_db( $ip, $email, $date ) { 
    752759                 * Filter the comment flood status.
    753760                 *
    754761                 * @since 2.1.0
     762                 * @since 4.6.0 Add $comment_type.
    755763                 *
    756764                 * @param bool $bool             Whether a comment flood is occurring. Default false.
    757765                 * @param int  $time_lastcomment Timestamp of when the last comment was posted.
    758766                 * @param int  $time_newcomment  Timestamp of when the new comment was posted.
     767                 * @param string $comment_type   Comment Type.
    759768                 */
    760                 $flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment );
     769                $flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment, $comment_type );
    761770                if ( $flood_die ) {
    762771                        /**
    763772                         * Fires before the comment flood message is triggered.
    function wp_filter_comment($commentdata) { 
    16831692 * Whether a comment should be blocked because of comment flood.
    16841693 *
    16851694 * @since 2.1.0
     1695 * @since 4.6.0 Add Comment Type.
    16861696 *
    16871697 * @param bool $block Whether plugin has already blocked comment.
    16881698 * @param int $time_lastcomment Timestamp for last comment.
    16891699 * @param int $time_newcomment Timestamp for new comment.
     1700 * @param string $comment_type Type of Comment.
    16901701 * @return bool Whether comment should be blocked.
    16911702 */
    1692 function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {
     1703function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment, $comment_type) {
    16931704        if ( $block ) // a plugin has already blocked... we'll let that decision stand
    16941705                return $block;
    16951706        if ( ($time_newcomment - $time_lastcomment) < 15 )
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index f7bfeb5..df79298 100644
    add_filter( 'tiny_mce_before_init', '_mce_set_direction' ); 
    190190add_filter( 'teeny_mce_before_init',    '_mce_set_direction'                  );
    191191add_filter( 'pre_kses',                 'wp_pre_kses_less_than'               );
    192192add_filter( 'sanitize_title',           'sanitize_title_with_dashes',   10, 3 );
    193 add_action( 'check_comment_flood',      'check_comment_flood_db',       10, 3 );
    194 add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',    10, 3 );
     193add_action( 'check_comment_flood',      'check_comment_flood_db',       10, 4 );
     194add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',    10, 4 );
    195195add_filter( 'pre_comment_content',      'wp_rel_nofollow',              15    );
    196196add_filter( 'comment_email',            'antispambot'                         );
    197197add_filter( 'option_tag_base',          '_wp_filter_taxonomy_base'            );