PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.4.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.4.2
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / includes / class-wpstream_product.php

class-wpstream_product.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.4.2, at includes/class-wpstream_product.php

722 lines 32.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * To change this license header, choose License Headers in Project Properties.
5 * To change this template file, choose Tools | Templates
6 * and open the template in the editor.
7 */
8
9
10 /**
11 * Description of class-wpstream-wpstream_product
12 *
13 * @author cretu
14 */
15 class Wpstream_Product {
16
17 public function __construct() {
18 add_action( 'create_term', array($this,'wpstream_redo_transient') );
19 add_action( 'edit_term', array($this,'wpstream_redo_transient') );
20 add_action( 'delete_term', array($this,'wpstream_redo_transient') );
21 }
22
23
24 public function wpstream_redo_transient(){
25 delete_transient('wpstream_woo_movie_category_values');
26 delete_transient('wpstream_woo_actors_category_values');
27 delete_transient('wpstream_woo_product_cat');
28 delete_transient('wpstream_woo_movie_rating_category_values');
29 $this->wpstream_generate_woo_movie_category_values_shortcode();
30 $this->wpstream_generate_actors_category_values_shortcode();
31 $this->wpstream_generate_woo_product_tax_values_shortcode();
32 $this->wpstream_generate_movie_rating_category_values_shortcode();
33 }
34
35
36
37 /**
38 * Register custom post type
39 *
40 * @link https://codex.wordpress.org/Function_Reference/register_post_type
41 */
42 private function register_single_post_type( $fields ) {
43
44
45 $labels = array(
46 'name' => $fields['plural'],
47 'singular_name' => $fields['singular'],
48 'menu_name' => $fields['menu_name'],
49 'new_item' => sprintf( __( 'New %s', 'wpstream' ), $fields['singular'] ),
50 'add_new_item' => sprintf( __( 'Add new %s', 'wpstream' ), $fields['singular'] ),
51 'edit_item' => sprintf( __( 'Edit %s', 'wpstream' ), $fields['singular'] ),
52 'view_item' => sprintf( __( 'View %s', 'wpstream' ), $fields['singular'] ),
53 'view_items' => sprintf( __( 'View %s', 'wpstream' ), $fields['plural'] ),
54 'search_items' => sprintf( __( 'Search %s', 'wpstream' ), $fields['plural'] ),
55 'not_found' => sprintf( __( 'No %s found', 'wpstream' ), strtolower( $fields['plural'] ) ),
56 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'wpstream' ), strtolower( $fields['plural'] ) ),
57 'all_items' => sprintf( __( 'All %s', 'wpstream' ), $fields['plural'] ),
58 'archives' => sprintf( __( '%s Archives', 'wpstream' ), $fields['singular'] ),
59 'attributes' => sprintf( __( '%s Attributes', 'wpstream' ), $fields['singular'] ),
60 'insert_into_item' => sprintf( __( 'Insert into %s', 'wpstream' ), strtolower( $fields['singular'] ) ),
61 'uploaded_to_this_item' => sprintf( __( 'Uploaded to this %s', 'wpstream' ), strtolower( $fields['singular'] ) ),
62
63 /* Labels for hierarchical post types only. */
64 'parent_item' => sprintf( __( 'Parent %s', 'wpstream' ), $fields['singular'] ),
65 'parent_item_colon' => sprintf( __( 'Parent %s:', 'wpstream' ), $fields['singular'] ),
66
67 /* Custom archive label. Must filter 'post_type_archive_title' to use. */
68 'archive_title' => $fields['plural'],
69 );
70
71 $args = array(
72 'labels' => $labels,
73 'description' => ( isset( $fields['description'] ) ) ? $fields['description'] : '',
74 'public' => ( isset( $fields['public'] ) ) ? $fields['public'] : true,
75 'publicly_queryable' => ( isset( $fields['publicly_queryable'] ) ) ? $fields['publicly_queryable'] : true,
76 'exclude_from_search'=> ( isset( $fields['exclude_from_search'] ) ) ? $fields['exclude_from_search'] : false,
77 'show_ui' => ( isset( $fields['show_ui'] ) ) ? $fields['show_ui'] : true,
78 'show_in_menu' => ( isset( $fields['show_in_menu'] ) ) ? $fields['show_in_menu'] : true,
79 'query_var' => ( isset( $fields['query_var'] ) ) ? $fields['query_var'] : true,
80 'show_in_admin_bar' => ( isset( $fields['show_in_admin_bar'] ) ) ? $fields['show_in_admin_bar'] : true,
81 'capability_type' => ( isset( $fields['capability_type'] ) ) ? $fields['capability_type'] : 'post',
82 'has_archive' => ( isset( $fields['has_archive'] ) ) ? $fields['has_archive'] : true,
83 'hierarchical' => ( isset( $fields['hierarchical'] ) ) ? $fields['hierarchical'] : true,
84 'supports' => ( isset( $fields['supports'] ) ) ? $fields['supports'] : array(
85 'title',
86 'editor',
87 'excerpt',
88 'author',
89 'thumbnail',
90 'comments',
91 'trackbacks',
92 'custom-fields',
93 'revisions',
94 'page-attributes',
95 'post-formats',
96 ),
97 'menu_position' => ( isset( $fields['menu_position'] ) ) ? $fields['menu_position'] : 21,
98 'menu_icon' => ( isset( $fields['menu_icon'] ) ) ? $fields['menu_icon']: 'dashicons-admin-generic',
99 'show_in_nav_menus' => ( isset( $fields['show_in_nav_menus'] ) ) ? $fields['show_in_nav_menus'] : true,
100 'taxonomies' => array( 'category','post_tag' ),
101 );
102
103 if ( isset( $fields['rewrite'] ) ) {
104
105 /**
106 * Add $this->plugin_name as translatable in the permalink structure,
107 * to avoid conflicts with other plugins which may use customers as well.
108 */
109 $args['rewrite'] = $fields['rewrite'];
110 }
111
112 if ( $fields['custom_caps'] ) {
113
114 /**
115 * Provides more precise control over the capabilities than the defaults. By default, WordPress
116 * will use the 'capability_type' argument to build these capabilities. More often than not,
117 * this results in many extra capabilities that you probably don't need. The following is how
118 * I set up capabilities for many post types, which only uses three basic capabilities you need
119 * to assign to roles: 'manage_examples', 'edit_examples', 'create_examples'. Each post type
120 * is unique though, so you'll want to adjust it to fit your needs.
121 *
122 * @link https://gist.github.com/creativembers/6577149
123 * @link http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types
124 */
125 $args['capabilities'] = array(
126
127 // Meta capabilities
128 'edit_post' => 'edit_' . strtolower( $fields['singular'] ),
129 'read_post' => 'read_' . strtolower( $fields['singular'] ),
130 'delete_post' => 'delete_' . strtolower( $fields['singular'] ),
131
132 // Primitive capabilities used outside of map_meta_cap():
133 'edit_posts' => 'edit_' . strtolower( $fields['plural'] ),
134 'edit_others_posts' => 'edit_others_' . strtolower( $fields['plural'] ),
135 'publish_posts' => 'publish_' . strtolower( $fields['plural'] ),
136 'read_private_posts' => 'read_private_' . strtolower( $fields['plural'] ),
137
138 // Primitive capabilities used within map_meta_cap():
139 'delete_posts' => 'delete_' . strtolower( $fields['plural'] ),
140 'delete_private_posts' => 'delete_private_' . strtolower( $fields['plural'] ),
141 'delete_published_posts' => 'delete_published_' . strtolower( $fields['plural'] ),
142 'delete_others_posts' => 'delete_others_' . strtolower( $fields['plural'] ),
143 'edit_private_posts' => 'edit_private_' . strtolower( $fields['plural'] ),
144 'edit_published_posts' => 'edit_published_' . strtolower( $fields['plural'] ),
145 'create_posts' => 'edit_' . strtolower( $fields['plural'] )
146
147 );
148
149 /**
150 * Adding map_meta_cap will map the meta correctly.
151 * @link https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types/108375#108375
152 */
153 $args['map_meta_cap'] = true;
154
155 /**
156 * Assign capabilities to users
157 * Without this, users - also admins - can not see post type.
158 */
159 $this->assign_capabilities( $args['capabilities'], $fields['custom_caps_users'] );
160 }
161
162 register_post_type( $fields['slug'], $args );
163
164 /**
165 * Register Taxnonmies if any
166 * @link https://codex.wordpress.org/Function_Reference/register_taxonomy
167 */
168 if ( isset( $fields['taxonomies'] ) && is_array( $fields['taxonomies'] ) ) {
169
170 foreach ( $fields['taxonomies'] as $taxonomy ) {
171
172 $this->register_single_post_type_taxnonomy( $taxonomy );
173
174 }
175
176 }
177
178 $this->wpstream_generate_woo_movie_category_values_shortcode();
179 $this->wpstream_generate_actors_category_values_shortcode();
180 $this->wpstream_generate_woo_product_tax_values_shortcode();
181 $this->wpstream_generate_movie_rating_category_values_shortcode();
182
183 }
184
185
186
187
188 public function wpstream_generate_woo_movie_category_values_shortcode(){
189
190 $all_tax_labels=array();
191 $property_action_category_values = get_transient('wpstream_woo_movie_category_values');
192 if($property_action_category_values===false){
193 $terms_category = get_terms( array(
194 'taxonomy' => 'wpstream_category',
195 'hide_empty' => false,
196 ) );
197
198 if( is_array($terms_category) ){
199 foreach($terms_category as $term){
200
201 $temp_array=array();
202 $temp_array['label'] = $term->name;
203 $temp_array['value'] = $term->term_id;
204 $all_tax[]=$temp_array;
205 $action_array[]=$temp_array;
206 $all_tax_labels[$term->term_id]= $term->name;
207 // tax based_array
208 $property_action_category_values[] = $temp_array;
209
210 }
211 }
212 set_transient('wpstream_woo_movie_category_values_label',$all_tax_labels,60*60*4);
213 set_transient('wpstream_woo_movie_category_values',$property_action_category_values,60*60*4);
214 }
215 return $property_action_category_values;
216 }
217
218
219
220
221 public function wpstream_generate_actors_category_values_shortcode(){
222 $all_tax_labels=array();
223 $movie_actors_values = get_transient('wpstream_woo_actors_category_values');
224
225 if($movie_actors_values===false){
226 $terms_actors= get_terms( array(
227 'taxonomy' => 'wpstream_actors',
228 'hide_empty' => false,
229 ) );
230
231
232 if( is_array($terms_actors) ){
233 foreach($terms_actors as $term){
234 $places[$term->name]= $term->term_id;
235 $temp_array=array();
236 $temp_array['label'] = $term->name;
237 $temp_array['value'] = $term->term_id;
238 $all_tax[]=$temp_array;
239
240 $all_tax_labels[$term->term_id]= $term->name;
241 $movie_actors_values[] = $temp_array;
242 }
243 }
244
245
246 set_transient('wpstream_woo_actors_category_values_label',$all_tax_labels,60*60*4);
247 set_transient('wpstream_woo_actors_category_values',$movie_actors_values,60*60*4);
248 }
249 return $movie_actors_values;
250 }
251
252
253 public function wpstream_generate_woo_product_tax_values_shortcode(){
254 $all_tax_labels=array();
255 $product_categ_values = get_transient('wpstream_woo_product_cat');
256
257 if($product_categ_values===false){
258 $product_cat= get_terms( array(
259 'taxonomy' => 'product_cat',
260 'hide_empty' => false,
261 ) );
262
263
264
265 if( is_array($product_cat) ){
266 foreach($product_cat as $term){
267 $places[$term->name]= $term->term_id;
268 $temp_array=array();
269 $temp_array['label'] = $term->name;
270 $temp_array['value'] = $term->term_id;
271 $all_places[]=$temp_array;
272 $area_array[]=$temp_array;
273 $all_tax[]=$temp_array;
274 $all_tax_labels[$term->term_id]= $term->name;
275 // tax based_array
276 $product_categ_values[] = $temp_array;
277
278 }
279 }
280 set_transient('wpstream_woo_product_cat_label',$all_tax_labels,60*60*4);
281 set_transient('wpstream_woo_product_cat',$product_categ_values,60*60*4);
282 }
283
284 return $product_categ_values;
285 }
286
287
288 public function wpstream_generate_movie_rating_category_values_shortcode(){
289 $all_tax_labels=array();
290 $movie_rating_values = get_transient('wpstream_woo_movie_rating_category_values');
291 if($movie_rating_values===false){
292 $movie_ratiog= get_terms( array(
293 'taxonomy' => 'wpstream_movie_rating',
294 'hide_empty' => false,
295 ) );
296 if( is_array($movie_ratiog) ){
297 foreach($movie_ratiog as $term){
298 $places[$term->name]= $term->term_id;
299 $temp_array=array();
300 $temp_array['label'] = $term->name;
301 $temp_array['value'] = $term->term_id;
302 $all_places[]=$temp_array;
303 $area_array[]=$temp_array;
304 $all_tax[]=$temp_array;
305 $all_tax_labels[$term->term_id]= $term->name;
306 // tax based_array
307 $movie_rating_values[] = $temp_array;
308
309 }
310 }
311 set_transient('wpstream_woo_movie_rating_category_values_label',$all_tax_labels,60*60*4);
312 set_transient('wpstream_woo_movie_rating_category_values',$movie_rating_values,60*60*4);
313 }
314
315 return $movie_rating_values;
316
317 }
318
319
320
321
322 /**
323 * Register taxonomy custom post type
324 *
325 * @link https://codex.wordpress.org/Function_Reference/register_taxonomy
326 */
327
328 private function register_single_post_type_taxnonomy( $tax_fields ) {
329
330 $labels = array(
331 'name' => $tax_fields['plural'],
332 'singular_name' => $tax_fields['single'],
333 'menu_name' => $tax_fields['plural'],
334 'all_items' => sprintf( __( 'All %s' , 'wpstream' ), $tax_fields['plural'] ),
335 'edit_item' => sprintf( __( 'Edit %s' , 'wpstream' ), $tax_fields['single'] ),
336 'view_item' => sprintf( __( 'View %s' , 'wpstream' ), $tax_fields['single'] ),
337 'update_item' => sprintf( __( 'Update %s' , 'wpstream' ), $tax_fields['single'] ),
338 'add_new_item' => sprintf( __( 'Add New %s' , 'wpstream' ), $tax_fields['single'] ),
339 'new_item_name' => sprintf( __( 'New %s Name' , 'wpstream' ), $tax_fields['single'] ),
340 'parent_item' => sprintf( __( 'Parent %s' , 'wpstream' ), $tax_fields['single'] ),
341 'parent_item_colon' => sprintf( __( 'Parent %s:' , 'wpstream' ), $tax_fields['single'] ),
342 'search_items' => sprintf( __( 'Search %s' , 'wpstream' ), $tax_fields['plural'] ),
343 'popular_items' => sprintf( __( 'Popular %s' , 'wpstream' ), $tax_fields['plural'] ),
344 'separate_items_with_commas' => sprintf( __( 'Separate %s with commas' , 'wpstream' ), $tax_fields['plural'] ),
345 'add_or_remove_items' => sprintf( __( 'Add or remove %s' , 'wpstream' ), $tax_fields['plural'] ),
346 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s' , 'wpstream' ), $tax_fields['plural'] ),
347 'not_found' => sprintf( __( 'No %s found' , 'wpstream' ), $tax_fields['plural'] ),
348 );
349
350 $args = array(
351 'label' => $tax_fields['plural'],
352 'labels' => $labels,
353 'hierarchical' => ( isset( $tax_fields['hierarchical'] ) ) ? $tax_fields['hierarchical'] : true,
354 'public' => ( isset( $tax_fields['public'] ) ) ? $tax_fields['public'] : true,
355 'show_ui' => ( isset( $tax_fields['show_ui'] ) ) ? $tax_fields['show_ui'] : true,
356 'show_in_nav_menus' => ( isset( $tax_fields['show_in_nav_menus'] ) ) ? $tax_fields['show_in_nav_menus'] : true,
357 'show_tagcloud' => ( isset( $tax_fields['show_tagcloud'] ) ) ? $tax_fields['show_tagcloud'] : true,
358 'meta_box_cb' => ( isset( $tax_fields['meta_box_cb'] ) ) ? $tax_fields['meta_box_cb'] : null,
359 'show_admin_column' => ( isset( $tax_fields['show_admin_column'] ) ) ? $tax_fields['show_admin_column'] : true,
360 'show_in_quick_edit' => ( isset( $tax_fields['show_in_quick_edit'] ) ) ? $tax_fields['show_in_quick_edit'] : true,
361 'update_count_callback' => ( isset( $tax_fields['update_count_callback'] ) ) ? $tax_fields['update_count_callback'] : '',
362 'show_in_rest' => ( isset( $tax_fields['show_in_rest'] ) ) ? $tax_fields['show_in_rest'] : true,
363 'rest_base' => $tax_fields['taxonomy'],
364 'rest_controller_class' => ( isset( $tax_fields['rest_controller_class'] ) ) ? $tax_fields['rest_controller_class'] : 'WP_REST_Terms_Controller',
365 'query_var' => $tax_fields['taxonomy'],
366 'rewrite' => ( isset( $tax_fields['rewrite'] ) ) ? $tax_fields['rewrite'] : true,
367 'sort' => ( isset( $tax_fields['sort'] ) ) ? $tax_fields['sort'] : '',
368 );
369
370 $args = apply_filters( $tax_fields['taxonomy'] . '_args', $args );
371
372 register_taxonomy( $tax_fields['taxonomy'], $tax_fields['post_types'], $args );
373
374 }
375
376 /**
377 * Assign capabilities to users
378 *
379 * @link https://codex.wordpress.org/Function_Reference/register_post_type
380 * @link https://typerocket.com/ultimate-guide-to-custom-post-types-in-wordpress/
381 */
382 public function assign_capabilities( $caps_map, $users ) {
383
384 foreach ( $users as $user ) {
385
386 $user_role = get_role( $user );
387
388 foreach ( $caps_map as $cap_map_key => $capability ) {
389
390 $user_role->add_cap( $capability );
391
392 }
393
394 }
395
396 }
397
398 /**
399 * CUSTOMIZE CUSTOM POST TYPE AS YOU WISH.
400 */
401
402
403 public function wpstream_category_callback_function($tag){
404 if(is_object ($tag)){
405 $t_id = $tag->term_id;
406 $term_meta = get_option( "taxonomy_$t_id");
407 $pagetax = $term_meta['pagetax'] ? $term_meta['pagetax'] : '';
408 $category_featured_image = $term_meta['category_featured_image'] ? $term_meta['category_featured_image'] : '';
409 $category_tagline = $term_meta['category_tagline'] ? $term_meta['category_tagline'] : '';
410 $category_tagline = stripslashes($category_tagline);
411 $category_attach_id = $term_meta['category_attach_id'] ? $term_meta['category_attach_id'] : '';
412 }else{
413 $pagetax = '';
414 $category_featured_image = '';
415 $category_tagline = '';
416 $category_attach_id = '';
417 }
418
419 print'
420 <table class="form-table">
421 <tbody>
422 <tr class="form-field">
423 <th scope="row" valign="top"><label for="term_meta[pagetax]">'.esc_html__( 'Page id for this term','wpstream').'</label></th>
424 <td>
425 <input type="text" name="term_meta[pagetax]" class="postform" value="'.$pagetax.'">
426 <p class="description">'.esc_html__( 'Page id for this term','wpstream').'</p>
427 </td>
428
429 <tr valign="top">
430 <th scope="row"><label for="category_featured_image">'.esc_html__( 'Featured Image','wpstream').'</label></th>
431 <td>
432 <input id="category_featured_image" type="text" class="postform" size="36" name="term_meta[category_featured_image]" value="'.$category_featured_image.'" />
433 <input id="category_featured_image_button" type="button" class="upload_button button category_featured_image_button" value="'.esc_html__( 'Upload Image','wpstream').'" />
434 <input id="category_attach_id" type="hidden" size="36" name="term_meta[category_attach_id]" value="'.$category_attach_id.'" />
435 </td>
436 </tr>
437
438 <tr valign="top">
439 <th scope="row"><label for="term_meta[category_tagline]">'. esc_html__( 'Category Tagline','wpstream').'</label></th>
440 <td>
441 <input id="category_tagline" type="text" size="36" name="term_meta[category_tagline]" value="'.$category_tagline.'" />
442 </td>
443 </tr>
444
445
446
447 <input id="category_tax" type="hidden" size="36" name="term_meta[category_tax]" value="'.$tag->taxonomy.'" />
448
449
450 </tr>
451 </tbody>
452 </table>';
453 }
454
455
456
457
458
459
460 /**
461 * CUSTOMIZE CUSTOM POST TYPE AS YOU WISH.
462 */
463
464
465 public function wpstream_category_callback_add_function($tag){
466 if(is_object ($tag)){
467 $t_id = $tag->term_id;
468 $term_meta = get_option( "taxonomy_$t_id");
469 $pagetax = $term_meta['pagetax'] ? $term_meta['pagetax'] : '';
470 $category_featured_image = $term_meta['category_featured_image'] ? $term_meta['category_featured_image'] : '';
471 $category_tagline = $term_meta['category_tagline'] ? $term_meta['category_tagline'] : '';
472 $category_attach_id = $term_meta['category_attach_id'] ? $term_meta['category_attach_id'] : '';
473 }else{
474 $pagetax = '';
475 $category_featured_image = '';
476 $category_tagline = '';
477 $category_attach_id = '';
478
479 }
480
481 print'
482 <div class="form-field">
483 <label for="term_meta[pagetax]">'. esc_html__( 'Page id for this term','wpstream').'</label>
484 <input type="text" name="term_meta[pagetax]" class="postform" value="'.$pagetax.'">
485 </div>
486
487 <div class="form-field">
488 <label for="term_meta[pagetax]">'. esc_html__( 'Featured Image','wpstream').'</label>
489 <input id="category_featured_image" type="text" size="36" name="term_meta[category_featured_image]" value="'.$category_featured_image.'" />
490 <input id="category_featured_image_button" type="button" class="upload_button button category_featured_image_button" value="'.esc_html__( 'Upload Image','wpstream').'" />
491 <input id="category_attach_id" type="hidden" size="36" name="term_meta[category_attach_id]" value="'.$category_attach_id.'" />
492
493 </div>
494
495 <div class="form-field">
496 <label for="term_meta[category_tagline]">'. esc_html__( 'Category Tagline','wpstream').'</label>
497 <input id="category_tagline" type="text" size="36" name="term_meta[category_tagline]" value="'.$category_tagline.'" />
498 </div>
499 <input id="category_tax" type="hidden" size="36" name="term_meta[category_tax]" value="'.$tag->taxonomy.'" />
500 ';
501 }
502
503 /**
504 * CUSTOMIZE CUSTOM POST TYPE AS YOU WISH.
505 */
506
507
508 function wpstream_category_save_extra_fields_callback($term_id ){
509 if ( isset( $_POST['term_meta'] ) ) {
510 $t_id = $term_id;
511 $term_meta = get_option( "taxonomy_$t_id");
512 $cat_keys = array_keys($_POST['term_meta']);
513 $allowed_html = array();
514 foreach ($cat_keys as $key){
515 $key=sanitize_key($key);
516 if (isset($_POST['term_meta'][$key])){
517 $term_meta[$key] = wp_kses( $_POST['term_meta'][$key],$allowed_html);
518 }
519 }
520 //save the option array
521 update_option( "taxonomy_$t_id", $term_meta );
522 }
523 }
524
525
526
527
528
529
530 /**
531 * Create post types
532 */
533 public function create_custom_post_type() {
534
535 /**
536 * This is not all the fields, only what I find important. Feel free to change this function ;)
537 *
538 * @link https://codex.wordpress.org/Function_Reference/register_post_type
539 *
540 * For more info on fields:
541 * @link https://github.com/JoeSz/WordPress-Plugin-Boilerplate-Tutorial/blob/9fb56794bc1f8aebfe04e99b15881db0c4bc61bd/wpstream/includes/class-wpstream-post_types.php#L230
542 */
543
544
545 $custom_slug = esc_html( get_option('wpstream_free_media_slug','') );
546 if($custom_slug==''){
547 $custom_slug='wpstream';
548 }
549
550 $custom_slug_vod = esc_html( get_option('wpstream_free_media_slug_vod','') );
551 if($custom_slug_vod==''){
552 $custom_slug_vod='wpstream_vod';
553 }
554
555
556 $post_types_fields = array(
557 array(
558 'slug' => 'wpstream_product',
559 'singular' => __( 'Free-To-View Live Channel','wpstream'),
560 'plural' => __( 'Free-To-View Live Channels','wpstream'),
561 'menu_name' => __( 'Free-To-View Live Channels','wpstream'),
562 'description' => __( 'Free-To-View Live Channels','wpstream'),
563 'has_archive' => true,
564 'hierarchical' => false,
565 'menu_icon' => WPSTREAM_PLUGIN_DIR_URL.'img/wpstream-icon-menu_2.png',
566 'rewrite' => array(
567 'slug' => $custom_slug,
568 'with_front' => true,
569 'pages' => true,
570 'feeds' => true,
571 'ep_mask' => EP_PERMALINK,
572 ),
573 'menu_position' => 20,
574 'public' => true,
575 'publicly_queryable' => true,
576 'exclude_from_search' => true,
577 'show_ui' => true,
578 'show_in_menu' => true,
579 'query_var' => true,
580 'show_in_admin_bar' => true,
581 'show_in_nav_menus' => true,
582 'supports' => array(
583 'title',
584 'editor',
585 'thumbnail',
586 'comments',
587
588 ),
589 'custom_caps' => true,
590 'custom_caps_users' => array(
591 'administrator',
592 ),
593 'taxonomies' => array(
594
595
596 array(
597 'taxonomy' => 'wpstream_actors',
598 'plural' => esc_html__('Actors','wpstream'),
599 'single' => esc_html__('Actor','wpstream'),
600 'post_types' => array('wpstream_product','product','wpstream_product_vod'),
601 'hierarchical' => true,
602 'query_var' => true,
603 'rewrite' => array( 'slug' => 'actors' )
604 ),
605
606 array(
607 'taxonomy' => 'wpstream_category',
608 'plural' => esc_html__('Media Categories','wpstream'),
609 'single' => esc_html__('Media Category','wpstream'),
610 'post_types' => array('wpstream_product','product','wpstream_product_vod'),
611 'hierarchical' => true,
612 'query_var' => true,
613 'rewrite' => array( 'slug' => 'media_category' )
614 ),
615
616 array(
617 'taxonomy' => 'wpstream_movie_rating',
618 'plural' => esc_html__('Movie Ratings','wpstream'),
619 'single' => esc_html__('Movie Rating','wpstream'),
620 'post_types' => array('wpstream_product','product','wpstream_product_vod'),
621 'hierarchical' => true,
622 'query_var' => true,
623 'rewrite' => array( 'slug' => 'rating' )
624 ),
625
626 ),
627 ),
628 );
629
630
631 $post_types_fields[] = array(
632
633 'slug' => 'wpstream_product_vod',
634 'singular' => __( 'Free-To-View VOD','wpstream'),
635 'plural' => __( 'Free-To-View VODs','wpstream'),
636 'menu_name' => __( 'Free-To-View VODs','wpstream'),
637 'description' => __( 'Free-To-View VODs','wpstream'),
638 'has_archive' => true,
639 'hierarchical' => false,
640 'menu_icon' => WPSTREAM_PLUGIN_DIR_URL.'img/wpstream-icon-menu_2.png',
641 'rewrite' => array(
642 'slug' => $custom_slug_vod,
643 'with_front' => true,
644 'pages' => true,
645 'feeds' => true,
646 'ep_mask' => EP_PERMALINK,
647 ),
648 'menu_position' => 20,
649 'public' => true,
650 'publicly_queryable' => true,
651 'exclude_from_search' => true,
652 'show_ui' => true,
653 'show_in_menu' => true,
654 'query_var' => true,
655 'show_in_admin_bar' => true,
656 'show_in_nav_menus' => true,
657 'supports' => array(
658 'title',
659 'editor',
660 'thumbnail',
661 'comments',
662
663 ),
664 'custom_caps' => true,
665 'custom_caps_users' => array(
666 'administrator',
667 ),
668
669 );
670
671
672
673 // loop torugh custom post type array and register
674 foreach ( $post_types_fields as $fields ) {
675 $this->register_single_post_type( $fields );
676 }
677
678 if( get_option('wpstream_updated_50')!=='yes' ){
679 $this->wpstream_50_post_update();
680 }
681
682
683 }
684
685
686 public function wpstream_50_post_update(){
687 $arg=array(
688 'post_type' =>'wpstream_product',
689 'post_status' => 'any',
690 'posts_per_page'=> -1
691 );
692
693
694 $the_query = new WP_Query($arg);
695
696 if($the_query->have_posts()){
697 while ( $the_query->have_posts() ) {
698 $the_query->the_post();
699 $post_id=get_the_ID();
700 $wpstream_product_type = esc_html(get_post_meta($post_id, 'wpstream_product_type', true));
701
702 if($wpstream_product_type==2 || $wpstream_product_type==3){
703 // print 'will update '.$post_id.' - '.get_the_title($post_id).'</br>'.PHP_EOL;
704 set_post_type( $post_id, 'wpstream_product_vod' );
705 }
706
707 }
708 global $wp_rewrite;
709 $wp_rewrite->flush_rules( true );
710
711 update_option('wpstream_updated_50','yes');
712 }
713 }
714
715
716
717
718
719
720
721 }
722