• Resolved alx359

    (@alx359)


    Hi David,

    Today noticed many recurring PHP warnings in php_error.log in the staging site (WAMP32/PHP7.1/Win7-64):

     
    WARNING: STRRPOS() EXPECTS PARAMETER 1 TO BE STRING, ARRAY GIVEN IN D:\DOMAINS\MYDOMAIN.COM\WP-CONTENT\PLUGINS\MEDIA-LIBRARY-ASSISTANT\INCLUDES\CLASS-MLA-SHORTCODE-SUPPORT.PHP ON LINE 1046
    
    
    NOTICE: ARRAY TO STRING CONVERSION IN D:\DOMAINS\MYDOMAIN.COM\WP-CONTENT\PLUGINS\MEDIA-LIBRARY-ASSISTANT\INCLUDES\CLASS-MLA-SHORTCODE-SUPPORT.PHP ON LINE 1286
    
    
    Warning: urlencode() expects parameter 1 to be string, array given in D:\domains\MYDOMAIN.COM\wp-content\plugins\media-library-assistant\includes\class-mla-list-table.php on line 1418
    

    The culprit seems to lead to invalid Attachment Metadata. The MLA Assistant hints to metadata that has somehow duplicated. For example:

    
    array (
      0 => 
      array (
        'width' => 1500,
        'height' => 1558,
        'file' => 'card-back1-w__custom.jpg',
        'sizes' => 
        array (
          'quick_view_image_size' => 
          array (
            'file' => 'card-back1-w__custom-481x500.jpg',
            'width' => 481,
            'height' => 500,
            'mime-type' => 'image/jpeg',
          ),
          'thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-150x150.jpg',
            'width' => 150,
            'height' => 150,
            'mime-type' => 'image/jpeg',
          ),
          'medium' => 
          array (
            'file' => 'card-back1-w__custom-289x300.jpg',
            'width' => 289,
            'height' => 300,
            'mime-type' => 'image/jpeg',
          ),
          'medium_large' => 
          array (
            'file' => 'card-back1-w__custom-768x798.jpg',
            'width' => 768,
            'height' => 798,
            'mime-type' => 'image/jpeg',
          ),
          'large' => 
          array (
            'file' => 'card-back1-w__custom-986x1024.jpg',
            'width' => 986,
            'height' => 1024,
            'mime-type' => 'image/jpeg',
          ),
          'widget-thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-75x75.jpg',
            'width' => 75,
            'height' => 75,
            'mime-type' => 'image/jpeg',
          ),
          'woocommerce_thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-247x296.jpg',
            'width' => 247,
            'height' => 296,
            'mime-type' => 'image/jpeg',
            'uncropped' => true,
          ),
          'woocommerce_single' => 
          array (
            'file' => 'card-back1-w__custom-510x530.jpg',
            'width' => 510,
            'height' => 530,
            'mime-type' => 'image/jpeg',
          ),
          'woocommerce_gallery_thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-100x100.jpg',
            'width' => 100,
            'height' => 100,
            'mime-type' => 'image/jpeg',
          ),
          'shop_catalog' => 
          array (
            'file' => 'card-back1-w__custom-247x296.jpg',
            'width' => 247,
            'height' => 296,
            'mime-type' => 'image/jpeg',
            'uncropped' => true,
          ),
          'shop_single' => 
          array (
            'file' => 'card-back1-w__custom-510x530.jpg',
            'width' => 510,
            'height' => 530,
            'mime-type' => 'image/jpeg',
          ),
          'shop_thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-100x100.jpg',
            'width' => 100,
            'height' => 100,
            'mime-type' => 'image/jpeg',
          ),
        ),
        'image_meta' => 
        array (
          'aperture' => '0',
          'credit' => 'Eva Campbell - EvitaWorks',
          'camera' => '',
          'caption' => 'Card Back1 W Custom',
          'created_timestamp' => '0',
          'copyright' => '(c) EvitaWorks.com. All rights reserved. Forbidden commercial use without permission.',
          'focal_length' => '0',
          'iso' => '0',
          'shutter_speed' => '0',
          'title' => 'Card Back1 W Custom',
          'orientation' => '0',
          'keywords' => 
          array (
          ),
        ),
      ),
      1 => 
      array (
        'width' => 1500,
        'height' => 1558,
        'file' => 'card-back1-w__custom.jpg',
        'sizes' => 
        array (
          'quick_view_image_size' => 
          array (
            'file' => 'card-back1-w__custom-481x500.jpg',
            'width' => 481,
            'height' => 500,
            'mime-type' => 'image/jpeg',
          ),
          'thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-150x150.jpg',
            'width' => 150,
            'height' => 150,
            'mime-type' => 'image/jpeg',
          ),
          'medium' => 
          array (
            'file' => 'card-back1-w__custom-289x300.jpg',
            'width' => 289,
            'height' => 300,
            'mime-type' => 'image/jpeg',
          ),
          'medium_large' => 
          array (
            'file' => 'card-back1-w__custom-768x798.jpg',
            'width' => 768,
            'height' => 798,
            'mime-type' => 'image/jpeg',
          ),
          'large' => 
          array (
            'file' => 'card-back1-w__custom-986x1024.jpg',
            'width' => 986,
            'height' => 1024,
            'mime-type' => 'image/jpeg',
          ),
          'widget-thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-75x75.jpg',
            'width' => 75,
            'height' => 75,
            'mime-type' => 'image/jpeg',
          ),
          'woocommerce_thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-247x296.jpg',
            'width' => 247,
            'height' => 296,
            'mime-type' => 'image/jpeg',
            'uncropped' => true,
          ),
          'woocommerce_single' => 
          array (
            'file' => 'card-back1-w__custom-510x530.jpg',
            'width' => 510,
            'height' => 530,
            'mime-type' => 'image/jpeg',
          ),
          'woocommerce_gallery_thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-100x100.jpg',
            'width' => 100,
            'height' => 100,
            'mime-type' => 'image/jpeg',
          ),
          'shop_catalog' => 
          array (
            'file' => 'card-back1-w__custom-247x296.jpg',
            'width' => 247,
            'height' => 296,
            'mime-type' => 'image/jpeg',
            'uncropped' => true,
          ),
          'shop_single' => 
          array (
            'file' => 'card-back1-w__custom-510x530.jpg',
            'width' => 510,
            'height' => 530,
            'mime-type' => 'image/jpeg',
          ),
          'shop_thumbnail' => 
          array (
            'file' => 'card-back1-w__custom-100x100.jpg',
            'width' => 100,
            'height' => 100,
            'mime-type' => 'image/jpeg',
          ),
        ),
        'image_meta' => 
        array (
          'aperture' => '0',
          'credit' => 'Eva Campbell - EvitaWorks',
          'camera' => '',
          'caption' => 'Card Back1 W Custom',
          'created_timestamp' => '0',
          'copyright' => '(c) EvitaWorks.com. All rights reserved. Forbidden commercial use without permission.',
          'focal_length' => '0',
          'iso' => '0',
          'shutter_speed' => '0',
          'title' => 'Card Back1 W Custom',
          'orientation' => '0',
          'keywords' => 
          array (
          ),
        ),
      ),
    )
    

    Have no idea why or when this had happened. I’m currently attempting to fix this with the Fix Media Library plugin.

    My questions are:

    1) Has MLA specific functionality that may help fixing issues like this?
    2) Would you consider addressing this issue in code? A workaround that’s working for me is hacking the $base_file variable into class-mla-shortcode-support.php at line 1012, and class-mla-list-table.php at line 1414:
    $base_file = is_array($base_file) ? $base_file[0]: $base_file;

    Update: Fix Media Library says it has found many issues, but didn’t fix the duplicating problem, unfortunately.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your report and for the detailed information regarding your investigation of the problem so far.

    The $base_file problem is related to but not the same as the “invalid Attachment Metadata” example you posted. The attachment metadata is stored in the postmeta database table under the meta_key value _wp_attachment_metadata. The $base_file variable is populated from a postmeta value named _wp_attached_file. It looks like both of these keys have duplicated values in your database.

    Although WordPress allows multiple values for a given postmeta key, the two key values named above are assumed to have just one value for a given post/item. Patching the code as you suggested would mask the symptoms of the problem but there is no telling where else in the site’s code (WordPress core, active theme and all plugins) a related problem might occur. Your database is corrupted and the solution is to fix the database.

    I installed and activated the “Fix Media Library” plugin you mentioned. Looking through the code I do not see any indication that the duplication problem you have is detected or corrected by this plugin.

    If you want to patch the MLA code, the best place to do that is the mla_fetch_attachment_metadata() function in /includes/class-mla-data-query.php. At lines 557 to 569 you will find:

    if ( stripos( $post_meta_key, '_wp_attached_file' ) === 0 ) {
    	$key = 'mla_wp_attached_file';
    	$attached_file = $post_meta_value[0];
    } elseif ( stripos( $post_meta_key, '_wp_attachment_metadata' ) === 0 ) {
    	$key = 'mla_wp_attachment_metadata';
    } elseif ( stripos( $post_meta_key, '_wp_attachment_image_alt' ) === 0 ) {
    	$key = 'mla_wp_attachment_image_alt';
    } else {
    	continue;
    }
    

    You can change that to something like:

    if ( stripos( $post_meta_key, '_wp_attached_file' ) === 0 ) {
    	$key = 'mla_wp_attached_file';
    	$attached_file = $post_meta_value[0];
    	$post_meta_value = array( 0 => $post_meta_value[0] );
    } elseif ( stripos( $post_meta_key, '_wp_attachment_metadata' ) === 0 ) {
    	$key = 'mla_wp_attachment_metadata';
    	$post_meta_value = array( 0 => $post_meta_value[0] );
    } elseif ( stripos( $post_meta_key, '_wp_attachment_image_alt' ) === 0 ) {
    	$key = 'mla_wp_attachment_image_alt';
    	$post_meta_value = array( 0 => $post_meta_value[0] );
    } else {
    	continue;
    }
    

    That should fix MLA’s use of the three important metadata fields. It won’t, of course, fix any other component using those values. I don’t plan to update the official MLA version with this patch because I am reluctant to work around database corruption as a matter of policy.

    It would be straightforward to write a small custom plugin that goes through the database and corrects this specific error. If that’s of interest I can give you more specific help, but I cannot promise a quick response because of my current workload.

    I will leave this topic unresolved until I hear back from you. Thanks for your understanding nd your continued interest in the plugin.

    Thread Starter alx359

    (@alx359)

    Thank you, David, for the detailed investigation of the real culprit of the issue!

    Lead by your suggestions tried just another plugin: Cleanup Duplicate Meta that seems to have fixed the meta fields duplication in about 80 records. Have unpatched MLA and the reported error has gone away for now.

    I recall now that while chasing another issue on stage lately, had to switch themes back and forth many times in a short period. An automatic thumbnail regeneration job notice appeared from the different media dimensions. I usually stopped it and continued without giving it any more thought, but perhaps may have missed it executing in one browser tab while I was switching themes into another, and that may have corrupted something.

    Anyway, thank you again for the in-depth analysis and kind offer for a specific fix. Completely agree masking DB corruption isn’t a good practice at all, but from edge cases like mine of all the things one can’t control is perhaps worth of a sensible check, e.g.:

    if ( is_array($base_file) ) return array( 'message' => sprintf( "WARNING: Duplicated metadata found. Please check your DB for corruption." ) );

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WARNING: STRRPOS() EXPECTS PARAMETER 1 TO BE STRING, ARRAY GIVEN’ is closed to new replies.