Skip to content

Instantly share code, notes, and snippets.

View fumikito's full-sized avatar
🐕
Have 1 dog. Her name is Packing.

Takahashi Fumiki fumikito

🐕
Have 1 dog. Her name is Packing.
View GitHub Profile
@fumikito
fumikito / single.php
Created December 16, 2015 09:46
Add term meta example
<?php
the_post();
/**
* Get color function.
*
* Get term meta on loop is little bit annoying.
* You should define some wrapper function.
*/
function get_color($tag){
@fumikito
fumikito / git_diff
Last active September 1, 2015 05:02
Archive files between 2 commits on Git repository
#!/usr/bin/env php
<?php
if( isset( $argv[1] ) && preg_match('/(-{1,2})?help$/', $argv[1] ) ) {
echo <<<'TXT'
/**
* Archive git diff file between specified commit
*
* git_diff ./archive 29879823c HEAD
*
* Enter above, diff between HEAD and 29879823c will be arvhived to `./archive`.
@fumikito
fumikito / gist:f401882937243564bdb1
Created June 17, 2015 12:15
ePubの目次サンプル
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" class="blog logged-in epub-toc rtl"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="UTF-8"/>
<title> 目次</title>
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" href="../Asset/wp-content/themes/hametuha/assets/css/epub.css" type="text/css"/>
</head>
@fumikito
fumikito / wp-cli-table-display.php
Created May 13, 2015 10:01
Show table on WP_CLI
<?php
$table = new \cli\Table();
$table->setHeaders( $header );
$table->setRows( $body );
$table->display();
@fumikito
fumikito / wpdb−test.php
Created December 8, 2014 16:32
wpdb道場第一回目
<?php
// これでWordPress関数がほとんど使えるようになる!
include 'wp-load.php';
// オプションを10件取得
$options = $wpdb->get_results("SELECT * FROM {$wpdb->options} LIMIT 10");
// 公開済み投稿の本文の長さを全部足す
$query = <<<SQL
SELECT SUM(CHAR_LENGTH(post_content))
@fumikito
fumikito / mecab.php
Last active May 2, 2023 22:35
PhpStormのプロジェクト内に入れておくとphp-mecabのコード補完ができる魔法のファイル
<?php
/**
* The MeCab PHP extension
*
* Copyright (c) 2006-2012 Ryusuke SEKIYAMA. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
@fumikito
fumikito / wp-pagenavi_bootstrap.php
Last active December 12, 2015 16:34
WordPressのWP-Pagenaviが返すHTMLをTwitter Bootstrapに合ったものに変更する
<?php
/**
* Change WP-Pagenavi's output
*
* @package hametuha
* @filter wp_pagenavi
* @param string $html
* @return string
*/
@fumikito
fumikito / lsf-to-scss.php
Created January 23, 2014 07:28
Ligature Symbolsのフォントをfont-awesomeライクなSCSSに返還するスクリプト - HTMLのテーブルをコピーしてテキストファイルに貼付け - Excelに貼付け後、TSVに書き出し - そのtsvと同階層で実行
<?php
$file = explode("\n", file_get_contents('./lsf.txt'));
$variables = [];
$sass = [];
foreach($file as $row){
list($title, $aliases, $unicode) = array_map('trim', explode("\t", trim($row)));
$title = 'lsf-'.$title;
@fumikito
fumikito / try-catch.php
Created January 19, 2014 04:33
catchブロックの中でエラーを投げてみる
<?php
/**
* catchブロックの中でエラーを投げてみる
*
* php try-catch.php 1000と入力すると、
* Uncaught exceptionが発生。したがって、こういうことをやりたい場合は
* 入れ子にしないとダメ。
* 結果的に、例外の種類が増えると入れ子がどんどん深くなっていく
* 5.5ならfinally があるので、もうちょっとすっきりできる
*/
@fumikito
fumikito / insert-to-wp-editor.js
Last active December 29, 2015 19:48
WordPressのエディタに対してiframe内からテキスト要素を追加ビジュアルエディタかHTMLエディタかを判別しつつ、最後にカーソルがあった位置に挿入する。ついでにthickboxを閉じる
jQuery(document).ready(function($){
// ショートコード挿入
$('.button-shortcode').click(function(e){
e.preventDefault();
// ex. ショートコードの値
var shortcode = $(this).prev('input').val(),
mce = window.parent.tinyMCE;
if( mce.activeEditor && !(mce.activeEditor.isHidden()) ){
// TinyMCEがオープンならそれを使う
window.parent.tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, shortCode )