Beispiel #1
0
/**
 * Edit post attachment.
 *
 * This function is shortuct of {@see beans_edit_image()}. It should be used to edit a post attachment.
 *
 * @since 1.0.0
 *
 * @param array  $args {
 *      Array of arguments used by the image editor.
 *
 * 		@type array $resize 	 Numeric array matching the {@link http://codex.wordpress.org/Class_Reference/WP_Image_Editor WP_Image_Editor} resize
 * 		      					 function arguments.
 * 		@type array $crop  	     Numeric array matching the {@link http://codex.wordpress.org/Class_Reference/WP_Image_Editor WP_Image_Editor} crop
 * 		      					 function arguments.
 * 		@type array $rotate      Numeric array matching the {@link http://codex.wordpress.org/Class_Reference/WP_Image_Editor WP_Image_Editor} rotate
 * 		      				     function arguments.
 * 		@type array $flip        Numeric array matching the {@link http://codex.wordpress.org/Class_Reference/WP_Image_Editor WP_Image_Editor} flip
 * 		      				     function arguments.
 * 		@type array $set_quality Numeric array matching the {@link http://codex.wordpress.org/Class_Reference/WP_Image_Editor WP_Image_Editor} set_quality
 * 		      					 function arguments. Default 100.
 * }
 *
 * @return object Edited post attachment data.
 */
function beans_edit_post_attachment($post_id, $args = array())
{
    if (!has_post_thumbnail($post_id)) {
        return false;
    }
    // Get full size image.
    $attachement = beans_get_post_attachment($post_id, 'full');
    if (!($edited = beans_edit_image($attachement->src, $args, 'ARRAY_A'))) {
        return false;
    }
    return (object) array_merge((array) $attachement, $edited);
}
Beispiel #2
0
/**
 * Echo post image.
 *
 * @since 1.0.0
 */
function beans_post_image()
{
    if (!has_post_thumbnail()) {
        return false;
    }
    global $post;
    /**
     * Filter the arguments used by {@see beans_edit_image()} to edit the post image.
     *
     * @since 1.0.0
     *
     * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
     *                              large size.
     */
    $edit_args = apply_filters('beans_edit_post_image_args', array('resize' => array(800, false)));
    if (empty($edit_args)) {
        $image = beans_get_post_attachment($post->ID, 'large');
    } else {
        $image = beans_edit_post_attachment($post->ID, $edit_args);
    }
    echo beans_open_markup('beans_post_image', 'div', array('class' => 'tm-article-image'));
    if (!is_singular()) {
        echo beans_open_markup('beans_post_image_link', 'a', array('href' => get_permalink(), 'title' => the_title_attribute('echo=0')));
    }
    echo beans_selfclose_markup('beans_post_image_item', 'img', array('width' => $image->width, 'height' => $image->height, 'src' => $image->src, 'alt' => esc_attr($image->alt)), $image);
    if (!is_singular()) {
        echo beans_close_markup('beans_post_image_link', 'a');
    }
    echo beans_close_markup('beans_post_image', 'div');
}
Beispiel #3
0
/**
 * Echo post image.
 *
 * @since 1.0.0
 */
