PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / classes / WpMatomo / Annotations.php
matomo / classes / WpMatomo Last commit date
Admin 5 years ago Commands 6 years ago Db 6 years ago Ecommerce 6 years ago Report 6 years ago Site 5 years ago TrackingCode 5 years ago User 5 years ago views 6 years ago API.php 5 years ago Access.php 6 years ago AjaxTracker.php 5 years ago Annotations.php 6 years ago Bootstrap.php 6 years ago Capabilities.php 6 years ago Compatibility.php 6 years ago Email.php 5 years ago Installer.php 6 years ago Logger.php 5 years ago OptOut.php 5 years ago Paths.php 6 years ago PrivacyBadge.php 6 years ago Referral.php 6 years ago Roles.php 6 years ago ScheduledTasks.php 6 years ago Settings.php 5 years ago Site.php 6 years ago TrackingCode.php 5 years ago Uninstaller.php 6 years ago Updater.php 6 years ago User.php 6 years ago
Annotations.php
87 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 * @package matomo
8 */
9
10 namespace WpMatomo;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // if accessed directly
14 }
15
16 class Annotations {
17 /**
18 * @var Settings
19 */
20 private $settings;
21
22 /**
23 * @var Logger
24 */
25 private $logger;
26
27 /**
28 * @param Settings $settings
29 */
30 public function __construct( $settings ) {
31 $this->settings = $settings;
32 $this->logger = new Logger();
33 }
34
35 public function register_hooks() {
36 add_action( 'transition_post_status', array( $this, 'add_annotation' ), 10, 3 );
37 }
38
39 /**
40 * Identify new posts if an annotation is required
41 * and create Piwik annotation
42 *
43 * @param string $new_status new post status
44 * @param string $old_status old post status
45 * @param object $post current post object
46 */
47 public function add_annotation( $new_status, $old_status, $post ) {
48 if ( ! $this->settings->is_tracking_enabled() ) {
49 return;
50 }
51
52 $enabled_post_types = $this->settings->get_global_option( 'add_post_annotations' );
53
54 if ( empty( $enabled_post_types[ $post->post_type ] ) ) {
55 return;
56 }
57
58 if ( 'publish' === $new_status
59 && 'publish' !== $old_status ) {
60 $site = new Site();
61 $idsite = $site->get_current_matomo_site_id();
62
63 if ( ! $idsite ) {
64 return; // no site we can add it to
65 }
66
67 try {
68 Bootstrap::do_bootstrap();
69
70 $logger = $this->logger;
71 \Piwik\Access::doAsSuperUser(
72 function () use ( $post, $logger, $idsite ) {
73 $note = esc_html__( 'Published:', 'matomo' ) . ' ' . $post->post_title . ' - URL: ' . get_permalink( $post->ID );
74 \Piwik\Plugins\Annotations\API::unsetInstance();// make sure latest instance will be loaded with all up to date dependencies... mainly needed for tests
75 $id = \Piwik\Plugins\Annotations\API::getInstance()->add( $idsite, gmdate( 'Y-m-d' ), $note );
76 $logger->log( 'Add post annotation. ' . $note . ' - ' . wp_json_encode( $id ) );
77 }
78 );
79 } catch ( \Exception $e ) {
80 $this->logger->log( 'Add post annotation failed: ' . $e->getMessage() );
81
82 return;
83 }
84 }
85 }
86 }
87