原因
Wordに挿入して投稿した画像のpost_mime_type
がimage/jpg
になるため
PHP
1if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
2 $nonce = wp_create_nonce( "image_editor-$post->ID" );
3 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
4}
で引っかかり編集ボタンが表示されない。
そして編集可能なファイル形式は以下の3つだけとなっている。
(通常は拡張子がjpg
のファイルをアップロードしてもjpeg
になるのでimage/jpg
を含める必要がなく且つそこまで想定していないからだと思われる)
PHP
1switch ( $mime_type ) {
2 case 'image/jpeg':
3 return ( $image_types & IMG_JPG ) != 0;
4 case 'image/png':
5 return ( $image_types & IMG_PNG ) != 0;
6 case 'image/gif':
7 return ( $image_types & IMG_GIF ) != 0;
8}
対策
少々強引だが、画像が追加された際にpost_mime_type
を確認してimage/jpg
だったらimage/jpeg
に強制的に書き換えてしまう。
以下のコードをテーマのfunctions.phpに追加するかプラグイン化
PHP
1add_action( 'add_attachment', function( $post_ID ){
2 $attachment_data = get_post( $post_ID );
3 if( $attachment_data->post_mime_type === 'image/jpg' ) {
4 $my_attachment = array(
5 'ID' => $post_ID ,
6 'post_mime_type' => 'image/jpeg'
7 );
8 wp_update_post( $my_attachment );
9 }
10} );
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/15 04:33