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

PHP wp_prepare_attachment_for_js函数代码示例

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

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



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

示例1: ajax_get_image

 /**
  * Ajax handler to retrieve content from Resource space and add as attachment.
  */
 function ajax_get_image()
 {
     $resource_id = intval($_POST['resource_id']);
     $parent_post_id = isset($_POST['post']) ? intval($_POST['post']) : 0;
     if (empty($resource_id)) {
         wp_send_json_error(esc_html__('Empty resource id', 'resourcespace'));
     }
     $url = PJ_RESOURCE_SPACE_DOMAIN . '/plugins/api_search/';
     $key = PJ_RESOURCE_SPACE_KEY;
     $url = add_query_arg(array('key' => $key, 'search' => $resource_id, 'prettyfieldnames' => 1, 'previewsize' => 'pre', 'original' => true), $url);
     $request_args = array('headers' => array());
     // Pass basic auth header if available.
     if (defined('PJ_RESOURCE_SPACE_AUTHL') && defined('PJ_RESOURCE_SPACE_AUTHP')) {
         $request_args['headers']['Authorization'] = 'Basic ' . base64_encode(PJ_RESOURCE_SPACE_AUTHL . ':' . PJ_RESOURCE_SPACE_AUTHP);
     }
     $response = wp_remote_get($url, $request_args);
     if (200 == wp_remote_retrieve_response_code($response)) {
         $data = json_decode(wp_remote_retrieve_body($response));
     } else {
         wp_send_json_error(esc_html__('Unable to query API', 'resourcespace'));
     }
     if (count($data) < 1) {
         wp_send_json_error(esc_html__('Resource not found', 'resourcespace'));
     }
     // Request original URL.
     // $attachment_id = $this->sideload_image( $data[0]->original );
     // Request preview size.
     $attachment_id = $this->sideload_image($data[0]->preview);
     if (is_wp_error($attachment_id)) {
         wp_send_json_error($attachment_id->get_error_message());
     } else {
         wp_send_json_success(wp_prepare_attachment_for_js($attachment_id));
     }
     exit;
 }
开发者ID:humanmade,项目名称:MEXP-Resource-Space,代码行数:38,代码来源:class-resource-space-loader.php


示例2: get_image

 function get_image($image_id)
 {
     $attachment_data = wp_prepare_attachment_for_js($image_id);
     $image = wp_array_slice_assoc($attachment_data, array('sizes', 'caption', 'description'));
     if (empty($image)) {
         return false;
     }
     foreach ($this->sizes as $size) {
         $size_name = $size;
         if (!isset($image['sizes'][$size])) {
             $size = 'full';
             $image['error'] = "wrong-size";
         }
         // Format Data
         $image[$size_name]['img'] = $image['sizes'][$size]['url'];
         $image[$size_name]['width'] = $image['sizes'][$size]['width'];
         $image[$size_name]['height'] = $image['sizes'][$size]['height'];
     }
     $image['id'] = $image_id;
     $image['desc'] = $image['description'];
     unset($image['sizes'], $image['description']);
     if (!$this->has_descriptions && !empty($image['description'])) {
         $this->has_descriptions = true;
     }
     $image['desc'] = htmlspecialchars(str_replace('"', '&quot;', $image['desc']), ENT_QUOTES);
     $image['caption'] = htmlspecialchars(str_replace('"', '&quot;', $image['caption']), ENT_QUOTES);
     return $image;
 }
开发者ID:justnorris,项目名称:village-client-area,代码行数:28,代码来源:CA_Gallery_Data.class.php


