-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbizzle_cpt_template_deluxe.php
306 lines (251 loc) · 10.4 KB
/
bizzle_cpt_template_deluxe.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
<?php
/*
Plugin Name: **Name This Plugin**
Plugin URI: http://www.bizzledesigns.com
Description: A Plugin to Add Custom Post Types to any Wordpress website
Version: 2.0
Author: Mr. Rob Ruiz
Author URI: http://www.bizzledesigns.com
License: GPL2
*/
//Post Type Terms - this is a shortcut for generic situations, some CPTs may call for more specific terminology
// - in which case replace the these variables with the static string terms inline
//replace all 'Presentation'; <-singular post type term
//replace all 'Presentations'; <- plural
//replace all 'Presentation Categories';
//replace all 'Presentation Categories';
//Register the Post Type
//Set all labels to appropriate termanology
function create_post_type() {
$labels = array(
'name' => _x( 'Presentation', 'post type general name' ),
'singular_name' => _x( 'Presentation', 'post type singular name' ),
'add_new' => _x( 'Add New', 'my_cpt' ),
'add_new_item' => __( 'Add New '.'Presentation' ),
'edit_item' => __( 'Edit '.'Presentation' ),
'new_item' => __( 'New '.'Presentation' ),
'all_items' => __( 'All '.'Presentations' ),
'view_item' => __( 'View '.'Presentations' ),
'search_items' => __( 'Search '.'Presentations' ),
'not_found' => __( 'No '.'Presentations'.' found' ),
'not_found_in_trash' => __( 'No '.'Presentations'.' found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Presentations'
);
//Supply the list of arguments for the function
$args = array(
'labels' => $labels,
'description' => 'Management for All Food & Spirits Magazines Online Issues',
'public' => true,
'menu_position' => 7,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments','custom-fields'),
'menu_icon' => 'dashicons-book-alt',
'has_archive' => 'my_cpt',
'taxonomies' => array('tag'),
);
//This is where we actually register the post type with the ever so creatively named function
//You'll want to change my_cpt to something that makes more sense for what you are using the CPTs for (ex. products, events, items, etc.)
register_post_type( 'my_cpt', $args );
}
//Here we are actually adding the action and thus initiallizing the post type creation from within this plugin
add_action( 'init', 'create_post_type' );
//Customize Post Type Messages with the filter API
function cpt_messages( $messages ) {
global $post, $post_ID;
$messages['my_cpt'] = array(
0 => '',
1 => sprintf( __('Presentation'.' updated. <a href="%s">View '.'Presentation'.'</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Presentation'.' updated.'),
5 => isset($_GET['revision']) ? sprintf( __('Presentation'.' restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Presentation'.' published. <a href="%s">View '.'Presentation'.'</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Issue saved.'),
8 => sprintf( __('Presentation'.' submitted. <a target="_blank" href="%s">Preview '.'Presentation'.'</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Presentation'.' scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview '.'Presentation'.'</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Presentation'.' draft updated. <a target="_blank" href="%s">Preview '.'Presentation'.'</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter( 'post_updated_messages', 'cpt_messages' );
// ====== Register Categories
// ==========================
function add_my_cpt_category() {
$labels = array(
'name' => _x( 'Presentation Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Presentation Category', 'taxonomy singular name' ),
'search_items' => __( 'Search '.'Presentation Categories' ),
'all_items' => __( 'All '.'Presentation Categories' ),
'parent_item' => __( 'Parent '.'Presentation Category' ),
'parent_item_colon' => __( 'Parent '.'Presentation Category'.':' ),
'edit_item' => __( 'Edit '.'Presentation Category' ),
'update_item' => __( 'Update '.'Presentation Category' ),
'add_new_item' => __( 'Add New '.'Presentation Category' ),
'new_item_name' => __( 'New '.'Presentation Category' ),
'menu_name' => __( 'Presentation Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy( 'my_cpt_category', 'my_cpt', $args );
}
add_action( 'init', 'add_my_cpt_category', 0 );
//============ END Categories =============================
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!! For Simple CPTs, Just remove or comment everything below here !!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// ===== create tags for the cpt (optional)
// ========================================
function create_cpt_tags()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tag','fsm_issues',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
add_action( 'init', 'create_issue_tags', 0 );
// =================== END Tags =========================
//======== Admin Menu Customizations - for listing your CPT ====
// ==== Create Columns Tags and Categories in backend
// =======================================================
add_filter( 'manage_edit-fsm_issues_columns', 'fsm_edit_issues_columns' ) ;
function fsm_edit_issues_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Issue #' ),
'issue_name' => __( 'Issue Name' ),
'issue_preview' => __('Preview'),
'date' => __( 'Date' )
);
/**
Removed columns
'customer_email'=> __( 'Customer Email' ),
'sales_rep'=> __( 'Sales Rep' ),
'artist'=> __( 'Artist' ),
*/
return $columns;
}
add_action( 'manage_fsm_issues_posts_custom_column', 'fsm_manage_issues_columns', 10, 2 );
function fsm_manage_issues_columns( $column, $post_id ) {
global $post;
global $wpdb;
switch( $column ) {
/* If displaying the 'Issue Name' column. */
case 'issue_name' :
$issue_name = get_post_meta( $post_id, 'issue_name', true );
if ( empty( $issue_name ) )
echo __( 'No Issue Name Assigned' );
/* If there is an issue name, show it. */
else
echo __( $issue_name );
break;
//If Displaying the Issue Preview
case 'issue_preview' :
$the_thumb = get_the_post_thumbnail( $post_id, 'thumbnail' );
if ( empty( $the_thumb ) )
echo __( 'No Image' );
else
echo __( $the_thumb );
break;
/* Just break out of the switch statement for everything else. */
default :
break;
}
}
// ================= END ====================================
/*function art_proofs_enqueue_scripts( $hook ) {
if( !in_array( $hook, array( 'edit.php') ) )
return;
wp_enqueue_script(
'your_script_handle', // Handle
plugins_url( '/style-proofs-listing.js', __FILE__ ), // Path to file
array( 'jquery' ) // Dependancies
);
}
add_action( 'admin_enqueue_scripts', 'art_proofs_enqueue_scripts', 2000 );*/
//Send out emails when a CPT is published
/*function proof_publish_send_email( $post ) {
// lets check the post type and only do it for Art Proofs
$current_post_type = $post->post_type;
$ID = $post->ID;
if ($current_post_type == "art_proofs"){
$message = '<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0" bgcolor="#ffffff">';
wp_mail($email_recipient, $subject, $message );
}
}
}
add_action( 'draft_to_publish', 'proof_publish_send_email', 10, 1 );*/
//Enqueue Custom Scripts (CSS or JS) on Admin or CPT related pages
/*add_action( 'admin_enqueue_scripts', 'html2canvas_enqueue_scripts', 2000 );
function html2canvas_enqueue_scripts( $hook ) {
wp_enqueue_script( 'html2canvas','/js/html2canvas.js', array('jquery'), '', true );
}*/
//Register Custom Shortcode
/*function hsi_artist_img( $atts ){
return '<div class="artist-img"></div>';
}
add_shortcode( 'artist_image', 'hsi_artist_img' );
/**
* Creating a Custom meta box!!!!
*/
function call_someClass()
{
return new someClass();
}
if ( is_admin() )
add_action( 'load-post.php', 'call_someClass' );
/**
* The Class
*/
class someClass
{
const LANG = 'some_textdomain';
public function __construct()
{
add_action( 'add_meta_boxes', array( &$this, 'add_some_meta_box' ) );
}
/**
* Adds the meta box container
*/
public function add_some_meta_box()
{
add_meta_box(
'some_meta_box_name'
,__( 'Proof Preview on Product', self::LANG )
,array( &$this, 'render_meta_box_content' )
,'art_proofs'
,'advanced'
,'high'
);
}
/**
* Render Meta Box content
*/
public function render_meta_box_content() {
//Add HTML for Meta Box here (or script tags for JS or whatever
}
}
?>