PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
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 13.8.3 All 506 releases
jetpack / jetpack_vendor / automattic / jetpack-import / src / endpoints / class-custom-css.php

class-custom-css.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at jetpack_vendor/automattic/jetpack-import/src/endpoints/class-custom-css.php

76 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Custom CSS REST route
4 *
5 * @package automattic/jetpack-import
6 */
7
8 namespace Automattic\Jetpack\Import\Endpoints;
9
10 use WP_Error;
11 use WP_REST_Request;
12 use WP_REST_Response;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 0 );
16 }
17
18 require_once ABSPATH . 'wp-includes/theme.php';
19
20 /**
21 * Class Custom_CSS
22 */
23 class Custom_CSS extends \WP_REST_Posts_Controller {
24
25 /**
26 * Base class
27 */
28 use Import;
29
30 /**
31 * The Import ID add a new item to the schema.
32 */
33 use Import_ID;
34
35 /**
36 * Whether the controller supports batching.
37 *
38 * @var array
39 */
40 protected $allow_batch = array( 'v1' => true );
41
42 /**
43 * Constructor.
44 */
45 public function __construct() {
46 parent::__construct( 'custom_css' );
47
48 $this->rest_base = 'custom-css';
49 }
50
51 /**
52 * Update the custom CSS post.
53 *
54 * @param WP_REST_Request $request Full details about the request.
55 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
56 */
57 public function create_item( $request ) {
58 // Set the WP_IMPORTING constant to prevent sync notifications
59 $this->set_importing();
60 $args = array(
61 'stylesheet' => $request['title'],
62 );
63
64 $post = wp_update_custom_css_post( $request['content'], $args );
65
66 if ( is_wp_error( $post ) ) {
67 return $post;
68 }
69
70 $response = $this->prepare_item_for_response( $post, $request );
71 $response = rest_ensure_response( $response );
72
73 return $this->add_import_id_metadata( $request, $response );
74 }
75 }
76