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/GoogleMap.php
<?php

namespace EssentialBlocks\Integrations;

use EssentialBlocks\Utils\HttpRequest;

class GoogleMap extends ThirdPartyIntegration {

	public function __construct() {
		$this->add_ajax(
			array(
				'google_map_api_key'      => array(
					'callback' => 'google_map_api_key_callback',
					'public'   => true,
				),
				'google_map_api_key_save' => array(
					'callback' => 'google_map_api_key_save_callback',
					'public'   => false,
				),
			)
		);
	}

	/**
	 * Get Google Map API
	 */
	public function google_map_api_key_callback() {
		if ( ! wp_verify_nonce( sanitize_key( $_POST['admin_nonce'] ), 'admin-nonce' ) ) {
			die(esc_html__( 'Nonce did not match', 'essential-blocks' ) );
		}

		$settings = get_option( 'eb_settings' );

		if ( is_array( $settings ) && isset( $settings['googleMapApi'] ) ) {
			wp_send_json_success( $settings['googleMapApi'] );
		} else {
			wp_send_json_error( "Couldn't found data" );
		}
		exit;
	}

	/**
	 * Google Map API key save callback
	 */
	public function google_map_api_key_save_callback() {
		if ( ! wp_verify_nonce( sanitize_key( $_POST['admin_nonce'] ), 'admin-nonce' ) ) {
			die(esc_html__( 'Nonce did not match', 'essential-blocks' ) );
		}
		if ( ! current_user_can( 'activate_plugins' ) ) {
			wp_send_json_error( __( 'You are not authorized!', 'essential-blocks' ) );
		}

		$api = '';
		if ( isset( $_POST['googleMapApi'] ) ) {
			$api = trim( sanitize_text_field( $_POST['googleMapApi'] ) );
		}

		$settings = is_array( get_option( 'eb_settings' ) ) ? get_option( 'eb_settings' ) : array();
		if ( strlen( $api ) === 0 ) {
			unset( $settings['googleMapApi'] );
		} else {
			$settings['googleMapApi'] = $api;
		}

		if ( is_array( $settings ) > 0 ) {
			$output = update_option( 'eb_settings', $settings );
			wp_send_json_success( $output );
		} else {
			wp_send_json_error( "Couldn't save data" );
		}

		exit;
	}
}