$this->get_label(), 'description' => __('Run several shops from one catalogue. A source site publishes its products as a token-protected feed and sister sites pull from it on a schedule — categories, attributes, images and variations included, matched by SKU or barcode so a pull updates rather than duplicates.', 'ai-eshop-optimizer'), 'bullets' => array( __('Choose exactly which products a feed carries, and rebuild it on a cadence you set or on demand.', 'ai-eshop-optimizer'), __('Feeds are token-gated and the token can be rotated at any time, so a shared catalogue is never simply public.', 'ai-eshop-optimizer'), __('Receiving sites choose create-only or overwrite, so a sister shop can keep its own prices while still taking new products.', 'ai-eshop-optimizer'), __('Images are side-loaded once and reused, and taxonomy terms are matched or created on the receiving site.', 'ai-eshop-optimizer'), __('Every run is logged per shard with created, updated, skipped and error counts, so a failed pull says what happened.', 'ai-eshop-optimizer'), ), ); } const ENGINE_MARKER = 'AIEO_Exchanger_Feeds'; public function __construct() { $this->load_services(); } private function load_services() { if (class_exists('AIEO_Exchanger_Rest')) { AIEO_Exchanger_Rest::register(); } if (class_exists('AIEO_Exchanger_Cron')) { AIEO_Exchanger_Cron::register(); } if (class_exists('AIEO_Exchanger_Media_Export')) { AIEO_Exchanger_Media_Export::register(); } } private function engine_present() { return class_exists(self::ENGINE_MARKER); } private function require_engine() { if (!$this->engine_present()) { if ($this->pro_active_but_not_loaded()) { wp_send_json_error(array('message' => __('Rooster One Pro is active, but it was not loaded for this request: a performance plugin is choosing which plugins run on admin-ajax. Allow ai-eshop-optimizer-pro for the aieo_exch_ actions in its rules.', 'ai-eshop-optimizer'))); } wp_send_json_error(array('message' => __('Rooster One Pro is not installed. The product-exchanger engine ships with the Pro plugin — install and activate it to publish or import feeds.', 'ai-eshop-optimizer'))); } } private function pro_active_but_not_loaded() { global $wpdb; $raw = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", 'active_plugins')); $active = is_string($raw) ? maybe_unserialize($raw) : array(); return is_array($active) && in_array('ai-eshop-optimizer-pro/ai-eshop-optimizer-pro.php', $active, true); } public function register_hooks() { add_action('wp_ajax_aieo_exch_save_feed', array($this, 'ajax_save_feed')); add_action('wp_ajax_aieo_exch_delete_feed', array($this, 'ajax_delete_feed')); add_action('wp_ajax_aieo_exch_build_feed', array($this, 'ajax_build_feed')); add_action('wp_ajax_aieo_exch_rotate_token', array($this, 'ajax_rotate_token')); add_action('wp_ajax_aieo_exch_notify_targets',array($this, 'ajax_notify_targets')); add_action('wp_ajax_aieo_exch_save_import', array($this, 'ajax_save_import')); add_action('wp_ajax_aieo_exch_delete_import', array($this, 'ajax_delete_import')); add_action('wp_ajax_aieo_exch_run_import', array($this, 'ajax_run_import')); add_action('wp_ajax_aieo_exch_media_save', array($this, 'ajax_media_save')); add_action('wp_ajax_aieo_exch_media_start', array($this, 'ajax_media_start')); add_action('wp_ajax_aieo_exch_media_step', array($this, 'ajax_media_step')); add_action('wp_ajax_aieo_exch_media_cancel', array($this, 'ajax_media_cancel')); add_action('wp_ajax_aieo_exch_media_rotate', array($this, 'ajax_media_rotate')); add_action('admin_post_aieo_exch_media_download', array($this, 'handle_media_download')); } public function get_tab_arg() { return 'exch_section'; } public function get_tabs() { return array( 'feeds' => array('label' => __('Feeds (outbound)', 'ai-eshop-optimizer'), 'icon' => 'send'), 'imports' => array('label' => __('Imports (inbound)', 'ai-eshop-optimizer'), 'icon' => 'import'), 'media' => array('label' => __('Media export', 'ai-eshop-optimizer'), 'icon' => 'image'), 'runlog' => array('label' => __('Run log', 'ai-eshop-optimizer'), 'icon' => 'scroll-text'), 'settings' => array('label' => __('Settings', 'ai-eshop-optimizer'), 'icon' => 'settings'), ); } public function render_subtab() { if (!$this->engine_present()) { $this->render_engine_missing_notice(); return; } $tabs = $this->get_tabs(); $section = isset($_GET['exch_section']) ? sanitize_key((string) $_GET['exch_section']) : 'feeds'; if (!isset($tabs[$section])) { $section = 'feeds'; } $base_url = admin_url('admin.php?page=' . AIEO_DMM::MENU_SLUG . '&dmm_tab=product_exchanger'); AIEO_DMM_UI::tab_strip($this->get_id(), $tabs, $section, array( 'arg' => $this->get_tab_arg(), 'wrapper' => 'div', 'margin' => '14px', )); switch ($section) { case 'imports': $this->render_imports(); break; case 'media': $this->render_media_export(); break; case 'runlog': $this->render_runlog(); break; case 'settings': $this->render_settings(); break; case 'feeds': default: $this->render_feeds(); } } private function render_engine_missing_notice() { echo '

' . esc_html__('Rooster One Pro is not installed.', 'ai-eshop-optimizer') . ' ' . esc_html__('The product-exchanger engine — feed building, the token-gated REST endpoints, the importer and its schedules — ships with the Rooster One Pro plugin. Install and activate it and this screen comes alive without further setup.', 'ai-eshop-optimizer') . '

'; if (class_exists('AIEO_One_Installer')) { AIEO_One_Installer::render('product_exchanger'); } } private function render_feeds() { $feeds = AIEO_Exchanger_Feeds::list_all(); $nonce = wp_create_nonce('aieo_exch_admin'); $ajax = admin_url('admin-ajax.php'); $cron_choices = $this->cron_choices(); $rows = array(); foreach ($feeds as $feed) { $rows[] = array( 'id' => (int) $feed['id'], 'name' => $feed['label'] ?: $feed['slug'], 'slug' => (string) $feed['slug'], 'manifest_url' => AIEO_Exchanger_Feeds::manifest_url($feed), 'schedule' => (string) $feed['schedule_cron'], 'last_built' => (string) $feed['last_built_at'], 'status' => (string) $feed['last_build_status'], 'enabled' => ! empty($feed['enabled']), ); } list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-feeds', 'title' => __('Feeds', 'ai-eshop-optimizer'), 'description' => __('Publish product feeds (token-gated, sharded JSON) for sister sites to consume, and import from feeds published by source sites. Replaces the rudr-simple-wp-crosspost plugin family.', 'ai-eshop-optimizer'), 'flush' => true, )); echo $aieo_px_open; AIEO_Table::render( array( 'columns' => array( array( 'key' => 'name', 'label' => __('Feed', 'ai-eshop-optimizer'), 'type' => 'text', ), array( 'key' => 'slug', 'label' => __('Slug / token', 'ai-eshop-optimizer'), 'type' => 'control', 'format' => array( 'render' => static function ($row) { $mask = class_exists('\Rooster\Admin\Fields') ? \Rooster\Admin\Fields::MASK : '••••••••••••'; return '' . esc_html($row['slug']) . '
' . '' . '' . esc_html__('Shown once, when issued or rotated.', 'ai-eshop-optimizer') . ' · ' . ' ' . '' . esc_html__('Copy manifest URL', 'ai-eshop-optimizer') . ''; }, ), ), array( 'key' => 'schedule', 'label' => __('Schedule', 'ai-eshop-optimizer'), 'type' => 'text', ), array( 'key' => 'last_built', 'label' => __('Last build', 'ai-eshop-optimizer'), 'type' => 'text', 'subline' => 'status', ), array( 'key' => 'enabled', 'label' => __('Enabled', 'ai-eshop-optimizer'), 'type' => 'boolean', ), array( 'key' => 'id', 'label' => '', 'type' => 'control', 'nowrap' => true, 'format' => array( 'render' => static function ($row) { $id = esc_attr($row['id']); return ' ' . ' ' . ' ' . ' ' . ''; }, ), ), ), 'rows' => $rows, 'row_key' => 'id', 'row_class' => static function ($row) { return ('' !== $row['status'] && 'OK' !== $row['status']) ? 'aieo-t-row--danger' : ''; }, 'empty' => __('No feeds yet. Create one below.', 'ai-eshop-optimizer'), 'page_id' => 'product_exchanger', ) ); echo \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-exch-feed-status')); echo $aieo_px_close; if (class_exists('\Rooster\Admin\States')) { $aieo_px_ask = \Rooster\Admin\States::confirm( 'aieo-exch-rotate-confirm', 'loss', __('Rotate token', 'ai-eshop-optimizer'), '

' . esc_html__('Issue a new access key? Anything still using the old one stops working until you pair it again.', 'ai-eshop-optimizer') . '

', array('confirm' => __('Rotate token', 'ai-eshop-optimizer'), 'word' => 'ROTATE') ); echo $aieo_px_ask; } list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-add-a-feed', 'icon' => 'plus', 'title' => __('Add a feed', 'ai-eshop-optimizer'), 'description' => __('Publish a product feed a sister site can import: choose its format and which products it carries.', 'ai-eshop-optimizer'), 'footer' => ' ' . ' ' . \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-exch-feed-savestatus')) . '', )); echo $aieo_px_open; echo '
'; echo ''; echo '
'; $aieo_px_cur = function_exists('get_woocommerce_currency_symbol') ? html_entity_decode((string) get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8') : ''; echo AIEO_Kit::row(__('Slug', 'ai-eshop-optimizer'), '', '', array('id' => 'aieo-exch-feed-slug')); $aieo_px_ctl = '', __('Hourly cron tick rebuilds the feed when the cadence is due.', 'ai-eshop-optimizer'), array('id' => 'aieo-exch-feed-schedule')); echo AIEO_Kit::row(__('Shard size', 'ai-eshop-optimizer'), '', __('Products per shard JSON file. 500 is a safe default for catalogs up to 50k.', 'ai-eshop-optimizer'), array('id' => 'aieo-exch-feed-shard')); foreach (array('price_min' => __('Price min', 'ai-eshop-optimizer'), 'price_max' => __('Price max', 'ai-eshop-optimizer')) as $aieo_px_name => $aieo_px_label) { $aieo_px_id = 'aieo-exch-feed-' . str_replace('_', '-', $aieo_px_name); echo AIEO_Kit::row($aieo_px_label, '' . ('' !== $aieo_px_cur ? '' . esc_html($aieo_px_cur) . '' : '') . '', '', array('id' => $aieo_px_id)); } echo '
'; list($aieo_px_sub_open, $aieo_px_sub_close) = AIEO_DMM_UI::card(array('anchor' => 'product-exchanger-feed-targeting', 'icon' => 'target', 'title' => __('Targeting', 'ai-eshop-optimizer'), 'description' => __('Limit the feed to chosen brands, categories, needs or products; left empty, it carries every product.', 'ai-eshop-optimizer'), 'level' => 3)); echo $aieo_px_sub_open; $ts_form = 'aieo-exch-feed-form'; include AIEO_DIR . 'assets/pages/dmm/_partials/targeting-selector.php'; echo $aieo_px_sub_close; echo '
'; echo AIEO_DMM_Product_Picker::dialogs(); echo $aieo_px_close; $this->print_admin_js($nonce, $ajax, $feeds); } private function render_imports() { $jobs = AIEO_Exchanger_Imports::list_all(); $nonce = wp_create_nonce('aieo_exch_admin'); $ajax = admin_url('admin-ajax.php'); $cron_choices = $this->cron_choices(); $modes = array( 'create_link_only' => __('1 — Create new (link existing terms only)', 'ai-eshop-optimizer'), 'create_with_term_meta' => __('2 — Create new + create missing terms WITH meta + images', 'ai-eshop-optimizer'), 'create_no_term_meta' => __('3 — Create new + create missing terms WITHOUT meta/images', 'ai-eshop-optimizer'), 'update_only' => __('4 — Update existing only (skip new)', 'ai-eshop-optimizer'), 'overwrite' => __('5 — Overwrite (full replace, unlink stale terms)', 'ai-eshop-optimizer'), ); $rows = array(); foreach ((array) $jobs as $job) { $rows[] = array( 'id' => (int) $job['id'], 'job' => (string) ($job['label'] ?: $job['slug']), 'slug' => (string) $job['slug'], 'source' => (string) $job['source_url'], 'mode' => (string) $job['mode'], 'match' => (string) $job['match_key'], 'schedule' => (string) $job['schedule_cron'], 'last_run' => (string) $job['last_run_at'], 'status' => (string) $job['last_status'], 'enabled' => ! empty($job['enabled']), ); } list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-imports', 'title' => __('Imports', 'ai-eshop-optimizer'), 'description' => __('The sister sites\' feeds this shop imports, with when each one last ran and what it did.', 'ai-eshop-optimizer'), 'flush' => true, )); echo $aieo_px_open; AIEO_Table::render(array( 'page_id' => $this->get_id(), 'row_key' => 'id', 'rows' => $rows, 'empty' => __('No import jobs yet. Create one below.', 'ai-eshop-optimizer'), 'columns' => array( array('key' => 'job', 'label' => __('Job', 'ai-eshop-optimizer'), 'subline' => 'slug'), array('key' => 'source', 'label' => __('Source', 'ai-eshop-optimizer'), 'truncate' => 60, 'tooltip' => true), array('key' => 'mode', 'label' => __('Mode / match', 'ai-eshop-optimizer'), 'type' => 'code', 'subline' => 'match'), array('key' => 'schedule', 'label' => __('Schedule', 'ai-eshop-optimizer'), 'type' => 'code'), array( 'key' => 'last_run', 'label' => __('Last run', 'ai-eshop-optimizer'), 'nowrap' => true, 'subline' => 'status', ), array('key' => 'enabled', 'label' => __('Enabled', 'ai-eshop-optimizer'), 'type' => 'boolean'), ), 'actions' => array( array( 'id' => 'edit', 'label' => __('Edit', 'ai-eshop-optimizer'), 'description' => __('Loads this job into the form below.', 'ai-eshop-optimizer'), 'variant' => 'secondary', 'data' => array('aieo-exch-edit-import' => 'id'), ), array( 'id' => 'run', 'label' => __('Run now', 'ai-eshop-optimizer'), 'description' => __('Starts this import now instead of waiting for its schedule.', 'ai-eshop-optimizer'), 'variant' => 'primary', 'data' => array('aieo-exch-run' => 'id'), ), array( 'id' => 'delete', 'label' => __('Delete', 'ai-eshop-optimizer'), 'description' => __('Removes this import job.', 'ai-eshop-optimizer'), 'variant' => 'destructive', 'destructive' => true, 'data' => array('aieo-exch-delete-import' => 'id'), ), ), )); echo \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-exch-import-status')); echo $aieo_px_close; list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-add-an-import-job', 'icon' => 'import', 'title' => __('Add an import job', 'ai-eshop-optimizer'), 'description' => __('Import a sister site\'s feed into this shop: give its address and decide what each run may change.', 'ai-eshop-optimizer'), 'footer' => ' ' . ' ' . \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-exch-import-savestatus')), )); echo $aieo_px_open; echo '
'; echo ''; echo '
'; echo AIEO_Kit::row(__('Slug', 'ai-eshop-optimizer'), '', '', array('id' => 'aieo-exch-import-slug')); echo AIEO_Kit::row(__('Label', 'ai-eshop-optimizer'), '', '', array('id' => 'aieo-exch-import-label')); echo AIEO_Kit::row(__('Source manifest URL', 'ai-eshop-optimizer'), '', '', array('id' => 'aieo-exch-import-source')); $aieo_px_token_ph = '64-char hex from the source feed'; $aieo_px_token = class_exists('\Rooster\Admin\Fields') ? \Rooster\Admin\Fields::secret('feed_token', false, array('id' => 'aieo-exch-import-token', 'placeholder' => $aieo_px_token_ph, 'attrs' => array('data-placeholder' => $aieo_px_token_ph))) : ''; echo AIEO_Kit::row(__('Feed token', 'ai-eshop-optimizer'), $aieo_px_token, '', array('id' => 'aieo-exch-import-token')); echo AIEO_Kit::row(__('Match key', 'ai-eshop-optimizer'), '', __('Products are matched on SKU. A barcode cannot identify a product: the same article carries different barcodes per country and per revision.', 'ai-eshop-optimizer'), array('id' => 'aieo-exch-import-match')); $aieo_px_ctl = '', '', array('id' => 'aieo-exch-import-mode')); $aieo_px_ctl = '', '', array('id' => 'aieo-exch-import-schedule')); echo AIEO_Kit::row(__('Enabled', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::toggle('enabled', true, array('id' => 'aieo-exch-import-enabled', 'hidden' => false, 'label' => __('Enabled', 'ai-eshop-optimizer'), 'label_hidden' => true)), '', array('id' => 'aieo-exch-import-enabled')); echo '
'; echo '
'; echo $aieo_px_close; $this->print_admin_js($nonce, $ajax, array(), $jobs); } private function media_export_present() { return class_exists('AIEO_Exchanger_Media_Export') && class_exists('AIEO_Product_Media_Resolver'); } private function term_chips(array $ids, $taxonomy) { $ids = array_values(array_filter(array_map('absint', $ids))); if (empty($ids) || !taxonomy_exists($taxonomy)) { return array(); } $terms = get_terms(array('taxonomy' => $taxonomy, 'include' => $ids, 'hide_empty' => false)); $out = array(); foreach (is_array($terms) ? $terms : array() as $t) { $out[] = array('id' => (int) $t->term_id, 'text' => (string) $t->name, 'type' => 'term', 'status' => 'publish'); } return $out; } private function render_media_export() { if (!$this->media_export_present()) { echo '

' . esc_html__('Update Rooster One and Rooster One Pro to the same version to use the media export.', 'ai-eshop-optimizer') . '

'; return; } $aieo_px_stored = get_option(AIEO_Exchanger_Media_Export::SETTINGS_OPTION, array()); $aieo_px_fresh = !is_array($aieo_px_stored) || '' === (string) ($aieo_px_stored['token'] ?? ''); $s = AIEO_Exchanger_Media_Export::settings(); $job = AIEO_Exchanger_Media_Export::job(); $files = AIEO_Exchanger_Media_Export::published_files(); list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-media-export', 'title' => __('Media export', 'ai-eshop-optimizer'), 'description' => __('Every product\'s photos, swatches and videos as files another platform can import, such as Shopify. One row per variation, with the product\'s default photo, the variation\'s swatch, its own image and gallery, titles, SKUs and the created and modified dates.', 'ai-eshop-optimizer'), 'footer' => ' ' . \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-exch-media-savestatus')), )); echo $aieo_px_open; echo '
'; echo '

' . esc_html__('Which products', 'ai-eshop-optimizer') . '

'; echo \Rooster\Admin\Guidance::text(__('Leave every field empty to export the whole catalogue. Each filled field narrows the list.', 'ai-eshop-optimizer')); echo '
'; foreach (array( 'brand' => array('brand_term_ids', 'product_brand', __('Brands', 'ai-eshop-optimizer')), 'category' => array('category_term_ids', 'product_cat', __('Categories', 'ai-eshop-optimizer')), 'need' => array('need_term_ids', 'pa_need', __('Needs', 'ai-eshop-optimizer')), ) as $entity => $f) { echo AIEO_DMM_Product_Picker::entity_field($entity, array( 'name' => $f[0], 'form' => 'aieo-exch-media-form', 'label' => $f[2], 'items' => $this->term_chips((array) $s[$f[0]], $f[1]), )); } echo AIEO_DMM_Product_Picker::entity_field('product', array( 'name' => 'product_ids', 'form' => 'aieo-exch-media-form', 'label' => __('Specific products', 'ai-eshop-optimizer'), 'selected' => (array) $s['product_ids'], )); echo '
'; ob_start(); echo '
'; foreach (array( 'brand' => array('excluded_brand_ids', 'product_brand', __('Excluded brands', 'ai-eshop-optimizer')), 'category' => array('excluded_category_ids', 'product_cat', __('Excluded categories', 'ai-eshop-optimizer')), 'need' => array('excluded_need_ids', 'pa_need', __('Excluded needs', 'ai-eshop-optimizer')), ) as $entity => $f) { echo AIEO_DMM_Product_Picker::entity_field($entity, array( 'name' => $f[0], 'form' => 'aieo-exch-media-form', 'mode' => 'exclude', 'label' => $f[2], 'items' => $this->term_chips((array) $s[$f[0]], $f[1]), )); } echo AIEO_DMM_Product_Picker::entity_field('product', array( 'name' => 'excluded_product_ids', 'form' => 'aieo-exch-media-form', 'mode' => 'exclude', 'label' => __('Excluded products', 'ai-eshop-optimizer'), 'selected' => (array) $s['excluded_product_ids'], )); echo '
'; echo AIEO_Kit::fold(__('Exclusions', 'ai-eshop-optimizer'), (string) ob_get_clean(), array('class' => 'aieo-details-block')); echo '
'; $aieo_px_ctl = ''; foreach (array( 'publish' => __('Published', 'ai-eshop-optimizer'), 'private' => __('Private', 'ai-eshop-optimizer'), 'draft' => __('Draft', 'ai-eshop-optimizer'), 'pending' => __('Pending review', 'ai-eshop-optimizer'), ) as $st => $label) { $aieo_px_ctl .= ''; } echo AIEO_Kit::row(__('Product status', 'ai-eshop-optimizer'), $aieo_px_ctl, '', array('id' => 'aieo-exch-media-statuses', 'group' => true)); echo AIEO_Kit::row(__('Changed since', 'ai-eshop-optimizer'), '', __('Only products edited on or after this day, in the shop\'s timezone. Leave empty for all.', 'ai-eshop-optimizer'), array('id' => 'aieo-exch-media-since')); echo AIEO_Kit::row(__('Excel', 'ai-eshop-optimizer'), '', __('Leave off when a script or an import app reads the files.', 'ai-eshop-optimizer'), array('id' => 'aieo-exch-media-excel', 'group' => true)); $aieo_px_ctl = '', __('Keeps the private links below current while both shops run side by side.', 'ai-eshop-optimizer'), array('id' => 'aieo-exch-media-auto')); echo '
'; echo '
'; echo AIEO_DMM_Product_Picker::dialogs(); echo $aieo_px_close; list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-media-export-files', 'icon' => 'download', 'title' => __('Build and download', 'ai-eshop-optimizer'), 'description' => __('Build the media sheet of every product\'s photos and videos, then download it or share a private link.', 'ai-eshop-optimizer'), )); echo $aieo_px_open; echo '

