将Wordpress“网站标题”功能放在“主题选项”页面中


Place Wordpress "Site Title" function within "Theme Options" page

我在Wordpress中创建了一个"主题选项.php"页面,可以在WP API"外观"设置菜单下找到。 在此页面上,我想包括"设置>常规选项"页面("网站标题"和"标语/副标题")中的两件事,可以在此处(在我的主题选项页面上)进行编辑并保存。

我该如何实现这一目标? 到目前为止,我有这个,它显示了所需的框和信息,但没有正确保存/更新。 我错过了什么?

主题选项.php

// Build our Page
function build_options_page() {
// Page Structure
   ob_start(); ?>
     <div class="wrap">
       <?php screen_icon();?>
       <h2>Theme Options</h2>
       <p><b><label for="blogname"><?php _e('Site Title') ?></label></b></p>
       <p><input name="blogname" type="text" id="blogname" value="<?php form_option('blogname'); ?>" class="regular-text" />  
       <span class="description"><?php _e('The name of your site.') ?></span></p> 
       <br />
       <p><b><label for="blogdescription"><?php _e('Tagline or Subheading') ?></label></b></p>
       <p><input name="blogdescription" type="text" id="blogdescription"  value="<?php form_option('blogdescription'); ?>" class="regular-text" /> 
       <span class="description"><?php _e('A brief description of your site.') ?></span></p> 
       <p class="submit">
       <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" />
       </p>
     </div>
   <?php
   echo ob_get_clean();
   ?>
}

此示例使用配置文件页面来显示和修改blognameblogdescription,但移植到代码中应该非常简单。

add_action( 'show_user_profile', 'show_extra_profile_fields', 1 );
add_action( 'edit_user_profile', 'show_extra_profile_fields', 1 );
function show_extra_profile_fields( $user ) { 
    ?>
    <table class="form-table">  
        <tr>
            <th><label for="user_address">Site Title</label></th>
            <td>
                <input type="text" name="blogname" id="blogname" value="<?php echo esc_attr( get_option('blogname') ); ?>" class="regular-text" /><br />
                <span class="description"></span>
            </td>
        </tr>
        <tr>
            <th><label for="user_zip">Tagline</label></th>
            <td>
                <input type="text" name="blogdescription" id="blogdescription" value="<?php echo esc_attr( get_option( 'blogdescription' ) ); ?>" class="regular-text" /><br />
                <span class="description"></span>
            </td>
        </tr>       
    </table>
    <?php 
}
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;
    update_option( 'blogname', $_POST['blogname'] );
    update_option( 'blogdescription', $_POST['blogdescription'] );
}