• Resolved hirschmedia

    (@hirschmedia)


    I’m relatively new to working with PHP, so I hope someone can explain in simple terms how to resolve an undefined offset notice appearing above each excerpt on the blog page. The notice says

    Notice: Undefined offset: 3 in /mnt/stor09-wc1-ord1/782565/855761/www.hirschmedia.biz/web/content/wp-content/themes/customizr/parts/class-content-post_list.php on line 173

    It also points to an error on line 208.

    Here’s the PHP code for line 173 and surrounding lines:

    //check if tc-thumb size exists for attachment and return large if not
                $image                      = wp_get_attachment_image_src( $tc_thumb_id, $tc_thumb_size);
                if (null == $image[3]) {
                  $tc_thumb_size            = 'medium';
                 }
                $tc_thumb                   = get_the_post_thumbnail( get_the_ID(),$tc_thumb_size);
                //get height and width
                $tc_thumb_height            = $image[2];
                $tc_thumb_width             = $image[1];
            }

    Here’s the code for line 208 and surrounding lines:

    if ( isset($attachments) ) {
    foreach ( $attachments as $attachment) {
    //check if tc-thumb size exists for attachment and return large if not
    $image = wp_get_attachment_image_src( $attachment->ID, $tc_thumb_size);
    if (false == $image[3]) {
    $tc_thumb_size = ‘medium’;
    }
    $tc_thumb = wp_get_attachment_image( $attachment->ID, $tc_thumb_size);
    //get height and width
    $tc_thumb_height = $image[2];
    $tc_thumb_width = $image[1];
    }

    I was wondering if this had something to do with deactivating the Regenerate Images plugin, but the Regenerate Images plugin developer recommends using Photon in Jetpack, and I’m doing that. I also tried reactivating Regenerate Images and that didn’t resolve the problem.

Viewing 7 replies - 1 through 7 (of 7 total)
  • It says that $image array doesn’t have the fourth element you’re indexing with $image[3] . And it’s the same warning bot for line 173 and 208 . For line 173 when tries to use the post thumbnails, for line 208 when tries to use the first found post attached image.

    Looking at the documentation that fourth element should be:

    [3] => boolean: true if $url is a resized image, false if it is the original.

    So something weird happened. Photon problem?
    Since I read about some issues with thumbnails when “Retina support” in customizr panel is not enabled, is it enabled there?

    I don’t think it’s related to Regenerate Images(Thumbnails?) plug-in deactivation, it does something just if you tell him to regenerate thumbnails.

    You can try deactivating Photon plug-in and write a new post + image, and see if the problem is still there.

    p.s.
    I hope you can solve, and maybe that somebody could figure out your problem.
    What I can say is that if you don’t find a solution, as extreme measure, you can avoid that notice warning, adding a condition to that if:
    making those:
    if (false == $image[3]) {

    become like this:
    if ( isset($image[3]) && false == $image[3]) {

    Looks like a bug. Not sure why this condition triggers like this on this site and has not been spotted before, though.

    Reporting to nikeo…

    You’re thinking about a customizr bug?
    I think something weird happened because of external parts, but maybe I’m wrong.
    Docs say that return value should have 4 elements or at least be a boolean if the image doesn’t exist at all.
    Consider that the thumbnail itself exists…

    I was assuming an bug because the image didn’t exist. In which case, [3] would not exist at all (and the array would be empty, which would give this php error).

    However, I see that on several posts with the error, the featured image does exist, so it’s not that.

    Looking further at the site, I see that there are quite a lot of issues with the images. For example, the featured images are coming out as https://i0.wp.com/www.hirschmedia.biz/wp-content/uploads/2013/11/CliffStaton.jpg?fit=300%2C300 rather than https://www.hirschmedia.biz/wp-content/uploads/2013/11/CliffStaton-270x250.jpg that I would expect. (I presume it’s photon that’s adding that extra bit at the end.)

    Additionally, many blog posts aren’t showing the images at all.

    @hirschmedia:

    I was wondering if this had something to do with deactivating the Regenerate Images plugin, but the Regenerate Images plugin developer recommends using Photon in Jetpack, and I’m doing that. I also tried reactivating Regenerate Images and that didn’t resolve the problem.

    Activating/deactivating regenerate thumbnails will make no difference. It’s only when you run it that it does something. For the rest of the time, it’s not active. The developer may recommend photon, but that’s not a reason you should have to use it. (I recommend Customizr, but there are lots of other themes out there…) Customizr images get served at the right size without Photon.

    I agree with d4z_c0nf that Photon will probably be causing the problem, and maybe whatever cache you are using.

    I know it’s a pain, but you need to deactivate all your plugins and reactivate them one by one to find the culprit. Each time you reactivate a plugin, check all your blog pictures are showing inside each post. Remember to clear any caches you have set up to see the effect of each change.

    Thread Starter hirschmedia

    (@hirschmedia)

    Thanks d4z_c0nf and ElectricFeet for your support on this. ElectricFeet, I took your advice, deactivating all plugins and reactivating one by one to find the source of the problem. Indeed, it was Photon!

    For what it’s worth, d4z_c0nf, yes, “Retina support” is enabled.

    Thanks again. So very glad to know help is out there. And now I can go back to learning code and updating the site without those ugly Undefined Offset notices.

    Glad you solved.

    Glad you solved.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Undefined offset notice on blog page’ is closed to new replies.