PluginProbe
Plausible Analytics / trunk
Plausible Analytics vtrunk
2.6.1 2.6.0 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 All 52 releases
plausible-analytics / src / Verification.php

Verification.php in Plausible Analytics trunk, at src/Verification.php

68 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plausible Analytics | Actions.
4 * @since 1.0.0
5 * @package WordPress
6 * @subpackage Plausible Analytics
7 */
8
9 namespace Plausible\Analytics\WP;
10
11 class Verification {
12 /**
13 * Build class.
14 * @return void
15 * @since 1.0.0
16 */
17 public function __construct( $init = true ) {
18 if ( $init ) {
19 $this->init();
20 }
21 }
22
23 /**
24 * Plugin actions/hooks
25 * @return void
26 */
27 private function init() {
28 add_action( 'wp_head', [ $this, 'maybe_insert_version_meta_tag' ] );
29 }
30
31 /**
32 * This <meta> tag "tells" the Plausible API which version of the plugin is used, to allow tailored error messages,
33 * specific to the plugin version.
34 *
35 * @return void
36 */
37 public function maybe_insert_version_meta_tag() {
38 $running_verification = array_key_exists( 'plausible_verification', $_GET );
39
40 if ( ! $running_verification ) {
41 return;
42 }
43
44 $version = $this->get_plugin_version();
45
46 if ( $version ) {
47 echo "<meta name='plausible-analytics-version' content='$version' />\n";
48 }
49 }
50
51 /**
52 * Retrieves the plugin's current version.
53 */
54 private function get_plugin_version() {
55 if ( ! function_exists( 'get_plugin_data' ) ) {
56 require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @codeCoverageIgnore
57 }
58
59 static $data = null;
60
61 if ( $data === null ) {
62 $data = get_plugin_data( PLAUSIBLE_ANALYTICS_PLUGIN_FILE );
63 }
64
65 return $data['Version'] ?? '';
66 }
67 }
68