Error codes when snippet is activated


Home Forums Front End PM PRO Error codes when snippet is activated

This topic is: Resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #43473
    lia.spoerl
    Participant

    Hi,

    I’m using the following snippet to add a link to the users name in the message box.

    add_filter( 'fep_filter_user_name', function( $name, $id ){
    	$authordata = get_userdata( fep_get_message_field( 'mgs_author' ) );
    	if( in_array( 'employer', $authordata->roles ) ){
    		$name = '<a href="/jobs/'. fep_get_userdata( $id, 'user_nicename', 'id' ) . '/" target="_blank" rel="noreferrer noopener">' . $name . '</a>';
    	}
    	return $name;
    }, 10, 2);
    

    However, I’m getting the below error codes when in debug mode. Is there a fix for this?

    Notice: Trying to get property ‘roles’ of non-object in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code on line 3 Warning: in_array() expects parameter 2 to be array, null given in /www/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code on line 3

    Thanks

    #43492
    lia.spoerl
    Participant

    I was able to fix the error code by using is_object() to check on the variable

    #43494
    lia.spoerl
    Participant

    Actually, that didn’t fix the issue…sorry

    #43506
    Shamim Hasan
    Keymaster

    Try following

    add_filter( 'fep_filter_user_name', function( $name, $id ){
    	$authordata = get_userdata( fep_get_message_field( 'mgs_author' ) );
    	if( $name && $authordata && $authordata->roles && in_array( 'employer', $authordata->roles ) ){
    		$name = '<a href="/jobs/'. fep_get_userdata( $id, 'user_nicename', 'id' ) . '/" target="_blank" rel="noreferrer noopener">' . $name . '</a>';
    	}
    	return $name;
    }, 10, 2);
    
    #43510
    lia.spoerl
    Participant

    That fixed it. Thanks

Viewing 5 posts - 1 through 5 (of 5 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.