示例3: json

 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @see WP_Fields_API_Control::to_json()
  */
 public function json()
 {
     $json = parent::json();
     $json['mime_type'] = $this->mime_type;
     $json['button_labels'] = $this->button_labels;
     $json['canUpload'] = current_user_can('upload_files');
     $value = $this->value();
     if (is_object($this->field)) {
         if ($this->field->default) {
             // Fake an attachment model - needs all fields used by template.
             // Note that the default value must be a URL, NOT an attachment ID.
             $type = 'document';
             if (in_array(substr($this->field->default, -3), array('jpg', 'png', 'gif', 'bmp'))) {
                 $type = 'image';
             }
             $default_attachment = array('id' => 1, 'url' => $this->field->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->field->default));
             if ('image' === $type) {
                 $default_attachment['sizes'] = array('full' => array('url' => $this->field->default));
             }
             $json['defaultAttachment'] = $default_attachment;
         }
         if ($value && $this->field->default && $value === $this->field->default) {
             // Set the default as the attachment.
             $json['attachment'] = $json['defaultAttachment'];
         } elseif ($value) {
             $json['attachment'] = wp_prepare_attachment_for_js($value);
         }
     }
     return $json;
 }
开发者ID:machouinard,项目名称:wordpress-fields-api,代码行数:35,代码来源:class-wp-fields-api-media-control.php


示例4: to_json

 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @see WP_Fields_API_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $this->json['label'] = html_entity_decode($this->label, ENT_QUOTES, get_bloginfo('charset'));
     $this->json['mime_type'] = $this->mime_type;
     $this->json['button_labels'] = $this->button_labels;
     $this->json['canUpload'] = current_user_can('upload_files');
     $value = $this->value();
     if (is_object($this->setting)) {
         if ($this->setting->default) {
             // Fake an attachment model - needs all fields used by template.
             // Note that the default value must be a URL, NOT an attachment ID.
             $type = in_array(substr($this->setting->default, -3), array('jpg', 'png', 'gif', 'bmp')) ? 'image' : 'document';
             $default_attachment = array('id' => 1, 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->setting->default));
             if ('image' === $type) {
                 $default_attachment['sizes'] = array('full' => array('url' => $this->setting->default));
             }
             $this->json['defaultAttachment'] = $default_attachment;
         }
         if ($value && $this->setting->default && $value === $this->setting->default) {
             // Set the default as the attachment.
             $this->json['attachment'] = $this->json['defaultAttachment'];
         } elseif ($value) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($value);
         }
     }
 }
开发者ID:Ramoonus,项目名称:wordpress-fields-api,代码行数:32,代码来源:class-wp-fields-api-media-control.php


示例5: blocks_get_gallery

function blocks_get_gallery($post_id)
{
    $ret = array('tags' => array(), 'images' => array());
    $gallery = get_post_gallery($post_id, false);
    $gallery_ids = $gallery ? explode(',', $gallery['ids']) : array();
    foreach ($gallery_ids as $id) {
        $thumb = wp_get_attachment_image_src($id, 'medium');
        $image = wp_get_attachment_image_src($id, 'large');
        if ($thumb && $image) {
            $image_data = array('tags' => array(), 'tags_string' => '');
            $image_data['thumbnail'] = $thumb;
            $image_data['image'] = $image;
            $image_data['tags'] = wp_get_post_tags($id);
            foreach ($image_data['tags'] as $tag) {
                $ret['tags'][$tag->slug] = $tag->name;
                $image_data['tags_string'] .= ' ' . $tag->slug;
            }
            $data = wp_prepare_attachment_for_js($id);
            $image_data['title'] = $data['title'];
            $image_data['caption'] = $data['caption'];
            $image_data['alt'] = $data['alt'];
            $image_data['description'] = $data['description'];
            $image_data['link'] = get_post_meta($id, "_blocks_link", true);
            $ret['images'][] = $image_data;
        }
    }
    asort($ret['tags']);
    return $ret;
}
开发者ID:hsnyc,项目名称:gedestad,代码行数:29,代码来源:wp_blocks.php


示例6: thumbnail

