HEX
Server: Apache
System: Linux www 5.10.0-10-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86_64
User: root (0)
PHP: 8.2.1
Disabled: 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals
Upload Files
File: /mnt/drbd/www/edenhouse/wp-content/plugins/essential-blocks/includes/Integrations/Data.php
<?php

namespace EssentialBlocks\Integrations;

use EssentialBlocks\Utils\Settings;

class Data extends ThirdPartyIntegration {
    public function __construct() {
        $this->add_ajax( [
            'eb_fetch_options_data' => [
                'callback' => 'fetch_options_data_callback',
                'public'   => false
            ],
            'eb_save_options_data'  => [
                'callback' => 'save_options_data_callback',
                'public'   => false
            ]
        ] );
    }

    /**
     * fetch_options_data_callback
     */
    public function fetch_options_data_callback() {
        if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'admin-nonce' ) ) {
            wp_send_json_error( __( 'Nonce Error', 'essential-blocks' ) );
        }

        if ( ! current_user_can( 'activate_plugins' ) ) {
            wp_send_json_error( __( 'You are not authorized!', 'essential-blocks' ) );
        }

        if ( isset( $_POST['key'] ) ) {
            $key  = trim( $_POST['key'] );
            $data = Settings::get( $key );

            if ( $data ) {
                wp_send_json_success( wp_unslash( $data ) );
            } else {
                wp_send_json_error( __( 'No Data Found!', 'essential-blocks' ) );
            }
        } else {
            wp_send_json_error( __( 'Something went wrong regarding getting options data.', 'essential-blocks' ) );
        }
        exit;
    }

    /**
     * save_options_data_callback
     */
    public function save_options_data_callback() {
        if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'admin-nonce' ) ) {
            wp_send_json_error( __( 'Nonce Error', 'essential-blocks' ) );
        }

        if ( ! current_user_can( 'activate_plugins' ) ) {
            wp_send_json_error( __( 'You are not authorized!', 'essential-blocks' ) );
        }

        if ( isset( $_POST['key'] ) && $_POST['value'] ) {
            $key   = trim( $_POST['key'] );
            $value = trim( $_POST['value'] );

            $save = Settings::save( $key, $value );

            if ( $save ) {
                wp_send_json_success( $save );
            } else {
                wp_send_json_error( __( 'Couldn\'t save data', 'essential-blocks' ) );
            }
        } else {
            wp_send_json_error( __( 'Something went wrong regarding getting options data.', 'essential-blocks' ) );
        }
        exit;
    }
}