Example #1
0
function attachment_toolbox($size = thumbnail, $type = 'house', $gallcount = '0', $ulClass = '', $emptyMsg = '')
{
    $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    $count = 0;
    $out = '<ul class="' . $ulClass . '">';
    foreach ($images as $image) {
        $attimg = wp_get_attachment_image_src($image->ID, $size);
        $attimgurl = $attimg[0];
        $atturl = wp_get_attachment_url($image->ID);
        $attlink = get_attachment_link($image->ID);
        $postlink = get_permalink($image->post_parent);
        $atttitle = apply_filters('the_title', $image->post_title);
        $attcontent = $image->post_content;
        $attimgtype = get_post_meta($image->ID, "_mySelectBox", true);
        $imglink = $image->guid;
        if ($attimgtype == $type) {
            $count++;
            $out .= '<li><a href=' . $imglink . ' rel="prettyPhoto[gallery' . $gallcount . ']"><img class="primary" src="' . $attimgurl . '"/></a></li>';
        }
    }
    $out .= '</ul>';
    if ($count > 0) {
        echo $out;
    } else {
        echo $emptyMsg;
    }
    return $count;
}
Example #2
0
/** Show Photo gallery shortcode
 * [photo-gallery]
 */
function guiabsn_shortcode_photo_gallery($atts)
{
    global $post;
    extract(shortcode_atts(array('size' => 'photography'), $atts));
    $_attachments = get_posts(array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID, 'order' => 'ASC', 'orderby' => 'menu_order ID'));
    // return false when invalid
    if (!count($_attachments)) {
        return false;
    }
    $output = '';
    $group_class = 'phogal-' . $post->ID;
    $output .= '<ul id="pg-thumb-list" class="pg-thumb-list">' . "\r\n";
    foreach ($_attachments as $key => $val) {
        $img_thumb = wp_get_attachment_image_src($val->ID, $size, false);
        $img_full_url = $val->guid;
        $output .= '<li id="thumb-' . $val->ID . '">';
        $output .= '<div class="pg-thumb-content">';
        $output .= '<a class="popup-img ' . $group_class . '" rel="' . $group_class . '" title="' . $val->post_title . '" href="' . get_attachment_link($val->ID) . '" data-url="' . $img_full_url . '"><img class="pt-thumb-image" src="' . $img_thumb[0] . '" alt="" title="" /></a>';
        $output .= '</div>';
        $output .= '</li>' . "\r\n";
    }
    $output .= '</ul>' . "\r\n";
    // fancybox
    if (count($_attachments)) {
        guiabsn_scripts_fancybox();
        $output .= '<script type="text/javascript">' . "\r\n" . '$(document).ready(function() {' . "\r\n" . '$("a[rel=\'' . $group_class . '\']").fancybox({ ' . "\r\n" . 'scrolling: "no", ' . "\r\n" . 'centerOnScroll: "true" ' . "\r\n" . '});' . "\r\n" . '});' . "\r\n" . '</script>' . "\r\n";
    }
    return $output;
}
Example #3
0
/**
 * Prints the attached image with a link to the next attached image.
 */