function thumbnail($sizeW = 300, $sizeH = 300, $params = array(), $postid = null, $thumbnailid = null, $echo = true)
{
    if ($postid == null) {
        $postid = get_the_ID();
    }
    $post = get_post($postid);
    $thumbnailid = $thumbnailid == null ? get_post_thumbnail_id($post->ID) : $thumbnailid;
    $datas = wp_prepare_attachment_for_js($thumbnailid);
    // extract intersting data
    $params['alt'] = isset($params['alt']) ? $params['alt'] : $datas['alt'];
    $image_path = the_thumbnail($sizeW, $sizeH, $postid, $thumbnailid);
    foreach ($params as $k => $param) {
        if ($param == 'ORIGINAL-SRC') {
            $params[$k] = $datas['url'];
        }
        if ($param == 'SRC') {
            $params[$k] = $image_path;
        }
    }
    $params['src'] = isset($params['src']) ? $params['src'] : $image_path;
    $s = parse_to_html($params);
    if ($echo == true) {
        echo '<img' . $s . '/>';
    } else {
        return '<img' . $s . '/>';
    }
}
开发者ID:Malagasy,项目名称:arpt-wp-plugs,代码行数:27,代码来源:images.php


示例7: getAttachment

 public function getAttachment($attachmentId, $width = null, $height = null, $crop = false, $bookId = false)
 {
     $width = (int) $width;
     $height = (int) $height;
     $cachedUrl = $this->getAttachUrlCached($attachmentId, $width, $height, $crop, $bookId);
     if ($cachedUrl) {
         return $cachedUrl;
     }
     $attachment = wp_prepare_attachment_for_js($attachmentId);
     $filePath = $this->getFilePath($attachment['url']);
     // First try:
     // Trying to find image in wordpress sizes.
     if (!empty($attachment) && $attachment['sizes']) {
         foreach ($attachment['sizes'] as $size) {
             if ($width && $width === $size['width'] && ($height && $height === $size['height'])) {
                 $this->saveAttachUrlCached($attachmentId, $width, $height, $crop, $bookId, $size['url']);
                 return $size['url'];
             }
         }
     }
     // Second try
     // Trying to find cropped images.
     $filename = pathinfo($filePath, PATHINFO_FILENAME);
     $filename = $filename . '-' . $width . 'x' . $height . '.' . pathinfo($filePath, PATHINFO_EXTENSION);
     if (is_file($file = dirname($filePath) . '/' . $filename)) {
         $imgUrl = str_replace(ABSPATH, get_bloginfo('wpurl') . '/', $file);
         $this->saveAttachUrlCached($attachmentId, $width, $height, $crop, $bookId, $imgUrl);
         return str_replace(ABSPATH, get_bloginfo('wpurl') . '/', $file);
     }
     // Third and last try
     $editor = wp_get_image_editor($filePath);
     if (!has_filter('image_resize_dimensions', 'image_crop_dimensions')) {
         function image_crop_dimensions($default, $orig_w, $orig_h, $new_w, $new_h, $crop)
         {
             if (!$crop || !$new_w || !$new_h) {
                 return null;
             }
             $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
             $crop_w = round($new_w / $size_ratio);
             $crop_h = round($new_h / $size_ratio);
             $s_x = floor(($orig_w - $crop_w) / 2);
             $s_y = floor(($orig_h - $crop_h) / 2);
             return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
         }
         add_filter('image_resize_dimensions', 'image_crop_dimensions', 10, 6);
     }
     if (is_wp_error($editor) || is_wp_error($editor->resize($width, $height, (bool) $crop))) {
         $imgUrl = isset($attachment['sizes'], $attachment['sizes']['full'], $attachment['sizes']['full']['url']) ? $attachment['sizes']['full']['url'] : $attachment['url'];
         $this->saveAttachUrlCached($attachmentId, $width, $height, $crop, $bookId, $imgUrl);
         return $imgUrl;
     }
     if (is_wp_error($data = $editor->save())) {
         return $attachment['sizes']['full']['url'];
     }
     $editor = null;
     unset($editor);
     $imgUrl = str_replace(ABSPATH, get_bloginfo('wpurl') . '/', $data['path']);
     $this->saveAttachUrlCached($attachmentId, $width, $height, $crop, $bookId, $imgUrl);
     return str_replace(ABSPATH, get_bloginfo('wpurl') . '/', $data['path']);
 }
