【发布时间】:2017-05-04 18:01:44
【问题描述】:
我目前想要实现的是一些简单的主题选项。我想要做的是;
在 Wordpress GUI 下,我目前进行了一些设置(后面没有任何操作)的主题选项部分是简单地“单击一个复选框,它将禁用首页小部件,如果它打开则显示它们如果它关闭禁用它们”
我理解背后的逻辑,但我不知道如何创建一些东西会返回一个简单的真假,从theme-options.php,将它链接到front-page.php并使用来自的结果主题选项作为显示所述区域的条件。
对此的任何帮助都会令人惊叹。
<?php $options = get_option( 'SV_theme_options' ); ?>
<input id="SV_theme_options[option1]" name="SV_theme_options[option1]" type="checkbox" value="1" <?php checked( '1', $options['option1'] ); ?> />
/**
* Sanitize and validate input. Accepts an array, return a sanitized array.
*/
function theme_options_validate( $input ) {
global $select_options, $radio_options;
// Our checkbox value is either 0 or 1
if ( ! isset( $input['option1'] ) )
$input['option1'] = null;
$input['option1'] = ( $input['option1'] == 1 ? 1 : 0 );
// Say our text option must be safe text with no HTML tags
$input['sometext'] = wp_filter_nohtml_kses( $input['sometext'] );
// Our select option must actually be in our array of select options
if ( ! array_key_exists( $input['selectinput'], $select_options ) )
$input['selectinput'] = null;
// Our radio option must actually be in our array of radio options
if ( ! isset( $input['radioinput'] ) )
$input['radioinput'] = null;
if ( ! array_key_exists( $input['radioinput'], $radio_options ) )
$input['radioinput'] = null;
// Say our textarea option must be safe text with the allowed tags for posts
$input['sometextarea'] = wp_filter_post_kses( $input['sometextarea'] );
return $input;
}
同样在 front-page.php 中,我已经为这个文件设置了 required_once,尝试通过以下方式调用:
echo theme_options_validate( $input['option1' );
但是我得到的只是返回的单词 Array。
问候, 本
【问题讨论】: