php-cli-tools icon indicating copy to clipboard operation
php-cli-tools copied to clipboard

Broken table layout when reporting WordPress vulnerabilities.

Open oscarssanchez opened this issue 5 years ago • 4 comments

Hi,

Running wp vuln status through WordPress 4.9.6 breaks the table layout when the package reports any vulnerabilities with WordPress version (not plugins, not themes. See screenshots).

Expected behavior:

Table layout is not broken. Expected to see the same layout as it is with the reports of plugins and themes.

Current behavior:

The table layout breaks.

Steps to reproduce:

Run wp-vulnerability scanner through a WordPress 4.9.6 install 1.- wp vuln status

WP-CLI version: 2.0.0-alpha-2646dac

Screenshots:

Layout broken when reporting problems with WordPress 4.9.6: vuln1

Layout is fine when reporting no vulnerabilities with WordPress 4.9.7 vuln2

It seems like it has been a recurring issue (https://github.com/wp-cli/php-cli-tools/issues/106)

Thank you!

oscarssanchez avatar Jul 24 '18 16:07 oscarssanchez

@oscarssanchez This issue was fixed, however we couldn't fixed it in a general way without breaking backwards-compat.

That's why you need to use the second argument to display_items() to make this work.

If you pass all of your columns through WP_CLI::colorize(), then pass true as the second argument to display_items().

If you pass only select columns through WP_CLI::colorize(), then pass an array of booleans to display_items(), with each boolean denoting whether the respective column is using WP_CLI::colorize().

So, for example, if you have 4 columns and only the first one is passed through WP_CLI::colorize(), then use array( true, false, false, false ) as the second argument to display_items().

Please let me know if that helps resolve the issue.

schlessera avatar Aug 21 '18 17:08 schlessera

@schlessera The new function to display a table seems to now be \WP_CLI\Utils\format_items so how do we address this with that function? The third param seems to just take in the column names

\WP_CLI\Utils\format_items( 'table', $items, array( 'module', 'key', 'status' ) );

UVLabs avatar Oct 26 '21 20:10 UVLabs

@schlessera I encountered the same issue as @UVLabs and would like to know if there is a solution or a workaround.

alexisferat avatar Mar 09 '22 13:03 alexisferat

@UVLabs @alexisferat Use a custom table registration instead of a generic \WP_CLI\Utils\format_items( 'table', $items ):

$table  = new \cli\Table();
$ascii  = new \cli\table\Ascii( [
	Colors::width( 'value 1', true ),
	Colors::width( 'value 2', false ),
	Colors::width( 'value 3', false )
] );

$ascii->setWidths( $widths );
$table->setRenderer( $ascii );

$table->setHeaders( [ 'module', 'key', 'status' ] );

$table->addRows( [ $rows ] );

$table->display();

slaFFik avatar Sep 28 '23 22:09 slaFFik