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