| Server IP : 10.19.1.101 / Your IP : 216.73.216.158 Web Server : Apache System : Linux web1f13.kinghost.net 5.4.282-1.el8.elrepo.x86_64 #1 SMP Mon Aug 19 18:33:22 EDT 2024 x86_64 User : schererimoveisrs ( 170628) PHP Version : 7.4.33 Disable Function : apache_child_terminate,c99_buff_prepare,c99_sess_put,dl,exec,leak,link,myshellexec,openlog,passthru,pclose,pcntl_exec,php_check_syntax,php_strip_whitespace,popen,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,socket_listen,socket_create_listen,putenv MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/schererimoveisrs/www/wp-content/plugins/elementor/app/modules/site-builder/rest/ |
Upload File : |
<?php
namespace Elementor\App\Modules\SiteBuilder\Rest;
use Elementor\Plugin;
use WP_Error;
use WP_REST_Response;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Rest_Api {
const API_NAMESPACE = 'elementor/v1';
const API_BASE = 'site-builder';
const SNAPSHOT_MAX_KEYS = 20;
public function register_routes(): void {
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/home-screen', [
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_home_screen' ],
'permission_callback' => fn() => current_user_can( 'manage_options' ),
] );
register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/snapshot', [
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_snapshot' ],
'permission_callback' => fn() => current_user_can( 'manage_options' ),
],
[
'methods' => WP_REST_Server::EDITABLE,
'callback' => [ $this, 'update_snapshot' ],
'permission_callback' => fn() => current_user_can( 'manage_options' ),
'args' => [
'value' => [
'required' => true,
'type' => 'object',
'validate_callback' => fn( $value ) => is_array( $value ),
'sanitize_callback' => fn( $value ) => is_array( $value ) ? $value : [],
],
],
],
] );
}
public function get_home_screen() {
$app = $this->get_connect_app();
if ( ! $app || ! $app->is_connected() ) {
return new WP_Error( 'site_builder_unavailable', 'Site builder is not connected.', [ 'status' => 503 ] );
}
$data = $app->get_home_screen();
if ( is_wp_error( $data ) ) {
return $data;
}
return new WP_REST_Response( $data, 200 );
}
public function get_snapshot() {
$snapshot = get_option( 'elementor_site_builder_snapshot', [] );
return new WP_REST_Response( [
'success' => true,
'data' => [ 'value' => $snapshot ],
], 200 );
}
public function update_snapshot( $request ) {
$value = $request->get_param( 'value' );
$sanitized = is_array( $value ) ? $value : [];
if ( count( $sanitized ) > self::SNAPSHOT_MAX_KEYS ) {
return new WP_REST_Response( [
'success' => false,
'data' => [ 'message' => 'Snapshot exceeds maximum allowed size.' ],
], 400 );
}
$success = update_option( 'elementor_site_builder_snapshot', $sanitized, false );
if ( $success || get_option( 'elementor_site_builder_snapshot' ) === $sanitized ) {
return new WP_REST_Response( [
'success' => true,
'data' => [ 'message' => 'Snapshot updated successfully.' ],
], 200 );
}
return new WP_REST_Response( [
'success' => false,
'data' => [ 'message' => 'Failed to update snapshot.' ],
], 500 );
}
protected function get_connect_app() {
if ( ! Plugin::$instance->common ) {
return null;
}
$connect = Plugin::$instance->common->get_component( 'connect' );
if ( ! $connect ) {
return null;
}
return $connect->get_app( 'site-builder' );
}
}