Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP警告:Mailchimp::call()缺少参数2_Php_Wordpress_Mailchimp_Mailchimp Api V3.0 - Fatal编程技术网

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

PHP警告:Mailchimp::call()缺少参数2,php,wordpress,mailchimp,mailchimp-api-v3.0,Php,Wordpress,Mailchimp,Mailchimp Api V3.0,可以在互联网上找到许多资源,它们都有相同的代码和说明,说明如何在WordPress中显示MailChimp订户数量。直到今天,当我收到一条PHP警告时,我才毫无问题地使用了该代码: PHP警告:缺少Mailchimp::call()的参数2,在中调用 /…第19行的/mc subscriber count/mc-subscriber-count.php和 在第192行的/../mc subscriber count/Mailchimp.php中定义 mc-subscriber-count.php

可以在互联网上找到许多资源,它们都有相同的代码和说明,说明如何在WordPress中显示MailChimp订户数量。直到今天,当我收到一条PHP警告时,我才毫无问题地使用了该代码:

PHP警告:缺少Mailchimp::call()的参数2,在中调用 /…第19行的/mc subscriber count/mc-subscriber-count.php和 在第192行的/../mc subscriber count/Mailchimp.php中定义

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行的函数-完整代码):

如何解决这个警告

更新

我忘了提到我看到缺少第二个论点,但我不明白第二个论点是什么

另外,我不是PHP程序员,所以不要打败我

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

因为我在这里只收到了反对票而没有得到帮助(但这并不重要),而且我的第一个解决方案也不起作用(见删除的文本),所以我再次在谷歌上搜索,最后我找到了一个更好的解决方案(我希望如此)。我只是将推荐的代码包装在一个短代码中,如下所示:

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订阅者计数的位置。

您可以指定第19行是什么吗?您发布了
MailChimp::call()
的代码,它需要两个参数(无可选参数)。你只用一个论点就可以称之为。问题出在哪里?@Tomm line#19在第一段代码中用注释标记。很抱歉,我没有看到这一点。请在您使用的SDK的文档中查找它。
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' );