new_demo_rang_date = date('Y-m-d', strtotime('-31 days')); parent::__construct(); add_action( 'wp_ajax_ep_elementor_demo_importer_data_import', array( $this, 'ajax_import_data' ) ); add_action( 'wp_ajax_ep_elementor_demo_importer_data_loading', array( $this, 'demo_tab_ajax_loading_demo' ) ); add_action( 'wp_ajax_ep_elementor_demo_importer_data_sync_demo_with_server', array( $this, 'sync_demo_with_server' ) ); add_action( 'wp_ajax_ep_elementor_demo_importer_send_report', array( $this, 'send_report' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_notices', [$this, 'admin_notice'] ); } function admin_menu() { if ( ! defined( 'BDTEP_LO' ) ) { add_submenu_page( self::PAGE_ID, BDTEP_TITLE, esc_html__( 'Template Library', 'bdthemes-element-pack' ), 'manage_options', 'element-pack-template-library', [ $this, 'plugin_page' ] ); } } public function enqueue_scripts() { wp_enqueue_script( 'ep-elementor-demo-importer-scripts', plugin_dir_url( __FILE__ ) . 'assets/js/element-pack-template-library.js', array( 'jquery' ), BDTEP_VER, false ); } ## Import Template function templates_get_content_remote_request( $url ) { $response = wp_remote_get( $url, array( 'timeout' => 60, 'sslverify' => false ) ); $result = json_decode( wp_remote_retrieve_body( $response ), true ); return $result; } /** * Ajax request. */ public function ajax_import_data() { if ( isset( $_REQUEST ) ) { $demo_url = $_REQUEST['demo_url']; $demo_id = $_REQUEST['demo_id']; $page_title = $_REQUEST['page_title']; $defaultPageTitle = $_REQUEST['default_page_title']; $importType = $_REQUEST['demo_import_type']; $response_data = $this->templates_get_content_remote_request( $demo_url ); $sourceData = ""; if ( is_array( $response_data ) ) { $manager = new Source_Local(); $sourceData = $manager->import_template( 'test.json', $demo_url ); } if ( ! is_array( $response_data ) || ! is_array( $sourceData ) ) { echo json_encode( array( 'success' => false, 'id' => '', 'edittxt' => esc_html__( 'Fail to upload. Try again.', 'bdthemes-element-pack' ) ) ); wp_die(); } if ( is_array( $sourceData ) && count( $sourceData ) == 1 && isset( $sourceData[0]['template_id'] ) && $sourceData[0]['template_id'] > 1 ) { $template_id = $sourceData[0]['template_id']; if ( $importType == 'page' ) { $metaData = get_post_meta( $template_id ); if ( isset( $metaData['_elementor_data'] ) && isset( $metaData['_elementor_data'][0] ) ) { $_elementor_data = wp_slash( $metaData['_elementor_data'][0] ); $defaulttitle = ( ! empty( $page_title ) ) ? $page_title : $defaultPageTitle; $args = [ 'post_type' => 'page', 'post_status' => empty( $page_title ) ? 'draft' : 'publish', 'post_title' => ! empty( $page_title ) ? $page_title : $defaulttitle, 'post_content' => '', ]; $new_post_id = wp_insert_post( $args ); update_post_meta( $new_post_id, '_elementor_data', $_elementor_data ); if(isset($metaData['_elementor_page_settings']) && isset($metaData['_elementor_page_settings'][0])){ $_elementor_page_settings = maybe_unserialize( $metaData['_elementor_page_settings'][0] ); update_post_meta( $new_post_id, '_elementor_page_settings', $_elementor_page_settings ); } update_post_meta( $new_post_id, '_elementor_template_type', $response_data['type'] ); update_post_meta( $new_post_id, '_elementor_edit_mode', 'builder' ); if ( $new_post_id && ! is_wp_error( $new_post_id ) ) { update_post_meta( $new_post_id, '_wp_page_template', ! empty( $response_data['page_template'] ) ? $response_data['page_template'] : 'elementor_header_footer' ); } echo json_encode( array( 'success' => true, 'id' => $new_post_id, 'edittxt' => ( $importType == 'page' ) ? esc_html__( 'Edit Page', 'bdthemes-element-pack' ) : esc_html__( 'Edit Template', 'bdthemes-element-pack' ) ) ); wp_die(); } } else { echo json_encode( array( 'success' => true, 'id' => $template_id, 'edittxt' => esc_html__( 'Edit Template', 'bdthemes-element-pack' ) ) ); wp_die(); } } } echo json_encode( array( 'success' => false, 'id' => '', 'edittxt' => esc_html__( 'Fail to upload. Try again', 'bdthemes-element-pack' ) ) ); wp_die(); } protected function loadHtmlItems( $demoData ) { foreach ( $demoData as $data ): include 'template-parts/demo-template-item.php'; endforeach; } public function admin_notice(){ Notices::add_notice( [ 'id' => 'template-library-issue', 'type' => 'warning', 'dismissible' => true, 'dismissible-time' => 1043200, 'message' => __( 'This template library will be deprecated soon so please use our brand new template library in your editor (Make sure you activated it from element pack settings).', 'bdthemes-element-pack' ), ] ); } /** All Pages Tab (First time load / on refresh load)**/ function plugin_page() { $naviationItems = $this->getNaviationItems(); $demoData = $this->getData(); $current_user = wp_get_current_user(); ?>
Hi,
"; $customerHtml .= 'You have a messaging regarding Import Demo as follows:
'; $customerHtml .= "Name: " . $data['display_name'] . "