开发者ID:estrategasdigitales,项目名称:dictobas,代码行数:60,代码来源:Attachment.php


示例8: get_gallery_post

function get_gallery_post()
{
    if (isset($_POST['id']) && !empty($_POST['id'])) {
        $projectsCats = array('cocheras', 'terrazas', 'habitaciones', 'antes-despues');
        $id = $_POST['id'];
        $post = get_post($id);
        $gallery = get_post_gallery($post->ID, false);
        $category = get_the_category($post->ID);
        $cat_elements = array();
        $cat_info = array();
        foreach ($projectsCats as $cat) {
            $catdata = get_category_by_slug($cat);
            $args = array('category_name' => $cat, 'orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'ASC', 'posts_per_page' => 3);
            $projects = new WP_Query($args);
            array_push($cat_info, $catdata);
            array_push($cat_elements, $projects);
        }
        if ($gallery !== false) {
            $gallerydata = array();
            $images = explode(',', $gallery['ids']);
            foreach ($images as $key => $image) {
                $imagedata = wp_prepare_attachment_for_js($image);
                array_push($gallerydata, $imagedata);
            }
            $post_info = array('post' => $post, 'category' => $category, 'categories' => $cat_elements, 'cat_info' => $cat_info, 'gallery' => $gallerydata);
            echo json_encode($post_info);
        }
        die;
    } else {
        echo 'error';
        die;
    }
    die;
}
开发者ID:hugobel,项目名称:wp-shadox,代码行数:34,代码来源:functions.php


示例9: get_attachment_data

 /**
  * Returns an object with data for an attachment using
  * wp_prepare_attachment_for_js based on the provided id.
  *
  * @since 1.0
  * @param string $id The attachment id.
  * @return object
  */
 public static function get_attachment_data($id)
 {
     $data = wp_prepare_attachment_for_js($id);
     if (gettype($data) == 'array') {
         return json_decode(json_encode($data));
     }
     return $data;
 }
开发者ID:nullality,项目名称:FEWD-SEA-7,代码行数:16,代码来源:class-fl-builder-photo.php


示例10: get_image

 /**
  * Return image markup
  *
  * carawebs_class_autoloader('Data');
  * StudentStudio\Fetch\Data::image( 2301, 'thumbnail' );
  *
  * @param  [type] $image_ID   [description]
  * @param  string $image_size [description]
  * @return [type]             [description]
  */
 public static function get_image($image_ID, $image_size = 'full')
 {
     $image_object = wp_prepare_attachment_for_js($image_ID);
     $src = $image_object['sizes'][$image_size]['url'];
     $title = $image_object['title'];
     $height = $image_object['sizes'][$image_size]['height'];
     $width = $image_object['sizes'][$image_size]['width'];
     $alt = $image_object['alt'];
     $image = "<img src='{$src}' width='{$width}' height='{$height}' title='{$title}' class='img-responsive'/>";
     return $image;
 }
开发者ID:DavidCWebs,项目名称:lamh-eile,代码行数:21,代码来源:Data.php


示例11: get_featured_images

 /**
  * Returns an array of the featured image details
  *
  * @param 	int 	$postID 		The post ID
  *
  * @return 	array 					Array of info about the featured image
  */
 public function get_featured_images($postID)
 {
     if (empty($postID)) {
         return FALSE;
     }
     $imageID = get_post_thumbnail_id($postID);
     if (empty($imageID)) {
         return FALSE;
     }
     return wp_prepare_attachment_for_js($imageID);
 }
开发者ID:slushman,项目名称:slushman-2016,代码行数:18,代码来源:themekit.php


示例12: to_json

 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @since 3.4.0
  *
  * @uses WP_Customize_Media_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $value = $this->value();
     if ($value) {
         // Get the attachment model for the existing file.
         $attachment_id = attachment_url_to_postid($value);
         if ($attachment_id) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
         }
     }
 }
