PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / settings / REST / Preferences.php

Preferences.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/settings/REST/Preferences.php

46 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Modules\Settings\REST;
4
5 use Templately\Admin\API\BaseAPI;
6 use Templately\Modules\Settings\Preferences as PreferencesStore;
7 use WP_REST_Request;
8
9 /**
10 * Per-user preference endpoint — separate route from settings/update on purpose:
11 * that handler unconditionally writes site options (an empty `siteTitle` blanks
12 * `blogname`), so piggybacking a personal pref on it would force callers to
13 * resend the whole site-settings payload. It also requires `manage_options`,
14 * while a personal UI pref belongs to anyone who can use the editor.
15 */
16 class Preferences extends BaseAPI {
17 private $endpoint = 'settings/preferences';
18
19 public function permission_check( WP_REST_Request $request ) {
20 $this->request = $request;
21
22 return is_user_logged_in() && current_user_can( 'edit_posts' );
23 }
24
25 public function register_routes() {
26 $this->post( $this->endpoint, [ $this, 'update_preferences' ] );
27 }
28
29 public function update_preferences() {
30 $preferences = $this->request->get_param( 'preferences' );
31
32 if ( ! is_array( $preferences ) ) {
33 return $this->error(
34 'invalid_preferences',
35 __( 'No preferences provided.', 'templately' ),
36 'settings/preferences',
37 400
38 );
39 }
40
41 return $this->success( [
42 'applied' => PreferencesStore::update( $preferences ),
43 ] );
44 }
45 }
46