PluginProbe ʕ •ᴥ•ʔ
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback / 5.1.3
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback v5.1.3
5.1.3 5.1.2 5.1.1 5.1 5.0 trunk 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2.0 3.2.1 3.22 3.22.1 3.22.2 3.22.3 3.22.4 3.22.5 3.22.6 3.3.0 3.3.1 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.30 3.31 3.32 3.4 3.4.1 3.4.3 3.4.4 3.5 3.5.1 3.6 3.6.1 3.7 3.8 3.9 3.9.1 3.9.2 3.9.3 3.9.4 3.9.6 3.9.6.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2 4.2.1 4.2.2 4.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4
atarim-visual-collaboration / third-party / wp-activity-log / class-avcf-wpal-rest.php
atarim-visual-collaboration / third-party / wp-activity-log Last commit date
atarim-wpal-integration-guide.txt 4 days ago class-avcf-wpal-abilities.php 4 days ago class-avcf-wpal-detector.php 4 days ago class-avcf-wpal-rest.php 4 days ago class-avcf-wpal-stats.php 4 days ago
class-avcf-wpal-rest.php
90 lines
1 <?php
2 /**
3 * REST endpoints for WP Activity Log statistics.
4 *
5 * Exposes WPAL yesterday counts and (premium) drill-down links to Atarim's
6 * dashboard backend over the existing atarim/v1 REST namespace. The MCP
7 * surface registers its own abilities in doit/class-avcf-mcp.php and does
8 * not depend on these endpoints.
9 *
10 * Authentication is server-to-server via the X-Atarim-Token header, validated
11 * against the secret token saved during site connection. WordPress user
12 * sessions are not used because the Atarim app calls these endpoints from
13 * its own backend.
14 *
15 * Endpoints:
16 * GET /wp-json/atarim/v1/wpal/stats Yesterday's counts plus availability.
17 * GET /wp-json/atarim/v1/wpal/links Premium drill-down links (or fallback).
18 *
19 * @package atarim-visual-collaboration
20 */
21
22 if ( ! defined('ABSPATH') ) {
23 exit; // Exit if accessed directly
24 }
25
26 class AVCF_WPAL_REST {
27
28 /**
29 * @var AVCF_WPAL_Stats
30 */
31 private $stats;
32
33 /**
34 * @var AVCF_MCP_Auth
35 */
36 private $auth;
37
38 public function __construct() {
39 $this->stats = new AVCF_WPAL_Stats();
40 $this->auth = new AVCF_MCP_Auth();
41 add_action( 'rest_api_init', array( $this, 'avcf_wpal_register_routes' ) );
42 }
43
44 public function avcf_wpal_register_routes() {
45 $permission_callback = array( $this, 'avcf_wpal_permission_check' );
46
47 register_rest_route( 'atarim/v1', '/wpal/stats', array(
48 'methods' => 'GET',
49 'callback' => array( $this, 'avcf_wpal_handle_stats' ),
50 'permission_callback' => $permission_callback,
51 ) );
52
53 register_rest_route( 'atarim/v1', '/wpal/links', array(
54 'methods' => 'GET',
55 'callback' => array( $this, 'avcf_wpal_handle_links' ),
56 'permission_callback' => $permission_callback,
57 ) );
58 }
59
60 /**
61 * Authenticate the request against the Atarim secret token.
62 *
63 * These endpoints are called server-to-server by Atarim's backend, so
64 * no WordPress user session is available. Auth is by shared secret in
65 * the X-Atarim-Token header, validated with hash_equals against the
66 * token saved during site connection (avc_atarim_secret_token).
67 */
68 public function avcf_wpal_permission_check( WP_REST_Request $request ) {
69 if ( $this->auth->avcf_mcp_validate_request() ) {
70 return true;
71 }
72
73 return new WP_Error(
74 'avcf_wpal_invalid_token',
75 __( 'Invalid or missing Atarim authentication token.', 'atarim-visual-collaboration' ),
76 array( 'status' => 401 )
77 );
78 }
79
80 public function avcf_wpal_handle_stats( WP_REST_Request $request ) {
81 return new WP_REST_Response( $this->stats->avcf_wpal_get_yesterday_counts(), 200 );
82 }
83
84 public function avcf_wpal_handle_links( WP_REST_Request $request ) {
85 return new WP_REST_Response( $this->stats->avcf_wpal_get_yesterday_links(), 200 );
86 }
87 }
88
89 new AVCF_WPAL_REST();
90