function cw_magazine_the_attached_image()
{
    $post = get_post();
    $attachment_size = apply_filters('underscore_attachment_size', array(1200, 1200));
    $next_attachment_url = wp_get_attachment_url();
    /**
     * Grab the IDs of all the image attachments in a gallery so we can get the
     * URL of the next adjacent image in a gallery, or the first image (if
     * we're looking at the last image in a gallery), or, in a gallery of one,
     * just the link to that image file.
     */
    $attachment_ids = get_posts(array('post_parent' => $post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
    // If there is more than 1 attachment in a gallery...
    if (count($attachment_ids) > 1) {
        foreach ($attachment_ids as $attachment_id) {
            if ($attachment_id == $post->ID) {
                $next_id = current($attachment_ids);
                break;
            }
        }
        // get the URL of the next image attachment...
        if ($next_id) {
            $next_attachment_url = get_attachment_link($next_id);
        } else {
            $next_attachment_url = get_attachment_link(array_shift($attachment_ids));
        }
    }
    printf('<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>', esc_url($next_attachment_url), the_title_attribute(array('echo' => false)), wp_get_attachment_image($post->ID, $attachment_size));
}
function get_permalink($id = 0)
{
    $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%', '%category%', '%author%', '%pagename%');
    $post =& get_post($id);
    if ($post->post_status == 'static') {
        return get_page_link($post->ID);
    } elseif ($post->post_status == 'attachment') {
        return get_attachment_link($post->ID);
    }
    $permalink = get_settings('permalink_structure');
    if ('' != $permalink && 'draft' != $post->post_status) {
        $unixtime = strtotime($post->post_date);
        $category = '';
        if (strstr($permalink, '%category%')) {
            $cats = get_the_category($post->ID);
            $category = $cats[0]->category_nicename;
            if ($parent = $cats[0]->category_parent) {
                $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
            }
        }
        $authordata = get_userdata($post->post_author);
        $author = $authordata->user_nicename;
        $date = explode(" ", date('Y m d H i s', $unixtime));
        $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name);
        return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);
    } else {
        // if they're not using the fancy permalink option
        $permalink = get_settings('home') . '/?p=' . $post->ID;
        return apply_filters('post_link', $permalink, $post);
    }
}
 /**
  * @ticket 36578
  */
 public function test_wp_ajax_send_attachment_to_editor_should_return_a_link()
 {
     // Become an administrator
     $post = $_POST;
     $user_id = self::factory()->user->create(array('role' => 'administrator', 'user_login' => 'user_36578_administrator', 'user_email' => '*****@*****.**'));
     wp_set_current_user($user_id);
     $_POST = array_merge($_POST, $post);
     $filename = DIR_TESTDATA . '/formatting/entities.txt';
     $contents = file_get_contents($filename);
     $upload = wp_upload_bits(basename($filename), null, $contents);
     $attachment = $this->_make_attachment($upload);
     // Set up a default request
     $_POST['nonce'] = wp_create_nonce('media-send-to-editor');
     $_POST['html'] = 'Bar Baz';
     $_POST['post_id'] = 0;
     $_POST['attachment'] = array('id' => $attachment, 'post_title' => 'Foo bar', 'url' => get_attachment_link($attachment));
     // Make the request
     try {
         $this->_handleAjax('send-attachment-to-editor');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     // Get the response.
     $response = json_decode($this->_last_response, true);
     $expected = sprintf('<a href="%s" rel="attachment wp-att-%d">Foo bar</a>', get_attachment_link($attachment), $attachment);
     // Ensure everything is correct
     $this->assertTrue($response['success']);
     $this->assertEquals($expected, $response['data']);
 }
 /**
  * Add an optional rel="tc-fancybox[]" attribute to all images embedded in a post gallery
  * Based on the original WP function
  * @package Customizr
  * @since Customizr 3.0.5
  *
  */
 function tc_modify_attachment_link($markup, $id, $size, $permalink, $icon, $text)
 {
     if (!$this->tc_is_gallery_enabled()) {
         return $markup;
     }
     $tc_fancybox = esc_attr(TC_utils::$inst->tc_opt('tc_gallery_fancybox'));
     $tc_gallery_fancybox = apply_filters('tc_gallery_fancybox', esc_attr(TC_utils::$inst->tc_opt('tc_gallery_fancybox') && $tc_fancybox), $id);
     if ($tc_gallery_fancybox == 1 && $permalink == false) {
         $id = intval($id);
         $_post = get_post($id);
         if (empty($_post) || 'attachment' != $_post->post_type || !($url = wp_get_attachment_url($_post->ID))) {
             return __('Missing Attachment', 'customizr');
         }
         if ($permalink) {
             $url = get_attachment_link($_post->ID);
         }
         $post_title = esc_attr($_post->post_title);
         if ($text) {
             $link_text = $text;
         } elseif ($size && 'none' != $size) {
             $link_text = wp_get_attachment_image($id, $size, $icon);
         } else {
             $link_text = '';
         }
         if (trim($link_text) == '') {
             $link_text = $_post->post_title;
         }
         $markup = '<a class="grouped_elements" rel="tc-fancybox-group" href="' . $url . '" title="' . $post_title . '">' . $link_text . '</a>';
     }
     return $markup;
 }
Example #7
0
 public function get_attachment_link($attachment_id, $orig_file)
 {
     if (isset($this->atts['link']) && $this->atts['link'] == 'file') {
         return $orig_file;
     } else {
         return get_attachment_link($attachment_id);
     }
 }
Example #8
0
function network_shared_media_media_upload()
{
    global $blog_id, $post;
    if (isset($_POST['send'])) {
        $nsm_blog_id = (int) $_GET['blog_id'];
        reset($_POST['send']);
        $nsm_send_id = (int) key($_POST['send']);
    }
    /* copied from wp-admin/inculdes/ajax-actions.php wp_ajax_send_attachment_to_editor() */
    if (isset($nsm_blog_id) && isset($nsm_send_id)) {
        switch_to_blog($nsm_blog_id);
        if (!current_user_can('upload_files')) {
            $current_blog_name = get_bloginfo('name');
            restore_current_blog();
            wp_die(__('You do not have permission to upload files to site: ') . $current_blog_name);
        }
        $attachment = wp_unslash($_POST['attachments'][$nsm_send_id]);
        $id = $nsm_send_id;
        if (!($post = get_post($id))) {
            wp_send_json_error();
        }
        if ('attachment' != $post->post_type) {
            wp_send_json_error();
        }
        $rel = $url = '';
        $html = $title = isset($attachment['post_title']) ? $attachment['post_title'] : '';
        if (!empty($attachment['url'])) {
            $url = $attachment['url'];
            if (strpos($url, 'attachment_id') || get_attachment_link($id) == $url) {
                $rel = ' rel="attachment wp-att-' . $id . '"';
            }
            $html = '<a href="' . esc_url($url) . '"' . $rel . '>' . $html . '</a>';
        }
        if ('image' === substr($post->post_mime_type, 0, 5)) {
            $align = isset($attachment['align']) ? $attachment['align'] : 'none';
            $size = isset($attachment['image-size']) ? $attachment['image-size'] : 'medium';
            $alt = isset($attachment['image_alt']) ? $attachment['image_alt'] : '';
            $caption = isset($attachment['post_excerpt']) ? $attachment['post_excerpt'] : '';
            $title = '';
            // We no longer insert title tags into <img> tags, as they are redundant.
            $html = get_image_send_to_editor($id, $caption, $title, $align, $url, (bool) $rel, $size, $alt);
        } elseif ('video' === substr($post->post_mime_type, 0, 5) || 'audio' === substr($post->post_mime_type, 0, 5)) {
            global $wp_embed;
            $meta = get_post_meta($id, '_wp_attachment_metadata', true);
            $html = $wp_embed->shortcode($meta, $url);
        }
        /** This filter is documented in wp-admin/includes/media.php */
        $html = apply_filters('media_send_to_editor', $html, $id, $attachment);
        // replace wp-image-<id>, wp-att-<id> and attachment_<id>
        $html = preg_replace(array('#(caption id="attachment_)(\\d+")#', '#(wp-image-|wp-att-)(\\d+)#'), array(sprintf('${1}nsm_%s_${2}', esc_attr($nsm_blog_id)), sprintf('${1}nsm-%s-${2}', esc_attr($nsm_blog_id))), $html);
        if (isset($_POST['chromeless']) && $_POST['chromeless']) {
            // WP3.5+ media browser is identified by the 'chromeless' parameter
            exit($html);
        } else {
            return media_send_to_editor($html);
        }
    }
}
Example #9
0
function add_social_tags()
{
    global $post;
    $id = $post->ID;
    $title = get_bloginfo('name');
    $urlFotoShare = wp_get_attachment_url($id);
    $urlFace = get_attachment_link($id);
    $descp = '';
    echo "\n            <meta name='description' content='{$title}' />\n            <meta name='DC.title' content='{$title}' />\n            <meta name='geo.region' content='BR-PR' />\n            <meta name='geo.placename' content='Cianorte' />\n            <meta name='geo.position' content='' />\n            <meta name='ICBM' content='' />\n\n            <meta property='og:url' content='{$urlFotoShare}'>\n            <meta property='og:title' content='{$title}'>\n            <meta property='og:site_name' content='Fato Basico'>\n            <meta property='og:description' content='descrição: {$descp}'>\n            <meta property='og:image' content='{$urlFotoShare}'>\n            <meta property='og:image:type' content='image/jpg'>\n            <meta property='og:image:width' content='114'> \n            <meta property='og:image:height' content='114'>\n            <meta property='og:type' content='website'> \n        ";
}
 public function __construct($attachment_image, $needs_attachment_link, $grayscale)
 {
     $this->image = $attachment_image;
     $this->grayscale = $grayscale;
     $this->image_title = $this->image->post_title;
     $this->image_alt = get_post_meta($this->image->ID, '_wp_attachment_image_alt', true);
     $this->orig_file = wp_get_attachment_url($this->image->ID);
     $this->link = $needs_attachment_link ? get_attachment_link($this->image->ID) : $this->orig_file;
     $this->img_src = add_query_arg(array('w' => $this->image->width, 'h' => $this->image->height, 'crop' => true), $this->orig_file);
 }
 /**
  * Outputs the content of the widget
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // outputs the content of the widget
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     $number_of_posts = -1;
     if (!empty($instance['show_number_files'])) {
         $number_of_posts = $instance['show_number_files'];
     }
     $orderby = 'date';
     if (!empty($instance['sort_parameter'])) {
         $orderby = $instance['sort_parameter'];
     }
     $order_direction = 'DESC';
     if (!empty($instance['sort_direction'])) {
         $order_direction = $instance['sort_direction'];
     }
     $exclude_ids = array();
     if (!empty($instance['exclude_ids'])) {
         $exclude_ids = $instance['exclude_ids'];
     }
     // TODO: get template choice. Echo css based on choice
     echo '<style>.list_mediafiles_box{';
     echo 'border: 1px solid #e2e2e2;';
     echo 'margin: 5px;';
     echo 'padding: 5px;';
     echo '} .list_mediafiles_box img{';
     echo 'max-width:100px;';
     echo '} </style>';
     $args = array('post_type' => 'attachment', 'numberposts' => $number_of_posts, 'post_status' => null, 'post_parent' => null, 'orderby' => $orderby, 'order' => $order_direction, 'exclude' => $exclude_ids);
     $attachments = get_posts($args);
     if ($attachments) {
         foreach ($attachments as $post) {
             echo '<div class="list_mediafiles_box">';
             setup_postdata($post);
             echo '<h4>' . get_the_title($post->ID) . '</h4>';
             switch ($post->post_mime_type) {
                 case 'image/jpeg':
                 case 'image/png':
                 case 'image/gif':
                     the_attachment_link($post->ID, false);
                     break;
                 default:
                     echo '<a href="' . get_attachment_link($post->ID) . '"><img src="' . wp_mime_type_icon($post->post_mime_type) . '"></a>';
             }
             echo '<span class="aligncenter" style="word-break:break-word;">';
             the_excerpt();
             echo '</span>';
             echo '</div>';
         }
     }
     //echo $args['after_widget'];
 }
function postimage($size = medium)
{
    if ($images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 5, 'post_mime_type' => 'image'))) {
        foreach ($images as $image) {
            $attachmenturl = get_attachment_link($image->ID);
            $attachmentimage = wp_get_attachment_image($image->ID, $size);
            echo '<a href="' . $attachmenturl . '" class="home-gallery-item" rel="lightbox">' . $attachmentimage . '</a>';
        }
    } else {
        echo "No Image";
    }
}
Example #13
0
function mfrh_media_send_to_editor($html, $attachment_id, $attachment)
{
    $post =& get_post($attachment_id);
    if (substr($post->post_mime_type, 0, 5) == 'image') {
        $url = wp_get_attachment_url($attachment_id);
        $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
        $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
        $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
        $rel = $url == get_attachment_link($attachment_id);
        return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
    }
    return $html;
}
Example #14
0
function attachment_toolbox($size = 'portfolio-image', $emptyMsg = 'EMPTY')
{
    $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    $count = 0;
    $out = '<div class="gallery">';
    foreach ($images as $image) {
        // split thumbParams
        $params = get_post_meta($image->ID, '_thumbnailParams', true);
        $params = explode(',', $params);
        $leftOffset = $params[0];
        $topOffset = $params[1];
        $width = $params[2];
        // Other image meta
        $colour = get_post_meta($image->ID, '_thumbnailColour', true);
        $attimg = wp_get_attachment_image_src($image->ID, $size);
        $attimgurl = $attimg[0];
        $atturl = wp_get_attachment_url($image->ID);
        $attlink = get_attachment_link($image->ID);
        $postlink = get_permalink($image->post_parent);
        $atttitle = apply_filters('the_title', $image->post_title);
        $attcontent = $image->post_content;
        $imglink = $image->guid;
        $attimgalt = get_post_meta($image->ID, '_wp_attachment_image_alt', true);
        $out .= '<img ';
        if ($leftOffset) {
            $out .= "data-leftOffset='{$leftOffset}' ";
        }
        if ($topOffset) {
            $out .= "data-topOffset='{$topOffset}' ";
        }
        if ($height) {
            $out .= "data-height='{$height}' ";
        }
        if ($width) {
            $out .= "data-width='{$width}' ";
        }
        if ($colour) {
            $out .= "data-colour='{$colour}'";
        }
        $out .= 'class="portfolioImage" src="' . $attimgurl . '" alt="' . $attimgalt . '" title="' . $atttitle . '"/>';
        $count++;
    }
    $out .= '</div>';
    if ($count > 0) {
        echo $out;
    } else {
        echo $emptyMsg;
    }
    return $count;
}
 /**
  * Constructs instance of Document.
  *
  * @param WP_Post $attachment Attachment object used to initalize fields.
  * @param DG_Gallery $gallery Instance of Gallery class.
  */
 public function __construct($attachment, $gallery)
 {
     // init general document data
     $this->gallery = $gallery;
     $this->description = wptexturize($attachment->post_content);
     $this->ID = $attachment->ID;
     $this->link = $gallery->linkToAttachmentPg() ? get_attachment_link($attachment->ID) : wp_get_attachment_url($attachment->ID);
     $this->title = wptexturize($attachment->post_title);
     $this->title_attribute = esc_attr(strip_tags($this->title));
     $this->path = get_attached_file($attachment->ID);
     $wp_filetype = wp_check_filetype_and_ext($this->path, basename($this->path));
     $this->extension = $wp_filetype['ext'];
     $this->size = size_format(filesize($this->path));
 }
function get_permalink($id = 0, $leavename = false)
{
    $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%');
    $post =& get_post($id);
    if (empty($post->ID)) {
        return FALSE;
    }
    if ($post->post_type == 'page') {
        return get_page_link($post->ID, $leavename);
    } elseif ($post->post_type == 'attachment') {
        return get_attachment_link($post->ID);
    }
    $permalink = get_option('permalink_structure');
    if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending'))) {
        $unixtime = strtotime($post->post_date);
        $category = '';
        if (strpos($permalink, '%category%') !== false) {
            $cats = get_the_category($post->ID);
            if ($cats) {
                usort($cats, '_usort_terms_by_ID');
            }
            // order by ID
            $category = $cats[0]->slug;
            if ($parent = $cats[0]->parent) {
                $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
            }
            // show default category in permalinks, without
            // having to assign it explicitly
            if (empty($category)) {
                $default_category = get_category(get_option('default_category'));
                $category = is_wp_error($default_category) ? '' : $default_category->slug;
            }
        }
        $author = '';
        if (strpos($permalink, '%author%') !== false) {
            $authordata = get_userdata($post->post_author);
            $author = $authordata->user_nicename;
        }
        $date = explode(" ", date('Y m d H i s', $unixtime));
        $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name);
        $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
        $permalink = user_trailingslashit($permalink, 'single');
        return apply_filters('post_link', $permalink, $post);
    } else {
        // if they're not using the fancy permalink option
        $permalink = get_option('home') . '/?p=' . $post->ID;
        return apply_filters('post_link', $permalink, $post);
    }
}
Example #17
0
 function mh_featured_image()
 {
     global $post;
     if (has_post_thumbnail()) {
         $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'content');
         $caption_text = get_post(get_post_thumbnail_id())->post_excerpt;
         $attachment_page = get_attachment_link(get_post_thumbnail_id());
         echo "\n" . '<div class="post-thumbnail">' . "\n";
         echo '<a href="' . $attachment_page . '"><img src="' . $thumbnail[0] . '" alt="' . get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true) . '" title="' . get_post(get_post_thumbnail_id())->post_title . '" /></a>' . "\n";
         if ($caption_text) {
             echo '<span class="wp-caption-text">' . $caption_text . '</span>' . "\n";
         }
         echo '</div>' . "\n";
     }
 }
 function getImageLink($id, $linktype, $parent_id = 0)
 {
     if ($linktype == 'direct' && $linktype != 'just display') {
         return wp_get_attachment_url($id);
     } elseif ($linktype == 'article' && $linktype != 'just display') {
         if ($parent_id == 0) {
             $parent_id == $id;
         }
         return get_permalink($parent_id);
     } elseif ($linktype != 'just display') {
         return get_attachment_link($id);
     } else {
         return false;
     }
 }
