' . __( 'Settings', 'ai-agent' ) . '', '' . __( 'Docs', 'ai-agent' ) . '', '' . __( 'Support', 'ai-agent' ) . '', ); return array_merge( $custom_links, $links ); } ); // WP Admin code related. require_once plugin_dir_path( __FILE__ ) . 'components/admin.php'; // Regiseter Public rest api. require_once plugin_dir_path( __FILE__ ) . 'components/public.php'; // Triggered when the plugin is activated. register_activation_hook( __FILE__, 'rwpai_on_plugin_activate' ); /** * Runs on plugin activation. * * Sets a flag that will be used to determine if a redirect should * occur immediately after the plugin is activated. */ function rwpai_on_plugin_activate() { // Set a flag so we know to redirect after activation. add_option( 'rwpai_do_activation_redirect', true ); if ( function_exists( 'rwpai_ensure_mcp_settings' ) ) { rwpai_ensure_mcp_settings(); } } /** * Redirects to the plugin settings page after activation. * * Checks if the activation redirect flag is set and redirects * to the plugin settings page if it is. Then deletes the flag * to prevent future redirects. */ function rwpai_redirect_after_activation() { // Check if we should redirect after activation. if ( get_option( 'rwpai_do_activation_redirect', false ) ) { // Delete the flag so we don't redirect again. delete_option( 'rwpai_do_activation_redirect' ); // Only redirect if we're not already on the settings page. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Activation redirect, no nonce available during plugin activation. if ( ! isset( $_GET['activate-multi'] ) ) { wp_safe_redirect( admin_url( 'admin.php?page=' . RWPAI_MENU_SLUG ) ); exit; } } } // Check the flag on the next admin load and redirect. add_action( 'admin_init', 'rwpai_redirect_after_activation' );