1. Go to this page and download the library: Download acrossai-co/main-menu library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
acrossai-co / main-menu example snippets
add_action( 'plugins_loaded', function () {
new \AcrossAI_Main_Menu\SettingsPage();
} );
add_action( 'admin_init', function () {
// 1. Register each option you want saved.
register_setting(
'acrossai-settings', // option_group — must match the page slug
'plugin_a_api_key', // option_name
[
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
]
);
// 2. Add a section to the shared page.
add_settings_section(
'plugin_a_section',
__( 'Plugin A', 'plugin-a' ),
function () {
echo '<p>' . esc_html__( 'Plugin A configuration.', 'plugin-a' ) . '</p>';
},
'acrossai-settings' // page slug
);
// 3. Add fields to that section.
add_settings_field(
'plugin_a_api_key',
__( 'API Key', 'plugin-a' ),
function () {
printf(
'<input type="text" name="plugin_a_api_key" value="%s" class="regular-text" />',
esc_attr( get_option( 'plugin_a_api_key', '' ) )
);
},
'acrossai-settings', // page slug
'plugin_a_section' // section id from step 2
);
} );
use AcrossAI_Main_Menu\TabbedPageRenderer;
final class ToolsPageRenderer extends TabbedPageRenderer {
protected function get_page_slug(): string { return 'acrossai-tools'; }
protected function get_tabs_key(): string { return 'tools'; }
}
// Register the submenu and point it at the renderer:
add_action( 'admin_menu', function () {
$renderer = new ToolsPageRenderer();
add_submenu_page(
\AcrossAI_Main_Menu\SettingsPage::PARENT_SLUG,
__( 'Tools', 'my-plugin' ),
__( 'Tools', 'my-plugin' ),
'manage_options',
'acrossai-tools',
[ $renderer, 'render' ]
);
} );
use AcrossAI_Main_Menu\Tabs;
final class ReportTabs extends Tabs {
protected function get_tabs_key(): string { return 'reports'; }
}
// Third-party plugins contribute tabs via `acrossai_reports_tabs`.
// Anywhere in the admin (custom `add_menu_page` callback, meta box, …):
$tabs_ui = new ReportTabs();
$tabs = $tabs_ui->get_tabs();
if ( ! empty( $tabs ) ) {
$active = $tabs_ui->get_active_tab( $tabs );
$tabs_ui->render_tab_nav( $tabs, $active['slug'] );
// Render the body for $active['slug'] however you like — no form
add_filter( 'acrossai_notices', function ( array $notices ): array {
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
$notices[] = [
'id' => 'my_plugin_wp_cron_disabled', // 'type' => 'warning', // error | warning | info | success (default: warning)
'source' => 'My Plugin', // optional label shown on the notice card
'action' => [ // optional CTA — rendered as a purple button on the card
'label' => __( 'Read the docs', 'my-plugin' ),
'url' => 'https://developer.wordpress.org/plugins/cron/',
],
];
}
return $notices;
} );