PHP 警告:Mailchimp::call() 缺少参数 2

PHP Warning: Missing argument 2 for Mailchimp::call()

可以在 Internet 上找到 there 很多资源,这些资源具有相同的代码和关于如何在 WordPress 中显示 MailChimp 订阅者数量的说明。直到今天,我一直在毫无问题地使用该代码,当时收到 PHP 警告:

PHP Warning: Missing argument 2 for Mailchimp::call(), called in /.../mc-subscriber-count/mc-subscriber-count.php on line 19 and defined in /.../mc-subscriber-count/Mailchimp.php on line 192

mc-subscriber-count.php完整代码:

function wpb_mc_sub_count() {
    include "Mailchimp.php";
    $lastRunLog = __DIR__ . '/logs/lastrun.log';
    $subfile = __DIR__ . '/logs/subcount.log';
    $lastRun = file_get_contents( $lastRunLog );

    if ( time() - $lastRun >= 86400 ) {
        $MailChimp = new MailChimp( 'Your_MailChimp_API_Key' );
        $mc = $MailChimp->call( 'lists/list' ); // THE LINE 19
        /*****************************************************/
        $subscriber_count .= $mc[data][0][stats][member_count];
        file_put_contents( $lastRunLog, time() );
        file_put_contents( $subfile, $subscriber_count );
    } else {
        $subscriber_count .= file_get_contents( $subfile );
    }

    return number_format( $subscriber_count );

}

add_shortcode( 'mc-subscribers', 'wpb_mc_sub_count' );
add_filter( 'widget_text', 'do_shortcode' );

Mailchimp.php 代码(只有第 192 行的函数 - 完整代码 here):

public function call($url, $params) {
    $params['apikey'] = $this->apikey;

    $params = json_encode($params);
    $ch     = $this->ch;

    curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);

    $start = microtime(true);
    $this->log('Call to ' . $this->root . $url . '.json: ' . $params);
    if($this->debug) {
        $curl_buffer = fopen('php://memory', 'w+');
        curl_setopt($ch, CURLOPT_STDERR, $curl_buffer);
    }

    $response_body = curl_exec($ch);

    $info = curl_getinfo($ch);
    $time = microtime(true) - $start;
    if($this->debug) {
        rewind($curl_buffer);
        $this->log(stream_get_contents($curl_buffer));
        fclose($curl_buffer);
    }
    $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
    $this->log('Got response: ' . $response_body);

    if(curl_error($ch)) {
        throw new Mailchimp_HttpError("API call to $url failed: " . curl_error($ch));
    }
    $result = json_decode($response_body, true);

    if(floor($info['http_code'] / 100) >= 4) {
        throw $this->castError($result);
    }

    return $result;
}

如何解决该警告?

更新

我忘了说我看到缺少第二个参数,但我不明白第二个参数是什么。

P.S。我不是PHP编码员,所以不要打我。

在收到评论后,我反复分析了上述两个函数,并决定将 `$params` 变量作为第二个参数添加到第 19 行,现在看起来像这样: $mc = $MailChimp->call( 'lists/list', $params ); 我不知道这是否是正确的方法,但我现在会等待错误,如果有的话。

更新

因为我在这里只收到了反对票而不是帮助(但这无关紧要)而且我的第一个解决方案不起作用(请参阅已删除的文本),我再次搜索并最终找到了更好的解决方案(我希望) to display the MailChimp subscribers count in Wordpress。我只是将推荐的代码包装在这样的简码中:

function wpb_mc_sub_count() {
    $api['key']= 'INSERT-YOUR-API-KEY-HERE';
    $url='https://INSERT-YOUR-US-DOMAIN-KEY.api.mailchimp.com/3.0//lists/INSERT-YOUR-LISTID-HERE/?apikey=INSERT-YOUR-API-KEY-HERE';
    $lastRunLog = '/logs/lastrun.log';
    $subfile = '/logs/subcount.log';
    $lastRun = file_get_contents($lastRunLog);

    if (time() - $lastRun >= 3600) {
        // it's been more than one hour so we will connect to the API
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL,$url);
        $result=curl_exec($ch);
        curl_close($ch);
        $json = json_decode($result, true);
        $total= $json['stats']['member_count'];
        // update lastrun.log with current time
        file_put_contents($lastRunLog, time());
        file_put_contents($subfile, $total);
    } else {
        $total = file_get_contents($subfile);
    }

    //echo $total;
    return $total;

}

add_shortcode( 'mc-subscribers', 'wpb_mc_sub_count' );
//add_filter( 'widget_text', 'do_shortcode' );

只需将 [mc-subscribers] 简码放在要显示 MailChimp 订阅者数量的位置。