• efc

    (@eceleste)


    I am still getting the fatal error others have noted with v.2.5.3, which was meant to fix this error.

    [16-Nov-2022 14:48:08 UTC] PHP Warning:  Trying to access array offset on value of type null in /sites/new.teamrcia.com/files/wp-content/plugins/svg-support/functions/mime-types.php on line 22
    [16-Nov-2022 14:48:08 UTC] PHP Fatal error:  Uncaught TypeError: array_intersect(): Argument #1 ($array) must be of type array, null given in /sites/new.teamrcia.com/files/wp-content/plugins/svg-support/functions/mime-types.php:28
    Stack trace:
    #0 /sites/new.teamrcia.com/files/wp-content/plugins/svg-support/functions/mime-types.php(28): array_intersect()
    #1 /sites/new.teamrcia.com/files/wp-includes/class-wp-hook.php(310): bodhi_svgs_upload_mimes()
    #2 /sites/new.teamrcia.com/files/wp-includes/plugin.php(205): WP_Hook->apply_filters()
    #3 /sites/new.teamrcia.com/files/wp-includes/functions.php(3546): apply_filters()
    #4 /sites/new.teamrcia.com/files/wp-includes/block-editor.php(216): get_allowed_mime_types()
    #5 /sites/new.teamrcia.com/files/wp-includes/class-wp-theme-json-resolver.php(297): get_default_block_editor_settings()
    #6 /sites/new.teamrcia.com/files/wp-includes/class-wp-theme-json-resolver.php(561): WP_Theme_JSON_Resolver::get_theme_data()
    #7 /sites/new.teamrcia.com/files/wp-includes/script-loader.php(3205): WP_Theme_JSON_Resolver::get_merged_data()
    #8 /sites/new.teamrcia.com/files/wp-includes/script-loader.php(3401): {closure}()
    #9 /sites/new.teamrcia.com/files/wp-includes/class-wp-hook.php(308): {closure}()
    #10 /sites/new.teamrcia.com/files/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
    #11 /sites/new.teamrcia.com/files/wp-includes/plugin.php(517): WP_Hook->do_action()
    #12 /sites/new.teamrcia.com/files/wp-settings.php(639): do_action()
    #13 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1317): require('...')
    #14 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1235): WP_CLI\Runner->load_wordpress()
    #15 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
    #16 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process()
    #17 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
    #18 phar:///usr/local/bin/wp/php/boot-phar.php(11): include('...')
    #19 /usr/local/bin/wp(4): include('...')
    #20 {main}
      thrown in /sites/new.teamrcia.com/files/wp-content/plugins/svg-support/functions/mime-types.php on line 28
Viewing 12 replies - 1 through 12 (of 12 total)
  • 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;
    }

    Mabio

    David

    (@dkomando)

    To Simplify where the error is occurring (line 28):
    PHP Warning: array_intersect(): Expected parameter 1 to be an array, null given in /var/www/example.com/example_prod/wp-content/plugins/svg-support/functions/mime-types.php on line 28

    However, the problem is really with line 22.
    When running WP-CLI, the variable $bodhi_svgs_options[‘restrict’] is null. And line 28’s array_intersect() parameter 1 is then null, which is throwing the error.

    For me I changed line 22 to actually check and set $allowed_roles_array properly.

    Fix:
    $allowed_roles_array = ( is_array( $bodhi_svgs_options ) && ! empty( $bodhi_svgs_options['restrict'] ) ) ? $bodhi_svgs_options['restrict'] : array();

    Additionally:
    I commented out line 19 since its no longer doing anything.
    e.g.
    // $allowed_roles_array = array();

    After implementing the above code, I verified “SVG Support” doesn’t throw errors in WP-CLI and I verified as an admin that I was able to upload an SVG.

    Hope this helps.

    So, actually I think this is PHP 8 related. As we upgraded to the latest release of this plugin yesterday and it wasn’t having an issue, however, as of today when we upgraded some infrastructure to PHP 8 this error started occurring.

    fidoboy

    (@fidoboy)

    In my case it happens with PHP 8.1 and it was working fine, without errors, in previous version running the same PHP version.

    @fidoboy well, I just confirmed that this version of the plugin doesn’t have a problem on PHP 7.4, but does have a problem on PHP 8.0. So this is a PHP 8.x related issue.

    David

    (@dkomando)

    The error still exists in latest SVG Support v2.5.4.

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

    While casting this value $allowed_roles_array = (array) $bodhi_svgs_options[‘restrict’]; to an array works. The problem is you’re attempting to fix an item in a global variable that is null (e.g. $bodhi_svgs_options).

    So, I’m guessing you would want to verify your global is actually an array or just check for a $user->ID like @mabioneto did right after your global or both.

    
    	global $bodhi_svgs_options;
    
    	if ( 0 === $user->ID || ! is_array( $bodhi_svgs_options ) ) {
    		return $mimes;
    	}
    
    • This reply was modified 2 years ago by David.
    • This reply was modified 2 years ago by David.

    This is occurring on php 7.4 as well (using plugin version 2.5.4).

    It seems that the global $bodhi_svgs_options variable is null within svg-support/functions/mime-types.php (function bodhi_svgs_upload_mimes).

    A potential fix would be to reload the plugin options instead of using the global variable using $bodhi_svgs_options = get_option('bodhi_svgs_settings');

    @dkomando your code snippet worked thanks. got me going until I have to upgrade something lol

    @benbodhi ^^^ this is the most helpful thread on this issue

    • This reply was modified 1 year, 12 months ago by sirjeff.

    @dwaynepivac Glad it helped you out.

    Also, I want to add that PHP 7.4 as of a couple days ago, has been retired. So being compatible with PHP 8.+ would probably be a very good thing.
    https://www.php.net/supported-versions.php

    Thread Starter efc

    (@eceleste)

    I believe that version 2.5.5 has resolved this issue for me. Can anyone else confirm that this issues is now resolved?

    It seems to be resolved for me as well. Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Still getting fatal PHP error with 2.5.3’ is closed to new replies.