| Server IP : 172.67.133.75 / Your IP : 162.159.115.10 Web Server : nginx/1.26.1 System : Linux HE9229 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/jl3_ph_com/wp-content/plugins/elementor/modules/wp-rest/classes/ |
Upload File : |
<?php
namespace Elementor\Modules\WpRest\Classes;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Elementor_Settings {
public function register(): void {
register_rest_route('elementor/v1', '/settings/(?P<key>[\w_-]+)', [
[
'methods' => \WP_REST_Server::READABLE,
'permission_callback' => function (): bool {
return current_user_can( 'manage_options' );
},
'sanitize_callback' => function ( string $param ): string {
return esc_attr( $param );
},
'validate_callback' => function ( \WP_REST_Request $request ): bool {
$params = $request->get_params();
return 0 === strpos( $params['key'], 'elementor' );
},
'callback' => function ( $request ): \WP_REST_Response {
try {
$key = $request->get_param( 'key' );
$current_value = get_option( $key );
return new \WP_REST_Response([
'success' => true,
// Nest in order to allow extending the response with more details.
'data' => [
'value' => $current_value,
],
], 200);
} catch ( \Exception $e ) {
return new \WP_REST_Response([
'success' => false,
'data' => [
'message' => $e->getMessage(),
],
], 500);
}
},
],
]);
register_rest_route('elementor/v1', '/settings/(?P<key>[\w_-]+)', [
[
'methods' => \WP_REST_Server::EDITABLE,
'permission_callback' => function (): bool {
return current_user_can( 'manage_options' );
},
'sanitize_callback' => function ( string $param ): string {
return esc_attr( $param );
},
'validate_callback' => function ( \WP_REST_Request $request ): bool {
$params = $request->get_params();
return 0 === strpos( $params['key'], 'elementor' ) && isset( $params['value'] );
},
'callback' => function ( \WP_REST_Request $request ): \WP_REST_Response {
$key = $request->get_param( 'key' );
$new_value = $request->get_param( 'value' );
$current_value = get_option( $key );
if ( $new_value === $current_value ) {
return new \WP_REST_Response([
'success' => true,
], 200);
}
$success = update_option( $key, $new_value );
if ( $success ) {
return new \WP_REST_Response([
'success' => true,
'data' => [
'message' => 'Setting updated successfully.',
],
], 200);
} else {
return new \WP_REST_Response([
'success' => false,
'data' => [
'message' => 'Failed to update setting.',
],
], 500);
}
},
],
]);
}
}