get_available_types(); if(empty($attribute_taxonomies)) { return; } foreach($attribute_taxonomies as $tax) { if(isset($types[$tax->attribute_type])) { if(Swatches::PA_LABEL === $tax->attribute_type) { $col = 'label_attribute_column'; } elseif(Swatches::PA_COLOR === $tax->attribute_type) { $col = 'color_attribute_column'; } else { $col = 'image_attribute_column'; } add_filter('manage_edit-pa_' . $tax->attribute_name . '_columns', [$this, $col]); add_filter('manage_pa_' . $tax->attribute_name . '_custom_column', [$this, 'add_attr_column_content'], 10, 3); add_action('pa_' . $tax->attribute_name . '_add_form_fields', [$this, 'add_attr_field']); add_action('pa_' . $tax->attribute_name . '_edit_form_fields', [$this, 'edit_attr_field'], 10, 2); } } add_action('created_term', [$this, 'persist_term_meta'], 10, 2); add_action('edit_term', [$this, 'persist_term_meta'], 10, 2); add_action('shopengine_attribute_field_chain', [$this, 'attribute_fields'], 10, 3); } public function add_attr_field($taxonomy) { $attr = Helper::get_tax_attribute($taxonomy); do_action('shopengine_attribute_field_chain', $attr->attribute_type, '', 'add'); } public function edit_attr_field($term, $taxonomy) { $attr = Helper::get_tax_attribute($taxonomy); $value = get_term_meta($term->term_id, $attr->attribute_type, true); do_action('shopengine_attribute_field_chain', $attr->attribute_type, $value, 'edit'); } public function label_attribute_column($columns) { $th = esc_html__('Label', 'shopengine'); return $this->add_attr_column($columns, $th); } public function image_attribute_column($columns) { $th = esc_html__('Thumbnail', 'shopengine'); return $this->add_attr_column($columns, $th); } public function color_attribute_column($columns) { $th = esc_html__('Color', 'shopengine'); return $this->add_attr_column($columns, $th); } /** * Add another td in the table * * @param $columns * @return mixed */ public function add_attr_column($columns, $th = '') { $new_columns = []; if(isset($columns['cb'])) { $new_columns['cb'] = $columns['cb']; } $new_columns['pa_preview'] = $th; unset($columns['cb']); return $new_columns + $columns; } public function add_attr_column_content($columns, $column, $term_id) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin and not possible nonce here if('pa_preview' !== $column && empty($_REQUEST['taxonomy'])) { return $columns; } //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin and not possible nonce here $attr = Helper::get_tax_attribute(sanitize_key($_REQUEST['taxonomy'])); $value = get_term_meta($term_id, $attr->attribute_type, true); switch($attr->attribute_type) { case Swatches::PA_COLOR: printf('
', esc_attr($value)); break; case Swatches::PA_IMAGE: $image = $value ? wp_get_attachment_image_src($value) : ''; $alt = $image ? trim( strip_tags( get_post_meta( $value, '_wp_attachment_image_alt', true ) ) ) : "Placeholder"; $image = $image ? $image[0] : Helper::get_dummy(); printf('