PHP警告:缺少参数1

时间:2014-07-04 02:25:03

标签: php wordpress warnings

我在php-fpm错误日志中收到此错误,我希望你们其中一人可以告诉我如何修复我的代码。这是错误:

PHP消息:PHP警告:缺少is_mx_handler :: is_mx_handler()的参数1,在/var/www/epiclasers.com/wp-content/plugins/devs-is-mx/devs-is-mx.php中调用在第37行并在第16行的/var/www/epiclasers.com/wp-content/plugins/devs-is-mx/devs-is-mx.php中定义“

这是我的插件PHP代码:

<?php
/*
Plugin Name: Dev's is MX ShortCodes
Description: If / Then shortcodes
Author: Devin Fleenor
Version: 1.0.0
*/

class is_mx_handler {

function generic_handler ($atts, $content, $condition, $elsecode) {
    list ($if, $else) = explode ($elsecode, $content, 2);
    return do_shortcode($condition ? $if : $else);
}

function is_mx_handler ($atts, $content="") {
        $ip = $_SERVER['REMOTE_ADDR'];

        global $quick_flag;
        if(isset($quick_flag) && is_object($quick_flag)){
                if(($info = $quick_flag->get_info($ip)) != false){
        $code = $info->code;            // Country code: MX
        $name = $info->name;            // Country name: Mexico
        $latitude = $info->latitude;    // Country latitude (float): 45.1667
        $longitude = $info->longitude;  // Country longitude (float): 15.5
                }
        }

        if ($code == "MX") $ismx = "true";

        return $this->generic_handler ($atts, $content, isset($ismx), '[not_mx]');
}


}

$is_mx_handler = new is_mx_handler;
add_shortcode('is_mx', array($is_mx_handler, 'is_mx_handler'));
?>

2 个答案:

答案 0 :(得分:1)

function is_mx_handler($atts, $content="") {

- 该行正在被调用 -

$is_mx_handler = new is_mx_handler;

- 但这里有两件事情很有挑战性:

  1. is_mx_handler希望您传递两个参数$atts(必填)和$content(可选)。您可以通过将函数语句更改为:

    来解决此问题
    function is_mx_handler($atts='',$content="") {
    

    或将您的实例化更改为:

    $is_mx_handler = new is_mx_handler("",""); // passing in blank values for both arguments
    
  2. 您的构造函数当前与您的类名称相同。 php4并不真正支持此功能,我建议您转而使用构造函数的以下方法名称:void __construct()the documentation here

答案 1 :(得分:1)

您可以尝试这样做:

<?php
/*
Plugin Name: Dev's is MX ShortCodes
Description: If / Then shortcodes
Author: Devin Fleenor
Version: 1.0.0
*/

class is_mx_handler {

    function generic_handler($atts, $content, $condition, $elsecode) {
        list ($if, $else) = explode ($elsecode, $content, 2);
        return do_shortcode($condition ? $if : $else);
    }

    function __construct() {

    }

    function handle_mx($atts="", $content="") {
            $ip = $_SERVER['REMOTE_ADDR'];

            global $quick_flag;
            if(isset($quick_flag) && is_object($quick_flag)) {
                if(($info = $quick_flag->get_info($ip)) != false) {
                    $code = $info->code;            // Country code: MX
                    $name = $info->name;            // Country name: Mexico
                    $latitude = $info->latitude;    // Country latitude (float): 45.1667
                    $longitude = $info->longitude;  // Country longitude (float): 15.5
                }
            }

            if ($code == "MX") $ismx = "true";

            return $this->generic_handler($atts, $content, isset($ismx), '[not_mx]');
    }


}

$is_mx_handler = new is_mx_handler();
add_shortcode('is_mx', array($is_mx_handler, 'handle_mx'));

?>
相关问题