• Resolved vahyd

    (@vahyd)


    I’m using the following code in a comment loop

    <?php if (current_user_can('edit_comment',$comment->comment_ID) ); {  ?>
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment"><img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/></a>
    <?php } ?>

    I get the error
    Fatal error: Call to undefined function if () in ….

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You cannot have semi-colons immediately after if conditions.
    Remove the semi-colon,
    from

    if (current_user_can('edit_comment',$comment->comment_ID) );

    Thread Starter vahyd

    (@vahyd)

    thanks.. but now I’m getting

    syntax error, unexpected ‘{‘

    now it looks like

    <?php if (current_user_can('edit_comment',$comment->comment_ID) ) {  ?>
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment">
    <img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/>
    </a>
    <?php } ?>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You still have the semi colon immediately after the if (condition).

    Thread Starter vahyd

    (@vahyd)

    sorry typing mistake.. semicolon was actually removed the code.
    And still getting unexpected ‘{‘ error

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I can’t see a syntax error in that code, can you post just the line in which the syntax error refers to?

    Thread Starter vahyd

    (@vahyd)

    It was the first line
    <?php if (current_user_can('edit_comment',$comment->comment_ID) ) { ?>

    I’ve got it working fine now. Will paste the code later in case someone wants to check it

    Thread Starter vahyd

    (@vahyd)

    This is the code that worked for me.

    <?php if (current_user_can('edit_comment',$comment->comment_ID)) : ?>
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment">
    <img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/>
    </a>
    <?php endif;?>

    I think my previous code (the code after removing the semicolon) had something to do with the server settings.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘if (current_user_can('edit_comment')) error’ is closed to new replies.