Filter badwords

Here’s a way to filter words that are foul. Here we have a table of blocked words loaded in the DB, then the script test every “word” inside your string versus the list of banned words in our DB. This even gives you what specific “banned words” is being filtered. Enjoy the code.

public function filter_words($string) {

$banned_words = $this->get_bad_words();
$badword = $this->found_bad_word;

for($i=0; $ifound_bad_word = $banned_words[$i];
}
}

if (!empty($this->found_bad_word)) {
return true;
} else {
return false;
}

}


Rare – Accoustic Version of Sweet Child of Mine


How to use WPDB class for DB access

require_once ‘../../../wp-load.php’;

function insertDB($name,$contact,$email,$evtName) {
global $wpdb;
$wpdb->custom_table = “custom_table_name”;

//$wpdb->show_errors();

$ok = $wpdb->insert($wpdb->custom_table, array(
‘name’ => $name,
‘contact’ => $contact,
‘email’ => $email,
‘event_name’ => $evtName
));

if ($ok) {
echo json_encode(array( ‘ok’ => true , ‘status’ => ‘success in DB insert’ ));
}else {
//$wpdb->print_error();
echo json_encode(array( ‘ok’ => false , ‘status’ => ‘failed on DB insert’ ));
}

}

insertDB($name,$contact,$email,$evtName);


How to use WP phpmailer on separate php file.


/* Send Mail */

require_once '../../../wp-includes/class-phpmailer.php';

//Gmail settings
define('GUSER', 'sender@gmail.com'); // Gmail username
define('GPWD', 'xxxxx'); // Gmail password

//Host settings
define('SMTPUSER', 'xerxis@domain.com'); // sec. smtp username
define('SMTPPWD', '12314'); // sec. password
define('SMTPSERVER', 'mail.domain.com'); // sec. smtp server

function smtpmailer($to, $from, $from_name, $subject, $body, $is_gmail = true) {
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
if ($is_gmail) {
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
} else {
$mail->Host = SMTPSERVER;
$mail->Username = SMTPUSER;
$mail->Password = SMTPPWD;
}
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}

$msg = 'Hello World';
$subj = 'test mail message';
$to = 'kaixersoft@gmail.com';
$from = 'from@mail.com';
$name = 'test email';

//try using gmail
if (smtpmailer($to, $from, $name, $subj, $msg)) {
echo json_encode(array('status' => 'message send via Gmail'));
//try host settings
} else {
if (!smtpmailer($to, $from, $name, $subj, $msg, false)) {
if (!empty($error)) echo $error;
} else {
echo json_encode(array('status' => 'message send via Host Settings'));
}
}


How to use WP-Includes (3.2.1++)

Load jQuery using Google CDN:

function init_includes() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js');
wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'init_includes');

see codex for other built-in includes:
http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_a_default_WordPress_script_from_a_non-default_location


How to capture form input into objects

Features :
1. auto check for selected and non-selected checkbox
2. auto capture selected radio


function nvp2obj(selector) {
var inputs = $(selector);
var o = {};
inputs.each(function(i) {
if (this.name) {
if (this.type == 'checkbox' && $(this).attr('checked')) o[this.name] = $(this).val();
if (this.type == 'radio' && $(this).attr('checked')) o[this.name] = $(this).val();
if (this.type == 'text' || this.type == 'textarea') o[this.name] = $(this).val();
}
});
return o;
}

How to use :
$('#btnLetsTalk').click(function(e) {

var inputs = nvp2obj('#frmLetsTalk :input');

console.log(inputs);

e.preventDefault();

});


How to Fix App Authorization issues

/*
-- [ Using Old FB SDK ] ------------------------------------------------------
FB.init({ appId: '202143216518919',
status: true,
cookie: true,
xfbml: true});

//App Settings
Encrypted Access Token = Disabled

*/
FB.getLoginStatus(function(response) {
if (!response.session) {
FB.ui({
method: "permissions.request",
"perms": permission
},
function(response) {
if (response) {
console.log(response);
}
}
);
}
});

/*
-- [ Using New FB SDK ] ------------------------------------------------------
FB.init({ appId: '202143216518919',
status: true,
cookie: true,
xfbml: true,
oauth : true //Enable OAuth 2.0
});

//App Settings
Encrypted Access Token = true

*/
FB.login(function(response) {
console.log(response);
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope:permission});

/*
-- [ Using New FB SDK / disabled OAuth ] ------------------------------------------------------
FB.init({ appId: '202143216518919',
status: true,
cookie: true,
xfbml: true,
oauth : false //Enable OAuth 2.0
});

//App Settings
Encrypted Access Token = true

*/
FB.getLoginStatus(function(response) {

console.log(response);
if (response.status === "notConnected") {
console.log('not yet authorized');
FB.ui({
method: "permissions.request",
"perms": permission
},function(response) {
if (response) {
var accessToken = response.authResponse.accessToken;
var uid = response.authResponse.accessToken
console.log(response);
}
});
} else {
console.log('connected to FB');
}

});


My iFrame Tab CSS reset

@CHARSET “ISO-8859-1″;
*
{
margin:0;
padding:0;
font-size: 11px;
font-family: tahoma,”lucida grande”,verdana,arial,sans-serif;
color: #333;
text-align: left;
direction: ltr;
}
img { border:none; }
a { text-decoration:none; }
textarea { resize: none; }
.TabContainer {
height:auto;
margin:0;
padding:0;
width:510px !important;
overflow:hidden !important;
overflow-x:hidden !important;
overflow-y:hidden !important;
}


How to embed Movies

                			<object width="311" height="176">
								<param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf"></param>
								<param name="flashvars" value="src=<?=$data['video_url']?>&poster=<?=$data['image_url']?>"></param><param name="allowFullScreen" value="true"></param>
								<param name="allowscriptaccess" value="always"></param>
								<embed src="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf" type="application/x-shockwave-flash"
								       allowscriptaccess="always" allowfullscreen="true" width="311" height="176" flashvars="src=<?=$data['video_url']?>&poster=<?=$data['image_url']?>"></embed>
							</object>


Dealing with multiple db connection with AdoDb ORM

  //ADODB ORM
	include_once('/usr/lib/php5/adodb5/adodb.inc.php');
	include_once('/usr/lib/php5/adodb5/adodb-active-record.inc.php');
	$ADODB_ASSOC_CASE = 2;
	$db = NewADOConnection("mysql://".APP_USERNAME.":".APP_PASSWORD."@".APP_HOST."/".APP_DB);
	ADOdb_Active_Record::SetDatabaseAdapter($db);

	//if dealing with multiple db connection
	include_once('/usr/lib/php5/adodb5/adodb.inc.php');
	include_once('/usr/lib/php5/adodb5/adodb-active-record.inc.php');
	$ADODB_ASSOC_CASE = 2;
	$db1 = NewADOConnection("mysql://".APP_USERNAME.":".APP_PASSWORD."@".APP_HOST."/".APP_DB);
	$db2 = NewADOConnection("mysql://".APP_USERNAME2.":".APP_PASSWORD2."@".APP_HOST2."/".APP_DB2);
	//on Model.php
	class Registration extends ADOdb_Active_Record {}
	class winner  extends ADOdb_Active_Record {}
	Registration::SetDatabaseAdapter($db);
	winner::SetDatabaseAdapter($db2);

Follow

Get every new post delivered to your Inbox.