__( 'Unauthorized', 'ai-eshop-optimizer' ) ), 403 ); } check_ajax_referer( 'aieo_save_chat_model', 'nonce' ); $model = isset( $_POST['model'] ) ? sanitize_text_field( wp_unslash( $_POST['model'] ) ) : ''; $embedding = isset( $_POST['embedding_model'] ) ? sanitize_text_field( wp_unslash( $_POST['embedding_model'] ) ) : ''; if ( '' === $model || ! class_exists( 'AI_eShop_Chat_Model_Registry' ) ) { wp_send_json_error( array( 'message' => __( 'No model chosen.', 'ai-eshop-optimizer' ) ) ); } $registry = AI_eShop_Chat_Model_Registry::get_instance(); if ( ! $registry->is_valid_model( $model, 'anthropic' ) ) { wp_send_json_error( array( 'message' => __( 'That model is not in the registry. Refresh AI Models and choose again.', 'ai-eshop-optimizer' ) ) ); } $current_embedding = (string) get_option( 'aieo_chat_embedding_model', '' ); if ( '' !== $embedding && $embedding !== $current_embedding && ! $registry->is_valid_model( $embedding, 'voyage' ) ) { wp_send_json_error( array( 'message' => __( 'That embedding model is not in the registry. Refresh AI Models and choose again.', 'ai-eshop-optimizer' ) ) ); } update_option( 'aieo_chat_model', $model ); if ( '' !== $embedding && $embedding !== $current_embedding ) { update_option( 'aieo_chat_embedding_model', $embedding ); update_option( 'aieo_embedding_provider', 'voyage' ); delete_transient( 'aieo_embedding_engine_counts' ); } wp_send_json_success( array( 'model' => $model, 'embedding_model' => '' !== $embedding ? $embedding : $current_embedding, 'message' => __( 'Models saved.', 'ai-eshop-optimizer' ), ) ); } public function render_subtab() { rooster_admin_band_open(array('cols' => 1)); if (!self::is_aieo_pro_user()) { $this->render_benefits(); } $this->render_template('subscription.php'); rooster_admin_band_close(); } protected function render_benefits() { $groups = $this->promos_by_group(); if (empty($groups)) { return; } $screens = 0; foreach ($groups as $g) { $screens += count($g['items']); } $aieo_pb_intro = sprintf( _n( '%1$d more admin screen, and the trial is free for 14 days. Rooster One Pro is %2$s after that, AI credits included.', '%1$d more admin screens, and the trial is free for 14 days. Rooster One Pro is %2$s after that, AI credits included.', $screens, 'ai-eshop-optimizer' ), (int) $screens, self::price_label() ) . ' ' . __('Everything already unlocked on this site stays free forever, with or without a subscription.', 'ai-eshop-optimizer'); $aieo_pb_footer = \Rooster\Admin\Ui::button( __('See pricing and subscribe', 'ai-eshop-optimizer'), array('variant' => 'primary', 'href' => 'https://rooster.systems/get-rooster-one/', 'external' => true) ); if (!self::is_connected()) { $aieo_pb_footer .= ' ' . esc_html__('or start the free 14-day trial below', 'ai-eshop-optimizer') . ''; } list($open, $close) = AIEO_DMM_UI::card(array( 'anchor' => 'pro-benefits', 'icon' => 'sparkles', 'title' => __('What Pro adds', 'ai-eshop-optimizer'), 'description' => $aieo_pb_intro, 'class' => 'aieo-pro-benefits', 'footer' => $aieo_pb_footer, )); echo $open; foreach ($groups as $g) { echo rooster_admin_card_section_html( (string) $g['label'], array('id' => 'aieo-section-pro-benefits-' . sanitize_title((string) $g['label'])) ); $aieo_pb_facts = array(); foreach ($g['items'] as $item) { $aieo_pb_text = '' !== $item['question'] ? $item['question'] : $item['description']; if (!empty($item['second_download'])) { $aieo_pb_text = trim($aieo_pb_text . ' ' . __('Ships in the separate Rooster One Pro plugin, included as a second download.', 'ai-eshop-optimizer')); } $aieo_pb_facts[] = array('label' => (string) $item['title'], 'value' => $aieo_pb_text); } echo \Rooster\Admin\Ui::facts($aieo_pb_facts, array('columns' => 2)); } $this->render_registry_line(); echo $close; } protected function promos_by_group() { if (!class_exists('AIEO_DMM')) { return array(); } $dmm = AIEO_DMM::instance(); $order = array(); $labels = array(); $i = 0; foreach ($dmm->get_group_definitions() as $g) { if (empty($g['id'])) { continue; } $labels[$g['id']] = isset($g['label']) ? (string) $g['label'] : (string) $g['id']; $order[$g['id']] = isset($g['priority']) ? (int) $g['priority'] : (1000 + $i); $i++; } $out = array(); foreach ($dmm->get_modules() as $mod) { if (!method_exists($mod, 'is_pro_locked') || !$mod->is_pro_locked()) { continue; } if (method_exists($mod, 'is_available') && !$mod->is_available()) { continue; } $promo = method_exists($mod, 'get_pro_promo') ? (array) $mod->get_pro_promo() : array(); $title = !empty($promo['title']) ? (string) $promo['title'] : (string) $mod->get_label(); $desc = !empty($promo['description']) ? (string) $promo['description'] : ''; $question = ''; if (class_exists('AIEO_Pro_Question') && method_exists($mod, 'pro_question_id')) { $question = (string) AIEO_Pro_Question::for_id($mod->pro_question_id()); } if ('' !== $question && '' !== $desc) { $desc = ''; } $gid = method_exists($mod, 'get_group') ? (string) $mod->get_group() : ''; $gid = $dmm->resolve_group_alias($gid); if ('' === $gid || !isset($labels[$gid])) { $gid = '_other'; $labels[$gid] = __('Everything else', 'ai-eshop-optimizer'); $order[$gid] = 9999; } if (!isset($out[$gid])) { $out[$gid] = array('label' => $labels[$gid], 'priority' => $order[$gid], 'items' => array()); } $out[$gid]['items'][] = array( 'title' => $title, 'description' => $desc, 'question' => $question, 'second_download' => method_exists($mod, 'requires_pro_plugin') && $mod->requires_pro_plugin(), 'priority' => method_exists($mod, 'get_priority') ? (int) $mod->get_priority() : 100, ); } uasort($out, static function ($a, $b) { return $a['priority'] <=> $b['priority']; }); foreach ($out as $gid => $g) { usort($out[$gid]['items'], static function ($a, $b) { return $a['priority'] === $b['priority'] ? strcmp($a['title'], $b['title']) : ($a['priority'] <=> $b['priority']); }); } return $out; } protected function render_registry_line() { if (!class_exists('AIEO_Capability_Registry')) { return; } $stats = (array) AIEO_Capability_Registry::stats(); if (!isset($stats['total'], $stats['pro'], $stats['free'], $stats['unclassified'])) { return; } if ((int) $stats['unclassified'] > 0 || (int) $stats['total'] < 1) { return; } echo '

' . esc_html(sprintf( __('Counted on this install: %1$d of the %2$d things Rooster One can do are free and stay free. The rest are what a subscription unlocks.', 'ai-eshop-optimizer'), (int) $stats['free'], (int) $stats['total'] )) . '

'; } public static function page_url($anchor = '') { if (class_exists('AIEO_Install_Status')) { return AIEO_Install_Status::panel_url($anchor); } return admin_url('admin.php?page=' . AIEO_DMM::MENU_SLUG . '&dmm_tab=subscription'); } }