function pixlr_link_input_fields($form_fields, $post, $url_type = '')
{
    if (substr($post->post_mime_type, 0, 5) == 'image') {
        $pixlr_link = wp_get_attachment_url($post->ID);
        $pixlr_file = get_attachment_link($post->ID);
        $url = '';
        if ($url_type == 'file') {
            $url = $pixlr_link;
        } elseif ($url_type == 'post') {
            $url = $pixlr_file;
        }
        $form_fields = array('post_title' => array('label' => __('Title'), 'value' => $edit_post->post_title), 'post_excerpt' => array('label' => __('Caption'), 'value' => $edit_post->post_excerpt), 'post_content' => array('label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea'), 'url' => array('label' => __('Your Links are Now Pixlr'), 'input' => 'html', 'html' => "\n\t\t\t\t\t<input type='text' class='urlfield'  name='attachments[{$post->ID}][url]' value='" . esc_attr($url) . "' /><br />\n\t\t\t\t\t\t\t<button type='button' class='button urlnone' title=''>" . __('None') . "</button>\n<!--\t\t\t\t\t\t\t<button type='button' class='button urlfile' title='" . esc_attr($pixlr_file) . "'>" . __('Post URL') . "</button> -->\n\t\t\t\t\t\t\t<button type='button' class='button urlpost' title='" . esc_attr($pixlr_link) . "'>" . __('File URL') . "</button>\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t", 'helps' => __('Enter a link URL or click above for presets.')), 'menu_order' => array('label' => __('Order'), 'value' => $edit_post->menu_order), 'align' => array('label' => __('Alignment'), 'input' => 'html', 'html' => image_align_input_fields($post, get_option('image_default_align'))));
        $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
    }
    return $form_fields;
}
 public function test_old_slug_redirect_attachment()
 {
     $file = DIR_TESTDATA . '/images/canola.jpg';
     $attachment_id = self::factory()->attachment->create_object($file, $this->post_id, array('post_mime_type' => 'image/jpeg', 'post_name' => 'my-attachment'));
     $old_permalink = get_attachment_link($attachment_id);
     wp_update_post(array('ID' => $this->post_id, 'post_name' => 'bar-baz'));
     $this->go_to($old_permalink);
     wp_old_slug_redirect();
     $this->assertNull($this->old_slug_redirect_url);
     $this->assertQueryTrue('is_attachment', 'is_singular', 'is_single');
     $old_permalink = get_attachment_link($attachment_id);
     wp_update_post(array('ID' => $attachment_id, 'post_name' => 'the-attachment'));
     $permalink = user_trailingslashit(trailingslashit(get_permalink($this->post_id)) . 'the-attachment');
     $this->go_to($old_permalink);
     wp_old_slug_redirect();
     $this->assertEquals($permalink, $this->old_slug_redirect_url);
 }
 public function __construct($attachment_image, $needs_attachment_link, $grayscale)
 {
     $this->image = $attachment_image;
     $this->grayscale = $grayscale;
     $this->image_title = $this->image->post_title;
     $this->image_alt = get_post_meta($this->image->ID, '_wp_attachment_image_alt', true);
     // If no Alt value, use the caption
     if (empty($this->image_alt) && !empty($this->image->post_excerpt)) {
         $this->image_alt = trim(strip_tags($this->image->post_excerpt));
     }
     // If still no Alt value, use the title
     if (empty($this->image_alt) && !empty($this->image->post_title)) {
         $this->image_alt = trim(strip_tags($this->image->post_title));
     }
     $this->orig_file = wp_get_attachment_url($this->image->ID);
     $this->link = $needs_attachment_link ? get_attachment_link($this->image->ID) : $this->orig_file;
     $this->img_src = add_query_arg(array('w' => $this->image->width, 'h' => $this->image->height, 'crop' => true), $this->orig_file);
 }
