user_email; // Save email contact for auth. update_option( RWPAI_WEB_EMAIL, $user_email ); // Globalize the script variables. wp_localize_script( $handle, RWPAI_JS_GLOBAL_VAR, array( 'nonce_admin' => rwpai_nonce_create( RWPAI_NONCE_NAME_ADMIN ), 'nonce_public' => rwpai_nonce_create( RWPAI_NONCE_NAME_PUBLIC ), 'site_url' => get_site_url(), 'site_lang' => get_locale(), 'site_langs' => rwpai_get_all_languages(), 'credential' => rwpai_get_credential(), 'assets_url' => plugins_url( 'public', RWPAI_PLUGIN_MAIN_FILE ), 'email' => $user_email, 'name' => $current_user->display_name ?? $current_user->user_login, ) ); } add_action( 'admin_enqueue_scripts', 'rwpai_enqueue_admin_scripts' ); /** * Adds the Reinvent WP AI Agent settings page to the admin menu. */ function rwpai_add_admin_menu() { add_menu_page( esc_html__( 'Reinvent WP AI Agent Settings', 'ai-agent' ), esc_html__( 'Reinvent WP AI Agent', 'ai-agent' ), 'manage_options', RWPAI_MENU_SLUG, 'rwpai_render_admin_page', 'dashicons-star-filled', 30 ); } add_action( 'admin_menu', 'rwpai_add_admin_menu' ); /** * Renders the admin page for the plugin. */ function rwpai_render_admin_page() { echo '
'; } /** * Get all available language codes for this WordPress site. * * Works with: * - Polylang. * - WPML. * - TranslatePress. * - Default WordPress (site language only). * * @return array List of language codes. */ function rwpai_get_all_languages() { $langs = array(); // Polylang. if ( function_exists( 'pll_get_the_languages' ) && is_callable( 'pll_get_the_languages' ) ) { $languages = call_user_func( 'pll_get_the_languages', array( 'raw' => 1 ) ); if ( ! empty( $languages ) ) { $langs = array_keys( $languages ); } } elseif ( function_exists( 'apply_filters' ) && has_filter( 'wpml_active_languages' ) ) { // WPML. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook $languages = apply_filters( 'wpml_active_languages', null, array() ); if ( ! empty( $languages ) && is_array( $languages ) ) { $langs = array_keys( $languages ); } } elseif ( function_exists( 'get_option' ) ) { // TranslatePress. $trp_settings = get_option( 'trp_settings', array() ); if ( isset( $trp_settings['publish-languages'] ) ) { $langs = array_keys( $trp_settings['publish-languages'] ); } } // Fallback: WordPress site language. if ( empty( $langs ) ) { $langs = array( get_bloginfo( 'language' ) ); } return $langs; }