' . ' ' . '' . '

'; echo ''; echo \Rooster\Admin\States::outcome('', '', array('id' => 'aieo-exch-media-status')); if (is_array($job) && $job['status'] !== 'running') { $this->render_media_last_job($job); } if (!empty($files)) { $labels = array( 'media' => __('Media sheet: one row per variation', 'ai-eshop-optimizer'), 'swatches' => __('Swatch list: one row per attribute value', 'ai-eshop-optimizer'), 'json' => __('Everything, nested per product', 'ai-eshop-optimizer'), ); echo self::section_html(__('Files', 'ai-eshop-optimizer')); echo ''; $aieo_px_links = self::section_html( __('Private links', 'ai-eshop-optimizer'), __('Give these to the team importing the data. Each link always serves the latest build, and anyone holding it can download the file, so issue new links when the move is done.', 'ai-eshop-optimizer') ); echo $aieo_px_links; $aieo_px_mask = class_exists('\Rooster\Admin\Fields') ? \Rooster\Admin\Fields::MASK : '••••••••••••'; foreach (array_keys($files) as $key) { $aieo_px_url = $aieo_px_fresh ? AIEO_Exchanger_Media_Export::feed_url($key) : rest_url('aieo/v1/exchanger/media-export/' . $key) . '?token=' . $aieo_px_mask; echo ''; } echo '

