PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
jetpack / jetpack_vendor / automattic / jetpack-premium-analytics / src / class-post-list-link.php

class-post-list-link.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-premium-analytics/src/class-post-list-link.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post list table integration.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8 namespace Automattic\Jetpack\PremiumAnalytics;
9
10 /**
11 * Sends the views column in the posts and pages list tables to the dashboard's
12 * post detail page instead of the Stats one.
13 *
14 * @since 0.4.0
15 */
16 class Post_List_Link {
17
18 /**
19 * Claim the column's link. Idempotent, like the other register() calls.
20 *
21 * Outside the admin-chrome gate on purpose: Quick Edit re-renders the cell
22 * over AJAX, where that gate is closed.
23 *
24 * @return void
25 */
26 public static function register() {
27 add_filter( 'jetpack_stats_post_list_column_url', array( __CLASS__, 'filter_url' ), 10, 2 );
28 }
29
30 /**
31 * Point one row at its post detail page.
32 *
33 * Wins even where the row would otherwise point at Calypso: this dashboard is the site's
34 * analytics UI and exists only in wp-admin, so the admin-interface preference doesn't apply.
35 *
36 * Defence in depth: Admin_Post_List_Column::add_stats_post_table() already drops the column
37 * without `view_stats`/`manage_options`, but this filter is public and its next caller may not gate.
38 *
39 * @param string $url Stats URL for the post.
40 * @param int $post_id The post the row belongs to.
41 * @return string
42 */
43 public static function filter_url( $url, $post_id ) {
44 $post_id = (int) $post_id;
45
46 if ( $post_id <= 0 ) {
47 return $url;
48 }
49
50 if ( ! Capabilities::current_user_can_view_analytics() ) {
51 return $url;
52 }
53
54 return Analytics::dashboard_url( '/post/' . $post_id );
55 }
56 }
57