W3TCExtensions_Plugin_Admin

W3 Total Cache ExtensionsAdmin plugin.

Defined (1)

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

/Extensions_Plugin_Admin.php  
  1. class Extensions_Plugin_Admin { 
  2. /** 
  3. * Config 
  4. */ 
  5. private $_config = null; 
  6.  
  7. function __construct() { 
  8. $this->_config = Dispatcher::config(); 
  9.  
  10. /** 
  11. * Runs plugin 
  12. */ 
  13. function run() { 
  14. // attach w3tc-bundled extensions 
  15. add_filter( 'w3tc_extensions', array( 
  16. '\W3TC\Extension_CloudFlare_Plugin_Admin',  
  17. 'w3tc_extensions' ),  
  18. 10, 2 ); 
  19. add_filter( 'w3tc_extensions', array( 
  20. '\W3TC\Extension_FeedBurner_Plugin_Admin',  
  21. 'w3tc_extensions' ),  
  22. 10, 2 ); 
  23. add_filter( 'w3tc_extensions', array( 
  24. '\W3TC\Extension_FragmentCache_Plugin_Admin',  
  25. 'w3tc_extensions' ),  
  26. 10, 2 ); 
  27. add_filter( 'w3tc_extensions', array( 
  28. '\W3TC\Extension_Genesis_Plugin_Admin',  
  29. 'w3tc_extensions' ),  
  30. 10, 2 ); 
  31. add_filter( 'w3tc_extensions_hooks', array( 
  32. '\W3TC\Extension_Genesis_Plugin_Admin',  
  33. 'w3tc_extensions_hooks' ) ); 
  34. add_filter( 'w3tc_notes_genesis_theme', array( 
  35. '\W3TC\Extension_Genesis_Plugin_Admin',  
  36. 'w3tc_notes_genesis_theme' ) ); 
  37. add_filter( 'w3tc_extensions', array( 
  38. '\W3TC\Extension_NewRelic_Plugin_Admin',  
  39. 'w3tc_extensions' ),  
  40. 10, 2 ); 
  41. add_filter( 'w3tc_extensions', array( 
  42. '\W3TC\Extension_Swarmify_Plugin_Admin',  
  43. 'w3tc_extensions' ),  
  44. 10, 2 ); 
  45. add_filter( 'w3tc_extensions', array( 
  46. '\W3TC\Extension_WordPressSeo_Plugin_Admin',  
  47. 'w3tc_extensions' ),  
  48. 10, 2 ); 
  49. add_filter( 'w3tc_extensions_hooks', array( 
  50. '\W3TC\Extension_WordPressSeo_Plugin_Admin',  
  51. 'w3tc_extensions_hooks' ) ); 
  52. add_action( 'w3tc_notes_wordpress_seo', array( 
  53. '\W3TC\Extension_WordPressSeo_Plugin_Admin',  
  54. 'w3tc_notes_wordpress_seo' ) ); 
  55. add_filter( 'w3tc_extensions', array( 
  56. '\W3TC\Extension_Wpml_Plugin_Admin',  
  57. 'w3tc_extensions' ),  
  58. 10, 2 ); 
  59. add_filter( 'w3tc_extensions', array( 
  60. '\W3TC\Extension_Amp_Plugin_Admin',  
  61. 'w3tc_extensions' ),  
  62. 10, 2 ); 
  63. add_filter( 'w3tc_extensions_hooks', array( 
  64. '\W3TC\Extension_Wpml_Plugin_Admin',  
  65. 'w3tc_extensions_hooks' ) ); 
  66. add_action( 'w3tc_notes_wpml', array( 
  67. '\W3TC\Extension_Wpml_Plugin_Admin',  
  68. 'w3tc_notes_wpml' ) ); 
  69.  
  70. add_action( 'admin_init', array( $this, 'admin_init' ), 1 ); 
  71. add_filter( 'pre_update_option_active_plugins', array( 
  72. $this, 'pre_update_option_active_plugins' ) ); 
  73. add_filter( 'w3tc_admin_menu', array( $this, 'w3tc_admin_menu' ), 10000 ); 
  74. add_action( 'w3tc_settings_page-w3tc_extensions',  
  75. array( $this, 'w3tc_settings_page_w3tc_extensions' ) ); 
  76.  
  77. if ( Util_Admin::is_w3tc_admin_page() ) { 
  78. if ( isset( $_GET['extension'] ) && isset( $_GET['action'] ) ) { 
  79. if ( in_array( $_GET['action'], array( 'activate', 'deactivate' ) ) ) { 
  80. add_action( 'init', array( $this, 'change_extension_status' ) ); 
  81. } elseif ( isset( $_POST['checked'] ) ) { 
  82. add_action( 'admin_init', array( $this, 'change_extensions_status' ) ); 
  83.  
  84. /** 
  85. * Adds menu 
  86. * @param unknown $menu 
  87. * @return array 
  88. */ 
  89. public function w3tc_admin_menu( $menu ) { 
  90. $menu_item = array( 
  91. 'w3tc_extensions' => array( 
  92. 'page_title' => __( 'Extensions', 'w3-total-cache' ),  
  93. 'menu_text' => __( 'Extensions', 'w3-total-cache' ),  
  94. 'visible_always' => false 
  95. ); 
  96. return array_merge( $menu, $menu_item ); 
  97.  
  98. /** 
  99. * Loads options page and corresponding view 
  100. */ 
  101. public function w3tc_settings_page_w3tc_extensions() { 
  102. $o = new Extensions_Page(); 
  103. $o->render_content(); 
  104.  
  105. public function pre_update_option_active_plugins( $o ) { 
  106. delete_option( 'w3tc_extensions_hooks' ); 
  107.  
  108. return $o; 
  109.  
  110. public function admin_init() { 
  111. // used to load even inactive extensions if they want to 
  112. $s = get_option( 'w3tc_extensions_hooks' ); 
  113. $hooks = @json_decode( $s, true ); 
  114. if ( !isset( $hooks['next_check_date'] ) || 
  115. $hooks['next_check_date'] < time() ) { 
  116. $hooks = array( 
  117. 'actions' => array(),  
  118. 'filters' => array(),  
  119. 'next_check_date' => time() + 24 * 60 * 60 
  120. ); 
  121. $hooks = apply_filters( 'w3tc_extensions_hooks', $hooks ); 
  122. update_option( 'w3tc_extensions_hooks', json_encode( $hooks ) ); 
  123.  
  124. if ( isset( $hooks['actions'] ) ) { 
  125. foreach ( $hooks['actions'] as $hook => $actions_to_call ) { 
  126. if ( is_array( $actions_to_call ) ) { 
  127. add_action( $hook, function() use ( $actions_to_call ) { 
  128. foreach ( $actions_to_call as $action ) 
  129. do_action( $action ); 
  130. } ); 
  131.  
  132. if ( isset( $hooks['filters'] ) ) { 
  133. foreach ( $hooks['filters'] as $hook => $filters_to_call ) { 
  134. if ( is_array( $filters_to_call ) ) { 
  135. add_filter( $hook, function( $v ) use ( $filters_to_call ) { 
  136. foreach ( $filters_to_call as $filter ) 
  137. $v = apply_filters( $filter, $v ); 
  138.  
  139. return $v; 
  140. } ); 
  141.  
  142. /** 
  143. * Alters the active state of multiple extensions 
  144. */ 
  145. public function change_extensions_status() { 
  146. $extensions = Util_Request::get_array( 'checked' ); 
  147. $action = Util_Request::get( 'action' ); 
  148. if ( '-1' == $action ) 
  149. $action = Util_Request::get( 'action2' ); // dropdown at bottom 
  150.  
  151. $message = ''; 
  152. if ( 'activate-selected' == $action ) { 
  153. foreach ( $extensions as $extension ) { 
  154. if ( Extensions_Util::activate_extension( $extension, $this->_config ) ) 
  155. $message .= '&activated=' . $extension; 
  156. wp_redirect( Util_Ui::admin_url( sprintf( 'admin.php?page=w3tc_extensions%s', $message ) ) ); 
  157. } elseif ( 'deactivate-selected' == $action ) { 
  158. foreach ( $extensions as $extension ) { 
  159. if ( Extensions_Util::deactivate_extension( $extension, $this->_config ) ) 
  160. $message .= '&deactivated=' . $extension; 
  161. wp_redirect( Util_Ui::admin_url( sprintf( 'admin.php?page=w3tc_extensions%s', $message ) ) ); 
  162. } else { 
  163. wp_redirect( Util_Ui::admin_url( 'admin.php?page=w3tc_extensions' ) ); 
  164.  
  165. /** 
  166. * Alters the active state of an extension 
  167. */ 
  168. public function change_extension_status() { 
  169. $action = Util_Request::get_string( 'action' ); 
  170.  
  171. if ( in_array( $action, array( 'activate', 'deactivate' ) ) ) { 
  172. $extension = Util_Request::get_string( 'extension' ); 
  173. if ( 'activate' == $action ) { 
  174. Extensions_Util::activate_extension( $extension, $this->_config ); 
  175. wp_redirect( Util_Ui::admin_url( sprintf( 'admin.php?page=w3tc_extensions&activated=%s', $extension ) ) ); 
  176. } elseif ( 'deactivate' == $action ) { 
  177. Extensions_Util::deactivate_extension( $extension, $this->_config ); 
  178. wp_redirect( Util_Ui::admin_url( sprintf( 'admin.php?page=w3tc_extensions&deactivated=%s', $extension ) ) );