' . esc_html__('Shown once, when issued or rotated.', 'ai-eshop-optimizer') . '

'; $aieo_px_rot_attrs = class_exists('\Rooster\Admin\States') ? \Rooster\Admin\Ui::attrs(\Rooster\Admin\States::confirm_attrs('aieo-exch-media-rotate-confirm')) : ''; echo '

'; if (class_exists('\Rooster\Admin\States')) { $aieo_px_ask = \Rooster\Admin\States::confirm( 'aieo-exch-media-rotate-confirm', 'replace', __('Issue new links', 'ai-eshop-optimizer'), '

' . esc_html__('Issue new links? The current links stop working at once.', 'ai-eshop-optimizer') . '

', array('confirm' => __('Issue new links', 'ai-eshop-optimizer')) ); echo $aieo_px_ask; } echo self::section_html(''); } echo \Rooster\Admin\Ui::fold(__('What the media sheet contains', 'ai-eshop-optimizer'), \Rooster\Admin\Guidance::text(__('Several images or videos in one cell are separated by commas. Dates carry the shop\'s timezone offset. A product without variations takes one row with the variation columns empty. The swatch source says where the swatch picture comes from: the attribute value itself, or the variation\'s or product\'s image when the value has none.', 'ai-eshop-optimizer'), 'guidance', array('question' => __('What do the cells hold?', 'ai-eshop-optimizer'))) . '

