Skip to content

Commit 495c63e

Browse files
dcalhounclaude
andauthored
feat: add GET endpoint for spam site referrers (#47566)
* feat: get spam site referrers endpoint Add GET endpoint for retrieving list of spam site referrers to enable listing and managing spam site referrers. * changelog * test: add referrers spam GET route to REST controller test coverage Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
1 parent cb67f41 commit 495c63e

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Add GET endpoint for retrieving spam site referrers.

projects/packages/stats-admin/src/class-rest-controller.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ public function register_rest_routes() {
256256
)
257257
);
258258

259+
// Get referrer spam list.
260+
register_rest_route(
261+
static::$namespace,
262+
sprintf( '/sites/%d/stats/referrers/spam', Jetpack_Options::get_option( 'id' ) ),
263+
array(
264+
'methods' => WP_REST_Server::READABLE,
265+
'callback' => array( $this, 'get_referrer_spam_list' ),
266+
'permission_callback' => array( $this, 'can_user_view_general_stats_callback' ),
267+
)
268+
);
269+
259270
// Mark referrer spam.
260271
register_rest_route(
261272
static::$namespace,
@@ -1022,6 +1033,25 @@ public function get_notice_status() {
10221033
return ( new Notices() )->get_notices_to_show();
10231034
}
10241035

1036+
/**
1037+
* Get the list of spam referrers.
1038+
*
1039+
* @return array
1040+
*/
1041+
public function get_referrer_spam_list() {
1042+
return WPCOM_Client::request_as_blog(
1043+
sprintf(
1044+
'/sites/%d/stats/referrers/spam',
1045+
Jetpack_Options::get_option( 'id' )
1046+
),
1047+
'v1.1',
1048+
array(
1049+
'timeout' => 5,
1050+
'method' => 'GET',
1051+
)
1052+
);
1053+
}
1054+
10251055
/**
10261056
* Mark a referrer as spam.
10271057
*

projects/packages/stats-admin/tests/php/REST_Controller_Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class REST_Controller_Test extends Stats_TestCase {
2121
'/jetpack/v4/stats-app/sites/999/stats/country-views',
2222
'/jetpack/v4/stats-app/sites/999/stats/clicks',
2323
'/jetpack/v4/stats-app/sites/999/stats/referrers',
24+
'/jetpack/v4/stats-app/sites/999/stats/referrers/spam',
2425
'/jetpack/v4/stats-app/sites/999/stats/top-authors',
2526
'/jetpack/v4/stats-app/sites/999/stats/video-plays',
2627
'/jetpack/v4/stats-app/sites/999/posts',

0 commit comments

Comments
 (0)