From 0fbd6baf74ebd0ed5f2467eae3025010134f192c Mon Sep 17 00:00:00 2001 From: Edward Date: Wed, 20 Mar 2024 07:18:43 +0100 Subject: [PATCH] Add post row analytics link --- src/Filters.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Filters.php b/src/Filters.php index e08e319e..0c6d9c1f 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -24,6 +24,7 @@ public function __construct() { add_filter( 'script_loader_tag', [ $this, 'add_plausible_attributes' ], 10, 2 ); add_filter( 'rest_url', [ $this, 'wpml_compatibility' ], 10, 1 ); add_filter( 'plausible_analytics_script_params', [ $this, 'maybe_add_custom_params' ] ); + add_filter( "post_row_actions", [ $this, 'add_link_to_analytics'], 10 , 2); } /** @@ -122,4 +123,22 @@ public function maybe_add_custom_params( $params ) { return apply_filters( 'plausible_analytics_pageview_properties', $params ); } + + /** + * Add link to analytics page for a single post + * @param array $actions + * @param WP_Post $post + * + * @return array + */ + public function add_link_to_analytics($actions, $post){ + if($post->post_status != "publish") return $actions; + + $url = wp_make_link_relative( get_permalink( $post->ID ) ); + $url = admin_url("index.php?page=plausible_analytics_statistics&page-url=$url"); + + $actions["plausible-analytics"] = "Analytics"; + + return $actions; + } }