1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plugin Name: PageSpeed Purge Button |
4
|
|
|
* Plugin URI: https://github.com/salaros/wp-pagespeed-purge |
5
|
|
|
* Description: One-click PageSpeed cache purging using an admin bar button |
6
|
|
|
* Version: 1.0.1 |
7
|
|
|
* Author: Zhmayev Yaroslav aka Salaros |
8
|
|
|
* Author URI: https://salaros.com |
9
|
|
|
* License: MIT |
10
|
|
|
* License URI: https://opensource.org/licenses/MIT |
11
|
|
|
* Text Domain: wp-pagespeed-purge |
12
|
|
|
* Domain Path: /languages/ |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
exit; // Exit if accessed directly. |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
class PageSpeedPurge { |
20
|
|
|
|
21
|
|
|
public function __construct() { |
22
|
|
|
// Enqueue css and js files |
23
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'embed_admin_assets' ), 101 ); |
24
|
|
|
|
25
|
|
|
// Add 'Clear Redis cache' button to the admin bar |
26
|
|
|
add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_button' ), 101 ); |
27
|
|
|
|
28
|
|
|
// Load plugin textdomain |
29
|
|
|
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function embed_admin_assets() { |
|
|
|
|
33
|
|
|
// This is where you can add your CSS/JS entries for wp-admin UI |
34
|
|
|
$plugin_url = plugin_dir_url( __FILE__ ); |
35
|
|
|
wp_enqueue_style( 'admin-styles', sprintf( '%s/assets/wp-pagespeed-purge.css', $plugin_url ) ); |
36
|
|
|
wp_enqueue_script( 'admin-styles', sprintf( '%s/assets/wp-pagespeed-purge.js', $plugin_url ), array( 'jquery' ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function add_admin_bar_button( $wp_admin_bar ) { |
|
|
|
|
40
|
|
|
$args = [ |
41
|
|
|
'id' => 'pagespeed_purge', |
42
|
|
|
'href' => '#pagespeed_purge', |
43
|
|
|
'title' => __( 'Purge Pagespeed Cache', 'wp-pagespeed-purge' ), |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$wp_admin_bar->add_menu( $args ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function load_plugin_textdomain() { |
|
|
|
|
50
|
|
|
$textdomain = 'wp-pagespeed-purge'; |
51
|
|
|
$plugin_locale = apply_filters( 'plugin_locale', get_locale(), $textdomain ); |
52
|
|
|
$plugin_dir = dirname( __FILE__ ); |
53
|
|
|
|
54
|
|
|
// wp-content/languages/plugin-name/plugin-name-ru_RU.mo |
55
|
|
|
load_textdomain( $textdomain, sprintf( '%s/plugins/%s-%s.mo', WP_LANG_DIR , $textdomain, $plugin_locale ) ); |
56
|
|
|
|
57
|
|
|
// wp-content/plugins/plugin-name/languages/plugin-name-ru_RU.mo |
58
|
|
|
load_textdomain( $textdomain, sprintf( '%s/languages/%s-%s.mo', $plugin_dir , $textdomain, $plugin_locale ) ); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
new PageSpeedPurge(); |
63
|
|
|
|
This check marks method names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.