PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.1
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 3.1.10 All 111 releases
templately / includes / API / DeveloperSettings.php

DeveloperSettings.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.4.1, at includes/API/DeveloperSettings.php

107 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\API;
4
5 use Templately\Core\Developer;
6 use WP_REST_Request;
7
8 /**
9 * Developer Settings API
10 *
11 * Handles developer-only settings that are available when TEMPLATELY_DEVELOPER_MODE is enabled
12 *
13 * @since 3.3.4
14 */
15 class DeveloperSettings extends API {
16
17 /**
18 * @param $request WP_REST_Request
19 * @return bool
20 */
21 public function permission_check( WP_REST_Request $request ) {
22 // Only allow access if developer mode is enabled and user has manage_options capability
23 return Developer::is_developer_mode_enabled() && current_user_can( 'manage_options' );
24 }
25
26 /**
27 * Register API routes
28 */
29 public function register_routes() {
30 $this->get( 'developer-settings', [ $this, 'get_settings' ] );
31 $this->post( 'developer-settings', [ $this, 'update_settings' ] );
32 }
33
34 /**
35 * Get current developer settings
36 *
37 * @return array
38 */
39 public function get_settings() {
40 $settings = Developer::get_settings();
41 $config = Developer::get_available_constants();
42 $override_status = Developer::get_constant_override_status();
43
44 return $this->success( [
45 'success' => true,
46 'data' => $settings,
47 'config' => $config,
48 'override_status' => $override_status,
49 ] );
50 }
51
52 /**
53 * Update developer settings
54 *
55 * Note: This method saves settings to the database but they won't take effect
56 * until the constants are updated in wp-config.php or the master constant is used.
57 *
58 * @return array
59 */
60 public function update_settings() {
61 $settings = $this->get_param( 'settings', [] );
62
63 if ( empty( $settings ) ) {
64 return $this->error( 'invalid_settings', __( 'No settings provided.', 'templately' ), 'update_settings', 400 );
65 }
66
67 // Use Developer class to update settings
68 $success = Developer::update_settings( $settings );
69
70 if ( ! $success ) {
71 return $this->error( 'update_failed', __( 'Failed to update developer settings.', 'templately' ), 'update_settings', 500 );
72 }
73
74 // Get the sanitized settings
75 $sanitized_settings = Developer::sanitize_settings( $settings );
76
77 return $this->success( [
78 'success' => true,
79 'data' => [
80 'message' => __( 'Developer settings saved successfully.', 'templately' ),
81 'settings' => $sanitized_settings,
82 'note' => __( 'Settings have been saved to the database. To activate them, add the generated constants to your wp-config.php file or ensure TEMPLATELY_DEVELOPER_MODE is enabled.', 'templately' )
83 ],
84 ] );
85 }
86
87 /**
88 * Get all available developer constants and their descriptions
89 *
90 * @return array
91 */
92 public function get_available_constants() {
93 $constants = Developer::get_available_constants();
94 return $this->success( $constants );
95 }
96
97 /**
98 * Check if network admin functionality is available
99 *
100 * @return array
101 */
102 public function get_network_admin_status() {
103 $status = Developer::get_network_admin_status();
104 return $this->success( $status );
105 }
106 }
107