本文整理汇总了PHP中get_attached_media函数的典型用法代码示例。如果您正苦于以下问题:PHP get_attached_media函数的具体用法?PHP get_attached_media怎么用?PHP get_attached_media使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_attached_media函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: task
/**
* Run the attachment deletion task.
*
* Uses transients to ensure that only small batches of posts are done each time.
* Once a batch is complete, the post offset transient is iterated.
*/
public function task()
{
// Set initial offset
if (false == ($offset = get_transient('media_manager_offset'))) {
set_transient('media_manager_offset', $offset = 0, DAY_IN_SECONDS);
}
$time = time();
while (time() < $time + self::TIME_LIMIT) {
// Get the post IDs
$query = new WP_Query(array('post_type' => $this->get_post_types(), 'posts_per_page' => 1, 'post_status' => 'publish', 'offset' => $offset, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'fields' => 'ids'));
$post_ids = $query->posts;
// Completed all posts, so delete offset and bail out
if (empty($post_ids)) {
delete_transient('media_manager_offset');
return;
}
// Loop through the posts
foreach ($post_ids as $key => $post_id) {
$attached_media = get_attached_media('image', $post_id);
$featured_id = get_post_thumbnail_id($post_id);
// Loop through media attached to each post
foreach ($attached_media as $x => $attachment) {
$attachment_id = $attachment->ID;
// If not a featured image, then delete the attachment
if ($attachment_id != $featured_id) {
wp_delete_post($attachment_id);
}
}
set_transient('media_manager_offset', $offset++, DAY_IN_SECONDS);
}
usleep(0.1 * 1000000);
// Delaying the execution (reduces resource consumption)
}
return;
}
示例2: vskb_columns
function vskb_columns($vskb_cats, $columns, $subcats = false, $excludes = null, $includes = null)
{
$return = "";
$columnNames = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
$return .= '<div id="vskb-' . $columnNames[$columns] . '">' . '<ul class="x-vskb-cat-list">';
$content = '';
// Get list of ICONs or images attached to the KB page, these can be icons.
$media = get_attached_media('image');
$icons = [];
foreach ($media as $key => $val) {
$icons[$val->post_name] = $val->guid;
}
$js = '';
$count = 0;
foreach ($vskb_cats as $cat) {
if (!empty($excludes) && in_array($cat->slug, $excludes)) {
continue;
} else {
if (!empty($includes) && !in_array($cat->slug, $includes)) {
continue;
}
}
// For each category we keep map in JS
$js .= 'cats["' . $cat->slug . '"] = ' . $count . ';';
$img = '';
if (!empty($icons[$cat->slug . '-ico'])) {
$img = '<img class="category-icon" src="' . $icons[$cat->slug . '-ico'] . '">';
}
// $return .= '<ul class="vskb-cat-list"><li class="vskb-cat-name"><a href="'. get_category_link( $cat->cat_ID ) .'" title="'. $cat->name .'" >'. $cat->name .'</a></li>';
$return .= '<li class="x-vskb-cat-name"><a href="#' . $cat->slug . '" title="' . $cat->name . '" >' . $img . $cat->name . '</a></li>';
$catColumn = $subCats ? 'category__in' : 'cat';
$vskb_args = array('orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, $catColumn => $cat->cat_ID);
$vskb_posts = get_posts($vskb_args);
$content .= '<div id="' . $cat->slug . '"><ul class="vskb-cat-list">';
foreach ($vskb_posts as $single_post) {
$content .= '<li class="vskb-post-name">';
$content .= '<a href="' . get_permalink($single_post->ID) . '" rel="bookmark" title="' . get_the_title($single_post->ID) . '">' . get_the_title($single_post->ID) . '</a>';
$content .= '</li>';
}
$content .= '</ul></div>';
$count++;
}
$return .= '</ul>' . $content;
$return .= '</div>';
// Add jQuery
$return .= '<script>
jQuery( function() {
var cats = {};
' . $js . '
console.log( window.location.hash, cats );
whichTab = 0;
jQuery( "#vskb-' . $columnNames[$columns] . '" ).tabs( { active : whichTab }).addClass( "ui-tabs-vertical ui-helper-clearfix" );
jQuery( "#vskb-' . $columnNames[$columns] . ' li.x-vskb-cat-name" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
});
</script>';
return $return;
}
示例3: get_post_field_images
/**
* Given information provided in an entry, get array of media IDs
*
* This is necessary because GF doesn't expect to need to update post images, only to create them.
*
* @see GFFormsModel::create_post()
*
* @since 1.17
*
* @param array $form Gravity Forms form array
* @param array $entry Gravity Forms entry array
*
* @return array Array of "Field ID" => "Media IDs"
*/
public static function get_post_field_images($form, $entry)
{
$post_data = self::get_post_fields($form, $entry);
$media = get_attached_media('image', $entry['post_id']);
$post_images = array();
foreach ($media as $media_item) {
foreach ((array) $post_data['images'] as $post_data_item) {
if (rgar($post_data_item, 'title') === $media_item->post_title && rgar($post_data_item, 'description') === $media_item->post_content && rgar($post_data_item, 'caption') === $media_item->post_excerpt) {
$post_images["{$post_data_item['field_id']}"] = $media_item->ID;
}
}
}
return $post_images;
}
示例4: get_items
public function get_items($request)
{
$id = $request['id'];
$type = $request['type'];
$query_result = get_attached_media($type, $id);
$medias = array();
foreach ($query_result as $media) {
//$mediaItem = json_decode(get_data(rest_url('wp/v2/media/' . $media->ID)));
$data = $this->prepare_item_for_response($media, $request);
$medias[] = $this->prepare_response_for_collection($data);
//$medias[] = $data;
}
$response = rest_ensure_response($medias);
return $response;
}
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:15,代码来源:class-wp-rest-media-extras-controller.php
示例5: delete_slider
function delete_slider()
{
global $wpdb;
// this is how you get access to the database
$postId = intval(substr($_POST['slide-id'], 6));
//first, delete all images attached to the post
$attaches = get_attached_media('image', $postId);
foreach ($attaches as $image) {
wp_delete_attachment($image->ID, true);
}
//second,delete the post itself
$deleted = wp_delete_post($postId, true);
if ($deleted != false) {
echo '1';
} else {
echo '-1';
}
wp_die();
// this is required to terminate immediately and return a proper response
}
示例6: post_helper_basic
/**
* @test
*/
public function post_helper_basic()
{
$num_categories = 3;
$categories = $this->factory->category->create_many($num_categories);
array_shift($categories);
$args = array('post_name' => 'slug', 'post_author' => '1', 'post_date' => '2012-11-15 20:00:00', 'post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'title', 'post_content' => 'content', 'post_category' => $categories, 'post_tags' => array('tag1', 'tag2'));
$helper = new Helper($args);
$post_id = $helper->insert();
$post = get_post($post_id);
foreach ($args as $key => $value) {
if ('post_category' === $key || 'post_tags' === $key) {
continue;
}
$this->assertSame($value, $post->{$key});
}
$this->assertSame(2, count(get_the_tags($post_id)));
$this->assertSame(count($categories), count(wp_get_object_terms($post_id, 'category')));
// it should be success to upload and should be attached to the post
$attachment_id = $helper->add_media('http://placehold.jp/100x100.png', 'title', 'description', 'caption', false);
$media = get_attached_media('image', $post_id);
$this->assertSame($attachment_id, $media[$attachment_id]->ID);
}
示例7: get_photos
private function get_photos()
{
$media = get_attached_media('image', $this->post->ID);
$photos = array();
foreach ($media as $object) {
$photos[] = ['href' => wp_get_attachment_url($object->ID), 'caption' => wptexturize($object->post_content), 'credit' => $object->post_excerpt];
}
return $photos;
}
示例8: getThumbs
function getThumbs($post_id)
{
$attatchments = get_attached_media('image', $post_id);
$attatchments_uris = array();
foreach ($attatchments as $attch) {
$attatchments_uris[] = wp_get_attachment_url($attch->ID);
}
return $attatchments_uris;
}
示例9: process
//.........这里部分代码省略.........
// Page Template
if ('page' == $articleData['post_type'] and wp_all_import_is_update_cf('_wp_page_template', $this->options) and (!empty($this->options['page_template']) or "no" == $this->options['is_multiple_page_template'])) {
update_post_meta($pid, '_wp_page_template', "no" == $this->options['is_multiple_page_template'] ? $page_template[$i] : $this->options['page_template']);
}
// [featured image]
$is_allow_import_images = apply_filters('wp_all_import_is_allow_import_images', false, $articleData['post_type']);
if (!empty($uploads) and false === $uploads['error'] and ($articleData['post_type'] == "product" and class_exists('PMWI_Plugin') or $is_allow_import_images) and (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_images'])) {
if (!empty($images_bundle)) {
$is_show_add_new_images = apply_filters('wp_all_import_is_show_add_new_images', true, $post_type[$i]);
foreach ($images_bundle as $slug => $bundle_data) {
$featured_images = $bundle_data['files'];
$option_slug = $slug == 'pmxi_gallery_image' ? '' : $slug;
if (!empty($featured_images[$i])) {
$targetDir = $uploads['path'];
$targetUrl = $uploads['url'];
$logger and call_user_func($logger, __('<b>IMAGES:</b>', 'wp_all_import_plugin'));
if (!@is_writable($targetDir)) {
$logger and call_user_func($logger, sprintf(__('<b>ERROR</b>: Target directory %s is not writable', 'wp_all_import_plugin'), $targetDir));
} else {
require_once ABSPATH . 'wp-admin/includes/image.php';
$success_images = false;
$gallery_attachment_ids = array();
$imgs = array();
$featured_delim = "yes" == $this->options[$option_slug . 'download_images'] ? $this->options[$option_slug . 'download_featured_delim'] : $this->options[$option_slug . 'featured_delim'];
$line_imgs = explode("\n", $featured_images[$i]);
if (!empty($line_imgs)) {
foreach ($line_imgs as $line_img) {
$imgs = array_merge($imgs, !empty($featured_delim) ? str_getcsv($line_img, $featured_delim) : array($line_img));
}
}
// keep existing and add newest images
if (!empty($articleData['ID']) and $this->options['is_update_images'] and $this->options['update_images_logic'] == "add_new" and $this->options['update_all_data'] == "no" and $is_show_add_new_images) {
$logger and call_user_func($logger, __('- Keep existing and add newest images ...', 'wp_all_import_plugin'));
$attachment_imgs = get_attached_media('image', $pid);
if ($post_type[$i] == "product") {
$gallery_attachment_ids = array_filter(explode(",", get_post_meta($pid, '_product_image_gallery', true)));
}
if ($attachment_imgs) {
foreach ($attachment_imgs as $attachment_img) {
$post_thumbnail_id = get_post_thumbnail_id($pid);
if (empty($post_thumbnail_id) and $this->options[$option_slug . 'is_featured']) {
set_post_thumbnail($pid, $attachment_img->ID);
} elseif (!in_array($attachment_img->ID, $gallery_attachment_ids) and $post_thumbnail_id != $attachment_img->ID) {
$gallery_attachment_ids[] = $attachment_img->ID;
}
}
$success_images = true;
}
if (!empty($gallery_attachment_ids)) {
foreach ($gallery_attachment_ids as $aid) {
do_action($slug, $pid, $aid, wp_get_attachment_url($aid), 'update_images');
}
}
}
if (!empty($imgs)) {
if ($this->options[$option_slug . 'set_image_meta_title'] and !empty($image_meta_titles_bundle[$slug])) {
$img_titles = array();
$line_img_titles = explode("\n", $image_meta_titles_bundle[$slug][$i]);
if (!empty($line_img_titles)) {
foreach ($line_img_titles as $line_img_title) {
$img_titles = array_merge($img_titles, !empty($this->options[$option_slug . 'image_meta_title_delim']) ? str_getcsv($line_img_title, $this->options[$option_slug . 'image_meta_title_delim']) : array($line_img_title));
}
}
}
if ($this->options[$option_slug . 'set_image_meta_caption'] and !empty($image_meta_captions_bundle[$slug])) {
$img_captions = array();
示例10: getIncidentMediaList
/**
* Returns an HTML structure containing nested lists and list items
* referring to any media attached to the given post ID.
*
* @param int $post_id The post ID from which to fetch attached media.
*
* @uses WP_Buoy_Alert::getIncidentMediaHtml()
*
* @return string HTML ready for insertion into an `<ul>` element.
*/
private static function getIncidentMediaList($post_id)
{
$html = '';
$posts = array('video' => get_attached_media('video', $post_id), 'image' => get_attached_media('image', $post_id), 'audio' => get_attached_media('audio', $post_id));
foreach ($posts as $type => $set) {
$html .= '<li class="' . esc_attr($type) . ' list-group">';
$html .= '<div class="list-group-item">';
$html .= '<h4 class="list-group-item-heading">';
switch ($type) {
case 'video':
$html .= esc_html('Video attachments', 'buoy');
break;
case 'image':
$html .= esc_html('Image attachments', 'buoy');
break;
case 'audio':
$html .= esc_html('Audio attachments', 'buoy');
break;
}
$html .= ' <span class="badge">' . count($set) . '</span>';
$html .= '</h4>';
$html .= '<ul>';
foreach ($set as $post) {
$html .= '<li id="incident-media-' . $post->ID . '" class="list-group-item">';
$html .= '<h5 class="list-group-item-header">' . esc_html($post->post_title) . '</h5>';
$html .= self::getIncidentMediaHtml($type, $post->ID);
$html .= '<p class="list-group-item-text">';
$html .= sprintf(esc_html_x('uploaded %1$s ago', 'Example: uploaded 5 mins ago', 'buoy'), human_time_diff(strtotime($post->post_date_gmt)));
$u = get_userdata($post->post_author);
$html .= ' ' . sprintf(esc_html_x('by %1$s', 'a byline, like "written by Bob"', 'buoy'), $u->display_name);
$html .= '</p>';
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</li>';
}
return $html;
}
示例11: get_posts
$slidePosts = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_parent' => $id, 'post_type' => 'Micro Slider'));
?>
<div id="all-slides">
<?php
// wp_delete_post(431, true);
//+проверка на пустую картинку
?>
<?php
// echo "<pre>";
// print_r($slidePosts);
// echo "</pre>";
?>
<?php
foreach ($slidePosts as $slider) {
$attach = get_attached_media('image', $slider->ID);
$cleanedObject = reset($attach);
// print_r(reset($attach)->guid);
//echo "<img src='" . reset($attach)->guid . "' />" . "<br />";
?>
<div class="single-slide" id="item-<?php
echo $cleanedObject->post_parent;
?>
">
<div class="image">
<img src="<?php
echo $cleanedObject->guid;
?>
" />
</div>
示例12: _s_get_post_image_uri
/**
* Return an image URI, no matter what.
*
* @param string $size The image size you want to return.
* @return string The image URI.
*/
function _s_get_post_image_uri($size = 'thumbnail')
{
// If featured image is present, use that.
if (has_post_thumbnail()) {
$featured_image_id = get_post_thumbnail_id(get_the_ID());
$media = wp_get_attachment_image_src($featured_image_id, $size);
if (is_array($media)) {
return current($media);
}
}
// Check for any attached image.
$media = get_attached_media('image', get_the_ID());
$media = current($media);
// Set up default image path.
$media_url = get_stylesheet_directory_uri() . '/assets/images/placeholder.png';
// If an image is present, then use it.
if (is_array($media) && 0 < count($media)) {
$media_url = 'thumbnail' === $size ? wp_get_attachment_thumb_url($media->ID) : wp_get_attachment_url($media->ID);
}
return $media_url;
}
示例13: test_get_attached_images
/**
* @ticket 22960
*/
function test_get_attached_images() {
$post_id = $this->factory->post->create();
$attachment_id = $this->factory->attachment->create_object( $this->img_name, $post_id, array(
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment'
) );
$images = get_attached_media( 'image', $post_id );
$this->assertEquals( $images, array( $attachment_id => get_post( $attachment_id ) ) );
}
示例14: custom_video_shortcode
function custom_video_shortcode($attr, $content = '')
{
global $content_width;
$post_id = get_post() ? get_the_ID() : 0;
static $instances = 0;
$instances++;
/**
* Override the default video shortcode.
*
* @since 3.7.0
*
* @param null Empty variable to be replaced with shortcode markup.
* @param array $attr Attributes of the shortcode.
* @param string $content Shortcode content.
* @param int $instances Unique numeric ID of this video shortcode instance.
*/
$html = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instances);
if ('' !== $html) {
return $html;
}
$video = null;
$default_types = wp_get_video_extensions();
$defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'height' => 1080, 'width' => empty($content_width) ? 1920 : $content_width, 'size' => '');
foreach ($default_types as $type) {
$defaults_atts[$type] = '';
}
$atts = shortcode_atts($defaults_atts, $attr, 'video');
extract($atts);
$w = $width;
$h = $height;
if (is_admin() && $width > 600) {
$w = 1920;
} elseif (!is_admin() && $w > $defaults_atts['width']) {
$w = $defaults_atts['width'];
}
if ($w < $width) {
$height = round($h * $w / $width);
}
$width = $w;
$primary = false;
if (!empty($src)) {
$type = wp_check_filetype($src, wp_get_mime_types());
if (!in_array(strtolower($type['ext']), $default_types)) {
return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($src), esc_html($src));
}
$primary = true;
array_unshift($default_types, 'src');
} else {
foreach ($default_types as $ext) {
if (!empty(${$ext})) {
$type = wp_check_filetype(${$ext}, wp_get_mime_types());
if (strtolower($type['ext']) === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_media('video', $post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$src = wp_get_attachment_url($video->ID);
if (empty($src)) {
return;
}
array_unshift($default_types, 'src');
}
$library = apply_filters('wp_video_shortcode_library', 'mediaelement');
/*if ( 'mediaelement' === $library && did_action( 'init' ) ) {
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );
}
/*$atts = array(
'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
'id' => sprintf( 'video-%d-%d', $post_id, $instances ),
'width' => absint( $width ),
'height' => absint( $height ),
'poster' => esc_url( $poster ),
'loop' => $loop,
'autoplay' => $autoplay,
'preload' => $preload,
);*/
// These ones should just be omitted altogether if they are blank
foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
if (empty($atts[$a])) {
unset($atts[$a]);
}
}
$attr_strings = array();
foreach ($atts as $k => $v) {
$attr_strings[] = $k . '="' . esc_attr($v) . '"';
}
$html .= '<video id="videoplayer" class="video-js vjs-mnml ' . $size . '" controls="controls" data-setup>';
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty(${$fallback})) {
//.........这里部分代码省略.........
示例15: artempol_get_posts
}
// News
$news = artempol_get_posts('news-list', array('category_name' => 'news', 'posts_per_page' => get_theme_mod('news-main-number', 2)), array('image', 'title', 'url', 'date', 'content'));
if ($news) {
$heading = artempol_container(array('tag' => 'h2', 'content' => __('News', 'artempol')));
$news = artempol_container(array('tag' => 'div', 'content' => $heading . $news, 'class' => 'content_wrap news padding_tb_20 wow fadeInUp'));
echo $news;
}
// Colored_blocks
$colored_blocks = artempol_get_posts('colored', array('category_name' => 'colorblocks'), array('counter', 'title', 'content'));
if ($colored_blocks) {
$colored_blocks = artempol_container(array('tag' => 'div', 'content' => $colored_blocks, 'class' => 'content_wrap clearfix padding_tb_10 wow fadeInUp'));
echo $colored_blocks;
}
// Achievements
$images = get_attached_media('image', get_theme_mod('achievements-page'));
$achievements = '';
foreach ($images as $post) {
$achievements .= artempol_get_post($post, 'achievements', array('achievement_image', 'achievement_url', 'achievement_margin'));
}
if ($achievements) {
$achievements = artempol_container(array('tag' => 'ul', 'content' => $achievements, 'class' => 'slides'));
$achievements = artempol_container(array('tag' => 'div', 'content' => $achievements, 'class' => 'slider-achieve flexslider wow fadeInUp'));
$achievements = artempol_container(array(), 'line') . $achievements;
echo $achievements;
}
// Services
$services = get_post(get_theme_mod('services-page'));
if ($services) {
$services = artempol_get_post($services, 'services', array('title', 'content'));
echo $services;