定制器不保存图像设置

时间:2018-08-16 作者:user2265915

我在customizer中创建了一个图像控件。它显示字段,我可以上载/选择图像。但是,如果我发布并离开customizer,我可以看到它不会保存图像。我的所有文本/文本区域字段都工作正常。我使用下划线作为基本主题。

这是我的定制器中有问题的字段。php:

...
function minisite_customize_register( $wp_customize ) {
$wp_customize->get_setting( \'blogname\' )->transport         = \'postMessage\';
$wp_customize->get_setting( \'blogdescription\' )->transport  = \'postMessage\';
$wp_customize->get_setting( \'header_textcolor\' )->transport = \'postMessage\';

// Add Footer Logo Setting
$wp_customize->add_setting( \'footer_logo\',
   array(
      \'default\' => \'\',
      \'transport\' => \'refresh\',
      \'sanitize_callback\' => \'absint\'
   )
);

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, \'footer_logo\',
   array(
      \'label\' => __( \'Footer Logo\' ),
      \'description\' => esc_html__( \'Choose a footer logo.\' ),
      \'section\' => \'title_tagline\',
   )
) );
...
在我的页脚中。php我正在使用它进行测试(但当我返回到customizer时,我也可以看到空的图像字段):

<?php
$footerlogo = get_theme_mod(\'footer_logo\');
if( !empty($footerlogo) )
{
    echo \'yes\';
} else {
    echo \'no\';
}
?>
我遵循本教程获取customizer中的图像字段:https://maddisondesigns.com/2017/05/the-wordpress-customizer-a-developers-guide-part-1#imagecontrol

我错过什么了吗?

1 个回复
最合适的回答,由SO网友:curious_curious 整理而成

问题在于sanitize_callback = \'absint\'.

WP_Customize_Image_Control 不保存附件id,因此无法使用absint, 如果要存储图像附件的ID,请使用WP_Customize_Media_Control, 这方面也有参考here

结束

相关推荐