= $limit ) { return false; } set_transient( $key, $count + 1, $window ); return true; } /** * The client IP. REMOTE_ADDR only, unless a trusted proxy header is * configured with the mapp_client_ip_header filter (e.g. CF-Connecting-IP). * * @return string */ public static function client_ip() { $header = apply_filters( 'mapp_client_ip_header', '' ); if ( $header ) { $server_key = 'HTTP_' . strtoupper( str_replace( '-', '_', $header ) ); if ( ! empty( $_SERVER[ $server_key ] ) ) { $ip = trim( explode( ',', sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) ) )[0] ); if ( filter_var( $ip, FILTER_VALIDATE_IP ) ) { return $ip; } } } $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; return filter_var( $ip, FILTER_VALIDATE_IP ) ? $ip : '0.0.0.0'; } }