blog.knym.net | I'm searching something to change my life.

WordPressのmedia画面で独自のフォーム項目を増やす

wp_image_url


スライドショー用の画像URLを取得できるフォームを設置してみた。



ファイルサイズは

http://your.blog.url.com/wp-admin/options-media.php

で設定でき、その中でlarge画像をスライドショー画像としてサイズを指定。


1. フォーム項目の追加


/wp-admin/includes/media.php
function get_attachment_fields_to_edit
の$form_fieldsに新しいフォームの記述を追加。


    $form_fields = array(
 ...
        ),
// add the form to see medium image file url.
        'file_url'          => array(
            'label'      => 'Slideshow Image URL',
            'input'      => 'html',
            'html'       => image_file_link_input_fields($post)
        ),
....


2. 出力したいフォーム項目のHTMLをつくるfunctionを追加


function image_file_link_input_fields($post) {
    $file = wp_get_attachment_url($post->ID);
    $path = pathinfo($file);
    $purl = parse_url($file);
// you can get sizes of thumbnail,medium and large.
    $downsize =image_downsize($post->ID, 'large');
    $size= sprintf( "%dx%d", $downsize[1], $downsize[2] );
    $url = $path['dirname'].'/'.$path['filename'].'-'.$size.'.'.$path['extension'];
    return "<input type='text' class='urlfield' name='attachments[$post->ID][file_url]' value='" . attribute_escape($url) . "' />";
}


media.phpはさまざまなファイル形式のアップロードに対応したコードが書かれているため、
読んでて勉強になるね。

Related Posts

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Essentials

Meta

Pages

Categories