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-publicize / src / rest-api / class-message-templates-placeholders-controller.php

class-message-templates-placeholders-controller.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-publicize/src/rest-api/class-message-templates-placeholders-controller.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Publicize: Message Templates Placeholders Controller
4 *
5 * @package automattic/jetpack-publicize
6 */
7
8 namespace Automattic\Jetpack\Publicize\REST_API;
9
10 use Automattic\Jetpack\Publicize\Message_Templates_Placeholders;
11 use WP_REST_Server;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 0 );
15 }
16
17 /**
18 * Publicize: Message Templates Placeholders Controller class.
19 *
20 * @phan-constructor-used-for-side-effects
21 */
22 class Message_Templates_Placeholders_Controller extends Base_Controller {
23
24 /**
25 * The constructor sets the route namespace, rest_base, and registers our API route and endpoint.
26 */
27 public function __construct() {
28 parent::__construct();
29
30 $this->namespace = 'wpcom/v2';
31 $this->rest_base = 'publicize/message-templates/placeholders';
32
33 $this->allow_requests_as_blog = true;
34
35 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
36 }
37
38 /**
39 * Register the routes.
40 */
41 public function register_routes() {
42 register_rest_route(
43 $this->namespace,
44 '/' . $this->rest_base,
45 array(
46 'methods' => WP_REST_Server::READABLE,
47 'callback' => array( $this, 'get_placeholders' ),
48 'permission_callback' => array( $this, 'permissions_check' ),
49 'private_site_security_settings' => array(
50 'allow_blog_token_access' => true,
51 ),
52 'schema' => array(
53 '$schema' => 'http://json-schema.org/draft-04/schema#',
54 'title' => 'publicize-message-templates-placeholders',
55 'type' => 'array',
56 'items' => array(
57 'type' => 'object',
58 'properties' => array(
59 'id' => array(
60 'type' => 'string',
61 'description' => __( 'The placeholder token (e.g. {title}).', 'jetpack-publicize-pkg' ),
62 ),
63 'label' => array(
64 'type' => 'string',
65 'description' => __( 'Human-readable description of the placeholder.', 'jetpack-publicize-pkg' ),
66 ),
67 ),
68 ),
69 ),
70 )
71 );
72 }
73
74 /**
75 * Permission check.
76 *
77 * @return true|\WP_Error
78 */
79 public function permissions_check() {
80 return $this->publicize_permissions_check();
81 }
82
83 /**
84 * Return the placeholder catalogue.
85 *
86 * @return \WP_REST_Response
87 */
88 public function get_placeholders() {
89 return rest_ensure_response( Message_Templates_Placeholders::get_all() );
90 }
91 }
92