Profanity Filter code I'm sharing with anyone who needs it | Support Questions | Support Forum

A A A

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Profanity Filter code I'm sharing with anyone who needs it
September 2, 2017
3:25 pm
mavellino
Member
Members
Forum Posts: 36
Member Since:
January 7, 2015
sp_UserOfflineSmall Offline

Having a classified ads website attracts all kind of spammers that place ads with their unwanted products or services, or even worse, people who place ads with illegal content, sex content etc.

AWPCP has a wonderful filter-hook to avoid this. I have implemented it on my website to avoid people placing ads with words like Viagra, sex, porn etc.

I’m sharing it with anyone who needs to filter out the ads for specific bad words without having to check ad by ad manually.

It works like this: when any of the words contained in this piece of code are placed in the ad, the filter will remove the words and they won´t show in the frontend. It works only with the new ads published after using these filters.

IMPORTANT!!! This code MUST be copy-pasted ONLY in the functions.php file of your Child Theme. If you are not using a child theme, you will have to create one first.

Just in case something goes wrong after saving this code, you will have to access your functions.php file via FTP and delete the pasted code.

As every ad field can be filtered, just use the one you need to filter or you can use all of them if you want.

Just replace badword1, badword 2 etc with the words you don´t want to appear in the ads. Any word of your choice can be used.

Once you’ve done it, place an ad by yourself (not logged in) containing any of the words you have used in the code. You’ll see that those words don´t appear in the ad.

I have attached a file with the code.

September 2, 2017
3:46 pm
mavellino
Member
Members
Forum Posts: 36
Member Since:
January 7, 2015
sp_UserOfflineSmall Offline

For some reason I don´t know the code is not showing in this thread Cry

September 2, 2017
3:57 pm
mavellino
Member
Members
Forum Posts: 36
Member Since:
January 7, 2015
sp_UserOfflineSmall Offline

//FUNCTION TO FILTER THE AD TITLE

function filter_title( $data, $context, $source ) {
if ( $context === ‘details’ ) {
$filterWords = array(‘badword1′,’badword2′,’badword3′,’badword4’);

$filterCount = sizeof($filterWords);

for($i=0; $i<$filterCount; $i++){

$data[‘ad_title’] = preg_replace(‘/\b’.$filterWords[$i].’\b/ie’,”str_repeat(‘ ‘,strlen(‘$0’))”,$data[‘ad_title’]);
}

$regExp = array(
“/(([+]{0,}\d{1,}[_\W]{0,}){9,})/”,
“/\b[\w.-][email protected][\w.-]+\.[A-Za-z]{2,6}\b/”
);

$data[‘ad_title’] = preg_replace($regExp, ”, $data[‘ad_title’]);

}
return $data;
}
add_filter( ‘awpcp-get-posted-data’, ‘filter_title’, 10, 3 );

 

//FUNCTION TO FILTER THE AD DESCRIPTION

function filter_description( $data, $context, $source ) {
if ( $context === ‘details’ ) {
$filterWords = array(‘badword1′,’badword2′,’badword3′,’badword4’);

$filterCount = sizeof($filterWords);

for($i=0; $i<$filterCount; $i++){

$data[‘ad_details’] = preg_replace(‘/\b’.$filterWords[$i].’\b/ie’,”str_repeat(‘ ‘,strlen(‘$0’))”,$data[‘ad_details’]);
}

$regExp = array(
“/(([+]{0,}\d{1,}[_\W]{0,}){9,})/”,
“/\b[\w.-][email protected][\w.-]+\.[A-Za-z]{2,6}\b/”
);

$data[‘ad_details’] = preg_replace($regExp, ”, $data[‘ad_details’]);

}
return $data;
}
add_filter( ‘awpcp-get-posted-data’, ‘filter_description’, 10, 3 );

Forum Timezone: America/Denver

Most Users Ever Online: 163

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Johnny B: 140

godie: 120

laburke: 94

NAIN KHAN: 93

kerdezo: 91

salvig67: 84

rude: 72

purplepaula: 72

WAYTOBAYWTB52: 71

gery: 71

Member Stats:

Guest Posters: 28

Members: 36977

Moderators: 2

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 6617

Posts: 29692

Newest Members:

Drachsi, Sheila, crocodile dundee, Jaydeb k, John Morotti, Jack Smith, Paul D, Jack, hockase, Upendra Yadav

Moderators: awpcp: 7530, AWPCP Support: 4622

Administrators: wpengine: 0, awpcp: 298

Skip to toolbar