Ejemplo n.º 1
0
/**
 * Purge the whole cache.
 *
 * @since  1.0.0.
 *
 * @param  array $purge_args Additional args to pass to the purge request.
 * @return array|bool|WP_Error                   The purge response.
 */
function purgely_purge_all($purge_args = array())
{
    $purgely = new Purgely_Purge();
    $purge_args = array_merge(array('allow-all' => Purgely_Settings::get_setting('allow_purge_all')), $purge_args);
    $purgely->purge('all', '', $purge_args);
    return $purgely->get_result();
}
Ejemplo n.º 2
0
 /**
  * Set the settings values.
  *
  * @since 1.0.0.
  *
  * @param  array $settings The current settings values.
  * @return void
  */
 public static function set_settings($settings)
 {
     self::$settings = $settings;
 }
Ejemplo n.º 3
0
 public function test_constants_are_used_when_database_options_are_empty_when_getting_individual_setting()
 {
     \WP_Mock::wpFunction('get_option', array('args' => array('purgely-settings', array()), 'times' => 1, 'return' => array()));
     $fastly_key = Purgely_Settings::get_setting('fastly_key');
     $this->assertEquals(PURGELY_FASTLY_KEY, $fastly_key);
 }
Ejemplo n.º 4
0
 /**
  * Add the Fastly API credential header to the request.
  *
  * @since 1.0.0.
  *
  * @param array $remote_request_args The current remote request args.
  * @return array The modified remote request args.
  */
 private function _add_credentials($remote_request_args)
 {
     $remote_request_args['headers']['Fastly-Key'] = Purgely_Settings::get_setting('fastly_key');
     return $remote_request_args;
 }
Ejemplo n.º 5
0
 public function setUp()
 {
     \WP_Mock::setUp();
     // Ensure that the settings are in a default state
     Purgely_Settings::set_settings(array());
 }
Ejemplo n.º 6
0
 /**
  * Sanitize all of the setting.
  *
  * @since 1.0.0.
  *
  * @param  array $settings The unsanitized settings.
  * @return array           The sanitized settings.
  */
 public function sanitize_settings($settings)
 {
     $clean_settings = array();
     $registered_settings = Purgely_Settings::get_registered_settings();
     foreach ($settings as $key => $value) {
         if (isset($registered_settings[$key])) {
             $clean_settings[$key] = call_user_func($registered_settings[$key]['sanitize_callback'], $value);
         }
     }
     return $settings;
 }
Ejemplo n.º 7
0
 /**
  * Initiate actions.
  *
  * @return Purgely
  */
 public function __construct()
 {
     // Set the main paths for the plugin.
     $this->root_dir = dirname(__FILE__);
     $this->src_dir = $this->root_dir . '/src';
     $this->file_path = $this->root_dir . '/' . basename(__FILE__);
     $this->url_base = untrailingslashit(plugins_url('/', __FILE__));
     // Include dependent files.
     include $this->src_dir . '/config.php';
     include $this->src_dir . '/utils.php';
     include $this->src_dir . '/classes/settings.php';
     include $this->src_dir . '/classes/related-urls.php';
     include $this->src_dir . '/classes/purge-request-collection.php';
     include $this->src_dir . '/classes/purge-request.php';
     include $this->src_dir . '/classes/header.php';
     include $this->src_dir . '/classes/header-cache-control.php';
     include $this->src_dir . '/classes/header-surrogate-control.php';
     include $this->src_dir . '/classes/header-surrogate-keys.php';
     include $this->src_dir . '/classes/surrogate-key-collection.php';
     if (is_admin()) {
         include $this->src_dir . '/settings-page.php';
     }
     // Handle all automatic purges.
     include $this->src_dir . '/wp-purges.php';
     // Initialize the key collector.
     $this::$surrogate_keys_header = new Purgely_Surrogate_Keys_Header();
     // Initialize the surrogate control header.
     $this::$surrogate_control_header = new Purgely_Surrogate_Control_Header(Purgely_Settings::get_setting('surrogate_control_ttl'));
     // Add the surrogate keys.
     add_action('wp', array($this, 'set_standard_keys'), 100);
     // Set the default stale while revalidate and stale if error values.
     if (true === Purgely_Settings::get_setting('enable_stale_while_revalidate')) {
         $this->add_cache_control_header(Purgely_Settings::get_setting('stale_while_revalidate_ttl'), 'stale-while-revalidate');
     }
     if (true === Purgely_Settings::get_setting('enable_stale_if_error')) {
         $this->add_cache_control_header(Purgely_Settings::get_setting('stale_if_error_ttl'), 'stale-if-error');
     }
     // Send the surrogate keys.
     add_action('wp', array($this, 'send_surrogate_keys'), 101);
     // Set and send the surrogate control header.
     add_action('wp', array($this, 'send_surrogate_control'), 101);
     // Set and send the surrogate control header.
     add_action('wp', array($this, 'send_cache_control'), 101);
     // Load in WP CLI.
     if (defined('WP_CLI') && WP_CLI) {
         include $this->src_dir . '/wp-cli.php';
     }
     // Load the textdomain.
     add_action('plugins_loaded', array($this, 'load_plugin_textdomain'));
 }