Support » Developing with WordPress » Help using a variable in a function parameter

  • Resolved Ryan Paul

    (@othellobloke)


    I have the following code in a plugin:

    if( $var != '' && !is_user_logged_in() ) {
    	if( is_child( $var ) ) {
    		auth_redirect();
    	}
    }

    $var is functioning as intended on the page and I use it elsewhere in the template, but it’s not working when used as a parameter for the is_child() function.

    If I put the ID number manually as the parameter.. it works perfectly.

    Can someone help me figure out why please?

    • This topic was modified 2 years, 5 months ago by Ryan Paul.
Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter Ryan Paul

    (@othellobloke)

    I did that. It showed me a bunch of errors about other random plugins, but not a single error about is_child.

    I even deleted ALL of that code from the plugin, and is_child then gave me an undefined function error.

    That’s very strange, and not something that I can help with any more.

    The problem is… you’re saying that there’s no other function called is_child(), but when you run the debugging code it’s saying that there is another function called that, so something somewhere is not right on your side. Faced with that… there’s no other answers that I can give. Maybe someone else might have an idea.

    Thread Starter Ryan Paul

    (@othellobloke)

    It said there was another function because when you told me to try that, I didn’t erase all of the other code that initially defined it.

    Thanks for your help anyway 🙂

    Thread Starter Ryan Paul

    (@othellobloke)

    I fixed it. I was using the ID, and just used the page slug and everything worked perfectly.

    Legit appreciate your help mate.

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Help using a variable in a function parameter’ is closed to new replies.