falsy skips the "-scaled" copy (needs a full decode) * intermediate_image_sizes_advanced -> empty makes _wp_make_subsizes() return early, * ahead of its wp_get_image_editor() call * * The original file is still attached and usable; only the derived sizes are skipped. * That trades ideal thumbnails for an import that completes, instead of a fatal that * takes the whole page down and repeats on every retry. * * @since 2.6.2 */ private static function wdkit_guard_oversized_images() { static $registered = false; // Registering twice would stack duplicate closures on both filters. if ( $registered ) { return; } $registered = true; if ( ! class_exists( 'Wdkit_Image_Guard' ) ) { require_once WDKIT_INCLUDES . 'admin/class-wdkit-image-guard.php'; } add_filter( 'big_image_size_threshold', function ( $threshold, $imagesize = array(), $file = '', $attachment_id = 0 ) { if ( ! empty( $imagesize[0] ) && ! empty( $imagesize[1] ) && ! Wdkit_Image_Guard::decode_fits( $imagesize[0], $imagesize[1], self::wdkit_available_image_memory() ) ) { return false; } return $threshold; }, 99, 4 ); add_filter( 'intermediate_image_sizes_advanced', function ( $sizes, $image_meta = array(), $attachment_id = 0 ) { if ( ! empty( $image_meta['width'] ) && ! empty( $image_meta['height'] ) && ! Wdkit_Image_Guard::decode_fits( $image_meta['width'], $image_meta['height'], self::wdkit_available_image_memory() ) ) { return array(); } return $sizes; }, 99, 3 ); } /** * Get Wdkit Api Call Ajax. */ public function wdkit_api_call() { check_ajax_referer( 'wdkit_nonce', 'kit_nonce' ); if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'content' => __( 'Insufficient permissions.', 'wdesignkit' ) ) ); } $type = isset( $_POST['type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['type'] ) ) ) : false; if ( ! $type ) { $this->wdkit_error_msg( __( 'Something went wrong.', 'wdesignkit' ) ); } switch ( $type ) { case 'onboarding_handler': $data = $this->wdkit_onboarding_handler(); break; case 'wkit_login': $data = apply_filters( 'wp_wdkit_login_ajax', 'wkit_login' ); break; case 'api_login': $data = apply_filters( 'wp_wdkit_login_ajax', 'api_login' ); break; case 'social_login': $data = apply_filters( 'wp_wdkit_login_ajax', 'social_login' ); break; case 'forgot_password': $data = apply_filters( 'wp_wdkit_login_ajax', 'forgot_password' ); break; case 'wdkit_user_signup': $data = apply_filters( 'wp_wdkit_login_ajax', 'wdkit_user_signup' ); break; case 'wkit_meta_data': $data = $this->wdkit_meta_data(); break; case 'get_user_info': $data = $this->wdkit_get_user_info(); break; case 'browse_page': $data = $this->wdkit_browse_page(); break; case 'kit_template': $data = $this->wdkit_template(); break; case 'wkit_preset_template': $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_template' ); break; case 'wdkit_preset_dwnld_template': $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_dwnld_template' ); break; case 'template_remove': $data = $this->wdkit_template_remove(); break; case 'save_template': $data = $this->wdkit_put_save_template(); break; case 'update_save_temp_image': $data = $this->wdkit_update_save_temp_image(); break; case 'save_wp_images': $data = $this->wdkit_save_wp_images(); break; case 'get_global_val': $data = $this->wdkit_get_global_val(); break; case 'update_global_val': $data = $this->wdkit_update_global_val(); break; case 'wdkit_get_site_setting': $data = $this->wdkit_get_site_setting(); break; case 'wdkit_update_site_setting': $data = $this->wdkit_update_site_setting(); break; case 'update_preset_setting': $data = $this->wdkit_update_preset(); break; case 'find_template': $data = $this->wdkit_find_existing_template(); break; case 'update_template': $data = $this->wdkit_update_template(); break; case 'manage_favorite': $data = $this->wdkit_manage_favorite(); break; case 'check_plugins_depends': $data = $this->wdkit_check_plugins_depends(); break; case 'install_plugins_depends': $data = $this->wdkit_install_plugins_depends(); break; case 'generate_site_logo': $data = $this->wkit_generate_site_logo(); break; case 'generate_ai_content': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'generate_ai_content' ); break; case 'generate_ai_content_batch': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'generate_ai_content_batch' ); break; case 'reset_site': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'reset_site' ); break; case 'wdkit_nxt_thembuilder_reset': $data = $this->wdkit_nxt_thembuilder_reset(); break; case 'wdkit_check_user_credit': $data = $this->wdkit_check_user_credit(); break; case 'wdkit_remove_header_footer': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wdkit_remove_header_footer' ); break; case 'check_post_count': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'check_post_count' ); break; case 'wkit_check_product_count': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_check_product_count' ); break; case 'select_team_img': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'select_team_img' ); break; case 'wkit_ai_desc_keyword': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_ai_desc_keyword' ); break; case 'wkit_ai_credit_update': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_ai_credit_update' ); break; case 'wkit_generate_post_data': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_generate_post_data' ); break; case 'wkit_generate_product_data': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_generate_product_data' ); break; case 'wkit_cteate_product': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_cteate_product' ); break; case 'wkit_remove_dummy_post': $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_remove_dummy_post' ); break; case 'update_latest_plugin': $data = $this->wdkit_update_latest_plugin(); break; case 'activate_container': $data = $this->wdkit_activate_container(); break; case 'import_taxonomy': $data = $this->wdkit_import_taxonomy(); break; case 'import_template': $data = $this->wdkit_import_template(); break; case 'import_multi_template': $data = $this->wdkit_import_multi_template(); break; case 'import_page_section': $data = $this->import_page_section_content(); break; case 'wkit_update_elementor_template': $data = $this->wkit_update_elementor_template(); break; case 'wdkit_update_page_content': $data = $this->wdkit_update_page_content(); break; case 'update_plugin_setting': $data = $this->update_plugin_setting(); break; case 'update_theme_setting': $data = $this->update_theme_setting(); break; case 'update_site_setting': $data = $this->update_site_setting(); break; case 'import_kit_template': $data = $this->wdkit_import_kit_template(); break; case 'enable_template_widgets': $data = $this->wdkit_enable_template_widgets(); break; case 'scan_nexter_widgets': if ( ! empty( $_POST['blockNames'] ) && has_filter( 'nexter_block_list_merge' ) ) { $posted_blocks = json_decode( stripslashes( $_POST['blockNames'] ), true ); if ( is_array( $posted_blocks ) ) { $blockList = array_map( 'sanitize_text_field', $posted_blocks ); // अब filter call करो $result = apply_filters( 'nexter_block_list_merge', $blockList ); wp_send_json( $result ); wp_die(); } } wp_send_json( array( 'success' => false, 'message' => __( 'No block names received or filter not found.', 'wdesignkit' ), 'description' => 'Ensure blockNames are posted and the filter is attached.', ) ); wp_die(); $data = ''; break; case 'shared_with_me': $data = $this->wdkit_shared_with_me(); break; case 'manage_workspace': $data = $this->wdkit_manage_workspace(); break; case 'widget_browse_page': $data = apply_filters( 'wp_wdkit_widget_ajax', 'widget_browse_page' ); break; case 'wkit_create_widget': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_create_widget' ); break; case 'wkit_import_widget': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_import_widget' ); break; case 'wkit_export_widget': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_export_widget' ); break; case 'wkit_delete_widget': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_delete_widget' ); break; case 'wkit_widget_preview': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_widget_preview' ); break; case 'wkit_check_widget_versions': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_check_widget_versions' ); break; case 'wkit_plugin_download_get': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_plugin_download_get' ); break; case 'wkit_manage_widget_workspace': $data = $this->wdkit_manage_widget_workspace(); break; case 'wkit_activate_key': $data = $this->wdkit_activate_key(); break; case 'wkit_manage_widget_category': $data = $this->wdkit_manage_widget_category(); break; case 'wkit_widget_json': $data = $this->wkit_widget_json(); break; case 'wkit_download_widget': $data = $this->wdkit_download_widget(); break; case 'wkit_public_download_widget': $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_public_download_widget' ); break; case 'wkit_add_widget': $data = $this->wdkit_add_widget(); break; case 'wkit_favourite_widget': $data = $this->wdkit_favourite_widget(); break; case 'wkit_setting_panel': $data = $this->wdkit_setting_panel(); break; case 'media_import': $data = $this->wdkit_media_import(); break; case 'active_licence': $data = $this->wdkit_activate_licence(); break; case 'delete_licence': $data = $this->wdkit_delete_licence_key(); break; case 'sync_licence': $data = $this->wdkit_sync_licence_key(); break; case 'get_wkit_version': $data = $this->wdkit_prev_version(); break; case 'rollback_wdkit': $data = $this->wdkit_rollback_check(); break; case 'wkit_logout': $data = $this->wdkit_logout(); break; case 'wkit_white_label': $this->wkit_white_label(); break; case 'wkit_reset_wl': $data = $this->wkit_reset_wl(); break; case 'wdkit_dark_mode': $data = $this->wdkit_dark_mode(); break; case 'wdkit_get_workspace_data': $data = $this->wdkit_get_workspace_data(); break; default: $this->wdkit_error_msg( __( 'Unknown request type.', 'wdesignkit' ) ); return; } $this->wdkit_success_msg( $data ); // wp_die(); } /** * * This Function is used for API call * * @since 1.0.0 * * @param array $data give array. * @param array $name store data. * @param int $timeout optional HTTP timeout in seconds. Default 100. */ protected function wkit_api_call( $data, $name, $timeout = 100 ) { $u_r_l = $this->wdkit_api; if ( empty( $u_r_l ) ) { return array( 'massage' => esc_html__( 'API Not Found', 'wdesignkit' ), 'success' => false, ); } $args = array( 'method' => 'POST', 'body' => $data, 'timeout' => $timeout, ); $response = wp_remote_post( $u_r_l . $name, $args ); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); /* Translators: %s is a placeholder for the error message */ $error_message = sprintf( esc_html__( 'API request error: %s', 'wdesignkit' ), esc_html( $error_message ) ); return array( 'massage' => $error_message, 'success' => false, ); } $status_code = wp_remote_retrieve_response_code( $response ); if ( 200 === $status_code ) { return array( 'data' => json_decode( wp_remote_retrieve_body( $response ) ), 'massage' => esc_html__( 'Success', 'wdesignkit' ), 'status' => $status_code, 'success' => true, ); } $error_message = sprintf( 'Server error: %d', esc_html( $status_code ) ); if ( isset( $error_data->message ) ) { $error_message .= ' (' . $error_data->message . ')'; } return array( 'massage' => $error_message, 'status' => $status_code, 'success' => false, ); } /** * * It is Use for handle onboarding data. * * @since 1.0.9 */ public function wdkit_onboarding_handler() { $page_template = isset( $_POST['page_template'] ) ? json_decode( wp_unslash( $_POST['page_template'] ), true ) : ''; $page_builder = isset( $_POST['page_builder'] ) ? json_decode( wp_unslash( $_POST['page_builder'] ), true ) : ''; $elementor_plugin = isset( $_POST['elementor_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['elementor_plugin'] ) ) : 0; $tpag_plugin = isset( $_POST['tpag_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['tpag_plugin'] ) ) : 0; $bricks_theme = isset( $_POST['bricks_theme'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['bricks_theme'] ) ) : 0; $site_info = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : false; $server_software = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : ''; $web_server = $server_software; $memory_limit = ini_get( 'memory_limit' ); $max_execution_time = ini_get( 'max_execution_time' ); $php_version = phpversion(); $wp_version = get_bloginfo( 'version' ); $email = get_option( 'admin_email' ); $siteurl = get_option( 'siteurl' ); $language = get_bloginfo( 'language' ); // Active Plugin Name. $act_plugin = array(); $actplu = get_option( 'active_plugins' ); if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugins = get_plugins(); foreach ( $actplu as $p ) { if ( isset( $plugins[ $p ] ) ) { $act_plugin[] = $plugins[ $p ]['Name']; } } $plugin = wp_json_encode( $act_plugin ); $theme = ''; $acthemeobj = wp_get_theme(); if ( $acthemeobj->get( 'Name' ) !== null && ! empty( $acthemeobj->get( 'Name' ) ) ) { $theme = $acthemeobj->get( 'Name' ); } $basic_requirements = array( 'elementor_install' => $elementor_plugin, 'tpag_install' => $tpag_plugin, 'bricks_install' => $bricks_theme, ); if ( ! empty( $site_info ) ) { $final = array( 'web_server' => $web_server, 'memory_limit' => $memory_limit, 'max_execution_time' => $max_execution_time, 'php_version' => $php_version, 'wp_version' => $wp_version, 'email' => $email, 'site_url' => $siteurl, 'site_language' => $language, 'theme' => $theme, 'plugins' => $act_plugin, 'basic_requirements' => $basic_requirements, 'page_template' => $page_template, 'page_builder' => $page_builder, ); } else { $final = array(); } $response = wp_remote_post( $this->wdkit_onbording_api, array( 'method' => 'POST', 'body' => wp_json_encode( $final ), ) ); $existing_value = get_option( $this->wdkit_onbording_end ); if ( false === $existing_value ) { add_option( $this->wdkit_onbording_end, true ); } if ( is_wp_error( $response ) ) { $result = array( 'success' => false, 'messages' => 'Oops', 'description' => 'Description', ); wp_send_json( $result ); } else { $status_one = wp_remote_retrieve_response_code( $response ); if ( 200 === $status_one ) { $get_data_one = wp_remote_retrieve_body( $response ); $get_res = json_decode( json_decode( $get_data_one, true ), true ); $result = array( 'success' => ! empty( $get_res['success'] ) ? $get_res['success'] : false, 'messages' => ! empty( $get_res['messages'] ) ? $get_res['messages'] : 'success', 'description' => ! empty( $get_res['description'] ) ? $get_res['description'] : 'Description', ); wp_send_json( $result ); } else { $result = array( 'success' => false, 'messages' => 'Oops', 'description' => 'description', ); wp_send_json( $result ); } } wp_die(); } /** * * It is Use for get meta data for non login user * * @since 1.0.0 */ protected function wdkit_meta_data() { $type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : ''; $data = array( 'type' => $type ); $response = $this->wkit_api_call( $data, 'meta' ); $success = ! empty( $response['success'] ) ? $response['success'] : false; $status = ! empty( $response['status'] ) ? (int) $response['status'] : 400; if ( empty( $success ) ) { $result = array( 'plugin' => array(), 'builder' => array(), 'category' => array(), 'widgetscategory' => array(), 'tags' => array(), 'widgetbuilder' => array(), 'message' => esc_html__( 'Server Error', 'wdesignkit' ), 'description' => esc_html__( 'Server Error, Data Not Found', 'wdesignkit' ), 'success' => false, ); wp_send_json( $result ); wp_die(); } $get_data_one = ! empty( $response['data'] ) ? $response['data'] : array(); $statuscode = array( 'HTTP_CODE' => $status ); $final = json_decode( wp_json_encode( $get_data_one ), true ); $final['Setting'] = self::wkit_get_settings_panel(); $final['widget_list'] = $this->wkit_manage_widget_sequence( array() ); $final = array( 'data' => $final, ); wp_send_json( $final ); wp_die(); } /** * * It is Use for get activate license key data from tpae and nexter blocks. * * @since 1.1.6 */ protected function wkit_manage_license_data() { $manage_licence = array(); $theplus_active_check = is_plugin_active( 'the-plus-addons-for-elementor-page-builder/theplus_elementor_addon.php' ); $nexter_active_check = is_plugin_active( 'the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php' ); $theplus_licence = get_option( 'tpaep_licence_data', array() ); // Also require the TPAE Pro plugin to be active (Pro defines THEPLUS_VERSION; // the free plugin defines L_THEPLUS_VERSION). This hides the "found active // key" notice when the Pro plugin is removed even though its licence option // still lingers in the database. if ( ! empty( $theplus_active_check ) && defined( 'THEPLUS_VERSION' ) && ! empty( $theplus_licence ) ) { $manage_licence['tpae'] = $theplus_licence; } $nexter_licence = get_option( 'tpgb_activate', array() ); // Also require the Nexter Blocks Pro plugin to be active (Pro defines // TPGBP_VERSION; the free plugin defines TPGB_VERSION), so the notice hides // when the Pro plugin is removed but its licence option persists. if ( ! empty( $nexter_active_check ) && defined( 'TPGBP_VERSION' ) && ! empty( $nexter_licence ) && ! empty( $nexter_licence['tpgb_activate_key'] ) ) { $tpgb_license_status = get_option( 'tpgbp_license_status', array() ); $tpgb_license_status['license_key'] = $nexter_licence['tpgb_activate_key']; $manage_licence['tpag'] = $tpgb_license_status; } return $manage_licence; } /** * * It is Use for get all info of user. * * @since 1.0.0 */ protected function wdkit_get_user_info() { $token = isset( $_POST['token'] ) ? wp_unslash( $_POST['token'] ) : false; $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : ''; $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : ''; $response = array(); if ( empty( $token ) ) { $response = array( 'success' => false, 'message' => $this->e_msg_login, 'description' => $this->e_desc_login, ); wp_send_json( $response ); wp_die(); } // $token = $this->wdkit_login_user_token( $email ); $args = array( 'token' => $token, 'builder' => $builder, 'site_url' => $site_url, ); $response = WDesignKit_Data_Query::get_data( 'get_user_info', $args ); if ( is_wp_error( $response ) ) { wp_send_json( array( 'success' => false, 'message' => $response->get_error_message(), 'description' => $response->get_error_message(), ) ); wp_die(); } $status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error'; $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; /**Condtion user for user logout & expire token*/ if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) { delete_transient( 'wdkit_auth_' . wdesignkit_cloud_session_key( $email ) ); // Clear stored license data when token expires so banner shows again delete_option( 'wdkit_licence_data' ); } if ( empty( $response ) ) { $response['login_reset'] = 'yes'; } // Store WDesignKit license data locally if present in response if ( ! empty( $response['credits']['wdkit_licence'] ) && is_array( $response['credits']['wdkit_licence'] ) ) { $wdkit_licence = $response['credits']['wdkit_licence']; // Handle serialized data if ( is_string( $wdkit_licence ) && is_serialized( $wdkit_licence ) ) { $wdkit_licence = unserialize( $wdkit_licence, array( 'allowed_classes' => false ) ); } if ( ! empty( $wdkit_licence ) && is_array( $wdkit_licence ) ) { update_option( 'wdkit_licence_data', $wdkit_licence ); } } $response['Setting'] = $this->wkit_get_settings_panel(); $response['widget_list'] = $this->wkit_manage_widget_sequence( $response ); $response['manage_licence'] = $this->wkit_manage_license_data(); $response = array( 'data' => $response, 'success' => true, ); wp_send_json( $response ); wp_die(); } /** * * It is Use for get all widgets local and server. * * @since 1.0.19 * @param string $response userinfo store. */ protected function wkit_manage_widget_sequence( $response = array() ) { $credits = ! empty( $response['credits']['widget_limit']['meta_value'] ) ? $response['credits']['widget_limit']['meta_value'] : 10; $server_list = ! empty( $response['widgettemplate'] ) ? $response['widgettemplate'] : array(); $db_builder_list = ! empty( $response['widgetbuilder'] ) ? $response['widgetbuilder'] : array(); // Whether this call actually carried the server widget list that activation state is // derived from. Captured before the loops below, which unset() matched $server_list // entries as they go. wdkit_meta_data() calls this method with array(), and without // this flag that call rebuilt $db_widget from local widgets only — every one of which // is forced 'active' further down — and then wrote the empty result over // wkit_deactivate_widgets, erasing every deactivation the user had made. $has_server_widgets = ! empty( $server_list ); $placeholderimg = WDKIT_URL . 'assets/images/placeholder.jpg'; $local_list = $this->wdkit_get_local_widgets(); $server_w_unique = array_column( $server_list, 'w_unique' ); $idx_builder = array(); foreach ( $db_builder_list as $index => $value ) { $builder_name = ! empty( $value['builder_slug'] ) ? $value['builder_slug'] : ''; $w_id = ! empty( $value['w_id'] ) ? $value['w_id'] : ''; if ( ! empty( $builder_name ) ) { $idx_builder[ $w_id ] = strtolower( str_replace( ' ', '_', trim( $builder_name ) ) ); } } foreach ( $server_list as $index => $value ) { $get_id = $server_list[ $index ]['builder'] ? $server_list[ $index ]['builder'] : ''; $server_list[ $index ]['type'] = 'server'; $server_list[ $index ]['builder'] = ! empty( $idx_builder[ $get_id ] ) ? $idx_builder[ $get_id ] : ''; } $count = 0; foreach ( $local_list as $key => $value ) { $widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : ''; $allow_push = isset( $value['widgetdata']['allow_push'] ) ? $value['widgetdata']['allow_push'] : true; if ( in_array( $widget_id, $server_w_unique ) ) { $index = array_search( $widget_id, $server_w_unique ); $server_list[ $index ]['title'] = $local_list[ $key ]['widgetdata']['name']; $server_list[ $index ]['w_version'] = $local_list[ $key ]['widgetdata']['widget_version']; $server_list[ $index ]['allow_push'] = $allow_push; $server_list[ $index ]['builder'] = $local_list[ $key ]['widgetdata']['type']; $server_list[ $index ]['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id']; $server_list[ $index ]['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg; $local_list[ $key ] = $server_list[ $index ]; $local_list[ $key ]['type'] = 'done'; unset( $server_list[ $index ] ); } else { $local_list[ $key ]['widgetdata']['builder'] = $local_list[ $key ]['widgetdata']['type']; $local_list[ $key ]['widgetdata']['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id']; $local_list[ $key ]['widgetdata']['allow_push'] = $allow_push; $local_list[ $key ]['widgetdata']['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg; $local_list[ $key ]['widgetdata']['is_activated'] = 'active'; $local_list[ $key ]['widgetdata']['type'] = 'plugin'; $local_list[ $key ]['widgetdata']['title'] = $local_list[ $key ]['widgetdata']['name']; unset( $local_list[ $key ]['widgetdata']['name'] ); unset( $local_list[ $key ]['widgetdata']['widget_id'] ); $local_list[ $key ] = $local_list[ $key ]['widgetdata']; } } $final = array_merge( $local_list, $server_list ); $db_widget = array(); foreach ( $final as $key => $self ) { $is_activated = ! empty( $final[ $key ]['is_activated'] ) ? $final[ $key ]['is_activated'] : 'active'; if ( 'active' === $is_activated ) { ++$count; } if ( ( $count > $credits ) && ( 'unlimited' !== $credits ) ) { $final[ $key ]['is_activated'] = 'deactive'; } if ( ! empty( $self['is_activated'] ) && 'active' !== $self['is_activated'] ) { $db_widget[] = array( 'w_unique' => $self['w_unique'], 'builder' => $self['builder'], 'title' => $self['title'], 'is_activated' => $self['is_activated'], ); } } // Only persist activation state when the server list it is derived from was actually // supplied. See $has_server_widgets above. if ( $has_server_widgets ) { // update_option() creates the row when it is missing, so it covers both cases. // The previous add_option()/update_option() split was chosen on empty( $option ), // but wdkit_db_widgetlist() creates this row as an empty array on every install — // so the empty branch ran while the row already existed, and add_option() is a // no-op for an existing option. Deactivating from the My Widgets screen was // therefore silently discarded on effectively every site. Autoload stays 'yes', // matching the original add_option() call and wdkit_db_widgetlist(). update_option( 'wkit_deactivate_widgets', $db_widget, 'yes' ); // The cached widget registry bakes in wkit_deactivate_widgets membership and is // stored as a no-expiry transient, so it never self-heals. Without this the // loaders kept registering a widget the user had just switched off (and kept // hiding one they had switched back on) until the transient was flushed by hand. // The write above is not per-builder — one save can change any builder's set, and // a widget can move between builders — so clear all four. if ( function_exists( 'wdesignkit_invalidate_widget_registry' ) ) { foreach ( array( 'elementor', 'gutenberg', 'gutenberg_core', 'bricks' ) as $builder_slug ) { wdesignkit_invalidate_widget_registry( $builder_slug ); } } } return $final; } /** * Browse Page Filter * * @since 1.0.0 */ protected function wdkit_browse_page() { $args = $this->wdkit_parse_args( $_POST ); $response = WDesignKit_Data_Query::get_data( 'browse_page', $args ); if ( is_wp_error( $response ) ) { wp_send_json( array( 'success' => false, 'message' => $response->get_error_message(), ) ); wp_die(); } $manage_licence = array(); $manage_licence['theplus_elementor_addon'] = ! empty( defined( 'THEPLUS_VERSION' ) ) ? true : false; $manage_licence['tpag'] = ! empty( defined( 'TPGBP_VERSION' ) ) ? true : false; $manage_licence['elementor-pro'] = ! empty( defined( 'ELEMENTOR_PRO_VERSION' ) ) ? true : false; $response['manage_licence'] = $manage_licence; wp_send_json( $response ); wp_die(); } /** * * It is Use for get template from kit. * * @since 1.0.0 */ protected function wdkit_template() { $args = $this->wdkit_parse_args( $_POST ); $response = WDesignKit_Data_Query::get_data( 'kit_template', $args ); wp_send_json( $response ); wp_die(); } /** * * It is Use for remove or delete template. * * @since 1.0.0 */ protected function wdkit_template_remove() { $args = $this->wdkit_parse_args( $_POST ); $user_email = strtolower( sanitize_email( $args['email'] ) ); $response = ''; // Bug D fix: response()->json() is Laravel syntax — causes PHP fatal. Use plain array. if ( empty( $user_email ) || empty( $args['template_id'] ) ) { $response = array( 'message' => $this->e_msg_login, 'description' => $this->e_desc_login, 'success' => false, ); wp_send_json( $response ); wp_die(); } $args['token'] = $this->wdkit_login_user_token( $user_email ); unset( $user_email ); $response = WDesignKit_Data_Query::get_data( 'template_remove', $args ); wp_send_json( $response ); wp_die(); } /** * * It is Use for save template from page builder. * * @since 1.0.0 */ protected function wdkit_put_save_template() { $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : ''; $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : ''; $response = ''; if ( empty( $email ) ) { $response = array( 'id' => 0, 'editpage' => '', 'message' => $this->e_msg_login, 'description' => $this->e_desc_login, 'success' => false, ); wp_send_json( $response ); wp_die(); } $args = $this->wdkit_parse_args( $_POST ); $args['token'] = $this->wdkit_login_user_token( $email ); unset( $args['email'] ); if( 'elementor' === $builder ){ $args['data'] = base64_decode( $args['data'] ); } else if ( 'gutenberg' === $builder ) { $args['data'] = base64_decode( $args['data'] ); } global $post; $custom_fields = array(); if ( ! empty( $post_id ) ) { $meta_fields = get_post_custom( $post_id ); foreach ( $meta_fields as $key => $value ) { if ( str_contains( $key, 'nxt-' ) ) { $custom_fields[ $key ] = $value; } } if ( ! empty( $custom_fields ) ) { $data = json_decode( $args['data'], true ); $data['custom_meta'] = $custom_fields; $args['data'] = wp_json_encode( $data ); } } $response = WDesignKit_Data_Query::get_data( 'save_template', $args ); /** * The cloud call can come back as a WP_Error (timeout, DNS, refused) or with an * empty / unparsable body, which json_decode()s to null. Forwarding that as-is * makes admin-ajax answer with a literal `null` that the editor then reads * `.id` off, killing the whole app. Normalise it to the failure shape used above. */ if ( is_wp_error( $response ) || ! is_array( $response ) ) { $response = array( 'id' => 0, 'editpage' => '', 'message' => esc_html__( 'Template Not Saved !', 'wdesignkit' ), 'description' => is_wp_error( $response ) ? $response->get_error_message() : esc_html__( 'Could not reach the WDesignKit server. Please try again.', 'wdesignkit' ), 'success' => false, ); } wp_send_json( $response ); wp_die(); } /** * * It is Use for update save template image. * * @since 2.0.6 */ protected function wdkit_update_save_temp_image() { $temp_content = isset( $_POST['temp_content'] ) ? esc_url_raw( $_POST['temp_content'] ) : ''; $content_name = isset( $_POST['content_name'] ) ? sanitize_text_field( $_POST['content_name'] ) : ''; $token = isset( $_POST['token'] ) ? sanitize_text_field( $_POST['token'] ) : ''; $user_type = isset( $_POST['user_type'] ) ? sanitize_text_field( $_POST['user_type'] ) : ''; $type = isset( $_POST['content_type'] ) ? sanitize_text_field( $_POST['content_type'] ) : ''; $id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : ''; if ( empty( $temp_content ) || empty( $user_type ) || empty( $id ) || empty( $token ) ) { $response = array( 'message' => __( 'Data not found', 'wdesignkit' ), 'description' => __( 'Data not found', 'wdesignkit' ), 'success' => false, ); } else { $temp_content = str_replace( '\\', '', $temp_content ); // SSRF guard (CWE-918): validate the resolved host before fetching a caller-supplied URL. $fetched = wdesignkit_safe_remote_get( $temp_content ); $temp_content = is_wp_error( $fetched ) ? '' : wp_remote_retrieve_body( $fetched ); $temp_content = base64_encode( $temp_content ); $args = array( 'token' => $token, 'template_id' => $id, 'name' => $content_name, 'content' => $temp_content, 'type' => $type, ); $response = $this->wkit_api_call( $args, 'save_images' ); $success = ! empty( $response['success'] ) ? $response['success'] : false; if ( $success ) { $response = array( 'data' => $response['data'], 'success' => true, ); } else { $response = array( 'message' => __( 'API Error', 'wdesignkit' ), 'description' => __( 'API Error', 'wdesignkit' ), 'data' => $response['data'], 'success' => false, ); } } wp_send_json( $response ); wp_die(); } /** * * It is Use for save image to WordPress Media Library. * * @since 2.3.3 */ protected function wdkit_save_wp_images() { // media_sideload_image() generates every registered thumbnail size, which decodes // the full source bitmap. Same guard as the page import. $this->wdkit_guard_oversized_images(); $image_url = isset( $_POST['image'] ) ? sanitize_text_field( $_POST['image'] ) : ''; if ( empty( $image_url ) ) { $response = array( 'message' => __( 'No Image Provided', 'wdesignkit' ), 'description' => __( 'No Image URL provided for save.', 'wdesignkit' ), 'success' => false, ); } else { $attachment_id = media_sideload_image( $image_url, 0, null, 'id' ); if ( is_wp_error( $attachment_id ) ) { $response = array( 'message' => __( 'Upload Failed', 'wdesignkit' ), 'description' => $attachment_id->get_error_message(), 'success' => false, ); } else { $saved_url = wp_get_attachment_url( $attachment_id ); // Elementor's importer skips an image only when it finds // _elementor_source_image_hash matching sha1 of the URL it is given. The // content we hand it now carries this local URL, so stamp the hash of that // URL too - without it Elementor re-downloads a file already on disk and // leaves a "-1" duplicate behind for every image on every page that uses it. if ( $saved_url ) { update_post_meta( $attachment_id, '_elementor_source_image_hash', sha1( $saved_url ) ); // Same purpose for the block importer, which keys off its own meta. update_post_meta( $attachment_id, 'tpgb_source_image_key', sha1( $saved_url ) ); } $response = array( 'message' => __( 'Image Saved', 'wdesignkit' ), 'description' => __( 'Image successfully saved to Media Library.', 'wdesignkit' ), 'success' => true, 'url' => $saved_url, ); } } wp_send_json( $response ); wp_die(); } /** * * Get Elementor Global color and Typography. * * @since 1.1.16 */ /** * Kit settings holding The Plus Addons' own globals. * * These sit in the Elementor kit's `_elementor_page_settings` alongside Elementor's * system_colors / system_typography, but the save flow only ever collected the four * Elementor keys. Widgets reference an entry in these lists by its `_id` through a * `tp_global_preset` setting, so a template saved without them travels with the * reference but not the definition - which is why imported sections come in missing * their button styling, radii and shadows. * * @since 2.6.4 * * @return array Kit setting keys. */ private function wdkit_tp_global_kit_keys() { return array( 'tp_global_button_style_list', 'tp_global_dimensions_list', 'tp_global_box_shadow_list', 'tp_global_gradient_list', 'tp_global_gsap_list', 'tp_global_scroll_animation_list', 'tp_text_global_gsap_list', 'tp_image_global_gsap_list', ); } /** * Merge incoming Plus globals into the active kit, keyed by `_id`. * * Entries are matched on their `_id`, never on position: an existing entry is always * left as it is, and only genuinely new ones are appended. That matters because * widgets - and the entries themselves, a button style points at dimension and shadow * entries - resolve by `_id`. Renumbering or overwriting would repoint references on * the destination site's own content. * * @since 2.6.4 * * @param array $incoming Lists captured with the template. * @return bool True when the kit was changed. */ /** * Global colour / typography ids this site already defines. * * @since 2.6.4 * * @param array $kit_meta Kit `_elementor_page_settings`. * @return array{color:array,typography:array} */ private function wdkit_known_global_ids( $kit_meta ) { $known = array( 'color' => array(), 'typography' => array(), ); $sources = array( 'color' => array( 'system_colors', 'custom_colors' ), 'typography' => array( 'system_typography', 'custom_typography' ), ); foreach ( $sources as $kind => $keys ) { foreach ( $keys as $key ) { if ( empty( $kit_meta[ $key ] ) || ! is_array( $kit_meta[ $key ] ) ) { continue; } foreach ( $kit_meta[ $key ] as $entry ) { if ( ! empty( $entry['_id'] ) ) { $known[ $kind ][ $entry['_id'] ] = true; } } } } return $known; } /** * Make one incoming Plus global's colour / font references resolvable here. * * A Plus global can point at an Elementor global: the "Primary Button" entry holds * `__globals__: { text_color: "globals/colors?id=72e09b4", … }`, which The Plus Addons * turns into `var(--e-global-color-72e09b4)`. Elementor only emits that variable for ids * present in the kit, so on a site without `72e09b4` the button renders with no colour. * * Two cases, and the difference is deliberate: * * - The site ALREADY defines that id — leave the reference alone. The button then picks * up the destination's own colour, which is the point of a global. Their palette is * never read from or written to beyond this check. * - The site does NOT define it — write the captured value straight into the entry and * drop the reference, so it renders as designed. * * Nothing is ever added to the user's global colours or fonts. An earlier version injected * the missing definitions into their palette, which made the reference resolve but grew * their Site Settings by every colour an imported template happened to use. * * @since 2.6.4 * * @param array $entry One repeater entry. * @param array $refs Definitions captured with the template. * @param array $known Ids this site defines, from wdkit_known_global_ids(). * @return array Entry, with unresolvable references replaced by their values. */ private function wdkit_resolve_entry_globals( $entry, $refs, $known ) { if ( empty( $entry['__globals__'] ) || ! is_array( $entry['__globals__'] ) ) { return $entry; } foreach ( $entry['__globals__'] as $control => $ref ) { if ( ! is_string( $ref ) || false === strpos( $ref, 'id=' ) ) { continue; } if ( false !== strpos( $ref, 'globals/colors' ) ) { $kind = 'color'; } elseif ( false !== strpos( $ref, 'globals/typography' ) ) { $kind = 'typography'; } else { continue; } $id = substr( $ref, strpos( $ref, 'id=' ) + 3 ); if ( '' === $id || isset( $known[ $kind ][ $id ] ) ) { // Defined here already — their value wins. continue; } $definition = null; foreach ( ( $refs[ $kind ] ?? array() ) as $candidate ) { if ( is_array( $candidate ) && ( $candidate['_id'] ?? '' ) === $id ) { $definition = $candidate; break; } } if ( null === $definition ) { // Nothing captured for it, so leave the reference rather than blank the field. continue; } if ( 'color' === $kind ) { if ( empty( $definition['color'] ) ) { continue; } $entry[ $control ] = $definition['color']; } else { // A typography global expands into its own set of controls: the reference is // held under e.g. `typography_typography`, and each definition key replaces // that suffix — `typography_font_family`, `typography_font_weight`, and so on. foreach ( $definition as $def_key => $def_value ) { if ( '_id' === $def_key || 'title' === $def_key ) { continue; } $entry[ str_replace( 'typography_typography', $def_key, $control ) ] = $def_value; } } unset( $entry['__globals__'][ $control ] ); } return $entry; } private function wdkit_merge_tp_globals( $incoming, $refs = array() ) { if ( empty( $incoming ) || ! is_array( $incoming ) ) { return false; } $kit_id = get_option( 'elementor_active_kit' ); if ( empty( $kit_id ) ) { return false; } $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true ); if ( ! is_array( $kit_meta ) ) { $kit_meta = array(); } // Which global ids this site already defines. The Plus Addons turns a reference into // var(--e-global-color-<_id>), and Elementor only emits that variable for ids in the // kit — so a reference the destination does not define resolves to nothing at all. $known = $this->wdkit_known_global_ids( $kit_meta ); $changed = false; foreach ( $this->wdkit_tp_global_kit_keys() as $key ) { if ( empty( $incoming[ $key ] ) || ! is_array( $incoming[ $key ] ) ) { continue; } $existing = ( ! empty( $kit_meta[ $key ] ) && is_array( $kit_meta[ $key ] ) ) ? $kit_meta[ $key ] : array(); $seen = array(); foreach ( $existing as $entry ) { if ( ! empty( $entry['_id'] ) ) { $seen[ $entry['_id'] ] = true; } } foreach ( $incoming[ $key ] as $entry ) { if ( ! is_array( $entry ) || empty( $entry['_id'] ) || isset( $seen[ $entry['_id'] ] ) ) { continue; } // Only ever rewrite the entry being added — never one already in the kit. $existing[] = $this->wdkit_resolve_entry_globals( $entry, $refs, $known ); $seen[ $entry['_id'] ] = true; $changed = true; } $kit_meta[ $key ] = array_values( $existing ); } if ( $changed ) { update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta ); // Writing kit meta directly does not rebuild the kit stylesheet, so the // merged globals would never reach the frontend. $this->wdkit_regenerate_elementor_kit_css(); } return $changed; } protected function wdkit_get_global_val() { $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( $_POST['builder'] ) ) : ''; if ( 'elementor' === $builder ) { $kit_id = get_option( 'elementor_active_kit' ); if ( empty( $kit_id ) ) { $response = array( 'message' => __( 'Elementor kit not found', 'wdesignkit' ), 'description' => __( 'No active Elementor kit found', 'wdesignkit' ), 'success' => false, ); wp_send_json( $response ); wp_die(); } $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true ); if ( empty( $kit_meta['system_colors'] ) ) { $static_meta = array( 'system_colors' => array( 0 => array( '_id' => 'primary', 'title' => 'Primary', 'color' => '#6EC1E4', ), 1 => array( '_id' => 'secondary', 'title' => 'Secondary', 'color' => '#54595F', ), 2 => array( '_id' => 'text', 'title' => 'Text', 'color' => '#7A7A7A', ), 3 => array( '_id' => 'accent', 'title' => 'Accent', 'color' => '#61CE70', ), ), 'custom_colors' => array(), 'system_typography' => array( 0 => array( '_id' => 'primary', 'title' => 'Primary', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto', 'typography_font_weight' => '600', ), 1 => array( '_id' => 'secondary', 'title' => 'Secondary', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto Slab', 'typography_font_weight' => '400', ), 2 => array( '_id' => 'text', 'title' => 'Text', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto', 'typography_font_weight' => '400', ), 3 => array( '_id' => 'accent', 'title' => 'Accent', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto', 'typography_font_weight' => '500', ), ), 'custom_typography' => array(), 'default_generic_fonts' => 'Sans-serif', 'site_name' => ! empty( get_bloginfo( 'name' ) ) ? get_bloginfo( 'name' ) : '', 'page_title_selector' => 'h1.entry-title', 'activeItemIndex' => 1, 'viewport_md' => 768, 'viewport_lg' => 1025, ); $kit_meta = $static_meta; update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta ); } $system_colors = ! empty( $kit_meta['system_colors'] ) ? $kit_meta['system_colors'] : array(); $custom_colors = ! empty( $kit_meta['custom_colors'] ) ? $kit_meta['custom_colors'] : array(); $system_typography = ! empty( $kit_meta['system_typography'] ) ? $kit_meta['system_typography'] : array(); $custom_typography = ! empty( $kit_meta['custom_typography'] ) ? $kit_meta['custom_typography'] : array(); $color_array = array_merge( $system_colors, $custom_colors ); $typo_array = array_merge( $system_typography, $custom_typography ); $global_data = array( 'color' => $color_array, 'typography' => $typo_array, ); $response = array( 'message' => __( 'Global data Found', 'wdesignkit' ), 'description' => __( 'Global Color and Typography found', 'wdesignkit' ), 'data' => $global_data, 'success' => true, ); } elseif ( 'gutenberg' === $builder ) { $plus_settings = get_option( 'tpgb_global_options', false ); $plus_settings = ! empty( $plus_settings ) ? json_decode( $plus_settings, true ) : json_decode( '[]' ); if ( empty( $plus_settings ) ) { $static_meta = array( 'active' => 'preset1', 'darkMode' => 'none', 'presets' => array( 'preset1' => array( 'name' => 'Preset 1', 'key' => 'preset1', 'colors' => array( array( 'label' => 'Primary', 'value' => '#8072FC', ), array( 'label' => 'Secondary', 'value' => '#6FC784', ), array( 'label' => 'Tertiary', 'value' => '#FF5A6E', ), array( 'label' => 'Accent', 'value' => '#F3F3F3', ), array( 'label' => 'Background', 'value' => '#888888', ), ), 'gradient' => array( array( 'label' => 'Primary', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Secondary', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Tertiary', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Accent', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Background', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), ), 'spacing' => array( array( 'label' => 'Large', 'value' => array( 'md' => 70, 'unit' => 'px', ), ), array( 'label' => 'Medium', 'value' => array( 'md' => 40, 'unit' => 'px', ), ), array( 'label' => 'Small', 'value' => array( 'md' => 20, 'unit' => 'px', ), ), ), 'typography' => array( array( 'label' => 'Display Text', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 65, 'unit' => 'px', ), 'height' => array( 'md' => 75, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 700, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Headline', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 45, 'unit' => 'px', ), 'height' => array( 'md' => 60, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 700, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Sub Headline', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 38, 'unit' => 'px', ), 'height' => array( 'md' => 45, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 500, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Title 1', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 30, 'unit' => 'px', ), 'height' => array( 'md' => 40, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 500, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Title 2', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 25, 'unit' => 'px', ), 'height' => array( 'md' => 30, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 400, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Body', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 17, 'unit' => 'px', ), 'height' => array( 'md' => 22, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 400, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Captions', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 13, 'unit' => 'px', ), 'height' => array( 'md' => 16, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 400, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), ), 'boxshadow' => array( array( 'label' => 'Normal Shadow', 'value' => array( 'openShadow' => 1, 'inset' => 0, 'horizontal' => 2, 'vertical' => 6, 'blur' => 10, 'spread' => 0, 'color' => 'rgba(0,0,0,0.15)', ), ), array( 'label' => 'Hover Shadow', 'value' => array( 'openShadow' => 1, 'inset' => 0, 'horizontal' => 2, 'vertical' => 5, 'blur' => 14, 'spread' => 3, 'color' => 'rgba(0,0,0,0.2)', ), ), ), ), 'preset2' => array( 'name' => 'Preset 2', 'key' => 'preset2', 'colors' => array( array( 'label' => 'Primary', 'value' => '#8072FC', ), array( 'label' => 'Secondary', 'value' => '#6FC784', ), array( 'label' => 'Tertiary', 'value' => '#FF5A6E', ), array( 'label' => 'Accent', 'value' => '#F3F3F3', ), array( 'label' => 'Background', 'value' => '#888888', ), ), 'gradient' => array( array( 'label' => 'Primary', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Secondary', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Tertiary', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Accent', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), array( 'label' => 'Background', 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)', ), ), 'spacing' => array( array( 'label' => 'Large', 'value' => array( 'md' => 70, 'unit' => 'px', ), ), array( 'label' => 'Medium', 'value' => array( 'md' => 40, 'unit' => 'px', ), ), array( 'label' => 'Small', 'value' => array( 'md' => 20, 'unit' => 'px', ), ), ), 'typography' => array( array( 'label' => 'Display Text', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 65, 'unit' => 'px', ), 'height' => array( 'md' => 75, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 700, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Headline', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 45, 'unit' => 'px', ), 'height' => array( 'md' => 60, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 700, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Sub Headline', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 38, 'unit' => 'px', ), 'height' => array( 'md' => 45, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 500, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Title 1', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 30, 'unit' => 'px', ), 'height' => array( 'md' => 40, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 500, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Title 2', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 25, 'unit' => 'px', ), 'height' => array( 'md' => 30, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 400, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Body', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 17, 'unit' => 'px', ), 'height' => array( 'md' => 22, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 400, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), array( 'label' => 'Captions', 'value' => array( 'openTypography' => 1, 'size' => array( 'md' => 13, 'unit' => 'px', ), 'height' => array( 'md' => 16, 'unit' => 'px', ), 'fontFamily' => array( 'family' => 'Roboto', 'type' => 'sans-serif', 'fontWeight' => 400, ), 'spacing' => array( 'md' => 0, 'unit' => 'px', ), ), ), ), 'boxshadow' => array( array( 'label' => 'Normal Shadow', 'value' => array( 'openShadow' => 1, 'inset' => 0, 'horizontal' => 2, 'vertical' => 6, 'blur' => 10, 'spread' => 0, 'color' => 'rgba(0,0,0,0.15)', ), ), array( 'label' => 'Hover Shadow', 'value' => array( 'openShadow' => 1, 'inset' => 0, 'horizontal' => 2, 'vertical' => 5, 'blur' => 14, 'spread' => 3, 'color' => 'rgba(0,0,0,0.2)', ), ), ), ), ), 'globalContainer' => array( 'md' => '', 'unit' => 'px', ), ); update_option( 'tpgb_global_options', json_encode( $static_meta ) ); $plus_settings = $static_meta; } $active_id = ! empty( $plus_settings['active'] ) ? $plus_settings['active'] : ''; $preset_array = ! empty( $plus_settings['presets'] ) ? $plus_settings['presets'] : array(); $act_preset = ! empty( $plus_settings['presets'][ $active_id ] ) ? $plus_settings['presets'][ $active_id ] : array(); foreach ( $act_preset['colors'] as $index => &$item ) { $item['id'] = $index + 1; } unset( $item ); foreach ( $act_preset['typography'] as $index => &$item ) { $item['id'] = $index + 1; } unset( $item ); $act_preset['color'] = $act_preset['colors']; unset( $act_preset['colors'] ); $response = array( 'message' => __( 'Global data Found', 'wdesignkit' ), 'description' => __( 'Global Color and Typography found', 'wdesignkit' ), 'data' => $act_preset, 'success' => true, ); } wp_send_json( $response ); wp_die(); } /** * * Get site settings. * * @since 2.1.3 */ protected function wdkit_get_site_setting() { $kit_id = get_option( 'elementor_active_kit' ); if ( empty( $kit_id ) ) { $response = array( 'message' => __( 'Elementor kit not found', 'wdesignkit' ), 'description' => __( 'No active Elementor kit found', 'wdesignkit' ), 'success' => false, ); wp_send_json( $response ); wp_die(); } $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true ); $container_width = ! empty( $kit_meta['container_width'] ) ? $kit_meta['container_width'] : array(); $globals = ! empty( $kit_meta['__globals__'] ) ? $kit_meta['__globals__'] : array(); $body_background_color = ! empty( $kit_meta['body_background_color'] ) ? $kit_meta['body_background_color'] : array(); $site_globals = array( 'body_background_color' => $body_background_color, 'container_width' => $container_width, 'globals' => $globals, ); $response = array( 'message' => __( 'Global data Found', 'wdesignkit' ), 'description' => __( 'Global Color and Typography found', 'wdesignkit' ), 'data' => $site_globals, 'success' => true, ); wp_send_json( $response ); wp_die(); } /** * * update site settings. * * @since 2.1.3 */ protected function wdkit_update_site_setting() { $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : ''; $site_data = ! empty( $_POST['site_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['site_data'] ) ), true ) : array(); if ( 'elementor' == $builder ) { $kit_id = get_option( 'elementor_active_kit' ); if ( ! $kit_id && did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Core\Kits\Manager' ) ) { \Elementor\Core\Kits\Manager::create_default_kit(); $kit_id = get_option( 'elementor_active_kit' ); } if ( ! $kit_id ) { $response = array( 'message' => __( 'Elementor kit not found', 'wdesignkit' ), 'description' => __( 'No active Elementor kit found', 'wdesignkit' ), 'success' => false, ); wp_send_json( $response ); wp_die(); } // A freshly created kit has no `_elementor_page_settings` meta yet, // so an empty result here is a valid starting point, not an error. $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true ); if ( ! is_array( $kit_meta ) ) { $kit_meta = array(); } $kit_meta['container_width'] = ! empty( $site_data['container_width'] ) ? $site_data['container_width'] : array(); $kit_meta['__globals__'] = ! empty( $site_data['globals'] ) ? $site_data['globals'] : array(); $kit_meta['body_background_color'] = ! empty( $site_data['body_background_color'] ) ? $site_data['body_background_color'] : array(); update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta ); // Regenerate Elementor's cached CSS. Writing the kit meta directly does // not rebuild the kit stylesheet, so the imported body background colour // and container width would otherwise never render on the frontend. $this->wdkit_regenerate_elementor_kit_css(); $response = array( 'message' => __( 'Site data Updated', 'wdesignkit' ), 'description' => __( 'Site Globals Updated', 'wdesignkit' ), 'success' => true, ); } elseif ( 'gutenberg' == $builder ) { $plus_settings = get_option( 'tpgb_global_options' ); $site_preset = json_decode( $plus_settings, true ); $site_preset['globalContainer'] = $site_data; update_option( 'tpgb_global_options', json_encode( $site_preset ) ); $response = array( 'message' => __( 'Site data Updated', 'wdesignkit' ), 'description' => __( 'Site Globals Updated', 'wdesignkit' ), 'success' => true, ); } else { $response = array( 'message' => __( 'Builder Not Found !', 'wdesignkit' ), 'description' => __( 'Template Builder not Found', 'wdesignkit' ), 'success' => true, ); } wp_send_json( $response ); wp_die(); } /** * * Update Elementor Global color and Typography. * * @since 1.1.20 */ protected function wdkit_update_global_val() { $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : ''; if ( 'elementor' == $builder ) { $g_color = ! empty( $_POST['g_color'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_color'] ) ), true ) : array(); $g_typo = ! empty( $_POST['g_typography'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_typography'] ) ), true ) : array(); // Get colors from Elementor Site Kit $kit_id = get_option( 'elementor_active_kit' ); if ( ! $kit_id && did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Core\Kits\Manager' ) ) { // No kit has ever been created on this site (the option is only // ever populated by Elementor's own activation hook). Create one // via Elementor's own helper so the import has somewhere to write. \Elementor\Core\Kits\Manager::create_default_kit(); $kit_id = get_option( 'elementor_active_kit' ); } if ( ! $kit_id ) { $response = array( 'message' => __( 'Elementor kit not found', 'wdesignkit' ), 'description' => __( 'No active Elementor kit found', 'wdesignkit' ), 'success' => false, ); wp_send_json( $response ); wp_die(); } // A freshly created kit has no `_elementor_page_settings` meta yet, // so an empty result here is a valid starting point, not an error. $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true ); if ( ! is_array( $kit_meta ) ) { $kit_meta = array(); } $kit_meta['custom_colors'] = array_merge( $g_color, $kit_meta['custom_colors'] ?? array() ); $kit_meta['custom_typography'] = array_merge( $g_typo, $kit_meta['custom_typography'] ?? array() ); update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta ); // Regenerate Elementor's cached CSS. Writing the kit meta directly does // not rebuild the kit stylesheet, so the imported global colours and // fonts would otherwise never render on the frontend. $this->wdkit_regenerate_elementor_kit_css(); $response = array( 'message' => __( 'Global data Updated', 'wdesignkit' ), 'description' => __( 'Global Color and Typography Updated', 'wdesignkit' ), 'success' => true, ); } elseif ( 'gutenberg' == $builder ) { $new_preset = ! empty( $_POST['new_preset'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['new_preset'] ) ), true ) : array(); $new_preset_id = ! empty( $new_preset['key'] ) ? $new_preset['key'] : ''; $plus_settings = get_option( 'tpgb_global_options' ); $site_preset = json_decode( $plus_settings, true ); $site_preset['presets'][ $new_preset_id ] = $new_preset; $site_preset['active'] = $new_preset_id; update_option( 'tpgb_global_options', json_encode( $site_preset ) ); $response = array( 'message' => __( 'Global data Updated', 'wdesignkit' ), 'description' => __( 'Global Color and Typography Updated', 'wdesignkit' ), 'success' => true, ); } else { $response = array( 'message' => __( 'Builder Not Found !', 'wdesignkit' ), 'description' => __( 'Template Builder not Found', 'wdesignkit' ), 'success' => true, ); } wp_send_json( $response ); wp_die(); } /** * Regenerate Elementor's cached CSS files after the active kit's * `_elementor_page_settings` meta has been changed directly. * * Elementor renders global colours, global fonts and the body background * colour into a cached kit stylesheet. Updating the meta via * update_post_meta() does not rebuild that stylesheet, so imported site * settings never reach the frontend until the cache is cleared. This * mirrors the clear_cache() call already used by the page/section import. * * @since 2.3.2 * * @return void */ protected function wdkit_regenerate_elementor_kit_css() { if ( did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Plugin' ) ) { \Elementor\Plugin::$instance->files_manager->clear_cache(); } } /** * * Create Gutenberg page and save for re-generate css file. * * @since 1.2.3 */ protected function wdkit_update_preset() { $act_type = ! empty( $_POST['act_type'] ) ? sanitize_text_field( $_POST['act_type'] ) : ''; $post_id = ! empty( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : ''; if ( 'create' == $act_type ) { $page_id = wp_insert_post( array( 'post_title' => 'WDesignKit Gutenberg', 'post_status' => 'publish', 'post_type' => 'post', 'post_name' => sanitize_title( 'wdesignkit' ), 'post_content' => '

Add Your Heading Text Here

', 'meta_input' => array( 'gutenberg_preview' => true, '_wp_page_template' => 'default', ), ) ); if ( is_wp_error( $page_id ) || ! $page_id ) { $response = array( 'success' => true, 'message' => esc_html__( 'Page Not Found!', 'wdesignkit' ), 'description' => esc_html__( 'Page Not Found!', 'wdesignkit' ), ); wp_send_json( $response ); wp_die(); } update_post_meta( $page_id, '_edit_lock', time() . ':1' ); update_post_meta( $page_id, '_edit_last', get_current_user_id() ); $preview_url = admin_url( 'post.php?post=' . $page_id . '&action=edit' ); $response = array( 'success' => true, 'post_id' => $page_id, 'preview_url' => $preview_url, 'message' => esc_html__( 'Page Created', 'wdesignkit' ), 'description' => esc_html__( 'Page Created', 'wdesignkit' ), ); wp_send_json( $response ); wp_die(); } if ( ! empty( $post_id ) && ( $act_type == 'remove' ) ) { wp_delete_post( $post_id, true ); $response = array( 'success' => true, 'message' => esc_html__( 'post deleted', 'wdesignkit' ), 'description' => esc_html__( 'post deleted', 'wdesignkit' ), ); wp_send_json( $response ); wp_die(); } } /** * * It is For Find User Existing template List. * * @since 1.0.6 */ protected function wdkit_find_existing_template() { $array_data = array( 'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '', 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '', 'u_id' => isset( $_POST['u_id'] ) ? sanitize_text_field( wp_unslash( $_POST['u_id'] ) ) : '', 'builder' => isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '', 'parpage' => isset( $_POST['parpage'] ) ? sanitize_text_field( wp_unslash( $_POST['parpage'] ) ) : 12, ); $response = $this->wkit_api_call( $array_data, 'existing_template' ); wp_send_json( $response ); wp_die(); } /** * * It is For Update User Existing template List. * * @since 1.0.6 */ protected function wdkit_update_template() { $array_data = array( 'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '', 'post_id' => isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '', 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '', 'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '', 'global_data' => isset( $_POST['global_data'] ) ? wp_unslash( $_POST['global_data'] ) : array(), // 'global_font_family' => isset( $_POST['global_font_family'] ) ? wp_unslash( $_POST['global_font_family'] ) : array(), // 'global_color' => isset( $_POST['global_color'] ) ? wp_unslash( $_POST['global_color'] ) : array(), ); if ( ! empty( $array_data['post_id'] ) ) { $custom_fields = array(); $post_id = $array_data['post_id']; $meta_fields = get_post_custom( $post_id ); foreach ( $meta_fields as $key => $value ) { if ( str_contains( $key, 'nxt-' ) ) { $custom_fields[ $key ] = $value; } } if ( ! empty( $custom_fields ) ) { $data = json_decode( $array_data['data'], true ); $data['custom_meta'] = $custom_fields; $array_data['data'] = wp_json_encode( $data ); } } $array_data['remove'] = 'yes'; $response = $this->wkit_api_call( $array_data, 'existing_template' ); wp_send_json( $response ); wp_die(); } /** * * It is Use for manage favourite template. * * @since 1.0.0 */ protected function wdkit_manage_favorite() { $template_id = isset( $_POST['template_id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['template_id'] ) ) ) : 0; $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; if ( empty( $email ) || empty( $template_id ) ) { $response = array( 'message' => $this->e_msg_login, 'description' => $this->e_desc_login, 'success' => false, ); wp_send_json( $response ); wp_die(); } $args = $this->wdkit_parse_args( $_POST ); $args['token'] = $this->wdkit_login_user_token( $email ); unset( $args['email'] ); $response = WDesignKit_Data_Query::get_data( 'manage_favorite', $args ); wp_send_json( $response ); wp_die(); } /** * * It is Use for Check Plugin Dependency of template. * * @since 1.0.0 * @version 1.0.9 */ protected function wdkit_check_plugins_depends() { $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array(); $update_plugin = array(); $update_theme = array(); if ( empty( $plugins ) || ! is_array( $plugins ) ) { $this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) ); } $all_plugins = $this->get_plugins(); foreach ( $plugins as $plugin ) { $pluginslug = ! empty( $plugin->plugin_slug ) ? sanitize_text_field( wp_unslash( $plugin->plugin_slug ) ) : ''; $free_pro = ! empty( $plugin->freepro ) ? sanitize_text_field( wp_unslash( $plugin->freepro ) ) : '0'; $type = ! empty( $plugin->type ) ? sanitize_text_field( wp_unslash( $plugin->type ) ) : 'plugin'; if ( is_null( $pluginslug ) ) { $plugin->status = 'warning'; $update_plugin[] = $plugin; $update_theme[] = $plugin; continue; } if ( 'plugin' === $type ) { if ( ! is_plugin_active( $pluginslug ) ) { if ( ! isset( $all_plugins[ $pluginslug ] ) ) { if ( isset( $free_pro ) && '1' === $free_pro ) { $plugin->status = 'manually'; } else { $plugin->status = 'unavailable'; } } else { $plugin->status = 'inactive'; } $update_plugin[] = $plugin; } elseif ( is_plugin_active( $pluginslug ) ) { $plugin->status = 'active'; $update_plugin[] = $plugin; } } elseif ( 'theme' === $type ) { $theme_array = array_keys( wp_get_themes() ); $theme_slug = get_stylesheet(); $parent_theme_slug = get_template(); if ( $theme_slug === $plugin->original_slug || $parent_theme_slug === $plugin->original_slug ) { $plugin->status = 'active'; } else { $theme_name = $plugin->original_slug; if ( ! in_array( $theme_name, $theme_array ) ) { if ( isset( $free_pro ) && '1' === $free_pro ) { $plugin->status = 'manually'; } else { $plugin->status = 'unavailable'; } } else { $plugin->status = 'inactive'; } } $update_theme[] = $plugin; } } $response = array( 'plugins' => $update_plugin, 'theme' => $update_theme, 'ele_container' => get_option( 'elementor_experiment-container', false ), ); $this->wdkit_success_msg( $response ); } /** * * It is Use for Install dependent plugin. * * @since 1.0.0 * @version 1.0.9 */ protected function wdkit_install_plugins_depends() { $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array(); $type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin'; $p_id = ! empty( $plugins['p_id'] ) ? $plugins['p_id'] : 'plugin'; $responce = ''; if ( 'plugin' === $type ) { $responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins ); } elseif ( 'theme' === $type ) { $theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : ''; if ( ! empty( $theme_name ) ) { $theme_array = array_keys( wp_get_themes() ); $theme_slug = get_stylesheet(); if ( in_array( $theme_name, $theme_array ) ) { $activate_result = switch_theme( $theme_name ); if ( ! is_wp_error( $activate_result ) ) { $responce = array( 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ), 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ), 'slug' => 'nexter', 'p_id' => $p_id, 'status' => 'active', 'success' => true, ); } else { $responce = array( 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ), 'description' => $activate_result->get_error_message(), 'status' => 'inactive', 'p_id' => $p_id, 'success' => false, ); } } else { $result = $this->wdkit_install_theme_depends( $theme_name ); $message = ! empty( $result['message'] ) ? $result['message'] : esc_html__( 'Somthing Wrong', 'wdesignkit' ); $description = ! empty( $result['description'] ) ? $result['description'] : esc_html__( 'Error Somthing Wrong', 'wdesignkit' ); $status = ! empty( $result['status'] ) ? $result['status'] : esc_html__( 'inactive', 'wdesignkit' ); $success = ! empty( $result['success'] ) ? $result['success'] : false; $responce = array( 'message' => $message, 'description' => $description, 'p_id' => $p_id, 'status' => $status, 'success' => $success, ); } } else { $responce = array( 'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ), 'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ), 'success' => false, ); } } wp_send_json( $responce ); wp_die(); } protected function wdkit_install_theme_depends( $name = 'nexter' ) { if ( ! current_user_can( 'install_themes' ) ) { $response = $this->tpae_set_response( false, 'Invalid nonce.', 'The security check failed. Please refresh the page and try again.' ); return $response; } $theme_slug = $name; $theme_api_url = 'https://api.wordpress.org/themes/info/1.0/'; // Parameters for the request $args = array( 'body' => array( 'action' => 'theme_information', 'request' => serialize( (object) array( 'slug' => $name, 'fields' => array( 'description' => false, 'sections' => false, 'rating' => true, 'ratings' => false, 'downloaded' => true, 'download_link' => true, 'last_updated' => true, 'homepage' => true, 'tags' => true, 'template' => true, 'active_installs' => false, 'parent' => false, 'versions' => false, 'screenshot_url' => true, 'active_installs' => false, ), ) ), ), ); // Make the request $response = wp_remote_post( $theme_api_url, $args ); // Check for errors if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); $result = $this->tpae_set_response( false, 'oops', 'oops', '' ); } else { // api.wordpress.org's theme_information response is a serialized stdClass // (accessed below via ->name / ->download_link). allowed_classes => false // blocks stdClass too, turning it into an __PHP_Incomplete_Class whose // properties silently don't exist — allow only stdClass, still refusing any // other (potentially dangerous) class the payload might reference. $theme_info = unserialize( $response['body'], array( 'allowed_classes' => array( 'stdClass' ) ) ); $theme_name = $theme_info->name; $theme_zip_url = $theme_info->download_link; // SSRF guard (CWE-918): validate the resolved host before fetching the ZIP // referenced by the external theme_info response. if ( ! wdesignkit_validate_external_url( $theme_zip_url ) ) { return array( 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ), 'description' => esc_html__( 'The theme package URL is not allowed.', 'wdesignkit' ), 'status' => 'inactive', 'success' => false, ); } if ( ! function_exists( 'WP_Filesystem' ) ) { require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); } require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ); require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/theme.php' ); WP_Filesystem(); $active_theme = wp_get_theme(); $theme_name = $active_theme->get( 'Name' ); // Install via WordPress core's Theme_Upgrader instead of manually fetching and // ZipArchive::extractTo()'ing the remote package: core already performs the // standard download -> unpack -> validate-package-structure -> move-into-place // flow (including cleanup on failure) used for every trusted theme install. $upgrader = new Theme_Upgrader( new Automatic_Upgrader_Skin() ); $install = $upgrader->install( $theme_zip_url ); if ( is_wp_error( $install ) || ! $install ) { return array( 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ), 'description' => is_wp_error( $install ) ? $install->get_error_message() : esc_html__( 'Theme could not be installed.', 'wdesignkit' ), 'status' => 'inactive', 'success' => false, ); } $activate_result = switch_theme( $name ); if ( ! is_wp_error( $activate_result ) ) { $response = array( 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ), 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ), 'status' => 'active', 'success' => true, ); } else { $response = array( 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ), 'description' => $activate_result->get_error_message(), 'status' => 'inactive', 'success' => false, ); } } return $response; } /** * * It is Use Update WDesignKit plugin latest version. * * @since 1.0.17 */ protected function wdkit_update_latest_plugin() { return Wdkit_Depends_Installer::get_instance()->wdkit_update_plugin(); } /** * * It is Use for get plugin list. * * @since 1.0.0 */ private function get_plugins() { if ( ! function_exists( 'get_plugins' ) ) { require_once \ABSPATH . 'wp-admin/includes/plugin.php'; } return get_plugins(); } /** * Get Download Template Content * * @since 1.0.0 */ protected function wdkit_activate_container() { $option_value = get_option( 'elementor_experiment-container', false ); if ( $option_value === false ) { add_option( 'elementor_experiment-container', 'active' ); } else { update_option( 'elementor_experiment-container', 'active' ); } $result = array( 'message' => esc_html__( 'Container Activated Successfully', 'wdesignkit' ), 'description' => esc_html__( 'Elementor Container Activated Successfully.', 'wdesignkit' ), 'success' => true, ); wp_send_json( $response ); wp_die(); } /** * import category and tags for post * * @since 2.0.0 */ protected function wdkit_import_taxonomy() { $category = isset( $_POST['category'] ) ? json_decode( wp_unslash( $_POST['category'] ) ) : array(); $tags = isset( $_POST['tags'] ) ? json_decode( wp_unslash( $_POST['tags'] ) ) : array(); $response = array( 'success' => false, 'categories' => array(), 'tags' => array(), ); if ( ! empty( $category ) && count( $category ) > 0 ) { foreach ( $category as $category_name ) { $category_name = sanitize_text_field( $category_name ); $term_exists = term_exists( $category_name, 'category' ); if ( ! $term_exists ) { $result = wp_insert_term( $category_name, 'category' ); if ( ! is_wp_error( $result ) ) { $response['categories'][] = array( 'name' => $category_name, 'term_id' => $result['term_id'], ); } else { $response['categories'][] = array( 'name' => $category_name, 'error' => $result->get_error_message(), ); } } else { $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; $response['categories'][] = array( 'name' => $category_name, 'term_id' => $term_id, ); } } $response['success'] = true; } if ( ! empty( $tags ) && count( $tags ) > 0 ) { foreach ( $tags as $tags_name ) { $tags_name = sanitize_text_field( $tags_name ); $term_exists = term_exists( $tags_name, 'post_tag' ); if ( ! $term_exists ) { $result = wp_insert_term( $tags_name, 'post_tag' ); if ( ! is_wp_error( $result ) ) { $response['tags'][] = array( 'name' => $tags_name, 'term_id' => $result['term_id'], ); } else { $response['tags'][] = array( 'name' => $tags_name, 'error' => $result->get_error_message(), ); } } else { $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; $response['tags'][] = array( 'name' => $tags_name, 'term_id' => $term_id, ); } } $response['success'] = true; } wp_send_json( $response ); wp_die(); } /** * Get Download Template Content * * @since 1.0.0 */ protected function wdkit_import_template() { $args = $this->wdkit_parse_args( $_POST ); $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template'; $response = ''; if ( empty( $args['template_id'] ) ) { $result = array( 'content' => '', 'message' => esc_html__( 'Invalid import', 'wdesignkit' ), 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), 'success' => false, ); wp_send_json( $response ); wp_die(); } $args['token'] = $this->wdkit_login_user_token( $args['email'] ); unset( $args['email'] ); $args['unique_id'] = get_option( 'wdkit_unique_id' ) ?? ''; $response = WDesignKit_Data_Query::get_data( $api_type, $args ); if ( is_wp_error( $response ) ) { wp_send_json( array( 'success' => false, 'message' => $response->get_error_message(), ) ); wp_die(); } $custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; /** Custom meta Field */ if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) { $res_content = json_decode( $response['content'], true ); if ( isset( $res_content['custom_meta'] ) && ! empty( $res_content['custom_meta'] ) ) { $meta_data = $res_content['custom_meta']; if ( ! empty( $meta_data ) ) { foreach ( $meta_data as $meta_key => $meta_val ) { if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { $meta_val[0] = unserialize( $meta_val[0], array( 'allowed_classes' => false ) ); } if ( get_post_meta( get_the_ID(), $meta_key, true ) === '' ) { add_post_meta( get_the_ID(), $meta_key, $meta_val[0] ); } else { update_post_meta( get_the_ID(), $meta_key, $meta_val[0] ); } } } } } /** * Fires after a template has been imported from the cloud. * * WDesignKit's templates live in the cloud, so nothing local records that an import * happened — there is no post type, no option, nothing to count after the fact. This is the * only moment the information exists. * * @since 2.6.4 * * @param string $kind 'single' or 'kit'. * @param string $builder Builder the template was imported for, e.g. 'elementor'. * @param int $count How many templates this import brought in. */ // Only a completed import counts. The cloud's failure shape for this endpoint family sets // content => 'error' (see the sibling check in wdkit_import_kit_template() above) — that is // non-empty, so the previous `||` fired the counter on failed imports too. Require success // AND an absent/non-'error' content instead. if ( ! empty( $response['success'] ) && ( ! isset( $response['content'] ) || 'error' !== $response['content'] ) ) { do_action( 'wdkit_template_imported', 'import_kit_template' === $api_type ? 'kit' : 'single', isset( $_POST['builder'] ) ? sanitize_key( wp_unslash( $_POST['builder'] ) ) : '', 1 ); } wp_send_json( $response ); wp_die(); } /** * This Function is Use For Media Import * * @since 1.0.0 * * @param array $content store media content. * @param string $editor it is check editor. */ /** * Resolve a local upload URL back to its attachment ID. * * Handles the "-scaled" copy WordPress makes for large originals and any * "-1920x1280" size suffix, both of which attachment_url_to_postid() misses because * they are not the value stored in _wp_attached_file. * * @since 2.6.2 * * @param string $url Local upload URL. * @return int Attachment ID, or 0. */ private static function wdkit_attachment_id_from_url( $url ) { static $cache = array(); if ( isset( $cache[ $url ] ) ) { return $cache[ $url ]; } $id = (int) attachment_url_to_postid( $url ); if ( ! $id ) { // Try the original file behind a -scaled or -WxH derivative. $stripped = preg_replace( '/-scaled(\.[a-z0-9]+)$/i', '$1', $url ); $stripped = preg_replace( '/-\d+x\d+(\.[a-z0-9]+)$/i', '$1', (string) $stripped ); if ( $stripped && $stripped !== $url ) { $id = (int) attachment_url_to_postid( $stripped ); } } // Only remember hits. Page imports run concurrently, so an attachment created by a // sibling request may not exist yet when this is first asked — caching that miss // would keep every later control in this request pointing at nothing. if ( $id ) { $cache[ $url ] = $id; } return $id; } /** * Is this media reference still pointing off-site? * * Template content arrives holding the URLs of wherever the media lived before. Those * carry that site's attachment IDs, which have no meaning here - and can collide with * unrelated local posts. * * @since 2.6.2 * * @param string $url URL from a media control. * @return bool True when the URL points at another site's uploads. */ private static function wdkit_is_foreign_media_url( $url ) { if ( ! class_exists( 'Wdkit_Image_Guard' ) ) { require_once WDKIT_INCLUDES . 'admin/class-wdkit-image-guard.php'; } $uploads = wp_get_upload_dir(); return Wdkit_Image_Guard::is_foreign_media( $url, isset( $uploads['baseurl'] ) ? $uploads['baseurl'] : '' ); } /** * Find - or make - the local attachment behind a source-site media URL. * * Elementor stamps every image it imports with `_elementor_source_image_hash` * (sha1 of the URL it came from), and its importer consults that before doing any * network work. Delegating here means a URL already imported at create time resolves * from the database, and one that never made it is fetched exactly once. * * Only ever called for foreign URLs. Handing it a local URL would re-download the * file and leave a duplicate, because the stored hash is of the *remote* URL and so * would never match. * * @since 2.6.2 * * @param string $url Source-site media URL. * @param int $source_id The source site's attachment ID, used as Elementor's cache key. * @return array Local `id` and `url`, or an empty array when it cannot be resolved. */ private static function wdkit_localise_media_url( $url, $source_id = 0 ) { static $cache = array(); if ( isset( $cache[ $url ] ) ) { return $cache[ $url ]; } if ( ! did_action( 'elementor/loaded' ) || ! class_exists( '\\Elementor\\Plugin' ) ) { return array(); } $images = \Elementor\Plugin::$instance->templates_manager->get_import_images_instance(); if ( ! $images ) { return array(); } // A download may happen, so keep the oversized-image guard in force. self::wdkit_guard_oversized_images(); $imported = $images->import( array( // Elementor only checks its hash table when an id is present. 'id' => $source_id ? $source_id : 1, 'url' => $url, ) ); $local = ( ! empty( $imported['id'] ) && ! empty( $imported['url'] ) ) ? array( 'id' => (int) $imported['id'], 'url' => $imported['url'], ) : array(); // Remember hits only: a sibling request importing concurrently may simply not have // finished yet, and caching that miss would strand every later control on this page. if ( $local ) { $cache[ $url ] = $local; } return $local; } /** * Repair dangling attachment IDs across every page of a finished import. * * The create-time repair in wdkit_media_import() can only see attachments that already * exist. Pages import concurrently and share images — an icon first imported by one * page is referenced by several others — so a page that runs early legitimately cannot * resolve an image a sibling request has not created yet. * * This runs at the finalize step, once every page and attachment exists, and fixes * whatever the per-page pass had to leave behind. * * @since 2.6.2 * * @param array $page_ids Imported post IDs. * @return int Number of pages actually rewritten. */ private function wdkit_sweep_attachment_ids( $page_ids ) { if ( empty( $page_ids ) || ! did_action( 'elementor/loaded' ) ) { return 0; } $fixed = 0; $ids = array_unique( array_map( 'intval', $page_ids ) ); // Primes the meta cache for the whole batch in one query, so the // get_post_meta() call below hits the cache instead of issuing one query // per imported page. update_meta_cache( 'post', $ids ); foreach ( $ids as $post_id ) { if ( ! $post_id ) { continue; } $raw = get_post_meta( $post_id, '_elementor_data', true ); if ( empty( $raw ) ) { continue; } $data = is_array( $raw ) ? $raw : json_decode( $raw, true ); if ( ! is_array( $data ) ) { continue; } $repaired = self::wdkit_repair_attachment_ids( $data ); if ( wp_json_encode( $repaired ) === wp_json_encode( $data ) ) { continue; } // Save through the document API so Elementor regenerates the page CSS — the // background-image rules are only emitted once the IDs resolve. $document = \Elementor\Plugin::$instance->documents->get( $post_id ); // Count only a save that actually happened. Document::save() returns false // without saving when the current user cannot edit the post, and reporting // those as repaired hides the fact that nothing changed. if ( $document && $document->save( array( 'elements' => $repaired ) ) ) { ++$fixed; } } if ( $fixed ) { \Elementor\Plugin::$instance->files_manager->clear_cache(); } return $fixed; } /** * Repair media controls whose attachment ID does not resolve. * * Elementor media controls store `{ url, id }`. Controls flagged `has_sizes` — the * container/section **background image** among them — do not render from `url` at all: * CSS generation resolves the image through the attachment ID, so a dangling ID * produces no `background-image` rule and the section renders with no image even * though its URL is perfectly correct. * * IDs arrive dangling whenever Elementor's own importer does not rewrite a control — * it carries the source site's ID, which means nothing locally. Now that the URL is * already a local upload before import, the ID can simply be looked up from it. * * @since 2.6.2 * * @param mixed $node Elementor data, walked recursively. * @return mixed Data with resolvable attachment IDs. */ private static function wdkit_repair_attachment_ids( $node ) { if ( ! is_array( $node ) ) { return $node; } // A media control value: has a url, and an id slot to correct. if ( isset( $node['url'] ) && is_string( $node['url'] ) && array_key_exists( 'id', $node ) ) { $current = (int) $node['id']; $is_live = $current && 'attachment' === get_post_type( $current ); if ( self::wdkit_is_foreign_media_url( $node['url'] ) ) { // Still pointing at the source site. Ask Elementor for the local copy: its // _elementor_source_image_hash lookup returns the attachment the create-time // import already made, so this normally costs a single query and no download. $local = self::wdkit_localise_media_url( $node['url'], $current ); if ( ! empty( $local['id'] ) && ! empty( $local['url'] ) ) { $node['id'] = $local['id']; $node['url'] = $local['url']; } } elseif ( ! $is_live && false !== strpos( $node['url'], '/wp-content/uploads/' ) ) { $resolved = self::wdkit_attachment_id_from_url( $node['url'] ); if ( $resolved ) { $node['id'] = $resolved; } } } foreach ( $node as $key => $value ) { if ( is_array( $value ) ) { $node[ $key ] = self::wdkit_repair_attachment_ids( $value ); } } return $node; } public function wdkit_media_import( $content = array(), $editor = '' ) { if ( empty( $content ) && empty( $editor ) ) { $args = $this->wdkit_parse_args( $_POST ); $content = ! empty( $args['content'] ) ? json_decode( $args['content'], true ) : array(); } else { $args = array( 'content' => $content, 'editor' => $editor, ); $content = ! empty( $args['content'] ) ? $args['content'] : array(); if ( 'elementor' === $args['editor'] ) { $content = json_decode( $content, true ); } } if ( ! class_exists( 'Wdkit_Import_Images' ) ) { require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php'; } if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) { $media_import = array( $content ); $media_import = self::blocks_import_media_copy_content( $media_import ); $content = $media_import[0]; } elseif ( ! empty( $args['editor'] ) && 'elementor' === $args['editor'] && ! empty( $content ) ) { $media_import = array( $content ); $media_import = self::widgets_elements_id_change( $media_import ); $media_import = self::widgets_import_media_copy_content( $media_import ); $content = $media_import[0]; // Last: point any control Elementor left holding a foreign attachment ID at the // local attachment its URL already refers to. Without this, has_sizes controls // such as container background images resolve to nothing and render empty. $content = self::wdkit_repair_attachment_ids( $content ); } return $content; } /** * Widgets elements data * * @since 1.0.0 * @param string $media_import it is store media data. */ protected static function widgets_elements_id_change( $media_import ) { if ( did_action( 'elementor/loaded' ) ) { return \Elementor\Plugin::instance()->db->iterate_data( $media_import, function ( $element ) { $element['id'] = \Elementor\Utils::generate_random_string(); return $element; } ); } else { return $media_import; } } /** * Widgets Media import copy content. * * @since 1.0.0 * * @param string $media_import it is store media data. */ protected static function widgets_import_media_copy_content( $media_import ) { if ( did_action( 'elementor/loaded' ) ) { return \Elementor\Plugin::instance()->db->iterate_data( $media_import, function ( $element_data ) { $elements = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $element_data ); if ( ! $elements ) { return null; } return self::widgets_element_import_start( $elements ); } ); } else { return $media_import; } } /** * Start element copy content for media import. * * @since 1.0.0 * * @param string \Elementor\Controls_Stack $element it is store elementor data. */ protected static function widgets_element_import_start( \Elementor\Controls_Stack $element ) { $get_element_instance = $element->get_data(); $tp_mi_on_fun = 'on_import'; if ( method_exists( $element, $tp_mi_on_fun ) ) { $get_element_instance = $element->{$tp_mi_on_fun}( $get_element_instance ); } foreach ( $element->get_controls() as $get_control ) { $control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] ); $control_name = $get_control['name']; if ( ! $control_type ) { // Skip just this control. Returning here would abandon every control after // it, so a single unregistered type - routine when a kit uses an addon that // is not fully active yet - would silently leave the rest of the element's // media pointing at the source site. continue; } if ( method_exists( $control_type, $tp_mi_on_fun ) ) { $get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control ); } } return $get_element_instance; } /** * Blocks Recursively data * * @param string $data_import gutenber data import. */ public static function blocks_import_media_copy_content( $data_import ) { if ( ! empty( $data_import ) ) { foreach ( $data_import[0] as $key => $val ) { if ( array_key_exists( 'blockName', $val ) && ( empty( $val['blockName'] ) || null === $val['blockName'] || empty( $val['blockName'] ) || ' ' === $val['blockName'] ) ) { unset( $data_import[0][ $key ] ); } } } return self::blocks_array_recursively_data( $data_import, function ( $block_data ) { $elements = self::blocks_data_instance( $block_data ); return $elements; } ); } /** * Blocks Recursively data * * @param array $data store data. * @param string $callback store data. * @param string $args store data. */ public static function blocks_array_recursively_data( $data, $callback, $args = array() ) { if ( ( isset( $data['name'] ) && ! empty( $data['name'] ) ) || ( isset( $data['blockName'] ) && ! empty( $data['blockName'] ) ) ) { if ( ! empty( $data['innerBlocks'] ) ) { $data['innerBlocks'] = self::blocks_array_recursively_data( $data['innerBlocks'], $callback, $args ); } return call_user_func( $callback, $data, $args ); } if ( ! empty( $data ) ) { $data = (array) $data; foreach ( $data as $block_key => $block_value ) { $block_data = self::blocks_array_recursively_data( $data[ $block_key ], $callback, $args ); if ( null === $block_data ) { continue; } $data[ $block_key ] = $block_data; } } return $data; } /** * Check Blocks data media Url * * @param array $block_data store data. * @param array $args store data. * @param array $block_args store data. */ public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) { 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'] ) ) ) { $blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() ); $blocks_attr = self::wdkit_import_block_media( $blocks_attr ); if ( isset( $block_data['attributes'] ) ) { $block_data['attributes'] = $blocks_attr; } elseif ( isset( $block_data['attrs'] ) ) { $block_data['attrs'] = $blocks_attr; } $block_data = self::wdkit_relink_block_markup( $block_data ); } return $block_data; } /** * Run block markup through the media import, the way the create path does. * * Used wherever block content is written from the browser: media import, then the Nexter * block processor so each block's rendered copy matches its attributes, then serialise. * * @since 2.6.2 * * @param string $content Block markup. * @return string Block markup with local media. */ private function wdkit_relink_gutenberg_content( $content ) { if ( ! is_string( $content ) || false === strpos( $content, ') which kses strips. Mirror the create path, which stores // the block markup slashed and unfiltered (endpoint is manage_options-gated // and the content is plugin-generated). $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : ''; // This content comes straight from the browser and still carries the template // site's media URLs and attachment IDs, so it has to go through the same pipeline // the create path uses. Without this the save simply undid the import: the files // were fetched, then overwritten by a copy still pointing at the source site. // // Re-running is cheap. Every URL already handled resolves from the source-hash // lookup, and media that is already local resolves straight from its URL, so no // image is fetched or stored twice. $content = $this->wdkit_relink_gutenberg_content( $content ); $result = wp_update_post( array( 'ID' => $post_id, 'post_content' => wp_slash( $content ), ), true ); if ( is_wp_error( $result ) ) { return array( 'success' => false, 'message' => $result->get_error_message(), ); } self::wdkit_rebuild_block_css( $post_id ); } else { $elements = isset( $_POST['content'] ) ? json_decode( wp_unslash( $_POST['content'] ), true ) : array(); if ( ! class_exists( '\\Elementor\\Plugin' ) ) { return array( 'success' => false, 'message' => esc_html__( 'Elementor not available', 'wdesignkit' ), ); } $document = \Elementor\Plugin::$instance->documents->get( $post_id ); if ( ! $document ) { return array( 'success' => false, 'message' => esc_html__( 'Elementor document not found', 'wdesignkit' ), ); } // Same as wkit_update_elementor_template(): browser-posted content keeps the // source template's attachment IDs, so repair them or this save undoes the // create-time fix and background images stop rendering. $elements = self::wdkit_repair_attachment_ids( $elements ); $document->save( array( 'elements' => $elements ) ); } return array( 'success' => true, 'message' => esc_html__( 'Page content updated', 'wdesignkit' ), ); } /** * Import single template and section from plugin only * * @param array $args store data. * @param array $template_id store data. * @param array $data store data. * @param array $temp_data store data. * */ protected function import_page_section_content() { // Elementor sideloads every image referenced by the page from inside this request. // A single oversized source image decodes to more than the whole memory limit, so // guard before any of that starts. $this->wdkit_guard_oversized_images(); // Sideloading images for image-heavy pages (wdkit_media_import → Imagick // thumbnail generation per image) can exceed the default 30s execution // limit and fatal the request mid-import. Give this single page import // more headroom; harmless no-op where set_time_limit() is disabled. if ( function_exists( 'set_time_limit' ) ) { @set_time_limit( 120 ); } if ( isset( $_POST['args'] ) ) { $args = ! empty( $_POST['args'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['args'] ) ), true ) : array(); } if ( isset( $_POST['temp_data'] ) ) { $temp_data = ! empty( $_POST['temp_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['temp_data'] ) ), true ) : array(); } if ( isset( $_POST['category_list'] ) ) { $category_list = ! empty( $_POST['category_list'] ) ? json_decode( wp_unslash( $_POST['category_list'] ), true ) : ''; } if ( isset( $_POST['tag_list'] ) ) { $tag_list = ! empty( $_POST['tag_list'] ) ? json_decode( wp_unslash( $_POST['tag_list'] ), true ) : ''; } if ( isset( $_POST['thumb_image'] ) ) { $thumb_image = ! empty( $_POST['thumb_image'] ) ? esc_url_raw( $_POST['thumb_image'] ) : ''; } if ( isset( $_POST['template_id'] ) ) { $template_id = ! empty( $_POST['template_id'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_id'] ), true ) ) : ''; } $temp_type = isset( $_POST['temp_type'] ) ? sanitize_text_field( wp_unslash( $_POST['temp_type'] ) ) : 'normal'; if ( isset( $_POST['data'] ) ) { $data = ! empty( $_POST['data'] ) ? json_decode( wp_unslash( $_POST['data'] ) ) : ''; } $enqueue_instance = new Wdkit_Enqueue(); $get_post_type = $enqueue_instance->wdkit_get_post_type_list(); $post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page'; if ( 'section' === $post_type ) { $post_type = $temp_data['wp_post_type']; } else { $post_type = $temp_data['wp_post_type']; } if ( ! array_key_exists( $post_type, $get_post_type ) ) { $post_type = 'page'; } if ( ! empty( $data ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) { $post_content = $data; // Restore The Plus Addons' globals before the page is built, so the widgets' // tp_global_preset references resolve as soon as it renders. Done here rather // than in the save-template UI's confirmation dialog so that every import path // - the library, the abilities, the theme builder - gets it. if ( isset( $post_content->tp_globals ) && ! empty( $post_content->tp_globals ) ) { $this->wdkit_merge_tp_globals( json_decode( wp_json_encode( $post_content->tp_globals ), true ), isset( $post_content->tp_global_refs ) ? json_decode( wp_json_encode( $post_content->tp_global_refs ), true ) : array() ); } $post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : ''; $post_slug = isset( $post_content->slug ) ? sanitize_text_field( $post_content->slug ) : ''; $file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : ''; $content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : ''; $temp_con = ''; if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) { if ( empty( $content ) ) { wp_send_json( array( 'template_id' => $template_id, 'message' => __( 'Content is Empty.', 'wdesignkit' ), ) ); wp_die(); } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) { $editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor']; $blocks = parse_blocks( stripslashes( $content ) ); $blocks = $this->wdkit_media_import( $blocks, $editor ); $processor = new WDKIT_Nexter_Block_Processor(); $blocks = $processor->run( $blocks ); $content = serialize_blocks( $blocks ); $content = $this->replace_unicode_glitch( serialize_blocks( $blocks ) ); $inserted_post = wp_insert_post( array( 'post_status' => 'publish', 'post_type' => $post_type, 'post_title' => $post_title, 'post_name' => $post_slug, 'post_content' => $content, ) ); if ( is_wp_error( $inserted_post ) ) { wp_send_json( array( 'import_failed' => $inserted_post->get_error_message(), 'code' => $inserted_post->get_error_code(), ) ); wp_die(); } if ( ! empty( $thumb_image ) && wdesignkit_validate_external_url( $thumb_image ) ) { // $featured_image_url = esc_url_raw( $thumb_image ); $tmp = download_url( $thumb_image ); if ( is_wp_error( $tmp ) ) { error_log( 'Image download failed: ' . esc_html( $tmp->get_error_message() ) ); } else { $file_array = array( 'name' => wp_basename( $thumb_image ), 'tmp_name' => $tmp, ); $image_id = media_handle_sideload( $file_array, $inserted_post ); if ( is_wp_error( $image_id ) ) { error_log( 'Image sideload failed: ' . esc_html( $image_id->get_error_message() ) ); } else { set_post_thumbnail( $inserted_post, $image_id ); } @unlink( $tmp ); } } if ( ! empty( $category_list ) && is_array( $category_list ) ) { $category_ids = array_map( 'intval', $category_list ); wp_set_post_terms( $inserted_post, $category_ids, 'category' ); } if ( ! empty( $tag_list ) && is_array( $tag_list ) ) { $tag_ids = array_map( 'intval', $tag_list ); wp_set_post_terms( $inserted_post, $tag_ids, 'post_tag' ); } if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) { $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : ''; if ( ! empty( $custom_meta ) ) { foreach ( $custom_meta as $meta_key => $meta_val ) { if ( isset( $meta_val[0] ) && ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { $meta_val[0] = unserialize( $meta_val[0], array( 'allowed_classes' => false ) ); } if ( '' === get_post_meta( $inserted_post, $meta_key, true ) && isset( $meta_val[0] ) ) { add_post_meta( $inserted_post, $meta_key, $meta_val[0] ); } } } } $temp_detail = array( 'title' => get_the_title( $inserted_post ), 'edit_link' => get_edit_post_link( $inserted_post, 'internal' ), 'view' => get_permalink( $inserted_post ), 'id' => $inserted_post, ); if ( ! empty( $template_id->id ) ) { $temp_id = $template_id->id; } elseif ( ! empty( $template_id ) ) { $temp_id = $template_id; } else { $temp_id = ''; } wp_update_post([ 'ID' => $inserted_post, ]); if (class_exists('Tpgb_Library') && method_exists('Tpgb_Library', 'remove_backend_dir_files')) { Tpgb_Library()->remove_backend_dir_files(); } clean_post_cache( $inserted_post ); // This whole method imports exactly one section per call — unlike // wdkit_import_template()/wdkit_import_kit_template(), it never fired this hook // at all, so single-section imports (Header/Footer/CTA/etc., a primary import // path per the Template Type sidebar) were invisible to tracking entirely. do_action( 'wdkit_template_imported', 'single', sanitize_key( $editor ), 1 ); wp_send_json( array( $temp_id => $temp_detail, 'description' => 'Yay! Your Section has been Successfully Imported.', 'message' => __( 'Successfully Imported.', 'wdesignkit' ), 'inserted_id' => $inserted_post, 'success' => true, ) ); wp_die(); } } elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) { if ( did_action( 'elementor/loaded' ) ) { if ( empty( $content ) ) { wp_send_json( array( 'template_id' => $template_id, 'message' => __( 'Content is Empty.', 'wdesignkit' ), ) ); wp_die(); } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) { $content = $this->wdkit_content_remover( $content ); $post_attributes = array( 'post_title' => $post_title, 'post_type' => $post_type, 'post_status' => 'publish', 'post_name' => $post_slug, ); if ( 'elementor_library' === $post_type ) { $el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page'; $new_document = \Elementor\Plugin::$instance->documents->create( $el_type, $post_attributes ); } else { $new_document = \Elementor\Plugin::$instance->documents->create( $post_attributes['post_type'], $post_attributes ); } if ( is_wp_error( $new_document ) ) { wp_send_json( array( 'import_failed' => $new_document->get_error_message(), 'code' => $new_document->get_error_code(), ) ); wp_die(); } $inserted_id = $new_document->get_main_id(); if ( ! empty( $thumb_image ) && wdesignkit_validate_external_url( $thumb_image ) ) { // $featured_image_url = esc_url_raw( $thumb_image ); $tmp = download_url( $thumb_image ); if ( is_wp_error( $tmp ) ) { error_log( 'Image download failed: ' . esc_html( $tmp->get_error_message() ) ); } else { $file_array = array( 'name' => wp_basename( $thumb_image ), 'tmp_name' => $tmp, ); $image_id = media_handle_sideload( $file_array, $inserted_id ); if ( is_wp_error( $image_id ) ) { error_log( 'Image sideload failed: ' . esc_html( $image_id->get_error_message() ) ); } else { set_post_thumbnail( $inserted_id, $image_id ); } @unlink( $tmp ); } } if ( ! empty( $category_list ) && is_array( $category_list ) ) { $category_ids = array_map( 'intval', $category_list ); wp_set_post_terms( $inserted_id, $category_ids, 'category' ); } if ( ! empty( $tag_list ) && is_array( $tag_list ) ) { $tag_ids = array_map( 'intval', $tag_list ); wp_set_post_terms( $inserted_id, $tag_ids, 'post_tag' ); } $settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array(); $content = wp_json_encode( $content ); $content = $this->wdkit_media_import( $content, $file_type ); $new_document->save( array( 'elements' => $content, 'settings' => ! empty( $settings ) ? $settings : array(), ) ); $inserted_id = $new_document->get_main_id(); if( $temp_type == 'navigation' ){ $temp_con = $content; } if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) { $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : ''; if ( ! empty( $custom_meta ) ) { foreach ( $custom_meta as $meta_key => $meta_val ) { if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { $meta_val[0] = unserialize( $meta_val[0], array( 'allowed_classes' => false ) ); } if ( '' === get_post_meta( $inserted_id, $meta_key, true ) ) { add_post_meta( $inserted_id, $meta_key, $meta_val[0] ); } } } } $temp_detail = array( 'title' => get_the_title( $inserted_id ), 'edit_link' => get_edit_post_link( $inserted_id, 'internal' ), 'view' => get_permalink( $inserted_id ), 'id' => $inserted_id, ); if ( ! empty( $template_id->id ) ) { $temp_id = $template_id->id; } elseif ( ! empty( $template_id ) ) { $temp_id = $template_id; } else { $temp_id = ''; } \Elementor\Plugin::$instance->files_manager->clear_cache(); // See the matching note in the Gutenberg branch above — this method never // fired the tracking hook for either editor. do_action( 'wdkit_template_imported', 'single', 'elementor', 1 ); wp_send_json( array( $temp_id => $temp_detail, 'content' => $temp_con, 'description' => 'Yay! Your Section has been Successfully Imported.', 'message' => __( 'Successfully Imported.', 'wdesignkit' ), 'inserted_id' => $inserted_id, 'success' => true, ) ); wp_die(); } } else { wp_send_json( array( 'template_id' => $template_id, 'message' => esc_html__( 'Relevant Page Builder not installed or activated', 'wdesignkit' ), ) ); wp_die(); } } } wp_send_json( array( 'success' => false, 'message' => esc_html__( 'Something went wrong', 'wdesignkit' ), ) ); wp_die(); } /** * Replace unicode glitch * * @since 2.0.0 */ private function replace_unicode_glitch( $content ) { // Fix escaped unicode like \u003c → < $content = preg_replace_callback( '/\\\\u([0-9a-fA-F]{4})/', function ( $match ) { return html_entity_decode( mb_convert_encoding( pack('H*', $match[1]), 'UTF-8', 'UCS-2BE' ), ENT_QUOTES, 'UTF-8' ); }, $content ); return $content; } /** * change plugins setting for import kit * * @since 2.0.0 */ protected function update_plugin_setting() { $temp_id = isset( $_POST['plugin_type'] ) ? sanitize_text_field( $_POST['plugin_type'] ) : ''; if ( $temp_id == 'elementor' ) { $unfiltered_files = get_option( 'elementor_unfiltered_files_upload', false ); $load_fa4 = get_option( 'elementor_load_fa4_shim', false ); $Inline_font_icons = get_option( 'elementor_experiment-e_font_icon_svg', false ); $container = get_option( 'elementor_experiment-container', false ); if ( isset( $unfiltered_files ) ) { update_option( 'elementor_unfiltered_files_upload', 1 ); } else { add_option( 'elementor_unfiltered_files_upload', 1 ); } if ( isset( $load_fa4 ) ) { update_option( 'elementor_load_fa4_shim', 'yes' ); } else { add_option( 'elementor_load_fa4_shim', 'yes' ); } if ( isset( $container ) ) { update_option( 'elementor_experiment-container', 'active' ); } else { add_option( 'elementor_experiment-container', 'active' ); } if ( isset( $Inline_font_icons ) ) { update_option( 'elementor_experiment-e_font_icon_svg', 'inactive' ); } else { add_option( 'elementor_experiment-e_font_icon_svg', 'inactive' ); } $response = array( 'message' => esc_html__( 'Plugin Setting updated', 'wdesignkit' ), 'description' => esc_html__( 'Plugin Setting updated', 'wdesignkit' ), 'success' => true, ); } else { $response = array( 'message' => esc_html__( 'Plugin not found', 'wdesignkit' ), 'description' => esc_html__( 'Plugin not found', 'wdesignkit' ), 'success' => false, ); } wp_send_json( $response ); wp_die(); } /** * generate different color logo * * @since 2.0.0 */ protected function wkit_generate_site_logo() { if ( empty( $_POST['image_url'] ) ) { wp_send_json_error( 'Image URL not provided.' ); } if ( isset( $_POST['colors'] ) ) { $img_colors = ! empty( $_POST['colors'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['colors'] ) ), true ) : array(); } if ( empty( $img_colors ) ) { wp_send_json_error( 'Image color not provided.' ); } $image_url = esc_url_raw( $_POST['image_url'] ); if ( ! wdesignkit_validate_external_url( $image_url ) ) { wp_send_json_error( 'Image could not be downloaded.' ); } $tmp_file = download_url( $image_url ); if ( is_wp_error( $tmp_file ) ) { wp_send_json_error( 'Image could not be downloaded.' ); } if ( mime_content_type( $tmp_file ) !== 'image/png' ) { unlink( $tmp_file ); wp_send_json_error( 'Not a PNG file.' ); } $src = imagecreatefrompng( $tmp_file ); imagesavealpha( $src, true ); $width = imagesx( $src ); $height = imagesy( $src ); $hasTransparency = false; for ( $x = 0; $x < $width; $x++ ) { for ( $y = 0; $y < $height; $y++ ) { $rgba = imagecolorat( $src, $x, $y ); $alpha = ( $rgba & 0x7F000000 ) >> 24; if ( $alpha > 0 ) { $hasTransparency = true; break 2; } } } if ( ! $hasTransparency ) { unlink( $tmp_file ); wp_send_json_error( 'PNG has no transparent pixels.' ); } $upload_dir = wp_upload_dir(); $result_urls = array(); $colour_index = 0; foreach ( $img_colors as $name => $rgb ) { // $name is a key from the posted colours payload and went straight into the output // filename, so traversal sequences in it steered imagepng() outside the upload // directory (CWE-22, ClickUp 86d41ced6). sanitize_file_name() flattens it to one // path segment; a key made only of dots/separators sanitizes to empty, so fall back // to a positional index rather than writing to a bare "colored--