| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 4 |
/** |
| 5 |
* The admin-specific Ajax files. |
| 6 |
* |
| 7 |
* @link http://rextheme.com/ |
| 8 |
* @since 8.0.0 |
| 9 |
* |
| 10 |
* @package Wpvr |
| 11 |
* @subpackage Wpvr/admin |
| 12 |
*/ |
| 13 |
|
| 14 |
class Wpvr_Ajax |
| 15 |
{ |
| 16 |
|
| 17 |
/** |
| 18 |
* Instance of WPVR_Format class |
| 19 |
* |
| 20 |
* @var object |
| 21 |
* @since 8.0.0 |
| 22 |
*/ |
| 23 |
protected $format; |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Instance of WPVR_StreetView class |
| 28 |
* |
| 29 |
* @var object |
| 30 |
* @since 8.0.0 |
| 31 |
*/ |
| 32 |
protected $streetview; |
| 33 |
|
| 34 |
|
| 35 |
/** |
| 36 |
* Instance of WPVR_Video class |
| 37 |
* |
| 38 |
* @var object |
| 39 |
* @since 8.0.0 |
| 40 |
*/ |
| 41 |
protected $video; |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* Instance of WPVR_Scene class |
| 46 |
* |
| 47 |
* @var object |
| 48 |
* @since 8.0.0 |
| 49 |
*/ |
| 50 |
protected $scene; |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
* Instance of WPVR_Validator class |
| 55 |
* |
| 56 |
* @var object |
| 57 |
* @since 8.0.0 |
| 58 |
*/ |
| 59 |
protected $validator; |
| 60 |
|
| 61 |
|
| 62 |
function __construct() |
| 63 |
{ |
| 64 |
$this->format = new WPVR_Format(); |
| 65 |
$this->streetview = new WPVR_StreetView(); |
| 66 |
$this->video = new WPVR_Video(); |
| 67 |
$this->scene = new WPVR_Scene(); |
| 68 |
$this->validator = new WPVR_Validator(); |
| 69 |
|
| 70 |
add_action('wp_ajax_wpvr_save', array($this, 'wpvr_save_data')); |
| 71 |
add_action('wp_ajax_wpvr_preview', array($this, 'wpvr_show_preview')); |
| 72 |
add_action('wp_ajax_wpvrstreetview_preview', array($this, 'wpvrstreetview_preview')); |
| 73 |
add_action('wp_ajax_wpvr_file_import', array($this, 'wpvr_file_import')); |
| 74 |
add_action('wp_ajax_wpvr_role_management', array($this, 'wpvr_role_management')); |
| 75 |
add_action('wp_ajax_wpvr_notice', array($this, 'wpvr_notice')); |
| 76 |
add_action('wp_ajax_wpvr_dismiss_black_friday_notice', array($this, 'dismiss_black_friday_notice')); |
| 77 |
add_action('wp_ajax_wpvr_review_request', array($this, 'wpvr_review_request')); |
| 78 |
|
| 79 |
//setup wizard ajax |
| 80 |
add_action( 'wp_ajax_wpvr_create_contact', array($this, 'wpvr_create_contact' ) ); |
| 81 |
|
| 82 |
//general setting ajax |
| 83 |
add_action( 'wp_ajax_wpvr_save_general_settings', array($this, 'wpvr_save_general_settings' ) ); |
| 84 |
} |
| 85 |
|
| 86 |
public function wpvr_review_request() |
| 87 |
{ |
| 88 |
if( !current_user_can( 'manage_options' ) ){ |
| 89 |
wp_send_json_error( array( 'message' => 'Unauthorized user' ), 403 ); |
| 90 |
return; |
| 91 |
} |
| 92 |
$nonce = sanitize_text_field($_POST['nonce']); |
| 93 |
if (!wp_verify_nonce($nonce, 'wpvr-dismiss-notice-five-star-review')) { |
| 94 |
$response = array( |
| 95 |
'success' => false, |
| 96 |
'data' => 'Permission denied.' |
| 97 |
); |
| 98 |
wp_send_json($response); |
| 99 |
} |
| 100 |
$payload = !empty($_POST['payload']) ? $_POST['payload'] : array(); |
| 101 |
$data = array( |
| 102 |
'show' => !empty($payload['show']) ? $payload['show'] : '', |
| 103 |
'time' => !empty($payload['frequency']) && 'never' !== $payload['frequency'] ? time() : '', |
| 104 |
'frequency' => !empty($payload['frequency']) ? $payload['frequency'] : '', |
| 105 |
); |
| 106 |
update_option('wpvr_feed_review_request', $data); |
| 107 |
$response = array( |
| 108 |
'success' => true, |
| 109 |
'data' => 'Review request updated successfully.' |
| 110 |
); |
| 111 |
wp_send_json($response); |
| 112 |
die(); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Responsible for Tour Preview |
| 117 |
* |
| 118 |
* @return void |
| 119 |
* @since 8.0.0 |
| 120 |
*/ |
| 121 |
public function wpvr_show_preview() |
| 122 |
{ |
| 123 |
//===Current user capabilities check===// |
| 124 |
if (!current_user_can('edit_posts')) { |
| 125 |
$response = array( |
| 126 |
'success' => false, |
| 127 |
'data' => 'Contact admin.' |
| 128 |
); |
| 129 |
wp_send_json($response); |
| 130 |
} |
| 131 |
//===Current user capabilities check===// |
| 132 |
//===Nonce check===// |
| 133 |
$nonce = sanitize_text_field($_POST['nonce']); |
| 134 |
if (!wp_verify_nonce($nonce, 'wpvr')) { |
| 135 |
$response = array( |
| 136 |
'success' => false, |
| 137 |
'data' => 'Permission denied.' |
| 138 |
); |
| 139 |
wp_send_json($response); |
| 140 |
} |
| 141 |
//===Nonce check===// |
| 142 |
|
| 143 |
$panoid = ''; |
| 144 |
$postid = sanitize_text_field($_POST['postid']); |
| 145 |
$panoid = 'pano' . $postid; |
| 146 |
if (isset($_POST['panovideo'])) { |
| 147 |
$panovideo = sanitize_text_field($_POST['panovideo']); |
| 148 |
} |
| 149 |
|
| 150 |
$post_type = get_post_type($postid); |
| 151 |
if ($post_type != 'wpvr_item') { |
| 152 |
die(); |
| 153 |
} |
| 154 |
|
| 155 |
do_action('wpvr_pro_street_view_preview', $postid, $panoid); |
| 156 |
|
| 157 |
if ($panovideo == 'off') { |
| 158 |
$this->scene->wpvr_scene_preview($panoid, $panovideo); // Preapre preview based on Scene data // |
| 159 |
} else { |
| 160 |
$this->video->wpvr_video_preview($panoid); // Prepare preview based on Video data // |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
/** |
| 166 |
* Responsible for saving WPVR data |
| 167 |
* |
| 168 |
* @return void |
| 169 |
* @since 8.0.0 |
| 170 |
*/ |
| 171 |
public function wpvr_save_data() |
| 172 |
{ |
| 173 |
|
| 174 |
//===Current user capabilities check===// |
| 175 |
if (!current_user_can('edit_posts')) { |
| 176 |
$response = array( |
| 177 |
'success' => false, |
| 178 |
'data' => 'Permission denied.' |
| 179 |
); |
| 180 |
wp_send_json($response); |
| 181 |
} |
| 182 |
//===Current user capabilities check===// |
| 183 |
//===Nonce check===// |
| 184 |
$nonce = sanitize_text_field($_POST['nonce']); |
| 185 |
if (!wp_verify_nonce($nonce, 'wpvr')) { |
| 186 |
$response = array( |
| 187 |
'success' => false, |
| 188 |
'data' => 'Permission denied.' |
| 189 |
); |
| 190 |
wp_send_json($response); |
| 191 |
} |
| 192 |
//===Nonce check===// |
| 193 |
$panoid = ''; |
| 194 |
$postid = sanitize_text_field($_POST['postid']); |
| 195 |
$post_type = get_post_type($postid); |
| 196 |
if ($post_type != 'wpvr_item') { |
| 197 |
die(); |
| 198 |
} |
| 199 |
$panoid = 'pano' . $postid; |
| 200 |
|
| 201 |
$post_status = get_post_status($postid); |
| 202 |
if ($post_status != 'publish') { |
| 203 |
wp_update_post(array( |
| 204 |
'ID' => $postid, |
| 205 |
'post_status' => 'publish' |
| 206 |
)); |
| 207 |
} |
| 208 |
|
| 209 |
$post_array = []; |
| 210 |
if (isset($_POST['post_status'])) { |
| 211 |
$post_status = sanitize_text_field($_POST['post_status']); |
| 212 |
$post_array['post_status'] = $post_status; |
| 213 |
} |
| 214 |
if (isset($_POST['post_password'])) { |
| 215 |
$visibility = sanitize_text_field($_POST['post_password']); |
| 216 |
$post_array['post_password'] = $visibility; |
| 217 |
} |
| 218 |
if (isset($_POST['visibility'])) { |
| 219 |
$visibility = sanitize_text_field($_POST['visibility']); |
| 220 |
$post_array['visibility'] = $visibility; |
| 221 |
if ($visibility == 'public' || $visibility == 'private') { |
| 222 |
$post_array['post_password'] = ''; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
$user_site_language = get_locale(); |
| 227 |
$language_mapping = [ |
| 228 |
'ar' => [ // Arabic |
| 229 |
'نشر' => 'Publish', // nashr |
| 230 |
'تحديث' => 'Update' // tahdith |
| 231 |
], |
| 232 |
'pt_PT' => [ // Portuguese (Portugal) |
| 233 |
'Publicar' => 'Publish', |
| 234 |
'Atualizar' => 'Update' |
| 235 |
], |
| 236 |
'es_ES' => [ // Spanish (Spain) |
| 237 |
'Publicar' => 'Publish', |
| 238 |
'Actualizar' => 'Update' |
| 239 |
], |
| 240 |
'he_IL' => [ // Hebrew (Israel) |
| 241 |
'לפרסם' => 'Publish', // lefarsem |
| 242 |
'לעדכן' => 'Update' // le'adken |
| 243 |
], |
| 244 |
'af' => [ // Afrikaans |
| 245 |
'Publiseer' => 'Publish', |
| 246 |
'Opdateer' => 'Update' |
| 247 |
], |
| 248 |
'cs_CZ' => [ // Czech (Czech Republic) |
| 249 |
'Publikovat' => 'Publish', |
| 250 |
'Aktualizovat'=> 'Update' |
| 251 |
], |
| 252 |
'da_DK' => [ // Danish (Denmark) |
| 253 |
'Udgiv' => 'Publish', |
| 254 |
'Opdater' => 'Update' |
| 255 |
], |
| 256 |
'de_DE' => [ // German (Germany) |
| 257 |
'Veröffentlichen' => 'Publish', |
| 258 |
'Aktualisieren' => 'Update' |
| 259 |
], |
| 260 |
'fi' => [ // Finnish |
| 261 |
'Julkaise' => 'Publish', |
| 262 |
'Päivitä' => 'Update' |
| 263 |
], |
| 264 |
'hr' => [ // Croatian |
| 265 |
'Objavi' => 'Publish', |
| 266 |
'Ažuriraj' => 'Update' |
| 267 |
], |
| 268 |
'it_IT' => [ // Italian (Italy) |
| 269 |
'Pubblica' => 'Publish', |
| 270 |
'Aggiorna' => 'Update' |
| 271 |
], |
| 272 |
'ja' => [ // Japanese |
| 273 |
'� |
| 274 |
�開' => 'Publish', // こうかい (Kōkai) |
| 275 |
'更新' => 'Update' // こうしん (Kōshin) |
| 276 |
], |
| 277 |
'nl_NL' => [ // Dutch (Netherlands) |
| 278 |
'Publiceren' => 'Publish', |
| 279 |
'Bijwerken' => 'Update' |
| 280 |
], |
| 281 |
'pl_PL' => [ // Polish (Poland) |
| 282 |
'Opublikuj' => 'Publish', |
| 283 |
'Aktualizuj' => 'Update' |
| 284 |
], |
| 285 |
'ru_RU' => [ // Russian (Russia) |
| 286 |
'Опубликовать' => 'Publish', // Opublikovat' |
| 287 |
'Обновить' => 'Update' // Obnovit' |
| 288 |
], |
| 289 |
'sv_SE' => [ // Swedish (Sweden) |
| 290 |
'Publicera' => 'Publish', |
| 291 |
'Uppdatera' => 'Update' |
| 292 |
], |
| 293 |
'fr_FR' => [ // French (France) |
| 294 |
'Publier' => 'Publish', |
| 295 |
'Mettre à jour' => 'Update' |
| 296 |
], |
| 297 |
'fr_CA' => [ // French (Canada) |
| 298 |
'Publier' => 'Publish', |
| 299 |
'Mettre à jour' => 'Update', // or 'Actualiser' |
| 300 |
], |
| 301 |
'fr_BE' => [ // French (Belgium) |
| 302 |
'Publier' => 'Publish', |
| 303 |
'Mettre à jour' => 'Update', |
| 304 |
], |
| 305 |
'fr_CH' => [ // Switzerland |
| 306 |
'Publier' => 'Publish', |
| 307 |
'Mettre à jour' => 'Update', |
| 308 |
], |
| 309 |
'fr_LU' => [ // Luxembourg |
| 310 |
'Publier' => 'Publish', |
| 311 |
'Mettre à jour' => 'Update', |
| 312 |
], |
| 313 |
'fr_MC' => [ // Monaco |
| 314 |
'Publier' => 'Publish', |
| 315 |
'Mettre à jour' => 'Update', |
| 316 |
], |
| 317 |
'fr_CM' => [ // Cameroon |
| 318 |
'Publier' => 'Publish', |
| 319 |
'Mettre à jour' => 'Update', |
| 320 |
], |
| 321 |
'fr_DZ' => [ // Algeria |
| 322 |
'Publier' => 'Publish', |
| 323 |
'Mettre à jour' => 'Update', |
| 324 |
], |
| 325 |
'fr_MA' => [ // Morocco |
| 326 |
'Publier' => 'Publish', |
| 327 |
'Mettre à jour' => 'Update', |
| 328 |
], |
| 329 |
'fr_TN' => [ // Tunisia |
| 330 |
'Publier' => 'Publish', |
| 331 |
'Mettre à jour' => 'Update', |
| 332 |
], |
| 333 |
'fr_SN' => [ // Senegal |
| 334 |
'Publier' => 'Publish', |
| 335 |
'Mettre à jour' => 'Update', |
| 336 |
], |
| 337 |
'fr_HT' => [ // Haiti |
| 338 |
'Publier' => 'Publish', |
| 339 |
'Mettre à jour' => 'Update', |
| 340 |
], |
| 341 |
'fr_RW' => [ // Rwanda |
| 342 |
'Publier' => 'Publish', |
| 343 |
'Mettre à jour' => 'Update', |
| 344 |
], |
| 345 |
'fr_CD' => [ // DR Congo |
| 346 |
'Publier' => 'Publish', |
| 347 |
'Mettre à jour' => 'Update', |
| 348 |
], |
| 349 |
'fr_CI' => [ // Côte d’Ivoire |
| 350 |
'Publier' => 'Publish', |
| 351 |
'Mettre à jour' => 'Update', |
| 352 |
], |
| 353 |
]; |
| 354 |
|
| 355 |
if (isset($_POST['post_value'])) { |
| 356 |
$post_value = sanitize_text_field($_POST['post_value']); |
| 357 |
$post_value = $language_mapping[$user_site_language][$post_value] ?? $post_value; |
| 358 |
if ($post_array['visibility'] == 'private') { |
| 359 |
$post_array['post_status'] = 'private'; |
| 360 |
} elseif ($post_value === 'Publish') { |
| 361 |
$post_array['post_status'] = 'publish'; |
| 362 |
} |
| 363 |
} |
| 364 |
$post_title = sanitize_text_field($_POST['post_title']); |
| 365 |
wp_update_post(array( |
| 366 |
'ID' => $postid, |
| 367 |
'post_status' => $post_array['post_status'], |
| 368 |
'post_password' => $post_array['post_password'], |
| 369 |
'visibility' => $post_array['visibility'], |
| 370 |
'post_title' => $post_title, |
| 371 |
|
| 372 |
)); |
| 373 |
|
| 374 |
do_action('wpvr_pro_update_street_view', $postid, $panoid); |
| 375 |
|
| 376 |
if(isset( $_POST['checklistData'] ) && !empty($_POST['checklistData'])){ |
| 377 |
$checklist_data = array_map( 'sanitize_text_field', $_POST['checklistData'] ); |
| 378 |
update_post_meta($postid, 'wpvr_checklist', $checklist_data ); |
| 379 |
} |
| 380 |
|
| 381 |
if ($_POST['panovideo'] == "on") { |
| 382 |
$this->video->wpvr_update_meta_box($postid, $panoid); |
| 383 |
} else { |
| 384 |
$this->scene->wpvr_update_meta_box($postid, $panoid); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
/** |
| 390 |
* Responsible for importing tour |
| 391 |
* |
| 392 |
* @return void |
| 393 |
* @since 8.0.0 |
| 394 |
*/ |
| 395 |
public function wpvr_file_import() |
| 396 |
{ |
| 397 |
//===Current user capabilities check===// |
| 398 |
if (!current_user_can('edit_posts')) { |
| 399 |
$response = array( |
| 400 |
'success' => false, |
| 401 |
'data' => 'Permission denied.' |
| 402 |
); |
| 403 |
wp_send_json($response); |
| 404 |
} |
| 405 |
//===Current user capabilities check===// |
| 406 |
//===Nonce check===// |
| 407 |
$nonce = sanitize_text_field($_POST['nonce']); |
| 408 |
if (!wp_verify_nonce($nonce, 'wpvr')) { |
| 409 |
$response = array( |
| 410 |
'success' => false, |
| 411 |
'data' => 'Permission denied.' |
| 412 |
); |
| 413 |
wp_send_json($response); |
| 414 |
} |
| 415 |
$file_name = ''; |
| 416 |
|
| 417 |
if ( isset( $_FILES['wpvr_import_file'] ) && ! empty( $_FILES['wpvr_import_file']['tmp_name'] ) ) { |
| 418 |
$file = $_FILES['wpvr_import_file']; |
| 419 |
|
| 420 |
// Validate file type - check if it's a ZIP file |
| 421 |
$file_type = wp_check_filetype($file['name']); |
| 422 |
$file_ext = strtolower($file_type['ext']); |
| 423 |
if ($file_ext !== 'zip') { |
| 424 |
wp_send_json_error(array('message' => 'Invalid file format. Only ZIP files are allowed.')); |
| 425 |
return; |
| 426 |
} |
| 427 |
|
| 428 |
// Get WordPress uploads directory |
| 429 |
$upload_dir = wp_upload_dir(); |
| 430 |
$temp_folder = $upload_dir['basedir'] . '/wpvr_imported_temp'; |
| 431 |
|
| 432 |
// Create temp folder if it doesn't exist |
| 433 |
if ( ! file_exists( $temp_folder ) ) { |
| 434 |
wp_mkdir_p( $temp_folder ); |
| 435 |
} |
| 436 |
|
| 437 |
$file_name = basename( $file['name'] ); |
| 438 |
|
| 439 |
// Define target file path inside temp folder |
| 440 |
$target_file = $temp_folder . '/' . basename( $file['name'] ); |
| 441 |
|
| 442 |
move_uploaded_file( $file['tmp_name'], $target_file ); |
| 443 |
|
| 444 |
} else { |
| 445 |
wp_send_json_error( array( 'message' => 'No file selected.' ) ); |
| 446 |
} |
| 447 |
|
| 448 |
//===Nonce check===// |
| 449 |
WPVR_Import::prepare_tour_import_feature($file_name); |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
/** |
| 455 |
* WPVR Role Management |
| 456 |
* |
| 457 |
* @return void |
| 458 |
* @since 8.0.0 |
| 459 |
*/ |
| 460 |
function wpvr_role_management() |
| 461 |
{ |
| 462 |
|
| 463 |
//===Current user capabilities check===// |
| 464 |
if (!current_user_can('edit_posts')) { |
| 465 |
$response = array( |
| 466 |
'success' => false, |
| 467 |
'data' => 'Permission denied.' |
| 468 |
); |
| 469 |
wp_send_json($response); |
| 470 |
} |
| 471 |
//===Current user capabilities check===// |
| 472 |
//===Nonce check===// |
| 473 |
$nonce = sanitize_text_field($_POST['nonce']); |
| 474 |
if (!wp_verify_nonce($nonce, 'wpvr')) { |
| 475 |
$response = array( |
| 476 |
'success' => false, |
| 477 |
'data' => 'Permission denied.' |
| 478 |
); |
| 479 |
wp_send_json($response); |
| 480 |
} |
| 481 |
//===Nonce check===// |
| 482 |
|
| 483 |
$editor = sanitize_text_field($_POST['editor']); |
| 484 |
$author = sanitize_text_field($_POST['author']); |
| 485 |
$fontawesome = sanitize_text_field($_POST['fontawesome']); |
| 486 |
|
| 487 |
|
| 488 |
$cardboard = !empty($_POST['wpvr_cardboard_disable']) ? sanitize_text_field($_POST['wpvr_cardboard_disable']) : 'no'; // |
| 489 |
|
| 490 |
$wpvr_webp_conversion = !empty($_POST['wpvr_webp_conversion']) ? sanitize_text_field($_POST['wpvr_webp_conversion']) : 'no'; |
| 491 |
|
| 492 |
$mobile_media_resize = sanitize_text_field($_POST['mobile_media_resize']); |
| 493 |
$high_res_image = sanitize_text_field($_POST['high_res_image']); |
| 494 |
$dis_on_hover = sanitize_text_field($_POST['dis_on_hover']); |
| 495 |
$wpvr_frontend_notice = sanitize_text_field($_POST['wpvr_frontend_notice']); |
| 496 |
$wpvr_frontend_notice_area = sanitize_text_field($_POST['wpvr_frontend_notice_area']); |
| 497 |
$wpvr_script_control = sanitize_text_field($_POST['wpvr_script_control']); |
| 498 |
$wpvr_script_list = sanitize_text_field($_POST['wpvr_script_list']); |
| 499 |
|
| 500 |
$wpvr_video_script_control = sanitize_text_field($_POST['wpvr_video_script_control']); |
| 501 |
$wpvr_video_script_list = sanitize_text_field($_POST['wpvr_video_script_list']); |
| 502 |
|
| 503 |
// $enable_woocommerce = sanitize_text_field($_POST['woocommerce']); |
| 504 |
|
| 505 |
$wpvr_script_list = str_replace(' ', '', $wpvr_script_list); |
| 506 |
|
| 507 |
update_option('wpvr_editor_active', $editor); |
| 508 |
update_option('wpvr_author_active', $author); |
| 509 |
update_option('wpvr_fontawesome_disable', $fontawesome); |
| 510 |
update_option('wpvr_cardboard_disable', $cardboard); |
| 511 |
update_option('wpvr_webp_conversion', $wpvr_webp_conversion); |
| 512 |
update_option('mobile_media_resize', $mobile_media_resize); |
| 513 |
update_option('high_res_image', $high_res_image); |
| 514 |
update_option('dis_on_hover', $dis_on_hover); |
| 515 |
update_option('wpvr_frontend_notice', $wpvr_frontend_notice); |
| 516 |
update_option('wpvr_frontend_notice_area', $wpvr_frontend_notice_area); |
| 517 |
update_option('wpvr_script_control', $wpvr_script_control); |
| 518 |
update_option('wpvr_script_list', $wpvr_script_list); |
| 519 |
|
| 520 |
update_option('wpvr_video_script_control', $wpvr_video_script_control); |
| 521 |
update_option('wpvr_video_script_list', $wpvr_video_script_list); |
| 522 |
|
| 523 |
if(is_plugin_active( 'dokan-lite/dokan.php' ) || is_plugin_active( 'dokan-pro/dokan.php' )){ |
| 524 |
$dokan_vendor = isset( $_POST['dokan_vendor'] ) ? sanitize_text_field($_POST['dokan_vendor']) : false; |
| 525 |
update_option('dokan_vendor_active', $dokan_vendor); |
| 526 |
} |
| 527 |
|
| 528 |
// update_option('wpvr_enable_woocommerce', $enable_woocommerce); |
| 529 |
|
| 530 |
$response = array( |
| 531 |
'status' => 'success', |
| 532 |
'message' => 'Successfully saved', |
| 533 |
); |
| 534 |
wp_send_json($response); |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
/** |
| 539 |
* WPVR Notice |
| 540 |
* |
| 541 |
* @return void |
| 542 |
* @since 8.0.0 |
| 543 |
*/ |
| 544 |
function wpvr_notice() |
| 545 |
{ |
| 546 |
//===Current user capabilities check===// |
| 547 |
if (!current_user_can('edit_posts')) { |
| 548 |
$response = array( |
| 549 |
'success' => false, |
| 550 |
'data' => 'Permission denied.' |
| 551 |
); |
| 552 |
wp_send_json($response); |
| 553 |
} |
| 554 |
//===Current user capabilities check===// |
| 555 |
//===Nonce check===// |
| 556 |
$nonce = sanitize_text_field($_POST['nonce']); |
| 557 |
if (!wp_verify_nonce($nonce, 'wpvr')) { |
| 558 |
$response = array( |
| 559 |
'success' => false, |
| 560 |
'data' => 'Permission denied.' |
| 561 |
); |
| 562 |
wp_send_json($response); |
| 563 |
} |
| 564 |
//===Nonce check===// |
| 565 |
update_option('wpvr_black_friday_notice', '1'); |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* Dismiss black friday notice |
| 570 |
*/ |
| 571 |
function dismiss_black_friday_notice(){ |
| 572 |
if( !current_user_can( 'manage_options' ) ){ |
| 573 |
wp_send_json_error( array( 'message' => 'Unauthorized user' ), 403 ); |
| 574 |
return; |
| 575 |
} |
| 576 |
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'wpvr')) { |
| 577 |
wp_die(__('Permission check failed', 'wpvr')); |
| 578 |
} |
| 579 |
update_option('_wpvr_eid_al_adha_2024', 'yes'); |
| 580 |
echo json_encode(['success' => true,]); |
| 581 |
wp_die(); |
| 582 |
} |
| 583 |
|
| 584 |
/** |
| 585 |
* Handles the creation of a contact via a webhook. |
| 586 |
* |
| 587 |
* This function validates the nonce, sanitizes and validates the input fields, |
| 588 |
* and then creates a new contact using the WPVR_Create_Contact class. |
| 589 |
* |
| 590 |
* @since 8.4.10 |
| 591 |
*/ |
| 592 |
function wpvr_create_contact(){ |
| 593 |
if( !current_user_can( 'manage_options' ) ){ |
| 594 |
wp_send_json_error( array( 'message' => 'Unauthorized user' ), 403 ); |
| 595 |
return; |
| 596 |
} |
| 597 |
$nonce = filter_input(INPUT_POST, 'security', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 598 |
$nonce = !empty( $nonce ) ? $nonce : null; |
| 599 |
if ( !wp_verify_nonce( $nonce, 'wpvr' ) ) { |
| 600 |
wp_send_json_error( array( 'message' => 'Invalid nonce' ), 400 ); |
| 601 |
return; |
| 602 |
} |
| 603 |
|
| 604 |
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 605 |
$industry = filter_input(INPUT_POST, 'industry', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 606 |
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); |
| 607 |
|
| 608 |
$name = !empty($name) ? $name: ''; |
| 609 |
$industry = !empty($industry ) ? $industry : ''; |
| 610 |
$email = !empty( $email ) ? $email : ''; |
| 611 |
|
| 612 |
if ( empty( $email ) ) { |
| 613 |
wp_send_json_error( array( 'message' => __('Email is required', 'rex-product-feed') ), 400 ); |
| 614 |
}elseif( !is_email( $email ) ){ |
| 615 |
wp_send_json_error( array( 'message' => __('Email is invalid', 'rex-product-feed') ), 400 ); |
| 616 |
} |
| 617 |
|
| 618 |
$create_contact_instance = new WPVR_Create_Contact( $email, $name, $industry ); |
| 619 |
$response = $create_contact_instance->create_contact_via_webhook(); |
| 620 |
|
| 621 |
if ( $response ) { |
| 622 |
wp_send_json_success( array( 'message' => __('Contact created successfully', 'wpvr') ), 200 ); |
| 623 |
} else { |
| 624 |
wp_send_json_error( array( 'message' => __('Failed to create contact', 'wpvr') ), 500 ); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
/** |
| 629 |
* Saves the general settings for the WPVR plugin. |
| 630 |
* |
| 631 |
* This function handles the nonce verification, sanitizes the input fields, |
| 632 |
* and updates the options in the database. It responds with a JSON success or error message. |
| 633 |
* |
| 634 |
* @since 8.4.10 |
| 635 |
*/ |
| 636 |
function wpvr_save_general_settings(){ |
| 637 |
|
| 638 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 639 |
wp_send_json_error( array( 'message' => 'Unauthorized user' ), 403 ); |
| 640 |
return; |
| 641 |
} |
| 642 |
|
| 643 |
$nonce = filter_input(INPUT_POST, 'security', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 644 |
$nonce = !empty( $nonce ) ? $nonce : null; // phpcs:ignore |
| 645 |
if ( !wp_verify_nonce( $nonce, 'wpvr' ) ) { |
| 646 |
wp_send_json_error( array( 'message' => 'Invalid nonce' ), 400 ); |
| 647 |
return; |
| 648 |
} |
| 649 |
|
| 650 |
$is_mobile_media_resize = filter_input(INPUT_POST, 'media_resizer', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 651 |
$convert_to_webp = filter_input(INPUT_POST, 'convert_to_webp', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 652 |
$vr_glass_support = filter_input(INPUT_POST, 'vr_glass_support', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 653 |
|
| 654 |
update_option('mobile_media_resize', $is_mobile_media_resize); |
| 655 |
update_option('wpvr_webp_conversion', $convert_to_webp); |
| 656 |
update_option('wpvr_cardboard_disable', $vr_glass_support); |
| 657 |
|
| 658 |
wp_send_json_success( array( 'message' => __('General setting data successfully saved.', 'wpvr') ), 200 ); |
| 659 |
} |
| 660 |
|
| 661 |
} |
| 662 |
|