Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@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: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 / 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: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:3180101
Created July 26, 2012 03:37
Linux: Add new user
useradd -m -d /home/USER_NAME -g wheel USER_NAME
usermod -G GROUP1,GROUP2 USER_NAME
@ekka21
ekka21 / gist:3180102
Created July 26, 2012 03:38
Linux: restart apache
sudo service httpd graceful
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 reload
@ekka21
ekka21 / gist:3180107
Created July 26, 2012 03:39
jQuery: check all checkboxes
// First way
$('#checkBox').attr('checked');
// Second way
$('#edit-checkbox-id').is(':checked');
//input name array
$('input[name=SOME_NAME\\[\\]]').is(':checked')
@ekka21
ekka21 / gist:3227450
Created August 1, 2012 14:46
jQuery: alert box when leaving the site
// If the link being clicked is external the user will be prompted
// to confirm they wish to leave the site. Confirmation results in
// the external link being opened in a new window
$('a')
.bind('click', function(event) {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
@ekka21
ekka21 / gist:3291612
Created August 8, 2012 02:47
php: regular expression regex
If you would like to remove a tag along with the text inside it then use the following code.
<?php
preg_replace('/(<tag>.+?)+(<\/tag>)/i', '', $string);
?>
example
<?php $string='<span class="normalprice">55 PKR</span>'; ?>
<?php
@ekka21
ekka21 / gist:3316966
Created August 10, 2012 19:08
Wordpress: hide acf admin menu
/**
* Hide ACF menu item from the admin menu
*/
function hide_admin_menu()
{
global $current_user;
get_currentuserinfo();
if($current_user->user_login != 'admin')