function beans_post_image()
{
    if (!has_post_thumbnail() || !current_theme_supports('post-thumbnails')) {
        return false;
    }
    global $post;
    /**
     * Filter whether Beans should handle the image edition (resize) or let WP do so.
     *
     * @since 1.2.5
     *
     * @param bool $edit True to use Beans Image API to handle the image edition (resize), false to let {@link http://codex.wordpress.org/Function_Reference/the_post_thumbnail the_post_thumbnail()} taking care of it. Default true.
     */
    $edit = apply_filters('beans_post_image_edit', true);
    if ($edit) {
        /**
         * Filter the arguments used by {@see beans_edit_image()} to edit the post image.
         *
         * @since 1.0.0
         *
         * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
         *                              large size.
         */
        $edit_args = apply_filters('beans_edit_post_image_args', array('resize' => array(800, false)));
        if (empty($edit_args)) {
            $image = beans_get_post_attachment($post->ID, 'large');
        } else {
            $image = beans_edit_post_attachment($post->ID, $edit_args);
        }
        /**
         * Filter the arguments used by {@see beans_edit_image()} to edit the post small image.
         *
         * The small image is only used for screens equal or smaller than the image width set, which is 480px by default.
         *
         * @since 1.0.0
         *
         * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
         *                              small size.
         */
        $edit_small_args = apply_filters('beans_edit_post_image_small_args', array('resize' => array(480, false)));
        if (empty($edit_small_args)) {
            $image_small = beans_get_post_attachment($post->ID, 'thumbnail');
        } else {
            $image_small = beans_edit_post_attachment($post->ID, $edit_small_args);
        }
    }
    beans_open_markup_e('beans_post_image', 'div', array('class' => 'tm-article-image'));
    if (!is_singular()) {
        beans_open_markup_e('beans_post_image_link', 'a', array('href' => get_permalink(), 'title' => the_title_attribute('echo=0')));
    }
    beans_open_markup_e('beans_post_image_item_wrap', 'picture');
    if ($edit) {
        beans_selfclose_markup_e('beans_post_image_small_item', 'source', array('media' => '(max-width: ' . $image_small->width . 'px)', 'srcset' => esc_url($image_small->src)), $image_small);
        beans_selfclose_markup_e('beans_post_image_item', 'img', array('width' => $image->width, 'height' => $image->height, 'src' => $image->src, 'alt' => $image->alt, 'itemprop' => 'image'), $image);
    } else {
        // Beans API isn't available, use wp_get_attachment_image_attributes filter instead.
        the_post_thumbnail();
    }
    beans_close_markup_e('beans_post_image_item_wrap', 'picture');
    if (!is_singular()) {
        beans_close_markup_e('beans_post_image_link', 'a');
    }
    beans_close_markup_e('beans_post_image', 'div');
}
Beispiel #4
0
/**
 * Echo post image.
 *
 * @since 1.0.0
 */
function beans_post_image()
{
    if (!has_post_thumbnail()) {
        return false;
    }
    global $post;
    /**
     * Filter the arguments used by {@see beans_edit_image()} to edit the post image.
     *
     * @since 1.0.0
     *
     * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
     *                              large size.
     */
    $edit_args = apply_filters('beans_edit_post_image_args', array('resize' => array(800, false)));
    if (empty($edit_args)) {
        $image = beans_get_post_attachment($post->ID, 'large');
    } else {
        $image = beans_edit_post_attachment($post->ID, $edit_args);
    }
    /**
     * Filter the arguments used by {@see beans_edit_image()} to edit the post small image.
     *
     * The small image is only used for screens equal or smaller than the image width set, which is 480px by default.
     *
     * @since 1.0.0
     *
     * @param bool|array $edit_args Arguments used by {@see beans_edit_image()}. Set to false to use WordPress
     *                              small size.
     */
    $edit_small_args = apply_filters('beans_edit_post_image_small_args', array('resize' => array(480, false)));
    if (empty($edit_small_args)) {
        $image_small = beans_get_post_attachment($post->ID, 'small');
    } else {
        $image_small = beans_edit_post_attachment($post->ID, $edit_small_args);
    }
    echo beans_open_markup('beans_post_image', 'div', array('class' => 'tm-article-image'));
    if (!is_singular()) {
        echo beans_open_markup('beans_post_image_link', 'a', array('href' => get_permalink(), 'title' => the_title_attribute('echo=0')));
    }
    echo beans_open_markup('beans_post_image_item_wrap', 'picture');
    echo beans_selfclose_markup('beans_post_image_small_item', 'source', array('media' => '(max-width: ' . $image_small->width . 'px)', 'srcset' => $image_small->src), $image_small);
    echo beans_selfclose_markup('beans_post_image_item', 'img', array('width' => $image->width, 'height' => $image->height, 'src' => $image->src, 'alt' => esc_attr($image->alt), 'itemprop' => 'image'), $image);
    echo beans_close_markup('beans_post_image_item_wrap', 'picture');
    if (!is_singular()) {
        echo beans_close_markup('beans_post_image_link', 'a');
    }
    echo beans_close_markup('beans_post_image', 'div');
}