Plugin Directory

Changeset 777776


Ignore:
Timestamp:
09/24/2013 03:26:13 PM (13 years ago)
Author:
eldad.chai
Message:

Version 1.4:
Instead of fiddling with the plugins' order on the $active_plugins record as before, the plugin now runs on the "init" hook, with a very high priority (set to -9999999).

Location:
incapsula/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • incapsula/trunk/incapsula.php

    r765629 r777776  
    44Plugin URI: http://wordpress.org/extend/plugins/incapsula/
    55Description: The Incapsula plugin will make sure that any reference to the user IP in your WordPress will use the correct IP address when your site is safeguarded by Incapsula
    6 Version: 1.3
     6Version: 1.4
    77Author: Incapsula
    88Author URI: http://www.incapsula.com
     
    1717//name of HTTP header with an initial IP
    1818define('HEADER_NAME','HTTP_INCAP_CLIENT_IP');
     19add_action("init", "incap_set_ip",-9999999);
    1920
    20 try {
    21     //echo('incap header: ['.$_SERVER[HEADER_NAME].']'.'<br />');
    22     //stop process if there is no header
    23     if (empty($_SERVER[HEADER_NAME])) throw new Exception('No header defined', 1);
    24    
    25     //validate header value
    26     if (function_exists('filter_var')) {
    27         $ip = filter_var($_SERVER[HEADER_NAME], FILTER_VALIDATE_IP);
    28         if (false === $ip) throw new Exception('The value is not a valid IP address', 2);
     21function incap_set_ip()
     22{
     23    try
     24    {
     25        //echo('incap header: ['.$_SERVER[HEADER_NAME].']'.'<br />');
     26       
     27        //stop process if there is no header
     28        if (empty($_SERVER[HEADER_NAME])) throw new Exception('No header defined', 1);
     29       
     30        //validate header value
     31        if (function_exists('filter_var'))
     32        {
     33            $ip = filter_var($_SERVER[HEADER_NAME], FILTER_VALIDATE_IP);
     34            if (false === $ip) throw new Exception('The value is not a valid IP address', 2);
     35        }
     36        else
     37        {
     38            $ip = trim($_SERVER[HEADER_NAME]);
     39            if (false === preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip)) throw new Exception('The value is not a valid IP address', 2);
     40        }
     41        //
     42        //At this point the initial IP value is exist and validated
     43        //echo('IP: ['.$ip.']'.'<br />');
     44        $_SERVER['REMOTE_ADDR'] = $ip;
    2945    }
    30     else {
    31         $ip = trim($_SERVER[HEADER_NAME]);
    32         if (false === preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip)) throw new Exception('The value is not a valid IP address', 2);
     46    catch (Exception $e)
     47    {
     48        //echo('exeption: ['.$e.']'.'<br />'); 
    3349    }
    34     //echo('IP: ['.$ip.']'.'<br />');
    35     //At this point the initial IP value is exist and validated
    36     $_SERVER['REMOTE_ADDR'] = $ip;
    37 } catch (Exception $e){
    38     //echo('exeption: ['.$e.']'.'<br />'); 
    3950}
    4051
    41 /**
    42  * Makes the pluging run first in order.
    43  */
    44 function this_plugin_first() {
    45     // ensure path to this file is via main wp plugin path
    46     $wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
    47     echo('this_plugin_first');
    48     $this_plugin = plugin_basename(trim($wp_path_to_this_file));
    49     $active_plugins = get_option('active_plugins');
    50     $this_plugin_key = array_search($this_plugin, $active_plugins);
    51     if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
    52         array_splice($active_plugins, $this_plugin_key, 1);
    53         array_unshift($active_plugins, $this_plugin);
    54         update_option('active_plugins', $active_plugins);
    55     }
    56 }
    57 add_action("activated_plugin", "this_plugin_first");
    5852?>
  • incapsula/trunk/readme.txt

    r768525 r777776  
    44Requires at least: 2.8
    55Tested up to: 3.6
    6 Stable tag: 1.3
     6Stable tag: 1.4
    77
    88This plugin ensures that your WordPress website runs optimally using Incapsula.
     
    1818
    1919* The plugin sets the value of $_SERVER['REMOTE_ADDR'] according to the client IP value reported by the Incapsula proxy.
    20 * The plugin will automatically position itself to execute first so that all other plugins that require the originating IP, continue to operate as usual.
     20* The plugin will execute with a high priority, to make sure it runs as early as possible.
    2121
    2222ABOUT INCAPSULA:
     
    3333
    3434== Changelog ==
     35
     36= 1.4 =
     37* Instead of fiddling with the plugins' order on the $active_plugins record as before, the plugin now runs on the "init" hook, with a very high priority (set to -9999999).
    3538 
    3639= 1.3 =
Note: See TracChangeset for help on using the changeset viewer.