我创建了一个自定义主题选项页面, 该页面很好并且在后端可见。我希望用户能够通过theme-options输入和保存url值。然后, 我将直接将其关联变量分配给标记, 以动态填充href值。
目前, 尝试保存更改时遇到问题。希望有人能够帮助我。谢谢你的时间。
<?php
function theme_settings_page()
{
?>
<div class="wrap">
<?php if (function_exists('the_custom_logo')) {
the_custom_logo();
}
else{
bloginfo('name');
}
?>
<h1>THEME OPTIONS</h1>
<p>The theme options panel allows you to directly control the output for some of the key features of your website.</p>
<p><i>Author: </i></p>
<p><i>Date: 06/05/18 | Version 1.0 </i></p>
<p><i>Website: </i></p>
<hr>
<h3>Social Connections</h3>
<p>Easily connect directly to your social profiles by providing the full absolute URL to your social account profile.</p>
<p>Example:<i><span> "https://facebook.com/yourprofile"</span></i></p>
<table>
<tr align="left" valign="middle">
<th scope="row"><?php _e( 'Facebook', 'customtheme' ); ?></th>
<td><input id="sample_theme_options[fburl]" type="text" name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['fburl'] ); ?>" /></td>
</tr>
<tr align="left" valign="middle">
<th scope="row"><?php _e( 'Google Plus', 'customtheme' ); ?></th>
<td><input id="sample_theme_options[gpurl]" type="text" name="sample_theme_options[gpurl]" value="<?php esc_attr_e( $options['gpurl'] ); ?>" /></td>
</tr>
<tr align="left" valign="middle">
<th scope="row"><?php _e( 'Instagram', 'customtheme' ); ?></th>
<td><input id="sample_theme_options[inurl]" type="text" name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['inurl'] ); ?>" /></td>
</tr>
<tr align="left" valign="middle">
<th scope="row"><?php _e( 'LinkedIn', 'customtheme' ); ?></th>
<td><input id="sample_theme_options[liurl]" type="text" name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['liurl'] ); ?>" /></td>
</tr>
<tr align="left" valign="middle">
<th scope="row"><?php _e( 'Twitter', 'customtheme' ); ?></th>
<td><input id="sample_theme_options[twurl]" type="text" name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['twurl'] ); ?>" /></td>
</tr>
<tr align="left" valign="middle">
<th scope="row"><?php _e( 'Youtube', 'customtheme' ); ?></th>
<td><input id="sample_theme_options[yturl]" type="text" name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['yturl'] ); ?>" /></td>
</tr>
</table>
<form method="post" action="options.php">
<?php
settings_fields("options");
do_settings_sections("theme-options");
submit_button();
?>
</form>
</div>
<?php
}
/**
Add Theme Options To Admin Side Menu **/
function add_theme_menu_item()
{
add_menu_page("Theme Options", "Theme Options", "manage_options", "theme-panel", "theme_settings_page", null, 60);
}
add_action("admin_menu", "add_theme_menu_item")
?>
#1
WordPress具有新的Options API, 可以管理所有这些选项页面和设置以及更多其他内容。
此处的Wordpress Options API的完整示例:https://codex.wordpress.org/Creating_Options_Pages
#2
你已经在表单中使用了设置字段。为此, 你必须先注册设置。有关设置, 请参阅:https://codex.wordpress.org/Settings_API
否则, 这里是分步指南:https://codex.wordpress.org/Creating_Options_Pages https://wisdmlabs.com/blog/create-settings-options-page-for-wordpress-plugin/
来源:
https://www.srcmini02.com/65796.html