PHP code example of cedaro / wprestcop

1. Go to this page and download the library: Download cedaro/wprestcop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cedaro / wprestcop example snippets



/**
 * Set the rate limit to 10 requests every 5 minutes.
 */
add_action( 'wprestcop_plugin_loaded', function( $wprestcop ) {
	$wprestcop
		->set_limit( 10 )
		->set_interval( 5 * MINUTE_IN_SECONDS );
} );


/**
 * Global IP rules configuration.
 */
add_action( 'wprestcop_plugin_loaded', function( $wprestcop ) {
	$wprestcop->get_ip_rules()
		->allow( '192.168.50.4' ); // Also accepts an array of IP addresses.

	// Or...

	$wprestcop->get_ip_rules()
		->deny( '66.249.66.1' ); // Also accepts an array of IP addresses.
} );


/**
 * Register routes.
 */
add_action( 'rest_api_init', function () {
    register_rest_route( 'myplugin/v1', '/internal/(?P<id>\d+)', [
        'methods'  => 'GET',
        'callback' => 'my_awesome_expensive_func',
        'ips'      => [
            'allow' => [ '192.168.50.4' ],
            'deny'  => [ '66.249.66.1' ],
        ]
    ] );
} );