Skip to content

Commit

Permalink
Add newsletter/reply-to proxy endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
enejb committed Apr 26, 2024
1 parent 9b454a4 commit b0b9fcd
Showing 1 changed file with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/**
* REST API endpoint for the Newsletter Categories
*
* @package automattic/jetpack
* @since 12.6
*/

use Automattic\Jetpack\Status\Host;

require_once __DIR__ . '/trait-wpcom-rest-api-proxy-request-trait.php';

/**
* Class WPCOM_REST_API_V2_Endpoint_Following
*/
class WPCOM_REST_API_V2_Endpoint_Subscriptions_Reply_To extends WP_REST_Controller {
use WPCOM_REST_API_Proxy_Request_Trait;

/**
* Constructor.
*/
public function __construct() {
$this->wpcom_is_wpcom_only_endpoint = true;
$this->wpcom_is_site_specific_endpoint = true;
$this->base_api_path = 'wpcom';
$this->version = 'v2';
$this->namespace = $this->base_api_path . '/' . $this->version;
$this->rest_base = '/newsletter/reply-to';
$this->wpcom_is_wpcom_only_endpoint = true;
$this->wpcom_is_site_specific_endpoint = true;

add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}

/**
* Register routes.
*/
public function register_routes() {
register_rest_route(
$this->namespace,
$this->rest_base,
array(
'show_in_index' => true,
'methods' => WP_REST_Server::READABLE,
// if this is not a wpcom site, we need to proxy the request to wpcom
'callback' => ( ( new Host() )->is_wpcom_simple() ) ? array( $this, 'get_reply_to_status' ) : array( $this, 'proxy_request_to_wpcom_as_user' ),
'permission_callback' => array( $this, 'permissions' ),
)
);

register_rest_route(
$this->namespace,
$this->rest_base,
array(
'show_in_index' => true,
'methods' => WP_REST_Server::CREATABLE,
// if this is not a wpcom site, we need to proxy the request to wpcom
'callback' => ( ( new Host() )->is_wpcom_simple() ) ? array( $this, 'resend_verification' ) : array( $this, 'proxy_request_to_wpcom_as_user' ),
'permission_callback' => array( $this, 'permissions' ),
)
);
}
/**
* Permission check for the endpoints.
*
* @return bool
*/
public function permissions() {
return current_user_can( 'manage_options' );
}

/**
* Get the state of the reply-to setting.
*
* @return array
*/
public function get_reply_to_status() {
return rest_ensure_response(

Check failure on line 78 in projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-subscriptions-reply-to.php

View workflow job for this annotation

GitHub Actions / Static analysis

TypeError PhanTypeMismatchReturn Returning rest_ensure_response(['status'=>apply_filters('jetpack_subscriptions_reply_to_status', 'not_set')]) of type \WP_Error|\WP_REST_Response but get_reply_to_status() is declared to return array
array(
'status' => apply_filters( 'jetpack_subscriptions_reply_to_status', 'not_set' ),
)
);
}
/**
* Resend the verification email.
*
* @return array
*/
public function resend_verification() {
return rest_ensure_response(

Check failure on line 90 in projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-subscriptions-reply-to.php

View workflow job for this annotation

GitHub Actions / Static analysis

TypeError PhanTypeMismatchReturn Returning rest_ensure_response(['resend'=>apply_filters('jetpack_subscriptions_reply_to_status_resend', null)]) of type \WP_Error|\WP_REST_Response but resend_verification() is declared to return array
array(
'resend' => apply_filters( 'jetpack_subscriptions_reply_to_status_resend', null ),
)
);
}
}

wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Subscriptions_Reply_To' );

0 comments on commit b0b9fcd

Please sign in to comment.