Skip to content

Instantly share code, notes, and snippets.

View ki6ool's full-sized avatar

ki6ool ki6ool

View GitHub Profile
@ki6ool
ki6ool / functions.php
Last active January 26, 2016 07:01
Wordpressでログを残して管理画面から見れるようにする
<?php
//ファイル名はご自由に
//ディスク容量気をつけてね
if ( WP_DEBUG_LOG ) ini_set('error_log', TEMPLATEPATH.'/log.php');
wp_log(array('テーマ編集からログを見れるようにするには' => '.phpにするのが最も容易。'));
function wp_log($message) {
if (WP_DEBUG === true) {
$message = ( is_array($message) ) print_r($message, true);
@ki6ool
ki6ool / gist:8f7d5d54deefa75ee190
Created November 9, 2015 10:42
Linuxコマンド備忘録
#CVSディレクトリ削除
$ rm -fr $(find ./ | grep "/CVS$")
#ファイル数
$ ls -1 | wc -l
#ディレクトリorファイルの容量
$ du -sh ./*
#300分以前に更新されたファイル一覧
@ki6ool
ki6ool / gist:f3bbcf66cd8f81fe214c
Created November 6, 2015 04:52
WordPressで独自のショートコードを追加
//標準のショートコードを削除する場合
remove_all_shortcodes();
/*
[p id='AAA']BBB[/p] to <p id="AAA">BBB</p>
*/
add_shortcode('p', function($atts, $content=''){
extract(shortcode_atts(array('id' => ''), $atts));
return "<p id=\"{$id}\">{$content}</p>";
});
@ki6ool
ki6ool / gist:f8e8aac3dd1d183862fa
Last active March 4, 2016 09:16
各SNSのJSをまとめて読み込むやつ
<script>
/**
* @link http://tokkono.cute.coocan.jp/blog/slow/index.php/xhtmlcss/asynchronous-loading-of-major-social-buttons/
*/
(function(w,d){
w.___gcfg={lang:"ja"};
var s,e = d.getElementsByTagName("script")[0],
a=function(u,f){if(!d.getElementById(f)){s=d.createElement("script");
s.src=u;if(f){s.id=f;}e.parentNode.insertBefore(s,e);}};
a("//b.st-hatena.com/js/bookmark_button.js");//hatena
@ki6ool
ki6ool / gist:393cbb032bb091011bea
Last active November 4, 2015 07:46
ajaxの際に使いそうなJavaScriptでのURL操作
// HTML5以降
// 履歴に#URL#を追加
history.pushState(null, null, '#URL#');
// 履歴を#URL#に書き換え
history.relpaceState(null, null, '#URL#');
// 戻るor進むイベントを取得
window.addEventListener('popstate', function(e) {
var path = location.pathname;
@ki6ool
ki6ool / gist:ca2e1420c8a59703bf1a
Last active November 4, 2015 07:46
GoogleAnalyticsを使ってクリック数を計測する
<a href="リンク先" onclick="javascript:ga('send', 'pageview', '識別名');">リンクテキスト</a>
@ki6ool
ki6ool / gist:4e2433a24a0a924bdc49
Last active November 4, 2015 07:46
Facebookのシェア数を取得
function get_social_count() {
var list = $(".fb .count").map(function(index, el) { return $(this) });
if ( !list ) return;
for (var i = 0; i < list.length; i++) {
var el_f = $(".fb .count:eq("+i+")");
var url = el_f.parents("li").children("a:eq(0)").attr("href");
get_count_fb(url, el_f);
}
}
@ki6ool
ki6ool / gist:c78ddd4537dc2533bd3c
Last active November 4, 2015 07:46
Opauthを使ってOAuthの実装
<?php
require_once '/to/path/Opauth/Opauth.php';
$config = array(
'security_salt' => '-----',
'path' => '/auth/',
'Strategy' => array(
'Twitter' => array(
'key' => '-----',
'secret' => '-----'
),
@ki6ool
ki6ool / gist:53c2f95b8f99350a4d7f
Last active November 6, 2015 05:02
xml to array
<?php
function xmlfile2array($filepath) {
if ( !file_exists($filepath) ) return false;
$xml = @simplexml_load_file($filepath);
return json_decode(json_encode($xml), true);
}
function xmlstr2array($str) {
$xml = @simplexml_load_string($str);
return json_decode(json_encode($xml), true);
@ki6ool
ki6ool / gist:b20cc1ab8db9f1a9fd37
Last active January 26, 2016 06:42
Wordpressで不要なのも削除したり変更したりするやつ
<?php
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
remove_action('wp_head', 'parent_post_rel_link', 10, 0);