Import Settings into WordPress SEO by Yoast - Version 1.1.4

Version Description

  • Fixed field update permissions for primary category
Download this release

Release Info

Developer WPAllImport
Plugin Icon 128x128 Import Settings into WordPress SEO by Yoast
Version 1.1.4
Comparing to
See all releases

Code changes from version 1.1.3 to 1.1.4

Files changed (3) hide show
  1. rapid-addon.php +1049 -1037
  2. readme.txt +104 -101
  3. yoast-addon.php +282 -266
rapid-addon.php CHANGED
@@ -1,1037 +1,1049 @@
1
- <?php
2
-
3
- if (!class_exists('RapidAddon')) {
4
-
5
- class RapidAddon {
6
-
7
- public $name;
8
- public $slug;
9
- public $fields;
10
- public $options = array();
11
- public $accordions = array();
12
- public $image_sections = array();
13
- public $import_function;
14
- public $post_saved_function;
15
- public $notice_text;
16
- public $logger = null;
17
- public $when_to_run = false;
18
- public $image_options = array(
19
- 'download_images' => 'yes',
20
- 'download_featured_delim' => ',',
21
- 'download_featured_image' => '',
22
- 'featured_image' => '',
23
- 'featured_delim' => ',',
24
- 'search_existing_images' => 1,
25
- 'is_featured' => 0,
26
- 'create_draft' => 'no',
27
- 'set_image_meta_title' => 0,
28
- 'image_meta_title_delim' => ',',
29
- 'image_meta_title' => '',
30
- 'set_image_meta_caption' => 0,
31
- 'image_meta_caption_delim' => ',',
32
- 'image_meta_caption' => '',
33
- 'set_image_meta_alt' => 0,
34
- 'image_meta_alt_delim' => ',',
35
- 'image_meta_alt' => '',
36
- 'set_image_meta_description' => 0,
37
- 'image_meta_description_delim' => ',',
38
- 'image_meta_description' => '',
39
- 'auto_rename_images' => 0,
40
- 'auto_rename_images_suffix' => '',
41
- 'auto_set_extension' => 0,
42
- 'new_extension' => ''
43
- );
44
-
45
- function __construct($name, $slug) {
46
-
47
- $this->name = $name;
48
- $this->slug = $slug;
49
-
50
- }
51
-
52
- function set_import_function($name) {
53
- $this->import_function = $name;
54
- }
55
-
56
- function set_post_saved_function($name) {
57
- $this->post_saved_function = $name;
58
- }
59
-
60
- function is_active_addon($post_type = null) {
61
-
62
- if ( ! is_plugin_active('wp-all-import-pro/wp-all-import-pro.php') and ! is_plugin_active('wp-all-import/plugin.php') ){
63
- return false;
64
- }
65
-
66
- $addon_active = false;
67
-
68
- if ($post_type !== null) {
69
- if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) {
70
- $addon_active = true;
71
- }
72
- }
73
-
74
- if ($addon_active){
75
-
76
- $current_theme = wp_get_theme();
77
-
78
- $parent_theme = $current_theme->parent();
79
-
80
- $theme_name = $current_theme->get('Name');
81
-
82
- $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false;
83
-
84
- if ( ! $addon_active and $parent_theme ){
85
- $parent_theme_name = $parent_theme->get('Name');
86
- $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false;
87
-
88
- }
89
-
90
- if ( $addon_active and ! empty($this->active_plugins) ){
91
-
92
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
93
-
94
- foreach ($this->active_plugins as $plugin) {
95
- if ( ! is_plugin_active($plugin) ) {
96
- $addon_active = false;
97
- break;
98
- }
99
- }
100
- }
101
-
102
- }
103
-
104
- if ($this->when_to_run == "always") {
105
- return true;
106
- }
107
-
108
- return $addon_active;
109
- }
110
-
111
- /**
112
- *
113
- * Add-On Initialization
114
- *
115
- * @param array $conditions - list of supported themes and post types
116
- *
117
- */
118
- function run($conditions = array()) {
119
-
120
- if (empty($conditions)) {
121
- $this->when_to_run = "always";
122
- }
123
-
124
- @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array();
125
- @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array();
126
- @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array();
127
-
128
- add_filter('pmxi_addons', array($this, 'wpai_api_register'));
129
- add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse'));
130
- add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import'));
131
- add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved'));
132
- add_filter('pmxi_options_options', array($this, 'wpai_api_options'));
133
- add_filter('wp_all_import_image_sections', array($this, 'additional_sections'), 10, 1);
134
- add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2);
135
- add_action('admin_init', array($this, 'admin_notice_ignore'));
136
-
137
- }
138
-
139
- function parse($data) {
140
-
141
- if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false;
142
-
143
- $parsedData = $this->helper_parse($data, $this->options_array());
144
- return $parsedData;
145
-
146
- }
147
-
148
-
149
- function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "") {
150
-
151
- $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug);
152
-
153
- $this->fields[$field_slug] = $field;
154
-
155
- if ( ! empty($enum_values) ){
156
- foreach ($enum_values as $key => $value) {
157
- if (is_array($value))
158
- {
159
- if ($field['type'] == 'accordion')
160
- {
161
- $this->fields[$value['slug']]['is_sub_field'] = true;
162
- }
163
- else
164
- {
165
- foreach ($value as $n => $param) {
166
- if (is_array($param) and ! empty($this->fields[$param['slug']])){
167
- $this->fields[$param['slug']]['is_sub_field'] = true;
168
- }
169
- }
170
- }
171
- }
172
- }
173
- }
174
-
175
- return $field;
176
-
177
- }
178
-
179
- /**
180
- *
181
- * Add an option to WP All Import options list
182
- *
183
- * @param string $slug - option name
184
- * @param string $default_value - default option value
185
- *
186
- */
187
- function add_option($slug, $default_value = ''){
188
- $this->options[$slug] = $default_value;
189
- }
190
-
191
- function options_array() {
192
-
193
- $options_list = array();
194
-
195
- foreach ($this->fields as $field_slug => $field_params) {
196
- if (in_array($field_params['type'], array('title', 'plain_text'))) continue;
197
- $default_value = '';
198
- if (!empty($field_params['enum_values'])){
199
- foreach ($field_params['enum_values'] as $key => $value) {
200
- $default_value = $key;
201
- break;
202
- }
203
- }
204
- $options_list[$field_slug] = $default_value;
205
- }
206
-
207
- if ( ! empty($this->options) ){
208
- foreach ($this->options as $slug => $value) {
209
- $options_arr[$slug] = $value;
210
- }
211
- }
212
-
213
- $options_arr[$this->slug] = $options_list;
214
- $options_arr['rapid_addon'] = plugin_basename( __FILE__ );
215
-
216
- return $options_arr;
217
-
218
- }
219
-
220
- function wpai_api_options($all_options) {
221
-
222
- $all_options = $all_options + $this->options_array();
223
-
224
- return $all_options;
225
-
226
- }
227
-
228
-
229
- function wpai_api_register($addons) {
230
-
231
- if (empty($addons[$this->slug])) {
232
- $addons[$this->slug] = 1;
233
- }
234
-
235
- return $addons;
236
-
237
- }
238
-
239
-
240
- function wpai_api_parse($functions) {
241
-
242
- $functions[$this->slug] = array($this, 'parse');
243
- return $functions;
244
-
245
- }
246
-
247
- function wpai_api_post_saved($functions){
248
- $functions[$this->slug] = array($this, 'post_saved');
249
- return $functions;
250
- }
251
-
252
-
253
- function wpai_api_import($functions) {
254
-
255
- $functions[$this->slug] = array($this, 'import');
256
- return $functions;
257
-
258
- }
259
-
260
- function post_saved( $importData ){
261
-
262
- if (is_callable($this->post_saved_function))
263
- call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']);
264
-
265
- }
266
-
267
- function import($importData, $parsedData) {
268
-
269
- if (!$this->is_active_addon($importData['post_type'])) {
270
- return;
271
- }
272
-
273
- $import_options = $importData['import']['options'][$this->slug];
274
-
275
- // echo "<pre>";
276
- // print_r($import_options);
277
- // echo "</pre>";
278
-
279
- if ( ! empty($parsedData) ) {
280
-
281
- $this->logger = $importData['logger'];
282
-
283
- $post_id = $importData['pid'];
284
- $index = $importData['i'];
285
-
286
- foreach ($this->fields as $field_slug => $field_params) {
287
-
288
- if (in_array($field_params['type'], array('title', 'plain_text'))) continue;
289
-
290
- switch ($field_params['type']) {
291
-
292
- case 'image':
293
-
294
- // import the specified image, then set the value of the field to the image ID in the media library
295
-
296
- $image_url_or_path = $parsedData[$field_slug][$index];
297
-
298
- $download = $import_options['download_image'][$field_slug];
299
-
300
- $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true);
301
-
302
- $data[$field_slug] = array(
303
- "attachment_id" => $uploaded_image,
304
- "image_url_or_path" => $image_url_or_path,
305
- "download" => $download
306
- );
307
-
308
- break;
309
-
310
- case 'file':
311
-
312
- $image_url_or_path = $parsedData[$field_slug][$index];
313
-
314
- $download = $import_options['download_image'][$field_slug];
315
-
316
- $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files");
317
-
318
- $data[$field_slug] = array(
319
- "attachment_id" => $uploaded_file,
320
- "image_url_or_path" => $image_url_or_path,
321
- "download" => $download
322
- );
323
-
324
- break;
325
-
326
- default:
327
- // set the field data to the value of the field after it's been parsed
328
- $data[$field_slug] = $parsedData[$field_slug][$index];
329
- break;
330
- }
331
-
332
- // apply mapping rules if they exist
333
- if ($import_options['mapping'][$field_slug]) {
334
- $mapping_rules = json_decode($import_options['mapping'][$field_slug], true);
335
-
336
- if (!empty($mapping_rules) and is_array($mapping_rules)) {
337
- foreach ($mapping_rules as $rule_number => $map_to) {
338
- if (!empty($map_to[trim($data[$field_slug])])){
339
- $data[$field_slug] = trim($map_to[trim($data[$field_slug])]);
340
- break;
341
- }
342
- }
343
- }
344
- }
345
- // --------------------
346
-
347
-
348
- }
349
-
350
- call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']);
351
- }
352
-
353
- }
354
-
355
-
356
- function wpai_api_metabox($post_type, $current_values) {
357
-
358
- if (!$this->is_active_addon($post_type)) {
359
- return;
360
- }
361
-
362
- echo $this->helper_metabox_top($this->name);
363
-
364
- $visible_fields = 0;
365
-
366
- foreach ($this->fields as $field_slug => $field_params) {
367
- if ($field_params['is_sub_field']) continue;
368
- $visible_fields++;
369
- }
370
-
371
- $counter = 0;
372
-
373
- foreach ($this->fields as $field_slug => $field_params) {
374
-
375
- // do not render sub fields
376
- if ($field_params['is_sub_field']) continue;
377
-
378
- $counter++;
379
-
380
- $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter);
381
-
382
- //if ( $field_params['type'] != 'accordion' ) echo "<br />";
383
-
384
- }
385
-
386
- echo $this->helper_metabox_bottom();
387
-
388
- if ( ! empty($this->image_sections) ){
389
- $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type);
390
- foreach ($this->image_sections as $k => $section) {
391
- $section_options = array();
392
- foreach ($this->image_options as $slug => $value) {
393
- $section_options[$section['slug'] . $slug] = $value;
394
- }
395
- if ( ! $is_images_section_enabled and ! $k ){
396
- $section_options[$section['slug'] . 'is_featured'] = 1;
397
- }
398
- PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']);
399
- }
400
- }
401
-
402
- }
403
-
404
- function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){
405
-
406
- if ($field_params['type'] == 'text') {
407
-
408
- PMXI_API::add_field(
409
- 'simple',
410
- $field_params['name'],
411
- array(
412
- 'tooltip' => $field_params['tooltip'],
413
- 'field_name' => $this->slug."[".$field_slug."]",
414
- 'field_value' => $current_values[$this->slug][$field_slug]
415
- )
416
- );
417
-
418
- } else if ($field_params['type'] == 'textarea') {
419
-
420
- PMXI_API::add_field(
421
- 'textarea',
422
- $field_params['name'],
423
- array(
424
- 'tooltip' => $field_params['tooltip'],
425
- 'field_name' => $this->slug."[".$field_slug."]",
426
- 'field_value' => $current_values[$this->slug][$field_slug]
427
- )
428
- );
429
-
430
- } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') {
431
-
432
- PMXI_API::add_field(
433
- $field_params['type'],
434
- $field_params['name'],
435
- array(
436
- 'tooltip' => $field_params['tooltip'],
437
- 'field_name' => $this->slug."[".$field_slug."]",
438
- 'field_value' => $current_values[$this->slug][$field_slug],
439
- 'download_image' => $current_values[$this->slug]['download_image'][$field_slug],
440
- 'field_key' => $field_slug,
441
- 'addon_prefix' => $this->slug
442
-
443
- )
444
- );
445
-
446
- } else if ($field_params['type'] == 'radio') {
447
-
448
- PMXI_API::add_field(
449
- 'enum',
450
- $field_params['name'],
451
- array(
452
- 'tooltip' => $field_params['tooltip'],
453
- 'field_name' => $this->slug."[".$field_slug."]",
454
- 'field_value' => $current_values[$this->slug][$field_slug],
455
- 'enum_values' => $field_params['enum_values'],
456
- 'mapping' => true,
457
- 'field_key' => $field_slug,
458
- 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug],
459
- 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug],
460
- 'addon_prefix' => $this->slug,
461
- 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values)
462
- )
463
- );
464
-
465
- } else if($field_params['type'] == 'accordion') {
466
-
467
- PMXI_API::add_field(
468
- 'accordion',
469
- $field_params['name'],
470
- array(
471
- 'tooltip' => $field_params['tooltip'],
472
- 'field_name' => $this->slug."[".$field_slug."]",
473
- 'field_key' => $field_slug,
474
- 'addon_prefix' => $this->slug,
475
- 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values),
476
- 'in_the_bottom' => $in_the_bottom
477
- )
478
- );
479
-
480
- } else if($field_params['type'] == 'title'){
481
- ?>
482
- <h4 class="wpallimport-add-on-options-title"><?php _e($field_params['name'], 'wp_all_import_plugin'); ?><?php if ( ! empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo $field_params['tooltip']; ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4>
483
- <?php
484
-
485
- } else if($field_params['type'] == 'plain_text'){
486
-
487
- ?>
488
- <p style="margin: 0 0 12px 0;"><?php echo $field_params['name'];?></p>
489
- <?php
490
-
491
- }
492
-
493
-
494
- }
495
- /**
496
- *
497
- * Helper function for nested radio fields
498
- *
499
- */
500
- function get_sub_fields($field_params, $field_slug, $current_values){
501
- $sub_fields = array();
502
- if ( ! empty($field_params['enum_values']) ){
503
- foreach ($field_params['enum_values'] as $key => $value) {
504
- $sub_fields[$key] = array();
505
- if (is_array($value)){
506
- if ($field_params['type'] == 'accordion'){
507
- $sub_fields[$key][] = $this->convert_field($value, $current_values);
508
- }
509
- else
510
- {
511
- foreach ($value as $k => $sub_field) {
512
- if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']]))
513
- {
514
- $sub_fields[$key][] = $this->convert_field($sub_field, $current_values);
515
- }
516
- }
517
- }
518
- }
519
- }
520
- }
521
- return $sub_fields;
522
- }
523
-
524
- function convert_field($sub_field, $current_values){
525
- $field = array();
526
- switch ($this->fields[$sub_field['slug']]['type']) {
527
- case 'text':
528
- $field = array(
529
- 'type' => 'simple',
530
- 'label' => $this->fields[$sub_field['slug']]['name'],
531
- 'params' => array(
532
- 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
533
- 'field_name' => $this->slug."[".$sub_field['slug']."]",
534
- 'field_value' => $current_values[$this->slug][$sub_field['slug']],
535
- 'is_main_field' => $sub_field['is_main_field']
536
- )
537
- );
538
- break;
539
- case 'textarea':
540
- $field = array(
541
- 'type' => 'textarea',
542
- 'label' => $this->fields[$sub_field['slug']]['name'],
543
- 'params' => array(
544
- 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
545
- 'field_name' => $this->slug."[".$sub_field['slug']."]",
546
- 'field_value' => $current_values[$this->slug][$sub_field['slug']],
547
- 'is_main_field' => $sub_field['is_main_field']
548
- )
549
- );
550
- break;
551
- case 'image':
552
- $field = array(
553
- 'type' => 'image',
554
- 'label' => $this->fields[$sub_field['slug']]['name'],
555
- 'params' => array(
556
- 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
557
- 'field_name' => $this->slug."[".$sub_field['slug']."]",
558
- 'field_value' => $current_values[$this->slug][$sub_field['slug']],
559
- 'download_image' => $current_values[$this->slug]['download_image'][$sub_field['slug']],
560
- 'field_key' => $sub_field['slug'],
561
- 'addon_prefix' => $this->slug,
562
- 'is_main_field' => $sub_field['is_main_field']
563
- )
564
- );
565
- case 'file':
566
- $field = array(
567
- 'type' => 'file',
568
- 'label' => $this->fields[$sub_field['slug']]['name'],
569
- 'params' => array(
570
- 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
571
- 'field_name' => $this->slug."[".$sub_field['slug']."]",
572
- 'field_value' => $current_values[$this->slug][$sub_field['slug']],
573
- 'download_image' => $current_values[$this->slug]['download_image'][$sub_field['slug']],
574
- 'field_key' => $sub_field['slug'],
575
- 'addon_prefix' => $this->slug,
576
- 'is_main_field' => $sub_field['is_main_field']
577
- )
578
- );
579
- break;
580
- case 'radio':
581
- $field = array(
582
- 'type' => 'enum',
583
- 'label' => $this->fields[$sub_field['slug']]['name'],
584
- 'params' => array(
585
- 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
586
- 'field_name' => $this->slug."[".$sub_field['slug']."]",
587
- 'field_value' => $current_values[$this->slug][$sub_field['slug']],
588
- 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'],
589
- 'mapping' => true,
590
- 'field_key' => $sub_field['slug'],
591
- 'mapping_rules' => $current_values[$this->slug]['mapping'][$sub_field['slug']],
592
- 'xpath' => $current_values[$this->slug]['xpaths'][$sub_field['slug']],
593
- 'addon_prefix' => $this->slug,
594
- 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values),
595
- 'is_main_field' => $sub_field['is_main_field']
596
- )
597
- );
598
- break;
599
- case 'accordion':
600
- $field = array(
601
- 'type' => 'accordion',
602
- 'label' => $this->fields[$sub_field['slug']]['name'],
603
- 'params' => array(
604
- 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
605
- 'field_name' => $this->slug."[".$sub_field['slug']."]",
606
- 'field_key' => $sub_field['slug'],
607
- 'addon_prefix' => $this->slug,
608
- 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values),
609
- 'in_the_bottom' => false
610
- )
611
- );
612
- break;
613
- default:
614
- # code...
615
- break;
616
- }
617
- return $field;
618
- }
619
-
620
- /**
621
- *
622
- * Add accordion options
623
- *
624
- *
625
- */
626
- function add_options( $main_field = false, $title = '', $fields = array() ){
627
-
628
- if ( ! empty($fields) )
629
- {
630
-
631
- if ($main_field){
632
-
633
- $main_field['is_main_field'] = true;
634
- $fields[] = $main_field;
635
-
636
- }
637
-
638
- return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields);
639
-
640
- }
641
-
642
- }
643
-
644
- function add_title($title = '', $tooltip = ''){
645
-
646
- if (empty($title)) return;
647
-
648
- return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip);
649
-
650
- }
651
-
652
- function add_text($text = ''){
653
-
654
- if (empty($text)) return;
655
-
656
- return $this->add_field(sanitize_key($text) . time(), $text, 'plain_text');
657
-
658
- }
659
-
660
- function helper_metabox_top($name) {
661
-
662
- return '
663
- <style type="text/css">
664
- .wpallimport-plugin .wpallimport-addon div.input {
665
- margin-bottom: 15px;
666
- }
667
- .wpallimport-plugin .wpallimport-addon .custom-params tr td.action{
668
- width: auto !important;
669
- }
670
- .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions{
671
- right:0 !important;
672
- }
673
- .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper{
674
- width: 80%;
675
- }
676
- .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper input{
677
- width: 100%;
678
- }
679
- .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions{
680
- float: right;
681
- right: 30px;
682
- position: relative;
683
- border: 1px solid #ddd;
684
- margin-bottom: 10px;
685
- }
686
-
687
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options {
688
- margin-bottom: 15px;
689
- margin-top: -16px;
690
- }
691
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-content-section{
692
- padding-bottom: 8px;
693
- margin:0;
694
- border: none;
695
- padding-top: 1px;
696
- background: #f1f2f2;
697
- }
698
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header{
699
- padding-left: 13px;
700
- }
701
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header h3{
702
- font-size: 14px;
703
- margin: 6px 0;
704
- }
705
-
706
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width{
707
- bottom: -40px;
708
- margin-bottom: 0;
709
- margin-left: -25px;
710
- margin-right: -25px;
711
- position: relative;
712
- }
713
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-content-section{
714
- margin:0;
715
- border-top:1px solid #ddd;
716
- border-bottom: none;
717
- border-right: none;
718
- border-left: none;
719
- background: #f1f2f2;
720
- }
721
- .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-collapsed-header h3{
722
- margin: 14px 0;
723
- }
724
-
725
- .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options{
726
- margin-left: 1px;
727
- margin-right: -1px;
728
- }
729
- .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options .wpallimport-content-section{
730
- border: 1px solid #ddd;
731
- border-top: none;
732
- }
733
- .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-bottom{
734
- margin-left: -25px;
735
- margin-right: -25px;
736
- }
737
- .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom{
738
- margin: 25px -1px 25px 1px;
739
- }
740
- .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom .wpallimport-content-section{
741
- border: 1px solid #ddd;
742
- }
743
- .wpallimport-plugin .wpallimport-addon .wpallimport-add-on-options-title{
744
- font-size: 14px;
745
- margin: 45px 0 15px 0;
746
- }
747
- </style>
748
- <div class="wpallimport-collapsed wpallimport-section wpallimport-addon '.$this->slug.' closed">
749
- <div class="wpallimport-content-section">
750
- <div class="wpallimport-collapsed-header">
751
- <h3>'.__($name,'pmxi_plugin').'</h3>
752
- </div>
753
- <div class="wpallimport-collapsed-content" style="padding: 0;">
754
- <div class="wpallimport-collapsed-content-inner">
755
- <table class="form-table" style="max-width:none;">
756
- <tr>
757
- <td colspan="3">';
758
- }
759
-
760
- function helper_metabox_bottom() {
761
-
762
- return ' </td>
763
- </tr>
764
- </table>
765
- </div>
766
- </div>
767
- </div>
768
- </div>';
769
-
770
- }
771
-
772
- /**
773
- *
774
- * simply add an additional section for attachments
775
- *
776
- */
777
- function import_files( $slug, $title ){
778
- $this->import_images( $slug, $title, 'files');
779
- }
780
-
781
- /**
782
- *
783
- * simply add an additional section
784
- *
785
- */
786
- function import_images( $slug, $title, $type = 'images' ){
787
-
788
- if ( empty($title) or empty($slug) ) return;
789
-
790
- $section_slug = 'pmxi_' . $slug;
791
-
792
- $this->image_sections[] = array(
793
- 'title' => $title,
794
- 'slug' => $section_slug,
795
- 'type' => $type
796
- );
797
-
798
- foreach ($this->image_options as $option_slug => $value) {
799
- $this->add_option($section_slug . $option_slug, $value);
800
- }
801
-
802
- if (count($this->image_sections) > 1){
803
- add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2);
804
- }
805
-
806
- add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2);
807
-
808
- if (function_exists($slug)) add_action( $section_slug, $slug, 10, 4);
809
- }
810
- /**
811
- *
812
- * filter to allow import images for free edition of WP All Import
813
- *
814
- */
815
- function is_allow_import_images($is_allow, $post_type){
816
- return ($this->is_active_addon($post_type)) ? true : $is_allow;
817
- }
818
-
819
- /**
820
- *
821
- * filter to control additional images sections
822
- *
823
- */
824
- function additional_sections($sections){
825
- if ( ! empty($this->image_sections) ){
826
- foreach ($this->image_sections as $add_section) {
827
- $sections[] = $add_section;
828
- }
829
- }
830
-
831
- return $sections;
832
- }
833
- /**
834
- *
835
- * remove the 'Don't touch existing images, append new images' when more than one image section is in use.
836
- *
837
- */
838
- function filter_is_show_add_new_images($is_show, $post_type){
839
- return ($this->is_active_addon($post_type)) ? false : $is_show;
840
- }
841
-
842
- /**
843
- *
844
- * disable the default images section
845
- *
846
- */
847
- function disable_default_images($post_type = false){
848
-
849
- add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2);
850
-
851
- }
852
- function is_enable_default_images_section($is_enabled, $post_type){
853
-
854
- return ($this->is_active_addon($post_type)) ? false : true;
855
-
856
- }
857
-
858
- function helper_parse($parsingData, $options) {
859
-
860
- extract($parsingData);
861
-
862
- $data = array(); // parsed data
863
-
864
- if ( ! empty($import->options[$this->slug])){
865
-
866
- $this->logger = $parsingData['logger'];
867
-
868
- $cxpath = $xpath_prefix . $import->xpath;
869
-
870
- $tmp_files = array();
871
-
872
- foreach ($options[$this->slug] as $option_name => $option_value) {
873
- if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') {
874
- if ($import->options[$this->slug][$option_name] == "xpath") {
875
- if ($import->options[$this->slug]['xpaths'][$option_name] == ""){
876
- $count and $this->data[$option_name] = array_fill(0, $count, "");
877
- } else {
878
- $data[$option_name] = XmlImportParser::factory($xml, $cxpath, $import->options[$this->slug]['xpaths'][$option_name], $file)->parse($records);
879
- $tmp_files[] = $file;
880
- }
881
- }
882
- else {
883
- $data[$option_name] = XmlImportParser::factory($xml, $cxpath, $import->options[$this->slug][$option_name], $file)->parse();
884
- $tmp_files[] = $file;
885
- }
886
-
887
-
888
- } else {
889
- $data[$option_name] = array_fill(0, $count, "");
890
- }
891
-
892
- }
893
-
894
- foreach ($tmp_files as $file) { // remove all temporary files created
895
- unlink($file);
896
- }
897
-
898
- }
899
-
900
- return $data;
901
- }
902
-
903
-
904
- function can_update_meta($meta_key, $import_options) {
905
-
906
- //echo "<pre>";
907
- //print_r($import_options['options']);
908
- //echo "</pre>";
909
-
910
- $import_options = $import_options['options'];
911
-
912
- if ($import_options['update_all_data'] == 'yes') return true;
913
-
914
- if ( ! $import_options['is_update_custom_fields'] ) return false;
915
-
916
- if ($import_options['update_custom_fields_logic'] == "full_update") return true;
917
- if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true;
918
- if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true;
919
-
920
- return false;
921
-
922
- }
923
-
924
- function can_update_image($import_options) {
925
-
926
- $import_options = $import_options['options'];
927
-
928
- if ($import_options['update_all_data'] == 'yes') return true;
929
-
930
- if (!$import_options['is_update_images']) return false;
931
-
932
- if ($import_options['is_update_images']) return true;
933
-
934
- return false;
935
- }
936
-
937
-
938
- function admin_notice_ignore() {
939
- if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) {
940
- update_option($this->slug.'_ignore', 'true');
941
- }
942
- }
943
-
944
- function display_admin_notice() {
945
-
946
-
947
- if ($this->notice_text) {
948
- $notice_text = $this->notice_text;
949
- } else {
950
- $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.';
951
- }
952
-
953
- if (!get_option(sanitize_key($this->slug).'_notice_ignore')) {
954
-
955
- ?>
956
-
957
- <div class="error notice is-dismissible wpallimport-dismissible" style="margin-top: 10px;" rel="<?php echo sanitize_key($this->slug); ?>">
958
- <p><?php _e(
959
- sprintf(
960
- $notice_text,
961
- '?'.$this->slug.'_ignore=0'
962
- ),
963
- 'rapid_addon_'.$this->slug
964
- ); ?></p>
965
- </div>
966
-
967
- <?php
968
-
969
- }
970
-
971
- }
972
-
973
- /*
974
- *
975
- * $conditions - array('themes' => array('Realia'), 'plugins' => array('plugin-directory/plugin-file.php', 'plugin-directory2/plugin-file.php'))
976
- *
977
- */
978
- function admin_notice($notice_text = '', $conditions = array()) {
979
-
980
- $is_show_notice = false;
981
-
982
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
983
-
984
- if ( ! is_plugin_active('wp-all-import-pro/wp-all-import-pro.php') and ! is_plugin_active('wp-all-import/plugin.php') ){
985
- $is_show_notice = true;
986
- }
987
-
988
- // Supported Themes
989
- if ( ! $is_show_notice and ! empty($conditions['themes']) ){
990
-
991
- $themeInfo = wp_get_theme();
992
- $parentInfo = $themeInfo->parent();
993
- $currentTheme = $themeInfo->get('Name');
994
-
995
- $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true;
996
-
997
- if ( $is_show_notice and $parentInfo ){
998
- $parent_theme = $parentInfo->get('Name');
999
- $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true;
1000
- }
1001
-
1002
- }
1003
-
1004
- // Required Plugins
1005
- if ( ! $is_show_notice and ! empty($conditions['plugins']) ){
1006
-
1007
- $requires_counter = 0;
1008
- foreach ($conditions['plugins'] as $plugin) {
1009
- if ( is_plugin_active($plugin) ) $requires_counter++;
1010
- }
1011
-
1012
- if ($requires_counter != count($conditions['plugins'])){
1013
- $is_show_notice = true;
1014
- }
1015
-
1016
- }
1017
-
1018
- if ( $is_show_notice ){
1019
-
1020
- if ( $notice_text != '' ) {
1021
- $this->notice_text = $notice_text;
1022
- }
1023
-
1024
- add_action('admin_notices', array($this, 'display_admin_notice'));
1025
- }
1026
-
1027
- }
1028
-
1029
- function log( $m = false){
1030
-
1031
- $m and $this->logger and call_user_func($this->logger, $m);
1032
-
1033
- }
1034
- }
1035
-
1036
- }
1037
-
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!class_exists('RapidAddon')) {
4
+
5
+ class RapidAddon {
6
+
7
+ public $name;
8
+ public $slug;
9
+ public $fields;
10
+ public $options = array();
11
+ public $accordions = array();
12
+ public $image_sections = array();
13
+ public $import_function;
14
+ public $post_saved_function;
15
+ public $notice_text;
16
+ public $logger = null;
17
+ public $when_to_run = false;
18
+ public $image_options = array(
19
+ 'download_images' => 'yes',
20
+ 'download_featured_delim' => ',',
21
+ 'download_featured_image' => '',
22
+ 'gallery_featured_image' => '',
23
+ 'gallery_featured_delim' => ',',
24
+ 'featured_image' => '',
25
+ 'featured_delim' => ',',
26
+ 'search_existing_images' => 1,
27
+ 'is_featured' => 0,
28
+ 'create_draft' => 'no',
29
+ 'set_image_meta_title' => 0,
30
+ 'image_meta_title_delim' => ',',
31
+ 'image_meta_title' => '',
32
+ 'set_image_meta_caption' => 0,
33
+ 'image_meta_caption_delim' => ',',
34
+ 'image_meta_caption' => '',
35
+ 'set_image_meta_alt' => 0,
36
+ 'image_meta_alt_delim' => ',',
37
+ 'image_meta_alt' => '',
38
+ 'set_image_meta_description' => 0,
39
+ 'image_meta_description_delim' => ',',
40
+ 'image_meta_description_delim_logic' => 'separate',
41
+ 'image_meta_description' => '',
42
+ 'auto_rename_images' => 0,
43
+ 'auto_rename_images_suffix' => '',
44
+ 'auto_set_extension' => 0,
45
+ 'new_extension' => ''
46
+ );
47
+
48
+ function __construct($name, $slug) {
49
+
50
+ $this->name = $name;
51
+ $this->slug = $slug;
52
+
53
+ }
54
+
55
+ function set_import_function($name) {
56
+ $this->import_function = $name;
57
+ }
58
+
59
+ function set_post_saved_function($name) {
60
+ $this->post_saved_function = $name;
61
+ }
62
+
63
+ function is_active_addon($post_type = null) {
64
+
65
+ if ( ! is_plugin_active('wp-all-import-pro/wp-all-import-pro.php') and ! is_plugin_active('wp-all-import/plugin.php') ){
66
+ return false;
67
+ }
68
+
69
+ $addon_active = false;
70
+
71
+ if ($post_type !== null) {
72
+ if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) {
73
+ $addon_active = true;
74
+ }
75
+ }
76
+
77
+ if ($addon_active){
78
+
79
+ $current_theme = wp_get_theme();
80
+
81
+ $parent_theme = $current_theme->parent();
82
+
83
+ $theme_name = $current_theme->get('Name');
84
+
85
+ $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false;
86
+
87
+ if ( ! $addon_active and $parent_theme ){
88
+ $parent_theme_name = $parent_theme->get('Name');
89
+ $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false;
90
+
91
+ }
92
+
93
+ if ( $addon_active and ! empty($this->active_plugins) ){
94
+
95
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
96
+
97
+ foreach ($this->active_plugins as $plugin) {
98
+ if ( ! is_plugin_active($plugin) ) {
99
+ $addon_active = false;
100
+ break;
101
+ }
102
+ }
103
+ }
104
+
105
+ }
106
+
107
+ if ($this->when_to_run == "always") {
108
+ return true;
109
+ }
110
+
111
+ return $addon_active;
112
+ }
113
+
114
+ /**
115
+ *
116
+ * Add-On Initialization
117
+ *
118
+ * @param array $conditions - list of supported themes and post types
119
+ *
120
+ */
121
+ function run($conditions = array()) {
122
+
123
+ if (empty($conditions)) {
124
+ $this->when_to_run = "always";
125
+ }
126
+
127
+ @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array();
128
+ @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array();
129
+ @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array();
130
+
131
+ add_filter('pmxi_addons', array($this, 'wpai_api_register'));
132
+ add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse'));
133
+ add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import'));
134
+ add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved'));
135
+ add_filter('pmxi_options_options', array($this, 'wpai_api_options'));
136
+ add_filter('wp_all_import_image_sections', array($this, 'additional_sections'), 10, 1);
137
+ add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2);
138
+ add_action('admin_init', array($this, 'admin_notice_ignore'));
139
+
140
+ }
141
+
142
+ function parse($data) {
143
+
144
+ if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false;
145
+
146
+ $parsedData = $this->helper_parse($data, $this->options_array());
147
+ return $parsedData;
148
+
149
+ }
150
+
151
+
152
+ function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true) {
153
+
154
+ $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html);
155
+
156
+ $this->fields[$field_slug] = $field;
157
+
158
+ if ( ! empty($enum_values) ){
159
+ foreach ($enum_values as $key => $value) {
160
+ if (is_array($value))
161
+ {
162
+ if ($field['type'] == 'accordion')
163
+ {
164
+ $this->fields[$value['slug']]['is_sub_field'] = true;
165
+ }
166
+ else
167
+ {
168
+ foreach ($value as $n => $param) {
169
+ if (is_array($param) and ! empty($this->fields[$param['slug']])){
170
+ $this->fields[$param['slug']]['is_sub_field'] = true;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ return $field;
179
+
180
+ }
181
+
182
+ /**
183
+ *
184
+ * Add an option to WP All Import options list
185
+ *
186
+ * @param string $slug - option name
187
+ * @param string $default_value - default option value
188
+ *
189
+ */
190
+ function add_option($slug, $default_value = ''){
191
+ $this->options[$slug] = $default_value;
192
+ }
193
+
194
+ function options_array() {
195
+
196
+ $options_list = array();
197
+
198
+ foreach ($this->fields as $field_slug => $field_params) {
199
+ if (in_array($field_params['type'], array('title', 'plain_text'))) continue;
200
+ $default_value = '';
201
+ if (!empty($field_params['enum_values'])){
202
+ foreach ($field_params['enum_values'] as $key => $value) {
203
+ $default_value = $key;
204
+ break;
205
+ }
206
+ }
207
+ $options_list[$field_slug] = $default_value;
208
+ }
209
+
210
+ if ( ! empty($this->options) ){
211
+ foreach ($this->options as $slug => $value) {
212
+ $options_arr[$slug] = $value;
213
+ }
214
+ }
215
+
216
+ $options_arr[$this->slug] = $options_list;
217
+ $options_arr['rapid_addon'] = plugin_basename( __FILE__ );
218
+
219
+ return $options_arr;
220
+
221
+ }
222
+
223
+ function wpai_api_options($all_options) {
224
+
225
+ $all_options = $all_options + $this->options_array();
226
+
227
+ return $all_options;
228
+
229
+ }
230
+
231
+
232
+ function wpai_api_register($addons) {
233
+
234
+ if (empty($addons[$this->slug])) {
235
+ $addons[$this->slug] = 1;
236
+ }
237
+
238
+ return $addons;
239
+
240
+ }
241
+
242
+
243
+ function wpai_api_parse($functions) {
244
+
245
+ $functions[$this->slug] = array($this, 'parse');
246
+ return $functions;
247
+
248
+ }
249
+
250
+ function wpai_api_post_saved($functions){
251
+ $functions[$this->slug] = array($this, 'post_saved');
252
+ return $functions;
253
+ }
254
+
255
+
256
+ function wpai_api_import($functions) {
257
+
258
+ $functions[$this->slug] = array($this, 'import');
259
+ return $functions;
260
+
261
+ }
262
+
263
+ function post_saved( $importData ){
264
+
265
+ if (is_callable($this->post_saved_function))
266
+ call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']);
267
+
268
+ }
269
+
270
+ function import($importData, $parsedData) {
271
+
272
+ if (!$this->is_active_addon($importData['post_type'])) {
273
+ return;
274
+ }
275
+
276
+ $import_options = $importData['import']['options'][$this->slug];
277
+
278
+ // echo "<pre>";
279
+ // print_r($import_options);
280
+ // echo "</pre>";
281
+
282
+ if ( ! empty($parsedData) ) {
283
+
284
+ $this->logger = $importData['logger'];
285
+
286
+ $post_id = $importData['pid'];
287
+ $index = $importData['i'];
288
+
289
+ foreach ($this->fields as $field_slug => $field_params) {
290
+
291
+ if (in_array($field_params['type'], array('title', 'plain_text'))) continue;
292
+
293
+ switch ($field_params['type']) {
294
+
295
+ case 'image':
296
+
297
+ // import the specified image, then set the value of the field to the image ID in the media library
298
+
299
+ $image_url_or_path = $parsedData[$field_slug][$index];
300
+
301
+ $download = $import_options['download_image'][$field_slug];
302
+
303
+ $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true);
304
+
305
+ $data[$field_slug] = array(
306
+ "attachment_id" => $uploaded_image,
307
+ "image_url_or_path" => $image_url_or_path,
308
+ "download" => $download
309
+ );
310
+
311
+ break;
312
+
313
+ case 'file':
314
+
315
+ $image_url_or_path = $parsedData[$field_slug][$index];
316
+
317
+ $download = $import_options['download_image'][$field_slug];
318
+
319
+ $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files");
320
+
321
+ $data[$field_slug] = array(
322
+ "attachment_id" => $uploaded_file,
323
+ "image_url_or_path" => $image_url_or_path,
324
+ "download" => $download
325
+ );
326
+
327
+ break;
328
+
329
+ default:
330
+ // set the field data to the value of the field after it's been parsed
331
+ $data[$field_slug] = $parsedData[$field_slug][$index];
332
+ break;
333
+ }
334
+
335
+ // apply mapping rules if they exist
336
+ if ($import_options['mapping'][$field_slug]) {
337
+ $mapping_rules = json_decode($import_options['mapping'][$field_slug], true);
338
+
339
+ if (!empty($mapping_rules) and is_array($mapping_rules)) {
340
+ foreach ($mapping_rules as $rule_number => $map_to) {
341
+ if (!empty($map_to[trim($data[$field_slug])])){
342
+ $data[$field_slug] = trim($map_to[trim($data[$field_slug])]);
343
+ break;
344
+ }
345
+ }
346
+ }
347
+ }
348
+ // --------------------
349
+
350
+
351
+ }
352
+
353
+ call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']);
354
+ }
355
+
356
+ }
357
+
358
+
359
+ function wpai_api_metabox($post_type, $current_values) {
360
+
361
+ if (!$this->is_active_addon($post_type)) {
362
+ return;
363
+ }
364
+
365
+ echo $this->helper_metabox_top($this->name);
366
+
367
+ $visible_fields = 0;
368
+
369
+ foreach ($this->fields as $field_slug => $field_params) {
370
+ if ($field_params['is_sub_field']) continue;
371
+ $visible_fields++;
372
+ }
373
+
374
+ $counter = 0;
375
+
376
+ foreach ($this->fields as $field_slug => $field_params) {
377
+
378
+ // do not render sub fields
379
+ if ($field_params['is_sub_field']) continue;
380
+
381
+ $counter++;
382
+
383
+ $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter);
384
+
385
+ //if ( $field_params['type'] != 'accordion' ) echo "<br />";
386
+
387
+ }
388
+
389
+ echo $this->helper_metabox_bottom();
390
+
391
+ if ( ! empty($this->image_sections) ){
392
+ $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type);
393
+ foreach ($this->image_sections as $k => $section) {
394
+ $section_options = array();
395
+ foreach ($this->image_options as $slug => $value) {
396
+ $section_options[$section['slug'] . $slug] = $value;
397
+ }
398
+ if ( ! $is_images_section_enabled and ! $k ){
399
+ $section_options[$section['slug'] . 'is_featured'] = 1;
400
+ }
401
+ PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']);
402
+ }
403
+ }
404
+
405
+ }
406
+
407
+ function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){
408
+
409
+ if (!isset($current_values[$this->slug][$field_slug])) { $current_values[$this->slug][$field_slug] = ''; }
410
+
411
+ if ($field_params['type'] == 'text') {
412
+
413
+ PMXI_API::add_field(
414
+ 'simple',
415
+ $field_params['name'],
416
+ array(
417
+ 'tooltip' => $field_params['tooltip'],
418
+ 'field_name' => $this->slug."[".$field_slug."]",
419
+ 'field_value' => $current_values[$this->slug][$field_slug]
420
+ )
421
+ );
422
+
423
+ } else if ($field_params['type'] == 'textarea') {
424
+
425
+ PMXI_API::add_field(
426
+ 'textarea',
427
+ $field_params['name'],
428
+ array(
429
+ 'tooltip' => $field_params['tooltip'],
430
+ 'field_name' => $this->slug."[".$field_slug."]",
431
+ 'field_value' => $current_values[$this->slug][$field_slug]
432
+ )
433
+ );
434
+
435
+ } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') {
436
+
437
+ if (!isset($current_values[$this->slug]['download_image'][$field_slug])) { $current_values[$this->slug]['download_image'][$field_slug] = ''; }
438
+
439
+ PMXI_API::add_field(
440
+ $field_params['type'],
441
+ $field_params['name'],
442
+ array(
443
+ 'tooltip' => $field_params['tooltip'],
444
+ 'field_name' => $this->slug."[".$field_slug."]",
445
+ 'field_value' => $current_values[$this->slug][$field_slug],
446
+ 'download_image' => $current_values[$this->slug]['download_image'][$field_slug],
447
+ 'field_key' => $field_slug,
448
+ 'addon_prefix' => $this->slug
449
+
450
+ )
451
+ );
452
+
453
+ } else if ($field_params['type'] == 'radio') {
454
+
455
+ if (!isset($current_values[$this->slug]['mapping'][$field_slug])) { $current_values[$this->slug]['mapping'][$field_slug] = array(); }
456
+ if (!isset($current_values[$this->slug]['xpaths'][$field_slug])) { $current_values[$this->slug]['xpaths'][$field_slug] = ''; }
457
+
458
+ PMXI_API::add_field(
459
+ 'enum',
460
+ $field_params['name'],
461
+ array(
462
+ 'tooltip' => $field_params['tooltip'],
463
+ 'field_name' => $this->slug."[".$field_slug."]",
464
+ 'field_value' => $current_values[$this->slug][$field_slug],
465
+ 'enum_values' => $field_params['enum_values'],
466
+ 'mapping' => true,
467
+ 'field_key' => $field_slug,
468
+ 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug],
469
+ 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug],
470
+ 'addon_prefix' => $this->slug,
471
+ 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values)
472
+ )
473
+ );
474
+
475
+ } else if($field_params['type'] == 'accordion') {
476
+
477
+ PMXI_API::add_field(
478
+ 'accordion',
479
+ $field_params['name'],
480
+ array(
481
+ 'tooltip' => $field_params['tooltip'],
482
+ 'field_name' => $this->slug."[".$field_slug."]",
483
+ 'field_key' => $field_slug,
484
+ 'addon_prefix' => $this->slug,
485
+ 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values),
486
+ 'in_the_bottom' => $in_the_bottom
487
+ )
488
+ );
489
+
490
+ } else if($field_params['type'] == 'title'){
491
+ ?>
492
+ <h4 class="wpallimport-add-on-options-title"><?php _e($field_params['name'], 'wp_all_import_plugin'); ?><?php if ( ! empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo $field_params['tooltip']; ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4>
493
+ <?php
494
+
495
+ } else if($field_params['type'] == 'plain_text'){
496
+ if ($field_params['is_html']):
497
+ echo $field_params['name'];
498
+ else:
499
+ ?>
500
+ <p style="margin: 0 0 12px 0;"><?php echo $field_params['name'];?></p>
501
+ <?php
502
+ endif;
503
+ }
504
+
505
+
506
+ }
507
+ /**
508
+ *
509
+ * Helper function for nested radio fields
510
+ *
511
+ */
512
+ function get_sub_fields($field_params, $field_slug, $current_values){
513
+ $sub_fields = array();
514
+ if ( ! empty($field_params['enum_values']) ){
515
+ foreach ($field_params['enum_values'] as $key => $value) {
516
+ $sub_fields[$key] = array();
517
+ if (is_array($value)){
518
+ if ($field_params['type'] == 'accordion'){
519
+ $sub_fields[$key][] = $this->convert_field($value, $current_values);
520
+ }
521
+ else
522
+ {
523
+ foreach ($value as $k => $sub_field) {
524
+ if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']]))
525
+ {
526
+ $sub_fields[$key][] = $this->convert_field($sub_field, $current_values);
527
+ }
528
+ }
529
+ }
530
+ }
531
+ }
532
+ }
533
+ return $sub_fields;
534
+ }
535
+
536
+ function convert_field($sub_field, $current_values){
537
+ $field = array();
538
+ switch ($this->fields[$sub_field['slug']]['type']) {
539
+ case 'text':
540
+ $field = array(
541
+ 'type' => 'simple',
542
+ 'label' => $this->fields[$sub_field['slug']]['name'],
543
+ 'params' => array(
544
+ 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
545
+ 'field_name' => $this->slug."[".$sub_field['slug']."]",
546
+ 'field_value' => $current_values[$this->slug][$sub_field['slug']],
547
+ 'is_main_field' => $sub_field['is_main_field']
548
+ )
549
+ );
550
+ break;
551
+ case 'textarea':
552
+ $field = array(
553
+ 'type' => 'textarea',
554
+ 'label' => $this->fields[$sub_field['slug']]['name'],
555
+ 'params' => array(
556
+ 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
557
+ 'field_name' => $this->slug."[".$sub_field['slug']."]",
558
+ 'field_value' => $current_values[$this->slug][$sub_field['slug']],
559
+ 'is_main_field' => $sub_field['is_main_field']
560
+ )
561
+ );
562
+ break;
563
+ case 'image':
564
+ $field = array(
565
+ 'type' => 'image',
566
+ 'label' => $this->fields[$sub_field['slug']]['name'],
567
+ 'params' => array(
568
+ 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
569
+ 'field_name' => $this->slug."[".$sub_field['slug']."]",
570
+ 'field_value' => $current_values[$this->slug][$sub_field['slug']],
571
+ 'download_image' => $current_values[$this->slug]['download_image'][$sub_field['slug']],
572
+ 'field_key' => $sub_field['slug'],
573
+ 'addon_prefix' => $this->slug,
574
+ 'is_main_field' => $sub_field['is_main_field']
575
+ )
576
+ );
577
+ case 'file':
578
+ $field = array(
579
+ 'type' => 'file',
580
+ 'label' => $this->fields[$sub_field['slug']]['name'],
581
+ 'params' => array(
582
+ 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
583
+ 'field_name' => $this->slug."[".$sub_field['slug']."]",
584
+ 'field_value' => $current_values[$this->slug][$sub_field['slug']],
585
+ 'download_image' => $current_values[$this->slug]['download_image'][$sub_field['slug']],
586
+ 'field_key' => $sub_field['slug'],
587
+ 'addon_prefix' => $this->slug,
588
+ 'is_main_field' => $sub_field['is_main_field']
589
+ )
590
+ );
591
+ break;
592
+ case 'radio':
593
+ $field = array(
594
+ 'type' => 'enum',
595
+ 'label' => $this->fields[$sub_field['slug']]['name'],
596
+ 'params' => array(
597
+ 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
598
+ 'field_name' => $this->slug."[".$sub_field['slug']."]",
599
+ 'field_value' => $current_values[$this->slug][$sub_field['slug']],
600
+ 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'],
601
+ 'mapping' => true,
602
+ 'field_key' => $sub_field['slug'],
603
+ 'mapping_rules' => $current_values[$this->slug]['mapping'][$sub_field['slug']],
604
+ 'xpath' => $current_values[$this->slug]['xpaths'][$sub_field['slug']],
605
+ 'addon_prefix' => $this->slug,
606
+ 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values),
607
+ 'is_main_field' => $sub_field['is_main_field']
608
+ )
609
+ );
610
+ break;
611
+ case 'accordion':
612
+ $field = array(
613
+ 'type' => 'accordion',
614
+ 'label' => $this->fields[$sub_field['slug']]['name'],
615
+ 'params' => array(
616
+ 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
617
+ 'field_name' => $this->slug."[".$sub_field['slug']."]",
618
+ 'field_key' => $sub_field['slug'],
619
+ 'addon_prefix' => $this->slug,
620
+ 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values),
621
+ 'in_the_bottom' => false
622
+ )
623
+ );
624
+ break;
625
+ default:
626
+ # code...
627
+ break;
628
+ }
629
+ return $field;
630
+ }
631
+
632
+ /**
633
+ *
634
+ * Add accordion options
635
+ *
636
+ *
637
+ */
638
+ function add_options( $main_field = false, $title = '', $fields = array() ){
639
+
640
+ if ( ! empty($fields) )
641
+ {
642
+
643
+ if ($main_field){
644
+
645
+ $main_field['is_main_field'] = true;
646
+ $fields[] = $main_field;
647
+
648
+ }
649
+
650
+ return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields);
651
+
652
+ }
653
+
654
+ }
655
+
656
+ function add_title($title = '', $tooltip = ''){
657
+
658
+ if (empty($title)) return;
659
+
660
+ return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip);
661
+
662
+ }
663
+
664
+ function add_text($text = '', $is_html = false){
665
+
666
+ if (empty($text)) return;
667
+
668
+ return $this->add_field(sanitize_key($text) . time(), $text, 'plain_text', null, "", $is_html);
669
+
670
+ }
671
+
672
+ function helper_metabox_top($name) {
673
+
674
+ return '
675
+ <style type="text/css">
676
+ .wpallimport-plugin .wpallimport-addon div.input {
677
+ margin-bottom: 15px;
678
+ }
679
+ .wpallimport-plugin .wpallimport-addon .custom-params tr td.action{
680
+ width: auto !important;
681
+ }
682
+ .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions{
683
+ right:0 !important;
684
+ }
685
+ .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper{
686
+ width: 80%;
687
+ }
688
+ .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper input{
689
+ width: 100%;
690
+ }
691
+ .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions{
692
+ float: right;
693
+ right: 30px;
694
+ position: relative;
695
+ border: 1px solid #ddd;
696
+ margin-bottom: 10px;
697
+ }
698
+
699
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options {
700
+ margin-bottom: 15px;
701
+ margin-top: -16px;
702
+ }
703
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-content-section{
704
+ padding-bottom: 8px;
705
+ margin:0;
706
+ border: none;
707
+ padding-top: 1px;
708
+ background: #f1f2f2;
709
+ }
710
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header{
711
+ padding-left: 13px;
712
+ }
713
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header h3{
714
+ font-size: 14px;
715
+ margin: 6px 0;
716
+ }
717
+
718
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width{
719
+ bottom: -40px;
720
+ margin-bottom: 0;
721
+ margin-left: -25px;
722
+ margin-right: -25px;
723
+ position: relative;
724
+ }
725
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-content-section{
726
+ margin:0;
727
+ border-top:1px solid #ddd;
728
+ border-bottom: none;
729
+ border-right: none;
730
+ border-left: none;
731
+ background: #f1f2f2;
732
+ }
733
+ .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-collapsed-header h3{
734
+ margin: 14px 0;
735
+ }
736
+
737
+ .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options{
738
+ margin-left: 1px;
739
+ margin-right: -1px;
740
+ }
741
+ .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options .wpallimport-content-section{
742
+ border: 1px solid #ddd;
743
+ border-top: none;
744
+ }
745
+ .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-bottom{
746
+ margin-left: -25px;
747
+ margin-right: -25px;
748
+ }
749
+ .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom{
750
+ margin: 25px -1px 25px 1px;
751
+ }
752
+ .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom .wpallimport-content-section{
753
+ border: 1px solid #ddd;
754
+ }
755
+ .wpallimport-plugin .wpallimport-addon .wpallimport-add-on-options-title{
756
+ font-size: 14px;
757
+ margin: 45px 0 15px 0;
758
+ }
759
+ </style>
760
+ <div class="wpallimport-collapsed wpallimport-section wpallimport-addon '.$this->slug.' closed">
761
+ <div class="wpallimport-content-section">
762
+ <div class="wpallimport-collapsed-header">
763
+ <h3>'.__($name,'pmxi_plugin').'</h3>
764
+ </div>
765
+ <div class="wpallimport-collapsed-content" style="padding: 0;">
766
+ <div class="wpallimport-collapsed-content-inner">
767
+ <table class="form-table" style="max-width:none;">
768
+ <tr>
769
+ <td colspan="3">';
770
+ }
771
+
772
+ function helper_metabox_bottom() {
773
+
774
+ return ' </td>
775
+ </tr>
776
+ </table>
777
+ </div>
778
+ </div>
779
+ </div>
780
+ </div>';
781
+
782
+ }
783
+
784
+ /**
785
+ *
786
+ * simply add an additional section for attachments
787
+ *
788
+ */
789
+ function import_files( $slug, $title ){
790
+ $this->import_images( $slug, $title, 'files');
791
+ }
792
+
793
+ /**
794
+ *
795
+ * simply add an additional section
796
+ *
797
+ */
798
+ function import_images( $slug, $title, $type = 'images' ){
799
+
800
+ if ( empty($title) or empty($slug) ) return;
801
+
802
+ $section_slug = 'pmxi_' . $slug;
803
+
804
+ $this->image_sections[] = array(
805
+ 'title' => $title,
806
+ 'slug' => $section_slug,
807
+ 'type' => $type
808
+ );
809
+
810
+ foreach ($this->image_options as $option_slug => $value) {
811
+ $this->add_option($section_slug . $option_slug, $value);
812
+ }
813
+
814
+ if (count($this->image_sections) > 1){
815
+ add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2);
816
+ }
817
+
818
+ add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2);
819
+
820
+ if (function_exists($slug)) add_action( $section_slug, $slug, 10, 4);
821
+ }
822
+ /**
823
+ *
824
+ * filter to allow import images for free edition of WP All Import
825
+ *
826
+ */
827
+ function is_allow_import_images($is_allow, $post_type){
828
+ return ($this->is_active_addon($post_type)) ? true : $is_allow;
829
+ }
830
+
831
+ /**
832
+ *
833
+ * filter to control additional images sections
834
+ *
835
+ */
836
+ function additional_sections($sections){
837
+ if ( ! empty($this->image_sections) ){
838
+ foreach ($this->image_sections as $add_section) {
839
+ $sections[] = $add_section;
840
+ }
841
+ }
842
+
843
+ return $sections;
844
+ }
845
+ /**
846
+ *
847
+ * remove the 'Don't touch existing images, append new images' when more than one image section is in use.
848
+ *
849
+ */
850
+ function filter_is_show_add_new_images($is_show, $post_type){
851
+ return ($this->is_active_addon($post_type)) ? false : $is_show;
852
+ }
853
+
854
+ /**
855
+ *
856
+ * disable the default images section
857
+ *
858
+ */
859
+ function disable_default_images($post_type = false){
860
+
861
+ add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2);
862
+
863
+ }
864
+ function is_enable_default_images_section($is_enabled, $post_type){
865
+
866
+ return ($this->is_active_addon($post_type)) ? false : true;
867
+
868
+ }
869
+
870
+ function helper_parse($parsingData, $options) {
871
+
872
+ extract($parsingData);
873
+
874
+ $data = array(); // parsed data
875
+
876
+ if ( ! empty($import->options[$this->slug])){
877
+
878
+ $this->logger = $parsingData['logger'];
879
+
880
+ $cxpath = $xpath_prefix . $import->xpath;
881
+
882
+ $tmp_files = array();
883
+
884
+ foreach ($options[$this->slug] as $option_name => $option_value) {
885
+ if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') {
886
+ if ($import->options[$this->slug][$option_name] == "xpath") {
887
+ if ($import->options[$this->slug]['xpaths'][$option_name] == ""){
888
+ $count and $this->data[$option_name] = array_fill(0, $count, "");
889
+ } else {
890
+ $data[$option_name] = XmlImportParser::factory($xml, $cxpath, $import->options[$this->slug]['xpaths'][$option_name], $file)->parse($records);
891
+ $tmp_files[] = $file;
892
+ }
893
+ }
894
+ else {
895
+ $data[$option_name] = XmlImportParser::factory($xml, $cxpath, $import->options[$this->slug][$option_name], $file)->parse();
896
+ $tmp_files[] = $file;
897
+ }
898
+
899
+
900
+ } else {
901
+ $data[$option_name] = array_fill(0, $count, "");
902
+ }
903
+
904
+ }
905
+
906
+ foreach ($tmp_files as $file) { // remove all temporary files created
907
+ unlink($file);
908
+ }
909
+
910
+ }
911
+
912
+ return $data;
913
+ }
914
+
915
+
916
+ function can_update_meta($meta_key, $import_options) {
917
+
918
+ //echo "<pre>";
919
+ //print_r($import_options['options']);
920
+ //echo "</pre>";
921
+
922
+ $import_options = $import_options['options'];
923
+
924
+ if ($import_options['update_all_data'] == 'yes') return true;
925
+
926
+ if ( ! $import_options['is_update_custom_fields'] ) return false;
927
+
928
+ if ($import_options['update_custom_fields_logic'] == "full_update") return true;
929
+ if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true;
930
+ if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true;
931
+
932
+ return false;
933
+
934
+ }
935
+
936
+ function can_update_image($import_options) {
937
+
938
+ $import_options = $import_options['options'];
939
+
940
+ if ($import_options['update_all_data'] == 'yes') return true;
941
+
942
+ if (!$import_options['is_update_images']) return false;
943
+
944
+ if ($import_options['is_update_images']) return true;
945
+
946
+ return false;
947
+ }
948
+
949
+
950
+ function admin_notice_ignore() {
951
+ if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) {
952
+ update_option($this->slug.'_ignore', 'true');
953
+ }
954
+ }
955
+
956
+ function display_admin_notice() {
957
+
958
+
959
+ if ($this->notice_text) {
960
+ $notice_text = $this->notice_text;
961
+ } else {
962
+ $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.';
963
+ }
964
+
965
+ if (!get_option(sanitize_key($this->slug).'_notice_ignore')) {
966
+
967
+ ?>
968
+
969
+ <div class="error notice is-dismissible wpallimport-dismissible" style="margin-top: 10px;" rel="<?php echo sanitize_key($this->slug); ?>">
970
+ <p><?php _e(
971
+ sprintf(
972
+ $notice_text,
973
+ '?'.$this->slug.'_ignore=0'
974
+ ),
975
+ 'rapid_addon_'.$this->slug
976
+ ); ?></p>
977
+ </div>
978
+
979
+ <?php
980
+
981
+ }
982
+
983
+ }
984
+
985
+ /*
986
+ *
987
+ * $conditions - array('themes' => array('Realia'), 'plugins' => array('plugin-directory/plugin-file.php', 'plugin-directory2/plugin-file.php'))
988
+ *
989
+ */
990
+ function admin_notice($notice_text = '', $conditions = array()) {
991
+
992
+ $is_show_notice = false;
993
+
994
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
995
+
996
+ if ( ! is_plugin_active('wp-all-import-pro/wp-all-import-pro.php') and ! is_plugin_active('wp-all-import/plugin.php') ){
997
+ $is_show_notice = true;
998
+ }
999
+
1000
+ // Supported Themes
1001
+ if ( ! $is_show_notice and ! empty($conditions['themes']) ){
1002
+
1003
+ $themeInfo = wp_get_theme();
1004
+ $parentInfo = $themeInfo->parent();
1005
+ $currentTheme = $themeInfo->get('Name');
1006
+
1007
+ $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true;
1008
+
1009
+ if ( $is_show_notice and $parentInfo ){
1010
+ $parent_theme = $parentInfo->get('Name');
1011
+ $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true;
1012
+ }
1013
+
1014
+ }
1015
+
1016
+ // Required Plugins
1017
+ if ( ! $is_show_notice and ! empty($conditions['plugins']) ){
1018
+
1019
+ $requires_counter = 0;
1020
+ foreach ($conditions['plugins'] as $plugin) {
1021
+ if ( is_plugin_active($plugin) ) $requires_counter++;
1022
+ }
1023
+
1024
+ if ($requires_counter != count($conditions['plugins'])){
1025
+ $is_show_notice = true;
1026
+ }
1027
+
1028
+ }
1029
+
1030
+ if ( $is_show_notice ){
1031
+
1032
+ if ( $notice_text != '' ) {
1033
+ $this->notice_text = $notice_text;
1034
+ }
1035
+
1036
+ add_action('admin_notices', array($this, 'display_admin_notice'));
1037
+ }
1038
+
1039
+ }
1040
+
1041
+ function log( $m = false){
1042
+
1043
+ $m and $this->logger and call_user_func($this->logger, $m);
1044
+
1045
+ }
1046
+ }
1047
+
1048
+ }
1049
+
readme.txt CHANGED
@@ -1,102 +1,105 @@
1
- === Import Settings into WordPress SEO by Yoast ===
2
- Contributors: soflyy, wpallimport
3
- Tags: seo, import seo, search engine optimization, import search engine optimization, yoast, import yoast, yoast seo, yoast wordpress seo, import yoast wordpress seo
4
- License: GPLv2 or later
5
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
6
- Requires at least: 4.1.0
7
- Tested up to: 4.5.2
8
- Stable tag: 1.1.3
9
-
10
- Easily import SEO settings from any XML or CSV file to Yoast WordPress SEO with the Yoast WordPress SEO Add-On for WP All Import.
11
-
12
- == Description ==
13
-
14
- The Yoast WordPress SEO Add-On for [WP All Import](http://wordpress.org/plugins/wp-all-import "WordPress XML & CSV Import") makes it easy to bulk import your SEO setting to the Yoast WordPress SEO plugin in less than 10 minutes.
15
-
16
- The left side shows all of the fields that you can import to and the right side displays the data from your XML/CSV file. Then you can simply drag & drop the data from your XML or CSV into the Yoast WordPress SEO fields to import them.
17
-
18
- The importer is so intuitive it is almost like manually configuring Yoast WordPress SEO when adding/editing a post.
19
-
20
- = Why you should use the Yoast WordPress SEO Add-On for WP All Import =
21
-
22
- * Import new posts, pages, or custom post types and configure their SEO settings all in the same import.
23
-
24
- * Update SEO settings for existing posts, pages, or custom post types already published on your site.
25
-
26
- * Compatible with all other WP All Import add-ons.
27
-
28
- * Complete support - configure all available SEO settings for your posts, including social media images.
29
-
30
- = WP All Import Professional Edition =
31
-
32
- The Yoast WordPress SEO Add-On for WP All Import is fully compatible with [the free version of WP All Import](http://wordpress.org/plugins/wp-all-import "WordPress XML & CSV Import").
33
-
34
- However, [the professional edition of WP All Import](http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast-seo) includes premium support and adds the following features:
35
-
36
- * Import files from a URL: Download and import files from external websites, even if they are password protected with HTTP authentication.
37
-
38
- * Cron Job/Recurring Imports: WP All Import Pro can check periodically check a file for updates, and add, edit, delete, and update the your property listings.
39
-
40
- * Custom PHP Functions: Pass your data through custom functions by using [my_function({data[1]})] in your import template. WP All Import will pass the value of {data[1]} through my_function and use whatever it returns.
41
-
42
- * Access to premium technical support.
43
-
44
- [Upgrade to the professional edition of WP All Import now.](http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast-seo)
45
-
46
- = Developers: Create Your Own Add-On =
47
- This Add-On was created using the [Rapid Add-On API](http://www.wpallimport.com/documentation/addon-dev/overview/) for WP All Import. We've made it really easy to write your own Add-On.
48
-
49
- Don't have time? We'll write one for you.
50
-
51
- [Read more about getting an Add-On made for your plugin or theme.](http://www.wpallimport.com/add-ons/#developers)
52
-
53
- == Installation ==
54
-
55
- First, install [WP All Import](http://wordpress.org/plugins/wp-all-import "WordPress XML & CSV Import").
56
-
57
- Then install the Yoast WordPress SEO Add-On.
58
-
59
- To install the Yoast WordPress SEO Add-On, either:
60
-
61
- * Upload the plugin from the Plugins page in WordPress
62
-
63
- * Unzip import-property-listings-into-realia.zip and upload the contents to /wp-content/plugins/, and then activate the plugin from the Plugins page in WordPress
64
-
65
- The Yoast WordPress SEO Add-On will appear in the Step 3 of WP All Import.
66
-
67
- == Changelog ==
68
-
69
- = 1.1.3 =
70
- * Bug fix related to new posts in existing import.
71
-
72
- = 1.1.2 =
73
- * Added focus keyword text input field
74
-
75
- = 1.1.1 =
76
- * Added primary category setting
77
-
78
- = 1.1.0 =
79
- * Bug fixes related to cron imports
80
-
81
- = 1.0.5 =
82
- * Bug fixes related to Yoast SEO Premium
83
-
84
- = 1.0.3 =
85
- * Add support for Yoast SEO Premium
86
- * Add 'Auto Calculate SEO Score'
87
-
88
- = 1.0.2 =
89
- * Update WP All Import add-on API
90
-
91
- = 1.0.0 =
92
- * Initial release on WP.org.
93
-
94
- == Support ==
95
-
96
- We do not handle support in the WordPress.org community forums.
97
-
98
- We do try to handle support for our free version users at the following e-mail address:
99
-
100
- E-mail: support@wpallimport.com
101
-
 
 
 
102
  Support for free version customers is not guaranteed and based on ability. For premium support, purchase [WP All Import Pro](http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast-seo).
1
+ === Import Settings into WordPress SEO by Yoast ===
2
+ Contributors: soflyy, wpallimport
3
+ Tags: seo, import seo, search engine optimization, import search engine optimization, yoast, import yoast, yoast seo, yoast wordpress seo, import yoast wordpress seo
4
+ License: GPLv2 or later
5
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
6
+ Requires at least: 4.1.0
7
+ Tested up to: 4.5.3
8
+ Stable tag: 1.1.4
9
+
10
+ Easily import SEO settings from any XML or CSV file to Yoast WordPress SEO with the Yoast WordPress SEO Add-On for WP All Import.
11
+
12
+ == Description ==
13
+
14
+ The Yoast WordPress SEO Add-On for [WP All Import](http://wordpress.org/plugins/wp-all-import "WordPress XML & CSV Import") makes it easy to bulk import your SEO setting to the Yoast WordPress SEO plugin in less than 10 minutes.
15
+
16
+ The left side shows all of the fields that you can import to and the right side displays the data from your XML/CSV file. Then you can simply drag & drop the data from your XML or CSV into the Yoast WordPress SEO fields to import them.
17
+
18
+ The importer is so intuitive it is almost like manually configuring Yoast WordPress SEO when adding/editing a post.
19
+
20
+ = Why you should use the Yoast WordPress SEO Add-On for WP All Import =
21
+
22
+ * Import new posts, pages, or custom post types and configure their SEO settings all in the same import.
23
+
24
+ * Update SEO settings for existing posts, pages, or custom post types already published on your site.
25
+
26
+ * Compatible with all other WP All Import add-ons.
27
+
28
+ * Complete support - configure all available SEO settings for your posts, including social media images.
29
+
30
+ = WP All Import Professional Edition =
31
+
32
+ The Yoast WordPress SEO Add-On for WP All Import is fully compatible with [the free version of WP All Import](http://wordpress.org/plugins/wp-all-import "WordPress XML & CSV Import").
33
+
34
+ However, [the professional edition of WP All Import](http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast-seo) includes premium support and adds the following features:
35
+
36
+ * Import files from a URL: Download and import files from external websites, even if they are password protected with HTTP authentication.
37
+
38
+ * Cron Job/Recurring Imports: WP All Import Pro can check periodically check a file for updates, and add, edit, delete, and update the your property listings.
39
+
40
+ * Custom PHP Functions: Pass your data through custom functions by using [my_function({data[1]})] in your import template. WP All Import will pass the value of {data[1]} through my_function and use whatever it returns.
41
+
42
+ * Access to premium technical support.
43
+
44
+ [Upgrade to the professional edition of WP All Import now.](http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast-seo)
45
+
46
+ = Developers: Create Your Own Add-On =
47
+ This Add-On was created using the [Rapid Add-On API](http://www.wpallimport.com/documentation/addon-dev/overview/) for WP All Import. We've made it really easy to write your own Add-On.
48
+
49
+ Don't have time? We'll write one for you.
50
+
51
+ [Read more about getting an Add-On made for your plugin or theme.](http://www.wpallimport.com/add-ons/#developers)
52
+
53
+ == Installation ==
54
+
55
+ First, install [WP All Import](http://wordpress.org/plugins/wp-all-import "WordPress XML & CSV Import").
56
+
57
+ Then install the Yoast WordPress SEO Add-On.
58
+
59
+ To install the Yoast WordPress SEO Add-On, either:
60
+
61
+ * Upload the plugin from the Plugins page in WordPress
62
+
63
+ * Unzip import-property-listings-into-realia.zip and upload the contents to /wp-content/plugins/, and then activate the plugin from the Plugins page in WordPress
64
+
65
+ The Yoast WordPress SEO Add-On will appear in the Step 3 of WP All Import.
66
+
67
+ == Changelog ==
68
+
69
+ = 1.1.4 =
70
+ * Fixed field update permissions for primary category
71
+
72
+ = 1.1.3 =
73
+ * Bug fix related to new posts in existing import.
74
+
75
+ = 1.1.2 =
76
+ * Added focus keyword text input field
77
+
78
+ = 1.1.1 =
79
+ * Added primary category setting
80
+
81
+ = 1.1.0 =
82
+ * Bug fixes related to cron imports
83
+
84
+ = 1.0.5 =
85
+ * Bug fixes related to Yoast SEO Premium
86
+
87
+ = 1.0.3 =
88
+ * Add support for Yoast SEO Premium
89
+ * Add 'Auto Calculate SEO Score'
90
+
91
+ = 1.0.2 =
92
+ * Update WP All Import add-on API
93
+
94
+ = 1.0.0 =
95
+ * Initial release on WP.org.
96
+
97
+ == Support ==
98
+
99
+ We do not handle support in the WordPress.org community forums.
100
+
101
+ We do try to handle support for our free version users at the following e-mail address:
102
+
103
+ E-mail: support@wpallimport.com
104
+
105
  Support for free version customers is not guaranteed and based on ability. For premium support, purchase [WP All Import Pro](http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast-seo).
yoast-addon.php CHANGED
@@ -1,267 +1,283 @@
1
- <?php
2
-
3
- /*
4
- Plugin Name: WP All Import - Yoast WordPress SEO Add-On
5
- Plugin URI: http://www.wpallimport.com/
6
- Description: Import data into Yoast WordPress SEO with WP All Import.
7
- Version: 1.1.3
8
- Author: Soflyy
9
- */
10
-
11
- include "rapid-addon.php";
12
-
13
- include_once(ABSPATH.'wp-admin/includes/plugin.php');
14
-
15
- add_action( 'pmxi_saved_post', 'yoast_addon_primary_category', 10, 1 );
16
-
17
- $yoast_addon = new RapidAddon( 'Yoast WordPress SEO Add-On', 'yoast_addon' );
18
-
19
- $yoast_addon->add_field( '_yoast_wpseo_focuskw', 'Focus Keyword', 'text', null, 'Pick the main keyword or keyphrase that this post/page is about.' );
20
-
21
- $yoast_addon->add_field( '_yoast_wpseo_title', 'SEO Title', 'text', null, 'The SEO title defaults to what is generated based on this sites title template for this posttype.' );
22
-
23
- $yoast_addon->add_field( '_yoast_wpseo_metadesc', 'Meta Description', 'text', null, 'The meta description will be limited to 156 chars. It is often shown as the black text under the title in a search result. For this to work it has to contain the keyword that was searched for.' );
24
-
25
- $yoast_addon->add_options(
26
- $yoast_addon->add_field( '_yoast_wpseo_opengraph-title', 'Facebook Title', 'text', null, "If you don't want to use the post title for sharing the post on Facebook but instead want another title there, import it here." ),
27
- 'Facebook Options',
28
- array(
29
- $yoast_addon->add_field( '_yoast_wpseo_opengraph-description', 'Description', 'text', null, "If you don't want to use the meta description for sharing the post on Facebook but want another description there, write it here." ),
30
- $yoast_addon->add_field( '_yoast_wpseo_opengraph-image', 'Image', 'image', null, "If you want to override the image used on Facebook for this post, import one here. The recommended image size for Facebook is 1200 x 628px."),
31
- )
32
- );
33
-
34
- $yoast_addon->add_options(
35
- $yoast_addon->add_field( '_yoast_wpseo_twitter-title', 'Twitter Title', 'text', null, "If you don't want to use the post title for sharing the post on Twitter but instead want another title there, import it here." ),
36
- 'Twitter Options',
37
- array(
38
- $yoast_addon->add_field( '_yoast_wpseo_twitter-description', 'Description', 'text', null, "If you don't want to use the meta description for sharing the post on Twitter but want another description there, import it here." ),
39
- $yoast_addon->add_field( '_yoast_wpseo_twitter-image', 'Image', 'image', null, "If you want to override the image used on Twitter for this post, import one here. The recommended image size for Twitter is 1024 x 512px."),
40
- )
41
- );
42
-
43
- $yoast_addon->add_options(
44
- null,
45
- 'Advanced SEO Options',
46
- array(
47
- $yoast_addon->add_field( '_yoast_wpseo_meta-robots-noindex', 'Meta Robots Index', 'radio',
48
- array(
49
- '' => 'default',
50
- '2' => 'index',
51
- '1' => 'noindex',
52
- ),
53
- "This setting can be overwritten by Yoast WordPress SEO's sitewide privacy settings"
54
- ),
55
- $yoast_addon->add_field( '_yoast_wpseo_meta-robots-nofollow', 'Meta Robots Nofollow', 'radio',
56
- array(
57
- '' => 'Follow',
58
- '1' => 'Nofollow'
59
- ) ),
60
- $yoast_addon->add_field( '_yoast_wpseo_meta-robots-adv', 'Meta Robots Advanced', 'radio',
61
- array(
62
- '' => 'default',
63
- 'none' => 'None',
64
- 'noodp' => 'NO ODP',
65
- 'noydir' => 'NO YDIR',
66
- 'noimageindex' => 'No Image Index',
67
- 'noarchive' => 'No Archive',
68
- 'nosnippet' => 'No Snippet'
69
- ),
70
- 'Advanced meta robots settings for this page.'
71
- ),
72
- $yoast_addon->add_field( '_yoast_wpseo_sitemap-include', 'Include in Sitemap', 'radio',
73
- array(
74
- '' => 'Auto detect',
75
- 'always' => 'Always include',
76
- 'never' => 'Never include'
77
- ),
78
- 'Should this page be in the XML Sitemap at all times, regardless of Robots Meta settings?'
79
- ),
80
- $yoast_addon->add_field( '_yoast_wpseo_sitemap-prio', 'Sitemap Priority', 'radio',
81
- array(
82
- '' => 'Automatic Prioritization',
83
- '1' => '1 - Highest priority',
84
- '0.9' => '0.9',
85
- '0.8' => '0.8 - Default for first tier pages',
86
- '0.7' => '0.7',
87
- '0.6' => '0.6 - Default for second tier pages and posts',
88
- '0.5' => '0.5 - Medium priority',
89
- '0.4' => '0.4',
90
- '0.3' => '0.3',
91
- '0.2' => '0.2',
92
- '0.1' => '0.1 - Lowest priority'
93
- ),
94
- 'The priority given to this page in the XML sitemap. '
95
- ),
96
- $yoast_addon->add_field( '_yoast_wpseo_canonical', 'Canonical URL', 'text', null, 'The canonical URL that this page should point to, leave empty to default to permalink. Cross domain canonical supported too.' ),
97
- $yoast_addon->add_field( '_yoast_wpseo_redirect', '301 Redirect', 'text', null, 'The URL that this page should redirect to.' ),
98
- $yoast_addon->add_field( '_yoast_wpseo_primary_category_addon', 'Primary Category', 'text', null, 'The name or slug of the primary category' )
99
-
100
- )
101
- );
102
-
103
- $yoast_addon->set_import_function( 'yoast_seo_addon_import' );
104
-
105
- if (function_exists('is_plugin_active')) {
106
-
107
- if ( !is_plugin_active( "wordpress-seo/wp-seo.php" ) && !is_plugin_active( "wordpress-seo-premium/wp-seo-premium.php" ) ) {
108
-
109
- $yoast_addon->admin_notice(
110
- 'The Yoast WordPress SEO Add-On requires WP All Import <a href="http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>, and the <a href="https://yoast.com/wordpress/plugins/seo/">Yoast WordPress SEO</a> plugin.',
111
- array(
112
- 'plugins' => array('wordpress-seo/wp-seo.php')
113
- )
114
- );
115
- }
116
-
117
- if ( is_plugin_active( "wordpress-seo/wp-seo.php" ) || is_plugin_active( "wordpress-seo-premium/wp-seo-premium.php" ) ) {
118
-
119
- $yoast_addon->run();
120
-
121
- }
122
- }
123
-
124
- function yoast_seo_addon_import( $post_id, $data, $import_options, $article ) {
125
-
126
- global $yoast_addon;
127
-
128
- // all fields except for slider and image fields
129
- $fields = array(
130
- '_yoast_wpseo_focuskw',
131
- '_yoast_wpseo_title',
132
- '_yoast_wpseo_metadesc',
133
- '_yoast_wpseo_meta-robots-noindex',
134
- '_yoast_wpseo_meta-robots-nofollow',
135
- '_yoast_wpseo_meta-robots-adv',
136
- '_yoast_wpseo_sitemap-include',
137
- '_yoast_wpseo_sitemap-prio',
138
- '_yoast_wpseo_canonical',
139
- '_yoast_wpseo_redirect',
140
- '_yoast_wpseo_opengraph-title',
141
- '_yoast_wpseo_opengraph-description',
142
- '_yoast_wpseo_twitter-title',
143
- '_yoast_wpseo_twitter-description',
144
- '_yoast_wpseo_primary_category_addon'
145
- );
146
-
147
- // image fields
148
- $image_fields = array(
149
- '_yoast_wpseo_opengraph-image',
150
- '_yoast_wpseo_twitter-image'
151
- );
152
-
153
- $fields = array_merge( $fields, $image_fields );
154
-
155
- // update everything in fields arrays
156
- foreach ( $fields as $field ) {
157
- if ( $field == '_yoast_wpseo_primary_category_addon' ) {
158
-
159
- $title = $data[$field];
160
-
161
- $cat_slug = sanitize_title( $title ); // Get the slug for the Primary Category so we can match it later
162
-
163
- update_post_meta( $post_id, '_yoast_wpseo_addon_category_slug', $cat_slug );
164
-
165
- // Set post metas for regular categories and product categories so we know if we can update them after pmxi_saved_post hook fires.
166
-
167
- update_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update', $yoast_addon->can_update_meta( '_yoast_wpseo_primary_category', $import_options ) );
168
-
169
- update_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update', $yoast_addon->can_update_meta( '_yoast_wpseo_primary_product_cat', $import_options ) );
170
-
171
- } else {
172
-
173
- if ( empty($article['ID']) or $yoast_addon->can_update_meta( $field, $import_options ) ) {
174
-
175
- if ( in_array( $field, $image_fields ) ) {
176
-
177
- if ( $yoast_addon->can_update_image( $import_options ) ) {
178
-
179
- $id = $data[$field]['attachment_id'];
180
-
181
- $url = wp_get_attachment_url( $id );
182
-
183
- update_post_meta( $post_id, $field, $url );
184
-
185
- }
186
-
187
- } else {
188
-
189
- if ( $field == '_yoast_wpseo_focuskw' ) {
190
-
191
- update_post_meta( $post_id, $field, $data[$field] );
192
- update_post_meta( $post_id, '_yoast_wpseo_focuskw_text_input', $data[$field] );
193
-
194
- } else {
195
-
196
- update_post_meta( $post_id, $field, $data[$field] );
197
-
198
- }
199
- }
200
- }
201
- }
202
- }
203
-
204
- // calculate _yoast_wpseo_linkdex
205
- if ( class_exists( 'WPSEO_Metabox' ) ) {
206
-
207
- wpseo_admin_init();
208
-
209
- $seo = new WPSEO_Metabox();
210
-
211
- $seo->calculate_results( get_post($post_id) );
212
- }
213
- }
214
-
215
- function yoast_addon_primary_category( $post_id ) {
216
-
217
- $product_update = get_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update', true ); // Can we update product primary categories?
218
-
219
- $post_update = get_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update', true ); // Can we update post primary categories?
220
-
221
- // Only proceed if we have permission to update one of them.
222
-
223
- if ( $post_update == 1 or $product_update == 1 ) {
224
-
225
- $cat_slug = get_post_meta( $post_id, '_yoast_wpseo_addon_category_slug', true );
226
-
227
- if ( !empty( $cat_slug ) ) {
228
-
229
- $post_type = get_post_type( $post_id );
230
-
231
- if ( !empty( $cat_slug ) and !empty( $post_type ) ) {
232
-
233
- if ( $post_type == 'product' and $product_update == 1 ) { // Products use 'product_cat' instead of 'categories'.
234
-
235
- $cat = get_term_by( 'slug', $cat_slug, 'product_cat' );
236
-
237
- $cat_id = $cat->term_id;
238
-
239
- if ( !empty( $cat_id ) ) {
240
-
241
- update_post_meta( $post_id, '_yoast_wpseo_primary_product_cat', $cat_id );
242
-
243
-
244
- }
245
-
246
- } else {
247
-
248
- if ( $post_update == 1 ) {
249
-
250
- $cat = get_term_by( 'slug', $cat_slug, 'category' );
251
-
252
- $cat_id = $cat->term_id;
253
-
254
- if ( !empty( $cat_id ) ) {
255
-
256
- update_post_meta( $post_id, '_yoast_wpseo_primary_category', $cat_id );
257
-
258
- }
259
- }
260
- }
261
- }
262
- }
263
- }
264
- delete_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update' );
265
- delete_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update' );
266
- delete_post_meta( $post_id, '_yoast_wpseo_addon_category_slug' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  }
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: WP All Import - Yoast WordPress SEO Add-On
5
+ Plugin URI: http://www.wpallimport.com/
6
+ Description: Import data into Yoast WordPress SEO with WP All Import.
7
+ Version: 1.1.4
8
+ Author: Soflyy
9
+ */
10
+
11
+ include "rapid-addon.php";
12
+
13
+ include_once(ABSPATH.'wp-admin/includes/plugin.php');
14
+
15
+ add_action( 'pmxi_saved_post', 'yoast_addon_primary_category', 10, 1 );
16
+
17
+ $yoast_addon = new RapidAddon( 'Yoast WordPress SEO Add-On', 'yoast_addon' );
18
+
19
+ $yoast_addon->add_field( '_yoast_wpseo_focuskw', 'Focus Keyword', 'text', null, 'Pick the main keyword or keyphrase that this post/page is about.' );
20
+
21
+ $yoast_addon->add_field( '_yoast_wpseo_title', 'SEO Title', 'text', null, 'The SEO title defaults to what is generated based on this sites title template for this posttype.' );
22
+
23
+ $yoast_addon->add_field( '_yoast_wpseo_metadesc', 'Meta Description', 'text', null, 'The meta description will be limited to 156 chars. It is often shown as the black text under the title in a search result. For this to work it has to contain the keyword that was searched for.' );
24
+
25
+ $yoast_addon->add_options(
26
+ $yoast_addon->add_field( '_yoast_wpseo_opengraph-title', 'Facebook Title', 'text', null, "If you don't want to use the post title for sharing the post on Facebook but instead want another title there, import it here." ),
27
+ 'Facebook Options',
28
+ array(
29
+ $yoast_addon->add_field( '_yoast_wpseo_opengraph-description', 'Description', 'text', null, "If you don't want to use the meta description for sharing the post on Facebook but want another description there, write it here." ),
30
+ $yoast_addon->add_field( '_yoast_wpseo_opengraph-image', 'Image', 'image', null, "If you want to override the image used on Facebook for this post, import one here. The recommended image size for Facebook is 1200 x 628px."),
31
+ )
32
+ );
33
+
34
+ $yoast_addon->add_options(
35
+ $yoast_addon->add_field( '_yoast_wpseo_twitter-title', 'Twitter Title', 'text', null, "If you don't want to use the post title for sharing the post on Twitter but instead want another title there, import it here." ),
36
+ 'Twitter Options',
37
+ array(
38
+ $yoast_addon->add_field( '_yoast_wpseo_twitter-description', 'Description', 'text', null, "If you don't want to use the meta description for sharing the post on Twitter but want another description there, import it here." ),
39
+ $yoast_addon->add_field( '_yoast_wpseo_twitter-image', 'Image', 'image', null, "If you want to override the image used on Twitter for this post, import one here. The recommended image size for Twitter is 1024 x 512px."),
40
+ )
41
+ );
42
+
43
+ $yoast_addon->add_options(
44
+ null,
45
+ 'Advanced SEO Options',
46
+ array(
47
+ $yoast_addon->add_field( '_yoast_wpseo_meta-robots-noindex', 'Meta Robots Index', 'radio',
48
+ array(
49
+ '' => 'default',
50
+ '2' => 'index',
51
+ '1' => 'noindex',
52
+ ),
53
+ "This setting can be overwritten by Yoast WordPress SEO's sitewide privacy settings"
54
+ ),
55
+ $yoast_addon->add_field( '_yoast_wpseo_meta-robots-nofollow', 'Meta Robots Nofollow', 'radio',
56
+ array(
57
+ '' => 'Follow',
58
+ '1' => 'Nofollow'
59
+ ) ),
60
+ $yoast_addon->add_field( '_yoast_wpseo_meta-robots-adv', 'Meta Robots Advanced', 'radio',
61
+ array(
62
+ '' => 'default',
63
+ 'none' => 'None',
64
+ 'noodp' => 'NO ODP',
65
+ 'noydir' => 'NO YDIR',
66
+ 'noimageindex' => 'No Image Index',
67
+ 'noarchive' => 'No Archive',
68
+ 'nosnippet' => 'No Snippet'
69
+ ),
70
+ 'Advanced meta robots settings for this page.'
71
+ ),
72
+ $yoast_addon->add_field( '_yoast_wpseo_sitemap-include', 'Include in Sitemap', 'radio',
73
+ array(
74
+ '' => 'Auto detect',
75
+ 'always' => 'Always include',
76
+ 'never' => 'Never include'
77
+ ),
78
+ 'Should this page be in the XML Sitemap at all times, regardless of Robots Meta settings?'
79
+ ),
80
+ $yoast_addon->add_field( '_yoast_wpseo_sitemap-prio', 'Sitemap Priority', 'radio',
81
+ array(
82
+ '' => 'Automatic Prioritization',
83
+ '1' => '1 - Highest priority',
84
+ '0.9' => '0.9',
85
+ '0.8' => '0.8 - Default for first tier pages',
86
+ '0.7' => '0.7',
87
+ '0.6' => '0.6 - Default for second tier pages and posts',
88
+ '0.5' => '0.5 - Medium priority',
89
+ '0.4' => '0.4',
90
+ '0.3' => '0.3',
91
+ '0.2' => '0.2',
92
+ '0.1' => '0.1 - Lowest priority'
93
+ ),
94
+ 'The priority given to this page in the XML sitemap. '
95
+ ),
96
+ $yoast_addon->add_field( '_yoast_wpseo_canonical', 'Canonical URL', 'text', null, 'The canonical URL that this page should point to, leave empty to default to permalink. Cross domain canonical supported too.' ),
97
+ $yoast_addon->add_field( '_yoast_wpseo_redirect', '301 Redirect', 'text', null, 'The URL that this page should redirect to.' ),
98
+ $yoast_addon->add_field( '_yoast_wpseo_primary_category_addon', 'Primary Category', 'text', null, 'The name or slug of the primary category' )
99
+
100
+ )
101
+ );
102
+
103
+ $yoast_addon->set_import_function( 'yoast_seo_addon_import' );
104
+
105
+ if (function_exists('is_plugin_active')) {
106
+
107
+ if ( !is_plugin_active( "wordpress-seo/wp-seo.php" ) && !is_plugin_active( "wordpress-seo-premium/wp-seo-premium.php" ) ) {
108
+
109
+ $yoast_addon->admin_notice(
110
+ 'The Yoast WordPress SEO Add-On requires WP All Import <a href="http://www.wpallimport.com/order-now/?utm_source=free-plugin&utm_medium=dot-org&utm_campaign=yoast" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>, and the <a href="https://yoast.com/wordpress/plugins/seo/">Yoast WordPress SEO</a> plugin.',
111
+ array(
112
+ 'plugins' => array('wordpress-seo/wp-seo.php')
113
+ )
114
+ );
115
+ }
116
+
117
+ if ( is_plugin_active( "wordpress-seo/wp-seo.php" ) || is_plugin_active( "wordpress-seo-premium/wp-seo-premium.php" ) ) {
118
+
119
+ $yoast_addon->run();
120
+
121
+ }
122
+ }
123
+
124
+ function yoast_seo_addon_import( $post_id, $data, $import_options, $article ) {
125
+
126
+ global $yoast_addon;
127
+
128
+ // all fields except for slider and image fields
129
+ $fields = array(
130
+ '_yoast_wpseo_focuskw',
131
+ '_yoast_wpseo_title',
132
+ '_yoast_wpseo_metadesc',
133
+ '_yoast_wpseo_meta-robots-noindex',
134
+ '_yoast_wpseo_meta-robots-nofollow',
135
+ '_yoast_wpseo_meta-robots-adv',
136
+ '_yoast_wpseo_sitemap-include',
137
+ '_yoast_wpseo_sitemap-prio',
138
+ '_yoast_wpseo_canonical',
139
+ '_yoast_wpseo_redirect',
140
+ '_yoast_wpseo_opengraph-title',
141
+ '_yoast_wpseo_opengraph-description',
142
+ '_yoast_wpseo_twitter-title',
143
+ '_yoast_wpseo_twitter-description',
144
+ '_yoast_wpseo_primary_category_addon'
145
+ );
146
+
147
+ // image fields
148
+ $image_fields = array(
149
+ '_yoast_wpseo_opengraph-image',
150
+ '_yoast_wpseo_twitter-image'
151
+ );
152
+
153
+ $fields = array_merge( $fields, $image_fields );
154
+
155
+ // update everything in fields arrays
156
+ foreach ( $fields as $field ) {
157
+ if ( $field == '_yoast_wpseo_primary_category_addon' ) {
158
+
159
+ $title = $data[$field];
160
+
161
+ $cat_slug = sanitize_title( $title ); // Get the slug for the Primary Category so we can match it later
162
+
163
+ update_post_meta( $post_id, '_yoast_wpseo_addon_category_slug', $cat_slug );
164
+
165
+ // Set post metas for regular categories and product categories so we know if we can update them after pmxi_saved_post hook fires.
166
+
167
+ if ( empty( $article['ID'] ) or $yoast_addon->can_update_meta( '_yoast_wpseo_primary_category', $import_options ) ) {
168
+
169
+ update_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update', 1 );
170
+
171
+ } else {
172
+
173
+ update_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update', 0 );
174
+
175
+ }
176
+
177
+ if ( empty( $article['ID'] ) or $yoast_addon->can_update_meta( '_yoast_wpseo_primary_product_cat', $import_options ) ) {
178
+
179
+ update_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update', 1 );
180
+
181
+ } else {
182
+
183
+ update_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update', 0 );
184
+
185
+ }
186
+
187
+ } else {
188
+
189
+ if ( empty($article['ID']) or $yoast_addon->can_update_meta( $field, $import_options ) ) {
190
+
191
+ if ( in_array( $field, $image_fields ) ) {
192
+
193
+ if ( $yoast_addon->can_update_image( $import_options ) ) {
194
+
195
+ $id = $data[$field]['attachment_id'];
196
+
197
+ $url = wp_get_attachment_url( $id );
198
+
199
+ update_post_meta( $post_id, $field, $url );
200
+
201
+ }
202
+
203
+ } else {
204
+
205
+ if ( $field == '_yoast_wpseo_focuskw' ) {
206
+
207
+ update_post_meta( $post_id, $field, $data[$field] );
208
+ update_post_meta( $post_id, '_yoast_wpseo_focuskw_text_input', $data[$field] );
209
+
210
+ } else {
211
+
212
+ update_post_meta( $post_id, $field, $data[$field] );
213
+
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ // calculate _yoast_wpseo_linkdex
221
+ if ( class_exists( 'WPSEO_Metabox' ) ) {
222
+
223
+ wpseo_admin_init();
224
+
225
+ $seo = new WPSEO_Metabox();
226
+
227
+ $seo->calculate_results( get_post($post_id) );
228
+ }
229
+ }
230
+
231
+ function yoast_addon_primary_category( $post_id ) {
232
+
233
+ $product_update = get_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update', true ); // Can we update product primary categories?
234
+
235
+ $post_update = get_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update', true ); // Can we update post primary categories?
236
+
237
+ // Only proceed if we have permission to update one of them.
238
+
239
+ if ( $post_update == 1 or $product_update == 1 ) {
240
+
241
+ $cat_slug = get_post_meta( $post_id, '_yoast_wpseo_addon_category_slug', true );
242
+
243
+ if ( !empty( $cat_slug ) ) {
244
+
245
+ $post_type = get_post_type( $post_id );
246
+
247
+ if ( !empty( $cat_slug ) and !empty( $post_type ) ) {
248
+
249
+ if ( $post_type == 'product' and $product_update == 1 ) { // Products use 'product_cat' instead of 'categories'.
250
+
251
+ $cat = get_term_by( 'slug', $cat_slug, 'product_cat' );
252
+
253
+ $cat_id = $cat->term_id;
254
+
255
+ if ( !empty( $cat_id ) ) {
256
+
257
+ update_post_meta( $post_id, '_yoast_wpseo_primary_product_cat', $cat_id );
258
+
259
+
260
+ }
261
+
262
+ } else {
263
+
264
+ if ( $post_update == 1 ) {
265
+
266
+ $cat = get_term_by( 'slug', $cat_slug, 'category' );
267
+
268
+ $cat_id = $cat->term_id;
269
+
270
+ if ( !empty( $cat_id ) ) {
271
+
272
+ update_post_meta( $post_id, '_yoast_wpseo_primary_category', $cat_id );
273
+
274
+ }
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+ delete_post_meta( $post_id, '_yoast_wpseo_primary_category_can_update' );
281
+ delete_post_meta( $post_id, '_yoast_wpseo_primary_product_cat_can_update' );
282
+ delete_post_meta( $post_id, '_yoast_wpseo_addon_category_slug' );
283
  }