• Resolved legezam

    (@legezam)


    I have the following setup:
    php: 7.2.24-0ubuntu0.18.04.6
    wordpress: 5.4.2

    Opening the plugin management page in admin area throws this error:

    PHP Fatal error:  Uncaught Error: [] operator not supported for strings in /wp-content/plugins/easy-image-collage/helpers/plugin_action_link.php:12
    Stack trace:
    #0 /wp-includes/class-wp-hook.php(289): EIC_Plugin_Action_Link->action_links('<')
    #1 /wp-includes/plugin.php(206): WP_Hook->apply_filters('<', Array)
    #2 /wp-admin/includes/class-wp-plugins-list-table.php(826): apply_filters('plugin_action_l...', '<', 'easy-image-coll...', Array, 'search')
    #3 /wp-admin/includes/class-wp-plugins-list-table.php(605): WP_Plugins_List_Table->single_row(Array)
    #4 /wp-admin/includes/class-wp-list-table.php(1273): WP_Plugins_List_Table->display_rows()
    #5 /wp-admin/includes/class-wp-list-table.php(1204): WP_List_Table->display_rows_or_placeholder()
    #6 /var/www/html/v2/wp-admin/plugins.php(637): WP_List_Table->display()
    #7 {main}
    thrown in /wp-content/plugins/easy-image-collage/helpers/plugin_action_link.php on line 12

    It seems to be related to a recent change in php that handles [] operator differently: https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax.modifying (see notes)

    Line #12 throws the error:

    
    <?php
    
    class EIC_Plugin_Action_Link {
    
        public function __construct()
        {
            add_filter( 'plugin_action_links_' . EasyImageCollage::get()->corePath . '/easy-image-collage.php', array( $this, 'action_links' ) );
        }
    
        public function action_links( $links )
        {
            $links[] = '<a href="'. get_admin_url(null, 'options-general.php?page=eic_settings') .'">'.__( 'Settings', 'easy-image-collage' ).'</a>';
    
            return $links;
        }
    }%                 
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Brecht

    (@brechtvds)

    Actually, that $links variable should be an array and not a string, so doing $links[] is perfectly valid: https://codex.ww.wp.xz.cn/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)

    Most likely another plugin or your theme is incorrectly using that filter.

    Try disabling all other plugins for a second and see if you get the warning then.
    If not, try switching to a default theme (like Twenty Seventeen) and check again.

    Thread Starter legezam

    (@legezam)

    Hi Brecht,
    Thanks for the reply.
    Disabling plugins are not entirely possible unfortunately because this error breaks the display of plugins on the plugins admin section. Therefore I could disable only those plugins that were loaded successfully in the table before the image collage plugin. No change when doing that.

    Reverted back to the factory default theme, no change.

    The only positive result i saw is when commented out out the 12nd line in the above file which seems to fix all the issues. WordPress is not complaining for anything and the plugin table displays everything perfectly in the admin area.

    Plugin Author Brecht

    (@brechtvds)

    Commenting out that line will indeed get rid of the error but not of what’s causing it.

    You can confirm we’re pretty much using the exact example of the documentation (the second one):
    https://codex.ww.wp.xz.cn/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)

    The error is [] operator not supported for strings which means the $links our plugin gets passed through is a string so something else is making that a string and that something else (most likely another plugin) is the one causing the problem.

    If you deactivate Easy Image Collage for a second (or comment out that line), then deactivate all other plugins and activate EIC again, you should find the error is not there anymore. Then you can activate plugins one by one until it stops working.

    Thread Starter legezam

    (@legezam)

    indeed, thanks for the advice!

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

The topic ‘Plugin throws error due to recent changes in php 7’ is closed to new replies.