-
Notifications
You must be signed in to change notification settings - Fork 0
/
reveal-presentations.php
150 lines (136 loc) · 5.15 KB
/
reveal-presentations.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
<?php
/**
* Plugin Name: Presentations
* Description: Create presentations powered by Reveal.js. Each slide is an individual post. A taxonomy holds the slides for a presentation.
* Version: 0.1
* License: GPLv3
*/
namespace HWDSB\Reveal;
/** UTILITY */
/**
* Return path to our plugin directory.
*
* @param string $path Add relative path to end of directory.
* @return string
*/
function return_path( $path = '' ) {
return __DIR__ . '/' . $path;
}
/**
* Return URL to our plugin directory.
*
* @param string $path Add path to end of root URL.
* @return string
*/
function return_url( $path = '' ) {
return esc_url_raw( plugins_url( basename( __DIR__ ) . '/' . $path ) );
}
/**
* Returns property.
*
* @param string $param Property name.
* @return mixed
*/
function get( $param = '' ) {
switch ( $param ) {
case 'post_type_slug' :
return apply_filters( 'hwdsb_reveal_post_type_slug', 'slides' );
break;
case 'presentation_slug' :
return apply_filters( 'hwdsb_reveal_presentation_slug', 'presentation' );
break;
default :
return '';
}
}
/** HOOKS */
/**
* Conditional loader.
*/
add_action( 'after_setup_theme', function() {
// Admin.
if ( defined( 'WP_NETWORK_ADMIN' ) ) {
require_once return_path( 'includes/admin-loader.php' );
// Frontend.
} else {
require_once return_path( 'includes/frontend-loader.php' );
}
} );
/**
* Register our post type and taxonomy.
*/
add_action( 'init', function() {
// Set up the slide post type.
$labels = [
'name' => _x( 'Presentation Slides', 'post type general name', 'reveal-presentations' ),
'singular_name' => _x( 'Presentation Slide', 'post type singular name', 'reveal-presentations' ),
'add_new' => _x( 'Add New Slide', 'slide', 'reveal-presentations' ),
'add_new_item' => esc_html__( 'Add New Slide', 'reveal-presentations' ),
'edit_item' => esc_html__( 'Edit Slide', 'reveal-presentations' ),
'new_item' => esc_html__( 'New Slide', 'reveal-presentations' ),
'all_items' => esc_html__( 'All Slides', 'reveal-presentations' ),
'view_item' => esc_html__( 'View Slide', 'reveal-presentations' ),
'search_items' => esc_html__( 'Search Slides', 'reveal-presentations' ),
'not_found' => esc_html__('No slides found', 'reveal-presentations' ),
'not_found_in_trash' => esc_html__( 'No slides found in Trash', 'reveal-presentations' ),
'parent_item_colon' => '',
'menu_name' => esc_html__( 'Presentations', 'reveal-presentations' ),
];
$args = [
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => false,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-images-alt',
'menu_position' => apply_filters( 'hwdsb_reveal_menu_position', 20 ),
'supports' => [ 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions', 'unpublish' ],
'show_in_rest' => true,
];
register_post_type( get( 'post_type_slug' ), $args );
foreach ( [ 'css', 'color', 'transition', 'background-transition', 'transition-speed' ] as $key ) {
register_post_meta( get( 'post_type_slug' ), "presentation-{$key}", [
'show_in_rest' => true,
'single' => true,
'type' => 'string',
] );
}
// Set up the presentation taxonomy.
$labels = [
'name' => _x( 'Presentations', 'taxonomy general name', 'reveal-presentations' ),
'singular_name' => _x( 'Presentation', 'taxonomy singular name', 'reveal-presentations' ),
'search_items' => esc_html__( 'Search Presentations', 'reveal-presentations' ),
'popular_items' => esc_html__( 'Popular Presentations', 'reveal-presentations' ),
'all_items' => esc_html__( 'All Presentations', 'reveal-presentations' ),
'edit_item' => esc_html__( 'Edit Presentation', 'reveal-presentations' ),
'view_item' => esc_html__( 'View Presentation', 'reveal-presentations' ),
'update_item' => esc_html__( 'Update Presentation', 'reveal-presentations' ),
'add_new_item' => esc_html__( 'Add New Presentation', 'reveal-presentations' ),
'new_item_name' => esc_html__( 'New Presentation Name', 'reveal-presentations' ),
'back_to_items' => esc_html__( '← Back to Presentations', 'reveal-presentations' ),
'parent_item' => null,
'parent_item_colon' => null,
];
$args = [
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'rewrite' => true,
'sort' => true,
'show_in_rest' => true,
'rest_base' => get( 'presentation_slug' ) . 's',
'show_tagcloud' => false,
'show_admin_column' => true,
];
register_taxonomy( get( 'presentation_slug' ), get( 'post_type_slug' ), $args );
register_term_meta( get( 'presentation_slug' ), '_presentation_theme', [
'show_in_rest' => true,
'single' => true,
'type' => 'string',
] );
} );