forked from zeen101/issuem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issuem-post-type.php
209 lines (154 loc) · 6.65 KB
/
issuem-post-type.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
<?php
/**
* Registers IssueM Article Post Type w/ Meta Boxes
*
* @package IssueM
* @since 1.0.0
*/
if ( !function_exists( 'create_article_post_type' ) ) {
/**
* Registers Article Post type for IssueM
*
* @since 1.0.0
*/
function create_article_post_type() {
$issuem_settings = get_issuem_settings();
if ( !empty( $issuem_settings['use_wp_taxonomies'] ) )
$taxonomies = array( 'category', 'post_tag' );
else
$taxonomies = array( 'issuem_issue_categories', 'issuem_issue_tags' );
$labels = array(
'name' => __( 'Articles', 'issuem' ),
'singular_name' => __( 'Article', 'issuem' ),
'add_new' => __( 'Add New Article', 'issuem' ),
'add_new_item' => __( 'Add New Article', 'issuem' ),
'edit_item' => __( 'Edit Article', 'issuem' ),
'new_item' => __( 'New Article', 'issuem' ),
'view_item' => __( 'View Article', 'issuem' ),
'search_items' => __( 'Search Articles', 'issuem' ),
'not_found' => __( 'No articles found', 'issuem' ),
'not_found_in_trash' => __( 'No articles found in trash', 'issuem' ),
'parent_item_colon' => '',
'menu_name' => __( 'Articles', 'issuem' )
);
$args = array(
'label' => 'article',
'labels' => $labels,
'description' => __( 'IssueM Articles', 'issuem' ),
'public' => true,
'publicly_queryable' => true,
'exclude_fromsearch' => false,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => array( 'article', 'articles' ),
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author', 'editor', 'custom-fields',
'revisions', 'thumbnail', 'excerpt', 'trackbacks',
'comments', 'page-attributes', 'post-formats' ),
'register_meta_box_cb' => 'add_issuem_articles_metaboxes',
'has_archive' => true,
'rewrite' => array( 'slug' => 'article' ),
'taxonomies' => $taxonomies,
'menu_icon' => ISSUEM_URL . '/images/issuem-16x16.png'
);
register_post_type( 'article', $args );
if ( 'true' === get_option( 'issuem_flush_rewrite_rules' ) ) {
// ATTENTION: This is *only* done during plugin activation hook in this example!
// You should *NEVER EVER* do this on every page load!!
flush_rewrite_rules();
delete_option( 'issuem_flush_rewrite_rules' );
}
}
add_action( 'init', 'create_article_post_type' );
}
if ( !function_exists( 'issuem_article_add_post_thumbnails' ) ) {
function issuem_article_add_post_thumbnails() {
$supported_post_types = get_theme_support( 'post-thumbnails' );
if( false === $supported_post_types ) {
$post_types = array( 'article' );
add_theme_support( 'post-thumbnails', $post_types );
} else if ( is_array( $supported_post_types ) ) {
$post_types = $supported_post_types[0];
$post_types[] = 'article';
add_theme_support( 'post-thumbnails', $post_types );
}
}
add_action( 'after_setup_theme', 'issuem_article_add_post_thumbnails', 99 );
}
if ( !function_exists( 'add_issuem_articles_metaboxes' ) ) {
/**
* Registers metaboxes for IssueM Articles
*
* @since 1.0.0
*/
function add_issuem_articles_metaboxes() {
add_meta_box( 'issuem_article_meta_box', __( 'IssueM Article Options', 'issuem' ), 'issuem_article_meta_box', 'article' );
do_action( 'add_issuem_articles_metaboxes' );
}
}
if ( !function_exists( 'issuem_article_meta_box' ) ) {
/**
* Outputs Article HTML for options metabox
*
* @since 1.0.0
*
* @param object $post WordPress post object
*/
function issuem_article_meta_box( $post ) {
$issuem_settings = get_issuem_settings();
$teaser_text = get_post_meta( $post->ID, '_teaser_text', true );
$featured_rotator = get_post_meta( $post->ID, '_featured_rotator', true );
$featured_thumb = get_post_meta( $post->ID, '_featured_thumb', true );
$issuem_author_name = get_post_meta( $post->ID, '_issuem_author_name', true );
?>
<div id="issuem-article-metabox">
<table id="iam-table">
<tr><td><label for="teaser_text"><?php _e( 'Teaser Text', 'issuem' ); ?></label></td><td><input class="regular-text" type="text" name="teaser_text" value="<?php echo $teaser_text; ?>" /></td></tr>
<?php if ( !empty( $issuem_settings['issuem_author_name'] ) ) { ?>
<tr><td><label for="featured_thumb"><?php _e( 'IssueM Author Name', 'issuem' ); ?></label></td><td><input class="regular-text" type="text" name="issuem_author_name" value="<?php echo $issuem_author_name; ?>" /></td></tr>
<?php } ?>
<tr><td colspan="2"><strong><?php _e( 'Featured Rotator Options', 'issuem' ); ?></strong></td></tr>
<tr><td><label for="featured_rotator"><?php _e( 'Set as Featured Rotator Article', 'issuem' ); ?></label></td><td><input id="featured_rotator" type="checkbox" name="featured_rotator" <?php checked( $featured_rotator || "on" == $featured_rotator ); ?> /></td></tr>
<tr><td colspan="2"><strong><?php _e( 'Featured Thumbnail Options', 'issuem' ); ?></strong></td></tr>
<tr><td><label for="featured_thumb"><?php _e( 'Set as Featured Thumbnail Article', 'issuem' ); ?></label></td><td><input id="featured_thumb" type="checkbox" name="featured_thumb" <?php checked( $featured_thumb || "on" == $featured_thumb ); ?> /></td></tr>
</table>
</div>
<?php
}
}
if ( !function_exists( 'save_issuem_article_meta' ) ) {
/**
* Saves Article meta
*
* @since 1.0.0
*
* @param int $post_id WordPress post ID
*/
function save_issuem_article_meta( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( isset( $_REQUEST['_inline_edit'] ) || isset( $_REQUEST['doing_wp_cron'] ) )
return;
if ( !empty( $_POST['teaser_text'] ) )
update_post_meta( $post_id, '_teaser_text', $_POST['teaser_text'] );
else
delete_post_meta( $post_id, '_teaser_text' );
if ( !empty( $_POST['featured_rotator'] ) )
update_post_meta( $post_id, '_featured_rotator', $_POST['featured_rotator'] );
else
delete_post_meta( $post_id, '_featured_rotator' );
if ( !empty( $_POST['featured_thumb'] ) )
update_post_meta( $post_id, '_featured_thumb', $_POST['featured_thumb'] );
else
delete_post_meta( $post_id, '_featured_thumb' );
if ( !empty( $_POST['issuem_author_name'] ) )
update_post_meta( $post_id, '_issuem_author_name', $_POST['issuem_author_name'] );
else
delete_post_meta( $post_id, '_issuem_author_name' );
do_action( 'save_issuem_article_meta', $post_id );
}
add_action( 'save_post', 'save_issuem_article_meta' );
}