Skip to content

Instantly share code, notes, and snippets.

View torounit's full-sized avatar

Hiroshi Urabe torounit

View GitHub Profile
<?php
class SampleTest extends WP_UnitTestCase {
function test_sample() {
$args = array(
'public' => true,
'label' => 'Books'
);
@torounit
torounit / functions.php
Created October 22, 2015 04:17
wp_nav_menu で出力される li タグに任意の class を設定する。
<?php
add_filter( 'nav_menu_css_class', function ( $classes, $item, $args ) {
if ( ! empty( $args->li_class ) ) {
$classes[] = $args->li_class;
}
return $classes;
}, 10, 3 );
@torounit
torounit / Auto_Terms_By_Date.php
Created November 30, 2015 09:31
タクソノミーをカスタムフィールドの日付を参照して自動設定する。イベント系の奴に使える。
<?php
/**
* Created by PhpStorm.
* User: torounit
* Date: 15/03/06
* Time: 11:03
*
* Taxonomy Decorator.
*/
@torounit
torounit / run-httpd-as-ec2-user.sh
Last active December 22, 2015 06:56
run-httpd-as-ec2-user-for-http2
#!/usr/bin/env bash
set -e
echo '{
"nginx" : { "http2_enable" : true, "config" : { "user" : "ec2-user" } },
"php" : { "config" : { "user" : "ec2-user" } },
"hhvm" : { "enabled" : true, "config" : { "user" : "ec2-user" } },
"run_list" : [ "recipe[amimoto]" ]
}' > /opt/local/amimoto.json
@torounit
torounit / getposts-by-jsonp.js
Last active December 11, 2015 06:22
WP REST API で JSONP
var list = $('<ul />');
var request = $.getJSON('http://torounit.com/wp-json/wp/v2/posts?_jsonp=?')
request.done(function(data){
data.forEach(function(row){
var item = $('<li>');
var content = $('<a />').text(row.title.rendered).attr('href', row.link);
item.append(content);
list.append(item);
});
@torounit
torounit / functions.php
Created December 16, 2015 05:37
WordPress 4.4 で 固定フロントページの時に、固定ページのタイトルが<title>に出力されるようになったのを戻す。
<?php
add_filter( 'document_title_parts', function ( $title ) {
if ( is_front_page() ) {
unset( $title['title'] );
$title['tagline'] = get_bloginfo( 'description', 'display' );
}
return $title;
} );
(function($){
$(function(){
var $target = $('.target');
$('.event-target').hover(
function(){
$target.addClass('hoge');
},
function(){
$target.removeClass('hoge');
#!/bin/sh
service monit stop
service nginx stop
docker run -it --rm -p 443:443 --name letsencrypt -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/lib/letsencrypt:/var/lib/letsencrypt" quay.io/letsencrypt/letsencrypt:latest certonly -d exmample.com -m [email protected] --agree-tos --standalone --renew-by-default
service nginx start
service monit start
@torounit
torounit / wp_setup_nav_menu_item_hotfix.php
Last active February 13, 2016 11:55
wp_setup_nav_menu_item の Hotfix
<?php
add_filter('wp_setup_nav_menu_item', function( $menu_item ) {
if ( isset( $menu_item->post_type ) ){
if( 'post_type_archive' == $menu_item->type ) {
$object = get_post_type_object( $menu_item->object );
$post_content = wp_trim_words( $menu_item->post_content, 200 );
$menu_item->description = '' == $post_content ? $object->description : $menu_item->post_content;
}
@torounit
torounit / create-dist-branch.sh
Last active February 21, 2016 15:32
create-dist-branch.sh
git checkout --orphan dist
git rm -rf .
touch .gitkeep
git add .gitkeep
git commit -a -m "dist branch init"
git push origin dist