-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpcustomfields.php
More file actions
152 lines (143 loc) · 5.72 KB
/
Copy pathcpcustomfields.php
File metadata and controls
152 lines (143 loc) · 5.72 KB
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
<?php
/* ###### ########
* ######### #########
* #### #### ####
* #### #########
* #### #######
* #### ####
* ######### ####
* ###### ####
*
*
* This file adds custom fields (ie meta fields) for all different types
* These include:
* Taxonomies:
* Status-Priority
* Status-IsClosed
* Product-Current Version
*/
//--------------------------------------------------------------
//Status Taxonomy
//--------------------------------------------------------------
// Add Status Page
function cpt_add_status_custom_fields() {
// This will add the Priority to the "add new" form...
?>
<div class="form-field">
<label for="term_meta[status_priority]">Priority</label>
<select name="term_meta[status_priority]">
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select>
<p class="description">What priority should this Status Take?</p>
</div>
<div class="form-field">
<label for="term_meta[status_isclosed]">Is Closed?</label>
<select name="term_meta[status_isclosed]">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<p class="description">Does this signify that the Status is Closed?</p>
</div>
<?php
}
add_action( 'cp_ticket_status_add_form_fields', 'cpt_add_status_custom_fields');
// Edit term page
function cpt_edit_status_custom_fields($term) {
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_option( "status_$t_id" ); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[status_priority]">Priority</label></th>
<td>
<select name="term_meta[status_priority]">
<option value="High" <?php echo esc_attr( $term_meta['status_priority']) == 'High' ? 'selected' : '' ?>>High</option>
<option value="Medium" <?php echo esc_attr( $term_meta['status_priority']) == 'Medium' ? 'selected' : '' ?>>Medium</option>
<option value="Low" <?php echo esc_attr( $term_meta['status_priority']) == 'Low' ? 'selected' : '' ?>>Low</option>
</select>
<p class="description">What priority should this Status Take?</p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="term_meta[status_isclosed]">Is Closed?</label>
</th>
<td>
<select name="term_meta[status_isclosed]">
<option value="Yes" <?php echo esc_attr( $term_meta['status_isclosed']) == 'Yes' ? 'selected' : '' ?>>Yes</option>
<option value="No" <?php echo esc_attr( $term_meta['status_isclosed']) == 'No' ? 'selected' : '' ?>>No</option>
</select>
<p class="description">Does this signify that the Status is Closed?</p>
</td>
</tr>
<?php
}
add_action( 'cp_ticket_status_edit_form_fields', 'cpt_edit_status_custom_fields');
// Save the Status fields....
function cpt_save_status_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "status_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
// Save the option array.
update_option( "status_$t_id", $term_meta );
}
}
add_action( 'edited_cp_ticket_status', 'cpt_save_status_fields');
add_action( 'create_cp_ticket_status', 'cpt_save_status_fields');
//--------------------------------------------------------------
//Product Taxonomy
//--------------------------------------------------------------
// Add Status Page
function cpt_add_product_custom_fields() {
// This will add the Priority to the "add new" form...
?>
<div class="form-field">
<label for="term_meta[product_version]">Current Version</label>
<input name="term_meta[product_version]" type="text" value=""/>
<p class="description">What version is this software currently at?</p>
</div>
<?php
}
add_action( 'cp_support_product_add_form_fields', 'cpt_add_product_custom_fields');
// Edit term page
function cpt_edit_product_custom_fields($term) {
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_option( "sproduct_$t_id" ); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[product_version]">Version</label></th>
<td>
<input type="text" name="term_meta[product_version]" value="<?php echo esc_attr($term_meta['product_version']) ? $term_meta['product_version'] : '' ?>"/>
<p class="description">What priority should this Status Take?</p>
</td>
</tr>
<?php
}
add_action( 'cp_support_product_edit_form_fields', 'cpt_edit_product_custom_fields');
// Save the Status fields....
function cpt_save_product_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "status_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
// Save the option array.
update_option( "sproduct_$t_id", $term_meta );
}
}
add_action( 'edited_cp_support_product', 'cpt_save_product_fields');
add_action( 'create_cp_support_product', 'cpt_save_product_fields');
?>