• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_get_attachment_metadata函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_get_attachment_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_attachment_metadata函数的具体用法?PHP wp_get_attachment_metadata怎么用?PHP wp_get_attachment_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_get_attachment_metadata函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: 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


示例2: migrate_attachment_to_s3

 /**
  * Migrate a single attachment's files to S3
  *
  * @subcommand migrate-attachment
  * @synopsis <attachment-id> [--delete-local]
  */
 public function migrate_attachment_to_s3($args, $args_assoc)
 {
     // Ensure things are active
     $instance = S3_Uploads::get_instance();
     if (!s3_uploads_enabled()) {
         $instance->setup();
     }
     $old_upload_dir = $instance->get_original_upload_dir();
     $upload_dir = wp_upload_dir();
     $files = array(get_post_meta($args[0], '_wp_attached_file', true));
     $meta_data = wp_get_attachment_metadata($args[0]);
     if (!empty($meta_data['sizes'])) {
         foreach ($meta_data['sizes'] as $file) {
             $files[] = path_join(dirname($meta_data['file']), $file['file']);
         }
     }
     foreach ($files as $file) {
         if (file_exists($path = $old_upload_dir['basedir'] . '/' . $file)) {
             if (!copy($path, $upload_dir['basedir'] . '/' . $file)) {
                 WP_CLI::line(sprintf('Failed to moved %s to S3', $file));
             } else {
                 if (!empty($args_assoc['delete-local'])) {
                     unlink($path);
                 }
                 WP_CLI::success(sprintf('Moved file %s to S3', $file));
             }
         } else {
             WP_CLI::line(sprintf('Already moved to %s S3', $file));
         }
     }
 }
开发者ID:iamlos,项目名称:S3-Uploads,代码行数:37,代码来源:class-s3-uploads-wp-cli-command.php


示例3: img_smart_image_shortcode

