예제 #1
0
<?php

/*
Plugin Name: Varnish
Description: WordPress plugin for flushing Varnish cache
Version: 1.2
Plugin URI: https://github.com/shtrihstr/wp-varnish
Author: Oleksandr Strikha
Author URI: https://github.com/shtrihstr
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
require_once __DIR__ . '/class-varnish-purge.php';
$GLOBALS['varnish_purge'] = new Varnish_Purge();
if (function_exists('flush_cache_add_button')) {
    flush_cache_add_button(__('Varnish cache'), function () {
        do_action('varnish_flush_all');
    });
}
예제 #2
0
파일: cdn.php 프로젝트: shtrihstr/wp-cdn
            $regex = "https?:\\/\\/({$regex_hosts})\\/(([^\"^']+)\\.({$regex_ext}))";
            $cf_url = 'https://' . CDN_DOMAIN;
            return preg_replace("/{$regex}/Ui", "{$cf_url}/\$2", $uri);
        }
    }
    $filters = ['script_loader_src', 'style_loader_src', 'wp_get_attachment_url', 'the_content'];
    foreach ($filters as $filter) {
        add_filter($filter, 'get_cdn_attachment_url', 999);
    }
    add_filter('wp_calculate_image_srcset', function ($sources) {
        foreach ($sources as $key => $source) {
            $sources[$key]['url'] = get_cdn_attachment_url($source['url']);
        }
        return $sources;
    });
    $add_version_to_url = function ($url) {
        return add_query_arg('ver', get_option('cdn-assets-version', '1.0'), $url);
    };
    add_filter('script_loader_src', $add_version_to_url);
    add_filter('style_loader_src', $add_version_to_url);
    add_filter('editor_stylesheets', function ($stylesheets) use($add_version_to_url) {
        return array_map($add_version_to_url, $stylesheets);
    });
    add_action('muplugins_loaded', function () {
        if (function_exists('flush_cache_add_button')) {
            flush_cache_add_button(__('Assets cache'), function () {
                update_option('cdn-assets-ver', sprintf('%0.1f', get_option('cdn-assets-ver', '1.0') + 0.1));
            });
        }
    });
}
<?php

if (!wp_using_ext_object_cache()) {
    flush_cache_add_button(__('Transient cache'), function () {
        global $wpdb;
        $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_%');");
        $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_site_transient_%');");
    });
}
예제 #4
0
<?php

if (wp_using_ext_object_cache()) {
    flush_cache_add_button(__('Object cache'), 'wp_cache_flush');
}