Skip to content

Commit

Permalink
Merge pull request #191 from EdwardBock/patch-1
Browse files Browse the repository at this point in the history
Add post row analytics link
  • Loading branch information
Dan0sz authored May 17, 2024
2 parents 102da20 + 0fbd6ba commit 60d5046
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Filters {
public function __construct() {
add_filter( 'script_loader_tag', [ $this, 'add_plausible_attributes' ], 10, 2 );
add_filter( 'plausible_analytics_script_params', [ $this, 'maybe_add_custom_params' ] );
add_filter( "post_row_actions", [ $this, 'add_link_to_analytics'], 10 , 2);
}

/**
Expand Down Expand Up @@ -103,4 +104,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"] = "<a href='$url'>Analytics</a>";

return $actions;
}
}

0 comments on commit 60d5046

Please sign in to comment.