| 1 |
<?php |
| 2 |
|
| 3 |
namespace WGMSRM\Traits; |
| 4 |
|
| 5 |
/** |
| 6 |
* Trait SetupWizard |
| 7 |
*/ |
| 8 |
trait SetupWizard |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Setup Wizard view |
| 13 |
* |
| 14 |
* @since 1.7.5 |
| 15 |
*/ |
| 16 |
public function wpgmap_setup_wizard() |
| 17 |
{ |
| 18 |
require WGM_PLUGIN_PATH . 'admin/includes/wpgmap_setup_wizard.php'; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Save setup wizard information |
| 23 |
* |
| 24 |
* @since 1.7.5 |
| 25 |
*/ |
| 26 |
public function wpgmap_save_setup_wizard() |
| 27 |
{ |
| 28 |
check_ajax_referer('wpgmapembed_save_setup_wizard', 'nonce'); |
| 29 |
|
| 30 |
if (!current_user_can($this->capability)) { |
| 31 |
echo wp_json_encode(['responseCode' => 403, 'message' => esc_html__('Unauthorized access.', 'gmap-embed')]); |
| 32 |
die(); |
| 33 |
} |
| 34 |
$api_key = isset($_POST['wgm_api_key']) ? sanitize_text_field(wp_unslash($_POST['wgm_api_key'])) : ''; |
| 35 |
$language = isset($_POST['wgm_language']) ? sanitize_text_field(wp_unslash($_POST['wgm_language'])) : ''; |
| 36 |
$regional_area = isset($_POST['wgm_regional_area']) ? sanitize_text_field(wp_unslash($_POST['wgm_regional_area'])) : ''; |
| 37 |
if (empty($api_key)) { |
| 38 |
$response = array('responseCode' => 101); |
| 39 |
echo wp_json_encode($response); |
| 40 |
die(); |
| 41 |
} |
| 42 |
if (empty($language)) { |
| 43 |
$response = array('responseCode' => 102); |
| 44 |
echo wp_json_encode($response); |
| 45 |
die(); |
| 46 |
} |
| 47 |
if (empty($regional_area)) { |
| 48 |
$response = array('responseCode' => 103); |
| 49 |
echo wp_json_encode($response); |
| 50 |
die(); |
| 51 |
} |
| 52 |
// Sanitize and validate before saving to DB |
| 53 |
update_option('wpgmap_api_key', sanitize_text_field($api_key), 'yes'); |
| 54 |
update_option('srm_gmap_lng', sanitize_text_field($language), 'yes'); |
| 55 |
update_option('srm_gmap_region', sanitize_text_field($regional_area), 'yes'); |
| 56 |
update_option('wgm_is_quick_setup_done', 'Y', 'yes'); |
| 57 |
$response = array('responseCode' => 200); |
| 58 |
echo wp_json_encode($response); |
| 59 |
die(); |
| 60 |
} |
| 61 |
} |
| 62 |
|