From 97dfe23d158b8af0ea3f7652e678688da6e52e51 Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Wed, 20 Mar 2024 18:33:33 +0200 Subject: [PATCH] Debug Bar: Display "Check Now" and "Request Info" in front end By default, these buttons are generated using the get_submit_button() API function, but that function is only available in the admin dashboard (unless explicitly loaded). Previously, the buttons were not shown in the front end. This patch adds a fallback that generates the buttons directly. These won't look exactly the same as admin buttons due to admin styles not being loaded, and WP may change submit button HTML at some point, but the fallback buttons should still work. Fixes #568 --- Puc/v5p4/DebugBar/Panel.php | 12 ++++++++++-- Puc/v5p4/DebugBar/PluginPanel.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Puc/v5p4/DebugBar/Panel.php b/Puc/v5p4/DebugBar/Panel.php index b846277..750408f 100644 --- a/Puc/v5p4/DebugBar/Panel.php +++ b/Puc/v5p4/DebugBar/Panel.php @@ -86,14 +86,22 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false echo '

Status

'; echo ''; $state = $this->updateChecker->getUpdateState(); - $checkNowButton = ''; + $checkButtonId = $this->updateChecker->getUniqueName('check-now-button'); if ( function_exists('get_submit_button') ) { $checkNowButton = get_submit_button( 'Check Now', 'secondary', 'puc-check-now-button', false, - array('id' => $this->updateChecker->getUniqueName('check-now-button')) + array('id' => $checkButtonId) + ); + } else { + //get_submit_button() is not available in the frontend. Make a button directly. + //It won't look the same without admin styles, but it should still work. + $checkNowButton = sprintf( + '', + esc_attr($checkButtonId), + esc_attr('Check Now') ); } diff --git a/Puc/v5p4/DebugBar/PluginPanel.php b/Puc/v5p4/DebugBar/PluginPanel.php index 4c1d230..cbf39b9 100644 --- a/Puc/v5p4/DebugBar/PluginPanel.php +++ b/Puc/v5p4/DebugBar/PluginPanel.php @@ -17,14 +17,20 @@ if ( !class_exists(PluginPanel::class, false) ): } protected function getMetadataButton() { - $requestInfoButton = ''; + $buttonId = $this->updateChecker->getUniqueName('request-info-button'); if ( function_exists('get_submit_button') ) { $requestInfoButton = get_submit_button( 'Request Info', 'secondary', 'puc-request-info-button', false, - array('id' => $this->updateChecker->getUniqueName('request-info-button')) + array('id' => $buttonId) + ); + } else { + $requestInfoButton = sprintf( + '', + esc_attr($buttonId), + esc_attr('Request Info') ); } return $requestInfoButton;