Skip to content

Instantly share code, notes, and snippets.

@wokamoto
wokamoto / WP-high-P183-P184-fix
Created April 14, 2012 21:55
WordPress 高速化&スマート運用必携ガイド P183〜P184 修正
#
# The default server
#
server {
listen 80;
server_name _;
root /var/www/html;
index index.html index.htm index.php;
charset utf-8;
@wokamoto
wokamoto / wp_get_social_counts.php
Created April 25, 2012 01:43
WordPress で記事のツイート数を取得する
<?php
/*
* Get Social Button Count twitter
*/
function get_social_counts( $url ){
$transient_key = md5('get_social_counts-' . $url);
// get cache
if ( false === ($counts = get_transient($transient_key)) ) {
$counts = array();
@wokamoto
wokamoto / nginxchampuru_get_cache.php
Created June 5, 2012 05:26
Nginx Cache Controller ver.1.1.2+ で、標準以外の URL キャッシュを削除する方法
<?php
add_filter('nginxchampuru_get_cache', 'nginxchampuru_get_cache', 10, 2);
function nginxchampuru_get_cache($key, $url = null) {
global $nginxchampuru;
if (!$url) {
$url = $nginxchampuru->get_the_url();
}
$keys = array(
$key,
$nginxchampuru->get_cache_key($url.'@ktai'),
@wokamoto
wokamoto / dec_to_n.php
Created June 8, 2012 03:46
62進数生成
<?php
function dec_to_n( $dec, $n = 62, $disits = null ) {
if ( !$disits ) {
$disits = array(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
@wokamoto
wokamoto / get_tweet_lines.php
Last active October 7, 2015 00:08
Twitterのツイートを表示する-RSS編
<?php
function get_tweet_lines($userName){
date_default_timezone_set('Asia/Tokyo');
$rssUrl = 'http://twitter.com/statuses/user_timeline/'.$userName.'.rss';
// get cache
if ( ($response = get_transient(md5($rssUrl))) === false ) {
$response = wp_remote_get($rssUrl);
if( !is_wp_error( $response ) && $response["response"]["code"] === 200 ) {
set_transient(md5($rssUrl), $response, 60 * 60 ); // 60sec * 60min = 1hour
@wokamoto
wokamoto / functions.php
Created August 20, 2012 06:52
thematic の子テーマ用
<?php
/**
* Create the post footer
*
* Override: childtheme_override_postfooter <br>
* Filter: thematic_postfooter
*/
function childtheme_override_postfooter() {
$post_type = get_post_type();
@wokamoto
wokamoto / just.php
Last active October 9, 2015 05:28
特定のプラグインを有効にするプラグイン
<?php
/*
Plugin Name: Just do it !
Plugin URI:
Description:
Version: 0.1
Author:
Author URI:
*/
new just_do_it();
@wokamoto
wokamoto / wp-custom-search.php
Last active August 30, 2018 03:26
WordPress でユーザー名とか、タグ名・カテゴリ名も検索対象に
<?php
function custom_search($search, $wp_query) {
global $wpdb;
//サーチページ以外だったら終了
if (!$wp_query->is_search)
return $search;
if (!isset($wp_query->query_vars))
return $search;
@wokamoto
wokamoto / nginx_cache_purge.php
Created August 29, 2012 15:21
簡易版 Nginx Cache Purge スクリプト
<?php
if ( isset($_GET['url']) ) {
$url = stripslashes($_GET['url']);
NginxCachePurge::purge($url);
}
Class NginxCachePurge {
const CACHE_LEVELS = '1:2';
const CACHE_DIR = '/var/cache/nginx/proxy_cache';
@wokamoto
wokamoto / aws.2012.09.04.txt
Created September 4, 2012 01:15
AWS メモ 2012.09.04
ec2-api-tools を Mac にインストール
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
unzip ec2-api-tools.zip
mkdir ~/ec2
mv ec2-api-tools-1.6.1.4//bin/ ~/ec2/
mv ec2-api-tools-1.6.1.4//lib/ ~/ec2/
export EC2_HOME=~/ec2
export PATH=$PATH:$EC2_HOME/bin