• Resolved ewilkinson

    (@ewilkinson)


    Hi, great plugin but I’ve run into one issue with the code:

    There is an extra conditional being called which prevents the empty check from functioning correctly.

    If you set Override existing alt tag to NO, then no alt tags are overwritten, even if empty – the alt tag logic is entirely skipped/disabled.

    However, if you set Override existing alt tag to YES, then all alt tags are being overridden, even if they’re already set.

    So, due to the extra conditional, there is currently no way to enable the alt tags to only replace alt tags that aren’t already set.

    This would be fine, except there is unreachable logic that is supposed to allow replacing the content ONLY IF it isn’t populated.

    I have this fixed and working, by commenting out one of the extra conditionals.

    Here is the where the issue is in the code:

    In the file: seo-optimized-images.php (version 1.6.7)

    ////////////////// check for alt tag /////////////////////////
    // In case there is not alt tag, create the tag and insert the value
    
    /* REMOVE THE FOLLOWING CONDITIONAL, or create a new variable for Enabling/Disabling using the alt tag replace feature and use it here. The problem is that this $alt_flag is used here, and then also within this condition (where it's always going to be true). The "Should we override the existing alt tag" is currently ALWAYS true, there's no way to prevent overriding the existing alt tag without turning the entire alt-tag replacement functionality off. */ 
    /*if ($alt_flag == "1")
    {*/
    
    // if alt tag is not present than insert the tag.
    if($is_alt == 0)
    {   
      $new_img = str_replace('<img ', '<img '.$t , $img);
      $content = str_replace($img, $new_img, $content);
    }
    // if alt tag is present
    elseif($is_alt==1)
    {
      $text = trim($alt[1][0]);
      // Check if the alt text is empty.
      if(empty($text))
      {
        $new_img = str_replace($alt[0][0], $t, $img);
        $content = str_replace($img, $new_img, $content);
      }
    
      // Should we override the existing alt tag
      if ($alt_flag == "1")
      {
        $new_img = str_replace($alt[0][0], $t, $img);
        $content = str_replace($img, $new_img, $content);
      }
    }
    
    //}
    //////////////////// checked for alt tag ////////////////////

    Please let me know if this can be updated. I would like to recommend this plugin to a client but am concerned about providing them with an edited version due to versioning/upgrading difficulty.

    Looking forward to your response.
    Best regards,
    Eric

    • This topic was modified 7 years, 11 months ago by ewilkinson.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Logic flaw forcing overwriting existing alt tags when enabled’ is closed to new replies.