PHP Класс Jetpack_PostImages, jetpack

Includes a few different methods, all of which return a similar-format array containing details of any images found. Everything can (should) be called statically, it's just a function-bucket. You can also call Jetpack_PostImages::get_image() to cycle through all of the methods until one of them finds something useful. This file is included verbatim in Jetpack
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
fit_image_url ( string $src, $width, $height ) : string Takes an image URL and pixel dimensions then returns a URL for the resized and croped image.
from_attachment ( $post_id, $width = 200, $height = 200 ) Get attachment images for a specified post and return them. Also make sure their dimensions are at or above a required minimum.
from_blavatar ( integer $post_id, integer $size = 96 ) : Array
from_gallery ( $post_id ) If a gallery is detected, then get all the images from it.
from_gravatar ( integer $post_id, integer $size = 96, string $default = false ) : Array
from_html ( mixed $html_or_id ) : Array Very raw -- just parse the HTML and pull out any/all img tags and return their src
from_slideshow ( $post_id, $width = 200, $height = 200 ) If a slideshow is embedded within a post, then parse out the images involved and return them
from_thumbnail ( integer $post_id, $width = 200, $height = 200 ) : Array Check if a Featured Image is set for this post, and return it in a similar format to the other images?_from_*() methods.
get_image ( integer $post_id, array $args = [] ) : Array Run through the different methods that we have available to try to find a single good display image for this post.
get_images ( integer $post_id, array $args = [] ) : Array Get an array containing a collection of possible images for this post, stopping once we hit a method that returns something useful.

Описание методов

fit_image_url() статический публичный Метод

Takes an image URL and pixel dimensions then returns a URL for the resized and croped image.
static public fit_image_url ( string $src, $width, $height ) : string
$src string
Результат string Transformed image URL

from_attachment() статический публичный Метод

Get attachment images for a specified post and return them. Also make sure their dimensions are at or above a required minimum.
static public from_attachment ( $post_id, $width = 200, $height = 200 )

from_blavatar() статический публичный Метод

static public from_blavatar ( integer $post_id, integer $size = 96 ) : Array
$post_id integer The post ID to check
$size integer
Результат Array containing details of the image, or empty array if none.

from_gravatar() статический публичный Метод

static public from_gravatar ( integer $post_id, integer $size = 96, string $default = false ) : Array
$post_id integer The post ID to check
$size integer
$default string The default image to use.
Результат Array containing details of the image, or empty array if none.

from_html() статический публичный Метод

Very raw -- just parse the HTML and pull out any/all img tags and return their src
static public from_html ( mixed $html_or_id ) : Array
$html_or_id mixed The HTML string to parse for images, or a post id
Результат Array containing images

from_slideshow() статический публичный Метод

If a slideshow is embedded within a post, then parse out the images involved and return them
static public from_slideshow ( $post_id, $width = 200, $height = 200 )

from_thumbnail() статический публичный Метод

Check if a Featured Image is set for this post, and return it in a similar format to the other images?_from_*() methods.
static public from_thumbnail ( integer $post_id, $width = 200, $height = 200 ) : Array
$post_id integer The post ID to check
Результат Array containing details of the Featured Image, or empty array if none.

get_image() статический публичный Метод

Run through the different methods that we have available to try to find a single good display image for this post.
static public get_image ( integer $post_id, array $args = [] ) : Array
$post_id integer
$args array Other arguments (currently width and height required for images where possible to determine)
Результат Array containing details of the best image to be used

get_images() статический публичный Метод

Get an array containing a collection of possible images for this post, stopping once we hit a method that returns something useful.
static public get_images ( integer $post_id, array $args = [] ) : Array
$post_id integer
$args array Optional args, see defaults list for details
Результат Array containing images that would be good for representing this post