-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwp-seedbank.php
More file actions
1474 lines (1381 loc) · 89.9 KB
/
wp-seedbank.php
File metadata and controls
1474 lines (1381 loc) · 89.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: WP-SeedBank
* Plugin URI: http://hummingbirdproject.org/initiatives/wordpress-seedbank-plugin/
* Description: Add a seed exchange post type to turn your WordPress website into a community seedbank or seed library! :D
* Author: <a href="http://hummingbirdproject.org/initiatives/wordpress-seedbank-plugin/#authors">The Hummingbird Project</a>
* Version: 0.4.4
* Text Domain: wp-seedbank
* Domain Path: /languages
*/
class WP_SeedBank {
private $post_type = 'seedbank';
private $taxonomies = array(
array('exchange_type'),
array('common_name'),
array('unit'),
array('scientific_name'),
// TODO: Exchange statuses shouldn't be taxonomies?
array('exchange_status')
);
private $meta_fields = array(
'exchange_type',
'quantity',
'common_name',
'unit',
'seed_expiry_date',
'exchange_expiry_date',
'exchange_status'
);
public function __construct () {
register_activation_hook(__FILE__, array($this, 'activate'));
add_action('plugins_loaded', array($this, 'registerL10n'));
add_action('init', array($this, 'createDataTypes'));
add_action('add_meta_boxes_' . $this->post_type, array($this, 'addMetaBoxes'));
add_action('save_post', array($this, 'savePost'));
add_action('admin_init', array($this, 'registerCustomSettings'));
foreach (array('post-new.php', 'post.php', 'edit.php') as $hook) {
add_action("load-$hook", array($this, 'radioIzeTaxonomyInterface'));
}
add_action('admin_menu', array($this, 'registerAdminMenus'));
add_action('pre_get_posts', array($this, 'registerCustomOrdering'));
add_action('admin_enqueue_scripts', array($this, 'registerAdminScripts'));
add_action('admin_head', array($this, 'registerCustomHelp'));
add_action($this->post_type . '_expire_exchange', array($this, 'expireExchangePost'));
add_action('manage_' . $this->post_type . '_posts_custom_column', array($this, 'displayCustomColumn'), 10, 2);
add_filter('manage_' . $this->post_type . '_posts_columns', array($this, 'registerCustomColumns'));
add_filter('manage_edit-' . $this->post_type . '_sortable_columns', array($this, 'registerSortableColumns'));
add_filter('the_content', array($this, 'displayContent'));
}
public function registerL10n () {
load_plugin_textdomain('wp-seedbank', false, dirname(plugin_basename(__FILE__)) . '/languages/');
}
public function createDataTypes () {
$this->registerCustomPostType();
$this->registerCustomTaxonomies();
}
private function registerCustomPostType () {
$labels = array(
'name' => __('Seed Exchanges', 'wp-seedbank'),
'singular_name' => __('Seed Exchange', 'wp-seedbank'),
'add_new' => __('Add Seed Exchange', 'wp-seedbank'),
'add_new_item' => __('Add Seed Exchange', 'wp-seedbank'),
'edit' => __('Edit Seed Exchange', 'wp-seedbank'),
'edit_item' => __('Edit Seed Exchange', 'wp-seedbank'),
'new_item' => __('New Seed Exchange', 'wp-seedbank'),
'view' => __('View Seed Exchange', 'wp-seedbank'),
'view_item' => __('View Seed Exchange', 'wp-seedbank'),
'search' => __('Search Seed Exchanges', 'wp-seedbank'),
'not_found' => __('No Seed Exchanges found', 'wp-seedbank'),
'not_found_in_trash' => __('No Seed Exchanges found in trash', 'wp-seedbank')
);
$url_rewrites = array(
'slug' => 'seed-exchange'
);
$args = array(
'labels' => $labels,
'description' => __('Postings to the SeedBank', 'wp-seedbank'),
'public' => true,
'menu_icon' => plugins_url('images/seedexchange_icon.png', __FILE__),
'has_archive' => true,
'supports' => array(
'title',
'editor',
'author',
'comments'
),
'rewrite' => $url_rewrites
);
register_post_type($this->post_type, $args);
}
private function registerCustomTaxonomies () {
register_taxonomy($this->post_type . '_exchange_type', $this->post_type, array(
'labels' => array(
'name' => __('Exchange Types', 'wp-seedbank'),
'singular_name' => __('Exchange Type', 'wp-seedbank'),
'all_items' => __('All Exchange Types', 'wp-seedbank'),
'edit_item' => __('Edit Exchange Type', 'wp-seedbank'),
'update_item' => __('Update Exchange Type', 'wp-seedbank'),
'add_new_item' => __('Add New Exchange Type', 'wp-seedbank'),
'new_item_name' => __('New Exchange Type', 'wp-seedbank'),
'search_items' => __('Search Exchange Types', 'wp-seedbank'),
),
'show_admin_column' => true
)
);
register_taxonomy_for_object_type($this->post_type . '_exchange_type', $this->post_type);
register_taxonomy($this->post_type . '_common_name', $this->post_type, array(
'labels' => array(
'name' => __('Common Names', 'wp-seedbank'),
'singular_name' => __('Common Name', 'wp-seedbank'),
'all_items' => __('All Common Names', 'wp-seedbank'),
'edit_item' => __('Edit Common Name', 'wp-seedbank'),
'update_item' => __('Update Common Name', 'wp-seedbank'),
'add_new_item' => __('Add New Common Name', 'wp-seedbank'),
'new_item_name' => __('New Common Name', 'wp-seedbank'),
'search_items' => __('Search Common Names', 'wp-seedbank'),
),
'show_admin_column' => true
)
);
register_taxonomy_for_object_type($this->post_type . '_common_name', $this->post_type);
register_taxonomy($this->post_type . '_unit', $this->post_type, array(
'labels' => array(
'menu_name' => __('Inventory Units', 'wp-seedbank'),
'name' => __('Units', 'wp-seedbank'),
'singular_name' => __('Unit', 'wp-seedbank'),
'all_items' => __('All Units', 'wp-seedbank'),
'edit_item' => __('Edit Unit', 'wp-seedbank'),
'update_item' => __('Update Unit', 'wp-seedbank'),
'add_new_item' => __('Add New Units', 'wp-seedbank'),
'new_item_name' => __('New Unit', 'wp-seedbank'),
'search_items' => __('Search Units', 'wp-seedbank'),
),
'show_admin_column' => true
)
);
register_taxonomy_for_object_type($this->post_type . '_unit', $this->post_type);
register_taxonomy($this->post_type . '_scientific_name', $this->post_type, array(
'labels' => array(
'name' => __('Scientific Names', 'wp-seedbank'),
'singular_name' => __('Scientific Name', 'wp-seedbank'),
'all_items' => __('All Scientific Names', 'wp-seedbank'),
'edit_item' => __('Edit Scientific Name', 'wp-seedbank'),
'update_item' => __('Update Scientific Name', 'wp-seedbank'),
'add_new_item' => __('Add New Scientific Name', 'wp-seedbank'),
'new_item_name' => __('New Scientific Name', 'wp-seedbank'),
'parent_item' => __('Parent Classification', 'wp-seedbank'),
'parent_item_colon' => __('Parent Classification:', 'wp-seedbank'),
'search_items' => __('Search Scientific Names', 'wp-seedbank'),
),
'hierarchical' => true,
'rewrite' => array(
'slug' => 'scientific-name'
),
'show_admin_column' => true
)
);
register_taxonomy_for_object_type($this->post_type . '_scientific_name', $this->post_type);
register_taxonomy($this->post_type . '_exchange_status', $this->post_type, array(
'labels' => array(
'name' => __('Exchange Statuses', 'wp-seedbank'),
'singular_name' => __('Exchange Status', 'wp-seedbank'),
'all_items' => __('All Exchange Statuses', 'wp-seedbank'),
'edit_item' => __('Edit Exchange Status', 'wp-seedbank'),
'update_item' => __('Update Exchange Status', 'wp-seedbank'),
'add_new_item' => __('Add New Exchange Status', 'wp-seedbank'),
'new_item_name' => __('New Exchange Status', 'wp-seedbank'),
'search_items' => __('Search Exchange Statuses', 'wp-seedbank'),
),
'show_ui' => false,
'show_admin_column' => true
)
);
register_taxonomy_for_object_type($this->post_type . '_exchange_status', $this->post_type);
}
public function registerCustomSettings () {
register_setting($this->post_type . '_settings', $this->post_type . '_settings', array($this, 'validateSettings'));
add_settings_section(
$this->post_type . '_settings',
ucwords(str_replace('_', ' ', $this->post_type . '_settings')),
array($this, 'renderReadingSettingsSection'),
'reading'
);
add_settings_field(
$this->post_type . '_display_meta',
__('Display Seed Exchange details using', 'wp-seedbank'),
array($this, 'renderDisplayMetaSetting'),
'reading',
$this->post_type . '_settings'
);
}
public function validateSettings ($input) {
switch ($input['display_meta']) {
case '2':
case '1':
case '0':
default:
$input['display_meta'] = (int) $input['display_meta'];
break;
}
return $input;
}
public function renderReadingSettingsSection () {
settings_fields($this->post_type . '_settings');
}
public function renderDisplayMetaSetting () {
$options = get_option($this->post_type . '_settings');
?>
<select name="<?php print esc_attr($this->post_type);?>_settings[display_meta]">
<option value="2"<?php if (2 === $options['display_meta']) { print ' selected="selected"'; }?>><?php esc_html_e('this plugin (below content)', 'wp-seedbank');?></option>
<option value="1"<?php if (1 === $options['display_meta']) { print ' selected="selected"'; }?>><?php esc_html_e('this plugin (above content)', 'wp-seedbank');?></option>
<option value="0"<?php if (0 === $options['display_meta']) { print ' selected="selected"'; }?>><?php esc_html_e('my own template', 'wp-seedbank');?></option>
</select>
<p class="description"><?php esc_html_e('Choosing your own template without writing your own template code may result in the Seed Exchange details not appearing on your website.', 'wp-seedbank');?></p>
<?php
}
public function addMetaBoxes ($post) {
add_meta_box(
$this->post_type . '-details-meta',
__('Seed Exchange Details', 'wp-seedbank'),
array($this, 'renderMetaBoxDetails'),
$this->post_type,
'normal',
'high'
);
// Since we create the above "Seed Exchange Details" meta box
// ourselves, we can remove the default meta boxes WordPress
// gives us with our default taxonomies.
foreach ($this->taxonomies as $taxonomy) {
remove_meta_box('tagsdiv-' . $this->post_type . '_' . $taxonomy[0], $this->post_type, 'side');
}
}
// TODO: Fix the i18n of the fill-in-the-blank web form?
public function renderMetaBoxDetails () {
global $post;
wp_nonce_field('editing_' . $this->post_type, $this->post_type . '_meta_box_details_nonce');
// Retrieve meta data fields, or set to initial blank slates.
$custom = get_post_custom($post->ID);
foreach ($this->meta_fields as $f) {
if (!isset($custom[$this->post_type . '_' . $f])) {
$custom[$this->post_type . '_' . $f] = array('');
}
}
// Create HTML
$select_elements = array();
$datalists = array();
foreach ($this->taxonomies as $taxonomy) {
$select_elements[$taxonomy[0]] = $this->taxonomyAsHtmlSelect($taxonomy[0], $post);
$datalists[$taxonomy[0]] = $this->taxonomyAsHtmlDatalist($taxonomy[0], $post);
}
?>
<p>
<label><?php esc_html_e('I would like to', 'wp-seedbank');?> <?php print $select_elements['exchange_type'];?></label>
<input name="<?php print esc_attr($this->post_type);?>_quantity" value="<?php print esc_attr($custom["{$this->post_type}_quantity"][0]);?>" placeholder="<?php esc_attr_e('enter a number', 'wp-seedbank');?>" />
<?php print $datalists['common_name'];?>
<?php print $select_elements['unit'];?>.
</p>
<p>
<label><?php esc_html_e('These seeds will expire on or about', 'wp-seedbank');?> <input id="<?php print esc_attr($this->post_type);?>_seed_expiry_date" name="<?php print esc_attr($this->post_type);?>_seed_expiry_date" class="datepicker" value="<?php (empty($custom["{$this->post_type}_seed_expiry_date"][0])) ? '' : print esc_attr(date(get_option('date_format'), $custom["{$this->post_type}_seed_expiry_date"][0]));?>" placeholder="<?php esc_attr_e('enter a date', 'wp-seedbank');?>" />.</label> <span class="description"><?php esc_html_e('(If you are requesting seeds, you can leave this blank.)', 'wp-seedbank');?></span>
</p>
<p>
<label><?php esc_html_e('If I don\'t hear from anyone by', 'wp-seedbank');?> <input name="<?php print $this->post_type;?>_exchange_expiry_date" class="datepicker" value="<?php (empty($custom["{$this->post_type}_exchange_expiry_date"][0])) ? print '' : print esc_attr(date(get_option('date_format'), $custom["{$this->post_type}_exchange_expiry_date"][0]));?>" placeholder="<?php esc_attr_e('enter a date', 'wp-seedbank');?>" required="required" />, <?php esc_html_e('I\'ll stop being available to make this exchange.', 'wp-seedbank');?></label> <span class="description"><?php esc_html_e('(If you do not get a response by this date, your request will automatically close.)', 'wp-seedbank');?></span>
</p>
<p>
<?php // TODO: i18n this ?>
<label><?php esc_html_e('This seed exchange is', 'wp-seedbank');?> <?php print $select_elements['exchange_status'];?>.</label> <span class="description">(<?php foreach (get_terms($this->post_type . '_exchange_status', 'hide_empty=0&order=ASC') as $x) :?>The <code><?php print esc_html(strtolower($x->name), 'wp-seedbank');?></code> type is for <?php print esc_html(strtolower($x->description));?> <?php endforeach;?>)</span>
</p>
<?php
}
private function taxonomyAsHtmlSelect ($taxonomy, $post) {
$custom = get_post_custom($post->ID);
$these_options = get_terms($this->post_type . '_' . $taxonomy, 'hide_empty=0&order=ASC');
ob_start();
print '<select id="' . esc_attr($this->post_type) . '-' . esc_attr(str_replace('_', '-', $taxonomy)) . '" '
. 'name="' . esc_attr($this->post_type) . '_' . esc_attr($taxonomy) . '">';
foreach ($these_options as $t) {
print '<option ';
if (isset($custom["{$this->post_type}_{$taxonomy}"][0]) && $t->name == $custom["{$this->post_type}_{$taxonomy}"][0]) {
print 'selected="selected" ';
}
print 'value="' . esc_attr($t->name) .'">' . esc_html(strtolower($t->name)) . '</option>' . PHP_EOL;
}
print '</select>';
$el = ob_get_contents();
ob_end_clean();
return $el;
}
private function taxonomyAsHtmlDatalist ($taxonomy, $post) {
$custom = get_post_custom($post->ID);
$these_options = get_terms($this->post_type . '_' . $taxonomy, 'hide_empty=0&order=ASC');
ob_start();
print '<input list="' . esc_attr($this->post_type) . '-' . esc_attr($taxonomy) . '-datalist" ';
print 'name="'. esc_attr($this->post_type) .'_' . esc_attr($taxonomy) . '" ';
print 'value="';
(empty($custom[$this->post_type . '_' . $taxonomy][0])) ? print '' : print esc_attr($custom[$this->post_type . '_' . $taxonomy][0]);
print '" ';
print 'placeholder="' . esc_attr($these_options[0]->name) . '" />' . PHP_EOL;
print '<datalist id="' . esc_attr($this->post_type) . '-' . esc_attr($taxonomy). '-datalist">';
foreach ($these_options as $t) {
print '<option value="' . esc_attr($t->name) . '" />' . PHP_EOL;
}
print '</datalist>';
$el = ob_get_contents();
ob_end_clean();
return $el;
}
/**
* Utility function to determine whether this meta field is one
* of our "date" or "time" fields.
*
* @param string $key The meta field key to check.
* @return bool True if the field is one we're using for a date or time, false otherwise.
*/
private function isDateOrTimeMeta ($key) {
$x = substr($key, -5);
return ($x === '_date' || $x === '_time') ? true : false;
}
/**
* Utility function to determine whether this name is one of our
* taxonomies. Useful for detecting duplication between existing
* meta fields and custom taxonomies (until that's worked out).
*/
private function isTaxonomy ($key) {
return (in_array(array($key), $this->taxonomies)) ? true : false;
}
public function radioIzeTaxonomyInterface () {
$screen = get_current_screen();
if (false === strpos($screen->id, 'seedbank')) { return; }
ob_start(array($this, 'swapOutCheckboxes'));
}
// Modified from
// https://github.com/pressupinc/only-one-category/blob/master/main.php
public function swapOutCheckboxes ($content) {
$content = str_replace(
'type="checkbox" name="tax_input[seedbank_scientific_name][]"',
'type="radio" name="tax_input[seedbank_scientific_name][]""',
$content
);
foreach (get_terms($this->post_type . '_scientific_name') as $t) {
$content = str_replace(
'id="in-popular-seedbank_scientific_name-' . $t->term_id . '" type="checkbox"',
'id="in-popular-seedbank_scientific_name-' . $t->term_id . '" type="radio"',
$content
);
}
return $content;
}
/**
* Runs when we save a Seed Exchange post.
*/
public function savePost ($post_id) {
if (!isset($_POST['post_type']) || $this->post_type !== $_POST['post_type']) { return; }
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; }
if (!wp_verify_nonce($_POST[$this->post_type . '_meta_box_details_nonce'], 'editing_' . $this->post_type)) { return; }
$this->saveMeta($post_id);
$this->scheduleExpiration($post_id);
}
private function saveMeta ($post_id) {
foreach ($this->meta_fields as $f) {
if (isset($_REQUEST[$this->post_type . '_' . $f])) {
$val = $_REQUEST[$this->post_type . '_' . $f];
// For meta fields that end in '_date' or '_time',
if ($this->isDateOrTimeMeta($f)) {
// convert their value to a UTC'ed unix timestamp
$val = gmdate('U', strtotime($val));
}
update_post_meta($post_id, $this->post_type . '_' . $f, sanitize_text_field($val));
// TODO: Only do wp_set_object_terms on taxonomies.
wp_set_object_terms($post_id, sanitize_text_field($_REQUEST[$this->post_type . '_' . $f]), $this->post_type . '_' . $f);
}
}
}
/**
* Uses WP Cron to schedule setting exchange_status to 'Deleted'
* once the time in exchange_expiry_date meta field is reached.
*/
private function scheduleExpiration ($post_id) {
wp_clear_scheduled_hook($this->post_type . '_expire_exchange', array($post_id));
$time = (int) get_post_meta($post_id, $this->post_type . '_exchange_expiry_date', true);
wp_schedule_single_event($time, $this->post_type . '_expire_exchange', array($post_id));
}
public function expireExchangePost ($post_id) {
update_post_meta($post_id, $this->post_type . '_exchange_status', __('Deleted', 'wp-seedbank'));
wp_set_object_terms(
$post_id,
sanitize_text_field(get_post_meta($post_id, $this->post_type . '_exchange_status', true)),
$this->post_type . '_exchange_status'
);
}
public function displayContent ($content) {
global $post;
$options = get_option($this->post_type . '_settings');
if ($this->post_type === get_post_type($post->ID)) {
$append = '<ul id="' . esc_attr($this->post_type . '-meta-' . $post->ID) . '" class="' . esc_attr($this->post_type) . '-meta">';
if ($val = get_the_term_list($post->ID, $this->post_type . '_scientific_name')) {
$append .= '<li><strong>' . __('Scientific Name:', 'wp-seedbank') . '</strong> ' . $val . '</li>';
}
$custom = get_post_custom($post->ID);
foreach ($this->meta_fields as $f) {
$val = $custom[$this->post_type . '_' . $f][0];
// For meta fields that end in '_date' or '_time',
if ($this->isDateOrTimeMeta($f)) {
// convert their value to blog's local date format
$val = date(get_option('date_format'), $val);
}
if ($val) {
$append .= '<li><strong>' . esc_html(ucwords(str_replace('_', ' ', $f))) . ':</strong> ';
if ($this->isTaxonomy($f)) {
$append .= get_the_term_list($post->ID, $this->post_type . '_' . $this->taxonomies[array_search(array($f), $this->taxonomies)][0]);
} else {
$append .= esc_html($val);
}
$append .= '</li>';
}
}
$append .= '</ul>';
switch ($options['display_meta']) {
case 1: // Position meta list above content.
$content = $append . $content;
break;
case 2: // Position meta list below content.
$content = $content . $append;
case 0:
default:
// Don't modify $content at all.
break;
}
}
return $content;
}
public function registerAdminScripts () {
global $wp_scripts;
$screen = get_current_screen();
// Only load this plugin's JS on this plugin's own screens.
if (false === strpos($screen->id, $this->post_type)) { return; }
wp_register_script('wp-seedbank', plugins_url('wp-seedbank.js', __FILE__), array('jquery', 'jquery-ui-datepicker'));
wp_enqueue_script('wp-seedbank');
$x = $wp_scripts->query('jquery-ui-core');
wp_enqueue_style('jquery-ui-smoothness', "//ajax.googleapis.com/ajax/libs/jqueryui/{$x->ver}/themes/smoothness/jquery-ui.min.css", false, null);
}
public function registerCustomColumns ($columns) {
$my_columns = array();
foreach ($this->meta_fields as $f) {
switch ($f) {
case 'quantity':
$my_columns[$this->post_type . '_quantity'] = esc_html__('Quantity', 'wp-seedbank');
break;
case 'seed_expiry_date':
$my_columns[$this->post_type . '_seed_expiry_date'] = esc_html__('Seed Expiry Date', 'wp-seedbank');
break;
case 'exchange_expiry_date':
$my_columns[$this->post_type . '_exchange_expiry_date'] = esc_html__('Exchange Expiry Date', 'wp-seedbank');
break;
}
}
return array_merge($columns, $my_columns);
}
public function displayCustomColumn ($column, $post_id) {
foreach ($this->meta_fields as $f) {
if ($column !== $this->post_type . '_' . $f) {
continue;
}
if ($this->isDateOrTimeMeta($f)) {
print esc_html(date(get_option('date_format'), get_post_meta($post_id, $this->post_type . '_' . $f, true)));
} else {
print esc_html(get_post_meta($post_id, $this->post_type . '_' . $f, true));
}
}
}
public function registerSortableColumns ($columns) {
$my_columns = array();
foreach ($this->meta_fields as $f) {
$my_columns[$this->post_type . '_' . $f] = $this->post_type . '_' . $f;
}
return array_merge($columns, $my_columns);
}
public function registerCustomOrdering ($query) {
switch ($query->get('orderby')) {
case $this->post_type . '_quantity':
case $this->post_type . '_seed_expiry_date':
case $this->post_type . '_exchange_expiry_date':
$query->set('meta_key', $query->get('orderby'));
$query->set('orderby', 'meta_value_num');
break;
}
}
public function registerCustomHelp () {
$screen = get_current_screen();
if ($screen->post_type !== $this->post_type) { return; }
// Tabs for specific screens.
switch ($screen->id) {
case 'seedbank':
$p1 = __('Make a new Seed Exchange on this page. A Seed Exchange is just like a blog post, but tailored specifically for the Seedbank. Have some seeds to share, or trying to find seeds to grow? Let others know by posting here!', 'wp-seedbank');
$p2 = __('To make a new Seed Exchange, follow these steps:', 'wp-seedbank');
$ol1_str1 = esc_html__('Write a title.', 'wp-seedbank');
$ol1_str2 = esc_html__('Short, descriptive summaries are best.', 'wp-seedbank');
$ol1_str3 = esc_html__('Click here and then type your title.', 'wp-seedbank');
$ol1 = "<strong>$ol1_str1</strong> $ol1_str2 <a href=\"#\" onclick=\"document.getElementById('title').focus()\">$ol1_str3</a>";
$ol2_str1 = esc_html__('Explain your request or offer.', 'wp-seedbank');
$ol2_str2 = esc_html__("In your own words, describe what you're looking for or what you're hoping to get, or both. Be sure to include any important words you think others might use to find your post when they're searching the website. Include any additional information relevant to your posting.", 'wp-seedbank');
$ol2_str3 = esc_html__('Click here and then type your message.', 'wp-seedbank');
$ol2 = "<strong>$ol2_str1</strong> $ol2_str2 <a href=\"#\" onclick=\"document.getElementById('content').focus()\">$ol2_str3</a>";
$ol3_str1 = esc_html__('Fill in the details.', 'wp-seedbank');
$ol3_str2 = sprintf(
esc_html__('In the %1$s box, there are some fields you should fill in to help other people find your post by organizing it in a sensible place in the Seedbank. Simply complete the sentences of the fill-in-the-blank paragraph.', 'wp-seedbank'),
'<a href="#' . $this->post_type . '-details-meta">' . __('Seed Exchange Details', 'wp-seedbank') . '</a>'
);
$ol3 = "<strong>$ol3_str1</strong> $ol3_str2";
$ul1 = sprintf(
esc_html__('If your seeds are in a packet, the wrapping might have an expiration date. Put that in the "%s" field.', 'wp-seedbank'),
'<a href="#seedbank_seed_expiry_date">' . esc_html__('These seeds will expire on or about', 'wp-seedbank') . '</a>'
);
$p3 = sprintf(
esc_html__('If you know the scientific name (genus, species, variety, etc.) of your seed, you can also select it from the list of %s.', 'wp-seedbank'),
'<a href="#seedbank_scientific_namediv">' . esc_html__('Scientific Names', 'wp-seedbank') . '</a>'
);
$p4 = esc_html__('When you have done this, click the "Publish" (or "Submit for review") button. Congratulations! And thank you for spreading the seed love!', 'wp-seedbank');
$html = <<<END_HTML
<p>$p1</p>
<p>$p2</p>
<ol>
<li>$ol1</li>
<li>$ol2</li>
<li>
$ol3
<ul>
<li>$ul1</li>
</ul>
</li>
</ol>
<p>$p3</p>
<p>$p4</p>
END_HTML;
$screen->add_help_tab(array(
'id' => $this->post_type . '-' . $screen->base . '-help',
'title' => __('Adding a Seed Exchange', 'wp-seedbank'),
'content' => $html
));
break;
case 'edit-seedbank_scientific_name':
$html = '<p>'
. esc_html__('You can use scientific names to communicate about the kind of seed you have in a more precise way. A scientific name contains information about the genus and species of your seed, as well as any applicable more specific classification (called an "infraspecific name"). The WordPress SeedBank plugin expects scientific names to match the accepted names in the International Code of Nomenclature for Cultivated Plants (ICNCP). Several dozen genera and various species, subspecies, varieties, and cultivar Groups are already included.', 'wp-seedbank')
. '</p>';
$screen->add_help_tab(array(
'id' => $this->post_type . '-' . $screen->id . '-help-overview',
'title' => __('Overview', 'wp-seedbank'),
'content' => $html
));
$html = '<p>'
. esc_html__('To add a new scientific name on this screen, enter the following information:', 'wp-seedbank')
. '</p>';
$html .= '<ol>';
$html .= '<li>'
. sprintf(
'<strong>' . esc_html__('Name:', 'wp-seedbank') . '</strong> '
. esc_html__('The name is the full scientific name for your seed. Be as specific as you know how and try to follow the examples already listed.', 'wp-seedbank')
)
. '</li>';
$html .= '<li>'
. sprintf(
'<strong>' . esc_html__('Slug:', 'wp-seedbank') . '</strong> '
. esc_html__('The slug is the URL-friendly version of the scientific name. You can leave this blank to automatically fill it in from the Name field you entered in the previous step.', 'wp-seedbank')
)
. '</li>';
$html .= '<li>'
. sprintf(
'<strong>' . esc_html__('Parent:', 'wp-seedbank') . '</strong> '
. esc_html__('The parent is the higher-level rank for this scientific name. Each new scientific name should be added to the proper place in the hierarchy of biological classification. For instance, if you are adding a new species, like %1$s, be sure to set the correct genus (%2$s) as its parent. If the appropriate higher-level rank does not yet exist, create it first and then come back to enter the lower-level scientific name. (WP-SeedBank expects the top-level category to be the seed genus.)', 'wp-seedbank'),
'<em class="scientific_name">' . esc_html__('Allium cepa', 'wp-seedbank') . '</em>',
'<em class="scientific_name">' . esc_html__('Allium', 'wp-seedbank') . '</em>'
)
. '</li>';
$html .= '<li>'
. sprintf(
'<strong>' . esc_html__('Description:', 'wp-seedbank') . '</strong> '
. esc_html__('You can enter a short explanation of what this scientific name means for laypeople who are more familiar with common vernacular than scientific terms. You can also provide any extra information about this specific seed, such as scientific name synonyms or other custom notes. This provides a good teaching opportunity for those in your community who want to learn more about seed saving. You can also leave this field blank.', 'wp-seedbank')
)
. '</li>';
$html .= '</ol>';
$screen->add_help_tab(array(
'id' => $this->post_type . '-' . $screen->id . '-help-adding',
'title' => __('Adding new Scientific Names', 'wp-seedbank'),
'content' => $html
));
break;
default:
break;
}
// Tabs for all screens.
$screen->add_help_tab(array(
'id' => $this->post_type . '-' . $screen->base . '-about-help',
'title' => __('About the WP-SeedBank', 'wp-seedbank'),
'content' => '<p>' . sprintf(
esc_html__('The %1$s is a labor of love, and passion. Conceived by %2$s and %3$s, it is maintained by %4$s who loves fresh food and hates Monsanto. %5$s'),
'<a href="https://wordpress.org/plugins/wp-seedbank/" title="' . __('WP-SeedBank on the WordPress Plugin Repository', 'wp-seedbank') . '">' . __('WP-SeedBank plugin', 'wp-seedbank') . '</a>',
'<a href="http://www.hummingbirdproject.org/initiatives/wordpress-seedbank-plugin/" title="' . __('The HummingBird Project\'s WP-SeedBank Initiative', 'wp-seedbank') . '">' . __('The Hummingbird Project', 'wp-seedbank') . '</a>',
'<a href="http://permaculturenews.org/2013/09/25/an-open-source-community-model-to-save-seeds-a-wordpress-seedbank-plugin/" title="An Open Source Community Model to Save Seeds — a WordPress Seedbank Plugin" rel="bookmark">' . __('initially developed at Cleveland GiveCamp', 'wp-seedbank') . '</a>',
'<a href="http://wordpress.org/plugins/wp-seedbank/other_notes/" title="' . __('Credits for WP-SeedBank', 'wp-seedbank') . '">' . __('Donations are appreciated.', 'wp-seedbank') . '</a>'
) . '</p>'
));
$sidebar = '<p><strong>' . esc_html__('More WP-SeedBank help:', 'wp-seedbank') . '</strong></p>';
$sidebar .= '<p><a href="https://wordpress.org/support/plugin/wp-seedbank" target="_blank">' . esc_html__('WP-SeedBank support forum', 'wp-seedbank') . '</a></p>';
$sidebar .= '<p><a href="https://github.org/fabacab/wp-seedbank/issues/new" target="_blank">' . esc_html__('WP-SeedBank bug report form (for programmers)', 'wp-seedbank') . '</a></p>';
$sidebar .= '<p>' . sprintf(
esc_html__('WP-SeedBank is free software, but sadly grocery stores do not offer free food. Please consider %sdonating some food to the plugin maintainer%s. %s', 'wp-seedbank'),
'<strong><a href="http://maybemaimed.com/cyberbusking/#food">', '</a></strong>', '♥'
) . '</p>';
$screen->set_help_sidebar($screen->get_help_sidebar() . $sidebar);
}
public function activate () {
$this->registerL10n();
$this->createDataTypes(); // This registers new taxonomies.
global $wpdb;
// If any old 0.2.x versions exist
if ('0.2' === substr(get_option('wp_seedbank_version'), 0, 3)) {
$errors = array();
// we need to do some database & option cleanup that looks
// something like the following:
// delete the no longer used "addInfo" meta key globally.
delete_post_meta_by_key('wp_seedbank_addInfo');
// NOTE: This SQL is a bit blunt. Any safer ways to do it?
// UPDATE wp_posts SET post_type = 'seedbank' WHERE post_type = 'wp_seedbank';
$sql = $wpdb->prepare(
"UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s",
$this->post_type,
'wp_seedbank'
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_term_taxonomy SET taxonomy = REPLACE(taxonomy, 'wp_seedbank', 'seedbank');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->term_taxonomy} SET taxonomy = REPLACE(taxonomy, %s, %s)",
'wp_seedbank',
$this->post_type
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_term_taxonomy SET taxonomy = REPLACE(taxonomy, 'seedbank_type', 'seedbank_exchange_type');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->term_taxonomy} SET taxonomy = REPLACE(taxonomy, %s, %s)",
$this->post_type . '_type',
$this->post_type . '_exchange_type'
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_term_taxonomy SET taxonomy = REPLACE(taxonomy, 'seedbank_genus', 'seedbank_seed_genus');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->term_taxonomy} SET taxonomy = REPLACE(taxonomy, %s, %s)",
$this->post_type . '_genus',
$this->post_type . '_seed_genus'
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_term_taxonomy SET taxonomy = REPLACE(taxonomy, 'seedbank_status', 'seedbank_exchange_status');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->term_taxonomy} SET taxonomy = REPLACE(taxonomy, %s, %s)",
$this->post_type . '_status',
$this->post_type . '_exchange_status'
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_postmeta SET meta_key = REPLACE(meta_key, 'wp_seedbank', 'seedbank');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->postmeta} SET meta_key = REPLACE(meta_key, %s, %s)",
'wp_seedbank',
$this->post_type
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_postmeta SET meta_key = REPLACE(meta_key, 'seedbank_type', 'seedbank_exchange_type');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->postmeta} SET meta_key = REPLACE(meta_key, %s, %s)",
$this->post_type . '_type',
$this->post_type . '_exchange_type'
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// UPDATE wp_postmeta SET meta_key = REPLACE(meta_key, 'seedbank_status', 'seedbank_exchange_status');
$sql = $wpdb->prepare(
"UPDATE {$wpdb->postmeta} SET meta_key = REPLACE(meta_key, %s, %s)",
$this->post_type . '_status',
$this->post_type . '_exchange_status'
);
if (false === $wpdb->query($sql)) {
$errors[] = array($wpdb->last_query, $wpdb->last_error);
}
// Now we need to associate the posts with our taxonomies,
// and update expiry date fields to their Unix timestamps.
$sql = $wpdb->prepare(
"SELECT * FROM {$wpdb->postmeta} WHERE meta_key LIKE '%s'",
like_escape($this->post_type) . '%'
);
$results = $wpdb->get_results($sql);
foreach ($results as $row) {
if ($this->isDateOrTimeMeta($row->meta_key)) {
update_post_meta(
(int) $row->post_id,
$row->meta_key,
gmdate('U', strtotime($row->meta_value))
);
}
// Find all posts with one of our taxonomies,
// and for each of those posts, relate them to terms.
foreach ($this->taxonomies as $taxonomy) {
$key = $this->post_type . '_' . $taxonomy[0];
if ($row->meta_key === $key) {
wp_set_object_terms(
(int) $row->post_id,
sanitize_text_field($row->meta_value),
sanitize_text_field($this->post_type . '_' . $taxonomy[0])
);
}
}
}
if (empty($errors)) {
delete_option('wp_seedbank_version'); // No longer used.
} else {
// TODO: Handle errors?
}
}
// Detect existence of obsolete taxonomy and remove it.
$sql = $wpdb->prepare(
"SELECT DISTINCT taxonomy FROM {$wpdb->term_taxonomy} WHERE taxonomy=%s",
$this->post_type . '_seed_genus'
);
$results = $wpdb->get_results($sql);
if (!empty($results)) {
register_taxonomy($this->post_type . '_seed_genus', $this->post_type);
register_taxonomy_for_object_type($this->post_type . '_exchange_type', $this->post_type);
$terms = get_terms($this->post_type . '_seed_genus', array('hide_empty' => false));
foreach ($terms as $t) {
wp_delete_term($t->term_id, $this->post_type . '_seed_genus');
}
global $wp_taxonomies; // hacky way to unregister taxonomy
unset($wp_taxonomies[$this->post_type . '_seed_genus']);
}
// Detect lack of unit taxonomy and copy any unit post meta values.
$unit_terms = get_terms($this->post_type . '_unit', 'hide_empty=0');
if (empty($unit_terms)) {
$posts_with_unit_meta = get_posts(array(
'posts_per_page' => -1,
'post_type' => $this->post_type,
'meta_key' => $this->post_type . '_unit'
));
foreach ($posts_with_unit_meta as $p) {
wp_set_object_terms($p->ID, get_post_meta($p->ID, $this->post_type . '_unit', true), $this->post_type . '_unit');
}
}
flush_rewrite_rules();
// Exchange Types (verbs)
wp_insert_term(_x( 'Swap', 'verb', 'wp-seedbank'), $this->post_type . '_exchange_type', array('description' => __('Exchanges offering seeds for other seeds.', 'wp-seedbank')));
wp_insert_term(_x( 'Sell', 'verb', 'wp-seedbank'), $this->post_type . '_exchange_type', array('description' => __('Exchanges offering seeds for money.', 'wp-seedbank')));
wp_insert_term(_x( 'Give', 'verb', 'wp-seedbank'), $this->post_type . '_exchange_type', array('description' => __('Exchanges offering free seeds being given away.', 'wp-seedbank')));
wp_insert_term(_x( 'Get', 'verb', 'wp-seedbank'), $this->post_type . '_exchange_type', array('description' => __('Exchanges requesting seeds of a variety not already listed.', 'wp-seedbank')));
// Scientific names (as defined by ICNCP, 8th Ed.)
// International Code of Nomenclature for Cultivated Plants 8th Ed.
// That means hierarchical levels map to the following ranks:
//
// Genus (top-level "category" or "rank")
// |
// -- species
// |
// -- Group (cultivar Group) OR subspecies OR variety
// |
// -- cultivar
//
// Empty slugs to calculate the slug from the i18n'd term name.
if ($genus = wp_insert_term(__('Abelmoschus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
// WordPress taxonomy cache is still not invalidating properly.
// See
// https://wordpress.stackexchange.com/questions/8357/inserting-terms-in-an-hierarchical-taxonomy/8921#8921
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Abelmoschus esculentus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Agastache', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Allium', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Allium cepa', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
wp_insert_term(__('Allium porrum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
wp_insert_term(__('Allium sativum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
wp_insert_term(__('Allium schoenoprasum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
if ($genus = wp_insert_term(__('Amaranthus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Amaranthus tricolor', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Anagallis', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Anethum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Anthenum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Antirrhinum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Apium', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
if ($species = wp_insert_term(__('Apium graveolens', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']))) {
if (is_array($species)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Apium graveolens var. dulce', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
wp_insert_term(__('Apium graveolens var. rapaceum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
}
}
}
}
if ($genus = wp_insert_term(__('Arachis', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Arachis hypogaea', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
if ($genus = wp_insert_term(__('Asparagus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Asparagus officinalis', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Asclepias', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Basella', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Basella rubra', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
if ($genus = wp_insert_term(__('Beta', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
if ($species = wp_insert_term(__('Beta vulgaris', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']))) {
if (is_array($species)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Beta vulgaris subsp. cicla', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
}
}
}
}
if ($genus = wp_insert_term(__('Brassica', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Brassica napus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
if ($species = wp_insert_term(__('Brassica oleracea', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']))) {
if (is_array($species)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Brassica oleracea Acephala Group', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
wp_insert_term(__('Brassica oleracea Botrytis Group', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
wp_insert_term(__('Brassica oleracea Capitata Group', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
wp_insert_term(__('Brassica oleracea Gemmifera Group', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
wp_insert_term(__('Brassica oleracea Gongylodes Group', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
wp_insert_term(__('Brassica oleracea Italica Group', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
}
}
wp_insert_term(__('Brassica rapa', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Calendula', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Capsicum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Capsicum annuum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Cardiospermum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Centaurea', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Chrysanthemum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Cichorium', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Cichorium endivia', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
wp_insert_term(__('Cichorium intybus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
if ($genus = wp_insert_term(__('Citrullus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Citrullus lanatus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Cleome', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Cobaea', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Consolida', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Convolvulus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Coreopsis', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Coriandrum', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Cosmos', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Cucumis', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Cucumis melo', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
wp_insert_term(__('Cucumis sativa', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
if ($genus = wp_insert_term(__('Cucurbita', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Cucurbita pepo', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
wp_insert_term(__('Cucurbita maxima', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
if ($genus = wp_insert_term(__('Cynara', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Cynara scolymus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']));
}
}
wp_insert_term(__('Dalea', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Daucus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
if ($species = wp_insert_term(__('Daucus carota', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']))) {
if (is_array($species)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Daucus carota subsp. sativus', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
}
}
}
}
wp_insert_term(__('Diplotaxis', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Dolichos', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
wp_insert_term(__('Echinacea', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));
if ($genus = wp_insert_term(__('Eruca', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''))) {
if (is_array($genus)) {
delete_option($this->post_type . '_scientific_name_children');
if ($species = wp_insert_term(__('Eruca vesicaria', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $genus['term_id']))) {
if (is_array($species)) {
delete_option($this->post_type . '_scientific_name_children');
wp_insert_term(__('Eruca vesicaria subsp. sativa', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => '', 'parent' => $species['term_id']));
}
}
}
}
wp_insert_term(__('Eschscholzia', 'wp-seedbank'), $this->post_type . '_scientific_name', array('slug' => ''));