Skip to content

Instantly share code, notes, and snippets.

/**
* Example : Validate specific actions of admin-ajax.php at front-end
* Use case: Give permission to ajax with specific action at public facing page
*
* @global array $_GET and $_POST requested queries
* @param array $queries array of admin queries which should bypass WP-ZEP.
* @return array $queries array of admin queries which should bypass WP-ZEP.
*/
function my_bypass_admins( $queries ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) ) {
@tokkonopapa
tokkonopapa / class-ip-geo-block-logs.php
Last active December 27, 2016 15:16
IP Geo Block SQL Error handling
/**
* SQL Error handling
*
*/
private static function error( $line ) {
if ( class_exists( 'IP_Geo_Block_Admin' ) ) {
global $wpdb;
if ( $wpdb->last_error )
IP_Geo_Block_Admin::add_admin_notice( 'error', __FILE__ . ' (' . $line . ') ' . $wpdb->last_error );
}
@tokkonopapa
tokkonopapa / functions.php
Last active December 29, 2016 02:21
Sample of "ip-geo-block-bypass-themes"
// pattern 1
if( has_filter( 'ip-geo-block-bypass-themes', 'my_bypass_themes' ) === false ) {
add_filter( 'ip-geo-block-bypass-themes', 'my_bypass_themes' );
}
function my_bypass_themes( $themes ) {
$whitelist = array( 'twentytwelve', );
return array_merge( $themes, $whitelist );
}
// pattern 2
@tokkonopapa
tokkonopapa / class-zcloudflare.php
Last active July 21, 2017 15:34
IP Geo Block api class library for CloudFlare
<?php
if ( class_exists( 'IP_Geo_Block_API', FALSE ) ) :
/**
* Class for CloudFlare
*
* @see https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-CloudFlare-handle-HTTP-Request-headers-
* @see https://support.cloudflare.com/hc/en-us/articles/200170856-How-do-I-restore-original-visitor-IP-with-vBulletin-
* @see https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-
@tokkonopapa
tokkonopapa / class-zcloudfront.php
Last active April 23, 2018 14:37
IP Geo Block api class library for CloudFront
<?php
if ( class_exists( 'IP_Geo_Block_API', FALSE ) ) :
/**
* Class for CloudFront
*
* @see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/georestrictions.html
* @see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#RequestCustomIPAddresses
* @see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#request-custom-headers-behavior
@tokkonopapa
tokkonopapa / drop-in.php
Created February 11, 2017 17:14
Add GravityView actions to IP Geoblock whitelist
<?php
/**
* Add GravityView actions to IP Geoblock whitelist
*
*/
function gravityview_ip_geoblock_bypass_admins( $queries ) {
$whitelist = array(
'gv_datatables_data',
@tokkonopapa
tokkonopapa / functions.php
Last active February 18, 2017 19:30
like button for theme belle
<?php
/**
* Add action for like button of theme 'belle' to IP Geo Block whitelist
*
* @link http://themecanon.com/belle/
*/
function my_ip_geo_block_bypass_admins( $list ) {
$whitelist = array(
'like_post',
@tokkonopapa
tokkonopapa / uninstall.php
Created March 11, 2017 09:57
Clean uninstall for IP Geo Block
<?php
/**
* Fired when the plugin is uninstalled.
*
* @package IP_Geo_Block
* @author tokkonopapa <[email protected]>
* @license GPL-2.0+
* @link http://www.ipgeoblock.com/
* @copyright 2013-2017 tokkonopapa
*/
@tokkonopapa
tokkonopapa / drop-in.php
Created March 17, 2017 16:54
In case $_SERVER[‘REMOTE_ADDR’] returns 127.0.0.1
<?php
/**
* Example 2: Usage of 'ip-geo-block-ip-addr'
* Use case: Retrieve ip address behind the proxy
*
* @param string $ip original ip address
* @return string $ip replaced ip address
*/
function my_retrieve_ip( $ip ) {
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
@tokkonopapa
tokkonopapa / ip-geo-block.php
Created March 23, 2017 09:56
Emergent Functionality
<?php
/**
* IP Geo Block
*
* A WordPress plugin that blocks undesired access based on geolocation of IP address.
*
* @package IP_Geo_Block
* @author tokkonopapa <[email protected]>
* @license GPL-2.0+
* @link http://www.ipgeoblock.com/