该框架提供了一个过滤器,用于验证optionsframework_validate
功能<仅供参考,以下是文件中的相关部分wp-content/themes/your-theme/inc/options-framework.php
:
/**
* Validate Options.
*
* This runs after the submit/reset button has been clicked and
* validates the inputs.
*/
function optionsframework_validate( $input ) {
/* code */
$clean[$id] = apply_filters( \'of_sanitize_\' . $option[\'type\'], $input[$id], $option );
/* code */
因此,考虑到我们在文件中有以下选项
wp-content/themes/your-theme/options.php
:
$options[] = array(
\'name\' => __(\'Input Text Mini\', \'options_framework_theme\'),
\'desc\' => __(\'A mini text input field.\', \'options_framework_theme\'),
\'id\' => \'blogname\',
\'std\' => \'Default\',
\'class\' => \'mini\',
\'type\' => \'text\');
$options[] = array(
\'name\' => __(\'Input Text\', \'options_framework_theme\'),
\'desc\' => __(\'A text input field.\', \'options_framework_theme\'),
\'id\' => \'blogdescription\',
\'std\' => \'Default Value\',
\'type\' => \'text\');
并且在
wp-content/themes/your-theme/functions.php
, 我们过滤
text
输入类型(
of_sanitize_
+ text
)以及它是否与我们定义的ID匹配(
blogname
和
blogdescription
, 就像在常规设置中一样,它将更新具有相同id的站点选项。
请注意,这不是另一种方式:在Settings -> General
不会反映在主题选项页面中
add_filter( \'of_sanitize_text\', \'wpse_77233_framework_to_settings\', 10, 2 );
function wpse_77233_framework_to_settings( $input, $option )
{
if( \'blogname\' == $option[\'id\'] )
update_option( \'blogname\', sanitize_text_field( $input ) );
if( \'blogdescription\' == $option[\'id\'] )
update_option( \'blogdescription\', sanitize_text_field( $input ) );
return $input;
}