开发者ID:onedaylabs,项目名称:onedaylabs.com,代码行数:19,代码来源:class-wp-customize-upload-control.php


示例13: view

 function view()
 {
     $args = $this->definition;
     $args['default'] = $args['size']['default'];
     $args['attachment'] = null;
     unset($args['size']['default']);
     usort($args['size'], array(&$this, 'orderSizes'));
     if (!empty($this->value) && !empty($this->value->id)) {
         $args['attachment'] = json_encode(wp_prepare_attachment_for_js($this->value->id));
     }
     $view = $this->propertyHelpers->getView($this->id, $this->groupId, $this->index, $args, json_encode($this->value));
     return $view;
 }
开发者ID:ridewing,项目名称:wp-superpowers,代码行数:13,代码来源:Image.php


示例14: element_shortcode_full

 /**
  * Generate HTML code from shortcode content.
  *
  * @param   array   $atts     Shortcode attributes.
  * @param   string  $content  Current content.
  *
  * @return  string
  */
 public function element_shortcode_full($atts = null, $content = null)
 {
     $arr_params = shortcode_atts($this->config['params'], $atts);
     extract($arr_params);
     $html_elemments = $script = '';
     $image_styles = array();
     if ($image_margin_top) {
         $image_styles[] = "margin-top:{$image_margin_top}px";
     }
     if ($image_margin_bottom) {
         $image_styles[] = "margin-bottom:{$image_margin_bottom}px";
     }
     if ($image_margin_right) {
         $image_styles[] = "margin-right:{$image_margin_right}px";
     }
     if ($image_margin_left) {
         $image_styles[] = "margin-left:{$image_margin_left}px";
     }
     $styles = count($image_styles) ? ' style="' . implode(';', $image_styles) . '"' : '';
     if ($image_file) {
         $html_elemments .= "<div class='contact-img-wrapper {$image_container_style}'>";
         $image_id = IG_Pb_Helper_Functions::get_image_id($image_file);
         $attachment = wp_prepare_attachment_for_js($image_id);
         $image_file = !empty($attachment['sizes'][$image_size]['url']) ? $attachment['sizes'][$image_size]['url'] : $image_file;
         $html_elemments .= "<img src='{$image_file}'{$alt_text}{$styles}{$class_img} />";
         $script = '';
         $target = '';
         $sub_shortcode = IG_Pb_Helper_Shortcode::remove_autop($content);
         $items = explode('<!--seperate-->', $sub_shortcode);
         $items = array_filter($items);
         if ($items) {
             $buttons = "" . implode('', $items) . '';
             $html_elemments .= "<div class='btns-wrapper'><div class='contact-btns'>" . $buttons . "</div><div class='vertical-helper'></div></div>";
         }
         $html_elemments .= '</div>';
         if (strtolower($image_alignment) != 'inherit') {
             if (strtolower($image_alignment) == 'left') {
                 $cls_alignment = 'pull-left';
             }
             if (strtolower($image_alignment) == 'right') {
                 $cls_alignment = 'pull-right';
             }
             if (strtolower($image_alignment) == 'center') {
                 $cls_alignment = 'text-center';
             }
             $html_elemments = "<div class='{$cls_alignment}'>" . $html_elemments . '</div>';
         }
     }
     return $this->element_wrapper($html_elemments . $script, $arr_params);
 }
开发者ID:binq2,项目名称:borealpaddle,代码行数:58,代码来源:contact.php


