本文整理汇总了PHP中wp_maybe_generate_attachment_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_maybe_generate_attachment_metadata函数的具体用法?PHP wp_maybe_generate_attachment_metadata怎么用?PHP wp_maybe_generate_attachment_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_maybe_generate_attachment_metadata函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_form_image_editor
/**
* Displays the image and editor in the post editor
*
* @since 3.5.0
*/
function edit_form_image_editor($post)
{
$open = isset($_GET['image-editor']);
if ($open) {
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
}
$thumb_url = false;
if ($attachment_id = intval($post->ID)) {
$thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 450), true);
}
$alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
$att_url = wp_get_attachment_url($post->ID);
?>
<div class="wp_attachment_holder">
<?php
if (wp_attachment_is_image($post->ID)) {
$image_edit_button = '';
if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
$nonce = wp_create_nonce("image_editor-{$post->ID}");
$image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
}
?>
<div class="imgedit-response" id="imgedit-response-<?php
echo $attachment_id;
?>
"></div>
<div<?php
if ($open) {
echo ' style="display:none"';
}
?>
class="wp_attachment_image" id="media-head-<?php
echo $attachment_id;
?>
">
<p id="thumbnail-head-<?php
echo $attachment_id;
?>
"><img class="thumbnail" src="<?php
echo set_url_scheme($thumb_url[0]);
?>
" style="max-width:100%" alt="" /></p>
<p><?php
echo $image_edit_button;
?>
</p>
</div>
<div<?php
if (!$open) {
echo ' style="display:none"';
}
?>
class="image-editor" id="image-editor-<?php
echo $attachment_id;
?>
">
<?php
if ($open) {
wp_image_editor($attachment_id);
}
?>
</div>
<?php
} elseif ($attachment_id && 0 === strpos($post->post_mime_type, 'audio/')) {
wp_maybe_generate_attachment_metadata($post);
echo wp_audio_shortcode(array('src' => $att_url));
} elseif ($attachment_id && 0 === strpos($post->post_mime_type, 'video/')) {
wp_maybe_generate_attachment_metadata($post);
$meta = wp_get_attachment_metadata($attachment_id);
$w = !empty($meta['width']) ? min($meta['width'], 640) : 0;
$h = !empty($meta['height']) ? $meta['height'] : 0;
if ($h && $w < $meta['width']) {
$h = round($meta['height'] * $w / $meta['width']);
}
$attr = array('src' => $att_url);
if (!empty($w) && !empty($h)) {
$attr['width'] = $w;
$attr['height'] = $h;
}
$thumb_id = get_post_thumbnail_id($attachment_id);
if (!empty($thumb_id)) {
$attr['poster'] = wp_get_attachment_url($thumb_id);
}
echo wp_video_shortcode($attr);
}
?>
</div>
<div class="wp_attachment_details edit-form-section">
<p>
<label for="attachment_caption"><strong><?php
_e('Caption');
?>
</strong></label><br />
//.........这里部分代码省略.........
示例2: generate_metadata
static function generate_metadata($attachment_id, $file)
{
require_once ABSPATH . 'wp-admin/includes/image.php';
wp_maybe_generate_attachment_metadata(get_post($attachment_id));
//$attachment_data = wp_generate_attachment_metadata( $attachment_id, $file );
//wp_update_attachment_metadata( $attachment_id, $attachment_data );
}