Making WordPress.org

Ticket #1688: exempt_plugin_admins_from_comment_throttle.patch

File exempt_plugin_admins_from_comment_throttle.patch, 1.8 KB (added by danieliser, 9 years ago)

Patches for admin/class-customizations.php

  • public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    3636                add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
    3737
    3838                add_action( 'wp_ajax_replyto-comment', array( $this, 'save_custom_comment' ), 0 );
     39                add_filter( 'comment_flood_filter', array( $this, 'comment_flood_exemption' ), 100, 3 );
    3940                add_filter( 'comment_row_actions', array( $this, 'custom_comment_row_actions' ), 10, 2 );
    4041
    4142                // Admin Metaboxes
     
    552553                $x = new \WP_Ajax_Response();
    553554                $x->add( $response );
    554555                $x->send();
     556        }
     557
     558        /**
     559         * Filters the comment flood boolean to exempt plugin admins from throttling.
     560         *
     561         * @param bool     $flood_die A true value will result in Slow Down comment warning.
     562         *
     563         * @return bool
     564         */
     565        public function comment_flood_exemption( $flood_die ) {
     566
     567                // Return if request is not AJAX or if comment type is anything other than internal-note.
     568                if ( ! defined( 'DOING_AJAX' ) || ! isset( $_REQUEST['comment_type'] ) || $_REQUEST['comment_type'] != 'internal-note' ) {
     569                        return $flood_die;
     570                }
     571
     572                // Check for exempted user roles.
     573                $user = wp_get_current_user();
     574
     575                $exempted_roles = array(
     576                        'plugin_admin',
     577                        'plugin_reviewer',
     578                );
     579
     580                // Check if any of the exempted roles exist for the current user.
     581                if ( count( array_intersect( $exempted_roles, (array) $user->roles ) ) ) {
     582
     583                        // Return false to override the flood alert.
     584                        return false;
     585                }
     586
     587                return $flood_die;
    555588        }
    556589}