保存 Wordpress 主题选项输入值
Saving Wordpress Theme Option Input Values
我已经创建了一个自定义的主题选项页面,它很好并且在后端可见。我希望用户能够通过主题选项输入和保存 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")
?>
Wordpress 有新的选项 API 来管理所有这些选项页面和设置等等。
此处为 Wordpress 选项 API 的完整示例:https://codex.wordpress.org/Creating_Options_Pages
您在表单中使用了设置字段。为此,您必须先注册您的设置。
设置请参考:
https://codex.wordpress.org/Settings_API
否则这里有一个分步指南:
https://codex.wordpress.org/Creating_Options_Pages
https://wisdmlabs.com/blog/create-settings-options-page-for-wordpress-plugin/
我已经创建了一个自定义的主题选项页面,它很好并且在后端可见。我希望用户能够通过主题选项输入和保存 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")
?>
Wordpress 有新的选项 API 来管理所有这些选项页面和设置等等。
此处为 Wordpress 选项 API 的完整示例:https://codex.wordpress.org/Creating_Options_Pages
您在表单中使用了设置字段。为此,您必须先注册您的设置。 设置请参考: https://codex.wordpress.org/Settings_API
否则这里有一个分步指南: https://codex.wordpress.org/Creating_Options_Pages https://wisdmlabs.com/blog/create-settings-options-page-for-wordpress-plugin/