CMS

[PHP]imagescale_output

public function imagescale_output($image_path,$save_path,$width,$height,$aspect_fill = true,$strict_size_on_aspect_fit = true,$space_color = array('r'=>255,'g'=>255,'b'=>255))
{
    if(!is_readable($image_path))
        return false;
    $o_img = $this->imagecreate($image_path);
    $o_w = imagesx($o_img);
    $o_h = imagesy($o_img);
    $w_ratio = $width / $o_w;
    $h_ratio = $height / $o_h;
    $ratio = $aspect_fill ? max($w_ratio,$h_ratio) : min($w_ratio,$h_ratio);
    $new_w = round($o_w * $ratio);
    $new_h = round($o_h * $ratio);
    if(function_exists('imagescale')){
        $new_img = imagescale($o_img,$new_w,$new_h);
    }else{
        $new_img = imagecreatetruecolor($new_w, $new_h);
        imagecopyresampled($new_img, $o_img, 0, 0, 0, 0, $new_w, $new_h, $o_w, $o_h);
    }
    
    $param = $aspect_fill ? array('x' => round(abs($width - $new_w) * 0.5), 'y' => round(abs($height - $new_h) * 0.5), 'width' => $width, 'height' => $height) : array('x' => 0, 'y' => 0, 'width' => $new_w, 'height' => $new_h);
    if(function_exists('imagecrop')) {
        $dest_img = imagecrop($new_img, $param);
    }else{
        $dest_img = imagecreatetruecolor($param['width'], $param['height']);
        imagecopy($dest_img, $new_img, 0, 0, $param['x'], $param['y'], $param['width'], $param['height']);
    }
    imagedestroy($new_img);
    if(!$aspect_fill && $strict_size_on_aspect_fit){
        $next_img = imagecreatetruecolor($width,$height);
        imagefill($next_img,0,0,empty($space_color) ? imagecolorat($dest_img,round($new_w*0.5),0) : imagecolorallocate($dest_img,$space_color['r'],$space_color['g'],$space_color['b']));
        imagecopy($next_img,$dest_img,round(abs($width - $new_w) * 0.5),round(abs($height - $new_h) * 0.5),0,0,$param['width'],$param['height']);
        $success = $this->imageoutput($next_img,$save_path);
        imagedestroy($o_img);
        imagedestroy($next_img);
        imagedestroy($dest_img);
    }else {
        $success = $this->imageoutput($dest_img, $save_path);
        imagedestroy($o_img);
        imagedestroy($dest_img);
    }
    return $success;
}

[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);
}

[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);
}

[MovableType]アーカイブマッピング:yyyymmdd_x.html

x
同じ日付の記事1つ目:1
同じ日付の記事2つ目:2

<mt:For regex_replace="/[\ \t\r\n]/mg","">
<mt:EntryDate format="%Y%m%d" setvar="current_entry_date" />
<mt:EntryID setvar="current_entry_id" />
<mt:EntryBlogID setvar="blog_id"/>
<mt:Blogs blog_ids="$blog_id">
<mt:Var name="count" value="1"/>
<mt:Var name="no" value="1"/>
<mt:Entries lastn="0" sort_by="authored_on" sort_order="ascend">
<mt:EntryDate format="%Y%m%d" setvar="entry_date" />
<mt:EntryID setvar="entry_id" />
<mt:If name="entry_date" eq="$current_entry_date">
<mt:If name="entry_id" eq="$current_entry_id"><mt:Var name="no" value="$count"/></mt:If>
<mt:SetVar name="count" op="++"/>
</mt:If>
</mt:Entries>
</mt:Blogs>
<mt:Var name="current_entry_date"/>_<mt:Var name="no"/>.html</mt:For>

[WordPress]テーブル接頭辞を変更

・wp-config.php

$table_prefix = 'dev_wp_';

$table_prefix = 'wp_';

へ変更

・下記を実行

ALTER TABLE dev_wp_commentmeta RENAME TO wp_commentmeta;
ALTER TABLE dev_wp_comments RENAME TO wp_comments;
ALTER TABLE dev_wp_links RENAME TO wp_links;
ALTER TABLE dev_wp_options RENAME TO wp_options;
ALTER TABLE dev_wp_postmeta RENAME TO wp_postmeta;
ALTER TABLE dev_wp_posts RENAME TO wp_posts;
ALTER TABLE dev_wp_term_relationships RENAME TO wp_term_relationships;
ALTER TABLE dev_wp_term_taxonomy RENAME TO wp_term_taxonomy;
ALTER TABLE dev_wp_usermeta RENAME TO wp_usermeta;
ALTER TABLE dev_wp_users RENAME TO wp_users;
ALTER TABLE dev_wp_terms RENAME TO wp_terms;
UPDATE wp_options SET option_name = 'wp_user_roles' WHERE option_name = 'dev_wp_user_roles';
UPDATE wp_usermeta SET meta_key = 'wp_capabilities' WHERE meta_key = 'dev_wp_capabilities';
UPDATE wp_usermeta SET meta_key = 'wp_user_level' WHERE meta_key = 'dev_wp_user_level';

[WordPress]Advanced Custom Fields: DB Field

Advanced Custom Fields: DB Field をリリースしました。
https://wordpress.org/plugins/acf-db-field/
https://github.com/ktyrnet/acf-db

ACFのアドオンなのでACFがインストールされている必要があります。
・任意のDB,テーブル,カラムを選択させるカスタムフィールドを追加出来ます。
・現在はWordPressと同じDBアカウントのDBにしか対応していません。

カスタムフィールド設定画面

投稿画面

[WordPress]EC2で現地時間が+9時間になる

AWS EC2上のWordPressにおいて
設定 > 一般 > タイムゾーン : 東京 の時、下記の症状が出る。
・世界標準時 (UTC) は “東京の時間” です。 現地時間は “東京の時間+9時間” です。
・記事を新規作成して「すぐに公開する」で公開しても、「予約済み」になる。

対処法
・SSHでサーバへ接続
・コマンド「sudo yum reinstall tzdata」
・コマンド「sudo service httpd restart」