D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
proc
/
thread-self
/
cwd
/
wp-content
/
plugins
/
aeen-core
/
inc
/
Filename :
demo-importer.php
back
Copy
<?php /** * @author RadiusTheme * @since 1.0 * @version 1.1 */ namespace radiustheme\Aeen_Core; use \FW_Ext_Backups_Demo; use \WPCF7_ContactFormTemplate; if ( ! defined( 'ABSPATH' ) ) exit; class Demo_Importer { protected static $instance; public function __construct() { add_filter( 'plugin_action_links_rt-demo-importer/rt-demo-importer.php', array( $this, 'add_action_links' ) ); // Link from plugins page add_filter( 'rt_demo_installer_warning', array( $this, 'data_loss_warning' ) ); add_filter( 'fw:ext:backups-demo:demos', array( $this, 'demo_config' ) ); add_action( 'fw:ext:backups:tasks:success:id:demo-content-install', array( $this, 'after_demo_install' ) ); } public static function instance() { if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } public function add_action_links( $links ) { $mylinks = array( '<a href="' . esc_url( admin_url( 'tools.php?page=fw-backups-demo-content' ) ) . '">'.__( 'Install Demo Contents', 'aeen-core' ).'</a>', ); return array_merge( $links, $mylinks ); } public function data_loss_warning( $links ) { $html = '<div style="margin-top:20px;color:#f00;font-size:20px;line-height:1.3;font-weight:600;margin-bottom:40px;border-color: #f00;border-style: dashed;border-width: 1px 0;padding:10px 0;">'; $html .= __( 'Warning: All your old data will be lost if you install One Click demo data from here, so it is suitable only for a new website.', 'aeen-core'); $html .= __( ' ( If one click demo import does not work please try manual demo import <a href="https://radiustheme.com/demo/wordpress/themes/aeen/docs/" target="__blank" style="text-decoration:none; color:#1b3452;">check documentation</a> )', 'aeen-core' ); $html .= '</div>'; return $html; } public function demo_config( $demos ) { $demos_array = array( 'demo1' => array( 'title' => __( 'Home 1', 'aeen-core' ), 'screenshot' => plugins_url( 'screenshots/home1.jpg', dirname(__FILE__) ), 'preview_link' => 'https://radiustheme.com/demo/wordpress/themes/aeen/', ), 'demo2' => array( 'title' => __( 'Home 2', 'aeen-core' ), 'screenshot' => plugins_url( 'screenshots/home2.jpg', dirname(__FILE__) ), 'preview_link' => 'https://radiustheme.com/demo/wordpress/themes/aeen/home-2/', ), 'demo3' => array( 'title' => __( 'Home 3', 'aeen-core' ), 'screenshot' => plugins_url( 'screenshots/home3.jpg', dirname(__FILE__) ), 'preview_link' => 'https://radiustheme.com/demo/wordpress/themes/aeen/home-3/', ), 'demo4' => array( 'title' => __( 'Home 4', 'aeen-core' ), 'screenshot' => plugins_url( 'screenshots/home4.jpg', dirname(__FILE__) ), 'preview_link' => 'https://radiustheme.com/demo/wordpress/themes/aeen/home-4/', ), ); $download_url = 'http://demo.radiustheme.com/wordpress/demo-content/aeen/'; foreach ($demos_array as $id => $data) { $demo = new FW_Ext_Backups_Demo($id, 'piecemeal', array( 'url' => $download_url, 'file_id' => $id, )); $demo->set_title($data['title']); $demo->set_screenshot($data['screenshot']); $demo->set_preview_link($data['preview_link']); $demos[ $demo->get_id() ] = $demo; unset($demo); } return $demos; } public function after_demo_install( $collection ){ // Update front page id $demos = array( 'demo1' => 7, 'demo2' => 388, 'demo3' => 7418, 'demo4' => 8406, ); $data = $collection->to_array(); foreach( $data['tasks'] as $task ) { if( $task['id'] == 'demo:demo-download' ){ $demo_id = $task['args']['demo_id']; $page_id = $demos[$demo_id]; update_option( 'page_on_front', $page_id ); flush_rewrite_rules(); break; } } // Update contact form 7 email $cf7ids = array( 342, 923, 485 ); foreach ( $cf7ids as $cf7id ) { $mail = get_post_meta( $cf7id, '_mail', true ); $mail['recipient'] = get_option( 'admin_email' ); if ( class_exists( 'WPCF7_ContactFormTemplate' ) ) { $pattern = "/<[^@\s]*@[^@\s]*\.[^@\s]*>/"; // <email@email.com> $replacement = '<'. WPCF7_ContactFormTemplate::from_email().'>'; $mail['sender'] = preg_replace($pattern, $replacement, $mail['sender']); } update_post_meta( $cf7id, '_mail', $mail ); } // Update post author id global $wpdb; $id = get_current_user_id(); $query = "UPDATE $wpdb->posts SET post_author = $id"; $wpdb->query($query); } } Demo_Importer::instance();