2012年6月4日月曜日

記事に画像を連続して挿入できるようにする

記事に画像を追加する度に、メディア挿入の画面が閉じてしまうので、非常に効率が悪いです。

メディアアップロードを別ウィンドウに

/wp-admin/includes/media.php
        echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
        echo "<a href=\"javascript:w=window.open('" . str_replace('TB_iframe=1', 'TB_iframe=0', esc_url(get_upload_iframe_src())) . "','','scrollbars=yes,Width=650,Height=700,top=0,left=0');w.focus();\" id=\"add_image\" title='" . esc_attr__('Add Media') . "' onclick='return true;'><img src='images/media-button-image.gif' alt='' /></a>";
もしくはこっちでもいいかもしれません。
        echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
        echo "<a href=\"javascript:w=window.open('" . esc_url(get_upload_iframe_src()) . "','','scrollbars=yes,Width=650,Height=700,top=0,left=0');w.focus();\" id=\"add_image\" title='" . esc_attr__('Add Media') . "' onclick='return true;'><img src='images/media-button-image.gif' alt='' /></a>";

挿入した後に戻る

私は、Custom Field Templateプラグインを使用しているため、media_send_to_editorがフックされています。 そのため、修正するのは/wp-content/plugins/custom-field-template/custom-field-template.phpとなります。
        function media_send_to_custom_field($html) {
                $out =  '<script type="text/javascript">' . "\n" .
                                        '       /* <![CDATA[ */' . "\n" .
                                        '       var win = window.dialogArguments || opener || parent || top;' . "\n" .
                                        '   if ( typeof win.send_to_custom_field == "function" ) ' . "\n" .
                                        '           win.send_to_custom_field("' . addslashes($html) . '");' . "\n" .
                                        '   else ' . "\n" .
                                        '       win.send_to_editor("' . addslashes($html) . '");' . "\n" .
                    '   history.back();' . "\n" .
                                        '/* ]]> */' . "\n" .
                                        '</script>' . "\n";

                echo $out;
                exit();

history.back();を追加するということですね。 Good Luck!

0 件のコメント:

コメントを投稿