Skip to content

Instantly share code, notes, and snippets.

View torounit's full-sized avatar

Hiroshi Urabe torounit

View GitHub Profile
@torounit
torounit / get_parent_page_template.php
Created May 17, 2013 02:06
子ページを持つ親ページに、テーマ内に page-parent.phpがある場合、それを読み込む。
<?php
add_filter("template_include", "get_parent_page_template");
function get_parent_page_template( $template ) {
global $post;
if(is_page()) {
$children = wp_list_pages("child_of=".$post->ID."&echo=0");
if( !$post->post_parent and !empty( $children )) {
$template = locate_template( array( "page-parent.php", "page.php" ) );
}
@torounit
torounit / Scheduled_Term.php
Last active December 17, 2015 19:39
カスタムフィールドで指定した時間にカテゴリー(or タグ or カスタム分類のターム)を切り替えるクラス。Advanced Custom Fieldsに依存。
<?php
Class Scheduled_Term {
public $taxonomy = "category";
public $term_id = 1;
public $term_slug;
public $event_key = "scheduled_term";
public $date_key = 'date';
@torounit
torounit / add_selectable_image_size.php
Last active December 17, 2015 19:39
WordPressで追加した画像サイズを本文に挿入できるようにする | Simple Colors ( http://www.warna.info/archives/2270/ ) をクラスにして、使い回しが聞くように。 add_image_size()風味で使えるadd_selectable_image_size()という関数も追加。
<?php
Class Add_Selectable_Image_Size {
public $image_sizes = array();
public function __construct() {
add_action( 'after_setup_theme', array(&$this, 'add_image_sizes') );
add_filter( 'image_size_names_choose', array(&$this, 'add_image_size_select') );
}
@torounit
torounit / add_custom_post_type_role.php
Created July 2, 2013 05:48
WordPress の User Role Editor 等で、カスタム投稿タイプに独自に権限設定する場合に、カスタム投稿タイプ用の権限を自動的に追加する。
<?php
function add_custom_post_type_role( $post_type ,$arg ) {
$role = get_role('administrator');
if( "post" != $arg->capability_type and !$arg->_builtin ) {
$role->add_cap( "edit_{$arg->name}" );
$role->add_cap( "read_{$arg->name}" );
$role->add_cap( "delete_{$arg->name}" );
$role->add_cap( "delete_{$arg->name}s" );
@torounit
torounit / any-mobile-theme-switcher-fix.php
Created July 22, 2013 01:09
Any Mobile Theme Switcherが管理画面でも適応されてしまうを避ける。
<?php
/*
Plugin Name: Any Mobile Theme Switcher Fix
Description:Any Mobile Theme Switcher Fix
*/
if(is_admin()) {
$_GET["am_force_theme_layout"] = "desktop";
$_COOKIE['am_force_theme_layout'] = "desktop";
@torounit
torounit / the_content_image.php
Created August 2, 2013 01:13
WordPressで、記事内の最初の画像を持ってくる
<?php
function the_content_image( $size = 'thumbnail', $align = "" ) {
global $post;
$output = preg_match('/<img.+class=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if( $output ) {
$first = $matches;
preg_match("/wp-image-([0-9]+)/", $first[1], $matches);
$attr = "";
if( $align ) {
$attr = array( "class" => $align );
@torounit
torounit / acf-encrypted_field.php
Last active December 20, 2015 13:09
ACFで、内容が保存時に暗号化されるフィールド。需要は知らない。
<?php
/*
Plugin Name: Advanced Custom Fields: encrypted_field
Version: 1.0.0
Author: Toro_Unit
Author URI: http://www.jbnet.jp
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
@torounit
torounit / jQuery.semiMediaQuery.coffee
Last active December 22, 2015 15:38
ウィンドウサイズで、CSSを切り替えるのを実装するためのjQueryプラグイン。media queriesを使うほどでもない場合用。
do ($=jQuery) ->
$.fn.semiMediaQuery = (breakpoints) ->
@init = (breakpoints) =>
@breakpoints = breakpoints
@getElements()
@delegateEvents()
@setWidthClass()
@torounit
torounit / Game_of_Life.coffee
Last active December 23, 2015 09:19
ライフゲームをCoffeeScriptで書いてみた。CoffeeScriptの練習用。両端でループします。無駄にjQueryプラグインになってます。
class Game_of_Life
#
# @CELL_SIZE セルの大きさ
# @BORAD_SIZE マスの数
# @FPS = FPS
#
constructor:( canvas, @CELL_SIZE = 10,@BORAD_SIZE = 100,@FPS = 50 ) ->
@timer
@memory = @createMemory()
@torounit
torounit / config.json
Last active December 24, 2015 11:39
Sublime textの設定。 あと、nodebrewでnode.js coffee-scriptとか管理してます。 sassとかCompassはCodekitを使っていますが、今ならhttp://alphapixels.com/prepros/とかでいいと思います。
{
"autoReloadChanged": true,
"blod_folder_labels": true,
"close_windows_when_empty": false,
"draw_white_space": "all",
"font_size": 13,
"highlight_line": true,
"ignored_packages":
[
"Vintage",