PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / admin / tools / dt-import.php
acf-extended / includes / admin / tools Last commit date
dbt-export.php 6 years ago dbt-import.php 6 years ago dop-export.php 6 years ago dop-import.php 6 years ago dpt-export.php 6 years ago dpt-import.php 6 years ago dt-export.php 6 years ago dt-import.php 6 years ago fg-local.php 6 years ago
dt-import.php
241 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 // Check setting
7 if(!acf_get_setting('acfe/modules/dynamic_taxonomies'))
8 return;
9
10 if(!class_exists('ACFE_Admin_Tool_Import_DT')):
11
12 class ACFE_Admin_Tool_Import_DT extends ACF_Admin_Tool{
13
14 function initialize(){
15
16 // vars
17 $this->name = 'acfe_tool_dt_import';
18 $this->title = __('Import Taxonomies');
19 $this->icon = 'dashicons-upload';
20
21 }
22
23 function html(){
24
25 ?>
26 <p><?php _e('Import Taxonomies', 'acf'); ?></p>
27
28 <div class="acf-fields">
29 <?php
30
31 acf_render_field_wrap(array(
32 'label' => __('Select File', 'acf'),
33 'type' => 'file',
34 'name' => 'acf_import_file',
35 'value' => false,
36 'uploader' => 'basic',
37 ));
38
39 ?>
40 </div>
41
42 <p class="acf-submit">
43 <button type="submit" name="action" class="button button-primary"><?php _e('Import File'); ?></button>
44 </p>
45 <?php
46
47 }
48
49 function submit(){
50
51 // Check file size.
52 if(empty($_FILES['acf_import_file']['size']))
53 return acf_add_admin_notice(__("No file selected", 'acf'), 'warning');
54
55 // Get file data.
56 $file = $_FILES['acf_import_file'];
57
58 // Check errors.
59 if($file['error'])
60 return acf_add_admin_notice(__("Error uploading file. Please try again", 'acf'), 'warning');
61
62 // Check file type.
63 if(pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json')
64 return acf_add_admin_notice(__("Incorrect file type", 'acf'), 'warning');
65
66 // Read JSON.
67 $json = file_get_contents($file['tmp_name']);
68 $json = json_decode($json, true);
69
70 // Check if empty.
71 if(!$json || !is_array($json))
72 return acf_add_admin_notice(__("Import file empty", 'acf'), 'warning');
73
74 $ids = array();
75
76 $dynamic_taxonomies = get_option('acfe_dynamic_taxonomies', array());
77
78 // Loop over json
79 foreach($json as $taxonomy_name => $args){
80
81 // Check if already exists
82 if(isset($dynamic_taxonomies[$taxonomy_name])){
83
84 acf_add_admin_notice(__("Taxonomy {$dynamic_taxonomies[$taxonomy_name]['label']} already exists. Import aborted."), 'warning');
85 continue;
86
87 }
88
89 // Vars
90 $title = $args['label'];
91 $name = $taxonomy_name;
92
93 // Insert post
94 $post_id = wp_insert_post(array(
95 'post_title' => $title,
96 'post_name' => $name,
97 'post_type' => 'acfe-dt',
98 'post_status' => 'publish'
99 ));
100
101 // Insert error
102 if(is_wp_error($post_id)){
103
104 acf_add_admin_notice(__("Something went wrong with the taxonomy {$title}. Import aborted."), 'warning');
105 continue;
106
107 }
108
109
110 // Register Args
111 update_field('acfe_dt_name', $taxonomy_name, $post_id);
112 update_field('label', $args['label'], $post_id);
113 update_field('description', $args['description'], $post_id);
114 update_field('hierarchical', $args['hierarchical'], $post_id);
115 update_field('post_types', $args['post_types'], $post_id);
116 update_field('public', $args['public'], $post_id);
117 update_field('publicly_queryable', $args['publicly_queryable'], $post_id);
118 update_field('update_count_callback', $args['update_count_callback'], $post_id);
119 update_field('sort', $args['sort'], $post_id);
120
121 // Meta box callback
122 if(!isset($args['meta_box_cb']) || $args['meta_box_cb'] === null){
123
124 update_field('meta_box_cb', 'null', $post_id);
125 update_field('meta_box_cb_custom', '', $post_id);
126
127 }
128
129 elseif($args['meta_box_cb'] === false){
130
131 update_field('meta_box_cb', 'false', $post_id);
132 update_field('meta_box_cb_custom', '', $post_id);
133
134 }
135
136 elseif(empty($args['meta_box_cb']) || is_string($args['meta_box_cb'])){
137
138 update_field('meta_box_cb', 'custom', $post_id);
139 update_field('meta_box_cb_custom', $args['meta_box_cb'], $post_id);
140
141 }
142
143 // Labels
144 if(!empty($args['labels'])){
145
146 foreach($args['labels'] as $label_key => $label_value){
147
148 update_field('labels_' . $label_key, $label_value, $post_id);
149
150 }
151
152 }
153
154 // Menu
155 update_field('show_ui', $args['show_ui'], $post_id);
156 update_field('show_in_menu', $args['show_in_menu'], $post_id);
157 update_field('show_in_nav_menus', $args['show_in_nav_menus'], $post_id);
158 update_field('show_tagcloud', $args['show_tagcloud'], $post_id);
159 update_field('show_in_quick_edit', $args['show_in_quick_edit'], $post_id);
160 update_field('show_admin_column', $args['show_admin_column'], $post_id);
161
162 // Capability
163 if(isset($args['capabilities']))
164 update_field('capabilities', acf_encode_choices($args['capabilities'], false), $post_id);
165
166 // Single
167 update_field('acfe_dt_single_template', $args['acfe_single_template'], $post_id);
168 update_field('acfe_dt_single_posts_per_page', $args['acfe_single_ppp'], $post_id);
169 update_field('acfe_dt_single_orderby', $args['acfe_single_orderby'], $post_id);
170 update_field('acfe_dt_single_order', $args['acfe_single_order'], $post_id);
171 update_field('rewrite', $args['rewrite'], $post_id);
172
173 // Admin
174 update_field('acfe_dt_admin_terms_per_page', $args['acfe_admin_ppp'], $post_id);
175 update_field('acfe_dt_admin_orderby', $args['acfe_admin_orderby'], $post_id);
176 update_field('acfe_dt_admin_order', $args['acfe_admin_order'], $post_id);
177
178 // REST
179 update_field('show_in_rest', $args['show_in_rest'], $post_id);
180 update_field('rest_base', $args['rest_base'], $post_id);
181 update_field('rest_controller_class', $args['rest_controller_class'], $post_id);
182
183 // Rewrite: override
184 if($args['rewrite'] && is_array($args['rewrite'])){
185
186 update_field('rewrite', true, $post_id);
187
188 update_field('rewrite_args_select', true, $post_id);
189
190 update_field('rewrite_args_acfe_dt_rewrite_slug', $args['rewrite']['slug'], $post_id);
191 update_field('rewrite_args_acfe_dt_rewrite_with_front', $args['rewrite']['with_front'], $post_id);
192 update_field('rewrite_args_hierarchical', $args['rewrite']['hierarchical'], $post_id);
193
194 }
195
196 // Create ACFE option
197 $dynamic_taxonomies[$taxonomy_name] = $args;
198
199 // Sort keys ASC
200 ksort($dynamic_taxonomies);
201
202 // Update ACFE option
203 update_option('acfe_dynamic_taxonomies', $dynamic_taxonomies);
204
205 // append message
206 $ids[] = $post_id;
207
208 }
209
210 if(empty($ids))
211 return;
212
213 // Count total
214 $total = count($ids);
215
216 // Generate text
217 $text = sprintf(_n('1 taxonomy imported', '%s taxonomies imported', $total, 'acf'), $total);
218
219 // Add links to text
220 $links = array();
221 foreach($ids as $id){
222
223 $links[] = '<a href="' . get_edit_post_link($id) . '">' . get_the_title($id) . '</a>';
224
225 }
226
227 $text .= ': ' . implode(', ', $links);
228
229 // Add notice
230 acf_add_admin_notice($text, 'success');
231
232 // Flush permalinks
233 flush_rewrite_rules();
234
235 }
236
237 }
238
239 acf_register_admin_tool('ACFE_Admin_Tool_Import_DT');
240
241 endif;