From 148a6ce4b2192999e33eae672ced64a8a08921e5 Mon Sep 17 00:00:00 2001 From: Giuseppe Foti Date: Wed, 7 Feb 2024 01:25:49 +0100 Subject: [PATCH] Fix undefined screen for WP_List_Table in WP < 6.1 Signed-off-by: Giuseppe Foti --- .gitignore | 5 ++++- .../class-gcmi-remote-files-list-table.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index caa92b0..97455ab 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ phpcs.xml node_modules npm-debug.log docs +coverage +coverage-html .sass-cache -/.phpunit.result.cache +.phpunit.result.cache +tests/phpunit/.phpunit.result.cache phpstan.neon \ No newline at end of file diff --git a/admin/includes/class-gcmi-remote-files-list-table.php b/admin/includes/class-gcmi-remote-files-list-table.php index 568e86c..c16744d 100644 --- a/admin/includes/class-gcmi-remote-files-list-table.php +++ b/admin/includes/class-gcmi-remote-files-list-table.php @@ -24,10 +24,24 @@ */ class Gcmi_Remote_Files_List extends WP_List_Table { - /** Class constructor */ + /** + * Class constructor + */ public function __construct() { + // necessario per WP < 6.1, see: https://core.trac.wordpress.org/changeset/54414 . + if ( is_null( get_current_screen() ) ) { + set_current_screen( 'admin.php' ); + } + $screen = get_current_screen(); + if ( ! is_null( $screen ) ) { + $screen_id = $screen->id; + } else { + $screen_id = 'admin.php'; + } parent::__construct( array( + // necessario per WP < 6.1 . + 'screen' => $screen_id, 'singular' => 'fname', // singular name of the listed records. 'plural' => 'fnames', // plural name of the listed records. 'ajax' => false, // should this table support ajax?