Home › Forums › Front End PM PRO › Function active only "if" a condition occurs.
This topic is: Resolved
- This topic has 3 replies, 2 voices, and was last updated 6 years, 1 month ago by c-alle.
Viewing 4 posts - 1 through 4 (of 4 total)
- AuthorPosts
- November 8, 2019 at 8:09 pm #30944c-alleParticipant
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.
November 8, 2019 at 8:15 pm #30947c-alleParticipantThis reply has been marked as private.November 9, 2019 at 3:07 pm #30982Shamim HasanKeymasterYou 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; });November 9, 2019 at 3:54 pm #30989c-alleParticipantThanks, it works perfectly.
- AuthorPosts
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.