/**
 * Builds the Smart Image shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is 'img_smart_image_shortcode' and passes an empty string, the attr
 * parameter and the content parameter values.
 *
 * The supported attributes for the shortcode are 'id', 'align', 'width', and
 * 'caption'.
 *
 * @since 2.6.0
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id      ID of the div element for the caption.
 *     @type string $align   Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft',
 *                           'aligncenter', alignright', 'alignnone'.
 *     @type int    $width   The width of the caption, in pixels.
 *     @type string $caption The caption text.
 *     @type string $class   Additional class name(s) added to the caption container.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_smart_image_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    $image_meta = wp_get_attachment_metadata($attr['image_id']);
    // gets the images
    $image_large = wp_get_attachment_image_src($attr['image_id'], 'full');
    $image_md = wp_get_attachment_image_src($attr['image_id'], 'medium-hero-png');
    $image_sm = wp_get_attachment_image_src($attr['image_id'], 'small-hero-png');
    $placeholder = wp_get_attachment_image_src($attr['image_id'], 'apple-square-76');
    // update to
    // Sets up the images array
    $images = array('(max-width:640px)' => $image_sm[0], '(min-width:640px)' => $image_md[0], '(min-width:1000px)' => $image_large[0]);
    // encodes the images array for future use in Javascript
    $images = base64_encode(json_encode($images));
    // If this image has zoom enabled, we turn it on here.
    $has_zoom = isset($attr['zoom']) && $attr['zoom'] === 'true' ? true : false;
    $has_zoom = $has_zoom ? ' has_zoom' : '';
    $has_bleed = false;
    // if the image hasn't been uploaded through the dashboard, we make it so that a string is echo'd to find those bugs.
    echo $image_meta === false ? 'Looks like image ' . $attr['image_id'] . ' hasn\'t been uploaded through the dashboard.' : '';
    // Sets the maximum width of the current image.
    $css_max_width = ' style="max-width:100%"';
    // If this image has bleed, but it's turned off
    if (!isset($attr['bleed']) || isset($attr['bleed']) && $attr['bleed'] === "false") {
        // set the image width if it's a retina image
        $css_max_width = isset($attr['retina']) && $attr['retina'] === true ? ' style="max-width:' . $image_large[1] / 2 . 'px;"' : ' style="max-width:' . $image_large[1] . 'px;"';
        // set the image width if it's a standard image
        if (isset($attr['retina']) && $attr['retina'] !== true) {
            $css_max_width = isset($attr['width']) && $attr['width'] !== true ? ' style="max-width:' . $attr['width'] . 'px;"' : $css_max_width;
        }
    } else {
        // otherwise, set bleed on.
        $has_bleed = ' has_bleed';
        $css_max_width = ' style="max-width:100%"';
    }
    // Sets the aspect ratio
    $css_padding_bottom = $image_large[1] !== null && $image_large[2] !== null ? $image_large[2] / $image_large[1] * 100 . '%' : 0;
    // begin creating the $final_image video with for the javascript to parse.
    $final_image = '<figure id="' . $attr['image_id'] . '" class="progressive_image js-not_loaded' . $has_zoom . $has_bleed . '" width="' . $attr['width'] . '" height="' . $attr['height'] . '" style="max-width:' . $attr['width'] . 'px;" itemscope="" itemtype="http://schema.org/ImageObject">';
    $final_image .= '<div class="aspect_ratio_placeholder"' . $css_max_width . '  style="background-image:url(\'' . $image_sm->url . '\');">';
    $final_image .= '<div class="aspect_ratio_fill" style="padding-bottom:' . $css_padding_bottom . ';"></div>';
    // this div keeps the aspect ratio so the placeholder doesn't collapse
    $final_image .= '<div class="progressiveMedia is-imageLoaded"' . $css_max_width . '>';
    $final_image .= '<img src="' . $placeholder[0] . '" class="low-quality-image"' . $css_max_width . ' itemscope="contentUrl" content="' . $image_lg->url . '"/>';
    // this is a tiny image with a resolution of e.g. ~27x17 and low quality
    // 		<canvas/> <!-- takes the above image and applies a blur filter -->
    $final_image .= '<div class="js-swap-for-picture" data-image_info="' . $images . '"></div>';
    // <!-- the large image to be displayed -->
    $no_script_image = '<img class="progressiveMedia-noscript js-progressiveMedia-inner" src="' . $image_large[0] . '" data-action="zoom" />';
    $final_image .= '<noscript>' . $no_script_image . '</noscript>';
    // fallback for no JS
    $final_image .= '</div>';
    $final_image .= '</div>';
    // If this image has a caption, echo it here.
    if ($content) {
        $final_image .= '<figcaption class="wp-caption-text">' . $content . '</figcaption>';
    }
    $final_image .= '</figure>';
    return $final_image;
}
开发者ID:aiganebraska,项目名称:AIGA-Nebraska,代码行数:85,代码来源:conf_shortcodes.php


示例4: themify_do_img

 /**
  * Resize images dynamically using wp built in functions
  *
  * @param string $img_url
  * @param int $width
  * @param int $height
  * @param bool $crop
  * @return array
  */
 function themify_do_img($img_url = null, $width, $height, $crop = false)
 {
     $src = esc_url($img_url);
     $upload_dir = wp_upload_dir();
     $base_url = $upload_dir['baseurl'];
     // Check if the image is an attachment. If it's external return url, width and height.
     if (substr($src, -strlen($base_url)) === $base_url) {
         return array('url' => $src, 'width' => $width, 'height' => $height);
     }
     // Get post's attachment meta data to look for references to the requested image size
     $attachment_id = themify_get_attachment_id_from_url($src, $base_url);
     // If no relationship between a post and a image size was found, return url, width and height.
     if (!$attachment_id) {
         return array('url' => $src, 'width' => $width, 'height' => $height);
     }
     // Go through the attachment meta data sizes looking for an image size match.
     $meta = wp_get_attachment_metadata($attachment_id);
     if (is_array($meta) && isset($meta['sizes']) && is_array($meta['sizes'])) {
         foreach ($meta['sizes'] as $key => $size) {
             if ($size['width'] == $width && $size['height'] == $height) {
                 setlocale(LC_CTYPE, get_locale() . '.UTF-8');
                 return array('url' => str_replace(basename($src), $size['file'], $src), 'width' => $width, 'height' => $height);
             }
         }
     }
     // Requested image size doesn't exists, so let's create one
     if (true == $crop) {
         add_filter('image_resize_dimensions', 'themify_img_resize_dimensions', 10, 5);
     }
     $image = themify_make_image_size($attachment_id, $width, $height, $meta, $src);
     if (true == $crop) {
         remove_filter('image_resize_dimensions', 'themify_img_resize_dimensions', 10);
     }
     return $image;
 }
