Validate email and ban certain domains - php

I have this code I currently use to validate emails:
return (bool) preg_match('/^([a-z0-9\+\_\-\.]+)#([a-z0-9\+\_\-\.]{2,})(\.[a-z]{2,4})$/i', $arg0);
How can I modify that code so I can ban several domains? I don't want any extra files to add, just to modify this code.
Thank you.

The easiest way would be to have an array with banned providers:
$providers = Array ( 'gmail.com', 'yahoo.com' );
and then just loop trough that array and check if provided email contains '#' . $provider.

Related

How to send variables like {contactfield=id} in MAUTIC email campaign?

I want to send {contactfield=id} (one of the variable of the mautic) into custom headers for a mail that is to be used for a campaign. I am not sure of the right way to send it. I am keeping this variable into custom headers under Channels > Emails and selecting a particular email's advanced settings and into custom headers. This sets the id value of the first contact in the contact list of the segment selected for the campaign into all the remaining contacts. I want to get the dynamic value of each contact's id respectively. How can I get this appropriate result? Thanks in advance.
Last time I checked, not all of the fields in the Email builder can contain tokens. I remember that the Body and Subject allow it, but there were some other fields that did not allow it.
You seem to be getting the correct token, so if it's not returning in the header based on your testing, that field may not get parsed for tokenization on processing.
As pointed out by Jordan Ryan, not all tokens are available under email, however the email object can be tapped by creating a custom plugin.
https://developer.mautic.org/#extending-emails
check out this section, it may help.
The second example on code block shows that you can place your custom placeholder and then replace it programmatically.
/**
* Search and replace tokens with content
*
* #param EmailSendEvent $event
*/
public function onEmailGenerate(EmailSendEvent $event)
{
// Get content
$content = $event->getContent();
// Search and replace tokens
$content = str_replace('{hello}', 'world!', $content);
// Set updated content
$event->setContent($content);
}

remove all user wordpress capabilities from a specific user

We want to remove specific user capability from a user, so we use that line of code below and it works for a specific capability:
$user->remove_cap( 'edit_pages');
but what if we want to delete all user capabilities of that specific user ?, we dont need to list all the capabilities because the line of code below doesn't work
$user->remove_cap( 'edit_pages', 'publish_products');
So is there is a way to delete all the capabilities with a line of code to remove all the capabilities instead of removing a specific capability ?
What you can do is get a list of all the capabilities said user has, then loop through them and remove each one like so:
$caps = $user->allcaps;
foreach($caps as $cap) {
$user->remove_cap($cap);
}
I believe this should work, if it doesn't or you have any clarifications you'd like me to make please let me know.
Source for All Capabilities (allcaps)
The WP_User::remove_all_caps() method does just that:
//Remove all of the capabilities of the user.
$user->remove_all_caps( );
Based on an earlier answer, you could loop through and remove them, but you'll need the name of the capability, not the value.
foreach($user->allcaps as $key=>$value) {
$user->remove_cap($key);
}
I haven't tested this a lot, but simply setting the array of capabilities to an empty array should do it too.
$user->allcaps = array();

How to remove IP Address and Email from Woocommerce Orders details admin panel

I am currently trying to remove the ip address from Woocommerce->Orders->Order Details. The method i have used for removing the emails and phone for the order details page was using the filter woocommerce_admin_billing_fields and then using unset to remove the variables. I figured this would be the same case for ip address but its not working, so im assuming i have to use a different filter?
In addition to this the emails displaying from Woocommerce -> Orders also dont
get remove, so is there a different filter for that as well?
Where can i find the filter for ip address and for email in woocommerce -> order? Or is there another method of removing this?
Thanks
You can try this code:
<?php
add_filter( 'update_post_metadata', 'mp1401091554', 10, 3 );
function mp1401091554( $null, $id, $key ) {
if ( '_customer_ip_address' === $key )
return FALSE;
return $null;
}

search mailchimp list by something else than email

currently all i can find is that the api only allow searching by email which is many cases not helpful because if the user wants to change his subscribing email he either have to
do something like this > http://kb.mailchimp.com/lists/signup-forms/how-subscribers-can-update-their-profiles
or i will have the new & old email from the user on the list because memberInfo() will return false because its a new given email.
also $update_existing=true is only used incase the user wants to change his (fname,lname) which in most cases they only want to change the email it self not the other info.
so does anyone knows a better way on how to handle subscribing/unsubscribing users using something else other than the email ???
Dublication :
check if user is in a list with mailchimp API V2.0
u can search by anything u want through
https://apidocs.mailchimp.com/api/2.0/helper/search-members.php i.e
MailchimpWrapper::helper()->searchMembers('what to search by', 'list_id');
,and to update the user info u can use
https://apidocs.mailchimp.com/api/2.0/lists/update-member.php i.e
MailchimpWrapper::lists()->updateMember(
'list_id',
['email' => $old_email],
['new-email' => $new_email],
'html',
false
);

How can I allow email addresses from two different domains using Regex?

I've got an small form to download some stuff. But I don't want every buddy to download it. Only from 2 specific domains you can download the stuff. So I made an form with an email validation. But How can I add two Domains in the test of the email?
What I was trying was:
$test = array(
'email' => '/^[\w.+-]{2,}\#[DOMAIN1][DOMAIN2]\.[a-z]{2,6}$/',
}
But that didn't worked …
Thanks for any help.
By grouping the evaluation () and placing an or operator in it | you'll be able to handle either domain. See the below modified regex:
'email' => '/^[\w.+-]{2,}\#(DOMAIN1|DOMAIN2)\.[a-z]{2,6}$/',

Categories