Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@ekka21
ekka21 / gist:3066659
Created July 7, 2012 14:27
Wordpress: Add Extra Media Type Filters to the WordPress Media Manager
function modify_post_mime_types( $post_mime_types ) {
// select the mime type, here: 'application/pdf'
// then we define an array with the label values
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
// then we return the $post_mime_types variable
return $post_mime_types;
@ekka21
ekka21 / gist:3058240
Created July 6, 2012 05:12
Wordpress: set default thumbnail if NULL
add_action( 'save_post', 'wptuts_save_thumbnail' );
function wptuts_save_thumbnail( $post_id ) {
// Get Thumbnail
$post_thumbnail = get_post_meta( $post_id, $key = '_thumbnail_id', $single = true );
// Verify that post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
// Check if Thumbnail exists
@ekka21
ekka21 / Get lat and lng from google map api
Created July 5, 2012 13:39
Get lat and lng from google map api
<?php
function getLatandLong($addr,$city,$state)
{
global $lat;
global $lng;
$doc = new DOMDocument();
$doc->load("http://maps.google.com/maps/api/geocode/xml?address=".$addr.",+".$city.",+".$state."&sensor=false"); //input address
//traverse the nodes to get to latitude and longitude
@ekka21
ekka21 / Wordpress Add a rel="nofollow" to the comment reply links
Created July 4, 2012 02:36
Wordpress: Add nofollow to the comment reply links
@ekka21
ekka21 / gist:3028773
Created July 1, 2012 15:40
Wordpress: saving default post thumbnail
//Paste this in function.php
add_action( 'save_post', 'wptuts_save_thumbnail' );
function wptuts_save_thumbnail( $post_id ) {
// Get Thumbnail
$post_thumbnail = get_post_meta( $post_id, $key = '_thumbnail_id', $single = true );
// Verify that post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
@ekka21
ekka21 / gist:3018426
Created June 29, 2012 14:52
Wordpress: Using wordpress call Ajax the right way
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'GET',//POST, JSON, XML
dataType: 'html',
data: ({
action: 'MY_AJAX_FUNCTION',
state: state,
}),
success: function(data){
if (data){
@ekka21
ekka21 / Wordpress load $wpdb class
Created June 28, 2012 17:08
Wordpress: Load core wordpress classes outside of wordpress
<?php
define( 'BLOCK_LOAD', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php' );
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
@ekka21
ekka21 / gist:2998115
Created June 26, 2012 19:09
Wordpress: Add a new class to body_class
add_filter('body_class','add_mobile_class');
function add_mobile_class($classes) {
$classes[] = 'NEW_CLASS';
return $classes;
}
@ekka21
ekka21 / gist:2992439
Created June 26, 2012 01:10
Wordpress: Disable theme switching
add_action('admin_init', 'slt_lock_theme');
function slt_lock_theme() {
global $submenu, $userdata;
get_currentuserinfo();
if ($userdata->ID != 1) {
unset($submenu['themes.php'][5]);
unset($submenu['themes.php'][15]);
}
}
@ekka21
ekka21 / gist:2992435
Created June 26, 2012 01:09
Wordpress: Disable the “please update now” message in WP dashboard
if ( !current_user_can( 'edit_users' ) ) {
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}