-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxonomy-pasta-categories.php
executable file
·70 lines (58 loc) · 2.82 KB
/
taxonomy-pasta-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
<?php
/*
* Register custom taxonomy wp_pizzeria_category for pizzas categorization
*/
class WP_Pizzeria_Pasta_Categories extends Tax_Factory {
protected $taxonomy = 'wp_pizzeria_pasta_category';
protected $cpt = array( 'wp_pizzeria_pasta' );
protected $rewrite = array( 'slug' => 'pasta-category' );
protected $category_images = 'wp_pizzeria_pasta_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( 'Pasta categories', 'taxonomy general name', 'wp_pizzeria' ),
'singular_name' => esc_html_x( 'Pasta categories', 'taxonomy singular name', 'wp_pizzeria' ),
'search_items' => esc_html__( 'Search Pasta categories', 'wp_pizzeria' ),
'all_items' => esc_html__( 'All Pasta categories', 'wp_pizzeria' ),
'parent_item' => esc_html__( 'Parent Pasta category', 'wp_pizzeria' ),
'parent_item_colon' => esc_html__( 'Parent Pasta category:', 'wp_pizzeria' ),
'edit_item' => esc_html__( 'Edit Pasta category', 'wp_pizzeria' ),
'update_item' => esc_html__( 'Update Pasta category', 'wp_pizzeria' ),
'add_new_item' => esc_html__( 'Add New Pasta category', 'wp_pizzeria' ),
'new_item_name' => esc_html__( 'New Pasta category name', 'wp_pizzeria' ),
'menu_name' => esc_html__( 'Pasta categories', 'wp_pizzeria' ),
);
}
public function image_add() { ?>
<div class="form-field">
<label for="pasta_category-image"><?php esc_html_e('Image', 'wp_pizzeria'); ?></label>
<input type="text" class="tag-image" name="pasta_category-image" id="pasta_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="pasta_category-image">Image</label>
</th>
<td>
<?php $category_images = maybe_unserialize( get_option( 'wp_pizzeria_category_images' ) ); ?>
<input type="text" class="tag-image" name="pasta_category-image" id="beverage_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['pasta_category-image'] ) ) {
$category_images = $this->get_category_images();
$category_images[$term_id] = absint( $_POST['pasta_category-image'] );
$this->set_category_images( $category_images );
}
}
}