Changeset 725508
- Timestamp:
- 06/12/2013 12:47:48 AM (13 years ago)
- Location:
- better-wp-varnish/trunk
- Files:
-
- 3 edited
-
better-wp-varnish.php (modified) (13 diffs)
-
inc/admin.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
better-wp-varnish/trunk/better-wp-varnish.php
r700897 r725508 4 4 Plugin URI: http://bit51.com/software/better-wp-varnish/ 5 5 Description: A better solution for clearing Varnish cache with WordPress 6 Version: 0.0.26 Version: Dev 7 7 Text Domain: better-wp-varnish 8 8 Domain Path: /languages … … 10 10 Author URI: http://bit51.com 11 11 License: GPLv2 12 Copyright 2012 Bit51.com (email: [email protected])12 Copyright 2012 - 2013 Bit51.com (email: [email protected]) 13 13 */ 14 14 … … 21 21 class bit51_bwpv extends Bit51 { 22 22 23 public $pluginversion = '000 2'; //current plugin version23 public $pluginversion = '0003'; //current plugin version 24 24 25 25 //important plugin information … … 49 49 50 50 global $bwpvoptions, $bwpvdata; 51 52 $this->pluginname = __( 'Better WP Varnish', 'better_wp_varnish' ); 51 53 52 54 //set path information … … 79 81 if ( $bwpvoptions['enabled'] == 1 ) { 80 82 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' ) ); 92 94 93 95 } … … 106 108 'parent' => false, // use 'false' for a root menu, or pass the ID of the parent menu 107 109 'id' => 'bwpv', // link ID, defaults to a sanitized title value 108 'title' => __( 'Varnish', $this->hook), // link title110 'title' => __( 'Varnish', 'better_wp_varnish' ), // link title 109 111 'href' => admin_url( 'options-general.php?page=better-wp-varnish' ), // name of file 110 112 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' ); … … 121 123 'parent' => 'bwpv', // use 'false' for a root menu, or pass the ID of the parent menu 122 124 'id' => 'bwpv-cp', // link ID, defaults to a sanitized title value 123 'title' => __( 'Clear This Page', $this->hook), // link title125 'title' => __( 'Clear This Page', 'better_wp_varnish' ), // link title 124 126 'href' => admin_url( 'options-general.php?page=better-wp-varnish&flush=current&id=' . $id . '&_wpnonce=' . $nonce ), // name of file 125 127 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' ); … … 130 132 'parent' => 'bwpv', // use 'false' for a root menu, or pass the ID of the parent menu 131 133 'id' => 'bwpv-ca', // link ID, defaults to a sanitized title value 132 'title' => __( 'Clear All', $this->hook), // link title134 'title' => __( 'Clear All', 'better_wp_varnish' ), // link title 133 135 'href' => admin_url( 'options-general.php?page=better-wp-varnish&flush=all&id=' . ( $id === false ? 'opts' : $id ) . '&_wpnonce=' . $nonce ), // name of file 134 136 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' ); … … 145 147 **/ 146 148 function purgeAll() { 147 148 $errorHandler = __( 'WordPress Core File Writing ignored.', $this->hook );149 149 150 150 if ( $this->purgeVarnish( '(.*)' ) == true ) { 151 151 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; 157 157 158 158 } … … 173 173 if ( $success == true ) { 174 174 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; 180 180 181 181 } … … 199 199 if ( $success == true ) { 200 200 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; 206 206 207 207 } … … 232 232 if ( $success == true ) { 233 233 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; 239 239 240 240 } … … 260 260 $out .= 'Connection: Close' . PHP_EOL . PHP_EOL; 261 261 262 $sock = fsockopen( $bwpvoptions['address'], $bwpvoptions['port'], $errno, $errstr, $bwpvoptions['timeout'] );262 $sock = @fsockopen( $bwpvoptions['address'], $bwpvoptions['port'], $errno, $errstr, $bwpvoptions['timeout'] ); 263 263 264 264 if ( $sock ) { 265 265 266 fwrite( $sock, $out );267 $result = fread( $sock, 256 );268 fclose( $sock );266 @fwrite( $sock, $out ); 267 $result = @fread( $sock, 256 ); 268 @fclose( $sock ); 269 269 270 270 } -
better-wp-varnish/trunk/inc/admin.php
r700897 r725508 11 11 12 12 //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' ) ); 15 15 16 16 //add menu items 17 add_action( 'admin_menu', array( &$this, 'register_settings_page' ) );17 add_action( 'admin_menu', array( $this, 'register_settings_page' ) ); 18 18 19 19 //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' ) ); 21 24 22 25 //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 ); 24 27 25 28 //add donation reminder 26 add_action( 'admin_init', array( &$this, 'ask' ) );29 add_action( 'admin_init', array( $this, 'ask' ) ); 27 30 28 31 } … … 33 36 function register_settings_page() { 34 37 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' ) ); 36 39 37 40 } … … 43 46 function bwpv_admin_init() { 44 47 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' ), 46 55 47 56 array( 48 57 49 array( __( 'Instructions', $this->hook), 'install_instructions' ), //primary admin page content50 array( __( 'General Options', $this->hook), 'general_options' ), //primary admin page content58 array( __( 'Instructions', 'better_wp_varnish' ), 'install_instructions' ), //primary admin page content 59 array( __( 'General Options', 'better_wp_varnish' ), 'general_options' ), //primary admin page content 51 60 52 61 ) … … 61 70 function install_instructions() { 62 71 ?> 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> 64 73 <?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 65 116 } 66 117 … … 69 120 */ 70 121 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; 88 123 ?> 89 124 <form method="post" action="options.php"> … … 92 127 <tr valign="top"> 93 128 <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 /> 97 132 </td> 98 133 </tr> 99 134 </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> 101 136 </form> 102 137 <?php -
better-wp-varnish/trunk/readme.txt
r700897 r725508 2 2 3 3 === Better WP Varnish === 4 Contributors: Bit51 4 Contributors: Bit51, ChrisWiegman 5 5 Donate link: http://bit51.com/software/better-wp-varnish/ 6 6 Tags: varnish, cache, performance 7 7 Requires at least: 3.5 8 Tested up to: 3. 5.18 Tested up to: 3.6 9 9 Stable tag: 0.0.2 10 10 … … 53 53 == Changelog == 54 54 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 55 63 = 0.0.2 = 56 64 * Fixed Bit51 feed with improved error handling
Note: See TracChangeset
for help on using the changeset viewer.