PHP警告:AEC_CONTACTOR_LIST::Form()的声明应与WP_Widget::Form($Instance)兼容

时间:2021-03-04 作者:Didzruwiem

Ajax事件日历插件不再更新,但我收到此错误。

PHP Warning: Declaration of aec_contributor_list::form() should be compatible with WP_Widget::form($instance) in /home/soso2358/public_html/wp-content/plugins/ajax-event-calendar/inc/widget-contributors.php on line 64下面是小部件贡献者的代码。php

<?php
class aec_contributor_list extends WP_Widget {

    function aec_contributor_list () {
        $widget_ops = array(\'description\' => __(\'A list of calendar contributors linked to their organization websites\', AEC_NAME));
        parent::WP_Widget(false, __(\'AEC Contributors\', AEC_NAME), $widget_ops);
    }
    
    function widget ($args, $instance) {
        extract($args);
        $contributors = $this->db_query_users_by_role(\'calendar_contributor\');
        echo $before_widget;
        $conts = sizeof($contributors);
        echo $before_title . sprintf(_n(\'(%d) Contributor\',\'(%d) Contributors\', $conts, AEC_NAME), $conts) . $after_title;
        if ($contributors) {
            echo \'<ul>\';
            foreach ($contributors as $contributor){
                $user = get_userdata($contributor);
                echo \'<li><a href="\' . $user->user_url . \'" target="_blank">\' .  $user->organization . \'</a></li>\';
            }
        }else{
            _e(\'No contributors as of yet.\', AEC_NAME);
        }
        echo \'</ul>\';
        echo $after_widget;
    }

    function db_query_users_by_role ($roles) {
        global $wpdb;
        if (!is_array($roles)) {
            $roles = explode(",", $roles);
            array_walk($roles, \'trim\');
        }
        $sql = \'
            SELECT  ID, display_name
            FROM    \' . $wpdb->users . \' INNER JOIN \' . $wpdb->usermeta . \'
            ON      \' . $wpdb->users . \'.ID =       \' . $wpdb->usermeta . \'.user_id
            WHERE   \' . $wpdb->usermeta . \'.meta_key =  \\\'\' . $wpdb->prefix . \'capabilities\\\'
            AND     (
        \';
        $i = 1;
        foreach ($roles as $role) {
            $sql .= \' \' . $wpdb->usermeta . \'.meta_value    LIKE    \\\'%"\' . $role . \'"%\\\' \';
            if ($i < count($roles)) {
                $sql .= \' OR \';
            }
            $i++;
        }
        $sql .= \') \';
        $sql .= \' ORDER BY display_name \';
        $userIDs = $wpdb->get_col($sql);
        return $userIDs;
    }

    
    /** @see WP_Widget::form */
    function form () {              
        _e(\'No options available.\', AEC_NAME);
    }
}
add_action(\'widgets_init\', create_function(\'\', \'return register_widget("aec_contributor_list");\'));
?>

1 个回复
SO网友:Pat J

WP_Widget::form() 期望收到array 作为参数,但插件form() 函数没有它。

您可能可以这样修复它:

/** @see WP_Widget::form */
function form ( $instance ) {              
    _e(\'No options available.\', AEC_NAME);
}
但是,请注意,如果插件不再受其开发人员的支持,则不会有任何安全更新。