Merge remote-tracking branch 'refs/remotes/YahnisElsts/master'
This commit is contained in:
commit
8dcacbd823
|
|
@ -9,6 +9,8 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
/** @var PluginUpdateChecker */
|
||||
private $updateChecker;
|
||||
|
||||
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
||||
|
||||
public function __construct($updateChecker) {
|
||||
$this->updateChecker = $updateChecker;
|
||||
$title = sprintf(
|
||||
|
|
@ -26,8 +28,14 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
esc_attr(wp_create_nonce('puc-ajax'))
|
||||
);
|
||||
|
||||
$responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
||||
$this->displayConfiguration();
|
||||
$this->displayStatus();
|
||||
$this->displayCurrentUpdate();
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function displayConfiguration() {
|
||||
echo '<h3>Configuration</h3>';
|
||||
echo '<table class="puc-debug-data">';
|
||||
$this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
|
||||
|
|
@ -38,7 +46,7 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
if ( function_exists('get_submit_button') ) {
|
||||
$requestInfoButton = get_submit_button('Request Info', 'secondary', 'puc-request-info-button', false, array('id' => 'puc-request-info-button-' . $this->updateChecker->slug));
|
||||
}
|
||||
$this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $responseBox);
|
||||
$this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
|
||||
|
||||
if ( $this->updateChecker->checkPeriod > 0 ) {
|
||||
$this->row('Automatic checks', 'Every ' . $this->updateChecker->checkPeriod . ' hours');
|
||||
|
|
@ -61,7 +69,9 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
}
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
private function displayStatus() {
|
||||
echo '<h3>Status</h3>';
|
||||
echo '<table class="puc-debug-data">';
|
||||
$state = $this->updateChecker->getUpdateState();
|
||||
|
|
@ -71,7 +81,7 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
}
|
||||
|
||||
if ( isset($state, $state->lastCheck) ) {
|
||||
$this->row('Last check', $this->formatTimeWithDelta($state->lastCheck) . ' ' . $checkNowButton . $responseBox);
|
||||
$this->row('Last check', $this->formatTimeWithDelta($state->lastCheck) . ' ' . $checkNowButton . $this->responseBox);
|
||||
} else {
|
||||
$this->row('Last check', 'Never');
|
||||
}
|
||||
|
|
@ -85,7 +95,9 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
}
|
||||
$this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
private function displayCurrentUpdate() {
|
||||
$update = $this->updateChecker->getUpdate();
|
||||
if ( $update !== null ) {
|
||||
echo '<h3>An Update Is Available</h3>';
|
||||
|
|
@ -98,8 +110,6 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel {
|
|||
} else {
|
||||
echo '<h3>No updates currently available</h3>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function formatTimeWithDelta($unixTime) {
|
||||
|
|
|
|||
|
|
@ -1093,13 +1093,9 @@ class PluginInfo_2_3 {
|
|||
return null;
|
||||
}
|
||||
|
||||
//Very, very basic validation.
|
||||
$valid = isset($apiResponse->name, $apiResponse->version) && !empty($apiResponse->name) && !empty($apiResponse->version);
|
||||
if ( !$valid ){
|
||||
trigger_error(
|
||||
"The plugin metadata file does not contain the required 'name' and/or 'version' keys.",
|
||||
E_USER_NOTICE
|
||||
);
|
||||
$valid = self::validateMetadata($apiResponse);
|
||||
if ( is_wp_error($valid) ){
|
||||
trigger_error($valid->get_error_message(), E_USER_NOTICE);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -1113,6 +1109,27 @@ class PluginInfo_2_3 {
|
|||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Very, very basic validation.
|
||||
*
|
||||
* @param StdClass $apiResponse
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
protected static function validateMetadata($apiResponse) {
|
||||
if (
|
||||
!isset($apiResponse->name, $apiResponse->version)
|
||||
|| empty($apiResponse->name)
|
||||
|| empty($apiResponse->version)
|
||||
) {
|
||||
return new WP_Error(
|
||||
'puc-invalid-metadata',
|
||||
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transform plugin info into the format used by the native WordPress.org API
|
||||
|
|
|
|||
Loading…
Reference in New Issue