' . esc_html(implode(' | ', AIEO_Exchanger_Media_Export::media_columns())) . '

'); echo $aieo_px_close; $this->print_media_js(wp_create_nonce('aieo_exch_admin'), $job); } private static function section_html($title, $description = '') { if (function_exists('rooster_admin_card_section_html') && class_exists('AIEO_Chrome') && AIEO_Chrome::on()) { return rooster_admin_card_section_html((string) $title, array('description' => (string) $description)); } if ('' === (string) $title) { return ''; } return '

' . esc_html($title) . '

' . ('' !== (string) $description ? '

' . esc_html($description) . '

' : ''); } private function render_media_last_job(array $job) { $when = !empty($job['finished_at']) ? wp_date(get_option('date_format') . ' ' . get_option('time_format'), (int) $job['finished_at']) : ''; if ($job['status'] === 'done') { echo '

' . esc_html(sprintf( __('Last build %1$s: %2$s products, %3$s variations, %4$s rows, in %5$s s.', 'ai-eshop-optimizer'), $when, number_format_i18n((int) $job['products']), number_format_i18n((int) $job['variations']), number_format_i18n((int) $job['rows']), number_format_i18n(max(0, (int) $job['finished_at'] - (int) $job['started_at'])) )) . '

'; if (!empty($job['skipped'])) { $aieo_px_skip = esc_html(sprintf( _n('%s product could not be read and was left out.', '%s products could not be read and were left out.', (int) $job['skipped'], 'ai-eshop-optimizer'), number_format_i18n((int) $job['skipped']) )) . (!empty($job['errors']) ? ' ' . esc_html(implode('; ', array_slice((array) $job['errors'], 0, 3))) . '' : ''); $aieo_px_skip = class_exists('\Rooster\Admin\Ui') ? \Rooster\Admin\Ui::notice($aieo_px_skip, 'warning', array('inline' => true)) : '

