本文整理汇总了PHP中wp_attachment_is_image函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_attachment_is_image函数的具体用法?PHP wp_attachment_is_image怎么用?PHP wp_attachment_is_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_attachment_is_image函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: plusify_content
/**
*
* @param string $content
* @return string
*/
function plusify_content($content)
{
include_once ATTACHMENTS_PP_PATH . 'class-library.php';
// only handle attachments that aren't already embedded (namely, not images)
if (is_attachment() && !wp_attachment_is_image()) {
$embed = AttachmentsPPLib::get_embedded_attachment();
if (!empty($embed)) {
// remove "attachment" class from $content -- it will be
// included in the outer div around the embedder & existing content
$regex = '#(.*)<(p|div)\\s*class=[\'"]([-_A-Za-z ]*)attachment([-_A-Za-z ]*)[\'"]>(.*)</\\2>(.*)#is';
if (preg_match($regex, $content, $matches)) {
$matches[3] = trim($matches[3]);
$matches[4] = trim($matches[4]);
$classes = '';
if (!empty($matches[3]) || !empty($matches[4])) {
if (!empty($matches[3]) && !empty($matches[4])) {
$classes = ' class="' . $matches[3] . ' ' . $matches[4] . '"';
} else {
$classes = ' class="' . $matches[3] . $matches[4] . '"';
}
}
$content = $matches[1] . '<' . $matches[2] . $classes . '>' . $matches[5] . '</' . $matches[2] . '>' . $matches[6];
}
$content = '<div class="attachment">' . $embed . $content . '</div>';
}
}
// Returns the content.
return $content;
}
开发者ID:thenadz,项目名称:attachments-plus-plus,代码行数:34,代码来源:attachments-plus-plus.php
示例2: output
/**
* Check AM_MBF for description.
*
* @todo Set class on div to set if the image has been selected and get rid of $hide_upload_button and $hide_clear_button.
*
* @since 1.0.0
*/
public function output()
{
// Get the file id, 0 represents a new field.
$image_id = intval($this->value) > 0 ? intval($this->value) : 0;
$image_url = '';
$image_title = '';
$class_icon = '';
$hide_upload_button = $hide_clear_button = ' style="display:none;"';
// Make sure the selected image is valid.
if ($image_id > 0) {
$post = get_post($image_id);
if (isset($post) && wp_attachment_is_image($image_id)) {
$image_url = wp_get_attachment_thumb_url($image_id);
$image_title = $post->post_title;
} else {
$this->error = __(sprintf('Selected Image (ID:%1$d) is invalid.', $image_id), 'am-cpts');
$class_icon = ' invalid';
}
$hide_clear_button = '';
} else {
$hide_upload_button = '';
}
// Text used by wp.media frame.
$wp_media_data = sprintf(' data-title="%1$s" data-button="%2$s"', esc_attr__('Choose an Image', 'am-cpts'), esc_attr__('Use this Image', 'am-cpts'));
return sprintf('
<div%11$s>
<input name="%2$s" type="hidden" class="meta-box-upload-image" value="%1$d"%12$s />
<img src="%10$s" class="meta-box-preview-image%3$s" title="%7$s" alt="%6$s"%5$s />
<a href="#" class="meta-box-upload-image-button button"%4$s%13$s>%8$s</a>
<span class="meta-box-image-title"%5$s>%6$s</span>
<a href="#" class="meta-box-clear-image-button"%5$s>%9$s</a>
</div>', esc_attr($image_id), esc_attr($this->name), $class_icon, $hide_upload_button, $hide_clear_button, isset($this->error) ? esc_html($this->error) : $image_title, esc_attr__('Selected Image', 'am-cpts'), esc_html__('Choose Image', 'am-cpts'), esc_html__('Remove Image', 'am-cpts'), esc_url($image_url), $this->get_classes('meta-box-image'), $this->get_data_atts(), $wp_media_data);
}
开发者ID:noplanman,项目名称:am-cpts,代码行数:40,代码来源:image.php
示例3: format_value
/**
* Format the value of the property before it's returned
* to WordPress admin or the site.
*
* @param mixed $value
* @param string $slug
* @param int $post_id
*
* @return mixed
*/
public function format_value($value, $slug, $post_id)
{
if (is_numeric($value)) {
$meta = wp_get_attachment_metadata($value);
if (isset($meta) && !empty($meta)) {
$att = get_post($value);
$mine = ['alt' => trim(strip_tags(get_post_meta($value, '_wp_attachment_image_alt', true))), 'caption' => trim(strip_tags($att->post_excerpt)), 'description' => trim(strip_tags($att->post_content)), 'id' => intval($value), 'is_image' => (bool) wp_attachment_is_image($value), 'title' => esc_html($att->post_title), 'url' => wp_get_attachment_url($value)];
$meta = is_array($meta) ? $meta : ['file' => $meta];
if (isset($meta['sizes'])) {
foreach (array_keys($meta['sizes']) as $size) {
if ($src = wp_get_attachment_image_src($mine['id'], $size)) {
$meta['sizes'][$size]['url'] = $src[0];
}
}
}
return (object) array_merge($meta, $mine);
}
return (int) $value;
}
if (is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = $this->format_value($v, $slug, $post_id);
}
return $value;
}
if (is_object($value) && !isset($value->url)) {
return;
}
return $value;
}
开发者ID:wp-papi,项目名称:papi,代码行数:40,代码来源:class-papi-property-file.php
示例4: attach_html
public static function attach_html($attach_id, $type = NULL)
{
if (!$type) {
$type = isset($_GET['type']) ? $_GET['type'] : 'image';
}
$attachment = get_post($attach_id);
if (!$attachment) {
return;
}
if (wp_attachment_is_image($attach_id)) {
$image = wp_get_attachment_image_src($attach_id, 'thumbnail');
$image = $image[0];
} else {
$image = wp_mime_type_icon($attach_id);
}
$html = '<li class="wpuf-image-wrap thumbnail">';
$html .= sprintf('<div class="attachment-name"><img src="%s" alt="%s" /></div>', $image, esc_attr($attachment->post_title));
if (wpuf_get_option('image_caption', 'wpuf_general', 'off') == 'on') {
$html .= '<div class="wpuf-file-input-wrap">';
$html .= sprintf('<input type="text" name="wpuf_files_data[%d][title]" value="%s" placeholder="%s">', $attach_id, esc_attr($attachment->post_title), __('Title', 'wpuf'));
$html .= sprintf('<textarea name="wpuf_files_data[%d][caption]" placeholder="%s">%s</textarea>', $attach_id, __('Caption', 'wpuf'), esc_textarea($attachment->post_excerpt));
$html .= sprintf('<textarea name="wpuf_files_data[%d][desc]" placeholder="%s">%s</textarea>', $attach_id, __('Description', 'wpuf'), esc_textarea($attachment->post_content));
$html .= '</div>';
}
$html .= sprintf('<input type="hidden" name="wpuf_files[%s][]" value="%d">', $type, $attach_id);
$html .= sprintf('<div class="caption"><a href="#" class="btn btn-danger btn-small attachment-delete" data-attach_id="%d">%s</a></div>', $attach_id, __('Delete', 'wpuf'));
$html .= '</li>';
return $html;
}
开发者ID:trdvelho,项目名称:estoque_wp,代码行数:29,代码来源:upload.php
示例5: yoimg_media_row_actions
function yoimg_media_row_actions($actions, $post, $detached)
{
if (wp_attachment_is_image($post->ID) && current_user_can('edit_post', $post->ID)) {
$actions['yoimg_crop'] = yoimg_get_edit_image_anchor($post->ID);
}
return $actions;
}
开发者ID:jawngee,项目名称:yoimages-crop,代码行数:7,代码来源:extend-admin-media.php
示例6: wp_delete_attachments
/**
* Delete attachments linked to a specified post
* @param int $parent_id Parent id of post to delete attachments for
*/
function wp_delete_attachments($parent_id, $unlink = true, $type = 'images')
{
if ($type == 'images' and has_post_thumbnail($parent_id)) {
delete_post_thumbnail($parent_id);
}
$ids = array();
$attachments = get_posts(array('post_parent' => $parent_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null));
foreach ($attachments as $attach) {
if ($type == 'files' and !wp_attachment_is_image($attach->ID)) {
if ($unlink) {
wp_delete_attachment($attach->ID, true);
} else {
$ids[] = $attach->ID;
}
} elseif ($type == 'images' and wp_attachment_is_image($attach->ID)) {
if ($unlink) {
wp_delete_attachment($attach->ID, true);
} else {
$ids[] = $attach->ID;
}
}
}
global $wpdb;
if (!empty($ids)) {
$ids_string = implode(',', $ids);
// unattach
$result = $wpdb->query("UPDATE {$wpdb->posts} SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( {$ids_string} )");
foreach ($ids as $att_id) {
clean_attachment_cache($att_id);
}
}
return $ids;
}
开发者ID:lizbur10,项目名称:js_finalproject,代码行数:37,代码来源:wp_delete_attachments.php
示例7: get_title
function get_title()
{
if (wp_attachment_is_image($this->item->ID)) {
return wp_get_attachment_image($this->item->ID, 'thumbnail', false);
}
return get_the_title($this->item);
}
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:7,代码来源:item-attachment.php
示例8: jbst_posttype_set_classes
function jbst_posttype_set_classes()
{
if (wp_attachment_is_image()) {
return 'image-attachment';
}
return 'site-content';
}
开发者ID:jwlayug,项目名称:jbst,代码行数:7,代码来源:template-functions.php
示例9: fifteen_scripts
function fifteen_scripts()
{
wp_enqueue_style('fifteen-basic-style', get_stylesheet_uri());
if (function_exists('of_get_option') && of_get_option('sidebar-layout', true) != 1) {
if (of_get_option('sidebar-layout', true) == 'right') {
wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/content-sidebar.css");
} else {
wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/sidebar-content.css");
}
} else {
wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/content-sidebar.css");
}
wp_enqueue_style('fifteen-bootstrap-style', get_template_directory_uri() . "/css/bootstrap/bootstrap.min.css", array('fifteen-layout'));
wp_enqueue_style('fifteen-main-skin', get_template_directory_uri() . "/css/skins/default.css", array('fifteen-layout', 'fifteen-bootstrap-style'));
wp_enqueue_script('fifteen-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true);
wp_enqueue_script('fifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true);
wp_enqueue_script('fifteen-bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script('fifteen-custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'));
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
if (is_singular() && wp_attachment_is_image()) {
wp_enqueue_script('fifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array('jquery'), '20120202');
}
}
开发者ID:jessmelvi,项目名称:twirlpool.me,代码行数:25,代码来源:functions.php
示例10: anno_media_send_to_editor
function anno_media_send_to_editor($html, $id, $attachment)
{
if (!anno_is_article($_REQUEST['post_id'])) {
return $html;
}
$html = '';
$attachment_object = get_post($id);
if (!$attachment_object) {
return '';
}
// Attachment is not an image, insert it as a link
if (!wp_attachment_is_image($id)) {
//@TODO NEEDS TO BE CONVERTED TO THE TEXTORUM EXPECTED TAG
$html = '<span class="ext-link" xmlns:xlink="http://www.w3.org/1999/xlink" data-xmlel="ext-link" ext-link-type="uri" xlink:href="' . esc_url($attachment['url']) . '">' . $attachment['post_title'] . '</span> ';
} else {
if (!isset($attachment['display'])) {
$attachment['display'] = 'figure';
}
$img_data = wp_get_attachment_image_src($id, $attachment['image-size']);
$img_url = is_array($img_data) && isset($img_data[0]) ? $img_data[0] : '';
if (trim($attachment['display']) == 'figure') {
$meta = array('label' => '_anno_attachment_image_label', 'copyright_statement' => '_anno_attachment_image_copyright_statement', 'copyright_holder' => '_anno_attachment_image_copyright_holder', 'license' => '_anno_attachment_image_license');
foreach ($meta as $key => $meta_key) {
$attachment[$key] = get_post_meta($id, $meta_key, true);
}
if (!empty($attachment['url'])) {
$fig_uri = '<div class="uri" data-xmlel="uri" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . $attachment['url'] . '"></div>';
} else {
$fig_uri = '';
}
// Editor removes empty items, need this to be valid
$attachment['license'] = empty($attachment['license']) ? ' ' : $attachment['license'];
$html = '
<div class="fig" data-xmlel="fig">
<img src="' . esc_attr($img_url) . '" data-mce-src="' . esc_attr($img_url) . '" alt="' . esc_attr($attachment['image_alt']) . '" />
<div class="label" data-xmlel="label">' . $attachment['label'] . '</div>
<div class="caption" data-xmlel="caption">
<div class="p" data-xmlel="p">' . $attachment['post_excerpt'] . '</div>
</div>
<div class="media" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . esc_attr($img_url) . '" data-xmlel="media">
<span class="alt-text" data-xmlel="alt-text">' . $attachment['image_alt'] . '</span>
<span class="long-desc" data-xmlel="long-desc">' . $attachment['post_content'] . '</span>
' . $fig_uri . '
<div class="permissions" data-xmlel="permissions">
<span class="copyright-statement" data-xmlel="copyright-statement">' . $attachment['copyright_statement'] . '</span>
<span class="copyright-holder" data-xmlel="copyright-holder">' . $attachment['copyright_holder'] . '</span>
<div class="license" data-xmlel="license" license-type="creative-commons">
<span class="license-p" data-xmlel="license-p">' . $attachment['license'] . '</span>
</div>
</div>
</div>
<div _mce_bogus="1" class="clearfix"></div>
</div>';
} else {
$html = '<span class="inline-graphic" data-xmlel="inline-graphic" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . esc_attr($img_url) . '"><img src="' . esc_url($img_url) . '" data-mce-src="' . esc_attr($img_url) . '" alt="' . esc_attr($attachment['image_alt']) . '" /></span><span> </span>';
}
}
return $html;
}
开发者ID:dregula,项目名称:Annotum,代码行数:60,代码来源:media-ajax.php
示例11: wck_preprocess_field_upload
function wck_preprocess_field_upload($field)
{
if ($field == '' || !is_numeric($field)) {
return false;
}
if (is_null(get_post($field))) {
return false;
}
if (wp_attachment_is_image($field)) {
$attachment = get_post($field);
// create array to hold value data
$src = wp_get_attachment_image_src($attachment->ID, 'full');
$value = array('id' => $attachment->ID, 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'url' => $src[0], 'width' => $src[1], 'height' => $src[2], 'sizes' => array());
// find all image sizes
$image_sizes = get_intermediate_image_sizes();
if ($image_sizes) {
foreach ($image_sizes as $image_size) {
// find src
$src = wp_get_attachment_image_src($attachment->ID, $image_size);
// add src
$value['sizes'][$image_size] = $src[0];
$value['sizes'][$image_size . '-width'] = $src[1];
$value['sizes'][$image_size . '-height'] = $src[2];
}
}
return $value;
} else {
$attachement = get_post($field);
return $attachement;
}
}
开发者ID:matthewepler,项目名称:moralcourage,代码行数:31,代码来源:wck-field-preprocess.php
示例12: image_attachments
function image_attachments($image_size = 'large', $width_min = 0, $height_min = 0)
{
// Initialize images array; only fetch images for singular content, exit early and return an empty array otherwise
$images = [];
if (!is_singular()) {
return $images;
}
global $post;
// @TODO: use get_the_ID()
// Override default image size; for reference, Facebook likes large images (1200 x 630 pixels) and Twitter likes smaller ones (less than 1 Mb)
$image_size = apply_filters('ubik_seo_image_attachments_size', $image_size);
// Are we are dealing with an actual image attachment page?
if (wp_attachment_is_image()) {
// Get all metadata (includes mime type) and image source in the usual way
$attachment = wp_get_attachment_metadata($post->ID);
$image_src = wp_get_attachment_image_src($post->ID, $image_size);
// Is there an attachment of the desired size? Fill the mime type and appropriate height/width info
if (!empty($attachment['sizes'][$image_size])) {
$images[] = ['url' => $image_src[0], 'type' => $attachment['sizes'][$image_size]['mime-type'], 'width' => $attachment['sizes'][$image_size]['width'], 'height' => $attachment['sizes'][$image_size]['height']];
// Otherwise fallback to the default image size
} else {
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type($post->ID), 'width' => $image_src[1], 'height' => $image_src[2]];
}
// All other posts, pages, etc.
} else {
// Featured image/post thumbnail first; Facebook prioritizes larger images so this might not have much of an effect
if (has_post_thumbnail($post->ID)) {
$image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type(get_post_thumbnail_id($post->ID)), 'width' => $image_src[1], 'height' => $image_src[2]];
}
// Get all images attachments sorted by date (oldest first)
$attachments = get_children(['post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'posts_per_page' => apply_filters('ubik_seo_image_attachments_limit', 20), 'orderby' => 'date', 'order' => 'ASC']);
// Cycle through all attachments and extract relevant image metadata
if (count($attachments) >= 1) {
foreach ($attachments as $attachment) {
$image_src = wp_get_attachment_image_src($attachment->ID, $image_size);
// Don't duplicate featured image
if (has_post_thumbnail($post->ID)) {
if ($image_src[0] !== $images[0]['url']) {
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type(get_post_thumbnail_id($post->ID)), 'width' => $image_src[1], 'height' => $image_src[2]];
}
} else {
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type($attachment->ID), 'width' => $image_src[1], 'height' => $image_src[2]];
}
}
}
}
// Restrict output based on width and height requirements
if ($images) {
for ($i = 0; $i < count($images); $i++) {
if ($images[$i]['width'] <= $width_min || $images[$i]['height'] <= $height_min) {
unset($images[$i]);
}
}
}
// Re-index array (removes gaps)
$images = array_values($images);
// Return an array of image attachment metadata: url, type (mime type; optional), width, and height; usage e.g. $images[0]['url']
return apply_filters('ubik_seo_image_attachments', $images);
}
开发者ID:synapticism,项目名称:ubik,代码行数:60,代码来源:seo.php
示例13: ajax_create_slide
/**
* Create a new slide and echo the admin HTML
*/
public function ajax_create_slide()
{
// security check
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'metaslider_addslide')) {
echo "<tr><td colspan='2'>" . __("Security check failed. Refresh page and try again.", 'metaslider') . "</td></tr>";
wp_die();
}
$slider_id = absint($_POST['slider_id']);
$selection = $_POST['selection'];
if (is_array($selection) && count($selection) && $slider_id > 0) {
foreach ($selection as $slide_id) {
$this->set_slide($slide_id);
$this->set_slider($slider_id);
if ($this->slide_exists_in_slideshow($slider_id, $slide_id)) {
echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide already exists in slideshow.", 'metaslider') . "</td></tr>";
} else {
if (!$this->slide_is_unassigned_or_image_slide($slider_id, $slide_id)) {
echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide is not of type 'image'.", 'metaslider') . "</td></tr>";
} else {
if (!wp_attachment_is_image($slide_id)) {
echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide is not an image.", 'metaslider') . "</td></tr>";
} else {
$this->tag_slide_to_slider();
$this->add_or_update_or_delete_meta($slide_id, 'type', 'image');
// override the width and height to kick off the AJAX image resizing on save
$this->settings['width'] = 0;
$this->settings['height'] = 0;
echo $this->get_admin_slide();
}
}
}
}
}
wp_die();
}
开发者ID:brittbec13,项目名称:citizenmodern,代码行数:38,代码来源:metaslide.image.class.php
示例14: zacklive_scripts
/**
* Enqueue scripts and styles
*/
function zacklive_scripts()
{
// load zacklive styles
wp_enqueue_style('zacklive-style', get_stylesheet_uri());
// load bootstrap css
wp_enqueue_style('zacklive-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap/bootstrap.min.css');
// load bootstrap for WordPress css
wp_enqueue_style('zacklive-bootstrapwp', get_template_directory_uri() . '/assets/css/bootstrap-wp.css');
// load font awesome css
wp_enqueue_style('zacklive-fontawesome', get_template_directory_uri() . '/assets/css/FontAwesome/font-awesome.min.css', array(), '4.3.0', 'all');
// load bootstrap.js
wp_enqueue_script('zacklive-bootstrapjs', get_template_directory_uri() . '/assets/js/bootstrap/bootstrap.js', array('jquery'));
// load bootstrap-wp.js
wp_enqueue_script('zacklive-bootstrapwp', get_template_directory_uri() . '/assets/js/bootstrap-wp.js', array('jquery'));
// FitVid (responsive video)
wp_enqueue_script('zacklive-fitvids', get_template_directory_uri() . '/assets/js/FitVids.js-master/jquery.fitvids.js', array('jquery'));
wp_enqueue_script('zacklive-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20130115', true);
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
//load keyboard-image-navigation.js
if (is_singular() && wp_attachment_is_image()) {
wp_enqueue_script('zacklive-keyboard-image-navigation', get_template_directory_uri() . '/assets/js/keyboard-image-navigation.js', array('jquery'), '20120202');
}
}
开发者ID:Red4x,项目名称:zacklive,代码行数:28,代码来源:functions.php
示例15: hoot_get_image_size_links
/**
* Returns a set of image attachment links based on size.
*
* @since 1.0.0
* @access public
* @return string
*/
function hoot_get_image_size_links()
{
/* If not viewing an image attachment page, return. */
if (!wp_attachment_is_image(get_the_ID())) {
return;
}
/* Set up an empty array for the links. */
$links = array();
/* Get the intermediate image sizes and add the full size to the array. */
$sizes = get_intermediate_image_sizes();
$sizes[] = 'full';
/* Loop through each of the image sizes. */
foreach ($sizes as $size) {
/* Get the image source, width, height, and whether it's intermediate. */
$image = wp_get_attachment_image_src(get_the_ID(), $size);
/* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
if (!empty($image) && (true === $image[3] || 'full' == $size)) {
/* Translators: Media dimensions - 1 is width and 2 is height. */
$label = sprintf(__('%1$s × %2$s', 'chromatic'), number_format_i18n(absint($image[1])), number_format_i18n(absint($image[2])));
$links[] = sprintf('<a class="image-size-link">%s</a>', $label);
}
}
/* Join the links in a string and return. */
return join(' <span class="sep">/</span> ', $links);
}
开发者ID:acafourek,项目名称:maidstone,代码行数:32,代码来源:template-media.php
示例16: prepare_post
/**
* Get attachment-specific data
*
* @param array $post
* @return array
*/
protected function prepare_post($post, $context = 'single')
{
$data = parent::prepare_post($post, $context);
if (is_wp_error($data) || $post['post_type'] !== 'attachment') {
return $data;
}
// $thumbnail_size = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail';
$data['source'] = wp_get_attachment_url($post['ID']);
$data['is_image'] = wp_attachment_is_image($post['ID']);
$data['attachment_meta'] = wp_get_attachment_metadata($post['ID']);
// Ensure empty meta is an empty object
if (empty($data['attachment_meta'])) {
$data['attachment_meta'] = new stdClass();
} elseif (!empty($data['attachment_meta']['sizes'])) {
$img_url_basename = wp_basename($data['source']);
foreach ($data['attachment_meta']['sizes'] as $size => &$size_data) {
// Use the same method image_downsize() does
$size_data['url'] = str_replace($img_url_basename, $size_data['file'], $data['source']);
}
} else {
$data['attachment_meta']['sizes'] = new stdClass();
}
// Override entity meta keys with the correct links
$data['meta'] = array('links' => array('self' => json_url('/media/' . $post['ID']), 'author' => json_url('/users/' . $post['post_author']), 'collection' => json_url('/media'), 'replies' => json_url('/media/' . $post['ID'] . '/comments'), 'version-history' => json_url('/media/' . $post['ID'] . '/revisions')));
if (!empty($post['post_parent'])) {
$data['meta']['links']['up'] = json_url('/media/' . (int) $post['post_parent']);
}
return apply_filters('json_prepare_attachment', $data, $post, $context);
}
开发者ID:dani-ocean,项目名称:wp_angular_api,代码行数:35,代码来源:class-wp-json-media.php
示例17: image_downsize
function image_downsize($id, $size = 'medium')
{
if (!wp_attachment_is_image($id)) {
return false;
}
$img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
$width = $height = 0;
// plugins can use this to provide resize services
if ($out = apply_filters('image_downsize', false, $id, $size)) {
return $out;
}
// try for a new style intermediate size
if ($intermediate = image_get_intermediate_size($id, $size)) {
$img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
$width = $intermediate['width'];
$height = $intermediate['height'];
} elseif ($size == 'thumbnail') {
// fall back to the old thumbnail
if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
$img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
$width = $info[0];
$height = $info[1];
}
}
if (!$width && !$height && isset($meta['width'], $meta['height'])) {
// any other type: use the real image and constrain it
list($width, $height) = image_constrain_size_for_editor($meta['width'], $meta['height'], $size);
}
if ($img_url) {
return array($img_url, $width, $height);
}
return false;
}
开发者ID:nurpax,项目名称:saastafi,代码行数:34,代码来源:media.php
示例18: tsd_tpng_filter_uploaded_images
function tsd_tpng_filter_uploaded_images($meta, $id)
{
// Make sure the upload is an image
if ($id && false === wp_attachment_is_image($id)) {
return $meta;
}
// Fetch the image file path
$attachment_file_path = get_attached_file($id);
// See what fields exist
// Change the properties of $meta as needed
$upload_dir = wp_upload_dir();
$input = get_attached_file($id);
$type = $meta['sizes']['thumbnail']['mime-type'];
$key = get_option('tsd_tpng_api_key');
$output = $input;
if ($key != "" && $type == "image/png") {
$url = "https://api.tinypng.com/shrink";
$options = array("http" => array("method" => "POST", "header" => array("Content-type: image/png", "Authorization: Basic " . base64_encode("api:{$key}")), "content" => file_get_contents($input)), "ssl" => array("cafile" => __DIR__ . "/cacert.pem", "verify_peer" => true));
$result = fopen($url, "r", false, stream_context_create($options));
if ($result) {
/* Compression was successful, retrieve output from Location header. */
foreach ($http_response_header as $header) {
if (substr($header, 0, 10) === "Location: ") {
file_put_contents($output, fopen(substr($header, 10), "rb", false));
}
}
} else {
/* Something went wrong! */
print "Compression failed";
}
}
return $meta;
}
开发者ID:miguderp,项目名称:Tiny-PNG-for-WordPress,代码行数:33,代码来源:tiny-png-wordpress.php
示例19: wp_user_avatars_ajax_assign_media
/**
* AJAX callback for setting media ID as user avatar
*
* @since 0.1.0
*/
function wp_user_avatars_ajax_assign_media()
{
// check required information and permissions
if (empty($_POST['user_id']) || empty($_POST['media_id']) || empty($_POST['_wpnonce'])) {
die;
}
// Cast values
$media_id = (int) $_POST['media_id'];
$user_id = (int) $_POST['user_id'];
// Bail if current user cannot proceed
if (!current_user_can('edit_avatar', $user_id)) {
die;
}
// Bail if nonce verification fails
if (!wp_verify_nonce($_POST['_wpnonce'], 'assign_wp_user_avatars_nonce')) {
die;
}
// ensure the media is real is an image
if (wp_attachment_is_image($media_id)) {
wp_user_avatars_update_avatar($user_id, $media_id);
}
// Output the new avatar
if (defined('DOING_AJAX') && DOING_AJAX) {
echo get_avatar($user_id, 90);
die;
}
}
开发者ID:stuttter,项目名称:wp-user-avatars,代码行数:32,代码来源:ajax.php
示例20: Radix_scripts
/**
Load needed scripts
**/
function Radix_scripts()
{
wp_enqueue_script('Radix-modernizr', RADIX_JS_URI . '/modernizr.min.js', array(), '2.8.3', true);
wp_enqueue_script('Radix-bootstrapjs', RADIX_JS_URI . '/bootstrap.min.js', array('jquery'), '3.3.5', true);
// jquery.nicescroll + WOW.js
wp_enqueue_script('Radix-plugins', RADIX_JS_URI . '/plugins.min.js', array(), '1.1.2', true);
wp_enqueue_script('Radix-scripts', RADIX_JS_URI . '/scripts.min.js', array(), '1.1.2', true);
if (is_singular() && wp_attachment_is_image()) {
wp_enqueue_script('keyboard-image-navigation', RADIX_JS_URI . '/keyboard-image-navigation.js');
}
if (!is_admin() && is_singular() && comments_open() && !is_front_page() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
// We dont need these in Frontpage
if (!is_home()) {
wp_enqueue_script('Radix-prettyphoto', RADIX_JS_URI . '/jquery.prettyPhoto.min.js', array('jquery'), '3.1.6', true);
wp_enqueue_style('Radix-prettyphoto-css', RADIX_CSS_URI . '/prettyPhoto.min.css');
}
// Animate.css - font-awesome
wp_enqueue_style('Radix-all-css', RADIX_CSS_URI . '/all.min.css');
// Load Bootstrap
wp_enqueue_style('Radix-bootstrap', RADIX_CSS_URI . '/bootstrap.min.css');
// Load main stylesheet
wp_enqueue_style('Radix-style', get_stylesheet_uri());
}
开发者ID:wpdesign,项目名称:Radix,代码行数:28,代码来源:scripts.php
注:本文中的wp_attachment_is_image函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论