Function active only "if" a condition occurs.


Home Forums Front End PM PRO Function active only "if" a condition occurs.

This topic is: Resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30944
    c-alle
    Participant

    Hi Shamim, I have this function on my function.php page (you wrote it and it works perfectly).

    add_filter( 'fep_filter_message_before_send', function( $message ) {
    	// The @ symbol must be surrounded by character on both sides
    	$message['message_content'] = preg_replace( '/[^@\s]*@[^@\s]*\.[^@\s]*/', '[EMAILNASCOSTA]', $message['message_content'] ); # for emails
    	
    	// Take any string that contains only numbers, spaces and dashes,
    	// Can optionally have a + before it.
    	$message['message_content'] = preg_replace( '/\+?[0-9\-]{5,}/', '[TELEFONONASCOSTO]', $message['message_content'] ); # for phone numbers
    	
    	return $message;
    });
    

    Now I would like to make sure that the function occurs and is only activated if a user has a value entered in a specific metakey other than “no” in the profile.

    I wrote this feature and it works:

    
    $user = get_current_user_id();
    $privacytel = get_user_meta( $user, 'privacytel', true ); 
    if ( is_user_logged_in() ) {
    if ( $privacytel !=  'No') {		
    YOUR FUNCTION SHOULD BE STARTED HERE, WHEN THE TWO "IF" ARE VERIFIED, WHEN THE USER IS LOGGED-IN AND WHEN THE METAKEY $PRIVACYTEL IN HIS PROFILE HAS AN EMPTY OR DIFFERENT VALUE FROM NO.
    		}
    

    How can I add it to your function to get my goal I wrote above?

    I hope I was clear.

    Thanks.

    #30947
    c-alle
    Participant
    This reply has been marked as private.
    #30982
    Shamim Hasan
    Keymaster

    You can use condition inside that function.

    add_filter( 'fep_filter_message_before_send', function( $message ) {
        if ( get_user_meta( get_current_user_id(), 'privacytel', true ) != 'No') {
    	    // The @ symbol must be surrounded by character on both sides
    	    $message['message_content'] = preg_replace( '/[^@\s]*@[^@\s]*\.[^@\s]*/', '[EMAILNASCOSTA]', $message['message_content'] ); # for emails
    	
    	    // Take any string that contains only numbers, spaces and dashes,
    	    // Can optionally have a + before it.
    	    $message['message_content'] = preg_replace( '/\+?[0-9\-]{5,}/', '[TELEFONONASCOSTO]', $message['message_content'] ); # for phone numbers
        }
        return $message;
    });
    
    #30989
    c-alle
    Participant

    Thanks, it works perfectly.

Viewing 4 posts - 1 through 4 (of 4 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.