WordPress为JS准备附件对象函数:wp_prepare_attachment_for_js

WordPress函数wp_prepare_attachment_for_js为JS准备附件对象,包含了附件的所有信息。

wp_prepare_attachment_for_js( int|WP_Post $attachment )

函数参数

$attachment

整数或WP_Post对象

附件的ID或对象

函数返回值

Array
(
    [id] => 3163
    [title] => baidusrf-for-linux
    [filename] => baidusrf-for-linux.webp
    [url] => https://www.beizigen.com/wp-content/uploads/2020/05/baidusrf-for-linux.webp
    [link] => https://www.beizigen.com/post/baidu-ime-for-linux-released/baidusrf-for-linux
    [alt] => 替代文本
    [author] => 1
    [description] => 
     => 百度输入法Linux版
    [name] => baidusrf-for-linux
    [status] => inherit
    [uploadedTo] => 2895 //父ID
    [date] => 1601856000
    [modified] => 1601856000
    [menuOrder] => 0
    [mime] => image/webp
    [type] => image
    [subtype] => webp
    [icon] => https://www.beizigen.com/wp-includes/images/media/default.png
    [dateFormatted] => 2020年10月05日
    [nonces] => Array
        (
            [update] => 
            [delete] => 
            [edit] => 
        )

    [editLink] => 
    [meta] => 
    [authorName] => admin
    [authorLink] => 
    [uploadedToTitle] => 百度输入法Linux版
    [uploadedToLink] => 
    [filesizeInBytes] => 22528
    [filesizeHumanReadable] => 22 KB
    [context] => 
    [height] => 430
    [width] => 768
    [orientation] => landscape
    [sizes] => Array
        (
            [thumbnail] => Array
                (
                    [height] => 200
                    [width] => 320
                    [url] => https://www.beizigen.com/wp-content/uploads/2020/05/baidusrf-for-linux-320x200.webp
                    [orientation] => landscape
                )

            [full] => Array
                (
                    [url] => https://www.beizigen.com/wp-content/uploads/2020/05/baidusrf-for-linux.webp
                    [height] => 430
                    [width] => 768
                    [orientation] => landscape
                )

        )

)

扩展阅读

wp_prepare_attachment_for_js()函数位于:wp-includes/media.php

相关函数:

  • get_media_states()
  • wp_get_original_image_url()
  • wp_get_original_image_path()
  • wp_ajax_media_create_image_subsizes()
  • wp_ajax_crop_image()
  • wp_ajax_upload_attachment()
  • wp_ajax_get_attachment()
阿里云