Support » Plugin: TablePress » Filter function for adding attribute scope to th won’t run

  • Resolved abrightclearweb

    (@abrightclearweb)


    Hi Tobias, thanks for this useful plugin.

    I was trying to add scope="col" to table headers, like rachitaora in this thread (https://wordpress.org/support/topic/tablepress-ada-accessibility/) and you very kindly provided the following code.

    function ada_tablepress_add_scope(  $tag_attributes, $table_id, $cell_content, $row_number, $col_number, $colspan, $rowspan ) {
        if ( $row_idx === 1 ) {
            $tag_attributes['scope'] = "col";
            return $tag_attributes;
        }
    }
    add_filter( 'tablepress_cell_tag_attributes', 'ada_tablepress_add_scope', 10, 7 );

    The only problem is that I get the following error when adding it:

    Fatal error: Uncaught TypeError: Argument 1 passed to TablePress_Render::_attributes_array_to_string() must be of the type array, null given, called in /app/public/wp-content/plugins/tablepress/classes/class-render.php on line 672 and defined in /app/public/wp-content/plugins/tablepress/classes/class-render.php:733 Stack trace: #0 /app/public/wp-content/plugins/tablepress/classes/class-render.php(672): TablePress_Render->_attributes_array_to_string(NULL) #1 /app/public/wp-content/plugins/tablepress/classes/class-render.php(371): TablePress_Render->_render_row(4, 'td') #2 /app/public/wp-content/plugins/tablepress/classes/class-render.php(135): TablePress_Render->_render_table() #3 /app/public/wp-content/plugins/tablepress/controllers/controller-frontend.php(645): TablePress_Render->get_output() #4 /app/public/wp-includes/shortcodes.php(325): TablePress_Frontend_Controller->shortcode_table(Array, '', 'table') #5 [internal function]: do_shortcode_tag(Array) #6 /app/public/wp-includes/shortcodes.php(199): preg_replace_callbac in /app/public/wp-content/plugins/tablepress/classes/class-render.php on line 733

    If I comment out the if statement in your code, it runs without error, but that adds scope="col" to all rows, which is not what I want.

    Do you know how to fix this error?

Viewing 1 replies (of 1 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.
    Also sorry for the late reply! As I was on holidays, I did not have a chance to look at this earlier.

    That code contains a bug. Please try again with

    function ada_tablepress_add_scope(  $tag_attributes, $table_id, $cell_content, $row_number, $col_number, $colspan, $rowspan ) {
        if ( $row_idx === 1 ) {
            $tag_attributes['scope'] = "col";
        }
        return $tag_attributes;
    }
    add_filter( 'tablepress_cell_tag_attributes', 'ada_tablepress_add_scope', 10, 7 );

    Regards,
    Tobias

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.