| 1 |
<?php |
| 2 |
/** |
| 3 |
* The file that defines the core plugin class |
| 4 |
* |
| 5 |
* @link https://posimyth.com/ |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Wdesignkit |
| 9 |
* @subpackage Wdesignkit/includes |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
use wdkit\Wdkit_Wdesignkit; |
| 17 |
use wdkit\WdKit_enqueue\Wdkit_Enqueue; |
| 18 |
use wdkit\wdkit_datahooks\Wdkit_Data_Hooks; |
| 19 |
|
| 20 |
if ( ! class_exists( 'Wdkit_Api_Call' ) ) { |
| 21 |
|
| 22 |
/** |
| 23 |
* Main classs call for all api |
| 24 |
* |
| 25 |
* @link https://posimyth.com/ |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
class Wdkit_Api_Call { |
| 29 |
|
| 30 |
/** |
| 31 |
* Member Variable |
| 32 |
* |
| 33 |
* @var instance |
| 34 |
*/ |
| 35 |
private static $instance; |
| 36 |
|
| 37 |
/** |
| 38 |
* Member Variable |
| 39 |
* |
| 40 |
* @var staring $wdkit_api |
| 41 |
*/ |
| 42 |
public $wdkit_api = WDKIT_SERVER_SITE_URL . 'api/wp/'; |
| 43 |
|
| 44 |
/** |
| 45 |
* Member Variable |
| 46 |
* |
| 47 |
* @var staring $widget_folder_u_r_l |
| 48 |
*/ |
| 49 |
public $widget_folder_u_r_l = ''; |
| 50 |
|
| 51 |
/** |
| 52 |
* Member Variable |
| 53 |
* |
| 54 |
* @var staring $e_msg_login |
| 55 |
*/ |
| 56 |
public $e_msg_login = 'Login Error: Check your details and try again.'; |
| 57 |
|
| 58 |
/** |
| 59 |
* Member Variable |
| 60 |
* |
| 61 |
* @var staring $e_desc_login |
| 62 |
*/ |
| 63 |
public $e_desc_login = 'Invalid Login Details'; |
| 64 |
|
| 65 |
/** |
| 66 |
* Member Variable |
| 67 |
* |
| 68 |
* @var staring wdkit_onbording_api |
| 69 |
*/ |
| 70 |
public $wdkit_onbording_api = 'https://api.posimyth.com/wp-json/wdkit/v2/wdkit_store_user_data'; |
| 71 |
|
| 72 |
/** |
| 73 |
* Member Variable |
| 74 |
* |
| 75 |
* @var staring wdkit_onbording_end |
| 76 |
*/ |
| 77 |
public $wdkit_onbording_end = 'wkit_onbording_end'; |
| 78 |
|
| 79 |
/** |
| 80 |
* Initiator |
| 81 |
*/ |
| 82 |
public static function get_instance() { |
| 83 |
if ( ! isset( self::$instance ) ) { |
| 84 |
self::$instance = new self(); |
| 85 |
} |
| 86 |
|
| 87 |
return self::$instance; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Define the core functionality of the plugin. |
| 92 |
*/ |
| 93 |
public function __construct() { |
| 94 |
add_action( 'wp_ajax_get_wdesignkit', array( $this, 'wdkit_api_call' ) ); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Error JSON message |
| 99 |
* |
| 100 |
* @param array $data give array. |
| 101 |
* @param string $status api code number. |
| 102 |
* |
| 103 |
* @since 1.0.0 |
| 104 |
* */ |
| 105 |
public function wdkit_error_msg( $data = null, $status = null ) { |
| 106 |
wp_send_json_error( $data ); |
| 107 |
wp_die(); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Success JSON message |
| 112 |
* |
| 113 |
* @param array $data give array. |
| 114 |
* @param string $status api code number. |
| 115 |
* |
| 116 |
* @since 1.0.0 |
| 117 |
* */ |
| 118 |
public function wdkit_success_msg( $data = null, $status = null ) { |
| 119 |
wp_send_json_success( $data, $status ); |
| 120 |
wp_die(); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Get Wdkit Api Call Ajax. |
| 125 |
*/ |
| 126 |
public function wdkit_api_call() { |
| 127 |
|
| 128 |
check_ajax_referer( 'wdkit_nonce', 'kit_nonce' ); |
| 129 |
|
| 130 |
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) { |
| 131 |
wp_send_json_error( array( 'content' => __( 'Insufficient permissions.', 'wdesignkit' ) ) ); |
| 132 |
} |
| 133 |
|
| 134 |
$type = isset( $_POST['type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['type'] ) ) ) : false; |
| 135 |
if ( ! $type ) { |
| 136 |
$this->wdkit_error_msg( __( 'Something went wrong.', 'wdesignkit' ) ); |
| 137 |
} |
| 138 |
|
| 139 |
switch ( $type ) { |
| 140 |
case 'onboarding_handler': |
| 141 |
$data = $this->wdkit_onboarding_handler(); |
| 142 |
break; |
| 143 |
case 'wkit_login': |
| 144 |
$data = apply_filters( 'wp_wdkit_login_ajax', 'wkit_login' ); |
| 145 |
break; |
| 146 |
case 'api_login': |
| 147 |
$data = apply_filters( 'wp_wdkit_login_ajax', 'api_login' ); |
| 148 |
break; |
| 149 |
case 'social_login': |
| 150 |
$data = apply_filters( 'wp_wdkit_login_ajax', 'social_login' ); |
| 151 |
break; |
| 152 |
case 'wkit_meta_data': |
| 153 |
$data = $this->wdkit_meta_data(); |
| 154 |
break; |
| 155 |
case 'get_user_info': |
| 156 |
$data = $this->wdkit_get_user_info(); |
| 157 |
break; |
| 158 |
case 'browse_page': |
| 159 |
$data = $this->wdkit_browse_page(); |
| 160 |
break; |
| 161 |
case 'kit_template': |
| 162 |
$data = $this->wdkit_template(); |
| 163 |
break; |
| 164 |
case 'wkit_preset_template': |
| 165 |
$data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_template' ); |
| 166 |
break; |
| 167 |
case 'wdkit_preset_dwnld_template': |
| 168 |
$data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_dwnld_template' ); |
| 169 |
break; |
| 170 |
case 'template_remove': |
| 171 |
$data = $this->wdkit_template_remove(); |
| 172 |
break; |
| 173 |
case 'save_template': |
| 174 |
$data = $this->wdkit_put_save_template(); |
| 175 |
break; |
| 176 |
case 'find_template': |
| 177 |
$data = $this->wdkit_find_existing_template(); |
| 178 |
break; |
| 179 |
case 'update_template': |
| 180 |
$data = $this->wdkit_update_template(); |
| 181 |
break; |
| 182 |
case 'manage_favorite': |
| 183 |
$data = $this->wdkit_manage_favorite(); |
| 184 |
break; |
| 185 |
case 'check_plugins_depends': |
| 186 |
$data = $this->wdkit_check_plugins_depends(); |
| 187 |
break; |
| 188 |
case 'install_plugins_depends': |
| 189 |
$data = $this->wdkit_install_plugins_depends(); |
| 190 |
break; |
| 191 |
case 'update_latest_plugin': |
| 192 |
$data = $this->wdkit_update_latest_plugin(); |
| 193 |
break; |
| 194 |
case 'import_template': |
| 195 |
$data = $this->wdkit_import_template(); |
| 196 |
break; |
| 197 |
case 'import_multi_template': |
| 198 |
$data = $this->wdkit_import_multi_template(); |
| 199 |
break; |
| 200 |
case 'import_kit_template': |
| 201 |
$data = $this->wdkit_import_kit_template(); |
| 202 |
break; |
| 203 |
case 'scan_tpae_widgets': |
| 204 |
if (has_filter('tpae_widget_scan')) { |
| 205 |
$type = array('get_wdkit_unused_widgets'); |
| 206 |
$data = apply_filters( 'tpae_widget_scan', $type ); |
| 207 |
|
| 208 |
$res = array( |
| 209 |
'massage' => 'Disabled Successfully', |
| 210 |
'description' => 'Unused widgets have been Disabled successfully', |
| 211 |
'success' => true, |
| 212 |
); |
| 213 |
wp_send_json(); |
| 214 |
wp_die(); |
| 215 |
} |
| 216 |
|
| 217 |
$data = ''; |
| 218 |
break; |
| 219 |
case 'scan_nexter_widgets': |
| 220 |
if (has_filter('tpgb_disable_unsed_block_filter')) { |
| 221 |
$data = apply_filters( 'tpgb_disable_unsed_block_filter', array('tpgb_disable_unsed_block_filter_fun') ); |
| 222 |
|
| 223 |
$res = array( |
| 224 |
'massage' => 'Disabled Successfully', |
| 225 |
'description' => 'Unused widgets have been Disabled successfully', |
| 226 |
'success' => true, |
| 227 |
); |
| 228 |
wp_send_json(); |
| 229 |
wp_die(); |
| 230 |
} |
| 231 |
|
| 232 |
$data = ''; |
| 233 |
break; |
| 234 |
case 'shared_with_me': |
| 235 |
$data = $this->wdkit_shared_with_me(); |
| 236 |
break; |
| 237 |
case 'manage_workspace': |
| 238 |
$data = $this->wdkit_manage_workspace(); |
| 239 |
break; |
| 240 |
case 'widget_browse_page': |
| 241 |
$data = apply_filters( 'wp_wdkit_widget_ajax', 'widget_browse_page' ); |
| 242 |
break; |
| 243 |
case 'wkit_create_widget': |
| 244 |
$data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_create_widget' ); |
| 245 |
break; |
| 246 |
case 'wkit_import_widget': |
| 247 |
$data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_import_widget' ); |
| 248 |
break; |
| 249 |
case 'wkit_export_widget': |
| 250 |
$data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_export_widget' ); |
| 251 |
break; |
| 252 |
case 'wkit_delete_widget': |
| 253 |
$data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_delete_widget' ); |
| 254 |
break; |
| 255 |
case 'wkit_manage_widget_workspace': |
| 256 |
$data = $this->wdkit_manage_widget_workspace(); |
| 257 |
break; |
| 258 |
case 'wkit_activate_key': |
| 259 |
$data = $this->wdkit_activate_key(); |
| 260 |
break; |
| 261 |
case 'wkit_manage_widget_category': |
| 262 |
$data = $this->wdkit_manage_widget_category(); |
| 263 |
break; |
| 264 |
case 'wkit_widget_json': |
| 265 |
$data = $this->wkit_widget_json(); |
| 266 |
break; |
| 267 |
case 'wkit_download_widget': |
| 268 |
$data = $this->wdkit_download_widget(); |
| 269 |
break; |
| 270 |
case 'wkit_public_download_widget': |
| 271 |
$data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_public_download_widget' ); |
| 272 |
break; |
| 273 |
case 'wkit_add_widget': |
| 274 |
$data = $this->wdkit_add_widget(); |
| 275 |
break; |
| 276 |
case 'wkit_favourite_widget': |
| 277 |
$data = $this->wdkit_favourite_widget(); |
| 278 |
break; |
| 279 |
case 'wkit_setting_panel': |
| 280 |
$data = $this->wdkit_setting_panel(); |
| 281 |
break; |
| 282 |
case 'media_import': |
| 283 |
$data = $this->wdkit_media_import(); |
| 284 |
break; |
| 285 |
case 'active_licence': |
| 286 |
$data = $this->wdkit_activate_licence(); |
| 287 |
break; |
| 288 |
case 'delete_licence': |
| 289 |
$data = $this->wdkit_delete_licence_key(); |
| 290 |
break; |
| 291 |
case 'sync_licence': |
| 292 |
$data = $this->wdkit_sync_licence_key(); |
| 293 |
break; |
| 294 |
case 'get_wkit_version': |
| 295 |
$data = $this->wdkit_prev_version(); |
| 296 |
break; |
| 297 |
case 'rollback_wdkit': |
| 298 |
$data = $this->wdkit_rollback_check(); |
| 299 |
break; |
| 300 |
case 'wkit_logout': |
| 301 |
$data = $this->wdkit_logout(); |
| 302 |
break; |
| 303 |
case 'wkit_white_label': |
| 304 |
$this->wkit_white_label(); |
| 305 |
break; |
| 306 |
case 'wkit_reset_wl': |
| 307 |
$response = $this->wkit_reset_wl(); |
| 308 |
break; |
| 309 |
} |
| 310 |
|
| 311 |
$this->wdkit_success_msg( $data ); |
| 312 |
// wp_die(); |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* |
| 317 |
* This Function is used for API call |
| 318 |
* |
| 319 |
* @since 1.0.0 |
| 320 |
* |
| 321 |
* @param array $data give array. |
| 322 |
* @param array $name store data. |
| 323 |
*/ |
| 324 |
protected function wkit_api_call( $data, $name ) { |
| 325 |
$u_r_l = $this->wdkit_api; |
| 326 |
|
| 327 |
if ( empty( $u_r_l ) ) { |
| 328 |
return array( |
| 329 |
'massage' => esc_html__( 'API Not Found', 'wdesignkit' ), |
| 330 |
'success' => false, |
| 331 |
); |
| 332 |
} |
| 333 |
|
| 334 |
$args = array( |
| 335 |
'method' => 'POST', |
| 336 |
'body' => $data, |
| 337 |
'timeout' => 100, |
| 338 |
); |
| 339 |
$response = wp_remote_post( $u_r_l . $name, $args ); |
| 340 |
|
| 341 |
if ( is_wp_error( $response ) ) { |
| 342 |
$error_message = $response->get_error_message(); |
| 343 |
|
| 344 |
/* Translators: %s is a placeholder for the error message */ |
| 345 |
$error_message = printf( esc_html__( 'API request error: %s', 'wdesignkit' ), esc_html( $error_message ) ); |
| 346 |
|
| 347 |
return array( |
| 348 |
'massage' => $error_message, |
| 349 |
'success' => false, |
| 350 |
); |
| 351 |
} |
| 352 |
|
| 353 |
$status_code = wp_remote_retrieve_response_code( $response ); |
| 354 |
if ( 200 === $status_code ) { |
| 355 |
|
| 356 |
return array( |
| 357 |
'data' => json_decode( wp_remote_retrieve_body( $response ) ), |
| 358 |
'massage' => esc_html__( 'Success', 'wdesignkit' ), |
| 359 |
'status' => $status_code, |
| 360 |
'success' => true, |
| 361 |
); |
| 362 |
} |
| 363 |
|
| 364 |
$error_message = printf( 'Server error: %d', esc_html( $status_code ) ); |
| 365 |
|
| 366 |
if ( isset( $error_data->message ) ) { |
| 367 |
$error_message .= ' (' . $error_data->message . ')'; |
| 368 |
} |
| 369 |
|
| 370 |
return array( |
| 371 |
'massage' => $error_message, |
| 372 |
'status' => $status_code, |
| 373 |
'success' => false, |
| 374 |
); |
| 375 |
} |
| 376 |
|
| 377 |
/** |
| 378 |
* |
| 379 |
* It is Use for handle onboarding data. |
| 380 |
* |
| 381 |
* @since 1.0.9 |
| 382 |
*/ |
| 383 |
public function wdkit_onboarding_handler() { |
| 384 |
$page_template = isset( $_POST['page_template'] ) ? json_decode( wp_unslash( $_POST['page_template'] ), true ) : ''; |
| 385 |
$page_builder = isset( $_POST['page_builder'] ) ? json_decode( wp_unslash( $_POST['page_builder'] ), true ) : ''; |
| 386 |
|
| 387 |
$elementor_plugin = isset( $_POST['elementor_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['elementor_plugin'] ) ) : 0; |
| 388 |
$tpag_plugin = isset( $_POST['tpag_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['tpag_plugin'] ) ) : 0; |
| 389 |
$bricks_theme = isset( $_POST['bricks_theme'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['bricks_theme'] ) ) : 0; |
| 390 |
|
| 391 |
$server_software = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : ''; |
| 392 |
|
| 393 |
$web_server = $server_software; |
| 394 |
$memory_limit = ini_get( 'memory_limit' ); |
| 395 |
$max_execution_time = ini_get( 'max_execution_time' ); |
| 396 |
$php_version = phpversion(); |
| 397 |
$wp_version = get_bloginfo( 'version' ); |
| 398 |
$email = get_option( 'admin_email' ); |
| 399 |
$siteurl = get_option( 'siteurl' ); |
| 400 |
$language = get_bloginfo( 'language' ); |
| 401 |
|
| 402 |
// Active Plugin Name. |
| 403 |
$act_plugin = array(); |
| 404 |
$actplu = get_option( 'active_plugins' ); |
| 405 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 406 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 407 |
} |
| 408 |
|
| 409 |
$plugins = get_plugins(); |
| 410 |
foreach ( $actplu as $p ) { |
| 411 |
if ( isset( $plugins[ $p ] ) ) { |
| 412 |
$act_plugin[] = $plugins[ $p ]['Name']; |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
$plugin = wp_json_encode( $act_plugin ); |
| 417 |
|
| 418 |
$theme = ''; |
| 419 |
$acthemeobj = wp_get_theme(); |
| 420 |
if ( $acthemeobj->get( 'Name' ) !== null && ! empty( $acthemeobj->get( 'Name' ) ) ) { |
| 421 |
$theme = $acthemeobj->get( 'Name' ); |
| 422 |
} |
| 423 |
|
| 424 |
$basic_requirements = array( |
| 425 |
'elementor_install' => $elementor_plugin, |
| 426 |
'tpag_install' => $tpag_plugin, |
| 427 |
'bricks_install' => $bricks_theme, |
| 428 |
); |
| 429 |
|
| 430 |
$final = array( |
| 431 |
'web_server' => $web_server, |
| 432 |
'memory_limit' => $memory_limit, |
| 433 |
'max_execution_time' => $max_execution_time, |
| 434 |
'php_version' => $php_version, |
| 435 |
'wp_version' => $wp_version, |
| 436 |
'email' => $email, |
| 437 |
'site_url' => $siteurl, |
| 438 |
'site_language' => $language, |
| 439 |
'theme' => $theme, |
| 440 |
'plugins' => $act_plugin, |
| 441 |
'basic_requirements' => $basic_requirements, |
| 442 |
'page_template' => $page_template, |
| 443 |
'page_builder' => $page_builder, |
| 444 |
); |
| 445 |
|
| 446 |
$response = wp_remote_post( |
| 447 |
$this->wdkit_onbording_api, |
| 448 |
array( |
| 449 |
'method' => 'POST', |
| 450 |
'body' => wp_json_encode( $final ), |
| 451 |
) |
| 452 |
); |
| 453 |
|
| 454 |
$existing_value = get_option( $this->wdkit_onbording_end ); |
| 455 |
if ( false === $existing_value ) { |
| 456 |
add_option( $this->wdkit_onbording_end, true ); |
| 457 |
} |
| 458 |
|
| 459 |
if ( is_wp_error( $response ) ) { |
| 460 |
$result = array( |
| 461 |
'success' => false, |
| 462 |
'messages' => 'Oops', |
| 463 |
'description' => 'Description', |
| 464 |
); |
| 465 |
|
| 466 |
wp_send_json( $result ); |
| 467 |
} else { |
| 468 |
$status_one = wp_remote_retrieve_response_code( $response ); |
| 469 |
|
| 470 |
if ( 200 === $status_one ) { |
| 471 |
$get_data_one = wp_remote_retrieve_body( $response ); |
| 472 |
|
| 473 |
$get_res = json_decode( json_decode( $get_data_one, true ), true ); |
| 474 |
|
| 475 |
$result = array( |
| 476 |
'success' => ! empty( $get_res['success'] ) ? $get_res['success'] : false, |
| 477 |
'messages' => ! empty( $get_res['messages'] ) ? $get_res['messages'] : 'success', |
| 478 |
'description' => ! empty( $get_res['description'] ) ? $get_res['description'] : 'Description', |
| 479 |
); |
| 480 |
|
| 481 |
wp_send_json( $result ); |
| 482 |
} else { |
| 483 |
|
| 484 |
$result = array( |
| 485 |
'success' => false, |
| 486 |
'messages' => 'Oops', |
| 487 |
'description' => 'description', |
| 488 |
); |
| 489 |
|
| 490 |
wp_send_json( $result ); |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
wp_die(); |
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* |
| 499 |
* It is Use for get meta data for non login user |
| 500 |
* |
| 501 |
* @since 1.0.0\ |
| 502 |
*/ |
| 503 |
protected function wdkit_meta_data() { |
| 504 |
$type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : ''; |
| 505 |
$data = array( 'type' => $type ); |
| 506 |
|
| 507 |
$response = $this->wkit_api_call( $data, 'meta' ); |
| 508 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 509 |
$status = ! empty( $response['status'] ) ? (int) $response['status'] : 400; |
| 510 |
|
| 511 |
if ( empty( $success ) ) { |
| 512 |
$result = array( |
| 513 |
'plugin' => array(), |
| 514 |
'builder' => array(), |
| 515 |
'category' => array(), |
| 516 |
'widgetscategory' => array(), |
| 517 |
'tags' => array(), |
| 518 |
'widgetbuilder' => array(), |
| 519 |
|
| 520 |
'message' => esc_html__( 'Server Error', 'wdesignkit' ), |
| 521 |
'description' => esc_html__( 'Server Error, Data Not Found', 'wdesignkit' ), |
| 522 |
'success' => false, |
| 523 |
); |
| 524 |
|
| 525 |
wp_send_json( $result ); |
| 526 |
wp_die(); |
| 527 |
} |
| 528 |
|
| 529 |
$get_data_one = ! empty( $response['data'] ) ? $response['data'] : array(); |
| 530 |
$statuscode = array( 'HTTP_CODE' => $status ); |
| 531 |
|
| 532 |
$final = json_decode( wp_json_encode( $get_data_one ), true ); |
| 533 |
|
| 534 |
$final['Setting'] = self::wkit_get_settings_panel(); |
| 535 |
$final['widget_list'] = $this->wkit_manage_widget_sequence( array() ); |
| 536 |
|
| 537 |
$final = array( |
| 538 |
'data' => $final, |
| 539 |
); |
| 540 |
|
| 541 |
wp_send_json( $final ); |
| 542 |
wp_die(); |
| 543 |
} |
| 544 |
|
| 545 |
/** |
| 546 |
* |
| 547 |
* It is Use for get activate license key data from tpae and nexter blocks. |
| 548 |
* |
| 549 |
* @since 1.1.6 |
| 550 |
*/ |
| 551 |
protected function wkit_manage_license_data() { |
| 552 |
$manage_licence = array(); |
| 553 |
$theplus_active_check = is_plugin_active('the-plus-addons-for-elementor-page-builder/theplus_elementor_addon.php'); |
| 554 |
$nexter_active_check = is_plugin_active('the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php'); |
| 555 |
|
| 556 |
$theplus_licence = get_option('tpaep_licence_data', []); |
| 557 |
|
| 558 |
if ( ! empty( $theplus_active_check ) &&! empty( $theplus_licence ) ) { |
| 559 |
$manage_licence['tpae'] = $theplus_licence; |
| 560 |
} |
| 561 |
|
| 562 |
$nexter_licence = get_option('tpgb_activate', []); |
| 563 |
|
| 564 |
if ( ! empty( $nexter_active_check ) && ! empty( $nexter_licence ) && !empty( $nexter_licence['tpgb_activate_key'] ) ) { |
| 565 |
$tpgb_license_status = get_option('tpgbp_license_status', []); |
| 566 |
$tpgb_license_status['license_key'] = $nexter_licence['tpgb_activate_key']; |
| 567 |
$manage_licence['tpag'] = $tpgb_license_status; |
| 568 |
} |
| 569 |
|
| 570 |
return $manage_licence; |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* |
| 575 |
* It is Use for get all info of user. |
| 576 |
* |
| 577 |
* @since 1.0.0 |
| 578 |
*/ |
| 579 |
protected function wdkit_get_user_info() { |
| 580 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 581 |
$builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : ''; |
| 582 |
|
| 583 |
$site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : ''; |
| 584 |
|
| 585 |
$response = array(); |
| 586 |
|
| 587 |
if ( empty( $email ) ) { |
| 588 |
$response = array( |
| 589 |
'success' => false, |
| 590 |
'message' => $this->e_msg_login, |
| 591 |
'description' => $this->e_desc_login, |
| 592 |
); |
| 593 |
|
| 594 |
wp_send_json( $response ); |
| 595 |
wp_die(); |
| 596 |
} |
| 597 |
|
| 598 |
$token = $this->wdkit_login_user_token( $email ); |
| 599 |
$args = array( |
| 600 |
'token' => $token, |
| 601 |
'builder' => $builder, |
| 602 |
'site_url' => $site_url, |
| 603 |
); |
| 604 |
|
| 605 |
$response = WDesignKit_Data_Query::get_data( 'get_user_info', $args ); |
| 606 |
$status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error'; |
| 607 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 608 |
|
| 609 |
/**Condtion user for user logout & expire token*/ |
| 610 |
if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) { |
| 611 |
delete_transient( 'wdkit_auth_' . $email ); |
| 612 |
} |
| 613 |
|
| 614 |
$response['Setting'] = $this->wkit_get_settings_panel(); |
| 615 |
$response['widget_list'] = $this->wkit_manage_widget_sequence( $response ); |
| 616 |
$response['manage_licence'] = $this->wkit_manage_license_data(); |
| 617 |
|
| 618 |
$response = array( |
| 619 |
'data' => $response, |
| 620 |
'success' => true, |
| 621 |
); |
| 622 |
|
| 623 |
wp_send_json( $response ); |
| 624 |
wp_die(); |
| 625 |
} |
| 626 |
|
| 627 |
/** |
| 628 |
* |
| 629 |
* It is Use for get all widgets local and server. |
| 630 |
* |
| 631 |
* @since 1.0.19 |
| 632 |
* @param string $response userinfo store. |
| 633 |
*/ |
| 634 |
protected function wkit_manage_widget_sequence( $response = array() ) { |
| 635 |
|
| 636 |
$credits = ! empty( $response['credits']['widget_limit']['meta_value'] ) ? $response['credits']['widget_limit']['meta_value'] : 10; |
| 637 |
$server_list = ! empty( $response['widgettemplate'] ) ? $response['widgettemplate'] : array(); |
| 638 |
$db_builder_list = ! empty( $response['widgetbuilder'] ) ? $response['widgetbuilder'] : array(); |
| 639 |
|
| 640 |
$placeholderimg = WDKIT_URL . 'assets/images/placeholder.jpg'; |
| 641 |
|
| 642 |
$local_list = $this->wdkit_get_local_widgets(); |
| 643 |
|
| 644 |
$server_w_unique = array_column( $server_list, 'w_unique' ); |
| 645 |
|
| 646 |
$idx_builder = array(); |
| 647 |
foreach ( $db_builder_list as $index => $value ) { |
| 648 |
$builder_name = ! empty( $value['builder_name'] ) ? $value['builder_name'] : ''; |
| 649 |
$w_id = ! empty( $value['w_id'] ) ? $value['w_id'] : ''; |
| 650 |
|
| 651 |
if ( ! empty( $builder_name ) ) { |
| 652 |
$idx_builder[ $w_id ] = strtolower( $builder_name ); |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
foreach ( $server_list as $index => $value ) { |
| 657 |
$get_id = $server_list[ $index ]['builder'] ? $server_list[ $index ]['builder'] : ''; |
| 658 |
|
| 659 |
$server_list[ $index ]['type'] = 'server'; |
| 660 |
$server_list[ $index ]['builder'] = ! empty( $idx_builder[ $get_id ] ) ? $idx_builder[ $get_id ] : ''; |
| 661 |
} |
| 662 |
|
| 663 |
$count = 0; |
| 664 |
|
| 665 |
foreach ( $local_list as $key => $value ) { |
| 666 |
$widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : ''; |
| 667 |
$allow_push = isset( $value['widgetdata']['allow_push'] ) ? $value['widgetdata']['allow_push'] : true; |
| 668 |
|
| 669 |
if ( in_array( $widget_id, $server_w_unique ) ) { |
| 670 |
|
| 671 |
$index = array_search( $widget_id, $server_w_unique ); |
| 672 |
|
| 673 |
$server_list[ $index ]['title'] = $local_list[ $key ]['widgetdata']['name']; |
| 674 |
$server_list[ $index ]['w_version'] = $local_list[ $key ]['widgetdata']['widget_version']; |
| 675 |
$server_list[ $index ]['allow_push'] = $allow_push; |
| 676 |
$server_list[ $index ]['builder'] = $local_list[ $key ]['widgetdata']['type']; |
| 677 |
$server_list[ $index ]['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id']; |
| 678 |
$server_list[ $index ]['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg; |
| 679 |
|
| 680 |
$local_list[ $key ] = $server_list[ $index ]; |
| 681 |
|
| 682 |
$local_list[ $key ]['type'] = 'done'; |
| 683 |
|
| 684 |
unset( $server_list[ $index ] ); |
| 685 |
} else { |
| 686 |
$local_list[ $key ]['widgetdata']['builder'] = $local_list[ $key ]['widgetdata']['type']; |
| 687 |
$local_list[ $key ]['widgetdata']['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id']; |
| 688 |
$local_list[ $key ]['widgetdata']['allow_push'] = $allow_push; |
| 689 |
$local_list[ $key ]['widgetdata']['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg; |
| 690 |
$local_list[ $key ]['widgetdata']['is_activated'] = 'active'; |
| 691 |
|
| 692 |
$local_list[ $key ]['widgetdata']['type'] = 'plugin'; |
| 693 |
|
| 694 |
$local_list[ $key ]['widgetdata']['title'] = $local_list[ $key ]['widgetdata']['name']; |
| 695 |
unset( $local_list[ $key ]['widgetdata']['name'] ); |
| 696 |
unset( $local_list[ $key ]['widgetdata']['widget_id'] ); |
| 697 |
|
| 698 |
$local_list[ $key ] = $local_list[ $key ]['widgetdata']; |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
$final = array_merge( $local_list, $server_list ); |
| 703 |
|
| 704 |
$db_widget = array(); |
| 705 |
|
| 706 |
foreach ( $final as $key => $self ) { |
| 707 |
$is_activated = ! empty( $final[ $key ]['is_activated'] ) ? $final[ $key ]['is_activated'] : 'active'; |
| 708 |
|
| 709 |
if ( 'active' === $is_activated ) { |
| 710 |
++$count; |
| 711 |
} |
| 712 |
|
| 713 |
if ( ( $count > $credits ) && ( 'unlimited' !== $credits ) ) { |
| 714 |
$final[ $key ]['is_activated'] = 'deactive'; |
| 715 |
} |
| 716 |
|
| 717 |
if ( ! empty( $self['is_activated'] ) && 'active' !== $self['is_activated'] ) { |
| 718 |
$db_widget[] = array( |
| 719 |
'w_unique' => $self['w_unique'], |
| 720 |
'builder' => $self['builder'], |
| 721 |
'title' => $self['title'], |
| 722 |
'is_activated' => $self['is_activated'], |
| 723 |
); |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
$get_db_widget = get_option( 'wkit_deactivate_widgets', array() ); |
| 728 |
if ( empty( $get_db_widget ) ) { |
| 729 |
add_option( 'wkit_deactivate_widgets', $db_widget, '', 'yes' ); |
| 730 |
} else { |
| 731 |
update_option( 'wkit_deactivate_widgets', $db_widget ); |
| 732 |
} |
| 733 |
|
| 734 |
return $final; |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Browse Page Filter |
| 739 |
* |
| 740 |
* @since 1.0.0 |
| 741 |
*/ |
| 742 |
protected function wdkit_browse_page() { |
| 743 |
$args = $this->wdkit_parse_args( $_POST ); |
| 744 |
|
| 745 |
$response = WDesignKit_Data_Query::get_data( 'browse_page', $args ); |
| 746 |
|
| 747 |
wp_send_json( $response ); |
| 748 |
wp_die(); |
| 749 |
} |
| 750 |
|
| 751 |
/** |
| 752 |
* |
| 753 |
* It is Use for get template from kit. |
| 754 |
* |
| 755 |
* @since 1.0.0 |
| 756 |
*/ |
| 757 |
protected function wdkit_template() { |
| 758 |
$args = $this->wdkit_parse_args( $_POST ); |
| 759 |
|
| 760 |
$response = WDesignKit_Data_Query::get_data( 'kit_template', $args ); |
| 761 |
|
| 762 |
wp_send_json( $response ); |
| 763 |
wp_die(); |
| 764 |
} |
| 765 |
|
| 766 |
/** |
| 767 |
* |
| 768 |
* It is Use for remove or delete template. |
| 769 |
* |
| 770 |
* @since 1.0.0 |
| 771 |
*/ |
| 772 |
protected function wdkit_template_remove() { |
| 773 |
$args = $this->wdkit_parse_args( $_POST ); |
| 774 |
|
| 775 |
$user_email = strtolower( sanitize_email( $args['email'] ) ); |
| 776 |
$response = ''; |
| 777 |
|
| 778 |
if ( empty( $user_email ) || empty( $args['template_id'] ) ) { |
| 779 |
$response = response()->json( |
| 780 |
array( |
| 781 |
'message' => $this->e_msg_login, |
| 782 |
'description' => $this->e_desc_login, |
| 783 |
'success' => true, |
| 784 |
) |
| 785 |
); |
| 786 |
|
| 787 |
wp_send_json( $response ); |
| 788 |
wp_die(); |
| 789 |
} |
| 790 |
|
| 791 |
$args['token'] = $this->wdkit_login_user_token( $user_email ); |
| 792 |
|
| 793 |
unset( $user_email ); |
| 794 |
$response = WDesignKit_Data_Query::get_data( 'template_remove', $args ); |
| 795 |
|
| 796 |
wp_send_json( $response ); |
| 797 |
wp_die(); |
| 798 |
} |
| 799 |
|
| 800 |
/** |
| 801 |
* |
| 802 |
* It is Use for save template from page builder. |
| 803 |
* |
| 804 |
* @since 1.0.0 |
| 805 |
*/ |
| 806 |
protected function wdkit_put_save_template() { |
| 807 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 808 |
$post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : ''; |
| 809 |
|
| 810 |
$response = ''; |
| 811 |
|
| 812 |
if ( empty( $email ) ) { |
| 813 |
$response = array( |
| 814 |
'id' => 0, |
| 815 |
'editpage' => '', |
| 816 |
'message' => $this->e_msg_login, |
| 817 |
'description' => $this->e_desc_login, |
| 818 |
'success' => false, |
| 819 |
); |
| 820 |
|
| 821 |
wp_send_json( $response ); |
| 822 |
wp_die(); |
| 823 |
} |
| 824 |
|
| 825 |
$args = $this->wdkit_parse_args( $_POST ); |
| 826 |
$args['token'] = $this->wdkit_login_user_token( $email ); |
| 827 |
unset( $args['email'] ); |
| 828 |
|
| 829 |
global $post; |
| 830 |
|
| 831 |
$custom_fields = array(); |
| 832 |
if ( ! empty( $post_id ) ) { |
| 833 |
$meta_fields = get_post_custom( $post_id ); |
| 834 |
|
| 835 |
foreach ( $meta_fields as $key => $value ) { |
| 836 |
if ( str_contains( $key, 'nxt-' ) ) { |
| 837 |
$custom_fields[ $key ] = $value; |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
if ( ! empty( $custom_fields ) ) { |
| 842 |
$data = json_decode( $args['data'], true ); |
| 843 |
$data['custom_meta'] = $custom_fields; |
| 844 |
$args['data'] = wp_json_encode( $data ); |
| 845 |
} |
| 846 |
} |
| 847 |
|
| 848 |
$response = WDesignKit_Data_Query::get_data( 'save_template', $args ); |
| 849 |
|
| 850 |
wp_send_json( $response ); |
| 851 |
wp_die(); |
| 852 |
} |
| 853 |
|
| 854 |
/** |
| 855 |
* |
| 856 |
* It is For Find User Existing template List. |
| 857 |
* |
| 858 |
* @since 1.0.6 |
| 859 |
*/ |
| 860 |
protected function wdkit_find_existing_template() { |
| 861 |
$array_data = array( |
| 862 |
'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '', |
| 863 |
'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', |
| 864 |
'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '', |
| 865 |
'u_id' => isset( $_POST['u_id'] ) ? sanitize_text_field( wp_unslash( $_POST['u_id'] ) ) : '', |
| 866 |
'builder' => isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '', |
| 867 |
'parpage' => isset( $_POST['parpage'] ) ? sanitize_text_field( wp_unslash( $_POST['parpage'] ) ) : 12, |
| 868 |
); |
| 869 |
|
| 870 |
$response = $this->wkit_api_call( $array_data, 'existing_template' ); |
| 871 |
|
| 872 |
wp_send_json( $response ); |
| 873 |
wp_die(); |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* |
| 878 |
* It is For Update User Existing template List. |
| 879 |
* |
| 880 |
* @since 1.0.6 |
| 881 |
*/ |
| 882 |
protected function wdkit_update_template() { |
| 883 |
$array_data = array( |
| 884 |
'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '', |
| 885 |
'post_id' => isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '', |
| 886 |
'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', |
| 887 |
'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '', |
| 888 |
'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '', |
| 889 |
); |
| 890 |
|
| 891 |
if ( ! empty( $array_data['post_id'] ) ) { |
| 892 |
$custom_fields = array(); |
| 893 |
$post_id = $array_data['post_id']; |
| 894 |
|
| 895 |
$meta_fields = get_post_custom( $post_id ); |
| 896 |
|
| 897 |
foreach ( $meta_fields as $key => $value ) { |
| 898 |
if ( str_contains( $key, 'nxt-' ) ) { |
| 899 |
$custom_fields[ $key ] = $value; |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
if ( ! empty( $custom_fields ) ) { |
| 904 |
$data = json_decode( $array_data['data'], true ); |
| 905 |
$data['custom_meta'] = $custom_fields; |
| 906 |
$array_data['data'] = wp_json_encode( $data ); |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
$response = $this->wkit_api_call( $array_data, 'existing_template' ); |
| 911 |
|
| 912 |
wp_send_json( $response ); |
| 913 |
wp_die(); |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* |
| 918 |
* It is Use for manage favourite template. |
| 919 |
* |
| 920 |
* @since 1.0.0 |
| 921 |
*/ |
| 922 |
protected function wdkit_manage_favorite() { |
| 923 |
$template_id = isset( $_POST['template_id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['template_id'] ) ) ) : 0; |
| 924 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 925 |
|
| 926 |
if ( empty( $email ) || empty( $template_id ) ) { |
| 927 |
$response = array( |
| 928 |
'message' => $this->e_msg_login, |
| 929 |
'description' => $this->e_desc_login, |
| 930 |
'success' => false, |
| 931 |
); |
| 932 |
|
| 933 |
wp_send_json( $response ); |
| 934 |
wp_die(); |
| 935 |
} |
| 936 |
|
| 937 |
$args = $this->wdkit_parse_args( $_POST ); |
| 938 |
$args['token'] = $this->wdkit_login_user_token( $email ); |
| 939 |
|
| 940 |
unset( $args['email'] ); |
| 941 |
$response = WDesignKit_Data_Query::get_data( 'manage_favorite', $args ); |
| 942 |
|
| 943 |
wp_send_json( $response ); |
| 944 |
wp_die(); |
| 945 |
} |
| 946 |
|
| 947 |
/** |
| 948 |
* |
| 949 |
* It is Use for Check Plugin Dependency of template. |
| 950 |
* |
| 951 |
* @since 1.0.0 |
| 952 |
* @version 1.0.9 |
| 953 |
*/ |
| 954 |
protected function wdkit_check_plugins_depends() { |
| 955 |
$plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array(); |
| 956 |
$update_plugin = array(); |
| 957 |
|
| 958 |
if ( empty( $plugins ) || ! is_array( $plugins ) ) { |
| 959 |
$this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) ); |
| 960 |
} |
| 961 |
|
| 962 |
$all_plugins = $this->get_plugins(); |
| 963 |
foreach ( $plugins as $plugin ) { |
| 964 |
$pluginslug = ! empty( $plugin->plugin_slug ) ? sanitize_text_field( wp_unslash( $plugin->plugin_slug ) ) : ''; |
| 965 |
$free_pro = ! empty( $plugin->freepro ) ? sanitize_text_field( wp_unslash( $plugin->freepro ) ) : '0'; |
| 966 |
$type = ! empty( $plugin->type ) ? sanitize_text_field( wp_unslash( $plugin->type ) ) : 'plugin'; |
| 967 |
|
| 968 |
if ( is_null( $pluginslug ) ) { |
| 969 |
$plugin->status = 'warning'; |
| 970 |
$update_plugin[] = $plugin; |
| 971 |
|
| 972 |
continue; |
| 973 |
} |
| 974 |
|
| 975 |
if ( 'plugin' === $type ) { |
| 976 |
if ( ! is_plugin_active( $pluginslug ) ) { |
| 977 |
if ( ! isset( $all_plugins[ $pluginslug ] ) ) { |
| 978 |
if ( isset( $free_pro ) && '1' === $free_pro ) { |
| 979 |
$plugin->status = 'manually'; |
| 980 |
} else { |
| 981 |
$plugin->status = 'unavailable'; |
| 982 |
} |
| 983 |
} else { |
| 984 |
$plugin->status = 'inactive'; |
| 985 |
} |
| 986 |
|
| 987 |
$update_plugin[] = $plugin; |
| 988 |
} elseif ( is_plugin_active( $pluginslug ) ) { |
| 989 |
$plugin->status = 'active'; |
| 990 |
$update_plugin[] = $plugin; |
| 991 |
} |
| 992 |
} elseif ( 'theme' === $type ) { |
| 993 |
$theme_array = array_keys( wp_get_themes() ); |
| 994 |
$theme_slug = get_stylesheet(); |
| 995 |
|
| 996 |
if ( $theme_slug === $plugin->name ) { |
| 997 |
|
| 998 |
$plugin->status = 'active'; |
| 999 |
} else { |
| 1000 |
$theme_name = $plugin->name; |
| 1001 |
if ( ! in_array( $theme_name, $theme_array ) ) { |
| 1002 |
if ( isset( $free_pro ) && '1' === $free_pro ) { |
| 1003 |
$plugin->status = 'manually'; |
| 1004 |
} else { |
| 1005 |
$plugin->status = 'unavailable'; |
| 1006 |
} |
| 1007 |
} else { |
| 1008 |
$plugin->status = 'inactive'; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
$update_plugin[] = $plugin; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
$this->wdkit_success_msg( array( 'plugins' => $update_plugin ) ); |
| 1017 |
} |
| 1018 |
|
| 1019 |
/** |
| 1020 |
* |
| 1021 |
* It is Use for Install dependent plugin. |
| 1022 |
* |
| 1023 |
* @since 1.0.0 |
| 1024 |
* @version 1.0.9 |
| 1025 |
*/ |
| 1026 |
protected function wdkit_install_plugins_depends() { |
| 1027 |
$plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array(); |
| 1028 |
$type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin'; |
| 1029 |
|
| 1030 |
$responce = ''; |
| 1031 |
if ( 'plugin' === $type ) { |
| 1032 |
$responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins ); |
| 1033 |
} elseif ( 'theme' === $type ) { |
| 1034 |
$theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : ''; |
| 1035 |
if ( ! empty( $theme_name ) ) { |
| 1036 |
|
| 1037 |
$activate_result = switch_theme( $theme_name ); |
| 1038 |
|
| 1039 |
if ( ! is_wp_error( $activate_result ) ) { |
| 1040 |
$responce = array( |
| 1041 |
'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ), |
| 1042 |
'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ), |
| 1043 |
'slug' => 'the-plus-addons-for-block-editor', |
| 1044 |
'status' => 'active', |
| 1045 |
'success' => true, |
| 1046 |
); |
| 1047 |
} else { |
| 1048 |
$responce = array( |
| 1049 |
'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ), |
| 1050 |
'description' => $activate_result->get_error_message(), |
| 1051 |
'status' => 'inactive', |
| 1052 |
'success' => false, |
| 1053 |
); |
| 1054 |
} |
| 1055 |
} else { |
| 1056 |
$responce = array( |
| 1057 |
'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ), |
| 1058 |
'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ), |
| 1059 |
'success' => true, |
| 1060 |
); |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
wp_send_json( $responce ); |
| 1065 |
wp_die(); |
| 1066 |
} |
| 1067 |
|
| 1068 |
/** |
| 1069 |
* |
| 1070 |
* It is Use Update WDesignKit plugin latest version. |
| 1071 |
* |
| 1072 |
* @since 1.0.17 |
| 1073 |
*/ |
| 1074 |
protected function wdkit_update_latest_plugin() { |
| 1075 |
|
| 1076 |
return Wdkit_Depends_Installer::get_instance()->wdkit_update_plugin(); |
| 1077 |
} |
| 1078 |
|
| 1079 |
/** |
| 1080 |
* |
| 1081 |
* It is Use for get plugin list. |
| 1082 |
* |
| 1083 |
* @since 1.0.0 |
| 1084 |
*/ |
| 1085 |
private function get_plugins() { |
| 1086 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 1087 |
require_once \ABSPATH . 'wp-admin/includes/plugin.php'; |
| 1088 |
} |
| 1089 |
|
| 1090 |
return get_plugins(); |
| 1091 |
} |
| 1092 |
|
| 1093 |
/** |
| 1094 |
* Get Download Template Content |
| 1095 |
* |
| 1096 |
* @since 1.0.0 |
| 1097 |
*/ |
| 1098 |
protected function wdkit_import_template() { |
| 1099 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1100 |
$api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template'; |
| 1101 |
|
| 1102 |
if( ! empty( $args['builder'] ) && 'elementor' === $args['builder'] ){ |
| 1103 |
$widgets = ['widgets', 'extensions']; |
| 1104 |
$widgets = apply_filters( 'tpae_enable_widgets', $widgets ); |
| 1105 |
} else if( ! empty( $args['builder'] ) && 'gutenberg' === $args['builder'] ){ |
| 1106 |
apply_filters( 'tpgb_blocks_enable_all', 'tpgb_blocks_enable_all_filter' ); |
| 1107 |
} |
| 1108 |
|
| 1109 |
$response = ''; |
| 1110 |
if ( empty( $args['template_id'] ) ) { |
| 1111 |
$result = array( |
| 1112 |
'content' => '', |
| 1113 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1114 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1115 |
'success' => false, |
| 1116 |
); |
| 1117 |
|
| 1118 |
wp_send_json( $response ); |
| 1119 |
wp_die(); |
| 1120 |
} |
| 1121 |
|
| 1122 |
$args['token'] = $this->wdkit_login_user_token( $args['email'] ); |
| 1123 |
|
| 1124 |
unset( $args['email'] ); |
| 1125 |
$response = WDesignKit_Data_Query::get_data( $api_type, $args ); |
| 1126 |
$custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; |
| 1127 |
|
| 1128 |
/** Custom meta Field */ |
| 1129 |
if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) { |
| 1130 |
|
| 1131 |
$res_content = json_decode( $response['content'], true ); |
| 1132 |
if ( isset( $res_content['custom_meta'] ) && ! empty( $res_content['custom_meta'] ) ) { |
| 1133 |
$meta_data = $res_content['custom_meta']; |
| 1134 |
|
| 1135 |
if ( ! empty( $meta_data ) ) { |
| 1136 |
foreach ( $meta_data as $meta_key => $meta_val ) { |
| 1137 |
if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { |
| 1138 |
$meta_val[0] = maybe_unserialize( $meta_val[0] ); |
| 1139 |
} |
| 1140 |
|
| 1141 |
if ( get_post_meta( get_the_ID(), $meta_key, true ) === '' ) { |
| 1142 |
add_post_meta( get_the_ID(), $meta_key, $meta_val[0] ); |
| 1143 |
} else { |
| 1144 |
update_post_meta( get_the_ID(), $meta_key, $meta_val[0] ); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
wp_send_json( $response ); |
| 1152 |
wp_die(); |
| 1153 |
} |
| 1154 |
|
| 1155 |
/** |
| 1156 |
* This Function is Use For Media Import |
| 1157 |
* |
| 1158 |
* @since 1.0.0 |
| 1159 |
* |
| 1160 |
* @param array $content store media content. |
| 1161 |
* @param string $editor it is check editor. |
| 1162 |
*/ |
| 1163 |
public function wdkit_media_import( $content = array(), $editor = '' ) { |
| 1164 |
|
| 1165 |
if ( empty( $content ) && empty( $editor ) ) { |
| 1166 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1167 |
$content = ! empty( $args['content'] ) ? json_decode( $args['content'], true ) : array(); |
| 1168 |
} else { |
| 1169 |
$args = array( |
| 1170 |
'content' => $content, |
| 1171 |
'editor' => $editor, |
| 1172 |
); |
| 1173 |
$content = ! empty( $args['content'] ) ? $args['content'] : array(); |
| 1174 |
|
| 1175 |
if ( 'elementor' === $args['editor'] ) { |
| 1176 |
$content = json_decode( $content, true ); |
| 1177 |
} |
| 1178 |
} |
| 1179 |
|
| 1180 |
if ( ! class_exists( 'Wdkit_Import_Images' ) ) { |
| 1181 |
require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php'; |
| 1182 |
} |
| 1183 |
|
| 1184 |
if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) { |
| 1185 |
$media_import = array( $content ); |
| 1186 |
$media_import = self::blocks_import_media_copy_content( $media_import ); |
| 1187 |
$content = $media_import[0]; |
| 1188 |
} elseif ( ! empty( $args['editor'] ) && 'elementor' === $args['editor'] && ! empty( $content ) ) { |
| 1189 |
$media_import = array( $content ); |
| 1190 |
$media_import = self::widgets_elements_id_change( $media_import ); |
| 1191 |
$media_import = self::widgets_import_media_copy_content( $media_import ); |
| 1192 |
$content = $media_import[0]; |
| 1193 |
} |
| 1194 |
|
| 1195 |
return $content; |
| 1196 |
} |
| 1197 |
|
| 1198 |
/** |
| 1199 |
* Widgets elements data |
| 1200 |
* |
| 1201 |
* @since 1.0.0 |
| 1202 |
* @param string $media_import it is store media data. |
| 1203 |
*/ |
| 1204 |
protected static function widgets_elements_id_change( $media_import ) { |
| 1205 |
if ( did_action( 'elementor/loaded' ) ) { |
| 1206 |
return \Elementor\Plugin::instance()->db->iterate_data( |
| 1207 |
$media_import, |
| 1208 |
function ( $element ) { |
| 1209 |
$element['id'] = \Elementor\Utils::generate_random_string(); |
| 1210 |
return $element; |
| 1211 |
} |
| 1212 |
); |
| 1213 |
} else { |
| 1214 |
return $media_import; |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
/** |
| 1219 |
* Widgets Media import copy content. |
| 1220 |
* |
| 1221 |
* @since 1.0.0 |
| 1222 |
* |
| 1223 |
* @param string $media_import it is store media data. |
| 1224 |
*/ |
| 1225 |
protected static function widgets_import_media_copy_content( $media_import ) { |
| 1226 |
if ( did_action( 'elementor/loaded' ) ) { |
| 1227 |
|
| 1228 |
return \Elementor\Plugin::instance()->db->iterate_data( |
| 1229 |
$media_import, |
| 1230 |
function ( $element_data ) { |
| 1231 |
$elements = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $element_data ); |
| 1232 |
|
| 1233 |
if ( ! $elements ) { |
| 1234 |
return null; |
| 1235 |
} |
| 1236 |
|
| 1237 |
return self::widgets_element_import_start( $elements ); |
| 1238 |
} |
| 1239 |
); |
| 1240 |
} else { |
| 1241 |
return $media_import; |
| 1242 |
} |
| 1243 |
} |
| 1244 |
|
| 1245 |
/** |
| 1246 |
* Start element copy content for media import. |
| 1247 |
* |
| 1248 |
* @since 1.0.0 |
| 1249 |
* |
| 1250 |
* @param string \Elementor\Controls_Stack $element it is store elementor data. |
| 1251 |
*/ |
| 1252 |
protected static function widgets_element_import_start( \Elementor\Controls_Stack $element ) { |
| 1253 |
$get_element_instance = $element->get_data(); |
| 1254 |
$tp_mi_on_fun = 'on_import'; |
| 1255 |
|
| 1256 |
if ( method_exists( $element, $tp_mi_on_fun ) ) { |
| 1257 |
$get_element_instance = $element->{$tp_mi_on_fun}( $get_element_instance ); |
| 1258 |
} |
| 1259 |
|
| 1260 |
foreach ( $element->get_controls() as $get_control ) { |
| 1261 |
$control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] ); |
| 1262 |
$control_name = $get_control['name']; |
| 1263 |
|
| 1264 |
if ( ! $control_type ) { |
| 1265 |
return $get_element_instance; |
| 1266 |
} |
| 1267 |
|
| 1268 |
if ( method_exists( $control_type, $tp_mi_on_fun ) ) { |
| 1269 |
$get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control ); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
return $get_element_instance; |
| 1274 |
} |
| 1275 |
|
| 1276 |
/** |
| 1277 |
* Blocks Recursively data |
| 1278 |
* |
| 1279 |
* @param string $data_import gutenber data import. |
| 1280 |
*/ |
| 1281 |
public static function blocks_import_media_copy_content( $data_import ) { |
| 1282 |
if ( ! empty( $data_import ) ) { |
| 1283 |
foreach ( $data_import[0] as $key => $val ) { |
| 1284 |
if ( array_key_exists( 'blockName', $val ) && ( empty( $val['blockName'] ) || null === $val['blockName'] || empty( $val['blockName'] ) || ' ' === $val['blockName'] ) ) { |
| 1285 |
unset( $data_import[0][ $key ] ); |
| 1286 |
} |
| 1287 |
} |
| 1288 |
} |
| 1289 |
|
| 1290 |
return self::blocks_array_recursively_data( |
| 1291 |
$data_import, |
| 1292 |
function ( $block_data ) { |
| 1293 |
$elements = self::blocks_data_instance( $block_data ); |
| 1294 |
return $elements; |
| 1295 |
} |
| 1296 |
); |
| 1297 |
} |
| 1298 |
|
| 1299 |
/** |
| 1300 |
* Blocks Recursively data |
| 1301 |
* |
| 1302 |
* @param array $data store data. |
| 1303 |
* @param string $callback store data. |
| 1304 |
* @param string $args store data. |
| 1305 |
*/ |
| 1306 |
public static function blocks_array_recursively_data( $data, $callback, $args = array() ) { |
| 1307 |
if ( ( isset( $data['name'] ) && ! empty( $data['name'] ) ) || ( isset( $data['blockName'] ) && ! empty( $data['blockName'] ) ) ) { |
| 1308 |
if ( ! empty( $data['innerBlocks'] ) ) { |
| 1309 |
$data['innerBlocks'] = self::blocks_array_recursively_data( $data['innerBlocks'], $callback, $args ); |
| 1310 |
} |
| 1311 |
|
| 1312 |
return call_user_func( $callback, $data, $args ); |
| 1313 |
} |
| 1314 |
|
| 1315 |
if ( ! empty( $data ) ) { |
| 1316 |
$data = (array) $data; |
| 1317 |
foreach ( $data as $block_key => $block_value ) { |
| 1318 |
$block_data = self::blocks_array_recursively_data( $data[ $block_key ], $callback, $args ); |
| 1319 |
|
| 1320 |
if ( null === $block_data ) { |
| 1321 |
continue; |
| 1322 |
} |
| 1323 |
|
| 1324 |
$data[ $block_key ] = $block_data; |
| 1325 |
} |
| 1326 |
} |
| 1327 |
|
| 1328 |
return $data; |
| 1329 |
} |
| 1330 |
|
| 1331 |
/** |
| 1332 |
* Check Blocks data media Url |
| 1333 |
* |
| 1334 |
* @param array $block_data store data. |
| 1335 |
* @param array $args store data. |
| 1336 |
* @param array $block_args store data. |
| 1337 |
*/ |
| 1338 |
public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) { |
| 1339 |
|
| 1340 |
if ( ( isset( $block_data['name'] ) && isset( $block_data['clientId'] ) && isset( $block_data['attributes'] ) ) || ( isset( $block_data['blockName'] ) && isset( $block_data['attrs'] ) && ! empty( $block_data['attrs'] ) ) ) { |
| 1341 |
$blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() ); |
| 1342 |
foreach ( $blocks_attr as $block_key => $block_val ) { |
| 1343 |
if ( isset( $block_val['url'] ) && isset( $block_val['id'] ) && ! empty( $block_val['url'] ) ) { |
| 1344 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val ); |
| 1345 |
$blocks_attr[ $block_key ] = $new_media; |
| 1346 |
} elseif ( isset( $block_val['url'] ) && ! empty( $block_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $block_val['url'] ) ) { |
| 1347 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val ); |
| 1348 |
$blocks_attr[ $block_key ] = $new_media; |
| 1349 |
} elseif ( is_array( $block_val ) && ! empty( $block_val ) ) { |
| 1350 |
if ( ! array_key_exists( 'md', $block_val ) && ! array_key_exists( 'openTypography', $block_val ) && ! array_key_exists( 'openBorder', $block_val ) && ! array_key_exists( 'openShadow', $block_val ) && ! array_key_exists( 'openFilter', $block_val ) ) { |
| 1351 |
foreach ( $block_val as $key => $val ) { |
| 1352 |
if ( is_array( $val ) && ! empty( $val ) ) { |
| 1353 |
|
| 1354 |
if ( isset( $val['url'] ) && ( isset( $val['Id'] ) || isset( $val['id'] ) ) && ! empty( $val['url'] ) ) { |
| 1355 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $val ); |
| 1356 |
$blocks_attr[ $block_key ][ $key ] = $new_media; |
| 1357 |
} elseif ( isset( $val['url'] ) && ! empty( $val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $val['url'] ) ) { |
| 1358 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $val ); |
| 1359 |
$blocks_attr[ $block_key ][ $key ] = $new_media; |
| 1360 |
} else { |
| 1361 |
foreach ( $val as $sub_key => $sub_val ) { |
| 1362 |
if ( isset( $sub_val['url'] ) && ( isset( $sub_val['Id'] ) || isset( $sub_val['id'] ) ) && ! empty( $sub_val['url'] ) ) { |
| 1363 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val ); |
| 1364 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media; |
| 1365 |
} elseif ( isset( $sub_val['url'] ) && ! empty( $sub_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val['url'] ) ) { |
| 1366 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val ); |
| 1367 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media; |
| 1368 |
} elseif ( is_array( $sub_val ) && ! empty( $sub_val ) ) { |
| 1369 |
foreach ( $sub_val as $sub_key1 => $sub_val1 ) { |
| 1370 |
if ( isset( $sub_val1['url'] ) && ( isset( $sub_val1['Id'] ) || isset( $sub_val1['id'] ) ) && ! empty( $sub_val1['url'] ) ) { |
| 1371 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 ); |
| 1372 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media; |
| 1373 |
} elseif ( isset( $sub_val1['url'] ) && ! empty( $sub_val1['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val1['url'] ) ) { |
| 1374 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 ); |
| 1375 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media; |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} |
| 1379 |
} |
| 1380 |
} |
| 1381 |
} |
| 1382 |
} |
| 1383 |
} |
| 1384 |
} |
| 1385 |
} |
| 1386 |
if ( isset( $block_data['attributes'] ) ) { |
| 1387 |
$block_data['attributes'] = $blocks_attr; |
| 1388 |
} elseif ( isset( $block_data['attrs'] ) ) { |
| 1389 |
$block_data['attrs'] = $blocks_attr; |
| 1390 |
} |
| 1391 |
} |
| 1392 |
|
| 1393 |
return $block_data; |
| 1394 |
} |
| 1395 |
|
| 1396 |
/** |
| 1397 |
* Kit Template Import Pages/Sections |
| 1398 |
* |
| 1399 |
* @since 1.0.0 |
| 1400 |
* */ |
| 1401 |
protected function wdkit_import_kit_template() { |
| 1402 |
|
| 1403 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 1404 |
return false; |
| 1405 |
} |
| 1406 |
|
| 1407 |
$builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : ''; |
| 1408 |
|
| 1409 |
if( !empty($builder) && $builder == 'elementor' ){ |
| 1410 |
$widgets = ['widgets', 'extensions']; |
| 1411 |
$widgets = apply_filters( 'tpae_enable_widgets', $widgets ); |
| 1412 |
} else if( ! empty( $builder ) && 'gutenberg' === $builder ){ |
| 1413 |
apply_filters( 'widget_load_nxt', 'tpgb_blocks_enable_all_filter' ); |
| 1414 |
} |
| 1415 |
|
| 1416 |
$page_section = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : ''; |
| 1417 |
|
| 1418 |
if ( isset( $page_section ) ) { |
| 1419 |
$args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : ''; |
| 1420 |
} |
| 1421 |
|
| 1422 |
$template_ids = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array(); |
| 1423 |
$email = ! empty( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : ''; |
| 1424 |
$editor = isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : ''; |
| 1425 |
$website_kit = isset( $_POST['website_kit'] ) ? sanitize_text_field( wp_unslash( $_POST['website_kit'] ) ) : ''; |
| 1426 |
$api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template'; |
| 1427 |
|
| 1428 |
if ( empty( $template_ids ) ) { |
| 1429 |
$output = array( |
| 1430 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1431 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1432 |
'success' => false, |
| 1433 |
); |
| 1434 |
|
| 1435 |
wp_send_json( $output ); |
| 1436 |
wp_die(); |
| 1437 |
} |
| 1438 |
|
| 1439 |
/**Not Usefull*/ |
| 1440 |
if ( isset( $_POST['select'] ) ) { |
| 1441 |
$args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : ''; |
| 1442 |
} |
| 1443 |
|
| 1444 |
$args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; |
| 1445 |
$args['editor'] = $editor; |
| 1446 |
|
| 1447 |
$token = $this->wdkit_login_user_token( $email ); |
| 1448 |
|
| 1449 |
$temp_args = array( |
| 1450 |
'token' => $token, |
| 1451 |
'template_id' => $template_ids['id'], |
| 1452 |
'editor' => $editor, |
| 1453 |
'website_kit' => $website_kit, |
| 1454 |
); |
| 1455 |
|
| 1456 |
$response = WDesignKit_Data_Query::get_data( $api_type, $temp_args ); |
| 1457 |
$output = array(); |
| 1458 |
|
| 1459 |
if ( 'error' === $response['content'] ) { |
| 1460 |
wp_send_json( $response ); |
| 1461 |
wp_die(); |
| 1462 |
} else { |
| 1463 |
$output[ $template_ids['id'] ] = $this->import_page_section_content( $args, $template_ids['id'], $response, $template_ids ); |
| 1464 |
$output['message'] = $response['message']; |
| 1465 |
$output['description'] = $response['description']; |
| 1466 |
$output['success'] = $response['success']; |
| 1467 |
} |
| 1468 |
|
| 1469 |
wp_send_json( $output ); |
| 1470 |
wp_die(); |
| 1471 |
} |
| 1472 |
|
| 1473 |
/** |
| 1474 |
* Import single template and section from plugin only |
| 1475 |
* */ |
| 1476 |
protected function wdkit_import_multi_template() { |
| 1477 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1478 |
$api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template'; |
| 1479 |
|
| 1480 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 1481 |
return false; |
| 1482 |
} |
| 1483 |
|
| 1484 |
if( ! empty( $args['builder'] ) && 'elementor' === $args['builder'] ){ |
| 1485 |
$widgets = ['widgets', 'extensions']; |
| 1486 |
$widgets = apply_filters( 'tpae_enable_widgets', $widgets ); |
| 1487 |
} else if( ! empty( $args['builder'] ) && 'gutenberg' === $args['builder'] ){ |
| 1488 |
apply_filters( 'widget_load_nxt', 'tpgb_blocks_enable_all_filter' ); |
| 1489 |
} |
| 1490 |
|
| 1491 |
if ( empty( $_POST['template_ids'] ) ) { |
| 1492 |
$output = array( |
| 1493 |
'data' => array(), |
| 1494 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1495 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1496 |
'success' => false, |
| 1497 |
); |
| 1498 |
|
| 1499 |
wp_send_json( $output ); |
| 1500 |
wp_die(); |
| 1501 |
} |
| 1502 |
|
| 1503 |
if ( isset( $_POST['template_ids'] ) ) { |
| 1504 |
$args['template_ids'] = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array(); |
| 1505 |
} |
| 1506 |
|
| 1507 |
if ( isset( $_POST['page_section'] ) ) { |
| 1508 |
$args['page_section'] = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : ''; |
| 1509 |
} |
| 1510 |
|
| 1511 |
if ( isset( $_POST['select'] ) ) { |
| 1512 |
$args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : ''; |
| 1513 |
} |
| 1514 |
|
| 1515 |
$args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; |
| 1516 |
if ( ! empty( $args['template_ids'] ) && ! empty( $args['page_section'] ) ) { |
| 1517 |
$output = array(); |
| 1518 |
if ( is_array( $args['template_ids'] ) ) { |
| 1519 |
foreach ( $args['template_ids'] as $key => $value ) { |
| 1520 |
if ( ! empty( $value['id'] ) ) { |
| 1521 |
$token = $this->wdkit_login_user_token( $args['email'] ); |
| 1522 |
$temp_args = array( |
| 1523 |
'token' => $token, |
| 1524 |
'template_id' => $value['id'], |
| 1525 |
'editor' => $args['editor'], |
| 1526 |
); |
| 1527 |
|
| 1528 |
$response = WDesignKit_Data_Query::get_data( $api_type, $temp_args ); |
| 1529 |
|
| 1530 |
if ( 'error' === $response['content'] ) { |
| 1531 |
wp_send_json( $response ); |
| 1532 |
wp_die(); |
| 1533 |
} else { |
| 1534 |
$output[ $value['id'] ] = $this->import_page_section_content( $args, $value['id'], $response, $value ); |
| 1535 |
$output['message'] = $response['message']; |
| 1536 |
$output['description'] = $response['description']; |
| 1537 |
$output['success'] = $response['success']; |
| 1538 |
} |
| 1539 |
} |
| 1540 |
} |
| 1541 |
} else { |
| 1542 |
$token = $this->wdkit_login_user_token( $args['email'] ); |
| 1543 |
$temp_args = array( |
| 1544 |
'token' => $token, |
| 1545 |
'template_id' => $args['template_ids'], |
| 1546 |
'editor' => $args['editor'], |
| 1547 |
); |
| 1548 |
|
| 1549 |
$response = WDesignKit_Data_Query::get_data( $api_type, $temp_args ); |
| 1550 |
|
| 1551 |
if ( 'error' === $response['content'] ) { |
| 1552 |
wp_send_json( $response ); |
| 1553 |
wp_die(); |
| 1554 |
} else { |
| 1555 |
$output[ $args['template_ids'] ] = $this->import_page_section_content( $args, $args['template_ids'], $response ); |
| 1556 |
$output['message'] = $response['message']; |
| 1557 |
$output['description'] = $response['description']; |
| 1558 |
$output['success'] = $response['success']; |
| 1559 |
} |
| 1560 |
} |
| 1561 |
|
| 1562 |
$output['success'] = true; |
| 1563 |
|
| 1564 |
wp_send_json( $output ); |
| 1565 |
wp_die(); |
| 1566 |
} |
| 1567 |
} |
| 1568 |
|
| 1569 |
/** |
| 1570 |
* Import single template and section from plugin only |
| 1571 |
* |
| 1572 |
* @param array $args store data. |
| 1573 |
* @param array $template_id store data. |
| 1574 |
* @param array $data store data. |
| 1575 |
* @param array $temp_data store data. |
| 1576 |
* */ |
| 1577 |
private function import_page_section_content( $args, $template_id, $data, $temp_data = array() ) { |
| 1578 |
$enqueue_instance = new Wdkit_Enqueue(); |
| 1579 |
$get_post_type = $enqueue_instance->wdkit_get_post_type_list(); |
| 1580 |
|
| 1581 |
$post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page'; |
| 1582 |
|
| 1583 |
if ( 'section' === $post_type ) { |
| 1584 |
$post_type = $temp_data['wp_post_type']; |
| 1585 |
} else { |
| 1586 |
$post_type = $temp_data['wp_post_type']; |
| 1587 |
} |
| 1588 |
|
| 1589 |
if ( ! array_key_exists( $post_type, $get_post_type ) ) { |
| 1590 |
$post_type = 'page'; |
| 1591 |
} |
| 1592 |
|
| 1593 |
if ( ! empty( $data ) && ! empty( $data['content'] ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) { |
| 1594 |
$post_content = json_decode( $data['content'] ); |
| 1595 |
$post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : ''; |
| 1596 |
$file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : ''; |
| 1597 |
$content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : ''; |
| 1598 |
|
| 1599 |
if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) { |
| 1600 |
if ( empty( $content ) ) { |
| 1601 |
wp_send_json( |
| 1602 |
array( |
| 1603 |
'template_id' => $template_id, |
| 1604 |
'message' => 'Content is Empty.', |
| 1605 |
) |
| 1606 |
); |
| 1607 |
wp_die(); |
| 1608 |
} elseif ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) { |
| 1609 |
$parse_blocks = parse_blocks( stripslashes( $content ) ); |
| 1610 |
|
| 1611 |
$editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor']; |
| 1612 |
$content = $this->wdkit_media_import( $parse_blocks, $editor ); |
| 1613 |
$content = addslashes( serialize_blocks( $content ) ); |
| 1614 |
|
| 1615 |
$inserted_post = wp_insert_post( |
| 1616 |
array( |
| 1617 |
'post_status' => 'publish', |
| 1618 |
'post_type' => $post_type, |
| 1619 |
'post_title' => $post_title, |
| 1620 |
'post_content' => $content, |
| 1621 |
) |
| 1622 |
); |
| 1623 |
|
| 1624 |
if ( is_wp_error( $inserted_post ) ) { |
| 1625 |
wp_send_json( |
| 1626 |
array( |
| 1627 |
'import_failed' => $inserted_post->get_error_message(), |
| 1628 |
'code' => $inserted_post->get_error_code(), |
| 1629 |
) |
| 1630 |
); |
| 1631 |
wp_die(); |
| 1632 |
} |
| 1633 |
|
| 1634 |
if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) { |
| 1635 |
$custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : ''; |
| 1636 |
if ( ! empty( $custom_meta ) ) { |
| 1637 |
foreach ( $custom_meta as $meta_key => $meta_val ) { |
| 1638 |
if ( isset( $meta_val[0] ) && ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { |
| 1639 |
$meta_val[0] = maybe_unserialize( $meta_val[0] ); |
| 1640 |
} |
| 1641 |
|
| 1642 |
if ( '' === get_post_meta( $inserted_post, $meta_key, true ) && isset( $meta_val[0] ) ) { |
| 1643 |
add_post_meta( $inserted_post, $meta_key, $meta_val[0] ); |
| 1644 |
} |
| 1645 |
} |
| 1646 |
} |
| 1647 |
} |
| 1648 |
|
| 1649 |
if (has_filter('tpgb_disable_unsed_block_filter')) { |
| 1650 |
apply_filters( 'tpgb_disable_unsed_block_filter', array('tpgb_disable_unsed_block_filter_fun') ); |
| 1651 |
} |
| 1652 |
|
| 1653 |
return array( |
| 1654 |
'title' => get_the_title( $inserted_post ), |
| 1655 |
'edit_link' => get_edit_post_link( $inserted_post, 'internal' ), |
| 1656 |
'view' => get_permalink( $inserted_post ), |
| 1657 |
); |
| 1658 |
} |
| 1659 |
} elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) { |
| 1660 |
if ( did_action( 'elementor/loaded' ) ) { |
| 1661 |
if ( empty( $content ) ) { |
| 1662 |
wp_send_json( |
| 1663 |
array( |
| 1664 |
'template_id' => $template_id, |
| 1665 |
'message' => 'Content is Empty.', |
| 1666 |
) |
| 1667 |
); |
| 1668 |
wp_die(); |
| 1669 |
} elseif ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) { |
| 1670 |
$post_attributes = array( |
| 1671 |
'post_title' => $post_title, |
| 1672 |
'post_type' => $post_type, |
| 1673 |
'post_status' => 'publish', |
| 1674 |
); |
| 1675 |
|
| 1676 |
if ( 'elementor_library' === $post_type ) { |
| 1677 |
$el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page'; |
| 1678 |
$new_document = \Elementor\Plugin::$instance->documents->create( |
| 1679 |
$el_type, |
| 1680 |
$post_attributes |
| 1681 |
); |
| 1682 |
} else { |
| 1683 |
$new_document = \Elementor\Plugin::$instance->documents->create( |
| 1684 |
$post_attributes['post_type'], |
| 1685 |
$post_attributes |
| 1686 |
); |
| 1687 |
} |
| 1688 |
|
| 1689 |
if ( is_wp_error( $new_document ) ) { |
| 1690 |
wp_send_json( |
| 1691 |
array( |
| 1692 |
'import_failed' => $new_document->get_error_message(), |
| 1693 |
'code' => $new_document->get_error_code(), |
| 1694 |
) |
| 1695 |
); |
| 1696 |
wp_die(); |
| 1697 |
} |
| 1698 |
|
| 1699 |
$settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array(); |
| 1700 |
|
| 1701 |
$content = wp_json_encode( $content ); |
| 1702 |
$content = $this->wdkit_media_import( $content, $file_type ); |
| 1703 |
|
| 1704 |
$new_document->save( |
| 1705 |
array( |
| 1706 |
'elements' => $content, |
| 1707 |
'settings' => ! empty( $settings ) ? $settings : array(), |
| 1708 |
) |
| 1709 |
); |
| 1710 |
|
| 1711 |
$inserted_id = $new_document->get_main_id(); |
| 1712 |
|
| 1713 |
if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) { |
| 1714 |
$custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : ''; |
| 1715 |
if ( ! empty( $custom_meta ) ) { |
| 1716 |
foreach ( $custom_meta as $meta_key => $meta_val ) { |
| 1717 |
if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { |
| 1718 |
$meta_val[0] = maybe_unserialize( $meta_val[0] ); |
| 1719 |
} |
| 1720 |
if ( '' === get_post_meta( $inserted_id, $meta_key, true ) ) { |
| 1721 |
add_post_meta( $inserted_id, $meta_key, $meta_val[0] ); |
| 1722 |
} |
| 1723 |
} |
| 1724 |
} |
| 1725 |
} |
| 1726 |
|
| 1727 |
if (has_filter('tpae_widget_scan')) { |
| 1728 |
$type = array('get_wdkit_unused_widgets'); |
| 1729 |
$data = apply_filters( 'tpae_widget_scan', $type ); |
| 1730 |
} |
| 1731 |
|
| 1732 |
return array( |
| 1733 |
'title' => get_the_title( $inserted_id ), |
| 1734 |
'edit_link' => get_edit_post_link( $inserted_id, 'internal' ), |
| 1735 |
'view' => get_permalink( $inserted_id ), |
| 1736 |
); |
| 1737 |
} |
| 1738 |
} else { |
| 1739 |
if (has_filter('tpae_widget_scan')) { |
| 1740 |
$type = array('get_wdkit_unused_widgets'); |
| 1741 |
$data = apply_filters( 'tpae_widget_scan', $type ); |
| 1742 |
} |
| 1743 |
|
| 1744 |
wp_send_json( |
| 1745 |
array( |
| 1746 |
'template_id' => $template_id, |
| 1747 |
'message' => esc_html__( 'Relevant Page Builder not installed or activated', 'wdesignkit' ), |
| 1748 |
) |
| 1749 |
); |
| 1750 |
wp_die(); |
| 1751 |
} |
| 1752 |
} |
| 1753 |
} |
| 1754 |
} |
| 1755 |
|
| 1756 |
/** |
| 1757 |
* Share with Me Template and widgets |
| 1758 |
* |
| 1759 |
* @since 1.0.0 |
| 1760 |
*/ |
| 1761 |
protected function wdkit_shared_with_me() { |
| 1762 |
$data = isset( $_POST['api_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['api_info'] ) ) ) ) : ''; |
| 1763 |
|
| 1764 |
$array_data = array( |
| 1765 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 1766 |
'type' => isset( $data->type ) ? sanitize_text_field( wp_unslash( $data->type ) ) : '', |
| 1767 |
'ParPage' => isset( $data->par_page ) ? (int) $data->par_page : 12, |
| 1768 |
'CurrentPage' => isset( $data->current_page ) ? (int) $data->current_page : 1, |
| 1769 |
'builder' => isset( $data->builder ) ? sanitize_text_field( wp_unslash( $data->builder ) ) : '', |
| 1770 |
); |
| 1771 |
|
| 1772 |
$response = $this->wkit_api_call( $array_data, 'shared_with_me' ); |
| 1773 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 1774 |
|
| 1775 |
wp_send_json( $response ); |
| 1776 |
wp_die(); |
| 1777 |
} |
| 1778 |
|
| 1779 |
/** |
| 1780 |
* Add new WorkSpace |
| 1781 |
* |
| 1782 |
* @since 1.0.0 |
| 1783 |
*/ |
| 1784 |
protected function wdkit_manage_workspace() { |
| 1785 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1786 |
|
| 1787 |
$user_email = ! empty( $args['email'] ) ? strtolower( sanitize_email( $args['email'] ) ) : ''; |
| 1788 |
$current_wid = ! empty( $_POST['current_wid'] ) ? strtolower( sanitize_text_field( $_POST['current_wid'] ) ) : ''; |
| 1789 |
|
| 1790 |
$args['current_wid'] = $current_wid; |
| 1791 |
|
| 1792 |
if ( empty( $user_email ) ) { |
| 1793 |
$response = array( |
| 1794 |
'message' => $this->e_msg_login, |
| 1795 |
'description' => $this->e_desc_login, |
| 1796 |
'success' => false, |
| 1797 |
); |
| 1798 |
|
| 1799 |
wp_send_json( $response ); |
| 1800 |
wp_die(); |
| 1801 |
} |
| 1802 |
|
| 1803 |
$args['token'] = $this->wdkit_login_user_token( $user_email ); |
| 1804 |
unset( $user_email ); |
| 1805 |
|
| 1806 |
$response = WDesignKit_Data_Query::get_data( 'manage_workspace', $args ); |
| 1807 |
|
| 1808 |
return $response; |
| 1809 |
} |
| 1810 |
|
| 1811 |
/** |
| 1812 |
* |
| 1813 |
* It is Use for manage workspace |
| 1814 |
* |
| 1815 |
* @since 1.0.0 |
| 1816 |
*/ |
| 1817 |
protected function wdkit_manage_widget_workspace() { |
| 1818 |
$workspace_info = isset( $_POST['workspace_info'] ) ? sanitize_text_field( wp_unslash( $_POST['workspace_info'] ) ) : array(); |
| 1819 |
$data = isset( $workspace_info ) ? json_decode( stripslashes( $workspace_info ) ) : array(); |
| 1820 |
|
| 1821 |
$array_data = array( |
| 1822 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 1823 |
'wstype' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 1824 |
'widget_id' => isset( $data->widget_id ) ? (int) $data->widget_id : '', |
| 1825 |
'wid' => isset( $data->wid ) ? (int) $data->wid : '', |
| 1826 |
'current_wid' => isset( $data->current_wid ) ? (int) $data->current_wid : '', |
| 1827 |
); |
| 1828 |
|
| 1829 |
$response = $this->wkit_api_call( $array_data, 'manage_workspace' ); |
| 1830 |
|
| 1831 |
wp_send_json( $response['data'] ); |
| 1832 |
wp_die(); |
| 1833 |
} |
| 1834 |
|
| 1835 |
/** |
| 1836 |
* |
| 1837 |
* It is Use for manage api key page |
| 1838 |
* |
| 1839 |
* @since 1.0.0 |
| 1840 |
*/ |
| 1841 |
protected function wdkit_activate_key() { |
| 1842 |
$email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; |
| 1843 |
$response = ''; |
| 1844 |
|
| 1845 |
if ( empty( $user_email ) ) { |
| 1846 |
$response = array( |
| 1847 |
'message' => $this->e_msg_login, |
| 1848 |
'description' => $this->e_desc_login, |
| 1849 |
'success' => false, |
| 1850 |
); |
| 1851 |
|
| 1852 |
wp_send_json( $response ); |
| 1853 |
wp_die(); |
| 1854 |
} |
| 1855 |
|
| 1856 |
$token = $this->wdkit_login_user_token( $email ); |
| 1857 |
$apikey = isset( $_POST['apikey'] ) ? sanitize_key( wp_unslash( $_POST['apikey'] ) ) : ''; |
| 1858 |
$product = isset( $_POST['product'] ) ? sanitize_text_field( wp_unslash( $_POST['product'] ) ) : ''; |
| 1859 |
$product_action = isset( $_POST['product_action'] ) ? sanitize_text_field( wp_unslash( $_POST['product_action'] ) ) : 'activate'; |
| 1860 |
if ( ! empty( $token ) && ! empty( $product ) && ! empty( $product_action ) ) { |
| 1861 |
$args = array( |
| 1862 |
'token' => $token, |
| 1863 |
'product' => $product, |
| 1864 |
'product_action' => $product_action, |
| 1865 |
); |
| 1866 |
|
| 1867 |
if ( 'activate' === $product_action ) { |
| 1868 |
$args['apikey'] = $apikey; |
| 1869 |
$args['site_url'] = home_url(); |
| 1870 |
} |
| 1871 |
|
| 1872 |
$response = Wdkit_Data_Hooks::get_data( 'wkit_activate_key', $args ); |
| 1873 |
} |
| 1874 |
|
| 1875 |
wp_send_json( $response ); |
| 1876 |
wp_die(); |
| 1877 |
} |
| 1878 |
|
| 1879 |
/** |
| 1880 |
* |
| 1881 |
* Get list local Widget List |
| 1882 |
* |
| 1883 |
* @since 1.0.0 |
| 1884 |
*/ |
| 1885 |
protected function wdkit_get_local_widgets() { |
| 1886 |
$builder = array(); |
| 1887 |
$a_c_s_d_s_c = array(); |
| 1888 |
$j_s_o_n_array = array(); |
| 1889 |
|
| 1890 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks', 'widget' ) ) { |
| 1891 |
array_push( $builder, 'bricks' ); |
| 1892 |
} |
| 1893 |
|
| 1894 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor', 'widget' ) ) { |
| 1895 |
array_push( $builder, 'elementor' ); |
| 1896 |
} |
| 1897 |
|
| 1898 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) { |
| 1899 |
array_push( $builder, 'gutenberg' ); |
| 1900 |
} |
| 1901 |
|
| 1902 |
foreach ( $builder as $key => $name ) { |
| 1903 |
$elementor_dir = WDKIT_BUILDER_PATH . '/' . $name; |
| 1904 |
|
| 1905 |
if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) { |
| 1906 |
$elementor_list = scandir( $elementor_dir ); |
| 1907 |
$elementor_list = array_diff( $elementor_list, array( '.', '..' ) ); |
| 1908 |
|
| 1909 |
if ( ! empty( $elementor_list ) ) { |
| 1910 |
foreach ( $elementor_list as $key => $value ) { |
| 1911 |
$a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) ]['data'] = $value; |
| 1912 |
$a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) ]['builder'] = $name; |
| 1913 |
} |
| 1914 |
} |
| 1915 |
} |
| 1916 |
} |
| 1917 |
|
| 1918 |
ksort( $a_c_s_d_s_c ); |
| 1919 |
$a_c_s_d_s_c = array_reverse( $a_c_s_d_s_c ); |
| 1920 |
|
| 1921 |
foreach ( $a_c_s_d_s_c as $key => $value ) { |
| 1922 |
$elementor_dir = WDKIT_BUILDER_PATH . '/' . $value['builder']; |
| 1923 |
|
| 1924 |
if ( file_exists( "{$elementor_dir}/{$value['data']}" ) && is_dir( "{$elementor_dir}/{$value['data']}" ) ) { |
| 1925 |
$sub_dir = scandir( "{$elementor_dir}/{$value['data']}" ); |
| 1926 |
$sub = array_diff( $sub_dir, array( '.', '..' ) ); |
| 1927 |
|
| 1928 |
foreach ( $sub as $sub_dir_value ) { |
| 1929 |
$file = new SplFileInfo( $sub_dir_value ); |
| 1930 |
$check_ext = $file->getExtension(); |
| 1931 |
$ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 1932 |
|
| 1933 |
if ( 'json' === $ext ) { |
| 1934 |
$widget1 = WDKIT_BUILDER_PATH . "/{$value['builder']}/{$value['data']}/{$sub_dir_value}"; |
| 1935 |
$filedata = wp_json_file_decode( $widget1 ); |
| 1936 |
$decode_data = json_decode( wp_json_encode( $filedata ), true ); |
| 1937 |
array_push( $j_s_o_n_array, $decode_data['widget_data'] ); |
| 1938 |
} |
| 1939 |
} |
| 1940 |
} |
| 1941 |
} |
| 1942 |
|
| 1943 |
return $j_s_o_n_array; |
| 1944 |
} |
| 1945 |
|
| 1946 |
/** |
| 1947 |
* |
| 1948 |
* It is Use for manage widget category. |
| 1949 |
* |
| 1950 |
* @since 1.0.0 |
| 1951 |
*/ |
| 1952 |
protected function wdkit_manage_widget_category() { |
| 1953 |
$data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : ''; |
| 1954 |
$data = json_decode( stripslashes( $data ) ); |
| 1955 |
|
| 1956 |
$type = isset( $data->manage_type ) ? sanitize_text_field( wp_unslash( $data->manage_type ) ) : ''; |
| 1957 |
$wkit_builder_option = get_option( 'wkit_builder' ); |
| 1958 |
|
| 1959 |
if ( empty( $wkit_builder_option ) ) { |
| 1960 |
add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' ); |
| 1961 |
} |
| 1962 |
|
| 1963 |
if ( 'get' === $type ) { |
| 1964 |
if ( ! in_array( 'WDesignKit', $wkit_builder_option ) ) { |
| 1965 |
update_option( 'wkit_builder', array( 'WDesignKit' ) ); |
| 1966 |
} |
| 1967 |
} elseif ( 'update' === $type ) { |
| 1968 |
$list = isset( $data->category_list ) ? $data->category_list : array(); |
| 1969 |
$list = array_unique( $list ); |
| 1970 |
$list = array_values( $list ); |
| 1971 |
|
| 1972 |
if ( ! empty( $list ) ) { |
| 1973 |
update_option( 'wkit_builder', $list ); |
| 1974 |
} |
| 1975 |
} |
| 1976 |
|
| 1977 |
wp_send_json( get_option( 'wkit_builder' ) ); |
| 1978 |
} |
| 1979 |
|
| 1980 |
/** |
| 1981 |
* |
| 1982 |
* Custom_upload_dir |
| 1983 |
* |
| 1984 |
* @since 1.0.0 |
| 1985 |
* |
| 1986 |
* @param array $upload store data. |
| 1987 |
*/ |
| 1988 |
public function custom_upload_dir( $upload ) { |
| 1989 |
// Specify the path to your custom upload directory. |
| 1990 |
if ( isset( $this->widget_folder_u_r_l ) && ! empty( $this->widget_folder_u_r_l ) ) { |
| 1991 |
|
| 1992 |
// Set the custom directory as the upload path. |
| 1993 |
$upload['path'] = $this->widget_folder_u_r_l; |
| 1994 |
// Set the URL for the uploaded file. |
| 1995 |
$upload['url'] = $upload['baseurl'] . $upload['subdir']; |
| 1996 |
} |
| 1997 |
|
| 1998 |
return $upload; |
| 1999 |
} |
| 2000 |
|
| 2001 |
/** |
| 2002 |
* |
| 2003 |
* It is Use for delete widget from server |
| 2004 |
* |
| 2005 |
* @since 1.0.0 |
| 2006 |
*/ |
| 2007 |
protected function wkit_widget_json() { |
| 2008 |
$json_path = isset( $_POST['json_path'] ) ? ( wp_unslash( $_POST['json_path'] ) ) : ''; |
| 2009 |
|
| 2010 |
if ( empty( $json_path ) ) { |
| 2011 |
return array( |
| 2012 |
'success' => false, |
| 2013 |
'message' => esc_html__( 'Widget JSON not found', 'wdesignkit' ), |
| 2014 |
'description' => esc_html__( 'widget JSON file not found.', 'wdesignkit' ), |
| 2015 |
); |
| 2016 |
} |
| 2017 |
|
| 2018 |
$json_data = wp_remote_get( $json_path ); |
| 2019 |
if ( ! empty( $json_data['body'] ) ) { |
| 2020 |
$result = (object) array( |
| 2021 |
'success' => true, |
| 2022 |
'data' => $json_data['body'], |
| 2023 |
'message' => esc_html__( 'Widget get Successfully', 'wdesignkit' ), |
| 2024 |
'description' => esc_html__( 'Widget JSON get Successfully', 'wdesignkit' ), |
| 2025 |
); |
| 2026 |
} else { |
| 2027 |
$result = (object) array( |
| 2028 |
'success' => false, |
| 2029 |
'message' => esc_html__( 'Widget not get', 'wdesignkit' ), |
| 2030 |
'description' => esc_html__( 'Widget JSON not get', 'wdesignkit' ), |
| 2031 |
); |
| 2032 |
} |
| 2033 |
|
| 2034 |
wp_send_json( $result ); |
| 2035 |
wp_die(); |
| 2036 |
} |
| 2037 |
|
| 2038 |
/** |
| 2039 |
* |
| 2040 |
* It is Use for download widget from widget listing. |
| 2041 |
* |
| 2042 |
* @since 1.0.0 |
| 2043 |
*/ |
| 2044 |
protected function wdkit_download_widget() { |
| 2045 |
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : ''; |
| 2046 |
$data = json_decode( stripslashes( $data ) ); |
| 2047 |
|
| 2048 |
$array_data = array( |
| 2049 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2050 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2051 |
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2052 |
); |
| 2053 |
|
| 2054 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2055 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2056 |
|
| 2057 |
if ( empty( $success ) ) { |
| 2058 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2059 |
$result = (object) array( |
| 2060 |
'success' => false, |
| 2061 |
'message' => $massage, |
| 2062 |
'description' => esc_html__( ' Widget not Downloaded', 'wdesignkit' ), |
| 2063 |
); |
| 2064 |
|
| 2065 |
wp_send_json( $result ); |
| 2066 |
wp_die(); |
| 2067 |
} |
| 2068 |
|
| 2069 |
$response = json_decode( wp_json_encode( $response['data'] ), true ); |
| 2070 |
|
| 2071 |
if ( empty( $response ) || empty( $response['data'] ) ) { |
| 2072 |
$message = ! empty( $response['message'] ) ? $response['message'] : 'No Response Found'; |
| 2073 |
$description = ! empty( $response['description'] ) ? $response['description'] : 'Widget not Downloaded'; |
| 2074 |
|
| 2075 |
$result = (object) array( |
| 2076 |
'success' => false, |
| 2077 |
'message' => esc_html( $message ), |
| 2078 |
'description' => esc_html( $description ), |
| 2079 |
); |
| 2080 |
|
| 2081 |
wp_send_json( $result ); |
| 2082 |
wp_die(); |
| 2083 |
} |
| 2084 |
|
| 2085 |
$img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : ''; |
| 2086 |
$json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'], true ) : ''; |
| 2087 |
|
| 2088 |
if( empty( $response['success'] ) ){ |
| 2089 |
wp_send_json( $responce ); |
| 2090 |
wp_die(); |
| 2091 |
} |
| 2092 |
|
| 2093 |
if ( empty( $img_url ) && empty( $json_data ) ) { |
| 2094 |
$responce = (object) array( |
| 2095 |
'success' => false, |
| 2096 |
'message' => esc_html__( 'No Response Found', 'wdesignkit' ), |
| 2097 |
'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ), |
| 2098 |
); |
| 2099 |
|
| 2100 |
wp_send_json( $responce ); |
| 2101 |
wp_die(); |
| 2102 |
} |
| 2103 |
|
| 2104 |
include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2105 |
\WP_Filesystem(); |
| 2106 |
global $wp_filesystem; |
| 2107 |
|
| 2108 |
if( !is_array($json_data) ){ |
| 2109 |
$json_data = json_decode( $json_data, true ); |
| 2110 |
} |
| 2111 |
|
| 2112 |
$title = ! empty( $json_data['widget_data']['widgetdata']['name'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['name'] ) : ''; |
| 2113 |
$builder = ! empty( $json_data['widget_data']['widgetdata']['type'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['type'] ) : ''; |
| 2114 |
$w_uniq = ! empty( $json_data['widget_data']['widgetdata']['widget_id'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['widget_id'] ) : ''; |
| 2115 |
|
| 2116 |
$folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq; |
| 2117 |
$file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq; |
| 2118 |
$builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/"; |
| 2119 |
|
| 2120 |
if ( ! is_dir( $builder_type_path ) ) { |
| 2121 |
wp_mkdir_p( $builder_type_path ); |
| 2122 |
} |
| 2123 |
|
| 2124 |
if ( ! is_dir( $builder_type_path . $folder_name ) ) { |
| 2125 |
wp_mkdir_p( $builder_type_path . $folder_name ); |
| 2126 |
} |
| 2127 |
|
| 2128 |
if ( ! empty( $img_url ) ) { |
| 2129 |
$img_body = wp_remote_get( $img_url ); |
| 2130 |
$img_ext = pathinfo( $img_url )['extension']; |
| 2131 |
|
| 2132 |
$wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] ); |
| 2133 |
$json_data['widget_data']['widgetdata']['w_image'] = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext"; |
| 2134 |
} |
| 2135 |
|
| 2136 |
$result = (object) array( |
| 2137 |
'success' => false, |
| 2138 |
'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ), |
| 2139 |
'description' => '', |
| 2140 |
'json' => wp_json_encode( $json_data ), |
| 2141 |
); |
| 2142 |
|
| 2143 |
wp_send_json( $result ); |
| 2144 |
wp_die(); |
| 2145 |
} |
| 2146 |
|
| 2147 |
/** |
| 2148 |
* |
| 2149 |
* It is Use for sync widget to server |
| 2150 |
* |
| 2151 |
* @since 1.0.0 |
| 2152 |
*/ |
| 2153 |
protected function wdkit_add_widget() { |
| 2154 |
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : ''; |
| 2155 |
$data = json_decode( stripslashes( $data ) ); |
| 2156 |
|
| 2157 |
$title = isset( $data->title ) ? sanitize_text_field( $data->title ) : ''; |
| 2158 |
$builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : ''; |
| 2159 |
$w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : ''; |
| 2160 |
$w_image = isset( $data->w_image ) ? esc_url_raw( $data->w_image ) : ''; |
| 2161 |
|
| 2162 |
if ( ! empty( $w_image ) ) { |
| 2163 |
$w_image = str_replace( '\\', '', $w_image ); |
| 2164 |
$w_image = wp_remote_get( $w_image )['body']; |
| 2165 |
} |
| 2166 |
|
| 2167 |
$array_data = array( |
| 2168 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2169 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2170 |
'title' => isset( $data->title ) ? sanitize_text_field( $data->title ) : '', |
| 2171 |
'content' => isset( $data->content ) ? sanitize_text_field( $data->content ) : '', |
| 2172 |
'builder' => isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '', |
| 2173 |
'w_data' => isset( $data->w_data ) ? $data->w_data : '', |
| 2174 |
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2175 |
'w_image' => $w_image, |
| 2176 |
'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '', |
| 2177 |
'w_version' => isset( $data->w_version ) ? $data->w_version : '', |
| 2178 |
'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ), |
| 2179 |
'r_id' => isset( $data->r_id ) ? $data->r_id : 0, |
| 2180 |
); |
| 2181 |
|
| 2182 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2183 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2184 |
|
| 2185 |
if ( empty( $success ) ) { |
| 2186 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2187 |
|
| 2188 |
$result = (object) array( |
| 2189 |
'success' => false, |
| 2190 |
'message' => $massage, |
| 2191 |
'description' => esc_html__( 'Widget Not Added', 'wdesignkit' ), |
| 2192 |
); |
| 2193 |
|
| 2194 |
wp_send_json( $result ); |
| 2195 |
wp_die(); |
| 2196 |
} |
| 2197 |
|
| 2198 |
$res = ! empty( $response['data'] ) ? $response['data'] : array(); |
| 2199 |
|
| 2200 |
$response = json_decode( wp_json_encode( $res ), true ); |
| 2201 |
$img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : ''; |
| 2202 |
|
| 2203 |
if ( ! empty( $img_url ) && 'error' !== $res ) { |
| 2204 |
$img_body = wp_remote_get( $img_url ); |
| 2205 |
$img_ext = pathinfo( $img_url )['extension']; |
| 2206 |
include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2207 |
\WP_Filesystem(); |
| 2208 |
global $wp_filesystem; |
| 2209 |
$folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq; |
| 2210 |
$file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq; |
| 2211 |
$file_path = WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name"; |
| 2212 |
|
| 2213 |
$u_r_l = wp_json_file_decode( "$file_path.json" ); |
| 2214 |
$u_r_l->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext"; |
| 2215 |
|
| 2216 |
$wp_filesystem->put_contents( "$file_path.json", wp_json_encode( $u_r_l ) ); |
| 2217 |
$wp_filesystem->put_contents( "$file_path.$img_ext", $img_body['body'] ); |
| 2218 |
} |
| 2219 |
|
| 2220 |
wp_send_json( $response ); |
| 2221 |
wp_die(); |
| 2222 |
} |
| 2223 |
|
| 2224 |
/** |
| 2225 |
* |
| 2226 |
* It is Use for manage favourite widget |
| 2227 |
* |
| 2228 |
* @since 1.0.0 |
| 2229 |
*/ |
| 2230 |
protected function wdkit_favourite_widget() { |
| 2231 |
$data = isset( $_POST['widget_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['widget_info'] ) ) ) ) : ''; |
| 2232 |
$array_data = array( |
| 2233 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2234 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2235 |
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2236 |
); |
| 2237 |
|
| 2238 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2239 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2240 |
|
| 2241 |
if ( empty( $success ) ) { |
| 2242 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2243 |
|
| 2244 |
$result = (object) array( |
| 2245 |
'success' => false, |
| 2246 |
'message' => $massage, |
| 2247 |
'description' => '', |
| 2248 |
); |
| 2249 |
|
| 2250 |
wp_send_json( $result ); |
| 2251 |
wp_die(); |
| 2252 |
} |
| 2253 |
|
| 2254 |
wp_send_json( $response ); |
| 2255 |
wp_die(); |
| 2256 |
} |
| 2257 |
|
| 2258 |
/** |
| 2259 |
* It is Used Setting Panel Defalut Data Get. |
| 2260 |
* |
| 2261 |
* @since 1.0.0 |
| 2262 |
*/ |
| 2263 |
protected function wdkit_setting_panel() { |
| 2264 |
$event = ! empty( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : 'get'; |
| 2265 |
|
| 2266 |
if ( 'get' === $event ) { |
| 2267 |
return self::wkit_get_settings_panel(); |
| 2268 |
} elseif ( 'set' === $event ) { |
| 2269 |
$data = ! empty( $_POST['data'] ) ? stripslashes( sanitize_text_field( wp_unslash( $_POST['data'] ) ) ) : array(); |
| 2270 |
|
| 2271 |
$data = json_decode( $data, true ); |
| 2272 |
|
| 2273 |
update_option( 'wkit_settings_panel', $data ); |
| 2274 |
return self::wkit_get_settings_panel(); |
| 2275 |
} else { |
| 2276 |
return false; |
| 2277 |
} |
| 2278 |
} |
| 2279 |
|
| 2280 |
/** |
| 2281 |
* Get Setting Panal Data |
| 2282 |
* |
| 2283 |
* @since 1.0.0 |
| 2284 |
*/ |
| 2285 |
protected static function wkit_get_settings_panel() { |
| 2286 |
$new_version = ''; |
| 2287 |
$current_version = WDKIT_VERSION; |
| 2288 |
$response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/wdesignkit.json' ); |
| 2289 |
|
| 2290 |
if ( is_wp_error( $response ) ) { |
| 2291 |
return false; |
| 2292 |
} |
| 2293 |
|
| 2294 |
$body = wp_remote_retrieve_body( $response ); |
| 2295 |
$data = json_decode( $body ); |
| 2296 |
|
| 2297 |
if ( isset( $data->version ) ) { |
| 2298 |
$new_version = $data->version; |
| 2299 |
} |
| 2300 |
|
| 2301 |
$version_check = array(); |
| 2302 |
|
| 2303 |
if ( $new_version && version_compare( $current_version, $new_version, '<' ) ) { |
| 2304 |
$version_check['success'] = true; |
| 2305 |
$version_check['version'] = $new_version; |
| 2306 |
} else { |
| 2307 |
$version_check['success'] = false; |
| 2308 |
$version_check['version'] = $new_version; |
| 2309 |
} |
| 2310 |
|
| 2311 |
$get_setting = get_option( 'wkit_settings_panel', false ); |
| 2312 |
|
| 2313 |
$setting_data = array( |
| 2314 |
'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true, |
| 2315 |
'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true, |
| 2316 |
'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true, |
| 2317 |
'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true, |
| 2318 |
'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false, |
| 2319 |
'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true, |
| 2320 |
'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true, |
| 2321 |
'plugin_version' => $version_check |
| 2322 |
); |
| 2323 |
|
| 2324 |
if(isset( $get_setting['remove_db'] )){ |
| 2325 |
$setting_data['remove_db'] = $get_setting['remove_db']; |
| 2326 |
} |
| 2327 |
|
| 2328 |
if(isset( $get_setting['debugger_mode'] )){ |
| 2329 |
$setting_data['debugger_mode'] = $get_setting['debugger_mode']; |
| 2330 |
} |
| 2331 |
|
| 2332 |
return $setting_data; |
| 2333 |
} |
| 2334 |
|
| 2335 |
/** |
| 2336 |
* Updated White Label Data. |
| 2337 |
* |
| 2338 |
* @since 1.1.8 |
| 2339 |
*/ |
| 2340 |
protected function wkit_white_label() { |
| 2341 |
|
| 2342 |
$get_wl_data = !empty( $_POST['WhiteLabelData'] ) ? wp_unslash( $_POST['WhiteLabelData'] ) : array(); |
| 2343 |
|
| 2344 |
if ( !empty( $get_wl_data ) ) { |
| 2345 |
$white_label_data = json_decode($get_wl_data, true); |
| 2346 |
$plugin_name = $white_label_data['plugin_name']; |
| 2347 |
}else{ |
| 2348 |
$result = array( |
| 2349 |
'success' => false, |
| 2350 |
'message' => esc_html__('Data Not Found', 'wdesignkit'), |
| 2351 |
); |
| 2352 |
|
| 2353 |
wp_send_json( $result ); |
| 2354 |
wp_die(); |
| 2355 |
} |
| 2356 |
|
| 2357 |
if (!empty($plugin_name)) { |
| 2358 |
$get_white_label = get_option('wkit_white_label', false); |
| 2359 |
if (!empty($get_white_label)) { |
| 2360 |
update_option( 'wkit_white_label', $white_label_data ); |
| 2361 |
}else{ |
| 2362 |
add_option( 'wkit_white_label', $white_label_data ); |
| 2363 |
} |
| 2364 |
}else{ |
| 2365 |
$result = array( |
| 2366 |
'success' => false, |
| 2367 |
'message' => esc_html__('Plugin Name Not Found', 'wdesignkit'), |
| 2368 |
); |
| 2369 |
|
| 2370 |
wp_send_json( $result ); |
| 2371 |
wp_die(); |
| 2372 |
} |
| 2373 |
|
| 2374 |
$get_updated_data = get_option('wkit_white_label', false); |
| 2375 |
$response = array( |
| 2376 |
'message' => 'Data Added successfully', |
| 2377 |
'success' => true, |
| 2378 |
'data' => $get_updated_data, |
| 2379 |
); |
| 2380 |
|
| 2381 |
wp_send_json( $response ); |
| 2382 |
} |
| 2383 |
|
| 2384 |
/** |
| 2385 |
* Reset White Label Data. |
| 2386 |
* |
| 2387 |
* @since 1.1.8 |
| 2388 |
*/ |
| 2389 |
public function wkit_reset_wl() { |
| 2390 |
$wl_data = get_option('wkit_white_label'); |
| 2391 |
|
| 2392 |
if ( !empty( $wl_data ) ) { |
| 2393 |
delete_option('wkit_white_label'); |
| 2394 |
|
| 2395 |
$result = array( |
| 2396 |
'success' => true, |
| 2397 |
'message' => esc_html__('Reset White Label Successfully', 'wdesignkit'), |
| 2398 |
); |
| 2399 |
|
| 2400 |
wp_send_json( $result ); |
| 2401 |
wp_die(); |
| 2402 |
} |
| 2403 |
} |
| 2404 |
|
| 2405 |
/** |
| 2406 |
* |
| 2407 |
* Use for Add new licence key. |
| 2408 |
* |
| 2409 |
* @since 1.0.0 |
| 2410 |
*/ |
| 2411 |
protected function wdkit_activate_licence() { |
| 2412 |
$args = array( |
| 2413 |
'token' => ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', |
| 2414 |
'licencekey' => ! empty( $_POST['licencekey'] ) ? sanitize_text_field( wp_unslash( $_POST['licencekey'] ) ) : '', |
| 2415 |
'licencename' => ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '', |
| 2416 |
'uichemyid' => ! empty( $_POST['uichemyid'] ) ? sanitize_text_field( wp_unslash( $_POST['uichemyid'] ) ) : '', |
| 2417 |
); |
| 2418 |
|
| 2419 |
$response = $this->wkit_api_call( $args, 'wkit_activate_key' ); |
| 2420 |
|
| 2421 |
wp_send_json( $response['data'] ); |
| 2422 |
wp_die(); |
| 2423 |
} |
| 2424 |
|
| 2425 |
/** |
| 2426 |
* |
| 2427 |
* Use for Delete licence key. |
| 2428 |
* |
| 2429 |
* @since 1.0.0 |
| 2430 |
*/ |
| 2431 |
protected function wdkit_delete_licence_key() { |
| 2432 |
$token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; |
| 2433 |
$licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : ''; |
| 2434 |
$apikey = ! empty( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : ''; |
| 2435 |
|
| 2436 |
$args = array( |
| 2437 |
'token' => $token, |
| 2438 |
'licencename' => $licencename, |
| 2439 |
'apikey' => $apikey, |
| 2440 |
); |
| 2441 |
|
| 2442 |
$response = $this->wkit_api_call( $args, 'licence_delete' ); |
| 2443 |
|
| 2444 |
wp_send_json( $response['data'] ); |
| 2445 |
wp_die(); |
| 2446 |
} |
| 2447 |
|
| 2448 |
/** |
| 2449 |
* |
| 2450 |
* Use for Sync licence key. |
| 2451 |
* |
| 2452 |
* @since 1.0.0 |
| 2453 |
*/ |
| 2454 |
protected function wdkit_sync_licence_key() { |
| 2455 |
$token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; |
| 2456 |
$licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : ''; |
| 2457 |
|
| 2458 |
$args = array( |
| 2459 |
'token' => $token, |
| 2460 |
'licencename' => $licencename, |
| 2461 |
); |
| 2462 |
|
| 2463 |
$response = $this->wkit_api_call( $args, 'licence_sync' ); |
| 2464 |
|
| 2465 |
wp_send_json( $response['data'] ); |
| 2466 |
wp_die(); |
| 2467 |
} |
| 2468 |
|
| 2469 |
/** |
| 2470 |
* Rollback to Previous Versions |
| 2471 |
* |
| 2472 |
* @since 1.1.0 |
| 2473 |
*/ |
| 2474 |
protected function wdkit_prev_version() { |
| 2475 |
|
| 2476 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 2477 |
|
| 2478 |
$plugin_info = plugins_api( |
| 2479 |
'plugin_information', |
| 2480 |
array( |
| 2481 |
'slug' => 'wdesignkit', |
| 2482 |
) |
| 2483 |
); |
| 2484 |
|
| 2485 |
if ( empty( $plugin_info->versions ) || ! is_array( $plugin_info->versions ) ) { |
| 2486 |
return array(); |
| 2487 |
} |
| 2488 |
|
| 2489 |
krsort( $plugin_info->versions ); |
| 2490 |
|
| 2491 |
$versions_list = array(); |
| 2492 |
$index = 0; |
| 2493 |
|
| 2494 |
foreach ( $plugin_info->versions as $version => $download_link ) { |
| 2495 |
|
| 2496 |
$lowercase_version = strtolower( $version ); |
| 2497 |
|
| 2498 |
$is_valid_version = ! preg_match( '/(beta|rc|trunk|dev)/i', $lowercase_version ); |
| 2499 |
|
| 2500 |
$is_valid_version = apply_filters( 'wdkit_check_rollback_version', $is_valid_version, $lowercase_version ); |
| 2501 |
|
| 2502 |
if ( ! $is_valid_version || version_compare( $version, WDKIT_VERSION, '>=' ) ) { |
| 2503 |
continue; |
| 2504 |
} |
| 2505 |
|
| 2506 |
$versions_list[] = $version; |
| 2507 |
++$index; |
| 2508 |
} |
| 2509 |
|
| 2510 |
// set_transient( 'wdkit_rollback_version_' . WDKIT_VERSION, $versions_list, WEEK_IN_SECONDS ); |
| 2511 |
|
| 2512 |
return $versions_list; |
| 2513 |
} |
| 2514 |
|
| 2515 |
/** |
| 2516 |
* Rollback to Previous Versions |
| 2517 |
* |
| 2518 |
* @since 1.1.0 |
| 2519 |
*/ |
| 2520 |
protected function wdkit_rollback_check() { |
| 2521 |
|
| 2522 |
$current_ver = isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : ''; |
| 2523 |
$rv = $this->wdkit_prev_version(); |
| 2524 |
|
| 2525 |
if ( empty( $current_ver ) || ! in_array( $current_ver, $rv) ) { |
| 2526 |
return array( |
| 2527 |
'message' => esc_html__( 'Invalid Nonce or version not found', 'wdesignkit' ), |
| 2528 |
'status' => 'error', |
| 2529 |
'success' => false, |
| 2530 |
); |
| 2531 |
} |
| 2532 |
|
| 2533 |
$plugin_slug = basename( WDKIT_PBNAME, '.php' ); |
| 2534 |
|
| 2535 |
$this_version = $current_ver; |
| 2536 |
$this_pluginname = WDKIT_PBNAME; |
| 2537 |
$this_plugin_u_r_l = sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $this_version ); |
| 2538 |
|
| 2539 |
$plugin_info = new \stdClass(); |
| 2540 |
$plugin_info->new_version = $this_version; |
| 2541 |
$plugin_info->slug = $plugin_slug; |
| 2542 |
$plugin_info->package = $this_plugin_u_r_l; |
| 2543 |
$plugin_info->url = 'https://wdesignkit.com/'; |
| 2544 |
|
| 2545 |
$update_plugins_data = get_site_transient( 'update_plugins' ); |
| 2546 |
|
| 2547 |
if ( ! is_object( $update_plugins_data ) ) { |
| 2548 |
$update_plugins_data = new \stdClass(); |
| 2549 |
} |
| 2550 |
|
| 2551 |
$update_plugins_data->response[ $this_pluginname ] = $plugin_info; |
| 2552 |
|
| 2553 |
set_site_transient( 'update_plugins', $update_plugins_data ); |
| 2554 |
|
| 2555 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 2556 |
|
| 2557 |
$logo_url = WDKIT_URL . 'assets/images/jpg/Wdesignkit-logo.png'; |
| 2558 |
|
| 2559 |
$args = array( |
| 2560 |
'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this_pluginname ), |
| 2561 |
'plugin' => $this_pluginname, |
| 2562 |
'nonce' => 'upgrade-plugin_' . $this_pluginname, |
| 2563 |
'title' => '<img src="' . esc_url( $logo_url ) . '" alt="wdesignkit-logo"><div class="theplus-rb-subtitle">' . esc_html__( 'Rollback to Previous Version', 'wdesignkit' ) . '</div>', |
| 2564 |
); |
| 2565 |
|
| 2566 |
$upgrader_plugin = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $args ) ); |
| 2567 |
$upgrader_plugin->upgrade( $this_pluginname ); |
| 2568 |
|
| 2569 |
activate_plugin( $this_pluginname ); |
| 2570 |
|
| 2571 |
return array( |
| 2572 |
'message' => esc_html__( 'Rollback Successful, Plugin Re-activated', 'wdesignkit' ), |
| 2573 |
'status' => 'Success', |
| 2574 |
'success' => true, |
| 2575 |
); |
| 2576 |
} |
| 2577 |
|
| 2578 |
/** |
| 2579 |
* |
| 2580 |
* It is Use for logout. |
| 2581 |
* |
| 2582 |
* @since 1.0.0 |
| 2583 |
*/ |
| 2584 |
protected function wdkit_logout() { |
| 2585 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 2586 |
$logout_type = isset( $_POST['logout_type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['logout_type'] ) ) ) : ''; |
| 2587 |
|
| 2588 |
$response = ''; |
| 2589 |
|
| 2590 |
if ( ! empty( $email ) ) { |
| 2591 |
$token = $this->wdkit_login_user_token( $email ); |
| 2592 |
$args = array( 'token' => $token ); |
| 2593 |
|
| 2594 |
if ( 'session' !== $logout_type ) { |
| 2595 |
delete_transient( 'wdkit_auth_' . $email ); |
| 2596 |
$response = WDesignKit_Data_Query::get_data( 'logout', $args ); |
| 2597 |
} |
| 2598 |
} |
| 2599 |
|
| 2600 |
wp_send_json( $response ); |
| 2601 |
wp_die(); |
| 2602 |
} |
| 2603 |
|
| 2604 |
/** |
| 2605 |
* |
| 2606 |
* It is Use for get token of login user. |
| 2607 |
* |
| 2608 |
* @since 1.0.0 |
| 2609 |
* |
| 2610 |
* @param string $email check user email. |
| 2611 |
*/ |
| 2612 |
protected function wdkit_login_user_token( $email = '' ) { |
| 2613 |
|
| 2614 |
if ( ! empty( $email ) ) { |
| 2615 |
$user_key = strstr( $email, '@', true ); |
| 2616 |
$get_login = get_transient( 'wdkit_auth_' . $user_key ); |
| 2617 |
|
| 2618 |
if ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) { |
| 2619 |
return $get_login['token']; |
| 2620 |
} |
| 2621 |
} |
| 2622 |
|
| 2623 |
return false; |
| 2624 |
} |
| 2625 |
|
| 2626 |
/** |
| 2627 |
* Parse args $_POST |
| 2628 |
* |
| 2629 |
* @since 1.0.0 |
| 2630 |
* |
| 2631 |
* @param string $data send all post data. |
| 2632 |
* @param string $type store text data. |
| 2633 |
* @param string $condition store text data. |
| 2634 |
*/ |
| 2635 |
protected function wdkit_sanitizer_bypass( $data, $type, $condition = 'none' ) { |
| 2636 |
|
| 2637 |
if ( 'none' === $condition ) { |
| 2638 |
return $data[ $type ]; |
| 2639 |
} elseif ( 'cr_widget' === $condition ) { |
| 2640 |
return $data[ $type ]; |
| 2641 |
} |
| 2642 |
} |
| 2643 |
|
| 2644 |
|
| 2645 |
/** |
| 2646 |
* Parse args $_POST |
| 2647 |
* |
| 2648 |
* @since 1.0.0 |
| 2649 |
* |
| 2650 |
* @param string $data send all post data. |
| 2651 |
*/ |
| 2652 |
protected function wdkit_parse_args( $data = array() ) { |
| 2653 |
if ( empty( $data ) ) { |
| 2654 |
return array(); |
| 2655 |
} |
| 2656 |
|
| 2657 |
$args = array(); |
| 2658 |
if ( isset( $data['email'] ) ) { |
| 2659 |
$args['email'] = isset( $data['email'] ) ? sanitize_email( $data['email'] ) : ''; |
| 2660 |
} |
| 2661 |
|
| 2662 |
if ( isset( $data['data'] ) ) { |
| 2663 |
$args['data'] = isset( $data['data'] ) ? wp_unslash( $data['data'] ) : array(); |
| 2664 |
} |
| 2665 |
|
| 2666 |
if ( isset( $data['plugins'] ) ) { |
| 2667 |
$args['plugins'] = isset( $data['plugins'] ) ? wp_unslash( $data['plugins'] ) : array(); |
| 2668 |
} |
| 2669 |
|
| 2670 |
if ( isset( $data['template_id'] ) ) { |
| 2671 |
$args['template_id'] = isset( $data['template_id'] ) ? intval( strtolower( sanitize_text_field( $data['template_id'] ) ) ) : ''; |
| 2672 |
} |
| 2673 |
|
| 2674 |
if ( isset( $data['builder'] ) ) { |
| 2675 |
$args['builder'] = isset( $data['builder'] ) ? wp_unslash( $data['builder'] ) : ''; |
| 2676 |
} |
| 2677 |
|
| 2678 |
if ( isset( $data['editor'] ) ) { |
| 2679 |
$args['editor'] = isset( $data['editor'] ) ? sanitize_text_field( $data['editor'] ) : ''; |
| 2680 |
} |
| 2681 |
|
| 2682 |
if ( isset( $data['type_upload'] ) ) { |
| 2683 |
$args['type_upload'] = isset( $data['type_upload'] ) ? sanitize_text_field( $data['type_upload'] ) : ''; |
| 2684 |
} |
| 2685 |
|
| 2686 |
if ( isset( $data['title'] ) ) { |
| 2687 |
$args['title'] = isset( $data['title'] ) ? wp_strip_all_tags( $data['title'] ) : ''; |
| 2688 |
} |
| 2689 |
|
| 2690 |
if ( isset( $data['template_type'] ) ) { |
| 2691 |
$args['template_type'] = isset( $data['template_type'] ) ? sanitize_text_field( $data['template_type'] ) : ''; |
| 2692 |
} |
| 2693 |
|
| 2694 |
if ( isset( $data['wstype'] ) ) { |
| 2695 |
$args['wstype'] = isset( $data['wstype'] ) ? wp_strip_all_tags( $data['wstype'] ) : ''; |
| 2696 |
} |
| 2697 |
|
| 2698 |
if ( isset( $data['wid'] ) ) { |
| 2699 |
$args['wid'] = isset( $data['wid'] ) ? intval( strtolower( sanitize_text_field( $data['wid'] ) ) ) : ''; |
| 2700 |
} |
| 2701 |
|
| 2702 |
if ( isset( $data['perpage'] ) ) { |
| 2703 |
$args['perpage'] = isset( $data['perpage'] ) ? intval( strtolower( sanitize_text_field( $data['perpage'] ) ) ) : 12; |
| 2704 |
} |
| 2705 |
|
| 2706 |
if ( isset( $data['page'] ) ) { |
| 2707 |
$args['page'] = isset( $data['page'] ) ? intval( strtolower( sanitize_text_field( $data['page'] ) ) ) : 1; |
| 2708 |
} |
| 2709 |
|
| 2710 |
if ( isset( $data['buildertype'] ) ) { |
| 2711 |
$args['buildertype'] = isset( $data['buildertype'] ) ? sanitize_text_field( $data['buildertype'] ) : ''; |
| 2712 |
} |
| 2713 |
|
| 2714 |
if ( isset( $data['search'] ) ) { |
| 2715 |
$args['search'] = isset( $data['search'] ) ? sanitize_text_field( $data['search'] ) : ''; |
| 2716 |
} |
| 2717 |
|
| 2718 |
if ( isset( $data['plugin'] ) ) { |
| 2719 |
$args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array(); |
| 2720 |
} |
| 2721 |
|
| 2722 |
if ( isset( $data['tag'] ) ) { |
| 2723 |
$args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array(); |
| 2724 |
} |
| 2725 |
|
| 2726 |
if ( isset( $data['category'] ) ) { |
| 2727 |
$args['category'] = isset( $data['category'] ) ? wp_unslash( $data['category'] ) : array(); |
| 2728 |
} |
| 2729 |
|
| 2730 |
if ( isset( $data['free_pro'] ) ) { |
| 2731 |
$args['free_pro'] = isset( $data['free_pro'] ) ? sanitize_text_field( wp_unslash( $data['free_pro'] ) ) : ''; |
| 2732 |
} |
| 2733 |
|
| 2734 |
if ( isset( $data['wp_post_type'] ) ) { |
| 2735 |
$args['wp_post_type'] = isset( $data['wp_post_type'] ) ? sanitize_text_field( wp_unslash( $data['wp_post_type'] ) ) : ''; |
| 2736 |
} |
| 2737 |
|
| 2738 |
if ( isset( $data['favorite'] ) ) { |
| 2739 |
$args['favorite'] = isset( $data['favorite'] ) ? sanitize_text_field( wp_unslash( $data['favorite'] ) ) : ''; |
| 2740 |
} |
| 2741 |
|
| 2742 |
if ( isset( $data['content'] ) ) { |
| 2743 |
$args['content'] = isset( $data['content'] ) ? wp_unslash( $data['content'] ) : ''; |
| 2744 |
} |
| 2745 |
|
| 2746 |
if ( isset( $data['page_type'] ) ) { |
| 2747 |
$args['page_type'] = isset( $data['page_type'] ) ? wp_unslash( $data['page_type'] ) : array(); |
| 2748 |
} |
| 2749 |
|
| 2750 |
return $args; |
| 2751 |
} |
| 2752 |
} |
| 2753 |
|
| 2754 |
Wdkit_Api_Call::get_instance(); |
| 2755 |
} |