[wp-hackers] iOS WP app: Featured image size problems

Nikola Nikolov nikolov.tmw at gmail.com
Wed Oct 23 19:39:13 UTC 2013


Can you try doing

print_r( wp_get_attachment_metadata( get_post_thumbnail_id( $post->ID ) ) );

And see what the "sizes" key of the returned array contains? In theory all
of your custom sizes data should be right there(see the function in the
codex -
http://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata ).

If there are no sizes(or only the default ones are there), try the
following:

$uploads_dir = wp_upload_dir();
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$file_name = wp_get_attachment_metadata( $thumbnail_id );
$file_name = $file_name && isset( $file_name['file'] ) ? $file_name['file']
: false;
if ( $file_name ) {
    include_once( ABSPATH . 'wp-admin/includes/image.php' );
    echo "Generating attachment metadata for attachment with ID {$
thumbnail_id}:\n";
    print_r( wp_generate_attachment_metadata( $thumbnail_id, $file_name ) );
} else {
    echo 'No file found';
}

This should in theory generate the attachment metadata - if you have your
sizes in the "sizes" array key, then the problem is either in your
set-up(theme/plugins), or the iOS app.

To investigate further, set-up a default install(no plugins, the default
theme - maybe add in a custom size in there) and use the iOS app to upload
a featured image for a post. Then see if the Featured image comes in your
size - if it does, then it's either your theme, or one of your plugins. If
it doesn't - it's a bug in the iOS app which you should file here -
https://github.com/wordpress-mobile/WordPress-iOS/issues

I hope some of that helps,
Nikola


On Wed, Oct 23, 2013 at 9:58 PM, Micky Hulse <mickyhulse.lists at gmail.com>wrote:

> Hello,
>
> Thanks so much for the replies J.D. and Simon, I really appreciate your
> help.
>
> On Wed, Oct 23, 2013 at 5:25 AM, J.D. Grimes <jdg at codesymphony.co> wrote:
> > I don't think that wp_get_attachment_image_src() accepts parameters of
> the format you are using ('300px').
> http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
> > The $size can either be a keyword (thumbnail, medium, large or full) or
> an array (array(300,300)).
>
> My bad. I apologize that I did not mention the rest of my setup.
>
> In my functions file, I have:
>
> function mytheme_setup() {
> add_theme_support('post-thumbnails');
> set_post_thumbnail_size(150, 150);
> }
> add_action('after_setup_theme', 'mytheme_setup');
> // ... and later on in this file:
> # Add new image sizes:
> add_image_size('130px', 130); // Thumbnail size: 130 x 130
> add_image_size('300px', 300); // Medium size: 300 x 300
> add_image_size('470px', 470);
> add_image_size('640px', 640);
> add_image_size('810px', 810);
> add_image_size('980px', 980); // Large size: 980 x 980
> add_image_size('1320px', 1320);
> add_image_size('1620px', 1620);
> add_image_size('1960px', 1960);
>
> The new image size names are based on another system we use ... I
> wanted to keep the "XXXpx" naming conventions the same across systems.
>
> With that said, the use of (for example):
>
> wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '300px')
> wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '640px')
>
> ... work for all images, except for images uploaded as a featured
> image using the WP iOS app.
>
> Other image getting functions also work, but it's the iOS images that
> just return the original source image size.
>
> On Wed, Oct 23, 2013 at 7:57 AM, Simon Vart <simon.vart at exigences.biz>
> wrote:
> > I think you could also add a new image size in functions.php :
> > add_image_size( '300px', 300, 300, true );
> > and then your call to wp_get_attachment_image_src() will be understood.
> When
> > you upload an image, WP will create a image of this size with the keyword
> > '300px'
>
> Sorry again, that I did not detail my setup. Thank you for the help,
> and thankfully I do have that setup in my functions.php file. I
> should've made that clear in my first message. :(
>
> Question(s):
>
> When you folks use the iOS WP app, and set a featured image, are you
> able to get at the different sizes on your templates?
>
> For some reason, my setup isn't allowing me to access the custom image
> sizes (only for iOS-uploaded featured images), even though they are
> generated and sitting there in my uploads folder.
>
> Maybe I'm not setup properly in my functions.php file? I have all of
> my add_image_size() calls just sitting out in the open. Do I need to
> have these inside of an action? Should they go inside the
> "after_setup_theme" action along side my
> add_theme_support('post-thumbnails') call?
>
> Please let me know if I can provide more information.
>
> Thank you!
>
> M
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list