php 说明如何提取wp_prepare_attachment_for_js()返回的附件详细信息。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 说明如何提取wp_prepare_attachment_for_js()返回的附件详细信息。相关的知识,希望对你有一定的参考价值。

<?php

/**
 * Illustrates how to extract attachment details returned by wp_prepare_attachment_for_js().
 *
 * The wp_prepare_attachment_for_js() function returns an array with the attachment post object
 * that can be used to extract specific information for the attachment.
 *
 * Following is a list of all the details that the function returns extrated into individual variables.
 *
 * @author	Alexis J. Villegas <alexis@ajvillegas.com>
 * @link	https://developer.wordpress.org/reference/functions/wp_prepare_attachment_for_js/
 */

// Get attachment details ($attachment_id = attachment ID or object)
$attachment = wp_prepare_attachment_for_js( $attachment_id );

// Attachment ID
$id = $attachment['id'];

// Attachment title
$title = $attachment['title'];

// Attachment file name
$filename = $attachment['filename'];

// Attachment URL
$url = $attachment['url'];

// Link to attachment page
$link = $attachment['link'];

// Attachment alt text
$alt = $attachment['alt'];

// Attachment author ID
$author = $attachment['author'];

// Attachment description
$description = $attachment['description'];

// Attachment caption
$caption = $attachment['caption'];

// Attachment name (no file extension)
$name = $attachment['name'];

// Attachment post status
$status = $attachment['status'];

// Attachment post parent
$uploadedTo = $attachment['uploadedTo'];

// Date attachment was uploaded in Unix timestamp format
$date = $attachment['date'];

// Date attachment was last modified in Unix timestamp format
$modified = $attachment['modified'];

// Attachment menu order parameter
$menuOrder = $attachment['menuOrder'];

// Attachment MIME type (type/subtype)
$mime = $attachment['mime'];

// Attachment file type (e.g., image)
$type = $attachment['type'];

// Attachment file subtype (e.g., jpeg)
$subtype = $attachment['subtype'];

// Attachment icon URL
$icon = $attachment['icon'];

// Formatted date when attachment was uploaded
$dateFormatted = $attachment['dateFormatted'];

// An array containing each nonce
$nonces = $attachment['nonces'];

// Attachment edit link URL
$editLink = $attachment['editLink'];

// Attachment meta
$meta = $attachment['meta'];

// Attachment author name
$authorName = $attachment['authorName'];

// Attachment file size in bytes
$filesizeInBytes = $attachment['filesizeInBytes'];

// Attachment file size
$filesizeHumanReadable = $attachment['filesizeHumanReadable'];

// Attachment height (in pixels)
$height = $attachment['height'];

// Attachment width (in pixels)
$width = $attachment['width'];

// Attachment orientation
$orientation = $attachment['orientation'];

// An sub-array containing details for each size
$sizes = $attachment['sizes'];

// Attachment 'medium' size height (replace 'medium' with name of attachment size)
$size_medium_height = $attachment['sizes']['medium']['height'];

// Attachment 'medium' size width (replace 'medium' with name of attachment size)
$size_medium_width = $attachment['sizes']['medium']['width'];

// Attachment 'medium' size URL (replace 'medium' with name of attachment size)
$size_medium_url = $attachment['sizes']['medium']['url'];

// Attachment 'medium' size orientation (replace 'medium' with name of attachment size)
$size_medium_orientation = $attachment['sizes']['medium']['orientation'];

以上是关于php 说明如何提取wp_prepare_attachment_for_js()返回的附件详细信息。的主要内容,如果未能解决你的问题,请参考以下文章

如何使用PHP读取文本文件内容

PHP cURL,提取 XML 响应

如何从 PHP 文件中提取 HTML?

php 如何在PHP中获取(提取)文件扩展名?

如何使用 PHP 从图像中提取文本

如何使用 php 从 HTML 表中提取数据