Skip to content

Instantly share code, notes, and snippets.

View 5iDS's full-sized avatar
💭
@ease with the Source

Max 5iDS

💭
@ease with the Source
View GitHub Profile
@5iDS
5iDS / _log.php
Created July 22, 2013 13:33
Centralize all log calls to use this function. will call a print_r on arrays and objects passed to the function for simple debugging.
if(!function_exists('_log')){
function _log( $message ) {
if( WP_DEBUG === true ){
if( is_array( $message ) || is_object( $message ) ){
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
@5iDS
5iDS / wpdb-stored-procedures.php
Created July 5, 2013 11:09
Search for : ( file wd-db.php ) and replace with the following
<?php
function query( $query ) {
if ( ! $this->ready )
return false;
if ( strpos($query, "CALL") === false )
{
$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
$this->set_charset( $this->dbh );
$this->ready = true;
<?php
function check_Str_len($string) {
echo stripslashes($string).'<br />';
echo strlen( stripslashes($string) ).'<br />';
}
check_Str_len('843175010');
?>
@5iDS
5iDS / wpdb-transactions
Created June 30, 2013 22:37
MySQL database transaction, using the WordPress database object $wpdb. When you render a page in WordPress (front end or admin area), the $wpdb database object has already been initialised and opened up a connection to the database. Therefore we can recycle this database connection for our own needs. The $wpdb object saves the database handle as…
<?php
global $wpdb;
// @ prefix used to suppress errors, but you should do your own
// error checking by checking return values from each mysql_query()
// Start Transaction
@mysql_query("BEGIN", $wpdb->dbh);
// Do some expensive/related queries here
@5iDS
5iDS / gist:5639245
Created May 23, 2013 20:37
Counting String Characters
function smartShorten($charset='utf-8', $str, $maxlength = 140, $max_cut_len = 10) {
$len = iconv_strlen($str, $charset);
if ($len > $maxlength) {
$str = iconv_substr($str, 0, $maxlength, $charset);
$prev_space_pos = iconv_strrpos($str, ' ', $charset);
if ( ($maxlength-$prev_space_pos) < $max_cut_len) {
$str = iconv_substr($str, 0, $prev_space_pos, $charset);
}
@5iDS
5iDS / JSszz...
Created May 1, 2013 20:04
JS Sleep function
function jszz(s){
s=s*1000;
var a=true;
var n=new Date();
var w;
var sMS=n.getTime();
while(a){
w=new Date();
wMS=w.getTime();
if(wMS-sMS>s) a=false;