Cloak email and phone on freelanceengine

When running a micro job/freelancer website you don’t want people to share email or phone details.  You can use this code below, placed it in your functions.php file. The theme that was used is from freelanceengine.

When the new job was posted, the email and numbers that were entered in the title and body will show a custom label to hide it.

function mask_phone_and_email ( $string ) {
    $regex_to_match = array (
        '[0-9]{10}',
        '[0-9]{3} [0-9]{7}',
        '([0-9]{3}) [0-9]{7}',
        '([0-9]{3})[0-9]{7}',
        '[0-9]{3} [0-9]{3} [0-9]{4}',
        '([0-9]{3}) [0-9]{3} [0-9]{4}',
        '([0-9]{3})[0-9]{3} [0-9]{4}',
        '[0-9]{3}-[0-9]{7}',
        '[0-9]{3}-[0-9]{3}-[0-9]{4}',
    );
    $regex_to_match = '(' . join ( ')|(', $regex_to_match ) . ')';
    
    $string = preg_replace_callback(
        "/".$regex_to_match."/",
        function ($matches) {
            return '[hidden]';
        },
    $string);
    
    $string = preg_replace_callback(
        "/[a-z0-9_-+][email protected][a-z0-9-]+.([a-z]{2,3})(?:.[a-z]{2})?/i",
        function ($matches) {
            return '[hidden]';
        },
    $string);
    
    return $string;
}



add_filter( 'wp_insert_post_data' , 'filter_mask_phone_and_email' , '99', 2 );
function filter_mask_phone_and_email( $data , $postarr ) {
    
    $data['post_title']     = mask_phone_and_email ( $data['post_title'] );
    $data['post_content']     = mask_phone_and_email ( $data['post_content'] );
    return $data;
}

 

 

 

freelanceengine-enginethemes-1510853573152
Once a week we send a digest with the most popular articles.

We are more than just a Hosting company!

AdminWP Host, Maintain (Site-care), Secure and Backup WordPress websites.