This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Attributes Page |
||
4 | * |
||
5 | * The attributes section lets users add custom attributes to assign to products - they can also be used in the layered nav widget. |
||
6 | * |
||
7 | * @author WooThemes |
||
8 | * @category Admin |
||
9 | * @package WooCommerce/Admin |
||
10 | * @version 2.3.0 |
||
11 | */ |
||
12 | |||
13 | if ( ! defined( 'ABSPATH' ) ) { |
||
14 | exit; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * WC_Admin_Attributes Class. |
||
19 | */ |
||
20 | class WC_Admin_Attributes { |
||
21 | |||
22 | /** |
||
23 | * Handles output of the attributes page in admin. |
||
24 | * |
||
25 | * Shows the created attributes and lets you add new ones or edit existing ones. |
||
26 | * The added attributes are stored in the database and can be used for layered navigation. |
||
27 | */ |
||
28 | public static function output() { |
||
29 | $result = ''; |
||
30 | $action = ''; |
||
31 | |||
32 | // Action to perform: add, edit, delete or none |
||
33 | if ( ! empty( $_POST['add_new_attribute'] ) ) { |
||
34 | $action = 'add'; |
||
35 | } elseif ( ! empty( $_POST['save_attribute'] ) && ! empty( $_GET['edit'] ) ) { |
||
36 | $action = 'edit'; |
||
37 | } elseif ( ! empty( $_GET['delete'] ) ) { |
||
38 | $action = 'delete'; |
||
39 | } |
||
40 | |||
41 | switch ( $action ) { |
||
42 | case 'add' : |
||
43 | $result = self::process_add_attribute(); |
||
44 | break; |
||
45 | case 'edit' : |
||
46 | $result = self::process_edit_attribute(); |
||
47 | break; |
||
48 | case 'delete' : |
||
49 | $result = self::process_delete_attribute(); |
||
50 | break; |
||
51 | } |
||
52 | |||
53 | if ( is_wp_error( $result ) ) { |
||
54 | echo '<div id="woocommerce_errors" class="error"><p>' . $result->get_error_message() . '</p></div>'; |
||
55 | } |
||
56 | |||
57 | // Show admin interface |
||
58 | if ( ! empty( $_GET['edit'] ) ) { |
||
59 | self::edit_attribute(); |
||
60 | } else { |
||
61 | self::add_attribute(); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get and sanitize posted attribute data. |
||
67 | * @return array |
||
68 | */ |
||
69 | private static function get_posted_attribute() { |
||
70 | $attribute = array( |
||
71 | 'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '', |
||
72 | 'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '', |
||
73 | 'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select', |
||
74 | 'attribute_orderby' => isset( $_POST['attribute_orderby'] ) ? wc_clean( $_POST['attribute_orderby'] ) : '', |
||
75 | 'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0 |
||
76 | ); |
||
77 | |||
78 | if ( empty( $attribute['attribute_type'] ) ) { |
||
79 | $attribute['attribute_type'] = 'select'; |
||
80 | } |
||
81 | if ( empty( $attribute['attribute_label'] ) ) { |
||
82 | $attribute['attribute_label'] = ucfirst( $attribute['attribute_name'] ); |
||
83 | } |
||
84 | if ( empty( $attribute['attribute_name'] ) ) { |
||
85 | $attribute['attribute_name'] = wc_sanitize_taxonomy_name( $attribute['attribute_label'] ); |
||
86 | } |
||
87 | |||
88 | return $attribute; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * See if an attribute name is valid. |
||
93 | * @param string $attribute_name |
||
94 | * @return bool|WP_error result |
||
95 | */ |
||
96 | private static function valid_attribute_name( $attribute_name ) { |
||
97 | if ( strlen( $attribute_name ) >= 28 ) { |
||
98 | return new WP_Error( 'error', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), sanitize_title( $attribute_name ) ) ); |
||
99 | } elseif ( wc_check_if_attribute_name_is_reserved( $attribute_name ) ) { |
||
100 | return new WP_Error( 'error', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), sanitize_title( $attribute_name ) ) ); |
||
101 | } |
||
102 | |||
103 | return true; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Add an attribute. |
||
108 | * @return bool|WP_Error |
||
109 | */ |
||
110 | private static function process_add_attribute() { |
||
111 | global $wpdb; |
||
112 | check_admin_referer( 'woocommerce-add-new_attribute' ); |
||
113 | |||
114 | $attribute = self::get_posted_attribute(); |
||
115 | |||
116 | if ( empty( $attribute['attribute_name'] ) || empty( $attribute['attribute_label'] ) ) { |
||
117 | return new WP_Error( 'error', __( 'Please, provide an attribute name and slug.', 'woocommerce' ) ); |
||
118 | } elseif ( ( $valid_attribute_name = self::valid_attribute_name( $attribute['attribute_name'] ) ) && is_wp_error( $valid_attribute_name ) ) { |
||
119 | return $valid_attribute_name; |
||
120 | } elseif ( taxonomy_exists( wc_attribute_taxonomy_name( $attribute['attribute_name'] ) ) ) { |
||
121 | return new WP_Error( 'error', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), sanitize_title( $attribute['attribute_name'] ) ) ); |
||
122 | } |
||
123 | |||
124 | $wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); |
||
125 | |||
126 | do_action( 'woocommerce_attribute_added', $wpdb->insert_id, $attribute ); |
||
127 | |||
128 | flush_rewrite_rules(); |
||
129 | delete_transient( 'wc_attribute_taxonomies' ); |
||
130 | |||
131 | return true; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Edit an attribute. |
||
136 | * @return bool|WP_Error |
||
137 | */ |
||
138 | private static function process_edit_attribute() { |
||
139 | global $wpdb; |
||
140 | $attribute_id = absint( $_GET['edit'] ); |
||
141 | check_admin_referer( 'woocommerce-save-attribute_' . $attribute_id ); |
||
142 | |||
143 | $attribute = self::get_posted_attribute(); |
||
144 | |||
145 | if ( empty( $attribute['attribute_name'] ) || empty( $attribute['attribute_label'] ) ) { |
||
146 | return new WP_Error( 'error', __( 'Please, provide an attribute name and slug.', 'woocommerce' ) ); |
||
147 | } elseif ( ( $valid_attribute_name = self::valid_attribute_name( $attribute['attribute_name'] ) ) && is_wp_error( $valid_attribute_name ) ) { |
||
148 | return $valid_attribute_name; |
||
149 | } |
||
150 | |||
151 | $taxonomy_exists = taxonomy_exists( wc_attribute_taxonomy_name( $attribute['attribute_name'] ) ); |
||
152 | $old_attribute_name = $wpdb->get_var( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ); |
||
153 | if ( $old_attribute_name != $attribute['attribute_name'] && wc_sanitize_taxonomy_name( $old_attribute_name ) != $attribute['attribute_name'] && $taxonomy_exists ) { |
||
154 | return new WP_Error( 'error', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), sanitize_title( $attribute['attribute_name'] ) ) ); |
||
155 | } |
||
156 | |||
157 | $wpdb->update( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute, array( 'attribute_id' => $attribute_id ) ); |
||
158 | |||
159 | do_action( 'woocommerce_attribute_updated', $attribute_id, $attribute, $old_attribute_name ); |
||
160 | |||
161 | if ( $old_attribute_name != $attribute['attribute_name'] && ! empty( $old_attribute_name ) ) { |
||
162 | // Update taxonomies in the wp term taxonomy table |
||
163 | $wpdb->update( |
||
164 | $wpdb->term_taxonomy, |
||
165 | array( 'taxonomy' => wc_attribute_taxonomy_name( $attribute['attribute_name'] ) ), |
||
166 | array( 'taxonomy' => 'pa_' . $old_attribute_name ) |
||
167 | ); |
||
168 | |||
169 | // Update taxonomy ordering term meta |
||
170 | if ( get_option( 'db_version' ) < 34370 ) { |
||
171 | $wpdb->update( |
||
172 | $wpdb->prefix . 'woocommerce_termmeta', |
||
173 | array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ), |
||
174 | array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) ) |
||
175 | ); |
||
176 | } else { |
||
177 | $wpdb->update( |
||
178 | $wpdb->termmeta, |
||
179 | array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ), |
||
180 | array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) ) |
||
181 | ); |
||
182 | } |
||
183 | |||
184 | // Update product attributes which use this taxonomy |
||
185 | $old_attribute_name_length = strlen( $old_attribute_name ) + 3; |
||
186 | $attribute_name_length = strlen( $attribute['attribute_name'] ) + 3; |
||
187 | |||
188 | $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE( meta_value, %s, %s ) WHERE meta_key = '_product_attributes'", |
||
189 | 's:' . $old_attribute_name_length . ':"pa_' . $old_attribute_name . '"', |
||
190 | 's:' . $attribute_name_length . ':"pa_' . $attribute['attribute_name'] . '"' |
||
191 | ) ); |
||
192 | |||
193 | // Update variations which use this taxonomy |
||
194 | $wpdb->update( |
||
195 | $wpdb->postmeta, |
||
196 | array( 'meta_key' => 'attribute_pa_' . sanitize_title( $attribute['attribute_name'] ) ), |
||
197 | array( 'meta_key' => 'attribute_pa_' . sanitize_title( $old_attribute_name ) ) |
||
198 | ); |
||
199 | } |
||
200 | |||
201 | echo '<div class="updated"><p>' . __( 'Attribute updated successfully', 'woocommerce' ) . '</p></div>'; |
||
202 | |||
203 | flush_rewrite_rules(); |
||
204 | delete_transient( 'wc_attribute_taxonomies' ); |
||
205 | |||
206 | return true; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Delete an attribute. |
||
211 | * @return bool |
||
212 | */ |
||
213 | private static function process_delete_attribute() { |
||
214 | global $wpdb; |
||
215 | |||
216 | $attribute_id = absint( $_GET['delete'] ); |
||
217 | |||
218 | check_admin_referer( 'woocommerce-delete-attribute_' . $attribute_id ); |
||
219 | |||
220 | $attribute_name = $wpdb->get_var( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ); |
||
221 | $taxonomy = wc_attribute_taxonomy_name( $attribute_name ); |
||
222 | |||
223 | do_action( 'woocommerce_before_attribute_delete', $attribute_id, $attribute_name, $taxonomy ); |
||
224 | |||
225 | if ( $attribute_name && $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ) ) { |
||
226 | if ( taxonomy_exists( $taxonomy ) ) { |
||
227 | $terms = get_terms( $taxonomy, 'orderby=name&hide_empty=0' ); |
||
228 | foreach ( $terms as $term ) { |
||
229 | wp_delete_term( $term->term_id, $taxonomy ); |
||
230 | } |
||
231 | } |
||
232 | |||
233 | do_action( 'woocommerce_attribute_deleted', $attribute_id, $attribute_name, $taxonomy ); |
||
234 | delete_transient( 'wc_attribute_taxonomies' ); |
||
235 | return true; |
||
236 | } |
||
237 | |||
238 | return false; |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * Edit Attribute admin panel. |
||
243 | * |
||
244 | * Shows the interface for changing an attributes type between select and text. |
||
245 | */ |
||
246 | public static function edit_attribute() { |
||
247 | global $wpdb; |
||
248 | |||
249 | $edit = absint( $_GET['edit'] ); |
||
250 | |||
251 | $attribute_to_edit = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'" ); |
||
252 | |||
253 | ?> |
||
254 | <div class="wrap woocommerce"> |
||
255 | <div class="icon32 icon32-attributes" id="icon-woocommerce"><br/></div> |
||
256 | <h1><?php _e( 'Edit Attribute', 'woocommerce' ) ?></h1> |
||
257 | |||
258 | <?php |
||
259 | |||
260 | if ( ! $attribute_to_edit ) { |
||
261 | echo '<div id="woocommerce_errors" class="error"><p>' . __( 'Error: non-existing attribute ID.', 'woocommerce' ) . '</p></div>'; |
||
262 | } else { |
||
263 | $att_type = $attribute_to_edit->attribute_type; |
||
264 | $att_label = $attribute_to_edit->attribute_label; |
||
265 | $att_name = $attribute_to_edit->attribute_name; |
||
266 | $att_orderby = $attribute_to_edit->attribute_orderby; |
||
267 | $att_public = $attribute_to_edit->attribute_public; |
||
268 | |||
269 | ?> |
||
270 | |||
271 | <form action="edit.php?post_type=product&page=product_attributes&edit=<?php echo absint( $edit ); ?>" method="post"> |
||
272 | <table class="form-table"> |
||
273 | <tbody> |
||
274 | <tr class="form-field form-required"> |
||
275 | <th scope="row" valign="top"> |
||
276 | <label for="attribute_label"><?php _e( 'Name', 'woocommerce' ); ?></label> |
||
277 | </th> |
||
278 | <td> |
||
279 | <input name="attribute_label" id="attribute_label" type="text" value="<?php echo esc_attr( $att_label ); ?>" /> |
||
280 | <p class="description"><?php _e( 'Name for the attribute (shown on the front-end).', 'woocommerce' ); ?></p> |
||
281 | </td> |
||
282 | </tr> |
||
283 | <tr class="form-field form-required"> |
||
284 | <th scope="row" valign="top"> |
||
285 | <label for="attribute_name"><?php _e( 'Slug', 'woocommerce' ); ?></label> |
||
286 | </th> |
||
287 | <td> |
||
288 | <input name="attribute_name" id="attribute_name" type="text" value="<?php echo esc_attr( $att_name ); ?>" maxlength="28" /> |
||
289 | <p class="description"><?php _e( 'Unique slug/reference for the attribute; must be shorter than 28 characters.', 'woocommerce' ); ?></p> |
||
290 | </td> |
||
291 | </tr> |
||
292 | <tr class="form-field form-required"> |
||
293 | <th scope="row" valign="top"> |
||
294 | <label for="attribute_public"><?php _e( 'Enable Archives?', 'woocommerce' ); ?></label> |
||
295 | </th> |
||
296 | <td> |
||
297 | <input name="attribute_public" id="attribute_public" type="checkbox" value="1" <?php checked( $att_public, 1 ); ?> /> |
||
298 | <p class="description"><?php _e( 'Enable this if you want this attribute to have product archives in your store.', 'woocommerce' ); ?></p> |
||
299 | </td> |
||
300 | </tr> |
||
301 | <tr class="form-field form-required"> |
||
302 | <th scope="row" valign="top"> |
||
303 | <label for="attribute_type"><?php _e( 'Type', 'woocommerce' ); ?></label> |
||
304 | </th> |
||
305 | <td> |
||
306 | <select name="attribute_type" id="attribute_type"> |
||
307 | <?php foreach ( wc_get_attribute_types() as $key => $value ) : ?> |
||
308 | <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $att_type, $key ); ?>><?php echo esc_attr( $value ); ?></option> |
||
309 | <?php endforeach; ?> |
||
310 | |||
311 | <?php |
||
312 | |||
313 | /** |
||
314 | * Deprecated action in favor of product_attributes_type_selector filter. |
||
315 | * |
||
316 | * @deprecated 2.4.0 |
||
317 | */ |
||
318 | do_action( 'woocommerce_admin_attribute_types' ); |
||
319 | ?> |
||
320 | </select> |
||
321 | <p class="description"><?php _e( 'Determines how you select attributes for products. Under admin panel -> products -> product data -> attributes -> values, <strong>Text</strong> allows manual entry whereas <strong>select</strong> allows pre-configured terms in a drop-down list.', 'woocommerce' ); ?></p> |
||
322 | </td> |
||
323 | </tr> |
||
324 | <tr class="form-field form-required"> |
||
325 | <th scope="row" valign="top"> |
||
326 | <label for="attribute_orderby"><?php _e( 'Default sort order', 'woocommerce' ); ?></label> |
||
327 | </th> |
||
328 | <td> |
||
329 | <select name="attribute_orderby" id="attribute_orderby"> |
||
330 | <option value="menu_order" <?php selected( $att_orderby, 'menu_order' ); ?>><?php _e( 'Custom ordering', 'woocommerce' ); ?></option> |
||
331 | <option value="name" <?php selected( $att_orderby, 'name' ); ?>><?php _e( 'Name', 'woocommerce' ); ?></option> |
||
332 | <option value="name_num" <?php selected( $att_orderby, 'name_num' ); ?>><?php _e( 'Name (numeric)', 'woocommerce' ); ?></option> |
||
333 | <option value="id" <?php selected( $att_orderby, 'id' ); ?>><?php _e( 'Term ID', 'woocommerce' ); ?></option> |
||
334 | </select> |
||
335 | <p class="description"><?php _e( 'Determines the sort order of the terms on the frontend shop product pages. If using custom ordering, you can drag and drop the terms in this attribute.', 'woocommerce' ); ?></p> |
||
336 | </td> |
||
337 | </tr> |
||
338 | </tbody> |
||
339 | </table> |
||
340 | <p class="submit"><input type="submit" name="save_attribute" id="submit" class="button-primary" value="<?php esc_attr_e( 'Update', 'woocommerce' ); ?>"></p> |
||
341 | <?php wp_nonce_field( 'woocommerce-save-attribute_' . $edit ); ?> |
||
342 | </form> |
||
343 | <?php } ?> |
||
344 | </div> |
||
345 | <?php |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * Add Attribute admin panel. |
||
350 | * |
||
351 | * Shows the interface for adding new attributes. |
||
352 | */ |
||
353 | public static function add_attribute() { |
||
354 | ?> |
||
355 | <div class="wrap woocommerce"> |
||
356 | <div class="icon32 icon32-attributes" id="icon-woocommerce"><br/></div> |
||
357 | <h1><?php _e( 'Attributes', 'woocommerce' ); ?></h1> |
||
358 | <br class="clear" /> |
||
359 | <div id="col-container"> |
||
360 | <div id="col-right"> |
||
361 | <div class="col-wrap"> |
||
362 | <table class="widefat attributes-table wp-list-table ui-sortable" style="width:100%"> |
||
363 | <thead> |
||
364 | <tr> |
||
365 | <th scope="col"><?php _e( 'Name', 'woocommerce' ); ?></th> |
||
366 | <th scope="col"><?php _e( 'Slug', 'woocommerce' ); ?></th> |
||
367 | <th scope="col"><?php _e( 'Type', 'woocommerce' ); ?></th> |
||
368 | <th scope="col"><?php _e( 'Order by', 'woocommerce' ); ?></th> |
||
369 | <th scope="col" colspan="2"><?php _e( 'Terms', 'woocommerce' ); ?></th> |
||
370 | </tr> |
||
371 | </thead> |
||
372 | <tbody> |
||
373 | <?php |
||
374 | if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) : |
||
375 | foreach ( $attribute_taxonomies as $tax ) : |
||
376 | ?><tr> |
||
377 | |||
378 | <td> |
||
379 | <strong><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&post_type=product"><?php echo esc_html( $tax->attribute_label ); ?></a></strong> |
||
380 | |||
381 | <div class="row-actions"><span class="edit"><a href="<?php echo esc_url( add_query_arg( 'edit', $tax->attribute_id, 'edit.php?post_type=product&page=product_attributes' ) ); ?>"><?php _e( 'Edit', 'woocommerce' ); ?></a> | </span><span class="delete"><a class="delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'delete', $tax->attribute_id, 'edit.php?post_type=product&page=product_attributes' ), 'woocommerce-delete-attribute_' . $tax->attribute_id ) ); ?>"><?php _e( 'Delete', 'woocommerce' ); ?></a></span></div> |
||
382 | </td> |
||
383 | <td><?php echo esc_html( $tax->attribute_name ); ?></td> |
||
384 | <td><?php echo esc_html( ucfirst( $tax->attribute_type ) ); ?> <?php echo $tax->attribute_public ? '(' . __( 'Public', 'woocommerce' ) . ')' : ''; ?></td> |
||
385 | <td><?php |
||
386 | switch ( $tax->attribute_orderby ) { |
||
387 | case 'name' : |
||
388 | _e( 'Name', 'woocommerce' ); |
||
389 | break; |
||
390 | case 'name_num' : |
||
391 | _e( 'Name (numeric)', 'woocommerce' ); |
||
392 | break; |
||
393 | case 'id' : |
||
394 | _e( 'Term ID', 'woocommerce' ); |
||
395 | break; |
||
396 | default: |
||
397 | _e( 'Custom ordering', 'woocommerce' ); |
||
398 | break; |
||
399 | } |
||
400 | ?></td> |
||
401 | <td class="attribute-terms"><?php |
||
402 | $taxonomy = wc_attribute_taxonomy_name( $tax->attribute_name ); |
||
403 | |||
404 | if ( taxonomy_exists( $taxonomy ) ) { |
||
405 | $terms = get_terms( $taxonomy, 'hide_empty=0' ); |
||
406 | |||
407 | View Code Duplication | switch ( $tax->attribute_orderby ) { |
|
0 ignored issues
–
show
|
|||
408 | case 'name_num' : |
||
409 | usort( $terms, '_wc_get_product_terms_name_num_usort_callback' ); |
||
410 | break; |
||
411 | case 'parent' : |
||
412 | usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); |
||
413 | break; |
||
414 | } |
||
415 | |||
416 | $terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) ); |
||
417 | if ( $terms_string ) { |
||
418 | echo $terms_string; |
||
419 | } else { |
||
420 | echo '<span class="na">–</span>'; |
||
421 | } |
||
422 | } else { |
||
423 | echo '<span class="na">–</span>'; |
||
424 | } |
||
425 | ?></td> |
||
426 | <td class="attribute-actions"><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&post_type=product" class="button alignright tips configure-terms" data-tip="<?php esc_attr_e( 'Configure terms', 'woocommerce' ); ?>"><?php _e( 'Configure terms', 'woocommerce' ); ?></a></td> |
||
427 | </tr><?php |
||
428 | endforeach; |
||
429 | else : |
||
430 | ?><tr><td colspan="6"><?php _e( 'No attributes currently exist.', 'woocommerce' ) ?></td></tr><?php |
||
431 | endif; |
||
432 | ?> |
||
433 | </tbody> |
||
434 | </table> |
||
435 | </div> |
||
436 | </div> |
||
437 | <div id="col-left"> |
||
438 | <div class="col-wrap"> |
||
439 | <div class="form-wrap"> |
||
440 | <h2><?php _e( 'Add New Attribute', 'woocommerce' ); ?></h2> |
||
441 | <p><?php _e( 'Attributes let you define extra product data, such as size or colour. You can use these attributes in the shop sidebar using the "layered nav" widgets. Please note: you cannot rename an attribute later on.', 'woocommerce' ); ?></p> |
||
442 | <form action="edit.php?post_type=product&page=product_attributes" method="post"> |
||
443 | <div class="form-field"> |
||
444 | <label for="attribute_label"><?php _e( 'Name', 'woocommerce' ); ?></label> |
||
445 | <input name="attribute_label" id="attribute_label" type="text" value="" /> |
||
446 | <p class="description"><?php _e( 'Name for the attribute (shown on the front-end).', 'woocommerce' ); ?></p> |
||
447 | </div> |
||
448 | |||
449 | <div class="form-field"> |
||
450 | <label for="attribute_name"><?php _e( 'Slug', 'woocommerce' ); ?></label> |
||
451 | <input name="attribute_name" id="attribute_name" type="text" value="" maxlength="28" /> |
||
452 | <p class="description"><?php _e( 'Unique slug/reference for the attribute; must be shorter than 28 characters.', 'woocommerce' ); ?></p> |
||
453 | </div> |
||
454 | |||
455 | <div class="form-field"> |
||
456 | <label for="attribute_public"><input name="attribute_public" id="attribute_public" type="checkbox" value="1" /> <?php _e( 'Enable Archives?', 'woocommerce' ); ?></label> |
||
457 | |||
458 | <p class="description"><?php _e( 'Enable this if you want this attribute to have product archives in your store.', 'woocommerce' ); ?></p> |
||
459 | </div> |
||
460 | |||
461 | <div class="form-field"> |
||
462 | <label for="attribute_type"><?php _e( 'Type', 'woocommerce' ); ?></label> |
||
463 | <select name="attribute_type" id="attribute_type"> |
||
464 | <?php foreach ( wc_get_attribute_types() as $key => $value ) : ?> |
||
465 | <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $value ); ?></option> |
||
466 | <?php endforeach; ?> |
||
467 | |||
468 | <?php |
||
469 | |||
470 | /** |
||
471 | * Deprecated action in favor of product_attributes_type_selector filter. |
||
472 | * |
||
473 | * @deprecated 2.4.0 |
||
474 | */ |
||
475 | do_action( 'woocommerce_admin_attribute_types' ); |
||
476 | ?> |
||
477 | </select> |
||
478 | <p class="description"><?php _e( 'Determines how you select attributes for products. Under admin panel -> products -> product data -> attributes -> values, <strong>Text</strong> allows manual entry whereas <strong>select</strong> allows pre-configured terms in a drop-down list.', 'woocommerce' ); ?></p> |
||
479 | </div> |
||
480 | |||
481 | <div class="form-field"> |
||
482 | <label for="attribute_orderby"><?php _e( 'Default sort order', 'woocommerce' ); ?></label> |
||
483 | <select name="attribute_orderby" id="attribute_orderby"> |
||
484 | <option value="menu_order"><?php _e( 'Custom ordering', 'woocommerce' ); ?></option> |
||
485 | <option value="name"><?php _e( 'Name', 'woocommerce' ); ?></option> |
||
486 | <option value="name_num"><?php _e( 'Name (numeric)', 'woocommerce' ); ?></option> |
||
487 | <option value="id"><?php _e( 'Term ID', 'woocommerce' ); ?></option> |
||
488 | </select> |
||
489 | <p class="description"><?php _e( 'Determines the sort order of the terms on the frontend shop product pages. If using custom ordering, you can drag and drop the terms in this attribute.', 'woocommerce' ); ?></p> |
||
490 | </div> |
||
491 | |||
492 | <p class="submit"><input type="submit" name="add_new_attribute" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Add Attribute', 'woocommerce' ); ?>"></p> |
||
493 | <?php wp_nonce_field( 'woocommerce-add-new_attribute' ); ?> |
||
494 | </form> |
||
495 | </div> |
||
496 | </div> |
||
497 | </div> |
||
498 | </div> |
||
499 | <script type="text/javascript"> |
||
500 | /* <![CDATA[ */ |
||
501 | |||
502 | jQuery( 'a.delete' ).click( function() { |
||
503 | if ( window.confirm( '<?php _e( "Are you sure you want to delete this attribute?", "woocommerce" ); ?>' ) ) { |
||
504 | return true; |
||
505 | } |
||
506 | return false; |
||
507 | }); |
||
508 | |||
509 | /* ]]> */ |
||
510 | </script> |
||
511 | </div> |
||
512 | <?php |
||
513 | } |
||
514 | } |
||
515 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.