array('label' => __('Hero', 'ai-eshop-optimizer'), 'icon' => 'image'), 'about' => array('label' => __('About', 'ai-eshop-optimizer'), 'icon' => 'book-open'), 'catalog' => array('label' => __('Catalog', 'ai-eshop-optimizer'), 'icon' => 'package'), 'footer' => array('label' => __('Footer', 'ai-eshop-optimizer'), 'icon' => 'layout-template'), 'related' => array('label' => __('Related', 'ai-eshop-optimizer'), 'icon' => 'network'), ); } public function get_tab_base_url() { $tax = AIEO_DMM_Brand_Extras_Data::managed_taxonomies(); $tax = !empty($tax) ? (string) reset($tax) : 'product_brand'; return admin_url('edit-tags.php?taxonomy=' . rawurlencode($tax)); } public function register_hooks() { add_action('wp_ajax_aieo_dmm_brand_extras_save', array($this, 'ajax_save')); $migrator_file = AIEO_DIR . 'includes/dmm/migrators/class-aieo-dmm-brand-pods-migrator.php'; if (file_exists($migrator_file)) { require_once $migrator_file; if (class_exists('AIEO_DMM_Brand_Pods_Migrator')) { AIEO_DMM_Brand_Pods_Migrator::register(); } } if (!is_admin()) { return; } foreach (AIEO_DMM_Brand_Extras_Data::managed_taxonomies() as $tax) { add_action($tax . '_edit_form_fields', array($this, 'render_term_extras'), 1, 2); add_action('edited_' . $tax, array($this, 'save_term_extras'), 10, 2); add_action('created_' . $tax, array($this, 'save_term_extras'), 10, 2); } add_action('admin_enqueue_scripts', array($this, 'enqueue_term_admin_assets')); } public function render_term_extras($term, $taxonomy) { if (!is_object($term) || !isset($term->term_id)) { return; } if (!in_array($taxonomy, AIEO_DMM_Brand_Extras_Data::managed_taxonomies(), true)) { return; } $row = AIEO_DMM_Brand_Extras_Data::get($taxonomy, (int) $term->term_id); $logo_url = $row['logo_image_id'] ? wp_get_attachment_image_url((int) $row['logo_image_id'], 'medium') : ''; $hero_url = $row['hero_image_id'] ? wp_get_attachment_image_url((int) $row['hero_image_id'], 'medium') : ''; $supplier_label = ''; if ($row['supplier_term_id']) { $sup_term = get_term((int) $row['supplier_term_id']); if ($sup_term && !is_wp_error($sup_term)) { $supplier_label = $sup_term->name; } } ?>
term_id, 'aieo_be_nonce'); ?>

'aieo_be[history_text]', 'textarea_rows' => 8, 'media_buttons' => true, 'teeny' => false, 'quicktags' => true, ) ); ?>
'aieo_be[ambassadors_text]', 'textarea_rows' => 5, 'media_buttons' => true, 'teeny' => false, 'quicktags' => true, ) ); ?>
'aieo_be[importer_text]', 'textarea_rows' => 4, 'media_buttons' => false, 'teeny' => true, 'quicktags' => true, ) ); ?>


'aieo_be[footer_text]', 'textarea_rows' => 8, 'media_buttons' => true, 'teeny' => false, 'quicktags' => true, ) ); ?>