示例15: ajax_get_image

 /**
  * Ajax handler to retrieve content from Resource space and add as attachment.
  */
 function ajax_get_image()
 {
     $resource_id = intval($_POST['resource_id']);
     $parent_post_id = isset($_POST['post']) ? intval($_POST['post']) : 0;
     if (empty($resource_id)) {
         wp_send_json_error(esc_html__('Empty resource id', 'resourcespace'));
         add_filter('http_request_host_is_external', '__return_true');
     }
     $args = array_map('rawurlencode', array('key' => PJ_RESOURCE_SPACE_KEY, 'search' => '!list' . $resource_id, 'prettyfieldnames' => false, 'original' => true, 'previewsize' => 'pre', 'metadata' => true));
     $url = add_query_arg($args, PJ_RESOURCE_SPACE_DOMAIN . '/plugins/api_search/');
     $request_args = array('headers' => array());
     // Pass basic auth header if available.
     if (defined('PJ_RESOURCE_SPACE_AUTHL') && defined('PJ_RESOURCE_SPACE_AUTHP')) {
         $request_args['headers']['Authorization'] = 'Basic ' . base64_encode(PJ_RESOURCE_SPACE_AUTHL . ':' . PJ_RESOURCE_SPACE_AUTHP);
     }
     $response = wp_remote_get($url, $request_args);
     if (200 == wp_remote_retrieve_response_code($response)) {
         $data = json_decode(wp_remote_retrieve_body($response));
     } else {
         wp_send_json_error(esc_html__('Unable to query API', 'resourcespace'));
     }
     if (count($data) < 1) {
         wp_send_json_error(esc_html__('Resource not found', 'resourcespace'));
     }
     // Request original URL.
     $attachment_id = wpcom_vip_download_image($data[0]->original_link);
     // Update the title to the actual title and content, not the filename
     $postarr = array('ID' => $attachment_id, 'post_title' => $data[0]->field8, 'post_content' => $data[0]->field18);
     wp_update_post($postarr);
     // Update post to show proper values in wp attachment views
     $post = array('ID' => $attachment_id, 'post_title' => isset($data[0]->field8) ? $data[0]->field8 : '', 'post_excerpt' => isset($data[0]->field18) ? $data[0]->field18 : '');
     wp_update_post($post);
     // Update Metadata.
     update_post_meta($attachment_id, 'resource_space', 1);
     // Metadata for connecting resource between Wp and RS
     update_post_meta($attachment_id, 'resource_external_id', $data[0]->ref);
     // Allow plugins to hook in here.
     do_action('resourcespace_import_complete', $attachment_id, $data[0]);
     if (is_wp_error($attachment_id)) {
         wp_send_json_error($attachment_id->get_error_message());
     } else {
         wp_send_json_success(wp_prepare_attachment_for_js($attachment_id));
     }
     exit;
 }
开发者ID:klandestino,项目名称:MEXP-Resource-Space,代码行数:48,代码来源:class-resource-space-loader.php


示例16: __construct

 function __construct($plugin_file_path, $aws)
 {
     parent::__construct($plugin_file_path);
     $this->aws = $aws;
     add_action('aws_admin_menu', array($this, 'admin_menu'));
     $this->plugin_title = __('Amazon S3 Uploader', 'wp_s3');
     $this->plugin_menu_title = __('S3 Uploader', 'wp_s3');
     add_action('wp_ajax_wp_s3-create-bucket', array($this, 'ajax_create_bucket'));
     add_filter('wp_get_attachment_url', array($this, 'wp_get_attachment_url'), 9, 2);
     //add_filter('wp_generate_attachment_metadata', array($this, 'wp_generate_attachment_metadata'), 20, 2);
     //add_filter('delete_attachment', array($this, 'delete_attachment'), 20);
     if (is_admin() && !empty($_FILES) && (!empty($_POST['html-upload']) || $_SERVER['REQUEST_URI'] == '/wp-admin/async-upload.php')) {
         $file = $_FILES['async-upload'];
         if (!is_array($file_info = $this->file_info($file))) {
             die('That file is not allowed: ' . $file_info . '. Hit back to try again.');
         }
         $upload = $this->file_upload($file_info, intval($_POST['post_id']));
         if ($_POST['action'] == 'upload-attachment') {
             $data = wp_prepare_attachment_for_js($upload['id']);
             if (substr($data['url'], 0, 5) == '/tmp/') {
                 $data['url'] = $upload['file'];
             }
             if (substr($data['url'], 0, 2) == '//') {
                 $data['url'] = 'http:' . $data['url'];
             }
             foreach ($upload['sizes'] as $key => $info) {
                 $data['sizes'][$key]['url'] = $upload['prefix'] . $info['file'];
             }
             $data['sizes']['full']['url'] = $data['url'];
             die(json_encode(array('success' => true, 'data' => $data)));
         }
         if (empty($_POST['html-upload'])) {
             die('' . $data['id']);
         }
         header("Location: upload.php");
         die('');
     }
 }