开发者ID:rgrasiano,项目名称:viabasica-hering,代码行数:44,代码来源:img.php


示例5: zem_rp_upload_articles

function zem_rp_upload_articles($api_key)
{
    $media = array();
    foreach (zem_rp_get_all_attachments() as $image) {
        if (empty($media[$image->post_parent])) {
            $media[$image->post_parent] = array();
        }
        $meta = unserialize($image->meta);
        $media["{$image->post_parent}"][] = array("URL" => $image->guid, "width" => $meta['width'], "height" => $meta['height']);
    }
    $payload = array("found" => 0, "posts" => array());
    foreach (get_posts(array('numberposts' => 10000)) as $post) {
        $obj = array("ID" => $post->ID, "URL" => get_permalink($post->ID), "attachment_count" => 0, "attachments" => array(), "content" => $post->post_content, "date" => $post->post_date, "excerpt" => $post->post_excerpt, "featured_image" => "", "modified" => $post->post_modified, "post_thumbnail" => null, "slug" => $post->post_name, "status" => $post->post_status, "title" => $post->post_title, "type" => $post->post_type);
        if (has_post_thumbnail($post->ID)) {
            $thumb_id = get_post_thumbnail_id($post->ID);
            $meta = wp_get_attachment_metadata($thumb_id);
            $obj["post_thumbnail"] = array("URL" => wp_get_attachment_url($thumb_id), "width" => $meta["width"], "height" => $meta["height"]);
        }
        if (!empty($media[$post->ID])) {
            $obj["attachments"] = $media[$post->ID];
        }
        $obj["attachment_count"] = sizeof($obj["attachments"]);
        $payload["posts"][] = $obj;
    }
    $payload["found"] = sizeof($payload["posts"]);
    $payload["posts"] = $payload["posts"];
    $http_response = wp_remote_post(ZEM_RP_ZEMANTA_UPLOAD_URL, array("body" => array("payload" => json_encode($payload), "blog_name" => get_bloginfo('name'), "api_key" => $api_key, "feed_url" => get_bloginfo('rss2_url'), "blog_url" => get_bloginfo('url'), "platform" => 'wordpress-zem')));
    if (!is_wp_error($http_response) && wp_remote_retrieve_response_code($http_response) == 200) {
        $response = json_decode(wp_remote_retrieve_body($http_response));
        return $response->status === 'ok';
    }
    return false;
}
开发者ID:se7ven214,项目名称:Kungfuphp.local,代码行数:33,代码来源:uploader.php


示例6: thb_image_get_attachment_id

 function thb_image_get_attachment_id($url)
 {
     $dir = wp_upload_dir();
     $dir = trailingslashit($dir['baseurl']);
     if (false === strpos($url, $dir)) {
         return false;
     }
     $file = basename($url);
     $query = array('post_type' => 'attachment', 'fields' => 'ids', 'meta_query' => array(array('value' => $file, 'compare' => 'LIKE')));
     $query['meta_query'][0]['key'] = '_wp_attached_file';
     $ids = get_posts($query);
     foreach ($ids as $id) {
         if ($url == array_shift(wp_get_attachment_image_src($id, 'full'))) {
             return $id;
         }
     }
     $query['meta_query'][0]['key'] = '_wp_attachment_metadata';
     $ids = get_posts($query);
     foreach ($ids as $id) {
         $meta = wp_get_attachment_metadata($id);
         foreach ($meta['sizes'] as $size => $values) {
             if ($values['file'] == $file && $url == array_shift(wp_get_attachment_image_src($id, $size))) {
                 return $id;
             }
         }
     }
     return false;
 }
开发者ID:alfredpp,项目名称:sarath-portfolio,代码行数:28,代码来源:helper.image.php