' . $aieo_px_skip . '

'; echo $aieo_px_skip; } } elseif ($job['status'] === 'failed') { $aieo_px_fail = esc_html(sprintf( __('The last build stopped: %s', 'ai-eshop-optimizer'), (string) $job['error'] )); $aieo_px_fail = class_exists('\Rooster\Admin\Ui') ? \Rooster\Admin\Ui::notice($aieo_px_fail, 'destructive', array('inline' => true)) : '

' . $aieo_px_fail . '

'; echo $aieo_px_fail; } elseif ($job['status'] === 'cancelled') { echo '

' . esc_html__('The last build was cancelled. The files below are from the build before it.', 'ai-eshop-optimizer') . '

'; } } private function print_media_js($nonce, $job) { $running = AIEO_Exchanger_Media_Export::is_live($job); $t = array( 'saving' => __('Saving…', 'ai-eshop-optimizer'), 'saved' => __('Saved. %s products match.', 'ai-eshop-optimizer'), 'failed' => __('Something went wrong. Reload the page and try again.', 'ai-eshop-optimizer'), 'starting' => __('Starting…', 'ai-eshop-optimizer'), 'progress' => __('%1$s of %2$s products, %3$s rows', 'ai-eshop-optimizer'), 'busy' => __('Working in the background…', 'ai-eshop-optimizer'), 'done' => __('Done. Reloading…', 'ai-eshop-optimizer'), 'cancelled' => __('Cancelled.', 'ai-eshop-optimizer'), 'confirm' => __('Issue new links? The current links stop working at once.', 'ai-eshop-optimizer'), 'copied' => __('Copied', 'ai-eshop-optimizer'), 'rotated' => __('New links issued. Send them again to whoever needs them.', 'ai-eshop-optimizer'), ); echo ''; } private function render_runlog() { $rows = AIEO_Exchanger_Run_Log::recent(100); AIEO_Table::card( array( 'anchor' => 'product-exchanger-runlog', 'heading' => 'h2', 'title' => __('Run log', 'ai-eshop-optimizer'), 'description' => __('Each feed build and import run, when it started and how it ended.', 'ai-eshop-optimizer'), 'columns' => array( array( 'key' => 'started_at', 'label' => __('When', 'ai-eshop-optimizer'), 'type' => 'text', 'suffix' => 'UTC', ), array( 'key' => 'side_job', 'label' => __('Side / job', 'ai-eshop-optimizer'), 'type' => 'text', ), array( 'key' => 'shard', 'label' => __('Shard', 'ai-eshop-optimizer'), 'type' => 'integer' ), array( 'key' => 'processed', 'label' => __('Processed', 'ai-eshop-optimizer'), 'type' => 'integer' ), array( 'key' => 'created', 'label' => __('Created', 'ai-eshop-optimizer'), 'type' => 'integer', 'tone' => 'success' ), array( 'key' => 'updated', 'label' => __('Updated', 'ai-eshop-optimizer'), 'type' => 'integer' ), array( 'key' => 'skipped', 'label' => __('Skipped', 'ai-eshop-optimizer'), 'type' => 'integer' ), array( 'key' => 'errors', 'label' => __('Errors', 'ai-eshop-optimizer'), 'type' => 'integer', 'bands' => array( array( 'min' => 1, 'tone' => 'danger' ), ), ), ), 'rows' => array_map( static function ($r) { return array( 'run_id' => isset($r['id']) ? (int) $r['id'] : 0, 'started_at' => (string) $r['started_at'], 'side_job' => (string) $r['side'] . ' #' . (int) $r['job_id'], 'shard' => (int) $r['shard'], 'processed' => (int) $r['processed'], 'created' => (int) $r['created'], 'updated' => (int) $r['updated'], 'skipped' => (int) $r['skipped'], 'errors' => (int) $r['errors_count'], 'errors_json' => (string) ( isset($r['errors_json']) ? $r['errors_json'] : '' ), ); }, (array) $rows ), 'row_key' => 'run_id', 'detail_row' => static function ($row) { if ($row['errors'] < 1 || '' === $row['errors_json']) { return ''; } return '
'
                        . esc_html(substr($row['errors_json'], 0, 1500)) . '