term_id); } else { echo '

' . esc_html__('Related-tab component unavailable.', 'ai-eshop-optimizer') . '

'; } ?>
taxonomy, AIEO_DMM_Brand_Extras_Data::managed_taxonomies(), true)) { return; } $raw = wp_unslash($_POST['aieo_be']); if (!is_array($raw)) { return; } $patch = array(); if (isset($raw['logo_image_id'])) { $patch['logo_image_id'] = (int) $raw['logo_image_id']; } if (isset($raw['hero_image_id'])) { $patch['hero_image_id'] = (int) $raw['hero_image_id']; } if (isset($raw['headline'])) { $patch['headline'] = sanitize_text_field((string) $raw['headline']); } if (isset($raw['history_text'])) { $patch['history_text'] = wp_kses_post((string) $raw['history_text']); } if (isset($raw['ambassadors_text'])) { $patch['ambassadors_text'] = wp_kses_post((string) $raw['ambassadors_text']); } if (isset($raw['importer_text'])) { $patch['importer_text'] = wp_kses_post((string) $raw['importer_text']); } if (isset($raw['website_url'])) { $patch['website_url'] = esc_url_raw((string) $raw['website_url']); } if (isset($raw['promo'])) { $patch['promo'] = !empty($raw['promo']) ? 1 : 0; } if (isset($raw['priority'])) { $patch['priority'] = (int) $raw['priority']; } if (isset($raw['bias'])) { $patch['bias'] = (float) $raw['bias']; } if (isset($raw['gross_margin'])) { $gm = trim((string) $raw['gross_margin']); $patch['gross_margin'] = ($gm === '') ? null : (float) $gm; } if (isset($raw['supplier_term_id'])) { $patch['supplier_term_id'] = (int) $raw['supplier_term_id']; } if (isset($raw['footer_text'])) { $patch['footer_text'] = wp_kses_post((string) $raw['footer_text']); } if (isset($raw['gallery_image_ids']) && is_array($raw['gallery_image_ids'])) { $patch['gallery_image_ids'] = array_map('intval', $raw['gallery_image_ids']); } AIEO_DMM_Brand_Extras_Data::save($term->taxonomy, $term_id, $patch); } public function ajax_save() { AIEO_DMM::verify_ajax_request(); wp_send_json_error(array('message' => 'not_implemented'), 501); } public function enqueue_term_admin_assets($hook) { if ($hook !== 'term.php') { return; } $tax = isset($_GET['taxonomy']) ? sanitize_key(wp_unslash($_GET['taxonomy'])) : ''; if (!in_array($tax, AIEO_DMM_Brand_Extras_Data::managed_taxonomies(), true)) { return; } wp_enqueue_media(); wp_enqueue_editor(); wp_enqueue_style( 'aieo-dmm-category-extras-admin', AIEO_URI . 'assets/css/aieo-dmm-category-extras-admin.css', array(), AIEO_VERSION ); wp_enqueue_script( 'aieo-dmm-category-extras-admin', AIEO_URI . 'assets/js/aieo-dmm-category-extras-admin.js', array('jquery'), AIEO_VERSION, true ); wp_localize_script('aieo-dmm-category-extras-admin', 'aieoCategoryExtras', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce(AIEO_DMM::NONCE_ACTION), 'i18n' => array( 'noResults' => __('No matches.', 'ai-eshop-optimizer'), 'searching' => __('Searching…', 'ai-eshop-optimizer'), 'pickImage' => __('Select image', 'ai-eshop-optimizer'), 'useImage' => __('Use this image', 'ai-eshop-optimizer'), ), )); } public function render_subtab() { rooster_admin_band_open( array( 'cols' => 2 ) ); global $wpdb; $brand_count = (int) $wpdb->get_var("SELECT COUNT(*) FROM " . AIEO_DMM_Brand_Extras_Data::table()); $tax = AIEO_DMM_Brand_Extras_Data::managed_taxonomies(); $tax = !empty($tax) ? (string) reset($tax) : 'product_brand'; $rel_count = (int) $wpdb->get_var($wpdb->prepare( 'SELECT COUNT(*) FROM ' . AIEO_DMM_Term_Relations::table() . ' WHERE source_taxonomy = %s', $tax )); list($open, $close) = AIEO_DMM_UI::card(array( 'anchor' => 'brand-extras-brands', 'title' => __('Brands', 'ai-eshop-optimizer'), 'description' => __('Where your brands, needs and suppliers carry extra details, and how to bring them across from Pods. The details themselves are edited on each term: WooCommerce → Products → Brands, Needs or Suppliers → click one.', 'ai-eshop-optimizer'), 'col' => 1, )); echo $open; echo \Rooster\Admin\Guidance::text(__('Logo, history, ambassadors, gallery, website, priority, bias, supplier and footer text.', 'ai-eshop-optimizer'), 'guidance', array('question' => __('Which details?', 'ai-eshop-optimizer'))); echo '
'; echo \Rooster\Admin\Ui::stat(__('Brand metadata rows', 'ai-eshop-optimizer'), number_format_i18n($brand_count)); echo \Rooster\Admin\Ui::stat(__('Links from brands', 'ai-eshop-optimizer'), number_format_i18n($rel_count)); echo '
'; echo '

' . esc_html__('see all linked content', 'ai-eshop-optimizer') . '

'; $has_pods = class_exists('AIEO_DMM_Brand_Pods_Migrator') && AIEO_DMM_Brand_Pods_Migrator::has_pods_source(); if (!$has_pods) { echo \Rooster\Admin\Guidance::text(__('Pods is not active here, so the Pods → Brand Extras migrator is hidden. Brand fields can be edited directly on each brand term-edit screen.', 'ai-eshop-optimizer'), 'guidance', array('question' => __('Where is the Pods migrator?', 'ai-eshop-optimizer'))); } echo $close; if ($has_pods) { $audit = AIEO_DMM_Brand_Pods_Migrator::audit(); $nonce = wp_create_nonce('aieo_brand_pods_migrate'); $ajax = admin_url('admin-ajax.php'); list($open, $close) = AIEO_DMM_UI::card(array( 'anchor' => 'brand-extras-pods-brand-extras-migrator', 'icon' => 'import', 'title' => __('Migrate brands from Pods', 'ai-eshop-optimizer'), 'description' => __('Copies brand fields from the Pods pod into Brand Extras in batches, and shows how many of your brand terms have already been migrated.', 'ai-eshop-optimizer'), 'col' => 1, )); echo $open; echo '

'; echo sprintf( esc_html__('Pods is active on the `%1$s` taxonomy. %2$d brand terms total, %3$d already migrated.', 'ai-eshop-optimizer'), esc_html($audit['taxonomy']), (int) $audit['brand_terms'], (int) $audit['already_migrated'] ); echo '

'; $job = \Rooster\Admin\States::job(array( 'id' => 'aieo-brand-pods-job', 'state' => 'idle', 'run' => __('Run migration', 'ai-eshop-optimizer'), 'run_attrs' => array('id' => 'aieo-brand-pods-run'), )); echo $job; ?> get_module( $absorbed ); if ( $mod && method_exists( $mod, 'render_subtab' ) ) { $mod->render_subtab(); } } rooster_admin_band_close(); } }