GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PageSpeedPurge   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 1
Metric Value
eloc 21
c 6
b 1
f 1
dl 0
loc 44
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A embed_admin_assets() 0 6 3
A load_plugin_textdomain() 0 10 1
A __construct() 0 12 3
A add_admin_bar_button() 0 8 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
* Plugin Name: PageSpeed Purge Button
4
* Plugin URI:  https://github.com/salaros/wp-purge-pagespeed-button
5
* Description: One-click PageSpeed cache purging using an admin bar button
6
* Version:     10.0.5
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-purge-pagespeed-button
12
* Domain Path: /languages/
13
*/
14
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit; // Exit if accessed directly.
17
}
18
19
class PageSpeedPurge {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
21
	public function __construct() {
22
		// Enqueue css and js files
23
		$action = ( ! is_admin() && is_admin_bar_showing() )
24
			? 'wp_enqueue_scripts'
25
			: 'admin_enqueue_scripts';
26
		add_action( $action, array( $this, 'embed_admin_assets' ), 101 );
27
28
		// Add 'Clear Redis cache' button to the admin bar
29
		add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_button' ), 101 );
30
31
		// Load plugin textdomain
32
		add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
33
	}
34
35
	public function embed_admin_assets() {
36
		// This is where you can add your CSS/JS entries for wp-admin UI
37
		$plugin_url   = plugin_dir_url( __FILE__ );
38
		$asset_suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
39
		wp_enqueue_style( 'admin-styles', sprintf( '%s/assets/wp-purge-pagespeed-button%s.css', $plugin_url, $asset_suffix ) );
40
		wp_enqueue_script( 'admin-styles', sprintf( '%s/assets/wp-purge-pagespeed-button%s.js', $plugin_url, $asset_suffix ), array( 'jquery' ) );
41
	}
42
43
	public function add_admin_bar_button( $wp_admin_bar ) {
44
		$args = [
45
			'id'    => 'pagespeed_purge',
46
			'href'  => '#pagespeed_purge',
47
			'title' => __( 'Purge Pagespeed Cache', 'wp-purge-pagespeed-button' ),
48
		];
49
50
		$wp_admin_bar->add_menu( $args );
51
	}
52
53
	public function load_plugin_textdomain() {
54
		$textdomain    = 'wp-purge-pagespeed-button';
55
		$plugin_locale = apply_filters( 'plugin_locale', get_locale(), $textdomain );
56
		$plugin_dir    = dirname( __FILE__ );
57
58
		// wp-content/languages/plugin-name/plugin-name-ru_RU.mo
59
		load_textdomain( $textdomain, sprintf( '%s/plugins/%s-%s.mo', WP_LANG_DIR, $textdomain, $plugin_locale ) );
60
61
		// wp-content/plugins/plugin-name/languages/plugin-name-ru_RU.mo
62
		load_textdomain( $textdomain, sprintf( '%s/languages/%s-%s.mo', $plugin_dir, $textdomain, $plugin_locale ) );
63
	}
64
}
65
66
add_action( 'plugins_loaded', function () {
67
	new PageSpeedPurge();
68
} );
69