W3TCVarnish_Plugin

Class Varnish_Plugin.

Defined (1)

The class is defined in the following location(s).

/Varnish_Plugin.php  
  1. /* class Varnish_Plugin 
  2. */ 
  3. class Varnish_Plugin { 
  4. /** 
  5. * Runs plugin 
  6. */ 
  7. public function run() { 
  8. Util_AttachToActions::flush_posts_on_actions(); 
  9.  
  10. add_action( 'w3tc_flush_all',  
  11. array( $this, 'varnish_flush' ),  
  12. 2000, 1 ); 
  13. add_action( 'w3tc_flush_post',  
  14. array( $this, 'varnish_flush_post' ),  
  15. 2000, 1 ); 
  16. add_action( 'w3tc_flushable_posts', '__return_true', 2000 ); 
  17. add_action( 'w3tc_flush_posts',  
  18. array( $this, 'varnish_flush' ),  
  19. 2000 ); 
  20. add_action( 'w3tc_flush_url',  
  21. array( $this, 'varnish_flush_url' ),  
  22. 2000, 1 ); 
  23.  
  24. add_filter( 'w3tc_admin_bar_menu',  
  25. array( $this, 'w3tc_admin_bar_menu' ) ); 
  26.  
  27.  
  28.  
  29. /** 
  30. * Purges varnish cache 
  31. * @return mixed 
  32. */ 
  33. public function varnish_flush( $extras = array() ) { 
  34. if ( isset( $extras['only'] ) && $extras['only'] != 'varnish' ) 
  35. return; 
  36.  
  37. $varnishflush = Dispatcher::component( 'Varnish_Flush' ); 
  38. $v = $varnishflush->flush(); 
  39.  
  40. return $v; 
  41.  
  42. /** 
  43. * Purges post from varnish 
  44. * @param integer $post_id 
  45. * @return mixed 
  46. */ 
  47. public function varnish_flush_post( $post_id ) { 
  48. $varnishflush = Dispatcher::component( 'Varnish_Flush' ); 
  49. $v = $varnishflush->flush_post( $post_id ); 
  50.  
  51. return $v; 
  52.  
  53. /** 
  54. * Purges post from varnish 
  55. * @param string $url 
  56. * @return mixed 
  57. */ 
  58. public function varnish_flush_url( $url ) { 
  59. $varnishflush = Dispatcher::component( 'Varnish_Flush' ); 
  60. $v = $varnishflush->flush_url( $url ); 
  61.  
  62. return $v; 
  63.  
  64. public function w3tc_admin_bar_menu( $menu_items ) { 
  65. $menu_items['20610.varnish'] = array( 
  66. 'id' => 'w3tc_flush_varnish',  
  67. 'parent' => 'w3tc_flush',  
  68. 'title' => __( 'Reverse Proxy', 'w3-total-cache' ),  
  69. 'href' => wp_nonce_url( network_admin_url( 
  70. 'admin.php?page=w3tc_dashboard&w3tc_flush_varnish' ),  
  71. 'w3tc' ) 
  72. ); 
  73.  
  74. return $menu_items;