PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.2.3
Kubio AI Page Builder v1.2.3
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / DemoSites / DemoSites.php
kubio / lib / src / DemoSites Last commit date
DemoSites.php 4 years ago DemoSitesHelpers.php 4 years ago DemoSitesImportBlockMap.php 4 years ago DemoSitesImporter.php 4 years ago DemoSitesLogger.php 4 years ago DemoSitesRepository.php 4 years ago WXRExporter.php 4 years ago WXRImporter.php 4 years ago WpCliCommand.php 4 years ago
DemoSites.php
112 lines
1 <?php
2
3 namespace Kubio\DemoSites;
4
5 use IlluminateAgnostic\Arr\Support\Arr;
6 use Kubio\PluginsManager;
7
8 class DemoSites {
9
10 public function __construct() {
11 add_action( 'admin_init', array( $this, 'init' ) );
12 }
13
14 public static function load() {
15 new DemoSites();
16 }
17
18 public static function exportDemoSiteContent() {
19 $option_keys = array( 'site_icon', 'site_logo', 'page_on_front', 'page_for_posts', 'show_on_front' );
20 $dummy_fallback_value = uniqid( 'kubio-dummy-option-' );
21 $options = array();
22 foreach ( $option_keys as $option_key ) {
23 $option_value = get_option( $option_key, $dummy_fallback_value );
24
25 if ( $option_value !== $dummy_fallback_value ) {
26 $options[ $option_key ] = $option_value;
27 }
28 }
29
30 $stylesheet = get_stylesheet();
31 $template = get_template();
32 $fse_base_query = array(
33 'post_status' => array( 'publish' ),
34 'posts_per_page' => - 1,
35 'tax_query' => array(
36 array(
37 'taxonomy' => 'wp_theme',
38 'field' => 'name',
39 'terms' => array( $stylesheet, $template ),
40 ),
41 ),
42 );
43
44 $wp_templates = get_posts( array_merge( $fse_base_query, array( 'post_type' => 'wp_template' ) ) );
45 $wp_template_parts = get_posts( array_merge( $fse_base_query, array( 'post_type' => 'wp_template_part' ) ) );
46 $template_slugs = array();
47 $template_parts_slugs = array();
48
49 foreach ( $wp_templates as $wp_template ) {
50 $template_slugs[] = $wp_template->post_name;
51 }
52
53 foreach ( $wp_template_parts as $wp_template_part ) {
54 $template_parts_slugs[] = $wp_template_part->post_name;
55 }
56
57 return array(
58 'site_url' => WXRExporter::getSiteURL(),
59 'content' => WXRExporter::export(),
60 'customizer' => get_theme_mods(),
61 'options' => $options,
62 'templates' => $template_slugs,
63 'template_parts' => $template_parts_slugs,
64 );
65 }
66
67 public function init() {
68 DemoSitesImporter::load();
69 DemoSitesRepository::load();
70
71 add_action( 'wp_ajax_kubio-demo-site-install-plugin', array( $this, 'installPlugin' ) );
72 add_action( 'wp_ajax_kubio-demo-site-activate-plugin', array( $this, 'activatePlugin' ) );
73 }
74
75 public function installPlugin() {
76 DemoSitesHelpers::verifyAjaxCall();
77
78 $slug = sanitize_text_field( Arr::get( $_REQUEST, 'slug', null ) );
79
80 if ( empty( $slug ) ) {
81 DemoSitesHelpers::sendAjaxError( __( 'Slug not found', 'kubio' ) );
82 }
83
84 $result = PluginsManager::getInstance()->installPlugin( $slug );
85
86 if ( is_wp_error( $result ) ) {
87 DemoSitesHelpers::sendAjaxError( $result );
88 } else {
89 wp_send_json_success();
90 }
91 }
92
93 public function activatePlugin() {
94 DemoSitesHelpers::verifyAjaxCall();
95
96 $slug = sanitize_text_field( Arr::get( $_REQUEST, 'slug', null ) );
97
98 if ( empty( $slug ) ) {
99 DemoSitesHelpers::sendAjaxError( __( 'Slug not found', 'kubio' ) );
100 }
101
102 $result = PluginsManager::getInstance()->activatePlugin( $slug, true );
103
104 if ( is_wp_error( $result ) ) {
105 DemoSitesHelpers::sendAjaxError( $result );
106 } else {
107 wp_send_json_success();
108 }
109 }
110
111 }
112