| 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 |
|