Plugin Directory

Changeset 725508


Ignore:
Timestamp:
06/12/2013 12:47:48 AM (13 years ago)
Author:
Bit51
Message:

Preparing for 1.0

Location:
better-wp-varnish/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • better-wp-varnish/trunk/better-wp-varnish.php

    r700897 r725508  
    44    Plugin URI: http://bit51.com/software/better-wp-varnish/
    55    Description: A better solution for clearing Varnish cache with WordPress
    6     Version: 0.0.2
     6    Version: Dev
    77    Text Domain: better-wp-varnish
    88    Domain Path: /languages
     
    1010    Author URI: http://bit51.com
    1111    License: GPLv2
    12     Copyright 2012 Bit51.com (email: [email protected])
     12    Copyright 2012 - 2013 Bit51.com (email: [email protected])
    1313*/
    1414
     
    2121    class bit51_bwpv extends Bit51 {
    2222   
    23         public $pluginversion   = '0002'; //current plugin version
     23        public $pluginversion   = '0003'; //current plugin version
    2424   
    2525        //important plugin information
     
    4949
    5050            global $bwpvoptions, $bwpvdata;
     51
     52            $this->pluginname = __( 'Better WP Varnish', 'better_wp_varnish' );
    5153       
    5254            //set path information
     
    7981            if ( $bwpvoptions['enabled'] == 1 ) {
    8082
    81                 add_action( 'edit_post', array( &$this, 'purgePost' ), 99 );
    82                 add_action( 'edit_post', array(  &$this, 'purgeCommon' ), 99 );
    83                 add_action( 'comment_post', array( &$this, 'purgeComment' ), 99 );
    84                 add_action( 'edit_comment', array( &$this, 'purgeComment' ), 99 );
    85                 add_action( 'trashed_comment', array( &$this, 'purgeComment' ), 99 );
    86                 add_action( 'untrashed_comment', array( &$this, 'purgeComment' ), 99 );
    87                 add_action( 'deleted_comment', array( &$this, 'purgeComment' ), 99 );
    88                 add_action( 'deleted_post', array( &$this, 'purgePost' ), 99 );
    89                 add_action( 'deleted_post', array( &$this, 'purgeCommon' ), 99 );
    90 
    91                 add_action( 'wp_before_admin_bar_render', array( &$this, 'adminBar' ) );               
     83                add_action( 'edit_post', array( $this, 'purgePost' ), 99 );
     84                add_action( 'edit_post', array(  $this, 'purgeCommon' ), 99 );
     85                add_action( 'comment_post', array( $this, 'purgeComment' ), 99 );
     86                add_action( 'edit_comment', array( $this, 'purgeComment' ), 99 );
     87                add_action( 'trashed_comment', array( $this, 'purgeComment' ), 99 );
     88                add_action( 'untrashed_comment', array( $this, 'purgeComment' ), 99 );
     89                add_action( 'deleted_comment', array( $this, 'purgeComment' ), 99 );
     90                add_action( 'deleted_post', array( $this, 'purgePost' ), 99 );
     91                add_action( 'deleted_post', array( $this, 'purgeCommon' ), 99 );
     92
     93                add_action( 'wp_before_admin_bar_render', array( $this, 'adminBar' ) );             
    9294
    9395            }
     
    106108                    'parent' => false, // use 'false' for a root menu, or pass the ID of the parent menu
    107109                    'id' => 'bwpv', // link ID, defaults to a sanitized title value
    108                     'title' => __( 'Varnish', $this->hook ), // link title
     110                    'title' => __( 'Varnish', 'better_wp_varnish' ), // link title
    109111                    'href' => admin_url( 'options-general.php?page=better-wp-varnish' ), // name of file
    110112                    'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
     
    121123                        'parent' => 'bwpv', // use 'false' for a root menu, or pass the ID of the parent menu
    122124                        'id' => 'bwpv-cp', // link ID, defaults to a sanitized title value
    123                         'title' => __( 'Clear This Page', $this->hook ), // link title
     125                        'title' => __( 'Clear This Page', 'better_wp_varnish' ), // link title
    124126                        'href' => admin_url( 'options-general.php?page=better-wp-varnish&flush=current&id=' . $id . '&_wpnonce=' . $nonce ), // name of file
    125127                        'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
     
    130132                    'parent' => 'bwpv', // use 'false' for a root menu, or pass the ID of the parent menu
    131133                    'id' => 'bwpv-ca', // link ID, defaults to a sanitized title value
    132                     'title' => __( 'Clear All', $this->hook ), // link title
     134                    'title' => __( 'Clear All', 'better_wp_varnish' ), // link title
    133135                    'href' => admin_url( 'options-general.php?page=better-wp-varnish&flush=all&id=' . ( $id === false ? 'opts' : $id ) . '&_wpnonce=' . $nonce ), // name of file
    134136                    'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
     
    145147         **/
    146148        function purgeAll() {
    147 
    148             $errorHandler = __( 'WordPress Core File Writing ignored.', $this->hook );
    149149           
    150150            if ( $this->purgeVarnish( '(.*)' ) == true ) {
    151151
    152                 echo '<div id="message" class="updated"><p><strong>' . __( 'Cache Succeddfully Cleared', $this->hook ) . '</strong></p></div>';
    153 
    154             } else {
    155 
    156                 echo '<div id="message" class="error"><p>' . __( 'ERROR: Could not clear cache. Contact your server administrator if this error persists.', $this->hook ) . '</p></div>';
     152                return true;
     153
     154            } else {
     155
     156                return false;
    157157
    158158            }
     
    173173            if ( $success == true ) {
    174174
    175                 echo '<div id="message" class="updated"><p><strong>' . __( 'Cache Succeddfully Cleared', $this->hook ) . '</strong></p></div>';
    176 
    177             } else {
    178 
    179                 echo '<div id="message" class="error"><p>' . __( 'ERROR: Could not clear cache. Contact your server administrator if this error persists.', $this->hook ) . '</p></div>';
     175                return true;
     176
     177            } else {
     178
     179                return false;
    180180
    181181            }
     
    199199            if ( $success == true ) {
    200200
    201                 echo '<div id="message" class="updated"><p><strong>' . __( 'Cache Succeddfully Cleared', $this->hook ) . '</strong></p></div>';
    202 
    203             } else {
    204 
    205                 echo '<div id="message" class="error"><p>' . __( 'ERROR: Could not clear cache. Contact your server administrator if this error persists.', $this->hook ) . '</p></div>';
     201                return true;
     202
     203            } else {
     204
     205                return false;
    206206
    207207            }
     
    232232            if ( $success == true ) {
    233233
    234                 echo '<div id="message" class="updated"><p><strong>' . __( 'Cache Succeddfully Cleared', $this->hook ) . '</strong></p></div>';
    235 
    236             } else {
    237 
    238                 echo '<div id="message" class="error"><p>' . __( 'ERROR: Could not clear cache. Contact your server administrator if this error persists.', $this->hook ) . '</p></div>';
     234                return true;
     235
     236            } else {
     237
     238                return false;
    239239
    240240            }
     
    260260            $out .= 'Connection: Close' . PHP_EOL . PHP_EOL;
    261261
    262             $sock = fsockopen( $bwpvoptions['address'], $bwpvoptions['port'], $errno, $errstr, $bwpvoptions['timeout'] );
     262            $sock = @fsockopen( $bwpvoptions['address'], $bwpvoptions['port'], $errno, $errstr, $bwpvoptions['timeout'] );
    263263
    264264            if ( $sock ) {
    265265               
    266                 fwrite( $sock, $out );
    267                 $result = fread( $sock, 256 );
    268                 fclose( $sock );
     266                @fwrite( $sock, $out );
     267                $result = @fread( $sock, 256 );
     268                @fclose( $sock );
    269269
    270270            }
  • better-wp-varnish/trunk/inc/admin.php

    r700897 r725508  
    1111           
    1212            //add scripts and css
    13             add_action( 'admin_print_scripts', array( &$this, 'config_page_scripts' ) );
    14             add_action( 'admin_print_styles', array( &$this, 'config_page_styles' ) );
     13            add_action( 'admin_print_scripts', array( $this, 'config_page_scripts' ) );
     14            add_action( 'admin_print_styles', array( $this, 'config_page_styles' ) );
    1515       
    1616            //add menu items
    17             add_action( 'admin_menu', array( &$this, 'register_settings_page' ) );
     17            add_action( 'admin_menu', array( $this, 'register_settings_page' ) );
    1818       
    1919            //add settings
    20             add_action( 'admin_init', array( &$this, 'register_settings' ) );
     20            add_action( 'admin_init', array( $this, 'register_settings' ) );
     21
     22            //add processing
     23            add_action( 'admin_init', array( $this, 'process_call' ) );
    2124       
    2225            //add action link
    23             add_filter( 'plugin_action_links', array( &$this, 'add_action_link' ), 10, 2 );
     26            add_filter( 'plugin_action_links', array( $this, 'add_action_link' ), 10, 2 );
    2427       
    2528            //add donation reminder
    26             add_action( 'admin_init', array( &$this, 'ask' ) );
     29            add_action( 'admin_init', array( $this, 'ask' ) );
    2730           
    2831        }
     
    3336        function register_settings_page() {
    3437
    35             add_options_page( __( $this->pluginname, $this->hook ), __( $this->pluginname, $this->hook ), $this->accesslvl, $this->hook, array( &$this,'bwpv_admin_init' ) );
     38            add_options_page( $this->pluginname, $this->pluginname, $this->accesslvl, $this->hook, array( $this,'bwpv_admin_init' ) );
    3639
    3740        }   
     
    4346        function bwpv_admin_init() {
    4447
    45             $this->admin_page( $this->pluginname . ' ' . __( 'Options', $this->hook ),
     48            global $bwpv_error;
     49
     50            if ( is_wp_error( $bwpv_error ) ) {
     51                echo '<div id="message" class="error"><p>' . __( 'ERROR: Could not clear the Varnish cache. Please check your settings below and contact your server administrator if this error persists.', 'better_wp_varnish' ) . '</p></div>';     
     52            }
     53
     54            $this->admin_page( $this->pluginname . ' ' . __( 'Options', 'better_wp_varnish' ),
    4655
    4756                array(
    4857
    49                     array( __( 'Instructions', $this->hook), 'install_instructions' ), //primary admin page content
    50                     array( __( 'General Options', $this->hook), 'general_options' ), //primary admin page content
     58                    array( __( 'Instructions', 'better_wp_varnish' ), 'install_instructions' ), //primary admin page content
     59                    array( __( 'General Options', 'better_wp_varnish' ), 'general_options' ), //primary admin page content
    5160
    5261                )
     
    6170        function install_instructions() {
    6271            ?>
    63             <p><?php _e( 'Simply enter your varnish server address and port below and select enable. Caches will automatically be cleared where appropriate (new content, comments, etc) and you can manually clear your cache via the admin bar.', $this->hook ); ?></p>
     72            <p><?php _e( 'Simply enter your varnish server address and port below and select enable. Caches will automatically be cleared where appropriate (new content, comments, etc) and you can manually clear your cache via the admin bar. Please note that messages will only diplay when there is an error. You can confirm the cache has been cleared by looking for "varnish-cleared" at the end of the URL when manually clearing the cache or if there is no error message for all other occasions.', 'better_wp_varnish' ); ?></p>
    6473            <?php
     74        }
     75
     76        /**
     77         * Process call to clear cache
     78         *
     79         * @return void
     80         */
     81        function process_call() {
     82
     83            global $bwpvoptions, $bit51bwpv, $bwpv_error;
     84
     85            if ( isset( $_GET['flush'] ) && isset( $_GET['id'] ) && wp_verify_nonce( filter_var( $_REQUEST['_wpnonce'], FILTER_SANITIZE_STRING ), 'bwpv-nonce') ) {
     86   
     87                if ( intval( $_GET['flush'] == filter_var( 'all', FILTER_SANITIZE_STRING ) ) ) {
     88
     89                    $result = $bit51bwpv->purgeAll();
     90
     91                } else {
     92
     93                    $result = $bit51bwpv->purgePost( filter_var( $_GET['id'], FILTER_SANITIZE_STRING ) );                   
     94
     95                }
     96
     97                if ( $result === false ) {
     98
     99                    $bwpv_error = new WP_Error( 'error', 'error' );
     100
     101                } else {
     102
     103                    if ( strpos( $_SERVER['HTTP_REFERER'], '?' ) === false && strpos( $_SERVER['HTTP_REFERER'], 'varnish-cleared' ) === false ) {
     104                        $cleared = '?varnish-cleared';
     105                    } else if ( strpos( $_SERVER['HTTP_REFERER'], 'varnish-cleared' ) === false ) {
     106                        $cleared = '&varnish-cleared';
     107                    } else {
     108                        $cleared = '';
     109                    }
     110
     111                    wp_safe_redirect( esc_url_raw( $_SERVER['HTTP_REFERER'] . $cleared ), 301 );
     112                }
     113
     114            }
     115
    65116        }
    66117       
     
    69120         */
    70121        function general_options() {
    71 
    72             global $bwpvoptions, $bit51bwpv;
    73 
    74             if ( isset( $_GET['flush'] ) && isset( $_GET['id'] ) && wp_verify_nonce( filter_var( $_REQUEST['_wpnonce'], FILTER_SANITIZE_STRING ), 'bwpv-nonce') ) {
    75    
    76                 if ( intval( $_GET['flush'] == filter_var( 'all', FILTER_SANITIZE_STRING ) ) ) {
    77 
    78                     $bit51bwpv->purgeAll();
    79 
    80                 } else {
    81 
    82                     $bit51bwpv->purgePost( filter_var( $_GET['id'], FILTER_SANITIZE_STRING ) );                 
    83 
    84                 }
    85 
    86             }
    87 
     122            global $bwpvoptions;
    88123            ?>
    89124            <form method="post" action="options.php">
     
    92127                    <tr valign="top">
    93128                        <td>
    94                             <input type="checkbox" name="bit51_bwpv[enabled]" id="enabled" value="1" <?php if ( $bwpvoptions['enabled'] == 1 ) echo "checked"; ?> /> <label for="buffer"><?php _e( 'Enable Varnish Cache Purge', $this->hook ); ?></label><br />
    95                             <label for"address"><?php _e( 'Server Address', $this->hook ); ?></label> <input name="bit51_bwpv[address]" id="header" value="<?php echo $bwpvoptions['address']; ?>" type="text"><br />
    96                             <label for"port"><?php _e( 'Server Address', $this->hook ); ?></label> <input name="bit51_bwpv[port]" id="port" value="<?php echo $bwpvoptions['port']; ?>" type="text"><br />
     129                            <input type="checkbox" name="bit51_bwpv[enabled]" id="enabled" value="1" <?php if ( $bwpvoptions['enabled'] == 1 ) echo "checked"; ?> /> <label for="buffer"><?php _e( 'Enable Varnish Cache Purge', 'better_wp_varnish' ); ?></label><br />
     130                            <label for"address"><?php _e( 'Server Address', 'better_wp_varnish' ); ?></label> <input name="bit51_bwpv[address]" id="header" value="<?php echo $bwpvoptions['address']; ?>" type="text"><br />
     131                            <label for"port"><?php _e( 'Server Port', 'better_wp_varnish' ); ?></label> <input name="bit51_bwpv[port]" id="port" value="<?php echo $bwpvoptions['port']; ?>" type="text"><br />
    97132                        </td>
    98133                    </tr>
    99134                </table>
    100                 <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" /></p>
     135                <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'better_wp_varnish' ) ?>" /></p>
    101136            </form>
    102137            <?php
  • better-wp-varnish/trunk/readme.txt

    r700897 r725508  
    22
    33=== Better WP Varnish ===
    4 Contributors: Bit51
     4Contributors: Bit51, ChrisWiegman
    55Donate link: http://bit51.com/software/better-wp-varnish/
    66Tags: varnish, cache, performance
    77Requires at least: 3.5
    8 Tested up to: 3.5.1
     8Tested up to: 3.6
    99Stable tag: 0.0.2
    1010
     
    5353== Changelog ==
    5454
     55= Dev =
     56* Minor refactoring
     57* Better error handling
     58* Typo correction
     59* No more messages when cache is cleared successfully
     60* Fixed options display
     61* Now uses proper translation encoding
     62
    5563= 0.0.2 =
    5664* Fixed Bit51 feed with improved error handling
Note: See TracChangeset for help on using the changeset viewer.