开发者ID:annegrundhoefer,项目名称:algebranation,代码行数:38,代码来源:amazon-s3-uploader.php


示例17: to_json

 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  *
  * highly based on WP_Customize_Media_Control merged with WP_Customize_Upload_Control ::to_json()
  */
 public function to_json()
 {
     $this->json['mime_type'] = $this->mime_type;
     $this->json['button_labels'] = $this->button_labels;
     $this->json['bg_repeat_options'] = $this->bg_repeat_options;
     $this->json['bg_attachment_options'] = $this->bg_attachment_options;
     $this->json['bg_position_options'] = $this->bg_position_options;
     $this->json['canUpload'] = current_user_can('upload_files');
     $this->json['default_model'] = $this->default_model;
     $value = $this->value();
     if (isset($this->setting) && is_object($this->setting)) {
         $_defaults = isset($this->setting->default) ? $this->setting->default : null;
         $default_bg_img = isset($_defaults['background-image']) ? $_defaults['background-image'] : null;
     }
     $default_bg_im = isset($default_bg_img) ? $default_bg_img : null;
     if ($default_bg_img) {
         // Fake an attachment model - needs all fields used by template.
         // Note that the default value must be a URL, NOT an attachment ID.
         $type = in_array(substr($default_bg_img, -3), array('jpg', 'png', 'gif', 'bmp', 'svg')) ? 'image' : 'document';
         $default_attachment = array('id' => 1, 'url' => $default_bg_img, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($default_bg_img));
         $default_attachment['sizes'] = array('full' => array('url' => $default_bg_img));
         $this->json['defaultAttachment'] = $default_attachment;
     }
     $background_image = isset($value['background-image']) ? $value['background-image'] : null;
     if ($background_image && $default_bg_img && $background_image === $default_bg_img) {
         // Set the default as the attachment.
         $this->json['attachment'] = $this->json['defaultAttachment'];
     } elseif ($background_image) {
         $attachment_id = attachment_url_to_postid($background_image);
         if ($attachment_id) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
         } else {
             //already an id
             $this->json['attachment'] = wp_prepare_attachment_for_js($background_image);
         }
     }
     parent::to_json();
 }
开发者ID:giorgioriccardi,项目名称:hueman,代码行数:44,代码来源:class-background-control.php


示例18: to_json

 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  *
  * @Override
  * @see WP_Customize_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $this->json['title'] = !empty($this->title) ? esc_html($this->title) : '';
     $this->json['notice'] = !empty($this->notice) ? $this->notice : '';
     $this->json['dst_width'] = isset($this->dst_width) ? $this->dst_width : $this->width;
     $this->json['dst_height'] = isset($this->dst_height) ? $this->dst_height : $this->height;
     //overload WP_Customize_Upload_Control
     //we need to re-build the absolute url of the logo src set in old Customizr
     $value = $this->value();
     if ($value) {
         //re-build the absolute url if the value isn't an attachment id before retrieving the id
         if ((int) esc_attr($value) < 1) {
             $upload_dir = wp_upload_dir();
             $value = false !== strpos($value, '/wp-content/') ? $value : $upload_dir['baseurl'] . $value;
         }
         // Get the attachment model for the existing file.
         $attachment_id = attachment_url_to_postid($value);
         if ($attachment_id) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
         }
     }
     //end overload
 }
开发者ID:giorgioriccardi,项目名称:hueman,代码行数:31,代码来源:class-cropped-image-control.php


示例19: wp_ajax_crop_image

/**
 * AJAX handler for cropping an image.
 *
 * @since 4.3.0
 *
 * @global WP_Site_Icon $wp_site_icon
 */
