• This produces a syntax error (unexpected T_VARIABLE):

    if (... stuff ...) {
    wpmu_create_blog($domain,?$path,?$title,?$user_id);
    } else if ...

    How do you run a function within if else?

Viewing 4 replies - 1 through 4 (of 4 total)
  • can you paste the full code, of whatever template that snippet belongs to, into a https://pastebin.com/ and post the link to it here?

    per se, the posted code is too short and taken out of context.

    in general, https://php.net/manual/en/control-structures.elseif.php

    function in if…else clause is okey ! but in detail ?

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Thanks for your response. Here is more context:

    $user_id = $curauth->ID;
    $title = $curauth->display_name;
    $domain = network_home_url();
    $path = $curauth->user_login;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {
    wpmu_create_blog($domain, $path, $title, $user_id);
    } else if (user_can_for_blog($user_id, $primary_blog, edit_posts )) {
    echo '<p>Member has site</p>';
    }

    I know the general if else structure, but examples always use echo or ‘some code to execute’. I can’t find any examples with functions with variables.

    I have tried ‘return wpmu_create_blog(…’ and other variations. Nothing works. And maybe this is a WP specific thing?

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Can anyone give a general answer to this?

    I can’t get any function within if/else to work, even when I try something basic like this:

    if(...) {
    wp_redirect( home_url() );
    exit;
    } else {
    ...
    }

    I keep getting server/syntax errors – unexpected T_STRING etc. Shouldn’t this just work?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Stupid syntax question: function within if else’ is closed to new replies.