addon_manager = $addon_manager; add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); add_action( 'admin_menu', array( $this, 'reorder_submenus' ), 9999 ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); } /** * 添加管理菜单 */ public function add_admin_menu() { // 添加顶级菜单 "AI Generator" add_menu_page( __( 'AI Generator', 'wpthemoon' ), // 页面标题 __( 'AI Generator', 'wpthemoon' ), // 菜单标题 'edit_posts', // 权限要求 'wpthemoon-ai-generator', // 菜单slug array( $this, 'render_batch_generator_page' ), // 回调函数 'dashicons-edit-large', // 图标 30 // 位置 ); // 添加子菜单 "Batch Generator" add_submenu_page( 'wpthemoon-ai-generator', // 父菜单slug __( 'Batch Generator', 'wpthemoon' ), // 页面标题 __( 'Batch Generator', 'wpthemoon' ), // 菜单标题 'edit_posts', // 权限要求 'wpthemoon-ai-generator', // 菜单slug (与父菜单相同,作为默认页面) array( $this, 'render_batch_generator_page' ) // 回调函数 ); // 添加子菜单 "Addons" add_submenu_page( 'wpthemoon-ai-generator', __( 'Addons', 'wpthemoon' ), __( 'Addons', 'wpthemoon' ), 'manage_options', 'wpthemoon-addons', array( $this, 'render_addons_page' ) ); // 添加子菜单 "Settings" add_submenu_page( 'wpthemoon-ai-generator', // 父菜单slug __( 'Settings', 'wpthemoon' ), // 页面标题 __( 'Settings', 'wpthemoon' ), // 菜单标题 'manage_options', // 权限要求 'wpthemoon-settings', // 菜单slug array( $this, 'render_settings_page' ) // 回调函数 ); } /** * 加载管理页面资源 */ public function enqueue_admin_assets( $hook ) { // 只在我们的管理页面加载资源 if ( strpos( $hook, 'wpthemoon' ) === false ) { return; } // 加载批量生成器页面的资源 if ( $hook === 'toplevel_page_wpthemoon-ai-generator' ) { $asset_file = include( WPTHEMOON_PATH . 'build/batch-generator.asset.php' ); wp_enqueue_script( 'wpthemoon-batch-generator', WPTHEMOON_URL . 'build/batch-generator.js', $asset_file['dependencies'], $asset_file['version'], true ); wp_enqueue_style( 'wpthemoon-batch-generator-style', WPTHEMOON_URL . 'build/batch-generator.css', array(), $asset_file['version'] ); // 注入 REST API 配置 wp_localize_script( 'wpthemoon-batch-generator', 'wpthemoonApi', array( 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ) ) ); // 加载翻译 wp_set_script_translations( 'wpthemoon-batch-generator', 'wpthemoon' ); } } /** * 渲染批量生成器页面 */ public function render_batch_generator_page() { ?>
get_name() ); ?> |
get_description() ); ?> | get_version() ); ?> |
|