Site logo

Archived topic

Syntax error in Hook from documentation

3 replies · Started by Carsten on January 6, 2023

Viewing posts 1–4 of 4

Hi there, when I insert this code snippet from your Using Hooks documentation into a php checker, I get a syntax error about a bracket, both with and without my own code content, but I'mnot able to locate the error.

Can you help?

add_action( 'your_hook_name','example_function_name' );  
function example_function_name() { ?> 
     
<?php }

PHP Syntax Check: Parse error: Unmatched '}' in your code on line 28

add_action( 'bp_after_member_profile_content','example_function_name' );  
function example_function_name() { ?> 

<span class="block-report">
	
<?php  

if ( is_user_logged_in() && function_exists( 'bp_send_private_message_button' ) && bp_is_user() && ! bp_is_my_profile() ) {
	echo bp_send_private_message_button(bp_displayed_user_id() );
}
 
	
if ( is_user_logged_in() && function_exists( 'bublock_get_button' ) && bp_is_user() && ! bp_is_my_profile() ) {
echo bublock_get_button(bp_displayed_user_id() ); 	
}
	
		
if ( function_exists( 'bpmts_report_button' ) && function_exists( 'bpmts_is_me' ) && ! bpmts_is_me( bp_displayed_user_id() ) && bpmts_user_can_report() ) {
 			bpmts_report_button( array(  
      'item_id'    => bp_displayed_user_id(),
      'item_type'  => 'user',
      'context'    => 'bp_user_header',
      'context_id' => bp_displayed_user_id(),
   ) ); 
}
		
?>
	
</span>

<?php }

Hi there,

I'm not sure why the checker would indicate that - there are no issues from what I can see.

Just tried adding the code using Code Snippets and received no warnings either.

Hi there, I detected the issue, the problem was that I had two functions named 'example_function_name' in my functions.php, which I can see is not allowed.

I can't explain why my php analyser came up with the Unmatched '}' error.

Thanks!

No problem :)

This archived topic is closed to new replies.