Error in Colormag version 1.2.1

Home Forums ColorMag Free Error in Colormag version 1.2.1

This topic contains 3 replies, has 2 voices, and was last updated by  ashishsthanp 2 months, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1324610

    fabio
    Participant

    Since updated Colormag to v. 1.2.1 I have always this error when displaying image in widget Advertisement 728×90:

    Notice: Undefined variable: image_alt in /var/www/ibaa/wp-content/themes/colormag/inc/widgets/widgets.php on line 1017

    I have checked your code related to the file widget.php. The 1.2.0 version (with no errors) was:

      $output .= '<a href="'.$image_link.'" class="single_ad_728x90" target="_blank" rel="nofollow">
                                        <img src="'.$image_url.'" width="728" height="90">
                               </a>';
                   } else {
                      $output .= '<img src="'.$image_url.'" width="728" height="90">';
                   }
                   $output .= '</div>';
    ...

    The new 1.2.1 code is this:

    ...
    				$image_id = attachment_url_to_postid( $image_url );
    				$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
                   $output .= '<a href="'.$image_link.'" class="single_ad_728x90" target="_blank" rel="nofollow">
                                        <img src="'.$image_url.'" width="728" height="90" alt="' . $image_alt . '">
                               </a>';
                   } else {
                      $output .= '<img src="'.$image_url.'" width="728" height="90" alt="' . $image_alt . '">';
                   }
                   $output .= '</div>';
    ...

    My image has the ALT tag stored in, but your code is not getting it from the metadata tag. Pls let me know.

    • This topic was modified 2 months, 1 week ago by  fabio.
    #1324612

    fabio
    Participant

    I have made some more troubleshooting. The error is displayed ONLY if I left blank the image_link field. If I put a link in there, the error disappears, but I do not need a link on that image and it looks not a mandatory field!

    #1324613

    fabio
    Participant

    I found the bug in the code!

    You should remove the $image_alt variable on line 1017, or move lines 1011 and 1012 BEFORE line 1010!
    It is a naive bug! 🙂

    How the code should be:

    Case 1 line 1017:

    $output .= '<img src="'.$image_url.'" width="728" height="90">';

    Case 2: starting from line 1010:

             $image_id = attachment_url_to_postid( $image_url );
             $image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
             if ( !empty( $image_link ) ) {
    				....

    The second one is a better solution.
    Thank you for updating.

    • This reply was modified 2 months, 1 week ago by  fabio.
    • This reply was modified 2 months, 1 week ago by  fabio.
    #1324722

    ashishsthanp
    Moderator

    @fabio
    This issue has been already fixed and will be available on next version of the theme.

    Thanks for the concern.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.