'; }, 'empty' => __('No runs yet.', 'ai-eshop-optimizer'), 'page_id' => 'product_exchanger', ) ); } private function render_settings() { if (function_exists('rooster_admin_band_open')) { rooster_admin_band_open(array('cols' => 2)); } list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-schema-state', 'icon' => 'database', 'title' => __('Exchanger table state', 'ai-eshop-optimizer'), 'description' => __('Whether the exchanger\'s database tables exist and how many rows each one holds.', 'ai-eshop-optimizer'), 'col' => 1, )); echo $aieo_px_open; echo ''; echo \Rooster\Admin\Guidance::text(__('Schema is auto-created on plugin activation. To rebuild manually: wp eval \'aieo_dmm_create_tables();\'', 'ai-eshop-optimizer')); echo $aieo_px_close; list($aieo_px_open, $aieo_px_close) = AIEO_DMM_UI::card(array( 'anchor' => 'product-exchanger-cron-events', 'icon' => 'clock', 'title' => __('Cron events', 'ai-eshop-optimizer'), 'description' => __('The scheduled tasks that build feeds and run imports, and when each one runs next.', 'ai-eshop-optimizer'), 'col' => 2, )); echo $aieo_px_open; echo ''; echo $aieo_px_close; if (function_exists('rooster_admin_band_close')) { rooster_admin_band_close(); } } private function cron_choices() { return array( '' => __('Manual only', 'ai-eshop-optimizer'), 'hourly' => __('Hourly', 'ai-eshop-optimizer'), 'twicedaily' => __('Twice daily', 'ai-eshop-optimizer'), 'daily' => __('Daily', 'ai-eshop-optimizer'), 'weekly' => __('Weekly', 'ai-eshop-optimizer'), ); } const TARGETING_KEYS = array('brand_term_ids', 'category_term_ids', 'need_term_ids', 'product_ids', 'excluded_brand_ids', 'excluded_category_ids', 'excluded_need_ids', 'excluded_product_ids'); public function feed_payload(array $f) { $brand = class_exists('AIEO_DMM_Brand_Discounts') ? (string) AIEO_DMM_Brand_Discounts::get_brand_taxonomy() : ''; $taxes = array( 'brand_term_ids' => '' !== $brand ? $brand : 'product_brand', 'category_term_ids' => 'product_cat', 'need_term_ids' => 'pa_need', 'excluded_brand_ids' => '' !== $brand ? $brand : 'product_brand', 'excluded_category_ids' => 'product_cat', 'excluded_need_ids' => 'pa_need', ); $out = array( 'id' => (int) $f['id'], 'slug' => (string) $f['slug'], 'label' => (string) $f['label'], 'enabled' => (int) $f['enabled'], 'schedule_cron' => (string) $f['schedule_cron'], 'shard_size' => (int) $f['shard_size'], 'rule_operator' => (string) ($f['rule_operator'] ?? 'AND'), 'date_from' => (string) ($f['date_from'] ?? ''), 'date_to' => (string) ($f['date_to'] ?? ''), 'min_subtotal' => (float) $f['min_subtotal'], 'price_min' => $f['price_min'], 'price_max' => $f['price_max'], ); foreach (self::TARGETING_KEYS as $key) { $ids = array_values(array_filter(array_map('absint', (array) ($f[$key] ?? array())))); if (isset($taxes[$key])) { $found = array(); foreach ($this->term_chips($ids, $taxes[$key]) as $chip) { $found[(int) $chip['id']] = $chip; } $pairs = array(); foreach ($ids as $id) { $pairs[] = isset($found[$id]) ? $found[$id] : array('id' => $id, 'text' => '#' . $id, 'type' => 'term', 'status' => 'missing'); } } else { $pairs = AIEO_DMM_Product_Picker::hydrate_ids($ids); } $out[$key] = AIEO_DMM_Product_Picker::chosen_items($pairs); } return $out; } private function print_admin_js($nonce, $ajax, $feeds = array(), $jobs = array()) { $feeds_json = wp_json_encode(array_map(array($this, 'feed_payload'), $feeds)); $jobs_json = wp_json_encode(array_map(function($j) { return array( 'id' => (int) $j['id'], 'slug' => (string) $j['slug'], 'label' => (string) $j['label'], 'enabled' => (int) $j['enabled'], 'source_url' => (string) $j['source_url'], 'has_token' => '' !== (string) $j['feed_token'], 'match_key' => (string) $j['match_key'], 'mode' => (string) $j['mode'], 'schedule_cron'=> (string) $j['schedule_cron'], ); }, $jobs)); $words = array( 'edit_feed' => __('Edit feed', 'ai-eshop-optimizer'), 'add_feed' => __('Add a feed', 'ai-eshop-optimizer'), 'edit_import' => __('Edit import job', 'ai-eshop-optimizer'), 'add_import' => __('Add an import job', 'ai-eshop-optimizer'), 'saving' => __('Saving…', 'ai-eshop-optimizer'), 'saved' => __('Saved.', 'ai-eshop-optimizer'), 'save_failed' => __('Save failed.', 'ai-eshop-optimizer'), 'building' => __('Building feed %1$s…', 'ai-eshop-optimizer'), 'built' => __('Feed built: %1$s products in %2$s files. Manifest: %3$s', 'ai-eshop-optimizer'), 'build_failed' => __('Build failed.', 'ai-eshop-optimizer'), 'rotated' => __('New access key issued. It is shown in the feed\'s row above: press “Copy token” to copy it.', 'ai-eshop-optimizer'), 'rotate_failed' => __('The new access key could not be issued.', 'ai-eshop-optimizer'), 'copied' => __('Copied!', 'ai-eshop-optimizer'), 'notified' => __('Shops notified: %1$s. Errors: %2$s.', 'ai-eshop-optimizer'), 'notify_failed' => __('The shops could not be notified.', 'ai-eshop-optimizer'), 'running' => __('Running import %1$s…', 'ai-eshop-optimizer'), 'run_done' => __('Import complete: %1$s processed, %2$s created, %3$s updated, %4$s skipped, %5$s errors.', 'ai-eshop-optimizer'), 'run_failed' => __('Run failed.', 'ai-eshop-optimizer'), ); echo ''; } public function ajax_save_feed() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } $data = array( 'id' => isset($_POST['id']) ? (int) $_POST['id'] : 0, 'slug' => isset($_POST['slug']) ? sanitize_key(wp_unslash((string) $_POST['slug'])) : '', 'label' => isset($_POST['label']) ? sanitize_text_field(wp_unslash((string) $_POST['label'])) : '', 'enabled' => !empty($_POST['enabled']), 'schedule_cron' => isset($_POST['schedule_cron']) ? sanitize_key(wp_unslash((string) $_POST['schedule_cron'])) : '', 'shard_size' => isset($_POST['shard_size']) ? (int) $_POST['shard_size'] : 500, 'rule_operator' => isset($_POST['rule_operator']) ? sanitize_text_field(wp_unslash((string) $_POST['rule_operator'])) : 'AND', 'date_from' => isset($_POST['date_from']) ? sanitize_text_field(wp_unslash((string) $_POST['date_from'])) : '', 'date_to' => isset($_POST['date_to']) ? sanitize_text_field(wp_unslash((string) $_POST['date_to'])) : '', 'min_subtotal' => isset($_POST['min_subtotal']) ? (float) $_POST['min_subtotal'] : 0, 'price_min' => isset($_POST['price_min']) && $_POST['price_min'] !== '' ? (float) $_POST['price_min'] : null, 'price_max' => isset($_POST['price_max']) && $_POST['price_max'] !== '' ? (float) $_POST['price_max'] : null, 'brand_term_ids' => isset($_POST['brand_term_ids']) ? array_map('intval', (array) wp_unslash($_POST['brand_term_ids'])) : array(), 'category_term_ids' => isset($_POST['category_term_ids']) ? array_map('intval', (array) wp_unslash($_POST['category_term_ids'])) : array(), 'need_term_ids' => isset($_POST['need_term_ids']) ? array_map('intval', (array) wp_unslash($_POST['need_term_ids'])) : array(), 'excluded_brand_ids' => isset($_POST['excluded_brand_ids']) ? array_map('intval', (array) wp_unslash($_POST['excluded_brand_ids'])) : array(), 'excluded_category_ids' => isset($_POST['excluded_category_ids']) ? array_map('intval', (array) wp_unslash($_POST['excluded_category_ids'])) : array(), 'excluded_need_ids' => isset($_POST['excluded_need_ids']) ? array_map('intval', (array) wp_unslash($_POST['excluded_need_ids'])) : array(), ); $data['product_ids'] = AIEO_DMM_Product_Picker::roll_up_to_parents( AIEO_DMM_Product_Picker::collect_ids('product_ids') ); $data['excluded_product_ids'] = AIEO_DMM_Product_Picker::roll_up_to_parents( AIEO_DMM_Product_Picker::collect_ids('excluded_product_ids') ); $r = AIEO_Exchanger_Feeds::save($data); if (is_wp_error($r)) { wp_send_json_error(array('message' => $r->get_error_message())); } $out = array('id' => (int) $r); if (0 === (int) $data['id']) { $created = AIEO_Exchanger_Feeds::get((int) $r); $out['feed_token'] = is_array($created) ? (string) $created['feed_token'] : ''; } wp_send_json_success($out); } public function ajax_delete_feed() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } AIEO_Exchanger_Feeds::delete(isset($_POST['id']) ? (int) $_POST['id'] : 0); wp_send_json_success(); } public function ajax_build_feed() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } $r = AIEO_Exchanger_Feed_Builder::build(isset($_POST['id']) ? (int) $_POST['id'] : 0); if (empty($r['ok'])) { wp_send_json_error(array('message' => (string) ($r['error'] ?? 'build_failed'))); } wp_send_json_success($r); } public function ajax_rotate_token() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } $token = AIEO_Exchanger_Feeds::rotate_token(isset($_POST['id']) ? (int) $_POST['id'] : 0); wp_send_json_success(array('feed_token' => $token)); } public function ajax_notify_targets() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } $feed = AIEO_Exchanger_Feeds::get(isset($_POST['id']) ? (int) $_POST['id'] : 0); if (!$feed) { wp_send_json_error(array('message' => 'feed_not_found')); } $r = AIEO_Exchanger_Rest::notify_targets($feed); wp_send_json_success($r); } public function ajax_save_import() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } $data = array( 'id' => isset($_POST['id']) ? (int) $_POST['id'] : 0, 'slug' => isset($_POST['slug']) ? sanitize_key(wp_unslash((string) $_POST['slug'])) : '', 'label' => isset($_POST['label']) ? sanitize_text_field(wp_unslash((string) $_POST['label'])) : '', 'enabled' => !empty($_POST['enabled']), 'source_url' => isset($_POST['source_url']) ? esc_url_raw(wp_unslash((string) $_POST['source_url'])) : '', 'feed_token' => isset($_POST['feed_token']) ? sanitize_text_field(wp_unslash((string) $_POST['feed_token'])) : '', 'match_key' => isset($_POST['match_key']) ? sanitize_key(wp_unslash((string) $_POST['match_key'])) : 'sku', 'mode' => isset($_POST['mode']) ? sanitize_key(wp_unslash((string) $_POST['mode'])) : 'create_with_term_meta', 'schedule_cron' => isset($_POST['schedule_cron']) ? sanitize_key(wp_unslash((string) $_POST['schedule_cron'])) : '', ); if ($data['id'] > 0 && '' === trim(str_replace("\u{2022}", '', $data['feed_token']))) { $stored = AIEO_Exchanger_Imports::get($data['id']); $data['feed_token'] = is_array($stored) ? (string) ($stored['feed_token'] ?? '') : ''; } $r = AIEO_Exchanger_Imports::save($data); if (is_wp_error($r)) { wp_send_json_error(array('message' => $r->get_error_message())); } wp_send_json_success(array('id' => (int) $r)); } public function ajax_delete_import() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } AIEO_Exchanger_Imports::delete(isset($_POST['id']) ? (int) $_POST['id'] : 0); wp_send_json_success(); } public function ajax_run_import() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } $r = AIEO_Exchanger_Puller::run_full(isset($_POST['id']) ? (int) $_POST['id'] : 0); if (empty($r['ok'])) { wp_send_json_error(array('message' => (string) ($r['error'] ?? 'run_failed'))); } wp_send_json_success($r); } private function media_guard() { check_ajax_referer('aieo_exch_admin', 'nonce'); $this->require_engine(); if (!$this->can_manage()) { wp_send_json_error(array('message' => 'forbidden')); } if (!$this->media_export_present()) { wp_send_json_error(array('message' => __('Update Rooster One and Rooster One Pro to the same version to use the media export.', 'ai-eshop-optimizer'))); } } private function media_progress($job) { $job = is_array($job) ? $job : array(); return array( 'status' => (string) ($job['status'] ?? ''), 'total' => (int) ($job['total'] ?? 0), 'cursor' => (int) ($job['cursor'] ?? 0), 'products' => (int) ($job['products'] ?? 0), 'variations' => (int) ($job['variations'] ?? 0), 'rows' => (int) ($job['rows'] ?? 0), 'skipped' => (int) ($job['skipped'] ?? 0), 'busy' => !empty($job['busy']), 'error' => (string) ($job['error'] ?? ''), ); } public function ajax_media_save() { $this->media_guard(); $statuses = isset($_POST['statuses']) ? array_map('sanitize_key', (array) wp_unslash($_POST['statuses'])) : array(); $s = AIEO_Exchanger_Media_Export::save_settings(array( 'brand_term_ids' => AIEO_DMM_Product_Picker::collect_ids('brand_term_ids'), 'category_term_ids' => AIEO_DMM_Product_Picker::collect_ids('category_term_ids'), 'need_term_ids' => AIEO_DMM_Product_Picker::collect_ids('need_term_ids'), 'product_ids' => AIEO_DMM_Product_Picker::roll_up_to_parents(AIEO_DMM_Product_Picker::collect_ids('product_ids')), 'excluded_brand_ids' => AIEO_DMM_Product_Picker::collect_ids('excluded_brand_ids'), 'excluded_category_ids' => AIEO_DMM_Product_Picker::collect_ids('excluded_category_ids'), 'excluded_need_ids' => AIEO_DMM_Product_Picker::collect_ids('excluded_need_ids'), 'excluded_product_ids' => AIEO_DMM_Product_Picker::roll_up_to_parents(AIEO_DMM_Product_Picker::collect_ids('excluded_product_ids')), 'statuses' => $statuses, 'changed_since' => isset($_POST['changed_since']) ? sanitize_text_field(wp_unslash((string) $_POST['changed_since'])) : '', 'excel_bom' => !empty($_POST['excel_bom']), 'auto' => isset($_POST['auto']) ? sanitize_key(wp_unslash((string) $_POST['auto'])) : '', )); wp_send_json_success(array('products' => count(AIEO_Exchanger_Media_Export::query_product_ids($s)))); } public function ajax_media_start() { $this->media_guard(); $job = AIEO_Exchanger_Media_Export::start('admin'); if (is_wp_error($job)) { wp_send_json_error(array('message' => $job->get_error_message())); } wp_send_json_success($this->media_progress($job)); } public function ajax_media_step() { $this->media_guard(); $job = AIEO_Exchanger_Media_Export::step(AIEO_Exchanger_Media_Export::STEP_SECONDS); if (!is_array($job)) { wp_send_json_error(array('message' => __('No export is running.', 'ai-eshop-optimizer'))); } wp_send_json_success($this->media_progress($job)); } public function ajax_media_cancel() { $this->media_guard(); wp_send_json_success($this->media_progress(AIEO_Exchanger_Media_Export::cancel())); } public function ajax_media_rotate() { $this->media_guard(); AIEO_Exchanger_Media_Export::rotate_token(); $links = array(); foreach (array_keys(AIEO_Exchanger_Media_Export::FILES) as $key) { $links[$key] = AIEO_Exchanger_Media_Export::feed_url($key); } wp_send_json_success(array('links' => $links)); } public function handle_media_download() { if (!$this->can_manage()) { wp_die(esc_html__('You are not allowed to do this.', 'ai-eshop-optimizer'), '', array('response' => 403)); } check_admin_referer('aieo_exch_media_download'); if (!$this->media_export_present()) { wp_die(esc_html__('Update Rooster One and Rooster One Pro to the same version to use the media export.', 'ai-eshop-optimizer'), '', array('response' => 404)); } $file = isset($_GET['file']) ? sanitize_key(wp_unslash((string) $_GET['file'])) : ''; AIEO_Exchanger_Media_Export::stream($file); } private function can_manage() { return current_user_can(defined('AIEO_CAPABILITY') ? AIEO_CAPABILITY : 'manage_options'); } }