-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwordpress-playground-plugin.php
343 lines (282 loc) · 11.5 KB
/
wordpress-playground-plugin.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
<?php
/*
Plugin Name: Custom Post Plugin
Description: Plugin to create custom post gremlin
*/
/*Creating new issue */
function create_issues(){
$labels=array(
'name' => 'Issues',
'singular_name' => 'Issue',
'add_new' => _x('Add New', 'coin'),
'add_new_item' =>__('Add a Issue'),
'edit_item' =>__('Edit Issue'),
'new_item' =>__('New Issue'),
'all_items' =>__('All Issues'),
'view_item' =>__('View Issue'),
'search_items' => __('Search Issue'),
'not_found' => __('No issues found'),
'not_found_in_trash' => __('No issues found in the trash'),
'parent_item_colon' => '',
'menu_name' => "Issues"
);
$args=array(
'labels' => $labels,
'description' => 'Use to create and manage journal issues',
'public' => true,
'exclude_from_search'=>false,
'menu_position'=> 5,
'supports' => array('title','editor','excerpt'),
'has_archive' => true
);
register_post_type('issue',$args);
};
add_action( 'init', 'create_issues' );
/* Cutstomizing Issue messages */
function updated_issue_messages( $messages ) {
global $post, $post_ID;
$messages['issue'] = array(
0 => '',
1 => sprintf( __('Issue updated. <a href="%s">View issue</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('issue updated.'),
3 => __('issue banished.'),
4 => __('issue updated.'),
5 => isset($_GET['revision']) ? sprintf( __('issue restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('issue published. <a href="%s">View issue</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('issue saved.'),
8 => sprintf( __('issue submitted. <a target="_blank" href="%s">Preview issue</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('issue scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview issue</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('issue draft updated. <a target="_blank" href="%s">Preview issue</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter( 'post_updated_messages', 'updated_issue_messages' );
/* Customizing issue help section */
function issue_contextual_help($contextual_help, $screen_id, $screen){
if('issue' == $screen->id){
$contextual_help = '<h2>Issue</h2>
<p> Use to create journal issues </p>';
}
elseif ( 'edit-issue' == $screen->id ) {
$contextual_help = '<h2>Issue editing</h2>
<p>This page allows you to view and modify journal issues';
}
return $contextual_help;
};
add_action( 'contextual_help', 'issue_contextual_help', 10, 3 );
/* Creating issue taxonomy theme */
function issue_taxonomies(){
$labels=array(
'name' => _x( ' Issue Themes', 'taxonomy general name' ),
'singular_name' => _x( 'Issue Theme', 'taxonomy singular name' ),
'search_items' => __( 'Search Issue Themes' ),
'all_items' => __( 'All Issue Themes' ),
'parent_item' => __( 'Parent Issue Theme' ),
'parent_item_colon' => __( 'Parent Issue Theme:' ),
'edit_item' => __( 'Edit Issue Theme' ),
'update_item' => __( 'Update Issue Theme' ),
'add_new_item' => __( 'Add New Issue Theme' ),
'new_item_name' => __( 'New Issue Theme' ),
'menu_name' => __( 'Issue Themes' ),
);
$args=array(
'labels'=>$labels,
'hierarchical'=>false
);
register_taxonomy('Themes','issue', $args);
};
add_action('init','issue_taxonomies',0);
/*----------------------------------------------------------------/*
/* Create Artcles */
function create_article(){
$labels=array(
'name' => 'Articles',
'singular_name' => 'Article',
'add_new' => _x('Add New', 'coin'),
'add_new_item' =>__('Add a Article'),
'edit_item' =>__('Edit Article'),
'new_item' =>__('New Article'),
'all_items' =>__('All Articles'),
'view_item' =>__('View Article'),
'search_items' => __('Search Article'),
'not_found' => __('No Articles found'),
'not_found_in_trash' => __('No articles found in the trash'),
'parent_item_colon' => '',
'menu_name' => "Articles"
);
$args=array(
'labels' => $labels,
'description' => 'For journal articles',
'public' => true,
'menu_position'=> 5,
'supports' => array('title','author','editor','thumbnail','excerpt','comments'),
'has_archive' => true
);
register_post_type('article',$args);
};
add_action( 'init', 'create_article' );
/* Cutstomizing article messages */
function updated_article_messages( $messages ) {
global $post, $post_ID;
$messages['article'] = array(
0 => '',
1 => sprintf( __('Article updated. <a href="%s">View article</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Article updated.'),
3 => __('Article banished.'),
4 => __('Article updated.'),
5 => isset($_GET['revision']) ? sprintf( __('Article restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Article published. <a href="%s">View article</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Article saved.'),
8 => sprintf( __('Article submitted. <a target="_blank" href="%s">Preview article</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Article scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview article</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Article draft updated. <a target="_blank" href="%s">Preview article</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter( 'post_updated_messages', 'updated_article_messages' );
/* Customizing article help section */
function article_contextual_help($contextual_help, $screen_id, $screen){
if('article' == $screen->id){
$contextual_help = '<h2>Article</h2>
<p> Use to create journal articles </p>';
}
elseif ( 'edit-article' == $screen->id ) {
$contextual_help = '<h2>Article editing</h2>
<p>This page allows you to view and modify journal articles';
}
return $contextual_help;
};
add_action( 'contextual_help', 'article_contextual_help', 10, 3 );
/* Creating article taxonomy theme */
function article_taxonomies(){
$labels=array(
'name' => _x( ' Article Topics', 'taxonomy general name' ),
'singular_name' => _x( 'Article Topic', 'taxonomy singular name' ),
'search_items' => __( 'Search Article Topics' ),
'all_items' => __( 'All Article Topics' ),
'parent_item' => __( 'Parent Article Topic' ),
'parent_item_colon' => __( 'Parent Article Topic:' ),
'edit_item' => __( 'Edit Article Topic' ),
'update_item' => __( 'Update Article Topic' ),
'add_new_item' => __( 'Add New Article Topic' ),
'new_item_name' => __( 'New Article Topic' ),
'menu_name' => __( 'Article Topics' ),
);
$args=array(
'labels'=>$labels,
'hierarchical'=>false
);
register_taxonomy('Topics','article', $args);
};
add_action('init','article_taxonomies',0);
function create_new_post_gremlin(){
$labels=array(
'name' => 'Gremlins',
'singular_name' => 'Gremlin',
'add_new' => _x('Add New', 'coin'),
'add_new_item' =>__('Add a gremlin'),
'edit_item' =>__('Edit Gremlin'),
'new_item' =>__('New Gremlin'),
'all_items' =>__('All Gremlins'),
'view_item' =>__('View Gremlin'),
'search_items' => __('Search Gremlin'),
'not_found' => __('No gremlins found'),
'not_found_in_trash' => __('No gremlins found in the trash'),
'parent_item_colon' => '',
'menu_name' => "Gremlins"
);
$args=array(
'labels' => $labels,
'description' => 'Use to create and manage your gremlins',
'public' => true,
'menu_position'=> 5,
'supports' => array('title','editor','thumbnail','excerpt','comments'),
'has_archive' => true
);
register_post_type('Gremlin',$args);
};
add_action( 'init', 'create_new_post_gremlin' );
function my_updated_messages( $messages ) {
global $post, $post_ID;
$messages['gremlin'] = array(
0 => '',
1 => sprintf( __('Grelim updated. <a href="%s">View gremlin</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Gremlin updated.'),
3 => __('Gremlin banished.'),
4 => __('Gremlin updated.'),
5 => isset($_GET['revision']) ? sprintf( __('Gremlin restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Gremlin published. <a href="%s">View gremlin</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Gremlin saved.'),
8 => sprintf( __('Gremlin submitted. <a target="_blank" href="%s">Preview gremlin</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Gremlin scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview gremlin</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Gremlin draft updated. <a target="_blank" href="%s">Preview gremlin</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
};
add_filter( 'post_updated_messages', 'my_updated_messages' );
function gremlin_contextual_help($contextual_help, $screen_id, $screen){
if('gremlin' == $screen->id){
$contextual_help = '<h2>Gremlin</h2>
<p> A page to manage your mischievous gremlins</p>';
}
elseif ( 'edit-gremlin' == $screen->id ) {
$contextual_help = '<h2>Making changes to your gremlins</h2>
<p>This page allows you to view and modify your gremlins';
}
return $contextual_help;
};
add_action( 'contextual_help', 'gremlin_contextual_help', 10, 3 );
function gremlin_taxonomies(){
$labels=array(
'name' => _x( 'Gremlin Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Gremlin Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Gremlin Categories' ),
'all_items' => __( 'All Gremlin Categories' ),
'parent_item' => __( 'Parent Gremlin Category' ),
'parent_item_colon' => __( 'Parent Gremlin Category:' ),
'edit_item' => __( 'Edit Gremlin Category' ),
'update_item' => __( 'Update Gremlin Category' ),
'add_new_item' => __( 'Add New Gremlin Category' ),
'new_item_name' => __( 'New Gremlin Category' ),
'menu_name' => __( 'Gremlin Categories' ),
);
$args=array(
'labels'=>$labels,
'hierarchical'=>true
);
register_taxonomy('gremlin_category','gremlin', $args);
};
add_action('init','gremlin_taxonomies',0);
add_action( 'add_meta_boxes', 'gremlin_price_box' );
function gremlin_price_box() {
add_meta_box(
'gremlin price_box',
'Gremlin Price',
'gremlin_price_box_content',
'gremlin',
'side',
'high'
);
}
function gremlin_price_box_content( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'product_price_box_content_nonce' );
echo '<label for="product_price"></label>';
echo '<input type="text" id="product_price" name="product_price" placeholder="enter a price" />';
}
add_action( 'save_post', 'gremlin_price_box_save' );
function gremlin_price_box_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !wp_verify_nonce( $_POST['product_price_box_content_nonce'], plugin_basename( __FILE__ ) ) )
return;
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
$gremlin_price = $_POST['gremlin_price'];
update_post_meta( $post_id, 'gremlin_price', $gremlin_price );
}
?>