Wordpress:默认选项页面值未显示

时间:2015-03-07 18:16:12

标签: php wordpress function admin

我不太确定,但是自定义表单的默认值没有显示。有任何想法吗?

是否与定位模板有关?

$blav_options_address = array(
    'street' => 'Street Address',
    'county' => 'County Address',
    'postcode' => 'Postcode',
);

function blavou_setup_address() {
    global $blav_options_address;
    if ( ! isset( $_REQUEST['updated'] ) )
        $_REQUEST['updated'] = false;
    ?>
    <?php if ( isset( $_GET['settings-updated'] ) ) {
        echo "<div class='updated'><p>Settings Saved. <a href='?page=blav-setup-social'>Continue Setup</a>.</p></div>";
    } ?>
    <?php locate_template( 'admin/templates/blav-setup-address.php', TRUE, TRUE ); ?>
    <?php
}


<div id="blav-wrapper">
<div class="blav-nav-wrapper">
    <h5 class="standard-title">Photographers Address</h5>
    <form method="post" action="options.php" class="standard-form">
    <?php $settings = get_option( 'blav_options_address', $blav_options_address ); ?>
    <?php settings_fields( 'blav_theme_options_address' );?>
        <input type="text" name="blav_options_address[street]" value="<?php esc_attr_e($settings['street']); ?>"/>
        <input type="text" name="blav_options_address[county]" value="<?php esc_attr_e($settings['county']); ?>"/>
        <input type="text" name="blav_options_address[postcode]" value="<?php esc_attr_e($settings['postcode']); ?>"/>
        <input type="submit" value="Save"></input>
    </form>
</div><!--end blav nav wrapper-->
</div><!--end blav-wrapper-->

1 个答案:

答案 0 :(得分:0)

我怀疑get_option()没有达到预期的效果。执行时:

$settings = get_option( 'blav_options_address', $blav_options_address );

然后唯一一次使用默认值($blav_options_address)是否找不到选项blav_options_address。如果该选项在数据库中,则无论是否具有正确的形式,都将使用返回的值,例如,如果它不是数组。如果它不是具有正确键的数组,那么当然不会为输入值显示任何内容。