WordPress.org

Ready to get started?Download WordPress

Forums

PHP Browser Detection
[resolved] Syntax errors with conditional statements included (11 posts)

  1. gecko_guy
    Member
    Posted 1 year ago #

    I'm using the plugin in a slightly unusual way, so not sure if it related to that, but it looks like the CONDITIONAL STATEMENTS INCLUDED in the plugin are actually wrong for Internet Explorer:

    is_lt_IE(6)
    is_lt_IE(7)
    is_lt_IE(8)
    is_lt_IE(9)

    Above are the tags as displayed at the top of the file, but they were not working when I tried to use them, so looked deeper.:

    /**
     * Conditional to test for less than IE9.
     *
     * @return bool
     *
     * @deprecated Use the future-proof syntax instead of this function: if(is_ie() && get_browser_version() < 9) { }
     */
    function /**
     * Conditional to test for less than IE9.
     *
     * @return bool
     *
     * @deprecated Use the future-proof syntax instead of this function: if(is_ie() && get_browser_version() < 9) { }
     */
    function is_lt_IE9() {
    	if(is_ie() && get_browser_version() < 9) {
    		return TRUE;
    	} else {
    		return FALSE;
    	}
    } {
    	if(is_ie() && get_browser_version() < 9) {
    		return TRUE;
    	} else {
    		return FALSE;
    	}
    }

    The function is defined as is_lt_IE9(), but the included conditional statement at the top is is_lt_IE(9)

    This is the same for all the "is older than" conditions.

    http://wordpress.org/extend/plugins/php-browser-detection/

  2. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    The is_lt_IE style function are being deprecated (no longer supported). Instead use the new syntax:

    if(is_ie() && get_browser_version() < 9) { }

    I will make sure the code comments get changed in the next release.

  3. gecko_guy
    Member
    Posted 1 year ago #

    Thanks, I tried that originally but get a parse error:

    Parse error: syntax error, unexpected T_IF in /wp-content/plugins/foobar/foobar.php(2517) : eval()'d code on line 1

    The old way works, but obviously I don't want to use a deprecated snippet so it is not ideal.

  4. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    If you are getting a parse error, double check your PHP syntax. Or post the full code here and I'll can find it for you.

  5. gecko_guy
    Member
    Posted 1 year ago #

    Thanks, I suspect the problem is actually in the Foobar plugin, which does not recognise the modern syntax.

    I will contact the developer and ask them to update their conditional logic functions for the plugin.

  6. gecko_guy
    Member
    Posted 1 year ago #

    Am I being dense?

    The function in your plugin is defined as:

    is_lt_IE10()

    I do not need to use the full function in my conditional logic field:

    function is_lt_IE10() {
    	if(is_ie() && get_browser_version() < 10) {
    		return TRUE;
    	} else {
    		return FALSE;
    	}
    }

    I can use the is_lt_IE10() statement to call the modern function?

    What I should not use is is_lt_IE(10)

    I'm no php wizard, so perhaps I have misunderstood the whole thing.

    I am using is_lt_IE10()

    Is this correct?

    Sorry for the trouble...

  7. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    You shouldn't use the syntax "is_lt_IE10" or "is_lt_IE" - both of these are being phased out. Instead you should use the much more flexible (and future proof):

    if(is_ie() && get_browser_version() < 10) {
    		return TRUE;
    	} else {
    		return FALSE;
    	}

    The reason is that we don't want to have to add a ton of different functions for every single borwser version when one function will do. For example, we will not be adding is_ie11() or is_lt_ie11()

  8. gecko_guy
    Member
    Posted 1 year ago #

    Thanks for taking the time to respond to my questions :)

    The way I am using the plugin is simply to display a message if the browser is less than IE10, as all future versions of IE will support the CSS3 styles in use on the site.

    The Foobar plugin allows me to insert the simple statement is_lt_IE10()

    There is no option to use the full function

    if(is_ie() && get_browser_version() < 10) {
    		return TRUE;
    	} else {
    		return FALSE;
    	}

    as it returns a parse error. I will only be using this particular notification to tell people using old versions of IE (pre IE10) that their version is old, and that they should consider upgrading.

    I am unable to edit the php of the Foobar plugin as it will simply be overwritten next time it is updated, so I guess the question becomes, can I use the deprecated syntax for this one instance as I do not need the full functionality of the PHP Browser Detection plugin?

    Could I potentially place the code in my functions.php file and do away with the plugin entirely in this case to lower the footprint?

  9. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    This is going beyond the scope of support for the actual PHP Browser Detection plugin. There are n almost infinite number of ways you could accomplish what you are trying to do with some basic PHP knowledge. Why not just create a custom function that does whatever you need it to in your functions.php file as you suggested?

    function myBrowserError() {
    if(is_ie() && get_browser_version() < 10) {
    		// do soemthing
    	} else {
    		// do soemthing
    	}
    }
    }

    And call that from Fubar? I am closing this topic as it is no longer directly related to my plugin, but rather about WordPress development in general.

  10. gecko_guy
    Member
    Posted 1 year ago #

    No problem, thank you

  11. gecko_guy
    Member
    Posted 1 year ago #

    I know you have closed the topic. I'm still mystified as to how the plugin works.

    I know it works, because it is doing what I want it to do, but I think we may have been talking at cross purposes.

    I am not using the plugin to do anything fancy, or to style things for different browsers, or to write my own functions.

    All I am doing is placing is_lt_IE10() in a conditional logic field that is already built into another plugin.

    I simply cannot understand the deprecation advice. If I use this statement in the field of the other plugin, it does what I want it to.

    Will it stop working when there is an upgrade to your plugin?

    I am sure I will figure it out, I'm simply confused by the language. Sorry to raise it again, feel a bit embarrassed to do so.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic