-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclass-book-reviews.php
1702 lines (1558 loc) · 59.4 KB
/
class-book-reviews.php
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.
*
* @package Book_Reviews
* @author Chris Reynolds <hello@chrisreynolds.io>
* @license GPLv3
* @link http://chrisreynolds.io
* @copyright 2014 Chris Reynolds
*/
/**
* Plugin class.
*
* @package Book_Reviews
* @author Chris Reynolds <hello@chrisreynolds.io>
*/
class Book_Reviews {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
protected $version = '1.4.10';
/**
* Unique identifier for your plugin.
*
* Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
* match the Text Domain file header in the main plugin file.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_slug = 'book-review-library';
/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;
/**
* Slug of the plugin screen.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_screen_hook_suffix = null;
/**
* Initialize the plugin by setting localization, filters, and administration functions.
*
* @since 1.0.0
*/
private function __construct() {
include_once( 'views/actions.php' );
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Do i18n stuff
*
* @since 1.4
* @link http://ottopress.com/2013/language-packs-101-prepwork/
*/
public function setup_i18n() {
load_plugin_textdomain( 'book-review-library', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
}
/**
* Fired when the plugin is activated.
*
* @since 1.0.0
*
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
*/
public static function activate( $network_wide ) {
$result = add_role( 'librarian', __( 'Librarian', 'book-review-library' ), array(
// core WordPress caps
'read' => true,
'delete_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'upload_files' => true,
'unfiltered_html' => true,
'unfiltered_upload' => true,
'manage_options' => true, // temporary fix for permissions to save book review options
'manage_book_review_options' => true,
// Book Review-speicifc caps
'publish_book-reviews' => true,
'edit_book-reviews' => true,
'edit_published_book-reviews' => true,
'delete_book-reviews' => true,
'delete_published_book-reviews' => true,
'read_book-reviews' => true,
'edit_others_book-reviews' => true,
'delete_others_book-reviews' => true,
) );
$result = add_role( 'book-reviewer', __( 'Book Reviewer', 'book-review-library' ), array(
// core WordPress caps
'read' => true,
'delete_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'upload_files' => true,
'unfiltered_html' => true,
'unfiltered_upload' => true,
// Book Review-specific caps
'publish_book-reviews' => true,
'edit_book-reviews' => true,
'edit_published_book-reviews' => true,
'delete_book-reviews' => true,
'delete_published_book-reviews' => true,
'read_book-reviews' => true,
) );
// add book-reviews caps to authors
if ( get_role( 'author' ) ) {
$role = get_role( 'author' );
$role->add_cap( 'add_book-reviews' );
$role->add_cap( 'publish_book-reviews' );
$role->add_cap( 'edit_book-reviews' );
$role->add_cap( 'read_book-reviews' );
$role->add_cap( 'edit_published_book-reviews' );
$role->add_cap( 'delete_published_book-reviews' );
$role->add_cap( 'delete_book-reviews' );
}
// add book-reviews caps to editors
if ( get_role( 'editor' ) ) {
$role = get_role( 'editor' );
$role->add_cap( 'add_book-reviews' );
$role->add_cap( 'publish_book-reviews' );
$role->add_cap( 'edit_book-reviews' );
$role->add_cap( 'edit_others_book-reviews' );
$role->add_cap( 'read_book-reviews' );
$role->add_cap( 'edit_published_book-reviews' );
$role->add_cap( 'delete_published_book-reviews' );
$role->add_cap( 'delete_book-reviews' );
}
// add book-reviews caps to admins
if ( get_role( 'administrator' ) ) {
$role = get_role( 'administrator' );
$role->add_cap( 'add_book-reviews' );
$role->add_cap( 'publish_book-reviews' );
$role->add_cap( 'edit_book-reviews' );
$role->add_cap( 'edit_others_book-reviews' );
$role->add_cap( 'read_book-reviews' );
$role->add_cap( 'edit_published_book-reviews' );
$role->add_cap( 'delete_published_book-reviews' );
$role->add_cap( 'delete_book-reviews' );
$role->add_cap( 'manage_book_review_options' );
}
}
/**
* Fired when the plugin is deactivated.
*
* @since 1.0.0
*
* @param boolean $network_wide True if WPMU superadmin uses "Network Deactivate" action, false if WPMU is disabled or plugin is deactivated on an individual blog.
*/
public static function deactivate( $network_wide ) {
if ( get_role( 'librarian' ) ) {
$role = get_role( 'librarian' );
$role->remove_cap( 'delete_published_book-reviews' );
$role->remove_cap( 'edit_published_book-reviews' );
$role->remove_cap( 'publish_book-reviews' );
$role->remove_cap( 'edit_book-reviews' );
$role->remove_cap( 'delete_book-reviews' );
$role->remove_cap( 'read_book-reviews' );
$role->remove_cap( 'edit_others_book-reviews' );
$role->remove_cap( 'edit_minute' );
$role->remove_cap( 'manage_book_review_options' );
$role->remove_cap( 'manage_options' );
remove_role( 'librarian' );
}
if ( get_role( 'book-reviewer' ) ) {
$role = get_role( 'book-reviewer' );
$role->remove_cap( 'add_book-reviews' );
$role->remove_cap( 'delete_published_book-reviews' );
$role->remove_cap( 'edit_published_book-reviews' );
$role->remove_cap( 'publish_book-reviews' );
$role->remove_cap( 'edit_book-reviews' );
$role->remove_cap( 'delete_book-reviews' );
$role->remove_cap( 'read_book-reviews' );
remove_role( 'book-reviewer' );
}
if ( get_role( 'author' ) ) {
$role = get_role( 'author' );
$role->remove_cap( 'add_agenda' );
$role->remove_cap( 'publish_book-reviews' );
$role->remove_cap( 'edit_book-reviews' );
$role->remove_cap( 'read_book-reviews' );
$role->remove_cap( 'edit_published_book-reviews' );
$role->remove_cap( 'delete_published_book-reviews' );
$role->remove_cap( 'delete_book-reviews' );
}
if ( get_role( 'editor' ) ) {
$role = get_role( 'editor' );
$role->remove_cap( 'add_agenda' );
$role->remove_cap( 'add_book-reviews' );
$role->remove_cap( 'publish_book-reviews' );
$role->remove_cap( 'edit_book-reviews' );
$role->remove_cap( 'edit_others_book-reviews' );
$role->remove_cap( 'read_book-reviews' );
$role->remove_cap( 'edit_published_book-reviews' );
$role->remove_cap( 'delete_published_book-reviews' );
$role->remove_cap( 'delete_book-reviews' );
}
if ( get_role( 'administrator' ) ) {
$role = get_role( 'administrator' );
$role->remove_cap( 'add_agenda' );
$role->remove_cap( 'add_book-reviews' );
$role->remove_cap( 'publish_book-reviews' );
$role->remove_cap( 'edit_book-reviews' );
$role->remove_cap( 'edit_others_book-reviews' );
$role->remove_cap( 'read_book-reviews' );
$role->remove_cap( 'edit_published_book-reviews' );
$role->remove_cap( 'delete_published_book-reviews' );
$role->remove_cap( 'delete_book-reviews' );
$role->remove_cap( 'manage_book_review_options' );
}
wp_delete_term( '0', 'rating' );
wp_delete_term( '1', 'rating' );
wp_delete_term( '2', 'rating' );
wp_delete_term( '3', 'rating' );
wp_delete_term( '4', 'rating' );
wp_delete_term( '5', 'rating' );
}
/**
* Remove the settings menu for librarians
*
* @since 1.4.6
*
* @todo Remove this when manage_book_review_options cap is working
*/
public function remove_menu_for_librarians() {
$user = wp_get_current_user();
if ( 'librarian' == $user->roles[0] ) { // if the current user is a librarian
remove_menu_page( 'options-general.php' );
}
}
/**
* Register and enqueue admin-specific style sheet.
*
* @since 1.0.0
*
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_styles() {
wp_enqueue_style( 'genericons', plugins_url( 'genericons/genericons.css', __FILE__ ), array(), $this->version );
wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
}
/**
* Register and enqueue admin-specific JavaScript.
*
* @since 1.0.0
*
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_scripts() {
if ( is_admin() && current_user_can( 'publish_book-reviews' ) ) {
wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), $this->version );
wp_enqueue_script( 'media-upload' );
}
}
/**
* Register and enqueue genericons style sheet.
*
* @since 1.0.0
*/
public function enqueue_styles() {
global $post;
if ( ! is_admin() && ( 'book-review' == get_post_type() || ( is_page() && has_shortcode( $post->post_content, 'book-reviews' ) ) ) ) {
wp_enqueue_style( $this->plugin_slug . '-genericons', plugins_url( 'genericons/genericons.css', __FILE__ ), array(), $this->version );
wp_enqueue_style( $this->plugin_slug . '-public', plugins_url( 'css/public.css', __FILE__ ), array(), $this->version );
}
}
/**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
*
* @since 0.1
*/
public function add_plugin_admin_menu() {
$this->plugin_screen_hook_suffix = add_submenu_page(
'edit.php?post_type=book-review',
__( 'Book Reviews Options', 'book-review-library' ),
__( 'Options', 'book-review-library' ),
'manage_book_review_options',
$this->plugin_slug . '-options',
array( $this, 'display_plugin_admin_page' )
);
}
/**
* Render the settings page for this plugin.
*
* @since 1.0.0
*/
public function display_plugin_admin_page() {
include_once( 'views/admin.php' );
}
/**
* Flush rewrite rules
*
* @since 1.4.3
*/
public function flush_rewrites() {
flush_rewrite_rules();
}
/**
* Register the book review post type
*
* @since 1.0.0
*/
public function register_post_type_book_review() {
include_once( BOOK_REVIEWS_FUNC );
$defaults = book_reviews_option_defaults();
$options = get_option( 'book_reviews_settings', $defaults );
if ( isset( $options['comments'] ) && $options['comments'] ) {
$supports = array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'comments' );
} else {
$supports = array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions' );
}
$capabilities = array(
'publish_posts' => 'publish_book-reviews',
'edit_posts' => 'edit_book-reviews',
'edit_others_posts' => 'edit_others_book-reviews',
'delete_posts' => 'delete_book-reviews',
'edit_post' => 'edit_book-review',
'delete_post' => 'delete_book-review',
'read_post' => 'read_book-review',
);
$labels = array(
'name' => __( 'Book Reviews', 'book-review-library' ),
'singular_name' => __( 'Book Review', 'book-review-library' ),
'add_new' => __( 'Add New', 'book-review-library' ),
'add_new_item' => __( 'Add New Book Review', 'book-review-library' ),
'edit_item' => __( 'Edit Review', 'book-review-library' ),
'new_item' => __( 'New Book Review', 'book-review-library' ),
'view_item' => __( 'View Book Review', 'book-review-library' ),
'search_items' => __( 'Search Book Reviews', 'book-review-library' ),
'not_found' => __( 'No book reviews found', 'book-review-library' ),
'not_found_in_trash' => __( 'No book reviews found in Trash', 'book-review-library' ),
'menu_name' => __( 'Book Reviews', 'book-review-library' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Book Review',
'supports' => $supports,
'taxonomies' => array( 'genre', 'review-author' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'book-review',
'capabilities' => $capabilities,
'map_meta_cap' => true,
);
register_post_type( 'book-review', $args );
}
/**
* Register the genre taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_genre() {
register_taxonomy('genre', array( 'book-review' ), array(
'label' => __( 'Genres', 'book-review-library' ),
'labels' => array(
'name' => __( 'Genres', 'book-review-library' ),
'singular_name' => __( 'Genre', 'book-review-library' ),
'search_items' => __( 'Search Genres', 'book-review-library' ),
'popular_items' => __( 'Popular Genres', 'book-review-library' ),
'all_items' => __( 'All Genres', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Genre', 'book-review-library' ),
'update_item' => __( 'Update Genre', 'book-review-library' ),
'add_new_item' => __( 'Add New Genre', 'book-review-library' ),
'new_item_name' => __( 'New Genre Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate genres with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove genres', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used genres', 'book-review-library' ),
'not_found' => __( 'No genres found', 'book-review-library' ),
'menu_name' => __( 'Genres', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => false,
'update_count_callback' => '',
'query_var' => 'genre',
'rewrite' => array(
'slug' => 'genre',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the review author taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_review_author() {
register_taxonomy('review-author', array( 'book-review' ), array(
'label' => __( 'Review Author', 'book-review-library' ),
'labels' => array(
'name' => __( 'Review Author', 'book-review-library' ),
'singular_name' => __( 'Review Author', 'book-review-library' ),
'search_items' => __( 'Search Review Authors', 'book-review-library' ),
'popular_items' => __( 'Popular Review Authors', 'book-review-library' ),
'all_items' => __( 'All Review Authors', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Review Author', 'book-review-library' ),
'update_item' => __( 'Update Review Author', 'book-review-library' ),
'add_new_item' => __( 'Add New Review Author', 'book-review-library' ),
'new_item_name' => __( 'New Review Author Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Review Authors with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Review Authors', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Review Authors', 'book-review-library' ),
'menu_name' => __( 'Review Authors', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'update_count_callback' => '',
'query_var' => 'review-author',
'rewrite' => array(
'slug' => 'review-author',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the book author taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_book_author() {
register_taxonomy('book-author', array( 'book-review' ), array(
'label' => __( 'Book Authors', 'book-review-library' ),
'labels' => array(
'name' => __( 'Book Authors', 'book-review-library' ),
'singular_name' => __( 'Author', 'book-review-library' ),
'search_items' => __( 'Search Book Authors', 'book-review-library' ),
'popular_items' => __( 'Popular Book Authors', 'book-review-library' ),
'all_items' => __( 'All Book Authors', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Author', 'book-review-library' ),
'update_item' => __( 'Update Author', 'book-review-library' ),
'add_new_item' => __( 'Add New Author', 'book-review-library' ),
'new_item_name' => __( 'New Author Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Book Authors with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Book Authors', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Book Authors', 'book-review-library' ),
'menu_name' => __( 'Book Authors', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'update_count_callback' => '',
'query_var' => 'book-author',
'rewrite' => array(
'slug' => 'book-author',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the reading level taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_reading_level() {
register_taxonomy('reading-level', array( 'book-review' ), array(
'label' => __( 'Reading Level', 'book-review-library' ),
'labels' => array(
'name' => __( 'Reading Level', 'book-review-library' ),
'singular_name' => __( 'Reading Level', 'book-review-library' ),
'search_items' => __( 'Search Reading Levels', 'book-review-library' ),
'popular_items' => __( 'Popular Reading Levels', 'book-review-library' ),
'all_items' => __( 'All Reading Levels', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Reading Level', 'book-review-library' ),
'update_item' => __( 'Update Reading Level', 'book-review-library' ),
'add_new_item' => __( 'Add New Reading Level', 'book-review-library' ),
'new_item_name' => __( 'New Reading Level Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Reading Levels with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Reading Levels', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Reading Levels', 'book-review-library' ),
'menu_name' => __( 'Reading Levels', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => false,
'update_count_callback' => '',
'query_var' => 'reading-level',
'rewrite' => array(
'slug' => 'reading-level',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the subject taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_subject() {
register_taxonomy('subject', array( 'book-review' ), array(
'label' => __( 'Subjects', 'book-review-library' ),
'labels' => array(
'name' => __( 'Subjects', 'book-review-library' ),
'singular_name' => __( 'Subject', 'book-review-library' ),
'search_items' => __( 'Search Subjects', 'book-review-library' ),
'popular_items' => __( 'Popular Subjects', 'book-review-library' ),
'all_items' => __( 'All Subjects', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Subject', 'book-review-library' ),
'update_item' => __( 'Update Subject', 'book-review-library' ),
'add_new_item' => __( 'Add New Subject', 'book-review-library' ),
'new_item_name' => __( 'New Subject Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Subjects with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Subjects', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Subjects', 'book-review-library' ),
'menu_name' => __( 'Subjects', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => false,
'update_count_callback' => '',
'query_var' => 'subject',
'rewrite' => array(
'slug' => 'subject',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the illustrator taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_illustrator() {
register_taxonomy('illustrator', array( 'book-review' ), array(
'label' => __( 'Illustrators', 'book-review-library' ),
'labels' => array(
'name' => __( 'Illustrators', 'book-review-library' ),
'singular_name' => __( 'Illustrator', 'book-review-library' ),
'search_items' => __( 'Search Illustrators', 'book-review-library' ),
'popular_items' => __( 'Popular Illustrators', 'book-review-library' ),
'all_items' => __( 'All Illustrators', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Illustrator', 'book-review-library' ),
'update_item' => __( 'Update Illustrator', 'book-review-library' ),
'add_new_item' => __( 'Add New Illustrator', 'book-review-library' ),
'new_item_name' => __( 'New Illustrator Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Illustrators with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Illustrators', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Illustrators', 'book-review-library' ),
'menu_name' => __( 'Illustrators', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'update_count_callback' => '',
'query_var' => 'illustrator',
'rewrite' => array(
'slug' => 'illustrator',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the awards taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_awards() {
register_taxonomy('awards', array( 'book-review' ), array(
'label' => __( 'Awards', 'book-review-library' ),
'labels' => array(
'name' => __( 'Awards', 'book-review-library' ),
'singular_name' => __( 'Award', 'book-review-library' ),
'search_items' => __( 'Search Awards', 'book-review-library' ),
'popular_items' => __( 'Popular Awards', 'book-review-library' ),
'all_items' => __( 'All Awards', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Award', 'book-review-library' ),
'update_item' => __( 'Update Award', 'book-review-library' ),
'add_new_item' => __( 'Add New Award', 'book-review-library' ),
'new_item_name' => __( 'New Award Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Awards with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Awards', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Awards', 'book-review-library' ),
'menu_name' => __( 'Awards', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => false,
'update_count_callback' => '',
'query_var' => 'awards',
'rewrite' => array(
'slug' => 'awards',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the series taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_series() {
register_taxonomy('series', array( 'book-review' ), array(
'label' => __( 'Series', 'book-review-library' ),
'labels' => array(
'name' => __( 'Series', 'book-review-library' ),
'singular_name' => __( 'Series', 'book-review-library' ),
'search_items' => __( 'Search Series', 'book-review-library' ),
'popular_items' => __( 'Popular Series', 'book-review-library' ),
'all_items' => __( 'All Series', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Series', 'book-review-library' ),
'update_item' => __( 'Update Series', 'book-review-library' ),
'add_new_item' => __( 'Add New Series', 'book-review-library' ),
'new_item_name' => __( 'New Series Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Series with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Series', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Series', 'book-review-library' ),
'menu_name' => __( 'Series', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'update_count_callback' => '',
'query_var' => 'series',
'rewrite' => array(
'slug' => 'series',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Register the rating taxonomy
*
* @since 1.0.0
*/
public function register_taxonomy_rating() {
register_taxonomy('rating', array( 'book-review' ), array(
'label' => __( 'Star Ratings', 'book-review-library' ),
'labels' => array(
'name' => __( 'Star Ratings', 'book-review-library' ),
'singular_name' => __( 'Star', 'book-review-library' ),
'search_items' => __( 'Search Ratings', 'book-review-library' ),
'popular_items' => __( 'Popular Ratings', 'book-review-library' ),
'all_items' => __( 'Stars', 'book-review-library' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Rating', 'book-review-library' ),
'update_item' => __( 'Update Rating', 'book-review-library' ),
'add_new_item' => __( 'Add New Rating', 'book-review-library' ),
'new_item_name' => __( 'New Rating Name', 'book-review-library' ),
'separate_items_with_commas' => __( 'Separate Star Ratings with commas', 'book-review-library' ),
'add_or_remove_items' => __( 'Add or remove Star Ratings', 'book-review-library' ),
'choose_from_most_used' => __( 'Choose from the most used Star Ratings', 'book-review-library' ),
'menu_name' => __( 'Star Ratings', 'book-review-library' ),
),
'public' => true,
'show_in_nav_menus' => false,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'update_count_callback' => '',
'query_var' => 'rating',
'rewrite' => array(
'slug' => 'rating',
'with_front' => true,
'hierarchical' => false,
),
'capabilities' => array(
'manage_terms' => 'edit_book-reviews',
'edit_terms' => 'edit_book-reviews',
'delete_terms' => 'edit_others_book-reviews',
'manage_categories' => 'edit_book-reviews',
'assign_terms' => 'edit_book-reviews',
),
));
}
/**
* Inserts the rating levels
*
* @since 1.0.0
*/
public function insert_star_ratings() {
wp_insert_term( '0', 'rating', array(
'description' => __( 'Zero stars', 'book-review-library' ),
'slug' => 'zero-stars',
) );
wp_insert_term( '1', 'rating', array(
'description' => __( 'One star', 'book-review-library' ),
'slug' => 'one-star',
) );
wp_insert_term( '2', 'rating', array(
'description' => __( 'Two stars', 'book-review-library' ),
'slug' => 'two-stars',
) );
wp_insert_term( '3', 'rating', array(
'description' => __( 'Three stars', 'book-review-library' ),
'slug' => 'three-stars',
) );
wp_insert_term( '4', 'rating', array(
'description' => __( 'Four stars', 'book-review-library' ),
'slug' => 'four-stars',
) );
wp_insert_term( '5', 'rating', array(
'description' => __( 'Five stars', 'book-review-library' ),
'slug' => 'five-stars',
) );
}
/**
* Removes rating submenu so rating levels cannot be (easily) changed from the default
*
* @since 1.0.0
*/
public function remove_rating_submenu() {
remove_submenu_page( 'edit.php?post_type=book-review','edit-tags.php?taxonomy=rating&post_type=book-review' );
}
/**
* Moves the taxonomy meta boxes around and modifies the featured image text
*
* @since 1.0.0
*/
public function move_meta_boxes() {
global $wp_meta_boxes;
$screen = get_current_screen();
if ( 'book-review' != $screen->post_type ) {
return;
} else {
include_once( BOOK_REVIEWS_FUNC );
$options = get_option( 'book_reviews_settings', book_reviews_option_defaults() );
unset( $wp_meta_boxes['book-review']['normal']['core']['authordiv'] );
unset( $wp_meta_boxes['book-review']['side']['core']['book-authordiv'] );
add_meta_box( 'book-authordiv', __( 'Book Author', 'book-review-library' ), 'post_categories_meta_box', 'book-review', 'normal', 'core', array( 'taxonomy' => 'book-author' ) );
if ( isset( $options['illustrator'] ) && ($options['illustrator'] == true) ) {
unset( $wp_meta_boxes['book-review']['side']['core']['illustratordiv'] );
add_meta_box( 'illustratordiv', __( 'Illustrator', 'book-review-library' ), 'post_categories_meta_box', 'book-review', 'normal', 'core', array( 'taxonomy' => 'illustrator' ) );
}
if ( isset( $options['series'] ) && ($options['series'] == true) ) {
unset( $wp_meta_boxes['book-review']['side']['core']['seriesdiv'] );
add_meta_box( 'seriesdiv', __( 'Series', 'book-review-library' ), 'post_categories_meta_box', 'book-review', 'normal', 'core', array( 'taxonomy' => 'series' ) );
}
if ( isset( $options['reading-level'] ) && ($options['reading-level'] == true) ) {
unset( $wp_meta_boxes['book-review']['side']['core']['tagsdiv-reading-level'] );
add_meta_box( 'tagsdiv-reading-level', __( 'Reading Level', 'book-review-library' ), 'post_tags_meta_box', 'book-review', 'normal', 'core', array( 'taxonomy' => 'reading-level' ) );
}
if ( isset( $options['rating'] ) && ($options['rating'] == true) ) {
unset( $wp_meta_boxes['book-review']['side']['core']['ratingdiv'] );
add_meta_box( 'ratingdiv', __( 'Star Rating', 'book-review-library' ), 'post_categories_meta_box', 'book-review', 'normal', 'core', array( 'taxonomy' => 'rating' ) );
}
remove_meta_box( 'postimagediv', 'book-review', 'side' );
add_meta_box( 'postimagediv', __( 'Book Cover', 'book-review-library' ), 'post_thumbnail_meta_box', 'book-review', 'side', 'default' );
}
}
/**
* Adds the Additional Information meta box for book review posts
*
* @since 1.0.0
*/
public function book_reviews_meta_box() {
add_meta_box( 'book-reviews-meta', __( 'Additional Information', 'book-review-library' ), array( $this, 'book_reviews_box' ), 'book-review', 'normal', 'default' );
}
/**
* Renters the actual content of the Additional Information meta box
*
* @since 1.0.0
*/
public function book_reviews_box() {
global $post;
include_once( BOOK_REVIEWS_FUNC );
$options = get_option( 'book_reviews_settings', book_reviews_option_defaults() );
echo '<input type="hidden" name="noncename" id="noncename" value="' .
wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
echo '<div class="isbn-meta">';
echo '<label for="isbn"><strong>' . __( 'ISBN:', 'book-review-library' ) . '</strong></label><br />';
echo '<input class="widefat" id="isbn" name="isbn" value="' . wp_strip_all_tags( get_post_meta( $post->ID, 'isbn', true ), true ) . '" type="text" />';
echo '</div>';
if ( isset( $options['stock'] ) && ($options['stock'] == true) ) {
echo '<div class="in-stock-box">';
echo '<label for="in-stock"><strong>' . __( 'In stock?', 'book-review-library' ) . '</strong></label><br />';
echo '<select name="book_in_stock">';
$selected = get_post_meta( $post->ID, 'book_in_stock', true );
echo '<option value="1" ' . selected( $selected, 1 ) . '>' . __( 'Book is in stock', 'book-review-library' ) . '</option>';
echo '<option value="0" ' . selected( $selected, 0 ) . '>' . __( 'Book out of stock', 'book-review-library' ) . '</option>';
echo '</select>';
echo '</div>';
}
if ( isset( $options['awards'] ) && ($options['awards'] == true) ) {
echo '<div class="award-image-upload">';
echo '<label for-"award-image-upload"><strong>' . __( 'Upload Award Image', 'book-review-library' ) . '</strong></label><br />';
echo '<input style="width: 55%;" id="award_image" class="award_image" name="award_image" value="' . get_post_meta( $post->ID, 'award_image', true ) . '" type="text" /> <input id="upload_file_image_button" type="button" class="upload_button button button-primary" value="Upload Image" />';
echo '</div>';
}
}
/**
* Registers the options
*
* @since 1.0.0
*/
public function settings_init() {
register_setting( 'book_reviews_settings', 'book_reviews_settings' );
}
/**
* Filter for the featured image post box
*
* @since 1.0.0