[WordPress]Gutenbergでカテゴリ、タグが表示されないetc

対処法3パターン
・カスタム投稿タイプ、カスタムタクソノミーの設定で「show_in_rest = true」にする。
・index.php、.htaccessを適切に設置出来ているか確認する。
・DBを直接書き換えて下記のようなプロトコル、ドメインを含めないアドレスを設定している時、
投稿編集画面でtinymce.jsが読み込めていないため

WordPress アドレス (URL)「/manage」
サイトアドレス (URL)「/」

/manage/.htaccessに下記を追記する

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^manage/(.+)$ /manage/$1 [L]
</IfModule>

[PHP]copy_image_with_suffix

function copy_image_with_suffix($guid,$suffix)
{
    $upload_dir = $this->get_upload_dir();
    $o_image = dirname($upload_dir) . DIRECTORY_SEPARATOR . ltrim($guid,'/');
    $new_image = dirname($upload_dir)  . DIRECTORY_SEPARATOR . ltrim($this->add_suffix_to_filename($guid, $suffix),'/');
    if(!file_exists($o_image)) {
        $o_image = mb_convert_encoding($o_image, 'CP932', 'UTF-8');
        $new_image = mb_convert_encoding($new_image, 'CP932', 'UTF-8');
    }

    if (file_exists($new_image))
        unlink($new_image);

    $success = copy($o_image, $new_image);
    return $success;
}
public function add_suffix_to_filename($filename = '',$suffix = '')
{
    if(empty($filename))
        return '';
    return preg_replace('/\.(.{3,4})$/',"{$suffix}.$1",$filename);
}

[JavaScript]getDateStrByFormat

getDateStrByFormat(format,d,defaultValue){
    if(typeof d == 'string'){
        d = this.getDateByYYYYMMDD(d);
    }
    if(!d){
        if(defaultValue != undefined && defaultValue != null){
            return defaultValue;
        }else{
            d = new Date();
        }
    }
    if(!format){
        format = 'Y-m-d';
    }
    const _pz = function(v,digits){
        var vs = v.toString();
        while(vs.length < digits){
            vs = '0' + vs;
        }
        return vs;
    };
    return format
        .replace(/Y/g,d.getFullYear())
        .replace(/y/g,d.getFullYear().toString().substr(2,2))
        .replace(/n/g,d.getMonth()+1)
        .replace(/m/g,_pz(d.getMonth()+1,2))
        .replace(/j/g,d.getDate())
        .replace(/d/g,_pz(d.getDate(),2))
        .replace(/G/g,d.getHours())
        .replace(/H/g,_pz(d.getHours(),2))
        .replace(/i/g,_pz(d.getMinutes(),2))
        .replace(/s/g,_pz(d.getSeconds(),2))
        .replace(/J/g,['日','月','火','水','木','金','土'][d.getDay()])
        .replace(/D/g,['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][d.getDay()]);
}

[WordPress]delete_all_transient

public function delete_all_transient()
{
    global $wpdb;
    $sql = "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_%');";
    $result = $wpdb->get_results($sql);
    $sql = "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_site_transient_%');";
    $result = $wpdb->get_results($sql);
}

[PHP]unzip

public function unzip($file,$to)
{
    $zip = new ZipArchive();
    $result = $zip->open($file);
    if($result === true){
        $result = $zip->extractTo($to);
        $zip->close();
    }
    return $result === true;
}

[MySQL]50音判定

REGEXPはマルチバイトに対応していないので、FIND_IN_SETを使用。

INSERT INTO xxx(initial_chara,gyo)
(
SELECT
SUBSTRING(tmp.name,1,1),
(CASE
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'あ,い,う,え,お') THEN 'あ'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'か,き,く,け,こ,が,ぎ,ぐ,げ,ご') THEN 'か'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'さ,し,す,せ,そ,ざ,じ,ず,ぜ,ぞ') THEN 'さ'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'た,ち,つ,て,と,だ,ぢ,づ,で,ど') THEN 'た'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'な,に,ぬ,ね,の') THEN 'な'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'は,ひ,ふ,へ,ほ,ば,び,ぶ,べ,ぼ') THEN 'は'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'ま,み,む,め,も') THEN 'ま'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'や,ゐ,ゆ,ゑ,よ') THEN 'や'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'ら,り,る,れ,ろ') THEN 'ら'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'わ,を,ん') THEN 'わ'
ELSE 'ん' END
)
FROM yyy AS tmp

[CodeIgniter]get_table_names_by_dbname

$this->db->list_tables();

上記だとキャッシュから取得する。キャッシュを回避する場合下記を使用。

public function get_table_names_by_dbname($dbname)
{
    $names = array();
    $sql = "SHOW TABLES FROM {$dbname}";
    $query = $this->db->query($sql);
    foreach ($query->result_array() as $row)
    {
        if ( ! isset($key))
        {
            if (isset($row['table_name']))
            {
                $key = 'table_name';
            }
            elseif (isset($row['TABLE_NAME']))
            {
                $key = 'TABLE_NAME';
            }
            else
            {
                $key = array_keys($row);
                $key = array_shift($key);
            }
        }

        $names[] = $row[$key];
    }
    return $names;
}

[CodeIgniter]set_header

$this->output->set_header('X-Frame-Options: SAMEORIGIN');
$this->output->set_header('Cache-control: no-cache, no-store, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header('Expires: Thu, 01 Dec 1994 16:00:00 GMT');

[PHP]zip

public function zip($zipfile,$add_file)
{
    $zip = new ZipArchive();
    $result = $zip->open($zipfile, ZipArchive::CREATE);
    if($result === true)
    {
        $zip->addFile($add_file);
        $result = $zip->close();
    }
    return $result === true;
}