选项面板Wordpress

时间:2013-12-27 17:12:18

标签: wordpress

你好我编码一个主题,它很难编辑 我创建了一个主题选项面板 但我有一个问题。 问题是,当我添加一些值并更新其工作,如果我去主题选项面板值休息。 这是代码。

    <?php 
    if(get_option('cms_theme_go')){ 
    $theme_options = get_option('cms_theme_go'); 
    }else{ 
    add_option('cms_theme_go', array('lessons' => 'lessons' 
    )); 
    $theme_options = get_option('cms_theme_go'); }
    add_action('admin_menu', 'theme_page_add'); 
    function theme_page_add(){ 
    add_submenu_page('themes.php', 'Theme Options', 'Theme Options', 8, 'themeoptions', 'theme_page_options'); } 
    function theme_page_options(){ 
    global $theme_options; 
    $new_values = array( 
    'gold' => htmlentities($_POST['gold'], ENT_QUOTES), 
    'news' => htmlentities($_POST['news'], ENT_QUOTES), 
    'lessons' => htmlentities($_POST['lessons'], ENT_QUOTES) 
    ); 
    update_option('cms_theme_go', $new_values); 
    $theme_options = $new_values; 
    echo '<center><div class="wrap">'; 
    echo '<h2>~Theme Options~</h2><br><br>'; 
    ?> 
    <form action="themes.php?page=themeoptions" method="post"> 
    <b>Gold Category ID</b>  
    <br> 
    <input type="text" size="30" value="<?php echo $theme_options['gold']; ?>" name="gold" > 
    <br> 
    <br> 
    <b>News Category ID</b>  
    <br> 
    <input type="text" size="30" value="<?php echo $theme_options['news']; ?>" name="news" > 
    <br> 
    <br> 
    <b>Lessons Category ID</b>  
    <br> 
    <input type="text" size="30" value="<?php echo $theme_options['lessons']; ?>" name="lessons"> 
    <br> 
    <br> 
    <b></b>  
    <br> 
    <input type="submit" value="Update" name="submit" > 
    </form> 
    <?php 
    } 
    echo'</div></center>'; 
    ?>

我希望有人可以提供帮助

1 个答案:

答案 0 :(得分:0)

它应该,因为你的选项总是以一些未知的值保存。

替换这些行 -

$new_values = array( 
    'gold' => htmlentities($_POST['gold'], ENT_QUOTES), 
    'news' => htmlentities($_POST['news'], ENT_QUOTES), 
    'lessons' => htmlentities($_POST['lessons'], ENT_QUOTES) 
);
update_option('cms_theme_go', $new_values); 
$theme_options = $new_values; 

有了这些 -

if( isset($_POST['submit']) && 'Update' == $_POST['submit'] ){
    $new_values = array( 
        'gold' => htmlentities($_POST['gold'], ENT_QUOTES), 
        'news' => htmlentities($_POST['news'], ENT_QUOTES), 
        'lessons' => htmlentities($_POST['lessons'], ENT_QUOTES) 
    );
    update_option('cms_theme_go', $new_values); 
    $theme_options = $new_values;
}