示例7: ut_delete_resized_images

 function ut_delete_resized_images($post_id)
 {
     // Get attachment image metadata
     $metadata = wp_get_attachment_metadata($post_id);
     /* no meta found, let's leave */
     if (!$metadata) {
         return;
     }
     /* meta found but no image meta set */
     if (!isset($metadata['file']) || !isset($metadata['image_meta']['resized_images'])) {
         return;
     }
     $pathinfo = pathinfo($metadata['file']);
     $resized_images = $metadata['image_meta']['resized_images'];
     /* get Wordpress uploads directory (and bail if it doesn't exist) */
     $wp_upload_dir = wp_upload_dir();
     $upload_dir = $wp_upload_dir['basedir'];
     if (!is_dir($upload_dir)) {
         return;
     }
     /* Delete the resized images */
     foreach ($resized_images as $dims) {
         // Get the resized images filenames
         $file = $upload_dir . '/' . $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $dims . '.' . $pathinfo['extension'];
         $file_retina = $upload_dir . '/' . $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $dims . '@2x.' . $pathinfo['extension'];
         // Delete the resized image
         @unlink($file);
         @unlink($file_retina);
     }
 }
开发者ID:amptdesign,项目名称:ampt-2016,代码行数:30,代码来源:ut-image-resize.php