Example #22
0
 public function __construct($attachment_image, $needs_attachment_link, $grayscale)
 {
     $this->image = $attachment_image;
     $this->grayscale = $grayscale;
     $this->image_title = $this->image->post_title;
     $this->image_alt = get_post_meta($this->image->ID, '_wp_attachment_image_alt', true);
     // If no Alt value, use the caption
     if (empty($this->image_alt) && !empty($this->image->post_excerpt)) {
         $this->image_alt = trim(strip_tags($this->image->post_excerpt));
     }
     // If still no Alt value, use the title
     if (empty($this->image_alt) && !empty($this->image->post_title)) {
         $this->image_alt = trim(strip_tags($this->image->post_title));
     }
     $this->orig_file = wp_get_attachment_url($this->image->ID);
     $this->link = $needs_attachment_link ? get_attachment_link($this->image->ID) : $this->orig_file;
     $this->img_src = jetpack_photon_url($this->orig_file, array('resize' => sprintf('%d,%d', $this->image->width, $this->image->height)));
 }
Example #23
0
 function ktz_gallery_slide()
 {
     global $post;
     $meta_values = get_post_custom($post->ID);
     if (isset($meta_values['ktz_gallery_post_postformat'][0]) && has_post_format('gallery')) {
         $title = get_the_title();
         $gallery = explode(',', get_post_meta(get_the_ID(), 'ktz_gallery_post_postformat', true));
         echo '<div class="box_gallery box_gallery_single"><div id="inner_box_gallery">';
         $count = 0;
         foreach ($gallery as $slide) {
             $attachment_url = get_attachment_link($slide);
             $img_url = wp_get_attachment_url($slide);
             $desc_img = get_the_title($slide);
             $params = array('width' => 539);
             $image_ori = bfi_thumb($img_url, $params);
             //resize & crop the image
             if ($count == 0) {
                 echo '<a class="data-original-link" href="' . $attachment_url . '" data-title="Image for ' . $desc_img . '"><img class="data-original" src="' . $image_ori . '" height="auto" width="539" alt="' . $desc_img . '" title="' . $desc_img . '" /></a>';
             }
             $count++;
         }
         echo '</div>';
         echo '<div class="widget_carousel ktz-slidesingle"><div class="list_carousel"><div class="ktzcarousel-little owl-carousel owl-theme owl-little">';
         foreach ($gallery as $slide) {
             $attachment_url = get_attachment_link($slide);
             $img_url = wp_get_attachment_url($slide);
             $desc_img = get_the_title($slide);
             $params_1 = array('width' => 177, 'height' => 130, 'crop' => true);
             $image = bfi_thumb($img_url, $params_1);
             //resize & crop the image
             $params_2 = array('width' => 539);
             $image_ori = bfi_thumb($img_url, $params_2);
             //resize & crop the image
             echo '<div class="item ktz-widgetcolor"><img src="' . $image . '" data-ori="' . $attachment_url . '" data-crop="' . $image_ori . '" height="130" width="177" alt="' . $desc_img . '" data-title="' . $desc_img . '" /></div>';
         }
         echo '</div></div></div></div>';
     } else {
         echo '<div class="ktz-featuredimg">';
         echo ktz_featured_img_width(540);
         echo '</div>';
     }
 }
