PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.5
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.5
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / widgets / gutenberg / lib / experimental / class-wp-rest-customizer-nonces.php
widget-options / includes / widgets / gutenberg / lib / experimental Last commit date
fonts-api 2 years ago interactivity-api 2 years ago block-editor-settings-mobile.php 2 years ago block-editor-settings.php 2 years ago blocks.php 2 years ago class-gutenberg-rest-global-styles-revisions-controller.php 2 years ago class-wp-classic-to-block-menu-converter.php 2 years ago class-wp-navigation-fallback-gutenberg.php 2 years ago class-wp-rest-block-editor-settings-controller.php 2 years ago class-wp-rest-customizer-nonces.php 2 years ago class-wp-rest-navigation-fallback-controller.php 2 years ago editor-settings.php 2 years ago kses.php 2 years ago l10n.php 2 years ago navigation-fallback.php 2 years ago navigation-theme-opt-in.php 2 years ago rest-api.php 2 years ago
class-wp-rest-customizer-nonces.php
73 lines
1 <?php
2 /**
3 * WP_Rest_Customizer_Nonces class.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Class that returns the customizer "save" nonce that's required for the
10 * batch save operation using the customizer API endpoint.
11 */
12 class WP_Rest_Customizer_Nonces extends WP_REST_Controller {
13
14 /**
15 * Constructor.
16 */
17 public function __construct() {
18 $this->namespace = '__experimental';
19 $this->rest_base = 'customizer-nonces';
20 }
21
22 /**
23 * Registers the necessary REST API routes.
24 *
25 * @access public
26 */
27 public function register_routes() {
28 register_rest_route(
29 $this->namespace,
30 '/' . $this->rest_base . '/get-save-nonce',
31 array(
32 array(
33 'methods' => WP_REST_Server::READABLE,
34 'callback' => array( $this, 'get_save_nonce' ),
35 'permission_callback' => array( $this, 'permissions_check' ),
36 'args' => $this->get_collection_params(),
37 ),
38 'schema' => array( $this, 'get_public_item_schema' ),
39 )
40 );
41 }
42
43 /**
44 * Checks if a given request has access to read menu items if they have access to edit them.
45 *
46 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
47 */
48 public function permissions_check() {
49 $post_type = get_post_type_object( 'nav_menu_item' );
50 if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
51 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.', 'gutenberg' ), array( 'status' => rest_authorization_required_code() ) );
52 }
53 return true;
54 }
55
56 /**
57 * Returns the nonce required to request the customizer API endpoint.
58 *
59 * @access public
60 */
61 public function get_save_nonce() {
62 require_once ABSPATH . 'wp-includes/class-wp-customize-manager.php';
63 $wp_customize = new WP_Customize_Manager();
64 $nonce = wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() );
65 return array(
66 'success' => true,
67 'nonce' => $nonce,
68 'stylesheet' => $wp_customize->get_stylesheet(),
69 );
70 }
71
72 }
73