| 1 |
<?php |
| 2 |
|
| 3 |
namespace Pronamic\WordPress\PronamicClient; |
| 4 |
|
| 5 |
class AkismetModule { |
| 6 |
/** |
| 7 |
* Instance of this class. |
| 8 |
* |
| 9 |
* @since 1.4.0 |
| 10 |
* |
| 11 |
* @var Tracking |
| 12 |
*/ |
| 13 |
protected static $instance = null; |
| 14 |
|
| 15 |
/** |
| 16 |
* Plugin |
| 17 |
* |
| 18 |
* @var Plugin |
| 19 |
*/ |
| 20 |
private $plugin; |
| 21 |
|
| 22 |
/** |
| 23 |
* Construct Akismet module. |
| 24 |
* |
| 25 |
* @param Plugin $plugin |
| 26 |
*/ |
| 27 |
private function __construct( Plugin $plugin ) { |
| 28 |
$this->plugin = $plugin; |
| 29 |
|
| 30 |
\add_action( 'admin_init', [ $this, 'admin_init' ] ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Admin init. |
| 35 |
* |
| 36 |
* @link https://plugins.trac.wordpress.org/browser/akismet/tags/4.1.3/class.akismet-admin.php#L890 |
| 37 |
*/ |
| 38 |
public function admin_init() { |
| 39 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 40 |
if ( ! array_key_exists( 'page', $_GET ) || 'akismet-key-config' !== \sanitize_text_field( \wp_unslash( $_GET['page'] ) ) ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 45 |
if ( ! array_key_exists( 'view', $_GET ) || 'stats' !== \sanitize_text_field( \wp_unslash( $_GET['view'] ) ) ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! \method_exists( '\Akismet', 'get_api_key' ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
$api_key = \Akismet::get_api_key(); |
| 54 |
|
| 55 |
if ( 'fc432369b1e26b1aeb4119e2deb0be15' !== \md5( $api_key ) ) { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
\wp_die( \__( 'Sorry, you are not allowed to view this page.', 'pronamic-client' ) ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Return an instance of this class. |
| 64 |
* |
| 65 |
* @since 1.1.0 |
| 66 |
* |
| 67 |
* @return object A single instance of this class. |
| 68 |
*/ |
| 69 |
public static function get_instance( $plugin = false ) { |
| 70 |
// If the single instance hasn't been set, set it now. |
| 71 |
if ( null === self::$instance ) { |
| 72 |
self::$instance = new self( $plugin ); |
| 73 |
} |
| 74 |
|
| 75 |
return self::$instance; |
| 76 |
} |
| 77 |
} |
| 78 |
|