• giladehven

    (@giladehven)


    Upon running any WP-CLI command:

    Warning: Trying to access array offset on value of type null in /.../plugins/svg-support/functions/mime-types.php on line 22

    And:

    Fatal error: Uncaught TypeError: array_intersect(): Argument #1 ($array) must be of type array, null given in /.../plugins/svg-support/functions/mime-types.php:28

    Adding something like if ( is_array( $allowed_roles_array ) ) to the offending line “fixes” the issue (albeit only until the next update, of course). Unfortunately, I didn’t have a chance to look into whether there is fallout elsewhere (I only went this hack route to avoid deactivating and reactivating the plugin every time I need to do something with WP-CLI while we wait for a real fix).

    Wonderful plugin, BTW!

Viewing 15 replies - 1 through 15 (of 15 total)
  • bezzo

    (@bezzo)

    I can confirm the issue. While the plugin is activated running any wp-cli command causes to throw an error.

    
    $ wp plugin list
    
    In mime-types.php line 22:
    Trying to access array offset on value of type null`
    
    mabioneto

    (@mabioneto)

    The error is being raised because no user is logged in. Before it would raise just a warning, but now is a fatal error and it breaks wp-cli, among other things.

    To fix until the developer patches on the next upcoming upgrade, just add the following 3 lines right after line 24 (on the file svg-support/functions/mime-types.php):
    //returns if user is not logged in
    if ($user->ID==0) {
    return $mimes;
    }

    plumbweb

    (@plumbweb)

    I can confirm this is happening still and on 2.5.3 as well.

    Thread Starter giladehven

    (@giladehven)

    Any idea when a lasting fix is expected?

    Our process depends upon atomic deployments (we ship the entire code base at every release), and we deploy very frequently. This means that temporary fixes of the type I described above (or the more complete approach that @mabioneto posted) really aren’t supportable.

    FYI, I can confirm that this issue is PHp 8.x related. We didn’t have a problem with this version of the plugin when some infrastructure was running PHP 7.4, after upgrading that infrastructure to PHP 8.0 this error occurred.

    pkostadinov

    (@pkostadinov)

    I also experienced the issue.

    The problem is that you define a global variable, but don’t actually define it as global (aka missing global keyword).

    File: svg-support/svg-support.php
    On Line 25 add this code:
    global $bodhi_svgs_options;

    Right after the comment:

    /**
     * Global variables
     */

    —-

    On the separate note – other users are correct:

    @tnolte comment points to that the php.ini for the CLI version of PHP must have errors display disabled for any production environment. You may have different php.ini files for the CLI version, and this is totally normal, you need all of them to be setup correctly for production. This should be the default setup for any server, but the plugin creators can remind people about it, in the plugin documentation.

    @giladehven mentiones proper escaping. Just in that 1 function in file mime-types.php, there are 2 missing data validations:
    – Line 21: if ( empty( $bodhi_svgs_options['restrict'] ) ) { return $mimes; }
    – Line 25: if ( ! $user ) { return $mimes; }
    ( if you don’t have user with ID 0, and you are not logged in which would be the case during the WP-CLI request, you need to just skip the remaining lines in this file)

    Thread Starter giladehven

    (@giladehven)

    Update: Version 2.5.4 appears to resolve the issue (it’s working as expected in our environments).

    • This reply was modified 2 years ago by giladehven.
    plumbweb

    (@plumbweb)

    Awesome, same with us! Thank you to the developer!

    pkostadinov

    (@pkostadinov)

    Still not fully resolved, there are PHP Warnings remaining during any WP Cli commands:

    PHP Warning: Trying to access array offset on value of type null in /wp-content/plugins/svg-support/functions/mime-types.php on line 22

    My original suggestion for adding global $bodhi_svgs_options; at the beginning of plugin file sitll resolves the problem.

    On the plus side – at least now there are no fatal errors…

    Thread Starter giladehven

    (@giladehven)

    I’m still getting the same warning:

    Warning: Trying to access array offset on value of type null in ... /plugins/svg-support/functions/mime-types.php on line 22

    Is there an ETA on the fix?

    • This reply was modified 2 years ago by giladehven.

    PHP: 7.4.33
    WP: 6.1.1 (multisite)
    SVG Support: 2.5.4

    Same issue with cli. Notice: Trying to access array offset on value of type null in /home/wildone2/public_html/wp-content/plugins/svg-support/functions/mime-types.php on line 22.

    I’m running PHP 8.1 and I also get the warning:

    PHP Warning: Trying to access array offset on value of type null in /wp-content/plugins/svg-support/functions/mime-types.php on line 22

    I can confirm this bug too:
    ? WP 6.1.1
    ? svg-support 2.5.4
    ? wp-cli: 2.7.1
    ? PHP version: 8.0.22

    I even had falsely reported the bug at the wp-cli issue tracker until I later realized the cause must be in the svg-plugin itself.

    • This reply was modified 1 year, 11 months ago by abitofmind.
    • This reply was modified 1 year, 11 months ago by abitofmind.
    Thread Starter giladehven

    (@giladehven)

    The plugin itself appears to be working, and we no longer have fatal errors, so this is now more of an irritation than a serious problem.

    That said, since we have multiple projects using this plugin, and since all of them make frequent use of WP-CLI for management and reporting, and since all our deployments are atomic (making hacky fixes impractical), this irritation is actually interfering with daily work.

    I don’t want to come across as ungrateful, this is a great plugin, but we do need to get past this problem to skip the constant clean up and I really don’t want to move to a different plugin…

    Can we have an ETA on a lasting fix?

    @all: On my WP 6.1.1 the plugin svg-support today received an update from 2.5.4 to 2.5.5 and its error messages when invoking wp-cli are now gone.

    The changelog for 2.5.5 says nothing specific, just “More error fixes and general clean up.”, buton my installation the problem is gone now.

    As I interpret @giladehven ‘s comment this seems to be a recurring bug. I hope for the best… Will report should I get this wp-cli error again.

    • This reply was modified 1 year, 11 months ago by abitofmind.
    • This reply was modified 1 year, 11 months ago by abitofmind.
Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Version 2.5.2 breaks WP-CLI’ is closed to new replies.