' . wp_kses_post( $result->get_error_message() ) . '

'; } // Show admin interface. if ( ! empty( $_GET['edit'] ) ) { self::edit_attribute(); } else { self::add_attribute(); } } /** * Get and sanitize posted attribute data. * * @return array */ private static function get_posted_attribute() { $attribute = array( 'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( wp_unslash( $_POST['attribute_label'] ) ) : '', // WPCS: input var ok, CSRF ok. 'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( wp_unslash( $_POST['attribute_name'] ) ) : '', // WPCS: input var ok, CSRF ok, sanitization ok. 'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( wp_unslash( $_POST['attribute_type'] ) ) : 'select', // WPCS: input var ok, CSRF ok. 'attribute_orderby' => isset( $_POST['attribute_orderby'] ) ? wc_clean( wp_unslash( $_POST['attribute_orderby'] ) ) : '', // WPCS: input var ok, CSRF ok. 'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0, // WPCS: input var ok, CSRF ok. ); if ( empty( $attribute['attribute_type'] ) ) { $attribute['attribute_type'] = 'select'; } if ( empty( $attribute['attribute_label'] ) ) { $attribute['attribute_label'] = ucfirst( $attribute['attribute_name'] ); } if ( empty( $attribute['attribute_name'] ) ) { $attribute['attribute_name'] = wc_sanitize_taxonomy_name( $attribute['attribute_label'] ); } return $attribute; } /** * Add an attribute. * * @return bool|WP_Error */ private static function process_add_attribute() { check_admin_referer( 'woocommerce-add-new_attribute' ); $attribute = self::get_posted_attribute(); $args = array( 'name' => $attribute['attribute_label'], 'slug' => $attribute['attribute_name'], 'type' => $attribute['attribute_type'], 'order_by' => $attribute['attribute_orderby'], 'has_archives' => $attribute['attribute_public'], ); $id = wc_create_attribute( $args ); if ( is_wp_error( $id ) ) { return $id; } return true; } /** * Edit an attribute. * * @return bool|WP_Error */ private static function process_edit_attribute() { $attribute_id = isset( $_GET['edit'] ) ? absint( $_GET['edit'] ) : 0; check_admin_referer( 'woocommerce-save-attribute_' . $attribute_id ); $attribute = self::get_posted_attribute(); $args = array( 'name' => $attribute['attribute_label'], 'slug' => $attribute['attribute_name'], 'type' => $attribute['attribute_type'], 'order_by' => $attribute['attribute_orderby'], 'has_archives' => $attribute['attribute_public'], ); $id = wc_update_attribute( $attribute_id, $args ); if ( is_wp_error( $id ) ) { return $id; } self::$edited_attribute_id = $id; return true; } /** * Delete an attribute. * * @return bool */ private static function process_delete_attribute() { $attribute_id = isset( $_GET['delete'] ) ? absint( $_GET['delete'] ) : 0; check_admin_referer( 'woocommerce-delete-attribute_' . $attribute_id ); return wc_delete_attribute( $attribute_id ); } /** * Edit Attribute admin panel. * * Shows the interface for changing an attributes type between select and text. */ public static function edit_attribute() { global $wpdb; $edit = isset( $_GET['edit'] ) ? absint( $_GET['edit'] ) : 0; $attribute_to_edit = $wpdb->get_row( $wpdb->prepare( " SELECT attribute_type, attribute_label, attribute_name, attribute_orderby, attribute_public FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d ", $edit ) ); ?>

' . esc_html__( 'Error: non-existing attribute ID.', 'woocommerce' ) . '

'; } else { if ( self::$edited_attribute_id > 0 ) { echo '

' . esc_html__( 'Attribute updated successfully', 'woocommerce' ) . '

' . esc_html__( 'Back to Attributes', 'woocommerce' ) . '

'; self::$edited_attribute_id = null; } $att_type = $attribute_to_edit->attribute_type; $att_label = format_to_edit( $attribute_to_edit->attribute_label ); $att_name = $attribute_to_edit->attribute_name; $att_orderby = $attribute_to_edit->attribute_orderby; $att_public = $attribute_to_edit->attribute_public; ?>

/>


attribute_label ); ?>
|
attribute_name ); ?> attribute_type ) ); ?> attribute_public ? esc_html__( '(Public)', 'woocommerce' ) : ''; ?> attribute_orderby ) { case 'name': esc_html_e( 'Name', 'woocommerce' ); break; case 'name_num': esc_html_e( 'Name (numeric)', 'woocommerce' ); break; case 'id': esc_html_e( 'Term ID', 'woocommerce' ); break; default: esc_html_e( 'Custom ordering', 'woocommerce' ); break; } ?> attribute_name ); if ( taxonomy_exists( $taxonomy ) ) { $terms = get_terms( $taxonomy, 'hide_empty=0' ); $terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) ); if ( $terms_string ) { echo esc_html( $terms_string ); } else { echo ''; } } else { echo ''; } ?>