Skip to content

Instantly share code, notes, and snippets.

View waviaei's full-sized avatar
🤔

Toru Miki waviaei

🤔
View GitHub Profile
# 更新通知のメモ
## コアのアップデートの通知
- シングルサイトの場合
- administrator もしくは `current_user_can( 'update_core' )`
- `<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.`
- administrator 以外
- `<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.`
- マルチサイトの場合

WordPress マルチサイトのDBの移行手順

マルチサイトはシングルサイトと場合と違い、サイトのドメインやURLに関する設定項目が wp_options 以外にもあり、また、既に子サイトが1つ以上ある場合は複数サイト分の置換を行う必要があるため躓きやすいです。

下記は、ステージング https://example.test からからプロダクション https://example.com へDBを移行する事を想定した手順書です。 逆方向やローカル環境への移行にも使えますが、その際は適切なドメインを当てはめてください。

ポイントとしては:

  • サイトネットワーク全体及び各サイト全てのドメインとURLの設定はシリアラズされていないので、SQLでピンポイントに確実に変更する。
// Dequeue core's block library styles, only if Classic Editor plugin is in use.
add_action( 'wp_enqueue_scripts', function() {
if ( class_exists( 'Classic_Editor' ) ) {
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
}
} );
add_filter( 'wpseo_metadesc', function ($trim) {
if ( is_singular() ) {
if ( empty( $trim ) ) {
// If excerpt is empty, use core's auto-generate excerpt to put excerpt string back in to the var.
// 返ってきた抜粋が空白の場合、コアの自動抜粋・抜粋取得処理を使って抜粋を入れ直す.
$trim = get_the_excerpt();
// If you prefer to, additionally, trimm at "。" (full stop, if any), then you can do this instead of above.
// コアが作る自動抜粋の中に句点がもしあれば、句点の後は切り捨てたい場合.
@waviaei
waviaei / cache-control.php
Last active April 27, 2021 01:52
HTTP ヘッダーに Cache-Control ディレクティブを出力する例。
<?php
/**
* HTTP ヘッダーに Cache-Control ディレクティブを出力する例。
*/
add_action( 'template_redirect', function() {
// ログイン済みなら何もしない
if ( is_user_logged_in() ) {
return;
}
@waviaei
waviaei / block-list-in-md-table.txt
Created September 4, 2019 07:56
WordPress 5.2.2 のコアに含まれているブロックのリスト。課題管理サービス(Backlog 等)へコピペする事を想定:Wiki 記法、優先度カラムなど。「優先度」や○、△、×などは必要に応じて適当に書き勝てください。
## コアのブロック
○ =
△ =
× =
— =
●/▲ =
### 一般ブロック / Common
@waviaei
waviaei / gist:a89b1e7992b195914bb5364c04a7269b
Created February 20, 2019 08:06
Faster way to add comma, then delete the last one
// Categories
$start = microtime(true);
$cats = get_the_category();
if ( $cats ) {
foreach ( $cats as $cat ) {
$cat_list[] = '<a href="' . get_category_link( $cat->term_id ) . '">' . $cat->cat_name . '</a>';
}
}
/**
* Filters the list of category links to be displyaed on Post's entry meta
@waviaei
waviaei / functions.php
Last active September 3, 2018 02:46
Test different patterns of 'post_status' and 'perm' arguments set for query
/**
* Test different patterns of 'post_status' and 'perm' arguments set for query
* publish, pending, draft, auto-draft, future, private, inherit, trash, any
*/
// Add Shortcode
function status_permission_test_shortcode() {
// the query
$args = array(
'post_status' => array( 'publish' ),
# OS files
.DS_Store
Thumbs.db
# Dreamweaver
_notes/
dwsync.xml
*.LCK
* - Copy
* - コピー
@waviaei
waviaei / site.yml
Created May 14, 2015 05:34
site.yml for vccw
# encoding: utf-8
# vim: ft=ruby expandtab shiftwidth=2 tabstop=2
#
# General Settings
#
wp_box: miya0001/vccw
chef_cookbook_path: ./provision
#