Example #24
0
function show_attachment_file_list( $cat )
{
	$args = [
		'post_type' => 'attachment',
		'numberposts' => -1,
		'post_status' => null,
		'category_name' => $cat
	];
	$attachments = get_posts( $args );
	foreach( $attachments as $attachment ):
		echo '<ul>';
?>
<a href='<?php echo get_attachment_link( $attachment->ID ); ?>'>
<?php echo $attachment->post_title ?>
<?php echo get_attached_file( $attachment->ID ); ?>
</a>
<?php
		echo '</ul>';
endforeach;
}
 /**
  * Print the attached image with a link to the next attached image.
  *
  * @since Dichan 1.0
  *
  * @return void
  */
 function zatolab_the_attached_image()
 {
     $post = get_post();
     /**
      * Filter the default Dichan attachment size.
      *
      * @since Dichan 1.0
      *
      * @param array $dimensions {
      *     An array of height and width dimensions.
      *
      *     @type int $height Height of the image in pixels. Default 810.
      *     @type int $width  Width of the image in pixels. Default 810.
      * }
      */
     $attachment_size = apply_filters('zatolab_attachment_size', array(810, 810));
     $next_attachment_url = wp_get_attachment_url();
     /*
      * Grab the IDs of all the image attachments in a gallery so we can get the URL
      * of the next adjacent image in a gallery, or the first image (if we're
      * looking at the last image in a gallery), or, in a gallery of one, just the
      * link to that image file.
      */
     $attachment_ids = get_posts(array('post_parent' => $post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
     // If there is more than 1 attachment in a gallery...
     if (count($attachment_ids) > 1) {
         foreach ($attachment_ids as $attachment_id) {
             if ($attachment_id == $post->ID) {
                 $next_id = current($attachment_ids);
                 break;
             }
         }
         // get the URL of the next image attachment...
         if ($next_id) {
             $next_attachment_url = get_attachment_link($next_id);
         } else {
             $next_attachment_url = get_attachment_link(array_shift($attachment_ids));
         }
     }
     printf('<a href="%1$s" rel="attachment">%2$s</a>', esc_url($next_attachment_url), wp_get_attachment_image($post->ID, $attachment_size));
 }
 function wc_theme_the_attached_image()
 {
     $post = get_post();
     $attachment_size = apply_filters('wc_theme_attachment_size', array(810, 810));
     $next_attachment_url = wp_get_attachment_url();
     $attachment_ids = get_posts(array('post_parent' => $post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
     if (count($attachment_ids) > 1) {
         foreach ($attachment_ids as $attachment_id) {
             if ($attachment_id == $post->ID) {
                 $next_id = current($attachment_ids);
                 break;
             }
         }
         if ($next_id) {
             $next_attachment_url = get_attachment_link($next_id);
         } else {
             $next_attachment_url = get_attachment_link(array_shift($attachment_ids));
         }
     }
     printf('<a href="%1$s" rel="attachment">%2$s</a>', esc_url($next_attachment_url), wp_get_attachment_image($post->ID, $attachment_size));
 }
Example #27
0
function show_all_thumbs()
{
    global $post;
    $post = get_post($post);
    $images =& get_children('post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=' . $post->post_parent);
    if ($images) {
        $thumblist = '';
        foreach ($images as $imageID => $imagePost) {
            if ($imageID == $post->ID) {
                unset($the_b_img);
                $the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
                $thumblist .= '<a class="active" href="' . get_attachment_link($imageID) . '">' . $the_b_img . '</a>';
            } else {
                unset($the_b_img);
                $the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
                $thumblist .= '<a href="' . get_attachment_link($imageID) . '">' . $the_b_img . '</a>';
            }
        }
    }
    return $thumblist;
}
Example #28
0
function attachment_toolbox($size = thumbnail, $ulClass = '')
{
    $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    $count = 0;
    $out = '<ul class="' . $ulClass . '">';
    foreach ($images as $image) {
        $attimg = wp_get_attachment_image_src($image->ID, $size);
        $attimgurl = $attimg[0];
        $atturl = wp_get_attachment_url($image->ID);
        $attlink = get_attachment_link($image->ID);
        $postlink = get_permalink($image->post_parent);
        $atttitle = apply_filters('the_title', $image->post_title);
        $attcontent = $image->post_content;
        $attimgtype = get_post_meta($image->ID, "_mySelectBox", true);
        $imglink = $image->guid;
        if ($attimgtype == $type) {
            $count++;
            $out .= '<li><img title="' . $atttitle . '" src="' . $attimgurl . '"/></li>';
        }
    }
    $out .= '</ul>';
}
Example #29
0
function show_all_thumbs()
{
    global $post;
    $post = get_post($post);
    $images =& get_children('post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=' . $post->post_parent);
    if ($images) {
        $thumblist = "";
        foreach ($images as $imageID => $imagePost) {
            if ($imageID == $post->ID) {
            } else {
                $thumblist .= '<li class="item">';
                unset($the_b_img);
                $the_b_img = wp_get_attachment_image_src($imageID, 'full', false);
                // mr-image-resize script
                $_new_image_url = theme_thumb($the_b_img[0], 148, 98);
                $thumblist .= '<a href="' . get_attachment_link($imageID) . '"><img src="' . $_new_image_url . '" /></a>';
                $thumblist .= '</li>';
            }
        }
    }
    return $thumblist;
}
Example #30
0
 function ktz_get_gallery_post()
 {
     global $post;
     $meta_values = get_post_custom($post->ID);
     if (isset($meta_values['ktz_gallery_post_postformat'][0]) && has_post_format('gallery')) {
         $title = get_the_title();
         $gallery = explode(',', get_post_meta(get_the_ID(), 'ktz_gallery_post_postformat', true));
         echo '<div class="ktz-gallery"><ul>';
         foreach ($gallery as $slide) {
             $attachment_url = get_attachment_link($slide);
             $img_url = wp_get_attachment_url($slide);
             $desc_img = get_the_title($slide);
             $params = array('width' => 140, 'height' => 120, 'crop' => true);
             $image_ori = bfi_thumb($img_url, $params);
             //resize & crop the image
             echo '<li>';
             echo '<a href="' . $attachment_url . '" title="Image for ' . $desc_img . '"><img src="' . $image_ori . '" height="250" width="300" alt="' . $desc_img . '" title="' . $desc_img . '" /></a>';
             echo '</li>';
         }
         echo '<ul></div>';
     }
 }