示例8: testImageEditOverwriteConstant

 /**
  * @ticket 32171
  */
 public function testImageEditOverwriteConstant()
 {
     define('IMAGE_EDIT_OVERWRITE', true);
     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     $filename = DIR_TESTDATA . '/images/canola.jpg';
     $contents = file_get_contents($filename);
     $upload = wp_upload_bits(basename($filename), null, $contents);
     $id = $this->_make_attachment($upload);
     $_REQUEST['action'] = 'image-editor';
     $_REQUEST['context'] = 'edit-attachment';
     $_REQUEST['postid'] = $id;
     $_REQUEST['target'] = 'all';
     $_REQUEST['do'] = 'save';
     $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":289,"h":322}}]';
     $ret = wp_save_image($id);
     $media_meta = wp_get_attachment_metadata($id);
     $sizes1 = $media_meta['sizes'];
     $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":189,"h":322}}]';
     $ret = wp_save_image($id);
     $media_meta = wp_get_attachment_metadata($id);
     $sizes2 = $media_meta['sizes'];
     $file_path = dirname(get_attached_file($id));
     foreach ($sizes1 as $key => $size) {
         if ($sizes2[$key]['file'] !== $size['file']) {
             $files_that_shouldnt_exist[] = $file_path . '/' . $size['file'];
         }
     }
     foreach ($files_that_shouldnt_exist as $file) {
         $this->assertFileNotExists($file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.');
     }
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:34,代码来源:MediaEdit.php


示例9: custom_logo_image

function custom_logo_image()
{
    $logoID = get_field('logo', 'options');
    if ($logoID) {
        $meta = wp_get_attachment_metadata($logoID);
        ?>
		<style>
			body.login #login h1 a {
				background: url(<?php 
        echo esc_attr(wp_get_attachment_url($logoID));
        ?>
) no-repeat center top transparent;
				height: <?php 
        echo $meta['height'];
        ?>
px;
				width: <?php 
        echo $meta['width'];
        ?>
px;
				background-size: contain;
			}
		</style>
		<?php 
    }
}
开发者ID:RadGH,项目名称:WordPress-Sports-Theme,代码行数:26,代码来源:login.php


示例10: get_template_variables

 function get_template_variables($instance, $args)
 {
     static $player_id = 1;
     $poster = '';
     $video_host = $instance['host_type'];
     if ($video_host == 'self') {
         if (!empty($instance['video']['self_video'])) {
             // Handle an attachment video
             $src = wp_get_attachment_url($instance['video']['self_video']);
             $vid_info = wp_get_attachment_metadata($instance['video']['self_video']);
             $video_type = 'video/' . empty($vid_info['fileformat']) ? '' : $vid_info['fileformat'];
         } else {
             if (!empty($instance['video']['self_video_fallback'])) {
                 // Handle an external URL video
                 $src = $instance['video']['self_video_fallback'];
                 $vid_info = wp_check_filetype(basename($instance['video']['self_video_fallback']));
                 $video_type = $vid_info['type'];
             }
         }
         $poster = !empty($instance['video']['self_poster']) ? wp_get_attachment_url($instance['video']['self_poster']) : '';
     } else {
         $video_host = $this->get_host_from_url($instance['video']['external_video']);
         $video_type = 'video/' . $video_host;
         $src = !empty($instance['video']['external_video']) ? $instance['video']['external_video'] : '';
     }
     $return = array('player_id' => 'sow-player-' . $player_id++, 'host_type' => $instance['host_type'], 'src' => $src, 'video_type' => $video_type, 'is_skinnable_video_host' => $this->is_skinnable_video_host($video_host), 'poster' => $poster, 'autoplay' => !empty($instance['playback']['autoplay']), 'skin_class' => 'default');
     // Force oEmbed for this video
     if ($instance['host_type'] == 'external' && $instance['playback']['oembed']) {
         $return['is_skinnable_video_host'] = false;
     }
     return $return;
 }
开发者ID:MichaelEniolade,项目名称:MechrisPlanetWebsite,代码行数:32,代码来源:so-video-widget.php


示例11: mediatag_item_callback_show_meta

function mediatag_item_callback_show_meta($post_item, $size = 'medium')
{
    //	$image_src 	= wp_get_attachment_image_src($post_item->ID, $size);
    $media_meta = wp_get_attachment_metadata($post_item->ID);
    //	echo "media_meta<pre>"; print_r($media_meta); echo "</pre>";
    $image_meta = $media_meta['image_meta'];
    //print_r ($metadata);
    $meta_out = '';
    if ($image_meta['camera']) {
        $meta_out .= $image_meta['camera'] . ' ';
    }
    if ($image_meta['focal_length']) {
        $meta_out .= '@ ' . $image_meta['focal_length'] . ' mm ';
    }
    if ($image_meta['shutter_speed']) {
        $meta_out .= '- ¹/' . 1 / $image_meta['shutter_speed'] . ' sec';
    }
    if ($image_meta['aperture']) {
        $meta_out .= ', ƒ/' . $image_meta['aperture'] . ' ';
    }
    if ($image_meta['iso']) {
        $meta_out .= ', ISO ' . $image_meta['iso'] . ' ';
    }
    if ($image_meta['created_timestamp']) {
        $meta_out .= ' on ' . date('j F, Y', $image_meta['created_timestamp']) . ' ';
    }
    return $meta_out;
}
开发者ID:vsalx,项目名称:rattieinfo,代码行数:28,代码来源:mediatags_shortcodes.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: get

 public function get($type = "", $id = "", $size = "", $attr = array())
 {
     if (is_array($id) && $id["id"]) {
         $id = $id["id"];
     }
     if (!$id) {
         $id = get_post_thumbnail_id(get_the_ID());
     }
     if (!$id) {
         $id = get_field('image', get_the_ID());
         $id = $id["id"];
     }
     if (!$id) {
         $id = get_field('placeholder', 'options');
     }
     if (!$id) {
         return;
     }
     if ($type == "html") {
         return wp_get_attachment_image($id, $size);
     } else {
         if ($type == "url") {
             return reset(wp_get_attachment_image_src($id, $size));
         } else {
             if ($type == "") {
                 return wp_get_attachment_metadata($id);
             } else {
                 $res = wp_get_attachment_metadata($id);
                 return $res[$type];
             }
         }
     }
 }
开发者ID:razvan-rotaru,项目名称:wp_framework,代码行数:33,代码来源:Img.php


示例14: get_image_url

 /**
  * Retrieve resized image URL
  *
  * @param int $id Post ID or Attachment ID
  * @param int $width desired width of image (optional)
  * @param int $height desired height of image (optional)
  * @return string URL
  * @author Modern Tribe, Inc. (Peter Chester)
  */
 function get_image_url($id, $width = false, $height = false)
 {
     /**/
     // Get attachment and resize but return attachment path (needs to return url)
     $attachment = wp_get_attachment_metadata($id);
     $attachment_url = wp_get_attachment_url($id);
     if (isset($attachment_url)) {
         if ($width && $height) {
             $uploads = wp_upload_dir();
             $imgpath = $uploads['basedir'] . '/' . $attachment['file'];
             if (WP_DEBUG) {
                 error_log(__CLASS__ . '->' . __FUNCTION__ . '() $imgpath = ' . $imgpath);
             }
             $image = image_resize($imgpath, $width, $height);
             if ($image && !is_wp_error($image)) {
                 $image = path_join(dirname($attachment_url), basename($image));
             } else {
                 $image = $attachment_url;
             }
         } else {
             $image = $attachment_url;
         }
         if (isset($image)) {
             return $image;
         }
     }
 }
开发者ID:ramonvloon,项目名称:Ingrid,代码行数:36,代码来源:image-widget.php


示例15: filter_image_downsize

 /**
  * Callback for the "image_downsize" filter.
  *
  * @param bool $ignore A value meant to discard unfiltered info returned from this filter.
  * @param int $attachment_id The ID of the attachment for which we want a certain size.
  * @param string $size_name The name of the size desired.
  */
 public function filter_image_downsize($ignore = false, $attachment_id = 0, $size_name = 'thumbnail')
 {
     global $_wp_additional_image_sizes;
     $attachment_id = (int) $attachment_id;
     $size_name = trim($size_name);
     $meta = wp_get_attachment_metadata($attachment_id);
     /* the requested size does not yet exist for this attachment */
     if (empty($meta['sizes']) || empty($meta['sizes'][$size_name])) {
         // let's first see if this is a registered size
         if (isset($_wp_additional_image_sizes[$size_name])) {
             $height = (int) $_wp_additional_image_sizes[$size_name]['height'];
             $width = (int) $_wp_additional_image_sizes[$size_name]['width'];
             $crop = (bool) $_wp_additional_image_sizes[$size_name]['crop'];
             // if not, see if name is of form [width]x[height] and use that to crop
         } else {
             if (preg_match('#^(\\d+)x(\\d+)$#', $size_name, $matches)) {
                 $height = (int) $matches[2];
                 $width = (int) $matches[1];
                 $crop = true;
             }
         }
         if (!empty($height) && !empty($width)) {
             $resized_path = $this->_generate_attachment($attachment_id, $width, $height, $crop);
             $fullsize_url = wp_get_attachment_url($attachment_id);
             $file_name = basename($resized_path);
             $new_url = str_replace(basename($fullsize_url), $file_name, $fullsize_url);
             if (!empty($resized_path)) {
                 $meta['sizes'][$size_name] = array('file' => $file_name, 'width' => $width, 'height' => $height);
                 wp_update_attachment_metadata($attachment_id, $meta);
                 return array($new_url, $width, $height, true);
             }
         }
     }
     return false;
 }
开发者ID:ahsaeldin,项目名称:projects,代码行数:42,代码来源:filosofo-custom-image-sizes.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: __construct

 public function __construct($controller)
 {
     $this->ctrl = $controller;
     //init the option if needed
     if (!isset($_SESSION["wp-short-pixel-priorityQueue"])) {
         //take the priority list from the options (we persist there the priority IDs from the previous session)
         $prioQueueOpt = WPShortPixel::getOpt('wp-short-pixel-priorityQueue', array());
         //here we save the IDs for the files that need to be processed after an image upload for example
         $_SESSION["wp-short-pixel-priorityQueue"] = array();
         foreach ($prioQueueOpt as $ID) {
             $meta = wp_get_attachment_metadata($ID);
             WPShortPixel::log("INIT: Item {$ID} from options has metadata: " . json_encode($meta));
             if (!isset($meta['ShortPixelImprovement'])) {
                 $this->push($ID);
             }
         }
         update_option('wp-short-pixel-priorityQueue', $_SESSION["wp-short-pixel-priorityQueue"]);
         WPShortPixel::log("INIT: Session queue not found, updated from Options with " . json_encode($_SESSION["wp-short-pixel-priorityQueue"]));
     }
     $this->startBulkId = WPShortPixel::getOpt('wp-short-pixel-query-id-start', 0);
     //current query ID used for postmeta queries
     $this->stopBulkId = WPShortPixel::getOpt('wp-short-pixel-query-id-stop', 0);
     //min ID used for postmeta queries
     $this->bulkCount = WPShortPixel::getOpt("wp-short-pixel-bulk-count", 0);
     $this->bulkPreviousPercent = WPShortPixel::getOpt("wp-short-pixel-bulk-previous-percent", 0);
     $this->bulkCurrentlyProcessed = WPShortPixel::getOpt("wp-short-pixel-bulk-processed-items", 0);
     $this->bulkAlreadyDoneCount = WPShortPixel::getOpt("wp-short-pixel-bulk-done-count", 0);
     $this->lastBulkStartTime = WPShortPixel::getOpt('wp-short-pixel-last-bulk-start-time', 0);
     //time of the last start of the bulk.
     $this->lastBulkSuccessTime = WPShortPixel::getOpt('wp-short-pixel-last-bulk-success-time', 0);
     //time of the last start of the bulk.
     $this->bulkRunningTime = WPShortPixel::getOpt('wp-short-pixel-bulk-running-time', 0);
     //how long the bulk ran that far.
 }
开发者ID:konsultanblog,项目名称:tagamon,代码行数:34,代码来源:shortpixel_queue.php


示例18: gabfire_call_post_thumb

 function gabfire_call_post_thumb($parameters)
 {
     /* Get default Post Thumbnail of WordPress */
     global $post;
     $image_id = get_post_thumbnail_id();
     $image_url = wp_get_attachment_image_src($image_id, $parameters['name']);
     $image_url = $image_url[0];
     $image_meta = wp_get_attachment_metadata($image_id);
     //error_log(serialize($image_meta));
     $alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
     if (!empty($alt_text)) {
         $title = $alt_text;
     } else {
         $title = get_the_title();
     }
     if ($parameters['link'] == 1) {
         echo "<a href='" . get_permalink() . "' rel='bookmark'>";
     }
     if ($parameters['imgtag'] == 1) {
         echo "<img src='";
         //echo "<img width='".$image_meta['sizes'][$parameters['name']]['width']."' height='".$image_meta['sizes'][$parameters['name']]['height']."' src='";
     }
     echo $image_url;
     if ($parameters['imgtag'] == 1) {
         echo "' class='" . $parameters['thumb_align'] . "' alt='" . get_the_title() . "' title='" . $title . "' />";
     }
     if ($parameters['link'] == 1) {
         echo "</a>";
     }
 }
开发者ID:wpmonty,项目名称:skinny,代码行数:30,代码来源:gabfire-media.php


示例19: get_photos

 /**
  * Get the photos belonging to an album
  *
  * @param $album_id
  *
  * @return array
  */
 public function get_photos($album_id)
 {
     $media = get_post_meta($album_id, '_apg_album_items', true);
     $stored_value = get_post_meta($album_id, 'apg_photo_order', true);
     $images = array();
     if (!isset($media['photos'])) {
         return array();
     }
     if (isset($stored_value) && !empty($stored_value)) {
         $photo_index = array_flip($this->arrayColumn($media['photos'], 'id'));
         $stored_value = explode(',', $stored_value);
         foreach ($stored_value as $item) {
             if (empty($item) || !isset($photo_index[$item])) {
                 continue;
             }
             $key_id = $photo_index[$item];
             $images[] = array('ID' => $media['photos'][$key_id]['id'], 'metadata' => wp_get_attachment_metadata($media['photos'][$key_id]['id']));
             unset($media['photos'][$key_id]);
         }
     } else {
         foreach ($media['photos'] as $item) {
             $images[] = array('ID' => $item['id'], 'metadata' => wp_get_attachment_metadata($item['id']));
         }
     }
     return $images;
 }
开发者ID:Code-Brothers,项目名称:Awesome-Photo-Gallery,代码行数:33,代码来源:class-viewer.php


示例20: wr2x_manage_media_custom_column

function wr2x_manage_media_custom_column($column_name, $id)
{
    if ($column_name != 'Retina') {
        return;
    }
    if (wr2x_is_ignore($id)) {
        echo "<img style='margin-top: -2px; margin-bottom: 2px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-retina-2x/img') . "tick-circle.png' />";
        return;
    }
    // Check if the attachment is an image
    $meta = wp_get_attachment_metadata($id);
    if (!($meta && isset($meta['width']) && isset($meta['height']))) {
        return;
    }
    $isAlright = true;
    $info = wr2x_retina_info($id);
    foreach ($info as $name => $attr) {
        if ($attr == 'PENDING' || is_array($attr)) {
            $isAlright = false;
        }
    }
    // Displays the result
    echo "<p id='wr2x_attachment_{$id}' style='margin-bottom: 2px;'>";
    if ($isAlright) {
        echo "<img style='margin-top: -2px; margin-bottom: 2px; width: 16px; height: 16px;' src='" . trailingslashit(WP_PLUGIN_URL) . trailingslashit('wp-ret 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_get_attachment_thumb_file函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_get_attachment_link函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap