Wordpress:PHP 警告:sprintf():参数太少

Wordpress : PHP Warning: sprintf(): Too few arguments

我有这个警告:

PHP Warning:  sprintf(): Too few arguments in /var/www/wordpress/wp-includes/widgets.php on line 1193

这是widgets.php中引用的函数:

function the_widget( $widget, $instance = array(), $args = array() ) {
    global $wp_widget_factory;

    if ( ! isset( $wp_widget_factory->widgets[ $widget ] ) ) {
        _doing_it_wrong(
            __FUNCTION__,
            sprintf(
                /* translators: %s: register_widget() */
                __( 'Widgets need to be registered using %s, before they can be displayed.' ),
                '<code>register_widget()</code>'
            ),
            '4.9.0'
        );
        return;
    }

    $widget_obj = $wp_widget_factory->widgets[ $widget ];
    if ( ! ( $widget_obj instanceof WP_Widget ) ) {
        return;
    }

    $default_args          = array(
        'before_widget' => '<div class="widget %s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>',
    );
    $args                  = wp_parse_args( $args, $default_args );
    $args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] );
    
    $instance = wp_parse_args( $instance );

    /** This filter is documented in wp-includes/class-wp-widget.php */
    $instance = apply_filters( 'widget_display_callback', $instance, $widget_obj, $args );

    if ( false === $instance ) {
        return;
    }

widget.php 的第 1193 行是:

$args['before_widget'] = sprintf($args['before_widget'],$widget_obj->widget_options['classname']);

我不知道如何解决,我怕做错什么,因为我是新手php而且函数不是我创建或修改的

我通过在行中添加一个 id 自行解决了我的问题:

$args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->id , $widget_obj->widget_options['classname'] );

我不知道为什么或在哪里但是 $args['before_widget'] return :

'<section id="%1$s" class="widget %2$s">'

所以它需要 2 个参数,所以我只添加 $widget_obj->id 而我没有任何错误消息! 我希望有一天它能对某人有所帮助:)