Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Making time to write a novel.

Takahashi Fumiki fumikito

💭
Making time to write a novel.
View GitHub Profile
@fumikito
fumikito / block-editor-modal.js
Last active Nov 28, 2020
Force something in block editor and change post title programatically
View block-editor-modal.js
/*!
* Force post title to include "WordPress"
*
* @deps wp-data, wp-dom-ready, wp-element, wp-components
*/
const { data, domReady } = wp;
const { render, Component } = wp.element;
const { Modal, Button, TextControl } = wp.components;
@fumikito
fumikito / block-editor-notice.js
Created Nov 27, 2020
Display notice depending on the contents in WordPress block editor
View block-editor-notice.js
/*!
* Test document.
*
* @deps wp-data, wp-dom-ready
*/
const { data, domReady } = wp;
const wordLimiter = {
80: false,
@fumikito
fumikito / gianism-login-button.php
Created Oct 19, 2020
Change label for Gianism login button
View gianism-login-button.php
<?php
/**
* Gianismのログインボタンのラベルを変更
*
* @param string $label
* @param bool $register
* @param string $context
* @return string
*/
add_filter( 'gianism_login_button_label', function( $label, $register, $context ) {
@fumikito
fumikito / lazy-load-images.php
Last active Mar 16, 2020
Add lazy attributes to all img tags in WordPress.
View lazy-load-images.php
<?php
/**
* Add loading="lazy" and decodiing="async"
*
* @see https://spelldata.co.jp/blog/blog-2019-12-19.html
*/
/**
* Start buffer for img attributes.
*/
@fumikito
fumikito / hide-cf7.php
Created Feb 27, 2020
Hide recaptcha v3 on every page with Contact Form 7
View hide-cf7.php
<?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 Jan 23, 2020
Arguments of WordPress post and taxonomy labels to copy & paste.
View regisgter_post_or_taxonomy_labels.php
<?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 Sep 30, 2019
Import theme unit test data from WP-CLI.
View wp-import.sh
#!/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
View maisu.php
#!/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 Jun 19, 2018
さくらインターネットのレンタルサーバーでやること
View setup.sh
# シェル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 Apr 16, 2018
Hide specific attachments from media library.
View hide_from_media_library.php
<?php
/**
* Hide specific media from media library.
*/
/**
* Case 1. Do not allow gif.
*
* This filter will be triggered by media library's AJAX action.
*
You can’t perform that action at this time.