-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache-purge.php
More file actions
77 lines (73 loc) · 2.07 KB
/
cache-purge.php
File metadata and controls
77 lines (73 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
Plugin Name: Cache Purge
Description: Trigger a cache purge of Cloudflare and/or GraphCDN on content change
Version: 1.0.0
Author: Funkhaus
Plugin URI: https://github.com/funkhaus/cache-purge
Author URI: http://funkhaus.us
*/
/*
* Import required files
*/
include_once plugin_dir_path(__FILE__) . "includes/utilities.php";
include_once plugin_dir_path(__FILE__) . "includes/purger.php";
include_once plugin_dir_path(__FILE__) . "includes/settings.php";
include_once plugin_dir_path(__FILE__) . "includes/admin-bar.php";
include_once plugin_dir_path(__FILE__) . "includes/api.php";
include_once plugin_dir_path(__FILE__) . "includes/nested-page-compatibility.php";
/*
* Plugin activated, setup default options
*/
function cp_plugin_activated()
{
$defaults = [
"graphcdn_admin_url" => "",
"graphcdn_token" => "",
"cloudflare_zone_id" => "",
"cloudflare_token" => "",
];
add_option("cp_settings", $defaults);
}
register_activation_hook(__FILE__, "cp_plugin_activated");
function cp_admin_scripts()
{
$plugin_version = '1.0.0';
wp_enqueue_script("jquery");
wp_enqueue_script(
"cp_main",
plugins_url("js/main.js", __FILE__),
null,
$plugin_version
);
wp_enqueue_style(
"cp_main",
plugins_url("css/main.css", __FILE__),
null,
$plugin_version
);
wp_enqueue_style("dashicons");
$js_vars = [
"hasConfiguredCacheProvider" => cp_has_configured_plugin(),
"nonce" => wp_create_nonce("wp_rest"),
"apiUrl" => site_url("/wp-json/cp")
];
wp_add_inline_script(
"cp_main",
"var cp_vars = " . wp_json_encode($js_vars),
"before"
);
}
add_action("admin_enqueue_scripts", "cp_admin_scripts");
function cp_add_api_routes()
{
// Use this to trigger a cache purge
register_rest_route("cp", "/purge", [
[
"methods" => "POST",
"callback" => "cp_purge_post",
"permission_callback" => "cp_check_user_can_purge",
],
]);
}
add_action("rest_api_init", "cp_add_api_routes");