• Resolved Aldo

    (@ab_lu)


    Hi Stefan

    We try to add some additional attributes to the img tag:

    'attributes' => array(
                                'img' => array(
                                      'class'           => 'lazyload img-responsive',
                                      'data-sizes'      => 'auto',
                                      'data-parent-fit' => 'cover'
                                  )
                                )

    Unfortunately we get then the following error:

    <b>Warning</b>:  Illegal string offset 'property' in <b>/Volumes/Data/WEB/HTDOCS/site/web/app/plugins/responsify-wp/includes/img.php</b> on line <b>43</b><br />
    <br />
    <b>Warning</b>:  Illegal string offset 'value' in <b>/Volumes/Data/WEB/HTDOCS/site/web/app/plugins/responsify-wp/includes/img.php</b> on line <b>43</b><br />
    <br />
    <b>Warning</b>:  Illegal string offset 'property' in <b>/Volumes/Data/WEB/HTDOCS/site/web/app/plugins/responsify-wp/includes/img.php</b> on line <b>43</b><br />
    <br />
    <b>Warning</b>:  Illegal string offset 'value' in <b>/Volumes/Data/WEB/HTDOCS/site/web/app/plugins/responsify-wp/includes/img.php</b> on line <b>43</b><br />

    Any idea?

    https://wordpress.org/plugins/responsify-wp/

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author stefanledin

    (@stefanledin)

    Remove the img array. Like this:

    'attributes' => array(
        'class'           => 'lazyload img-responsive',
        'data-sizes'      => 'auto',
        'data-parent-fit' => 'cover'
    )
    Thread Starter Aldo

    (@ab_lu)

    Still the same.

    Plugin Author stefanledin

    (@stefanledin)

    With the other thread in mind, are you doing something special with media queries? The error occurs when the sizes attribute is created.

    Thread Starter Aldo

    (@ab_lu)

    No, nothing special. This is the complete attributes array:

    $rwp_attributes = array(
                    'sizes' => array( 'image-xs', 'image-sm', 'image-md', 'image-lg', 'image-xlg' ),
                    'media_queries' => array(
                                  'image-xs' => 'max-width: 320px',
                                  'image-sm' => 'min-width: 321px',
                                  'image-md' => 'min-width: 770px',
                                  'image-lg' => 'min-width: 1000px',
                                  'image-xlg' => 'min-width: 1540px'
                      ),
                      'retina' => true,
                      'attributes' => array(
                                      'class'           => 'lazyload img-responsive',
                                      'data-sizes'      => 'auto',
                                      'data-parent-fit' => 'cover'
                                  )
    
                    );
    Thread Starter Aldo

    (@ab_lu)

    It only happens using rwp_img.
    With rwp_picture the output is fine.
    But I need to use rwp_img

    Plugin Author stefanledin

    (@stefanledin)

    Oh, now I see. Media queries are written like that for the picture element. For img, you’re really only changing the sizes attribute, which you can set in the attributes array.

    $rwp_attributes = array(
    	'sizes' => array( 'thumbnail', 'medium', 'large' ),
    	'retina' => true,
    	'attributes' => array(
    		'class'           => 'lazyload img-responsive',
    		'data-sizes'      => 'auto',
    		'data-parent-fit' => 'cover',
    		'sizes' => '(min-width: 1540px) [image-lg-width]px, (min-width: 1000px) [image-lg-width]px, (min-width: 770px) [image-md-width]px, (min-width: 321px) [image-sm-width]px, [image-xs-width]px'
    	)
    );

    I know it’s hard to understand the code above, but I think that this “formula” would do the trick. You just have to insert the sizes of your custom image sizes.

    Thread Starter Aldo

    (@ab_lu)

    I still get the same error.
    BTW: Do I not need to add the retina sizes in the ‘sizes’ paramter?

    Plugin Author stefanledin

    (@stefanledin)

    Really? You don’t have the old code in some other place?

    Yeah you just have to add the image sizes that you wanna use. img just want to have a bunch of different images to choose from, it doesn’t care if it’s “retina” or not. picture however needs to have the original and retina image grouped together in the same <source> tag.

    Thread Starter Aldo

    (@ab_lu)

    No nowhere else.
    And the warnings are returned exactly where the image markup is rendered.

    Plugin Author stefanledin

    (@stefanledin)

    Haha, of course they are. Why would anything be easy? 😉

    Okey, back to the drawing board. Can I get the code for your custom image sizes and dimensions for the built in sizes so I can recreate the scenario?
    Twenty fifteen was the theme, right?

    Thread Starter Aldo

    (@ab_lu)

    Her you go 🙂

    add_image_size( 'image-xs', 385, 9999 );
    add_image_size( 'image-xs@2x', 770, 9999 );
    
    add_image_size( 'image-sm', 500, 9999 );
    add_image_size( 'image-sm@2x', 1000, 9999 );
    
    add_image_size( 'image-md', 770, 9999 );
    add_image_size( 'image-md@2x', 1540, 9999 );
    
    add_image_size( 'image-lg', 1000, 9999 );
    add_image_size( 'image-lg@2x', 2000, 9999 );
    
    add_image_size( 'image-xlg', 1540, 9999 );
    add_image_size( 'image-xlg@2x', 3080, 9999 );

    Regarding the theme, it doesn’t matter a tried with some standard WP themes and my own and I get everywhere the same warnings.

    Plugin Author stefanledin

    (@stefanledin)

    Thanks!
    It works like a charm for me… I tested on a clean installation with twenty fifteen and standard RWP settings, beside of the picture element as markup pattern.

    I uploaded an image and placed the following code above the loop in index.php:

    <?php
    echo rwp_img(6, array(
        'sizes' => array( 'image-xs', 'image-sm', 'image-md', 'image-lg', 'image-xlg' ),
        'retina' => true,
        'attributes' => array(
            'class'           => 'lazyload img-responsive',
            'data-sizes'      => 'auto',
            'data-parent-fit' => 'cover',
            'sizes' => '(min-width: 1540px) 1540px, (min-width: 1000px) 1000px, (min-width: 770px) 770px, (min-width: 321px) 500px, 385px'
    
        )
    ));
    ?>

    Works perfectly!

    What happens if you remove the settings array? Any errors then? And if you then add one option at the time into the settings array?

    You could also add var_dump($mq); before line 43 in responsify-wp/includes/img.php and see what happens.
    It should look like this then:

    if ( isset($images[$i]['media_query']) ) {
        $mq = $images[$i]['media_query'];
        $attribute[] = '('.$mq['property'].': '.$mq['value'].') '.$images[$i]['width'].'px';
    } else {
        $attribute[] = $images[$i]['width'].'px';
    }
    Thread Starter Aldo

    (@ab_lu)

    Hi Stefan

    I found the issue.
    Had the media_queries array still present. removed it and all okay.
    But one remaining issue.

    The images in the srcset are all returned twice. Here the markup:

    <img srcset="/app/uploads/2016/04/Webseite_Mood-385x261.jpg 385w, /app/uploads/2016/04/Webseite_Mood-770x522.jpg 770w, /app/uploads/2016/04/Webseite_Mood-500x339.jpg 500w, /app/uploads/2016/04/Webseite_Mood-1000x678.jpg 1000w, /app/uploads/2016/04/Webseite_Mood-770x522.jpg 770w, /app/uploads/2016/04/Webseite_Mood-1540x1045.jpg 1540w, /app/uploads/2016/04/Webseite_Mood-1000x678.jpg 1000w, /app/uploads/2016/04/Webseite_Mood-2000x1357.jpg 2000w, /app/uploads/2016/04/Webseite_Mood-1540x1045.jpg 1540w" sizes="(min-width: 1540px) 1540px, (min-width: 1000px) 1000px, (min-width: 770px) 770px, (min-width: 321px) 500px, 385px" class="lazyload img-responsive" data-sizes="auto" data-parent-fit="cover">

    Any idea?

    Plugin Author stefanledin

    (@stefanledin)

    Isn’t it the retina sizes?

    Thread Starter Aldo

    (@ab_lu)

    No, if the would have the “@2x” in the filename, not?

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Error when adding additional attributes’ is closed to new replies.