0

I am getting this error in my php-fpm error log, and I was hoping one of you could show me how to fix my code. Here's the error:

PHP message: PHP Warning: Missing argument 1 for is_mx_handler::is_mx_handler(), called in /var/www/epiclasers.com/wp-content/plugins/devs-is-mx/devs-is-mx.php on line 37 and defined in /var/www/epiclasers.com/wp-content/plugins/devs-is-mx/devs-is-mx.php on line 16"

and here's my plugin PHP code:

<?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
  • I'm not entirely sure, but I think you can't have more than one parameter in the method is_mx_handler. Try getting rid of $content=""; you can pass that as part of $atts instead. Commented Jul 4, 2014 at 2:30
  • I think you are missing () in the contructor. Try: $is_mx_handler = new is_mx_handler(); Also first parameter is not optional, it is mandatory. Commented Jul 4, 2014 at 2:32

2 Answers 2

1

You may wish to try this:

<?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'));

?>
Sign up to request clarification or add additional context in comments.

Comments

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

-- that line is being called by --

$is_mx_handler = new is_mx_handler;

-- but two things are challenging here:

  1. is_mx_handler expects you to pass it two parameters, $atts (required), and $content (optional). You can fix this by changing your function statement to:

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

    or by changing your instantiation to:

    $is_mx_handler = new is_mx_handler("",""); // passing in blank values for both arguments
    
  2. Your constructor is currently named the same thing as your class. This functionality isn't really supported in php4 and I recommend you move to using the following method name for your constructor : void __construct() per the documentation here

1 Comment

Hi John. Thanks for your response! I am very new to PHP, so if you could show me switch to the new void _contstruct() functionality that would be great - I'm not exactly sure how to change my code after reading that documentation page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.