Help with adding a condition to conditional code

I am trying to add one more condition to this conditional code.

This code is working well. Only a user with a avatar/photo can send a message.

public static function addMessage($ID, $user, $message) {
        
        $user_id = get_current_user_id();
        $avatar=ThemexCore::getUserMeta($user_id, 'avatar');
        if(empty($avatar)) {         
        $message=trim(preg_replace($filters, '', $message));
        }

I trying to add is a condition that Only a user with a Description in their profile can send a message.

This code checks if a text description has been saved to the users profile.

if(!ThemexCore::checkOption('description')) {
            $fields[]=array(
                'label' => __('Description', 'theme'),
                'name' => 'description',
                'type' => 'text',
                'default' => true,
            );
        }

I have tried many coding combinations, yet so far no joy.

Here is one example:

$user_id = get_current_user_id();        
        $description=ThemexCore::getUserMeta($user_id, 'description'); 
        $description=ThemexCore::checkOption('description');       
        if(empty($description)) {         
        $message=trim(preg_replace($filters, '', $message));
        }

All help appreciated :slight_smile:

1 Like

Could someone please tell me what is incorrect with this code.

I am wanting to message if the User has not filled in their First name - first_name

   $user_id = get_current_user_id();
        $first_name=ThemexCore::getUserMeta($user_id, 'first_name');
        if(empty($first_name)) {         
        $message=trim(preg_replace($filters, '', $message));
        }

Ok have it working now, changed this line of code:

$first_name=get_user_meta($user_id, 'first_name', true);

When that plugin is updated those changes will be lost. Changes should be made in a way which they do not break future updates.

1 Like

Hello oddz, yes a good point, thank you :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.