class-fl-builder-export.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Custom export handling.
*
* @since 1.8
*/
final class FLBuilderExport {
/**
* @since 1.8
* @return void
*/
static public function init()
{
add_action( 'admin_enqueue_scripts', 'FLBuilderExport::enqueue_scripts' );
add_action( 'export_filters', 'FLBuilderExport::filters' );
add_action( 'wp_ajax_fl_builder_export_templates_data', 'FLBuilderExport::templates_data' );
add_action( 'export_wp', 'FLBuilderExport::export' );
}
/**
* Enqueues the export scripts and styles.
*
* @since 1.8
* @return void
*/
static public function enqueue_scripts()
{
global $pagenow;
if ( 'export.php' != $pagenow ) {
return;
}
wp_enqueue_style( 'fl-builder-export', FL_BUILDER_URL . 'css/fl-builder-export.css', array(), FL_BUILDER_VERSION );
wp_enqueue_script( 'fl-builder-export', FL_BUILDER_URL . 'js/fl-builder-export.js', array(), FL_BUILDER_VERSION, true );
}
/**
* Renders the export filters markup.
*
* @since 1.8
* @return void
*/
static public function filters()
{
include FL_BUILDER_DIR . 'includes/export-filters.php';
}
/**
* Called via AJAX and returns the data used for selecting
* templates for export.
*
* @since 1.8
* @return void
*/
static public function templates_data()
{
$data = array();
$query = new WP_Query( array(
'post_type' => 'fl-builder-template',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => '-1'
) );
foreach( $query->posts as $post ) {
$data[] = array(
'id' => $post->ID,
'title' => $post->post_title
);
}
echo json_encode( $data );
die();
}
/**
* Download the export file.
*
* @since 1.8
* @param array $args
* @return void
*/
static public function export( $args )
{
if ( ! current_user_can( 'export' ) ) {
return;
}
if ( 'fl-builder-template' != $args['content'] ) {
return;
}
if ( ! isset( $_REQUEST['fl-builder-template-export-select'] ) ) {
return;
}
if ( 'all' == $_REQUEST['fl-builder-template-export-select'] ) {
return;
}
if ( ! is_array( $_REQUEST['fl-builder-export-template'] ) ) {
return;
}
require_once FL_BUILDER_DIR . 'includes/export.php';
fl_export_wp( $_REQUEST['fl-builder-export-template'] );
die();
}
}
FLBuilderExport::init();