Plugin Directory

Changeset 3372633


Ignore:
Timestamp:
10/03/2025 11:18:58 PM (6 months ago)
Author:
oc3dots
Message:

Fix menu items creation & conflict with other plugins.

Location:
oc3-semantic-box/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • oc3-semantic-box/trunk/lib/controllers/AdminConfigController.php

    r3263660 r3372633  
    1515       
    1616        public function __construct() {
    17            
     17
    1818            add_action('wp_ajax_oc3sb_store_general_tab', [$this, 'processSettingsSubmit']);
    1919            add_action('wp_ajax_oc3sb_gpt_conf_models', [$this, 'gptGetModels']);
     
    4040
    4141        // Ensure this is the correct page
    42         if ($current_screen->id !== 'toplevel_page_oc3semanticb_settings') {
     42        if ($current_screen->id !== 'oc3-semantic-box_page_oc3semanticb_settings') {
    4343            return;
    4444        }
    4545
    4646        // Enqueue a script as a placeholder
    47         wp_enqueue_script('oc3-semantic-box-config',OC3SEMANTICB_URL . '/views/resources/js/oc3-semantic-box-dummy.js', [], '1.0.0', true);
     47        wp_enqueue_script('oc3-semantic-box-config',OC3SEMANTICB_URL . '/views/resources/js/oc3-semanticbox-dummy.js', [], '1.0.0', true);
    4848    }
    4949
     
    5252
    5353        // Ensure this is the correct page
    54         if ($current_screen->id !== 'toplevel_page_oc3semanticb_settings') {
     54        if ($current_screen->id !== 'oc3-semantic-box_page_oc3semanticb_settings') {
    5555            return;
    5656        }
     
    7777            $current_screen = get_current_screen();
    7878
    79             if ($current_screen->id !== 'toplevel_page_oc3semanticb_settings') {
     79            if ($current_screen->id !== 'oc3-semantic-box_page_oc3semanticb_settings') {
    8080                return;
    8181            }
     
    227227        });"
    228228                    . "";
    229            
     229            //var_dump($inline_js);
     230            //die();
    230231            wp_add_inline_script('oc3-semantic-box-config', $inline_js);
    231232           
     
    514515
    515516            if (!Oc3Semanticb_Utils::checkEditInstructionAccess()) {
    516                 return;
    517             }
    518            
     517                //return;
     518            }
     519
    519520            $oc3semanticb_open_ai_gpt_key = get_option(OC3SEMANTICB_PREFIX_LOW . 'open_ai_gpt_key', '');
    520521            $oc3semanticb_pinecone_key = get_option(OC3SEMANTICB_PREFIX_LOW . 'opinecone_key', '');
  • oc3-semantic-box/trunk/lib/controllers/AdminController.php

    r3234031 r3372633  
    88        const ADMIN_MENU = OC3SEMANTICB_PREFIX_LOW . 'settings'; //
    99        const ADMIN_MENU_CALLBACK = null; //can be view file or some callback function
    10 
     10        const MENU_SLUG      = 'oc3semanticb';            // top-level menu slug
     11        const PAGE_SETTINGS  = 'oc3semanticb_settings';   // settings page slug
     12        const PAGE_SEARCH    = 'oc3semanticb_search';     // search page slug
     13       
    1114       
    1215        public $config_controller = false;
     
    9699        }
    97100
    98         public function registerAdminMenu() {
     101        public function registerAdminMenu()
     102    {
     103        // 1) Top-level menu (redirected to Settings)
     104        $top_hook = add_menu_page(
     105            __('OC3 Semantic Box', 'oc3-semantic-box'),
     106            __('OC3 Semantic Box', 'oc3-semantic-box'),
     107            'edit_posts',
     108            self::MENU_SLUG,
     109            '__return_null',
     110            $this->admlogo
     111        );
    99112
    100         add_menu_page('Settings',
    101         'OC3 Semantic Box',
    102                     'edit_posts', self::ADMIN_MENU, null,
    103                     $this->admlogo);
    104             $this->config_controller->registerAdminMenu();
    105            
    106             add_submenu_page(self::ADMIN_MENU, __('Search', 'oc3-semantic-box'),
    107                 __('Search', 'oc3-semantic-box'), 'edit_posts',
    108                OC3SEMANTICB_PREFIX_LOW . 'search', [$this->search_controller, 'showMainView']);
    109            
    110             if (!Oc3Semanticb_Utils::checkEditInstructionAccess()) {
    111                 return;
    112             }
    113            
    114            
     113        add_action('load-' . $top_hook, function () {
     114            $url = menu_page_url(self::PAGE_SETTINGS, false);
     115            if ($url) { wp_safe_redirect($url); exit; }
     116        });
     117
     118        // 2) SETTINGS submenu — REGISTER IT HERE so it always exists
     119        $settings_cb = [$this->config_controller, 'showSettings'];
     120        if (!is_callable($settings_cb)) {
     121            $settings_cb = function () {
     122                echo '<div class="wrap"><h1>Settings</h1><p>Settings view callback missing.</p></div>';
     123            };
    115124        }
     125
     126        $settings_hook = add_submenu_page(
     127            self::MENU_SLUG,
     128            __('Settings', 'oc3-semantic-box'),
     129            __('Settings', 'oc3-semantic-box'),
     130            'edit_posts',
     131            self::PAGE_SETTINGS,
     132            $settings_cb
     133        );
     134
     135        // Wire processing handler (lives in config controller)
     136        if (method_exists($this->config_controller, 'processSettingsSubmit')) {
     137            add_action('load-' . $settings_hook, [$this->config_controller, 'processSettingsSubmit']);
     138        }
     139
     140        // 3) SEARCH submenu
     141        $search_cb = [$this->search_controller, 'showMainView'];
     142        if (!is_callable($search_cb)) {
     143            $search_cb = function () {
     144                echo '<div class="wrap"><h1>Search</h1><p>Search view callback missing.</p></div>';
     145            };
     146        }
     147
     148        add_submenu_page(
     149            self::MENU_SLUG,
     150            __('Search', 'oc3-semantic-box'),
     151            __('Search', 'oc3-semantic-box'),
     152            'edit_posts',
     153            self::PAGE_SEARCH,
     154            $search_cb
     155        );
     156
     157        // 4) Remove WP’s auto “duplicate parent” submenu so "Settings" appears first
     158        add_action('admin_menu', function () {
     159            remove_submenu_page(self::MENU_SLUG, self::MENU_SLUG);
     160        }, 999);
     161    }
     162
     163
    116164
    117165        function showSettings() {
  • oc3-semantic-box/trunk/lib/controllers/AdminSearchController.php

    r3234031 r3372633  
    153153            }
    154154           
    155             wp_enqueue_script('oc3-semantic-box-search',OC3SEMANTICB_URL . '/views/resources/js/oc3-semantic-box-dummy.js', [], '1.0.0', true);
     155            wp_enqueue_script('oc3-semantic-box-search',OC3SEMANTICB_URL . '/views/resources/js/oc3-semanticbox-dummy.js', [], '1.0.0', true);
    156156
    157157            $inline_js = "const oc3sengineajaxAction = '".esc_url(admin_url('admin-ajax.php'))."';\n".
     
    181181        function showSearchSettings() {
    182182            if (!Oc3Semanticb_Utils::checkEditInstructionAccess()) {
    183                 return;
     183                //return;
    184184            }
    185185
  • oc3-semantic-box/trunk/lib/controllers/BaseController.php

    r3234031 r3372633  
    3838
    3939        public function render() {
     40
    4041            extract($this->view_vars, EXTR_SKIP);
    4142           
  • oc3-semantic-box/trunk/oc3-semantic-box.php

    r3263672 r3372633  
    88  Text Domain: oc3-semantic-box
    99  Domain Path: /lang
    10   Version: 1.0.4
     10  Version: 1.0.5
    1111  License:  GPL-2.0+
    1212  License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
  • oc3-semantic-box/trunk/readme.txt

    r3263672 r3372633  
    44Tags: AI, Semantic search, search, RAG, AI embedding
    55Requires at least: 5.6
    6 Tested up to: 6.7
     6Tested up to: 6.8
    77Requires PHP: 7.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    10 Stable tag: 1.0.4
     10Stable tag: 1.0.5
    1111
    1212Semantic search of website content with meaning...
     
    8787== Changelog ==
    8888
     89= 1.0.5 =
     90* Fix menu items creation & conflict with other  plugins
     91
    8992= 1.0.4 =
    9093* Fix readme
Note: See TracChangeset for help on using the changeset viewer.