-
Notifications
You must be signed in to change notification settings - Fork 2
/
post-types.php
282 lines (226 loc) · 10.2 KB
/
post-types.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
<?php
function unipress_api_post_types() {
$labels = array(
'name' => _x( 'Ads', 'post type general name', 'unipress-api' ),
'singular_name' => _x( 'Ad', 'post type singular name', 'unipress-api' ),
'menu_name' => _x( 'Ads', 'admin menu', 'unipress-api' ),
'name_admin_bar' => _x( 'Ad', 'add new on admin bar', 'unipress-api' ),
'add_new' => _x( 'Add New', 'ad', 'unipress-api' ),
'add_new_item' => __( 'Add New Ad', 'unipress-api' ),
'new_item' => __( 'New Ad', 'unipress-api' ),
'edit_item' => __( 'Edit Ad', 'unipress-api' ),
'view_item' => __( 'View Ad', 'unipress-api' ),
'all_items' => __( 'All Ads', 'unipress-api' ),
'search_items' => __( 'Search Ads', 'unipress-api' ),
'parent_item_colon' => __( 'Parent Ads:', 'unipress-api' ),
'not_found' => __( 'No ads found.', 'unipress-api' ),
'not_found_in_trash' => __( 'No ads found in Trash.', 'unipress-api' )
);
$args = array(
'labels' => $labels,
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => false,
'rewrite' => array( 'slug' => 'unipress-ad' ),
'capability_type' => 'post',
'register_meta_box_cb' => 'unipress_api_ad_metaboxes',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'thumbnail', 'author' )
);
register_post_type( 'unipress-ad', $args );
$labels = array(
'name' => _x( 'Push Notifications', 'post type general name', 'unipress-api' ),
'singular_name' => _x( 'Push Notification', 'post type singular name', 'unipress-api' ),
'menu_name' => _x( 'Push Notifications', 'admin menu', 'unipress-api' ),
'name_admin_bar' => _x( 'Push', 'add new on admin bar', 'unipress-api' ),
'add_new' => _x( 'Add New', 'Push', 'unipress-api' ),
'add_new_item' => __( 'Add New Push Notification', 'unipress-api' ),
'new_item' => __( 'New Push', 'unipress-api' ),
'edit_item' => __( 'Edit Push', 'unipress-api' ),
'view_item' => __( 'View Push', 'unipress-api' ),
'all_items' => __( 'All Push Notifications', 'unipress-api' ),
'search_items' => __( 'Search Push Notifications', 'unipress-api' ),
'parent_item_colon' => __( 'Parent Push Notifications:', 'unipress-api' ),
'not_found' => __( 'No Push Notifications found.', 'unipress-api' ),
'not_found_in_trash' => __( 'No Push Notifications found in Trash.', 'unipress-api' )
);
$args = array(
'labels' => $labels,
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => false,
'rewrite' => array( 'slug' => 'unipress-ad' ),
'capability_type' => 'post',
'register_meta_box_cb' => 'unipress_api_push_metaboxes',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'author' )
);
register_post_type( 'unipress-push', $args );
}
add_action( 'init', 'unipress_api_post_types' );
if ( !function_exists( 'unipress_api_ad_metaboxes' ) ) {
/**
* Registers metaboxes for IssueM Articles
*
* @since 1.0.0
*/
function unipress_api_ad_metaboxes() {
remove_meta_box( 'leaky_paywall_content_visibility', 'unipress-ad', 'side' );
add_meta_box( 'unipress_ad_meta_box', __( 'UniPress Ad Options', 'unipress-api' ), 'unipress_ad_meta_box', 'unipress-ad', 'normal', 'high' );
do_action( 'unipress_api_ad_metaboxes' );
}
}
if ( !function_exists( 'unipress_ad_meta_box' ) ) {
function unipress_ad_meta_box( $post ) {
$ad_type = get_post_meta( $post->ID, '_ad_type', true );
$ad_link = get_post_meta( $post->ID, '_ad_link', true );
?>
<div id="unipress-ad-metabox">
<p>
<label for="unipress-ad-type"><?php _e( 'Ad Type:', 'issuem' ); ?></label>
<select id="unipress-ad-type" name="ad-type">
<option value="tablet-portrait" <?php selected( 'tablet-portrait', $ad_type ) ?>><?php _e( 'Tablet Portrait', 'unipress-api' ); ?></option>
<option value="tablet-landscape" <?php selected( 'tablet-landscape', $ad_type ) ?>><?php _e( 'Tablet Landscape', 'unipress-api' ); ?></option>
<option value="smartphone" <?php selected( 'smartphone', $ad_type ) ?>><?php _e( 'Smartphone', 'unipress-api' ); ?></option>
<option value="wide-screen" <?php selected( 'wide-screen', $ad_type ) ?>><?php _e( 'Wide Screen', 'unipress-api' ); ?></option>
<option value="phone" <?php selected( 'phone', $ad_type ) ?>><?php _e( 'Phone (deprecated)', 'unipress-api' ); ?></option>
<option value="tablet" <?php selected( 'tablet', $ad_type ) ?>><?php _e( 'Tablet (deprecated)', 'unipress-api' ); ?></option>
</select>
</p>
<p>
<label for="unipress-ad-link"><?php _e( 'Ad Link:', 'issuem' ); ?></label>
<input id="unipress-ad-link" type="text" name="ad-link" value="<?php echo $ad_link; ?>" />
</p>
<p class="descripton">
<strong><?php _e( 'Tablet Portrait:', 'unipress-api' ); ?></strong> 1536px x 180px<br />
<strong><?php _e( 'Tablet Landscape:', 'unipress-api' ); ?></strong> 2048px x 180px <br />
<strong><?php _e( 'Smartphone:', 'unipress-api' ); ?></strong> 1080px x 168px<br />
<strong><?php _e( 'Wide Screen:', 'unipress-api' ); ?></strong> 2560px x 180px<br />
</p>
</div>
<?php
}
}
if ( !function_exists( 'save_unipress_ad_meta_box' ) ) {
/**
* Saves Article meta
*
* @since 1.0.0
*
* @param int $post_id WordPress post ID
*/
function save_unipress_ad_meta_box( $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['ad-type'] ) )
update_post_meta( $post_id, '_ad_type', $_POST['ad-type'] );
else
delete_post_meta( $post_id, '_ad_type' );
if ( !empty( $_POST['ad-link'] ) )
update_post_meta( $post_id, '_ad_link', $_POST['ad-link'] );
else
delete_post_meta( $post_id, '_ad_link' );
do_action( 'save_unipress_ad_meta_box', $post_id );
}
add_action( 'save_post_unipress-ad', 'save_unipress_ad_meta_box' );
}
if ( !function_exists( 'unipress_api_push_metaboxes' ) ) {
/**
* Registers metaboxes for IssueM Push Notifications
*
* @since CHANGEME
*/
function unipress_api_push_metaboxes() {
remove_meta_box( 'leaky_paywall_content_visibility', 'unipress-push', 'side' );
add_meta_box( 'unipress_push_meta_box', __( 'Push Notification', 'unipress-api' ), 'unipress_push_meta_box', 'unipress-push', 'normal', 'high' );
do_action( 'unipress_api_push_metaboxes' );
}
}
if ( !function_exists( 'unipress_push_meta_box' ) ) {
function unipress_push_meta_box( $post ) {
$push_type = get_post_meta( $post->ID, '_push_type', true );
$delivery_type = get_post_meta( $post->ID, '_delivery_type', true );
$push_content = get_post_meta( $post->ID, '_push_content', true );
$max_length = ( 'android' === $push_type ) ? UNIPRESS_API_ANDROID_MAX_CHAR : UNIPRESS_API_IOS_MAX_CHAR;
?>
<div id="unipress-push-metabox">
<p>
<label for="unipress-push-type"><?php _e( 'Push Type:', 'issuem' ); ?></label>
<select id="unipress-push-type" name="push-type">
<option value="all" <?php selected( 'all', $push_type ) ?>><?php _e( 'Both iOS and Android', 'unipress-api' ); ?></option>
<option value="iOS" <?php selected( 'ios', $push_type ) ?>><?php _e( 'iOS', 'unipress-api' ); ?></option>
<option value="Android" <?php selected( 'android', $push_type ) ?>><?php _e( 'Android', 'unipress-api' ); ?></option>
</select>
</p>
<p>
<label for="unipress-push-delivery"><?php _e( 'Push Delivery:', 'issuem' ); ?></label>
<select id="unipress-push-delivery" name="delivery-type">
<option value="categories" <?php selected( 'categories', $delivery_type ) ?>><?php _e( 'Categories Only', 'unipress-api' ); ?></option>
<option value="all_users" <?php selected( 'all_users', $delivery_type ) ?>><?php _e( 'All Users', 'unipress-api' ); ?></option>
</select>
</p>
<p>
<?php
$remaining = $max_length - strlen( $push_content );
if ( 10 > $remaining ) {
$length_class = 'unipress-push-count-superwarn';
} else if ( 20 > $remaining ) {
$length_class = 'unipress-push-count-warn';
} else {
$length_class = 'unipress-push-count';
}
?>
<label id="unipress-content-label" for="unipress-push-content"><?php printf( __( 'Push Content (%s bytes):', 'issuem' ), '<span id="push-current-length" class="' . $length_class . '">' . strlen( $push_content ) . '</span> / <span id="push-max-length">' . $max_length . '</span>' ); ?></label><br/>
<textarea id="unipress-push-content" name="push-content"><?php echo $push_content; ?></textarea><br/>
</p>
<script type="text/javascript" charset="utf-8">
var UNIPRESS_API_IOS_MAX_CHAR = <?php echo UNIPRESS_API_IOS_MAX_CHAR; ?>;
var UNIPRESS_API_ANDROID_MAX_CHAR = <?php echo UNIPRESS_API_ANDROID_MAX_CHAR; ?>;
</script>
</div>
<?php
}
}
if ( !function_exists( 'save_unipress_push_meta_box' ) ) {
/**
* Saves Article meta
*
* @since 1.0.0
*
* @param int $post_id WordPress post ID
*/
function save_unipress_push_meta_box( $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['push-type'] ) )
update_post_meta( $post_id, '_push_type', $_POST['push-type'] );
else
delete_post_meta( $post_id, '_push_type' );
if ( !empty( $_POST['delivery-type'] ) )
update_post_meta( $post_id, '_delivery_type', $_POST['delivery-type'] );
else
delete_post_meta( $post_id, '_delivery_type' );
if ( !empty( $_POST['push-content'] ) )
update_post_meta( $post_id, '_push_content', $_POST['push-content'] );
else
delete_post_meta( $post_id, '_push_content' );
do_action( 'save_unipress_push_meta_box', $post_id );
}
add_action( 'save_post_unipress-push', 'save_unipress_push_meta_box' );
}