为什么 WP 将我的两个选项页面的内容合并在一起?

Why does WP merge together the content of my two option pages?

我想要一个名为 "Taux de change" 的仪表板选项页面和一个名为 "Telephone" 的单独页面。这段代码应该可以做到这一点,但由于某种原因,将我的两个页面的内容组合在一个页面中(尽管我对两个选项页面使用了不同的函数名称):

add_action('admin_menu', 'add_global_custom_options');
function add_global_custom_options()
{
    add_menu_page('Taux de change', 'Taux de change', 'manage_options', 'functions','global_custom_options','', 83);
}
function global_custom_options()
{
?>
    <div class="wrap">
        <h2>Taux de change</h2>
        <form method="post" action="options.php">
            <?php wp_nonce_field('update-options') ?>
            <p>
                <strong>USD to EU:</strong><br />
                <input type="text" name="usd_to_eu" size="15" value="<?php echo get_option('usd_to_eu'); ?>" />
                <br /><br />
                <strong>USD to CAD:</strong><br />
                <input type="text" name="usd_to_cad" size="15" value="<?php echo get_option('usd_to_cad'); ?>" />
                <br /><br />
                <strong>USD to GBP:</strong><br />
                <input type="text" name="usd_to_gbp" size="15" value="<?php echo get_option('usd_to_gbp'); ?>" />
            </p>
            <p><input type="submit" name="Submit" value="OK" /></p>
            <input type="hidden" name="action" value="update" />
            <input type="hidden" name="page_options" value="usd_to_eu,usd_to_cad,usd_to_gbp" />
        </form>
    </div>
<?php
}

add_action('admin_menu', 'add_global_custom_options2');
function add_global_custom_options2()
{
    add_menu_page('Téléphone', 'Téléphone', 'manage_options', 'functions','global_custom_options2','', 84);
}
function global_custom_options2()
{
?>
    <div class="wrap">
        <h2>Numéro de téléphone</h2>
        <form method="post" action="options.php">
            <?php wp_nonce_field('update-options') ?>
            <p>
                <strong>Numéro de téléphone:</strong><br />
                <input type="text" name="telephone" size="15" value="<?php echo get_option('telephone'); ?>" />
                <br /><br />
            </p>
            <p><input type="submit" name="Submit" value="OK" /></p>
            <input type="hidden" name="action" value="update" />
            <input type="hidden" name="page_options" value="telephone" />
        </form>
    </div>
<?php
}

我做错了什么?

add_menu_page()的第四个参数$menu_slug应该是唯一的。您正在为这两个实例使用 functions

https://codex.wordpress.org/Function_Reference/add_menu_page

您可能需要注册不同的设置组。

add_action('admin_menu', 'add_global_custom_options');
function add_global_custom_options()
{
    add_menu_page('Taux de change', 'Taux de change', 'manage_options', 'functions','global_custom_options','', 83);
    //hook into the custom settings function
    add_action( 'admin_init', 'register_custom_options' );
}
// register the settings needed
function register_custom_options() {
     register_setting( 'custom_options_settings1', 'usd_to_eu' );
     register_setting( 'custom_options_settings1', 'usd_to_cad' );;
     register_setting( 'custom_options_settings1', 'usd_to_cad' );
}
function global_custom_options()
{
?>
    <div class="wrap">
        <h2>Taux de change</h2>
        <form method="post" action="options.php">
            //replace the default nonce with your custom settings fields here
            <?php settings_fields( 'custom_options_settings1' ); ?>
            <p>
                <strong>USD to EU:</strong><br />
                <input type="text" name="usd_to_eu" size="15" value="<?php echo get_option('usd_to_eu'); ?>" />
                <br /><br />
                <strong>USD to CAD:</strong><br />
                <input type="text" name="usd_to_cad" size="15" value="<?php echo get_option('usd_to_cad'); ?>" />
                <br /><br />
                <strong>USD to GBP:</strong><br />
                <input type="text" name="usd_to_gbp" size="15" value="<?php echo get_option('usd_to_gbp'); ?>" />
            </p>
            <p><input type="submit" name="Submit" value="OK" /></p>
            <input type="hidden" name="action" value="update" />
            <input type="hidden" name="page_options" value="usd_to_eu,usd_to_cad,usd_to_gbp" />
        </form>
    </div>
<?php
}

add_action('admin_menu', 'add_global_custom_options2');
function add_global_custom_options2()
{
    add_menu_page('Téléphone', 'Téléphone', 'manage_options', 'functions','global_custom_options2','', 84);
    add_action( 'admin_init', 'register_custom_options2' );
}
// register the settings needed
function register_custom_options2() {
     register_setting( 'custom_options_settings2', 'telephone' );
}
function global_custom_options2()
{
?>
    <div class="wrap">
        <h2>Numéro de téléphone</h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'custom_options_settings2' ); ?>
            <p>
                <strong>Numéro de téléphone:</strong><br />
                <input type="text" name="telephone" size="15" value="<?php echo get_option('telephone'); ?>" />
                <br /><br />
            </p>
            <p><input type="submit" name="Submit" value="OK" /></p>
            <input type="hidden" name="action" value="update" />
            <input type="hidden" name="page_options" value="telephone" />
        </form>
    </div>
<?php
}

有关详细信息,请参阅 WP 法典:http://codex.wordpress.org/Creating_Options_Pages

基本上,您需要注册不同的选项集以将它们拆分到多个页面上,否则据我所知它将默认将它们全部放在一页上。希望这对你有用。