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 / 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 / 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 / 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 / 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 / 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 / get_template_part.php
Created December 21, 2015 03:59
Alternative of WordPress' get_template_part which can accept arguments.
<?php
/**
* A template loader which accepts arguments.
*
* @param string $slug
* @param string|array $name
* @param array $args Arguments to pass.
* @param bool $echo If false, return string.
* @param string $glue Default is '-'. You can specify '/' which means directory separator.
*
@fumikito
fumikito / pages-input.applescript
Created January 27, 2016 02:13
Interactive Pages input
on run {input, parameters}
tell application "Pages"
activate
open input
tell front document
-- GET ALL TAGS
set theseTags to the tag of every placeholder text
-- FILTER FOR UNIQUE TAGS
@fumikito
fumikito / change_user_meta.sql
Created March 21, 2016 08:30
間違ってたクエリを直す
update tweeter_usermeta set meta_key = 'tweeter_capabilities' where meta_key = 'wp_capabilities';
update tweeter_options set option_name = 'tweeter_user_roles' where option_name = 'wp_user_roles';
@fumikito
fumikito / login.php
Last active March 23, 2016 15:21
勝手にログイン
<?php
# ID1でログインする
include __DIR__.'/wp-load.php';
wp_set_auth_cookie(1);
header( 'Location: '.admin_url() );
exit;
@fumikito
fumikito / endpoint.php
Last active March 25, 2016 10:26
エンドポイント
<?php
//
// ここから書いていく
//
add_action( 'rest_api_init', function(){
register_rest_route( 'tweeter/v1', '/friends/(?P<user_id>[0-9]+)/?', [
[
'methods' => 'POST',
'callback' => function($params){