/** * * @param string $content * @return string */ function plusify_content($content) { include_once ATTACHMENTS_PP_PATH . 'class-library.php'; // only handle attachments that aren't already embedded (namely, not images) if (is_attachment() && !wp_attachment_is_image()) { $embed = AttachmentsPPLib::get_embedded_attachment(); if (!empty($embed)) { // remove "attachment" class from $content -- it will be // included in the outer div around the embedder & existing content $regex = '#(.*)<(p|div)\\s*class=[\'"]([-_A-Za-z ]*)attachment([-_A-Za-z ]*)[\'"]>(.*)</\\2>(.*)#is'; if (preg_match($regex, $content, $matches)) { $matches[3] = trim($matches[3]); $matches[4] = trim($matches[4]); $classes = ''; if (!empty($matches[3]) || !empty($matches[4])) { if (!empty($matches[3]) && !empty($matches[4])) { $classes = ' class="' . $matches[3] . ' ' . $matches[4] . '"'; } else { $classes = ' class="' . $matches[3] . $matches[4] . '"'; } } $content = $matches[1] . '<' . $matches[2] . $classes . '>' . $matches[5] . '</' . $matches[2] . '>' . $matches[6]; } $content = '<div class="attachment">' . $embed . $content . '</div>'; } } // Returns the content. return $content; }
/** * Check AM_MBF for description. * * @todo Set class on div to set if the image has been selected and get rid of $hide_upload_button and $hide_clear_button. * * @since 1.0.0 */ public function output() { // Get the file id, 0 represents a new field. $image_id = intval($this->value) > 0 ? intval($this->value) : 0; $image_url = ''; $image_title = ''; $class_icon = ''; $hide_upload_button = $hide_clear_button = ' style="display:none;"'; // Make sure the selected image is valid. if ($image_id > 0) { $post = get_post($image_id); if (isset($post) && wp_attachment_is_image($image_id)) { $image_url = wp_get_attachment_thumb_url($image_id); $image_title = $post->post_title; } else { $this->error = __(sprintf('Selected Image (ID:%1$d) is invalid.', $image_id), 'am-cpts'); $class_icon = ' invalid'; } $hide_clear_button = ''; } else { $hide_upload_button = ''; } // Text used by wp.media frame. $wp_media_data = sprintf(' data-title="%1$s" data-button="%2$s"', esc_attr__('Choose an Image', 'am-cpts'), esc_attr__('Use this Image', 'am-cpts')); return sprintf(' <div%11$s> <input name="%2$s" type="hidden" class="meta-box-upload-image" value="%1$d"%12$s /> <img src="%10$s" class="meta-box-preview-image%3$s" title="%7$s" alt="%6$s"%5$s /> <a href="#" class="meta-box-upload-image-button button"%4$s%13$s>%8$s</a> <span class="meta-box-image-title"%5$s>%6$s</span> <a href="#" class="meta-box-clear-image-button"%5$s>%9$s</a> </div>', esc_attr($image_id), esc_attr($this->name), $class_icon, $hide_upload_button, $hide_clear_button, isset($this->error) ? esc_html($this->error) : $image_title, esc_attr__('Selected Image', 'am-cpts'), esc_html__('Choose Image', 'am-cpts'), esc_html__('Remove Image', 'am-cpts'), esc_url($image_url), $this->get_classes('meta-box-image'), $this->get_data_atts(), $wp_media_data); }
/** * 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; }
public static function attach_html($attach_id, $type = NULL) { if (!$type) { $type = isset($_GET['type']) ? $_GET['type'] : 'image'; } $attachment = get_post($attach_id); if (!$attachment) { return; } if (wp_attachment_is_image($attach_id)) { $image = wp_get_attachment_image_src($attach_id, 'thumbnail'); $image = $image[0]; } else { $image = wp_mime_type_icon($attach_id); } $html = '<li class="wpuf-image-wrap thumbnail">'; $html .= sprintf('<div class="attachment-name"><img src="%s" alt="%s" /></div>', $image, esc_attr($attachment->post_title)); if (wpuf_get_option('image_caption', 'wpuf_general', 'off') == 'on') { $html .= '<div class="wpuf-file-input-wrap">'; $html .= sprintf('<input type="text" name="wpuf_files_data[%d][title]" value="%s" placeholder="%s">', $attach_id, esc_attr($attachment->post_title), __('Title', 'wpuf')); $html .= sprintf('<textarea name="wpuf_files_data[%d][caption]" placeholder="%s">%s</textarea>', $attach_id, __('Caption', 'wpuf'), esc_textarea($attachment->post_excerpt)); $html .= sprintf('<textarea name="wpuf_files_data[%d][desc]" placeholder="%s">%s</textarea>', $attach_id, __('Description', 'wpuf'), esc_textarea($attachment->post_content)); $html .= '</div>'; } $html .= sprintf('<input type="hidden" name="wpuf_files[%s][]" value="%d">', $type, $attach_id); $html .= sprintf('<div class="caption"><a href="#" class="btn btn-danger btn-small attachment-delete" data-attach_id="%d">%s</a></div>', $attach_id, __('Delete', 'wpuf')); $html .= '</li>'; return $html; }
function yoimg_media_row_actions($actions, $post, $detached) { if (wp_attachment_is_image($post->ID) && current_user_can('edit_post', $post->ID)) { $actions['yoimg_crop'] = yoimg_get_edit_image_anchor($post->ID); } return $actions; }
/** * Delete attachments linked to a specified post * @param int $parent_id Parent id of post to delete attachments for */ function wp_delete_attachments($parent_id, $unlink = true, $type = 'images') { if ($type == 'images' and has_post_thumbnail($parent_id)) { delete_post_thumbnail($parent_id); } $ids = array(); $attachments = get_posts(array('post_parent' => $parent_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null)); foreach ($attachments as $attach) { if ($type == 'files' and !wp_attachment_is_image($attach->ID)) { if ($unlink) { wp_delete_attachment($attach->ID, true); } else { $ids[] = $attach->ID; } } elseif ($type == 'images' and wp_attachment_is_image($attach->ID)) { if ($unlink) { wp_delete_attachment($attach->ID, true); } else { $ids[] = $attach->ID; } } } global $wpdb; if (!empty($ids)) { $ids_string = implode(',', $ids); // unattach $result = $wpdb->query("UPDATE {$wpdb->posts} SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( {$ids_string} )"); foreach ($ids as $att_id) { clean_attachment_cache($att_id); } } return $ids; }
function get_title() { if (wp_attachment_is_image($this->item->ID)) { return wp_get_attachment_image($this->item->ID, 'thumbnail', false); } return get_the_title($this->item); }
function jbst_posttype_set_classes() { if (wp_attachment_is_image()) { return 'image-attachment'; } return 'site-content'; }
function fifteen_scripts() { wp_enqueue_style('fifteen-basic-style', get_stylesheet_uri()); if (function_exists('of_get_option') && of_get_option('sidebar-layout', true) != 1) { if (of_get_option('sidebar-layout', true) == 'right') { wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/content-sidebar.css"); } else { wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/sidebar-content.css"); } } else { wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/content-sidebar.css"); } wp_enqueue_style('fifteen-bootstrap-style', get_template_directory_uri() . "/css/bootstrap/bootstrap.min.css", array('fifteen-layout')); wp_enqueue_style('fifteen-main-skin', get_template_directory_uri() . "/css/skins/default.css", array('fifteen-layout', 'fifteen-bootstrap-style')); wp_enqueue_script('fifteen-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true); wp_enqueue_script('fifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true); wp_enqueue_script('fifteen-bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery')); wp_enqueue_script('fifteen-custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery')); if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } if (is_singular() && wp_attachment_is_image()) { wp_enqueue_script('fifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array('jquery'), '20120202'); } }
function anno_media_send_to_editor($html, $id, $attachment) { if (!anno_is_article($_REQUEST['post_id'])) { return $html; } $html = ''; $attachment_object = get_post($id); if (!$attachment_object) { return ''; } // Attachment is not an image, insert it as a link if (!wp_attachment_is_image($id)) { //@TODO NEEDS TO BE CONVERTED TO THE TEXTORUM EXPECTED TAG $html = '<span class="ext-link" xmlns:xlink="http://www.w3.org/1999/xlink" data-xmlel="ext-link" ext-link-type="uri" xlink:href="' . esc_url($attachment['url']) . '">' . $attachment['post_title'] . '</span> '; } else { if (!isset($attachment['display'])) { $attachment['display'] = 'figure'; } $img_data = wp_get_attachment_image_src($id, $attachment['image-size']); $img_url = is_array($img_data) && isset($img_data[0]) ? $img_data[0] : ''; if (trim($attachment['display']) == 'figure') { $meta = array('label' => '_anno_attachment_image_label', 'copyright_statement' => '_anno_attachment_image_copyright_statement', 'copyright_holder' => '_anno_attachment_image_copyright_holder', 'license' => '_anno_attachment_image_license'); foreach ($meta as $key => $meta_key) { $attachment[$key] = get_post_meta($id, $meta_key, true); } if (!empty($attachment['url'])) { $fig_uri = '<div class="uri" data-xmlel="uri" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . $attachment['url'] . '"></div>'; } else { $fig_uri = ''; } // Editor removes empty items, need this to be valid $attachment['license'] = empty($attachment['license']) ? ' ' : $attachment['license']; $html = ' <div class="fig" data-xmlel="fig"> <img src="' . esc_attr($img_url) . '" data-mce-src="' . esc_attr($img_url) . '" alt="' . esc_attr($attachment['image_alt']) . '" /> <div class="label" data-xmlel="label">' . $attachment['label'] . '</div> <div class="caption" data-xmlel="caption"> <div class="p" data-xmlel="p">' . $attachment['post_excerpt'] . '</div> </div> <div class="media" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . esc_attr($img_url) . '" data-xmlel="media"> <span class="alt-text" data-xmlel="alt-text">' . $attachment['image_alt'] . '</span> <span class="long-desc" data-xmlel="long-desc">' . $attachment['post_content'] . '</span> ' . $fig_uri . ' <div class="permissions" data-xmlel="permissions"> <span class="copyright-statement" data-xmlel="copyright-statement">' . $attachment['copyright_statement'] . '</span> <span class="copyright-holder" data-xmlel="copyright-holder">' . $attachment['copyright_holder'] . '</span> <div class="license" data-xmlel="license" license-type="creative-commons"> <span class="license-p" data-xmlel="license-p">' . $attachment['license'] . '</span> </div> </div> </div> <div _mce_bogus="1" class="clearfix"></div> </div>'; } else { $html = '<span class="inline-graphic" data-xmlel="inline-graphic" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . esc_attr($img_url) . '"><img src="' . esc_url($img_url) . '" data-mce-src="' . esc_attr($img_url) . '" alt="' . esc_attr($attachment['image_alt']) . '" /></span><span> </span>'; } } return $html; }
function wck_preprocess_field_upload($field) { if ($field == '' || !is_numeric($field)) { return false; } if (is_null(get_post($field))) { return false; } if (wp_attachment_is_image($field)) { $attachment = get_post($field); // create array to hold value data $src = wp_get_attachment_image_src($attachment->ID, 'full'); $value = array('id' => $attachment->ID, 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'url' => $src[0], 'width' => $src[1], 'height' => $src[2], 'sizes' => array()); // find all image sizes $image_sizes = get_intermediate_image_sizes(); if ($image_sizes) { foreach ($image_sizes as $image_size) { // find src $src = wp_get_attachment_image_src($attachment->ID, $image_size); // add src $value['sizes'][$image_size] = $src[0]; $value['sizes'][$image_size . '-width'] = $src[1]; $value['sizes'][$image_size . '-height'] = $src[2]; } } return $value; } else { $attachement = get_post($field); return $attachement; } }
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); }
/** * Create a new slide and echo the admin HTML */ public function ajax_create_slide() { // security check if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'metaslider_addslide')) { echo "<tr><td colspan='2'>" . __("Security check failed. Refresh page and try again.", 'metaslider') . "</td></tr>"; wp_die(); } $slider_id = absint($_POST['slider_id']); $selection = $_POST['selection']; if (is_array($selection) && count($selection) && $slider_id > 0) { foreach ($selection as $slide_id) { $this->set_slide($slide_id); $this->set_slider($slider_id); if ($this->slide_exists_in_slideshow($slider_id, $slide_id)) { echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide already exists in slideshow.", 'metaslider') . "</td></tr>"; } else { if (!$this->slide_is_unassigned_or_image_slide($slider_id, $slide_id)) { echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide is not of type 'image'.", 'metaslider') . "</td></tr>"; } else { if (!wp_attachment_is_image($slide_id)) { echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide is not an image.", 'metaslider') . "</td></tr>"; } else { $this->tag_slide_to_slider(); $this->add_or_update_or_delete_meta($slide_id, 'type', 'image'); // override the width and height to kick off the AJAX image resizing on save $this->settings['width'] = 0; $this->settings['height'] = 0; echo $this->get_admin_slide(); } } } } } wp_die(); }
/** * Enqueue scripts and styles */ function zacklive_scripts() { // load zacklive styles wp_enqueue_style('zacklive-style', get_stylesheet_uri()); // load bootstrap css wp_enqueue_style('zacklive-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap/bootstrap.min.css'); // load bootstrap for WordPress css wp_enqueue_style('zacklive-bootstrapwp', get_template_directory_uri() . '/assets/css/bootstrap-wp.css'); // load font awesome css wp_enqueue_style('zacklive-fontawesome', get_template_directory_uri() . '/assets/css/FontAwesome/font-awesome.min.css', array(), '4.3.0', 'all'); // load bootstrap.js wp_enqueue_script('zacklive-bootstrapjs', get_template_directory_uri() . '/assets/js/bootstrap/bootstrap.js', array('jquery')); // load bootstrap-wp.js wp_enqueue_script('zacklive-bootstrapwp', get_template_directory_uri() . '/assets/js/bootstrap-wp.js', array('jquery')); // FitVid (responsive video) wp_enqueue_script('zacklive-fitvids', get_template_directory_uri() . '/assets/js/FitVids.js-master/jquery.fitvids.js', array('jquery')); wp_enqueue_script('zacklive-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20130115', true); if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } //load keyboard-image-navigation.js if (is_singular() && wp_attachment_is_image()) { wp_enqueue_script('zacklive-keyboard-image-navigation', get_template_directory_uri() . '/assets/js/keyboard-image-navigation.js', array('jquery'), '20120202'); } }
/** * Returns a set of image attachment links based on size. * * @since 1.0.0 * @access public * @return string */ function hoot_get_image_size_links() { /* If not viewing an image attachment page, return. */ if (!wp_attachment_is_image(get_the_ID())) { return; } /* Set up an empty array for the links. */ $links = array(); /* Get the intermediate image sizes and add the full size to the array. */ $sizes = get_intermediate_image_sizes(); $sizes[] = 'full'; /* Loop through each of the image sizes. */ foreach ($sizes as $size) { /* Get the image source, width, height, and whether it's intermediate. */ $image = wp_get_attachment_image_src(get_the_ID(), $size); /* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */ if (!empty($image) && (true === $image[3] || 'full' == $size)) { /* Translators: Media dimensions - 1 is width and 2 is height. */ $label = sprintf(__('%1$s × %2$s', 'chromatic'), number_format_i18n(absint($image[1])), number_format_i18n(absint($image[2]))); $links[] = sprintf('<a class="image-size-link">%s</a>', $label); } } /* Join the links in a string and return. */ return join(' <span class="sep">/</span> ', $links); }
/** * 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); }
function image_downsize($id, $size = 'medium') { if (!wp_attachment_is_image($id)) { return false; } $img_url = wp_get_attachment_url($id); $meta = wp_get_attachment_metadata($id); $width = $height = 0; // plugins can use this to provide resize services if ($out = apply_filters('image_downsize', false, $id, $size)) { return $out; } // try for a new style intermediate size if ($intermediate = image_get_intermediate_size($id, $size)) { $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url); $width = $intermediate['width']; $height = $intermediate['height']; } elseif ($size == 'thumbnail') { // fall back to the old thumbnail if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) { $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url); $width = $info[0]; $height = $info[1]; } } if (!$width && !$height && isset($meta['width'], $meta['height'])) { // any other type: use the real image and constrain it list($width, $height) = image_constrain_size_for_editor($meta['width'], $meta['height'], $size); } if ($img_url) { return array($img_url, $width, $height); } return false; }
function tsd_tpng_filter_uploaded_images($meta, $id) { // Make sure the upload is an image if ($id && false === wp_attachment_is_image($id)) { return $meta; } // Fetch the image file path $attachment_file_path = get_attached_file($id); // See what fields exist // Change the properties of $meta as needed $upload_dir = wp_upload_dir(); $input = get_attached_file($id); $type = $meta['sizes']['thumbnail']['mime-type']; $key = get_option('tsd_tpng_api_key'); $output = $input; if ($key != "" && $type == "image/png") { $url = "https://api.tinypng.com/shrink"; $options = array("http" => array("method" => "POST", "header" => array("Content-type: image/png", "Authorization: Basic " . base64_encode("api:{$key}")), "content" => file_get_contents($input)), "ssl" => array("cafile" => __DIR__ . "/cacert.pem", "verify_peer" => true)); $result = fopen($url, "r", false, stream_context_create($options)); if ($result) { /* Compression was successful, retrieve output from Location header. */ foreach ($http_response_header as $header) { if (substr($header, 0, 10) === "Location: ") { file_put_contents($output, fopen(substr($header, 10), "rb", false)); } } } else { /* Something went wrong! */ print "Compression failed"; } } return $meta; }
/** * AJAX callback for setting media ID as user avatar * * @since 0.1.0 */ function wp_user_avatars_ajax_assign_media() { // check required information and permissions if (empty($_POST['user_id']) || empty($_POST['media_id']) || empty($_POST['_wpnonce'])) { die; } // Cast values $media_id = (int) $_POST['media_id']; $user_id = (int) $_POST['user_id']; // Bail if current user cannot proceed if (!current_user_can('edit_avatar', $user_id)) { die; } // Bail if nonce verification fails if (!wp_verify_nonce($_POST['_wpnonce'], 'assign_wp_user_avatars_nonce')) { die; } // ensure the media is real is an image if (wp_attachment_is_image($media_id)) { wp_user_avatars_update_avatar($user_id, $media_id); } // Output the new avatar if (defined('DOING_AJAX') && DOING_AJAX) { echo get_avatar($user_id, 90); die; } }
/** Load needed scripts **/ function Radix_scripts() { wp_enqueue_script('Radix-modernizr', RADIX_JS_URI . '/modernizr.min.js', array(), '2.8.3', true); wp_enqueue_script('Radix-bootstrapjs', RADIX_JS_URI . '/bootstrap.min.js', array('jquery'), '3.3.5', true); // jquery.nicescroll + WOW.js wp_enqueue_script('Radix-plugins', RADIX_JS_URI . '/plugins.min.js', array(), '1.1.2', true); wp_enqueue_script('Radix-scripts', RADIX_JS_URI . '/scripts.min.js', array(), '1.1.2', true); if (is_singular() && wp_attachment_is_image()) { wp_enqueue_script('keyboard-image-navigation', RADIX_JS_URI . '/keyboard-image-navigation.js'); } if (!is_admin() && is_singular() && comments_open() && !is_front_page() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } // We dont need these in Frontpage if (!is_home()) { wp_enqueue_script('Radix-prettyphoto', RADIX_JS_URI . '/jquery.prettyPhoto.min.js', array('jquery'), '3.1.6', true); wp_enqueue_style('Radix-prettyphoto-css', RADIX_CSS_URI . '/prettyPhoto.min.css'); } // Animate.css - font-awesome wp_enqueue_style('Radix-all-css', RADIX_CSS_URI . '/all.min.css'); // Load Bootstrap wp_enqueue_style('Radix-bootstrap', RADIX_CSS_URI . '/bootstrap.min.css'); // Load main stylesheet wp_enqueue_style('Radix-style', get_stylesheet_uri()); }
function motopressCEGetAttachmentThumbnail() { require_once dirname(__FILE__) . '/../verifyNonce.php'; require_once dirname(__FILE__) . '/../settings.php'; require_once dirname(__FILE__) . '/../access.php'; require_once dirname(__FILE__) . '/../functions.php'; require_once dirname(__FILE__) . '/../getLanguageDict.php'; $motopressCELang = motopressCEGetLanguageDict(); if (isset($_POST['id']) && !empty($_POST['id'])) { $id = (int) trim($_POST['id']); $attachment = get_post($id); if (!empty($attachment) && $attachment->post_type === 'attachment') { if (wp_attachment_is_image($id)) { $srcMedium = wp_get_attachment_image_src($id, 'medium'); $srcFull = wp_get_attachment_image_src($id, 'full'); if (isset($srcMedium[0]) && !empty($srcMedium[0]) && isset($srcFull[0]) && !empty($srcFull[0])) { $attachmentImageSrc = array(); $attachmentImageSrc['medium'] = $srcMedium[0]; $attachmentImageSrc['full'] = $srcFull[0]; wp_send_json($attachmentImageSrc); } else { motopressCESetError($motopressCELang->CEAttachmentImageSrc); } } else { motopressCESetError($motopressCELang->CEAttachmentNotImage); } } else { motopressCESetError($motopressCELang->CEAttachmentEmpty); } } else { motopressCESetError($motopressCELang->CEAttachmentThumbnailError); } exit; }
function dt_metabox_benefits_options_save($post_id) { $box_name = 'dt_benefits_options'; // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!isset($_POST[$box_name . '_nonce']) || !wp_verify_nonce($_POST[$box_name . '_nonce'], plugin_basename(__FILE__))) { return; } // Check permissions if (!current_user_can('edit_page', $post_id)) { return; } $mydata = null; if (!empty($_POST[$box_name . '_retina_image'])) { $mydata['retina_image'] = esc_url($_POST[$box_name . '_retina_image']); } if (!empty($_POST[$box_name . '_retina_image_w'])) { $mydata['retina_image_w'] = intval($_POST[$box_name . '_retina_image_w']); } if (!empty($_POST[$box_name . '_retina_image_h'])) { $mydata['retina_image_h'] = intval($_POST[$box_name . '_retina_image_h']); } if (!empty($_POST[$box_name . '_retina_image_id']) && wp_attachment_is_image(intval($_POST[$box_name . '_retina_image_id']))) { $mydata['retina_image_id'] = intval($_POST[$box_name . '_retina_image_id']); } update_post_meta($post_id, '_' . $box_name, $mydata); }
function dominant_attachment_save($attachment_id) { if (wp_attachment_is_image($attachment_id)) { $path = get_attached_file($attachment_id); $color = dominant_color($path); update_post_meta($attachment_id, 'dominant_color', $color); } }
/** * Initialization Hooks * * @since 1.3.0 * * @return Void */ public function init_hooks() { global $post; if (!is_null($post) and wp_attachment_is_image($post->ID)) { add_filter('attachment_fields_to_edit', array(&$this, 'output_attachments'), 11, 2); } // if() }
/** * Adds smush button and status to attachment modal and edit page if it's an image * * * @param array $form_fields * @param WP_Post $post * * @return array $form_fields */ function filter_attachment_fields_to_edit($form_fields, $post) { if (!wp_attachment_is_image($post->ID)) { return $form_fields; } $form_fields['wp_smush'] = array('label' => __('WP Smush', WP_SMUSH_DOMAIN), 'input' => 'html', 'html' => $this->smush_status($post->ID), 'show_in_edit' => true, 'show_in_modal' => true); return $form_fields; }
/** * Output the carousel HTML for the filmstrip * * @param string $html * @param integer $slider_id * @param array $settings * @return string $html */ public function metaslider_flex_filmstrip_html($html, $slider_id, $settings) { if (isset($settings["navigation"]) && $settings['navigation'] == 'filmstrip') { $slider = new MetaSlider($slider_id, array()); $query = $slider->get_slides(); if (isset($settings["noConflict"]) && $settings['noConflict'] == 'true') { $class = 'filmstrip'; } else { $class = 'flexslider filmstrip'; } $html .= '<div id="metaslider_' . $slider_id . '_filmstrip" class="' . $class . '">'; $html .= "\n <ul class='slides'>"; while ($query->have_posts()) { $query->next_post(); $type = get_post_meta($query->post->ID, 'ml-slider_type', true); if ($type == 'post_feed') { $post_feed = new MetaPostFeedSlide(); $post_feed->set_slide($query->post->ID); $post_feed->set_slider($slider_id); $the_query = new WP_Query($post_feed->get_post_args()); $slides = array(); while ($the_query->have_posts()) { $the_query->the_post(); $id = get_post_thumbnail_id($the_query->post->ID); if ($override_id = get_post_meta($the_query->post->ID, 'metaslider_post_feed_image', true)) { if (wp_attachment_is_image($override_id)) { $id = $override_id; } } $imageHelper = new MetaSliderImageHelper($id, $settings['thumb_width'], $settings['thumb_height'], 'true'); $url = $imageHelper->get_image_url(); $list_item = "<li class=\"ms-thumb slide-{$query->post->ID} post-{$the_query->post->ID}\" style=\"display: none;\"><img src=\"{$url}\" /></li>"; $list_item = apply_filters("metaslider_filmstrip_list_item", $list_item, $query->post, $url); $html .= "\n {$list_item}"; } wp_reset_query(); } else { if ($type == 'external') { $url = get_post_meta($query->post->ID, 'ml-slider_extimgurl', true); $list_item = "<li class=\"ms-thumb slide-{$query->post->ID}\" style=\"display: none;\"><img src=\"{$url}\" /></li>"; $list_item = apply_filters("metaslider_filmstrip_list_item", $list_item, $query->post, $url); $html .= "\n {$list_item}"; } else { // generate thumbnail $imageHelper = new MetaSliderImageHelper($query->post->ID, $settings['thumb_width'], $settings['thumb_height'], 'true'); $url = $imageHelper->get_image_url(); if (strlen($url)) { $list_item = "<li class=\"ms-thumb slide-{$query->post->ID}\" style=\"display: none;\"><img src=\"{$url}\" /></li>"; $list_item = apply_filters("metaslider_filmstrip_list_item", $list_item, $query->post, $url); $html .= "\n {$list_item}"; } } } } $html .= "\n </ul>\n </div>"; } return $html; }
/** * Set the file headers and force the download of a given file * * @return void */ public function download() { if (isset($_GET['download']) && isset($_GET['payment_id'])) { $transaction_id = urldecode($_GET['download']); $payment_id = urldecode($_GET['payment_id']); $product_id = urldecode($_GET['product_id']); // Old download links might not have attachment_id set. // This means they were purchased before we added support // for multiple attachments. So, we just grab the first // attachment_id saved in post meta. $attachment_id = !empty($_GET['attachment_id']) ? urldecode($_GET['attachment_id']) : sell_media_get_attachment_id($product_id); $size_id = !empty($_GET['size_id']) ? urldecode($_GET['size_id']) : null; $verified = apply_filters('sell_media_verify_download', $this->verify($transaction_id, $payment_id), $product_id); if ($verified) { $file = Sell_Media()->products->get_protected_file($product_id, $attachment_id); if (!file_exists($file)) { wp_die(__('The original high resolution file doesn\'t exist here: %1$s', 'sell_media'), $file); exit; } $file_type = wp_check_filetype($file); if (!ini_get('safe_mode')) { set_time_limit(0); } if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); } if (function_exists('apache_setenv')) { @apache_setenv('no-gzip', 1); } @ini_set('zlib.output_compression', 'Off'); nocache_headers(); header("Robots: none"); header("Content-Type: " . $file_type['type'] . ""); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"" . basename($file) . "\""); header("Content-Transfer-Encoding: binary"); // If image, generate the image sizes purchased and create a download if (wp_attachment_is_image($attachment_id)) { $this->download_image($product_id, $attachment_id, $size_id); } else { $this->download_file($file); } do_action('sell_media_after_successful_download', $product_id); exit; } else { do_action('sell_media_before_failed_download', $product_id, $attachment_id); wp_die(__('You do not have permission to download this file', 'sell_media'), __('Purchase Verification Failed', 'sell_media')); } exit; } // Rend purchase receipt? if (isset($_GET['resend_email']) && isset($_GET['payment_id'])) { $payment_id = $_GET['payment_id']; $payment_email = get_meta_key($payment_id, 'email'); Sell_Media()->payments->email_receipt($payment_id, $payment_email); } }
/** * Enqueue scripts and styles */ function cg_scripts() { if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } if (is_singular() && wp_attachment_is_image()) { wp_enqueue_script('cg-keyboard-image-navigation', CG_JS . '/src/cond/keyboard-image-navigation.js', array('jquery'), '20120202'); } }
/** * Checks if the attached file is an image * and runs functions that resizes and moves * high resolution files into protected dir. * If attachment isn't an image, it just moves it. * Original files are deleted. * * @param [integer] $attachment_id [The attachment id] * @return [null] */ function sell_media_move_file($attachment_id) { if (wp_attachment_is_image($attachment_id)) { Sell_Media()->images->move_image_from_attachment($attachment_id); } else { $attached_file = get_attached_file($attachment_id); sell_media_default_move($attached_file); } }
/** * Display widget content on frontend * * @param array $data * @param string $id * @param int $number */ public static function render_widget(array $data, $id, $number) { if (!empty($data['video'])) { echo wp_oembed_get($data['video']); } if (!empty($data['thumbnail']) && ($image_id = absint(attachment_url_to_postid($data['thumbnail']))) && wp_attachment_is_image($image_id)) { echo wp_get_attachment_image($image_id, 'medium'); } }