开发者

how to get the Media Settings wordpress

I wanted to pull the settings found for Media settings (thumbnail, med开发者_Go百科ium and large declared sizes) into my template. How do I do it, I cannot seem to find on Wordpress API, or maybe I didn't search quite well.

Thanks


There does not appear to be a special set of functions to retrieve these, but they are saved in the options table, so with a little bit of effort we can retrieve all those values.

Image Sizes

For the image dimension settings, you should be able to get these from the options table. The default sizes are 'medium', 'thumbnail', 'large', and 'post-thumbnail'. Keep in mind that crop only exists for thumbnails, and that it is a checkbox.

To get dimensions do the following:

$thumbnail_size = array (
    'width' = get_option('thumbnail_size_w'),
    'height'= get_option('thumbnail_size_h'),
    'crop' = get_option('thumbnail_crop')
);
$medium_size = array (
    'width' = get_option('medium_size_w'),
    'height'= get_option('medium_size_h')
);
$large_size = array (
    'width' = get_option('large_size_w'),
    'height'= get_option('large_size_h')
);

Embeds

Keep im mind that auto refers to whether or not to use oEmbed to auto embed media when people paste in a url.

$embeds = array(
    'auto' => get_option('embed_autourls'),
    'width'=> get_option('embed_size_w'),
    'height' => get_option('embed_size_h')
);

Uploading Files

The upload path is relative to ABSPATH (that is to say, it can not be outside the WordPress root directory - there is also a constant 'UPLOADS' that can change this setting. Keep in mind that the Year/Month option is another checkbox.

$upload_path = array(
    'path' => get_option('upload_path'),
    'url_path' => get_option('upload_url_path'),
    'yearmonth_folders' => get_option('uploads_use_yearmonth_folders')
);

If we wanted to put this together as one big function for easy use...

/**
 * Returns settings from the Media Settings page.
 *
 * @author Eddie Moya
 * @param string $option (Optional) The key for the particular set of options wanted.
 *
 * @return array Returns a set of specific options if $options is set, otherwise returns all optons.
 */
function get_media_settings($option = null){

    $thumbnail_size = array (
        'width' = get_option('thumbnail_size_w'),
        'height'= get_option('thumbnail_size_h'),
        'crop' = get_option('thumbnail_crop')
    );
    $medium_size = array (
        'width' = get_option('medium_size_w'),
        'height'= get_option('medium_size_h')
    );
    $large_size = array (
        'width' = get_option('large_size_w'),
        'height'= get_option('large_size_h')
    );

    $embeds = array(
        'auto' => get_option('embed_autourls'),
        'width'=> get_option('embed_size_w'),
        'height' => get_option('embed_size_h')
    );

    $upload_path = array(
        'path' => get_option('upload_path'),
        'url_path' => get_option('upload_url_path'),
        'yearmonth_folders' => get_option('uploads_use_yearmonth_folders')
    );


    $settings = array(
        'thumbnail_size' => $thumbnail_size,
        'medium_size' => $medium_size,
        'large_size' => $large_size,
        'embed_size' => $embeds,
        'upload_path' => $upload_path
    );

    if(!empty($option)){
        return $settings[$option];
    else
        return $settings;
}

You are of course free or organize all that data however you want, this is just an example. You can obviously also just directly get the options you want, although it might be annoying to have to remember all their names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