-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxonomy-dessert-categories.php
executable file
·73 lines (60 loc) · 2.91 KB
/
taxonomy-dessert-categories.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
<?php
/*
* Register custom taxonomy wp_pizzeria_category for pizzas categorization
*/
class WP_Pizzeria_Dessert_Categories extends Tax_Factory {
protected $taxonomy = 'wp_pizzeria_dessert_category';
protected $cpt = array( 'wp_pizzeria_dessert' );
protected $rewrite = array( 'slug' => 'dessert-category' );
protected $category_images = 'wp_pizzeria_dessert_category_images';
protected function __construct() {
parent::construct( $this );
add_action( 'edit_term', array( $this, 'image_save' ), 10, 1 );
add_action( 'create_term', array( $this, 'image_save' ), 10, 1 );
}
protected function get_labels() {
//setup labels
return array(
'name' => esc_html_x( 'Dessert categories', 'taxonomy general name', 'wp_pizzeria' ),
'singular_name' => esc_html_x( 'Dessert categories', 'taxonomy singular name', 'wp_pizzeria' ),
'search_items' => esc_html__( 'Search Dessert categories', 'wp_pizzeria' ),
'all_items' => esc_html__( 'All Dessert categories', 'wp_pizzeria' ),
'parent_item' => esc_html__( 'Parent Dessert category', 'wp_pizzeria' ),
'parent_item_colon' => esc_html__( 'Parent Dessert category:', 'wp_pizzeria' ),
'edit_item' => esc_html__( 'Edit Dessert category', 'wp_pizzeria' ),
'update_item' => esc_html__( 'Update Dessert category', 'wp_pizzeria' ),
'add_new_item' => esc_html__( 'Add New Dessert category', 'wp_pizzeria' ),
'new_item_name' => esc_html__( 'New Dessert category name', 'wp_pizzeria' ),
'menu_name' => esc_html__( 'Dessert categories', 'wp_pizzeria' ),
);
}
public function image_add() {
?>
<div class="form-field">
<label for="dessert_category-image"><?php esc_html_e( 'Image', 'wp_pizzeria' ); ?></label>
<input type="text" class="tag-image" name="dessert_category-image" id="dessert_category-image" value="" />
<p><?php esc_html_e( 'The image is not prominent by default; however themes modified for use with WP Pizzeria plugin will use it.', 'wp_pizzeria' ); ?></p>
</div><?php
}
public function image_edit( $taxonomy ) {
?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="dessert_category-image">Image</label>
</th>
<td>
<?php $category_images = $this->get_category_images(); ?>
<input type="text" class="tag-image" name="dessert_category-image" id="dessert_category-image" value="<?php echo esc_attr( $category_images[ $taxonomy->term_id ] ); ?>" />
<br />
<span class="description"><?php esc_html_e( 'The image is not prominent by default; however themes modified for use with WP Pizzeria plugin will use it.', 'wp_pizzeria' ); ?></span>
</td>
</tr><?php
}
public function image_save( $term_id ) {
if ( true === isset( $_POST['dessert_category-image'] ) ) {
$category_images = $this->get_category_images();
$category_images[ $term_id ] = absint( $_POST['dessert_category-image'] );
$this->set_category_images( $category_images );
}
}
}