Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@ekka21
ekka21 / gist:3140240
Created July 19, 2012 01:46
sql: Mass TextString Replace
UPDATE table_name SET COLUMN = REPLACE(COLUMN, 'old_text', 'new_text');
@ekka21
ekka21 / gist:3140222
Created July 19, 2012 01:44
Linux: show directories
//If you only want to show directories, replace "-type f" with "-type d".
find . -type f -exec du -sk {} \; | sort -nr
@ekka21
ekka21 / gist:3129478
Created July 17, 2012 13:46
Wordpress: get term without links
/**
* Getting taxonomy from DB without having links
* @param $post_id
* @return string "tag1,tag3,tag4"
*/
function go_get_terms($id){
global $wpdb;
$q = 'SELECT * from wp_terms t LEFT JOIN wp_term_relationships r on r.term_taxonomy_id = t.term_id WHERE object_id = '.$id;
$rows = $wpdb->get_results($wpdb->prepare($q));
$out = "";
@ekka21
ekka21 / Wordpress How to create custom dashboard help messages
Created July 14, 2012 05:17
Wordpress How to create custom dashboard help messages
function my_admin_help($text, $screen) {
// Check we're only on my Settings page
if (strcmp($screen, MY_PAGEHOOK) == 0 ) {
$text = 'Here is some very useful information to help you use this plugin...';
return $text;
}
// Let the default WP Dashboard help stuff through on other Admin pages
return $text;
}
@ekka21
ekka21 / gist:3098656
Last active October 7, 2015 03:28
php: states array
$states = array(''=>"STATE",'AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts", 'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri", 'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon", 'PA'=>"Pennsylvania", 'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming");
$states = array('AL'=>"Alabama",
'AK'=>"
@ekka21
ekka21 / gist:3095710
Created July 12, 2012 04:23
Wordpress: load image automatically
<?php
//set images directory
$directory = 'wp-content/themes/mizzou/images/banners/';
try {
// create slideshow div to be manipulated by the above jquery function
echo "<div id=\"slideshow\">";
//iterate through the directory, get images, set the path and echo them in img tags.
foreach ( new DirectoryIterator($directory) as $item ) {
if ($item->isFile()) {
$path = $directory . "/" . $item;
@ekka21
ekka21 / Wordpress get thumbnail image src
Created July 11, 2012 21:51
Wordpress: get thumbnail image src
/**
* Desc: Get image source from feature image
* @param $id
* @param $icon = 'thumbnail, medium, large or full'
* @return $image source
*/
function get_me_the_thumbnail_src($id , $size = 'full'){
$tmp = wp_get_attachment_image_src ( get_post_thumbnail_id ( $id ), $icon ) ;
$str = $tmp[0];
return $str;
@ekka21
ekka21 / gist:3077354
Created July 9, 2012 16:05
Linux: .htaccess Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com
RewriteRule (.*)$ http://newdomain.com/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteRule ^css/(.*) /wp-content/themes/roots/css/$1 [QSA,L]
RewriteRule ^js/(.*) /wp-content/themes/roots/js/$1 [QSA,L]
RewriteRule ^img/(.*) /wp-content/themes/roots/img/$1 [QSA,L]
@ekka21
ekka21 / gist:3071741
Created July 8, 2012 16:48
php: sanitize string
/**
* Function: sanitize
* Returns a sanitized string
*
* Parameters:
* $string - The string to sanitize.
* $force_lowercase - Force the string to lowercase?
* $anal - If set to *true*, will remove all non-alphanumeric characters.
*/
function sanitize($string, $force_lowercase = true, $anal = false) {
@ekka21
ekka21 / gist:3067107
Created July 7, 2012 16:30
Wordpress: remove post meta box
if (is_admin()) :
function my_remove_meta_boxes() {
if(!current_user_can('administrator')) {
remove_meta_box('linktargetdiv', 'link', 'normal');
remove_meta_box('linkxfndiv', 'link', 'normal');
remove_meta_box('linkadvanceddiv', 'link', 'normal');
remove_meta_box('postexcerpt', 'post', 'normal');
remove_meta_box('trackbacksdiv', 'post', 'normal');
remove_meta_box('commentstatusdiv', 'post', 'normal');
remove_meta_box('postcustom', 'post', 'normal');