/**
  * Runs plugin
  */
 function run()
 {
     $cdn_engine = $this->_config->get_string('cdn.engine');
     if (Cdn_Util::is_engine_fsd($cdn_engine)) {
         $this->run_fsd();
         return;
     }
     add_filter('cron_schedules', array($this, 'cron_schedules'));
     if (!$this->_config->get_boolean('cdn.debug')) {
         add_filter('w3tc_footer_comment', array($this, 'w3tc_footer_comment'));
     }
     if (!Cdn_Util::is_engine_mirror($cdn_engine)) {
         add_action('delete_attachment', array($this, 'delete_attachment'));
         add_filter('update_attached_file', array($this, 'update_attached_file'));
         add_filter('wp_update_attachment_metadata', array($this, 'update_attachment_metadata'));
         add_action('w3_cdn_cron_queue_process', array($this, 'cron_queue_process'));
         add_action('w3_cdn_cron_upload', array($this, 'cron_upload'));
         add_action('switch_theme', array($this, 'switch_theme'));
         add_filter('update_feedback', array($this, 'update_feedback'));
     }
     add_filter('w3tc_admin_bar_menu', array($this, 'w3tc_admin_bar_menu'));
     if (is_admin()) {
         add_action('w3tc_config_ui_save-w3tc_cdn', array($this, 'change_canonical_header'), 0, 0);
         add_filter('w3tc_module_is_running-cdn', array($this, 'cdn_is_running'));
     }
     /**
      * Start rewrite engine
      */
     if ($this->can_cdn()) {
         Util_Bus::add_ob_callback('cdn', array($this, 'ob_callback'));
     }
     if (is_admin() && Cdn_Util::can_purge($cdn_engine)) {
         add_filter('media_row_actions', array($this, 'media_row_actions'), 0, 2);
     }
 }
 /**
  * Runs plugin
  */
 function run()
 {
     add_filter('w3tc_admin_bar_menu', array($this, 'w3tc_admin_bar_menu'));
     if ($this->_config->get_boolean('browsercache.html.w3tc')) {
         add_action('send_headers', array($this, 'send_headers'));
     }
     if (!$this->_config->get_boolean('browsercache.html.etag')) {
         add_filter('wp_headers', array($this, 'filter_wp_headers'), 0, 2);
     }
     if ($this->can_ob()) {
         $this->browsercache_rewrite = $this->_config->get_boolean('browsercache.rewrite');
         Util_Bus::add_ob_callback('browsercache', array($this, 'ob_callback'));
         // modify CDN urls too
         add_filter('w3tc_cdn_url', array($this, 'w3tc_cdn_url'), 0, 3);
     }
 }
 /**
  * Runs plugin
  */
 function run()
 {
     add_filter('w3tc_config_default_values', array($this, 'w3tc_config_default_values'));
     $config = Dispatcher::config();
     // remainder only when extension is frontend-active
     if (!$config->is_extension_active_frontend('newrelic')) {
         return;
     }
     if ($this->_config->get_string(array('newrelic', 'monitoring_type')) == 'browser') {
         Util_Bus::add_ob_callback('newrelic', array($this, 'ob_callback_browser'));
     } else {
         require_once W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php';
         $this->set_appname();
         if (defined('DOING_CRON') && DOING_CRON) {
             $this->background_task();
         }
         Util_Bus::add_ob_callback('newrelic', array($this, 'ob_callback_apm'));
     }
     add_filter('w3tc_footer_comment', array($this, 'w3tc_footer_comment'));
 }
 /**
  * Runs plugin
  */
 function run()
 {
     add_action('init', array($this, 'init'));
     add_filter('cron_schedules', array($this, 'cron_schedules'));
     add_filter('w3tc_admin_bar_menu', array($this, 'w3tc_admin_bar_menu'));
     if (!$this->_config->get_boolean('minify.debug')) {
         add_filter('w3tc_footer_comment', array($this, 'w3tc_footer_comment'));
     }
     if ($this->_config->get_string('minify.engine') == 'file') {
         add_action('w3_minify_cleanup', array($this, 'cleanup'));
     }
     // usage statistics handling
     add_action('w3tc_usage_statistics_of_request', array($this, 'w3tc_usage_statistics_of_request'), 10, 1);
     add_filter('w3tc_usage_statistics_metrics', array($this, 'w3tc_usage_statistics_metrics'));
     /**
      * Start minify
      */
     if ($this->can_minify()) {
         Util_Bus::add_ob_callback('minify', array($this, 'ob_callback'));
     }
 }
 /**
  * Output buffering callback
  *
  * @param string  $buffer
  * @return string
  */
 function ob_callback($buffer)
 {
     global $wpdb;
     global $w3_late_caching_succeeded;
     if ($w3_late_caching_succeeded) {
         return $buffer;
     }
     if (Util_Content::is_database_error($buffer)) {
         status_header(503);
     } else {
         if (Util_Content::can_print_comment($buffer)) {
             /**
              * Add footer comment
              */
             $date = date_i18n('Y-m-d H:i:s');
             $host = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
             if (Util_Environment::is_preview_mode()) {
                 $buffer .= "\r\n<!-- W3 Total Cache used in preview mode -->";
             }
             if ($this->_config->get_string('common.support') != '' || $this->_config->get_boolean('common.tweeted')) {
                 $buffer .= sprintf("\r\n<!-- Served from: %s @ %s by W3 Total Cache -->", Util_Content::escape_comment($host), $date);
             } else {
                 $strings = array();
                 $strings = apply_filters('w3tc_footer_comment', $strings);
                 $buffer .= "\r\n<!-- Performance optimized by W3 Total Cache. Learn more: https://www.w3-edge.com/products/\r\n";
                 if (count($strings)) {
                     $buffer .= "\r\n" . Util_Content::escape_comment(implode("\r\n", $strings)) . "\r\n";
                 }
                 $buffer .= sprintf("\r\n Served from: %s @ %s by W3 Total Cache -->", Util_Content::escape_comment($host), $date);
             }
         }
         $buffer = Util_Bus::do_ob_callbacks(array('minify', 'newrelic', 'cdn', 'browsercache', 'pagecache'), $buffer);
     }
     return $buffer;
 }
 /**
  * Do cache logic
  */
 function process()
 {
     /**
      * Skip caching for some pages
      */
     switch (true) {
         case defined('DONOTCACHEPAGE'):
             if ($this->_debug) {
                 self::log('skip processing because of DONOTCACHEPAGE constant');
             }
             return;
         case defined('DOING_AJAX'):
         case defined('DOING_CRON'):
         case defined('APP_REQUEST'):
         case defined('XMLRPC_REQUEST'):
         case defined('WP_ADMIN'):
         case defined('SHORTINIT') && SHORTINIT:
             if ($this->_debug) {
                 self::log('skip processing because of generic constant');
             }
             return;
     }
     /**
      * Do page cache logic
      */
     if ($this->_debug) {
         $this->_time_start = Util_Debug::microtime();
     }
     $this->_caching = $this->_can_cache();
     global $w3_late_init;
     if ($this->_debug) {
         self::log('start, can_cache: ' . ($this->_caching ? 'true' : 'false'));
     }
     if ($this->_caching && !$this->_late_caching) {
         $this->_cached_data = $this->_extract_cached_page(false);
         if ($this->_cached_data) {
             if ($this->_late_init) {
                 $w3_late_init = true;
                 return;
             } else {
                 $this->process_cached_page_and_exit($this->_cached_data);
                 // if is passes here - exit is not possible now and
                 // will happen on init
                 return;
             }
         } else {
             $this->_late_init = false;
         }
     } else {
         $this->_late_init = false;
     }
     $w3_late_init = $this->_late_init;
     /**
      * Start output buffering
      */
     Util_Bus::add_ob_callback('pagecache', array($this, 'ob_callback'));
 }