function wp_ajax_crop_image()
{
    $attachment_id = absint($_POST['id']);
    check_ajax_referer('image_editor-' . $attachment_id, 'nonce');
    if (!current_user_can('customize')) {
        wp_send_json_error();
    }
    $context = str_replace('_', '-', $_POST['context']);
    $data = array_map('absint', $_POST['cropDetails']);
    $cropped = wp_crop_image($attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height']);
    if (!$cropped || is_wp_error($cropped)) {
        wp_send_json_error(array('message' => __('Image could not be processed.')));
    }
    switch ($context) {
        case 'site-icon':
            require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php';
            global $wp_site_icon;
            // Skip creating a new attachment if the attachment is a Site Icon.
            if (get_post_meta($attachment_id, '_wp_attachment_context', true) == $context) {
                // Delete the temporary cropped file, we don't need it.
                wp_delete_file($cropped);
                // Additional sizes in wp_prepare_attachment_for_js().
                add_filter('image_size_names_choose', array($wp_site_icon, 'additional_sizes'));
                break;
            }
            /** This filter is documented in wp-admin/custom-header.php */
            $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
            // For replication.
            $object = $wp_site_icon->create_attachment_object($cropped, $attachment_id);
            unset($object['ID']);
            // Update the attachment.
            add_filter('intermediate_image_sizes_advanced', array($wp_site_icon, 'additional_sizes'));
            $attachment_id = $wp_site_icon->insert_attachment($object, $cropped);
            remove_filter('intermediate_image_sizes_advanced', array($wp_site_icon, 'additional_sizes'));
            // Additional sizes in wp_prepare_attachment_for_js().
            add_filter('image_size_names_choose', array($wp_site_icon, 'additional_sizes'));
            break;
        default:
            /**
             * Fires before a cropped image is saved.
             *
             * Allows to add filters to modify the way a cropped image is saved.
             *
             * @since 4.3.0
             *
             * @param string $context       The Customizer control requesting the cropped image.
             * @param int    $attachment_id The attachment ID of the original image.
             * @param string $cropped       Path to the cropped image file.
             */
            do_action('wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped);
            /** This filter is documented in wp-admin/custom-header.php */
            $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
            // For replication.
            $parent_url = wp_get_attachment_url($attachment_id);
            $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
            $size = @getimagesize($cropped);
            $image_type = $size ? $size['mime'] : 'image/jpeg';
            $object = array('post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => $image_type, 'guid' => $url, 'context' => $context);
            $attachment_id = wp_insert_attachment($object, $cropped);
            $metadata = wp_generate_attachment_metadata($attachment_id, $cropped);
            /**
             * Filter the cropped image attachment metadata.
             *
             * @since 4.3.0
             *
             * @see wp_generate_attachment_metadata()
             *
             * @param array $metadata Attachment metadata.
             */
            $metadata = apply_filters('wp_ajax_cropped_attachment_metadata', $metadata);
            wp_update_attachment_metadata($attachment_id, $metadata);
            /**
             * Filter the attachment ID for a cropped image.
             *
             * @since 4.3.0
             *
             * @param int    $attachment_id The attachment ID of the cropped image.
             * @param string $context       The Customizer control requesting the cropped image.
             */
            $attachment_id = apply_filters('wp_ajax_cropped_attachment_id', $attachment_id, $context);
    }
    wp_send_json_success(wp_prepare_attachment_for_js($attachment_id));
}
开发者ID:hughnet,项目名称:WordPress,代码行数:90,代码来源:ajax-actions.php


示例20: getAttachment

 public function getAttachment($attachment_id)
 {
     return wp_prepare_attachment_for_js($attachment_id);
 }
开发者ID:neochic,项目名称:woodlets,代码行数:4,代码来源:WordPressWrapper.php



注:本文中的wp_prepare_attachment_for_js函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP wp_prepare_themes_for_js函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_pre_kses_less_than函数代码示例发布时间: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