Skip to content

Instantly share code, notes, and snippets.

View yoren's full-sized avatar

Yoren Chang yoren

View GitHub Profile
@yoren
yoren / gist:2054890
Created March 17, 2012 04:15
WordPress: Disable Feed
/**
* disable feed
* @link http://wpengineer.com/287/disable-wordpress-feed/
*/
function fb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
@yoren
yoren / php_get_extension.php
Created March 23, 2012 09:37 — forked from rugbyprof/php_get_extension.php
Php return file extension
function get_file_ext( $filename )
{
return end( explode( ".", $filename ) );
}
@yoren
yoren / html.html
Created April 27, 2012 05:56 — forked from fancyoung/html.html
HTML template
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>HTML template</title>
<link href="" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
</div>
@yoren
yoren / gist:2514914
Created April 28, 2012 01:28
Minimize WordPress default query.
function alter_the_query( $request ) {
$dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars
$dummy_query->parse_query( $request );
// @TODO sometimes this will help reduce queries, but sometimes won't
$args = array(
'showposts' => 1,
'update_post_term_cache' => 0,
'update_post_meta_cache' => 0,
'no_found_rows' => 1 // if showposts = -1, useless
@yoren
yoren / calendar_view.js
Created August 27, 2012 11:45 — forked from yonestra/calendar_view.js
Titaniumでmy365風なカレンダーアプリを作る(1) ref: http://qiita.com/items/1398
var win = Ti.UI.currentWindow;
//今日という日
var now = new Date();
now.setHours(12);
var Y = now.getYear()+1900;
var M = now.getMonth()+1;
//表示している画面の年と月
var whenLabel = Ti.UI.createLabel({
@yoren
yoren / gist:3749066
Created September 19, 2012 11:03 — forked from willmot/gist:1277790
WordPress attachment category plugin
<?php
/*
Plugin Name: Attachment Categories
Description: Allows attachments to be categorised
Version: 1.0
Author: Human Made Limited
Author URI: http://hmn.md
*/
@yoren
yoren / gist:4180839
Created December 1, 2012 06:34
WordPress: Debug Constants
if ( WP_DEBUG ) {
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
}
@yoren
yoren / del_dir.php
Created December 19, 2012 08:48 — forked from devpilot/del_dir.php
PHP: Delete directory and its content
<?php
/**
* Delete directory with content in it
* @author Pilot
* @param string $directory Directory to delete
*/
function del_dir($directory) {
$content = scandir($directory);
unset($content[0], $content[1]);

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@yoren
yoren / gist:4553933
Last active May 26, 2022 01:03
WordPress: Select post parent from another post type
add_action('admin_menu', function() {
remove_meta_box('pageparentdiv', 'chapter', 'normal');
});
add_action('add_meta_boxes', function() {
add_meta_box('chapter-parent', 'Part', 'chapter_attributes_meta_box', 'chapter', 'side', 'high');
});
function chapter_attributes_meta_box($post) {
$post_type_object = get_post_type_object($post->post_type);
if ( $post_type_object->hierarchical ) {