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 / hide-cf7.php
Created February 27, 2020 10:47
Hide recaptcha v3 on every page with Contact Form 7
<?php
/**
* Remove recaptcha if it's not contact form.
*/
add_action( 'wp_enqueue_scripts', function() {
if ( is_singular() && has_shortcode( get_queried_object()->post_content, 'contact-form-7' ) ) {
return;
}
wp_deregister_script( 'google-recaptcha' );
@fumikito
fumikito / regisgter_post_or_taxonomy_labels.php
Created January 23, 2020 06:56
Arguments of WordPress post and taxonomy labels to copy & paste.
<?php
$post_labels = [
'name' => __( '', 'domain' ),
'singular_name' => __( '', 'domain' ),
'add_new' => __( '', 'domain' ),
'add_new_item' => __( '', 'domain' ),
'edit_item' => __( '', 'domain' ),
'new_item' => __( '', 'domain' ),
'view_item' => __( '', 'domain' ),
'view_items' => __( '', 'domain' ),
@fumikito
fumikito / wp-import.sh
Created September 30, 2019 08:08
Import theme unit test data from WP-CLI.
#!/usr/bin/env bash
set -e
# Activate WP Importer plugin.
wp plugin install wordpress-importer --activate
# Don't know why, but failed importing directly.
wget https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml
# Import
wp import themeunittestdata.wordpress.xml --authors=create
#!/usr/bin/env php
# 利用方法
# 1. このファイルをホームフォルダなどのパスが通っている場所に maisu として保存します。
# wget https://gist.githubusercontent.com/fumikito/5496923ec71e4cc891f263029be79dec/raw/6154450c6a547d14522a2ee7aa6ffd438fcfe3b7/maisu.php -O ~/bin/maisu
# 2. 実行権限を付与します。
# chmod +x maisu
# 3. ファイルを指定して実行します。
# maisu example.txt
# => 400字詰原稿用紙(20字×20行)換算で1枚(12行)です。
#
@fumikito
fumikito / setup.sh
Last active June 19, 2018 06:52
さくらインターネットのレンタルサーバーでやること
# シェルBashに変更(要パスワード入力)
chsh -s /usr/local/bin/bash
echo "export LANG=ja_JP.UTF-8" >> .bash_profile
source .bash_profile
# 鍵認証(コピペ)
vim ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# コマンドインストール
@fumikito
fumikito / hide_from_media_library.php
Created April 16, 2018 08:09
Hide specific attachments from media library.
<?php
/**
* Hide specific media from media library.
*/
/**
* Case 1. Do not allow gif.
*
* This filter will be triggered by media library's AJAX action.
*
@fumikito
fumikito / short-code-template.php
Created February 3, 2018 16:44
Template file shortcode
<?php
/**
* Register shortcode [my-template]
*
* File based short code.
*
* @param array $atts Shoutcode attribures.
* @param string $string Content wrapped in shortcode.
* @return string Rendered result.
*/
@fumikito
fumikito / backup-wp.sh
Created February 2, 2018 06:15
Backup statics of WordPress
#
# Backup WordPress contents.
#
set -e
# Move to WordPress dir
cd /var/www/wordpress
# Remove if exists.
@fumikito
fumikito / fb-message-parse.php
Created August 25, 2017 15:18
Parse facebook message from archived data
<?php
# composer require sunra/php-simple-html-dom-parser
require __DIR__ . '/vendor/autoload.php';
// Change file size because fb message archive is very big data.
define( 'MAX_FILE_SIZE', 1000000000 );
$dom = Sunra\PhpSimple\HtmlDomParser::file_get_html( 'messages.htm' );
$messages = [];
@fumikito
fumikito / backlog-deploy.php
Last active August 23, 2017 04:26
BacklogのWebフックを受け取って、テーマをビルドする
<?php
// パスを設定。なぜかこれがないと動かず。
putenv('PATH=/home/ec2-user/.nvm/versions/node/v6.11.0/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin');
//リリースするブランチの指定
$deploy_ref = 'refs/heads/master';
//logファイルの指定
$log_path = '/var/www/wordpress/wp-content/git.log';