From 4076ba0f29c6561582b80e718eaa6c72c346b90e Mon Sep 17 00:00:00 2001 From: dikiyforester Date: Sat, 4 Apr 2020 13:21:38 +0500 Subject: [PATCH 1/2] Don't use deprecated hook 'contextual_help' --- AdminPage.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/AdminPage.php b/AdminPage.php index 7eb4c3b..fb0be04 100644 --- a/AdminPage.php +++ b/AdminPage.php @@ -135,7 +135,7 @@ public function __construct( $file = false, $options = null ) { } add_action( 'admin_menu', array( $this, 'page_init' ), $this->args['admin_action_priority'] ); - add_filter( 'contextual_help', array( $this, '_contextual_help' ), 10, 2 ); + add_action( 'current_screen', array( $this, '_contextual_help' ) ); if ( $file ) { $this->file = $file; @@ -534,23 +534,17 @@ private function check_args() { /** * Adds contextual help. * - * @param string $help - * @param string|object $screen + * @param WP_Screen $screen * * @return string */ - public function _contextual_help( $help, $screen ) { - if ( is_object( $screen ) ) { - $screen = $screen->id; - } + public function _contextual_help( $screen ) { $actual_help = $this->page_help(); - if ( $screen == $this->pagehook && $actual_help ) { - return $actual_help; + if ( $screen->id == $this->pagehook && $actual_help ) { + $screen::add_old_compat_help( $screen, $actual_help ); } - - return $help; } /** From 383690d39106b36f7ff03c2380b0dc48833d46d9 Mon Sep 17 00:00:00 2001 From: dikiyforester Date: Sat, 4 Apr 2020 13:59:20 +0500 Subject: [PATCH 2/2] Better compatibility with scbAdminPage subclasses that implement _contextual_help() method. --- AdminPage.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/AdminPage.php b/AdminPage.php index fb0be04..f4fb7f2 100644 --- a/AdminPage.php +++ b/AdminPage.php @@ -135,7 +135,7 @@ public function __construct( $file = false, $options = null ) { } add_action( 'admin_menu', array( $this, 'page_init' ), $this->args['admin_action_priority'] ); - add_action( 'current_screen', array( $this, '_contextual_help' ) ); + add_action( 'current_screen', array( $this, '_contextual_help_compat' ) ); if ( $file ) { $this->file = $file; @@ -534,14 +534,34 @@ private function check_args() { /** * Adds contextual help. * - * @param WP_Screen $screen + * @param string $help + * @param string|object $screen * * @return string */ - public function _contextual_help( $screen ) { + public function _contextual_help( $help, $screen ) { + if ( is_object( $screen ) ) { + $screen = $screen->id; + } $actual_help = $this->page_help(); + if ( $screen == $this->pagehook && $actual_help ) { + return $actual_help; + } + + return $help; + } + + /** + * Sets the old string-based contextual help for the screen for backward compatibility. + * + * @param WP_Screen $screen + */ + public function _contextual_help_compat( $screen ) { + + $actual_help = $this->_contextual_help( '', $screen ); + if ( $screen->id == $this->pagehook && $actual_help ) { $screen::add_old_compat_help( $screen, $actual_help ); }