Compare commits
75 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
68a70bf887 | |
|
|
36f3c2be5b | |
|
|
4f87723b6a | |
|
|
07a4c2586f | |
|
|
572bfe0986 | |
|
|
288f270d8e | |
|
|
69d30a9c17 | |
|
|
8add8143a2 | |
|
|
5dfd5e5d1e | |
|
|
e39f84488e | |
|
|
dbe1a66274 | |
|
|
b2cbbd98dd | |
|
|
60ec73fddc | |
|
|
a2db6871de | |
|
|
dc93f32388 | |
|
|
9f890f5cfd | |
|
|
46ee454f68 | |
|
|
73e6281e43 | |
|
|
8f54e73dea | |
|
|
845d65da93 | |
|
|
c74a3bcde2 | |
|
|
70f3c80c81 | |
|
|
8d785d75ac | |
|
|
dce70db088 | |
|
|
93a17f984c | |
|
|
7c907e7629 | |
|
|
ea8de31ebd | |
|
|
a622b0047a | |
|
|
cc5c8d9eca | |
|
|
dfc396c011 | |
|
|
432e7d5f1a | |
|
|
668e416c98 | |
|
|
1dd70e99f0 | |
|
|
3b1becb956 | |
|
|
1a040ee4bb | |
|
|
040a2ef658 | |
|
|
97dfe23d15 | |
|
|
e8e53e6d98 | |
|
|
1ee425c37b | |
|
|
a1445bb8dc | |
|
|
36efab0022 | |
|
|
a211943884 | |
|
|
c1bf33e770 | |
|
|
0a8fd4ad3a | |
|
|
5f251be064 | |
|
|
9c1bddcd46 | |
|
|
0b6bd7cd32 | |
|
|
90e055ecd3 | |
|
|
00774ef3d9 | |
|
|
0f7296123e | |
|
|
b9aa17be21 | |
|
|
5a270988c5 | |
|
|
565a071b59 | |
|
|
ad59ffe9a3 | |
|
|
48b03e93c9 | |
|
|
98f17e4d14 | |
|
|
8e2e6a3b34 | |
|
|
fcf85abaec | |
|
|
ddce4cd388 | |
|
|
53535fd83a | |
|
|
10404db947 | |
|
|
345778385c | |
|
|
eddade3ebb | |
|
|
01c1565344 | |
|
|
579d537926 | |
|
|
a42e1e7346 | |
|
|
ebf5bc21a0 | |
|
|
573467a543 | |
|
|
c86ce6ef9f | |
|
|
7457e85680 | |
|
|
75c05617ec | |
|
|
2fb701089d | |
|
|
304020175d | |
|
|
c4bf64eca4 | |
|
|
affb44665f |
|
|
@ -0,0 +1,6 @@
|
|||
/.editorconfig export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/build/ export-ignore
|
||||
/examples/ export-ignore
|
||||
/phpcs.xml export-ignore
|
||||
|
|
@ -4,7 +4,7 @@ namespace YahnisElsts\PluginUpdateChecker\v5;
|
|||
|
||||
if ( !class_exists(PucFactory::class, false) ):
|
||||
|
||||
class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p0\PucFactory {
|
||||
class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p6\PucFactory {
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(Autoloader::class, false) ):
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\PucFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\PucFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\UpdateChecker;
|
||||
|
||||
if ( !class_exists(Extension::class, false) ):
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\UpdateChecker;
|
||||
|
||||
if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false) ):
|
||||
|
||||
|
|
@ -41,11 +41,11 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
echo '<h3>Configuration</h3>';
|
||||
echo '<table class="puc-debug-data">';
|
||||
$this->displayConfigHeader();
|
||||
$this->row('Slug', htmlentities($this->updateChecker->slug));
|
||||
$this->row('DB option', htmlentities($this->updateChecker->optionName));
|
||||
$this->row('Slug', esc_html($this->updateChecker->slug));
|
||||
$this->row('DB option', esc_html($this->updateChecker->optionName));
|
||||
|
||||
$requestInfoButton = $this->getMetadataButton();
|
||||
$this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
|
||||
$this->row('Metadata URL', esc_html($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
|
||||
|
||||
$scheduler = $this->updateChecker->scheduler;
|
||||
if ( $scheduler->checkPeriod > 0 ) {
|
||||
|
|
@ -86,14 +86,22 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
echo '<h3>Status</h3>';
|
||||
echo '<table class="puc-debug-data">';
|
||||
$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(
|
||||
'<input type="button" id="%1$s" name="puc-check-now-button" value="%2$s" class="button button-secondary" />',
|
||||
esc_attr($checkButtonId),
|
||||
esc_attr('Check Now')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -107,10 +115,10 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
$this->row('Next automatic check', $this->formatTimeWithDelta($nextCheck));
|
||||
|
||||
if ( $state->getCheckedVersion() !== '' ) {
|
||||
$this->row('Checked version', htmlentities($state->getCheckedVersion()));
|
||||
$this->row('Checked version', esc_html($state->getCheckedVersion()));
|
||||
$this->row('Cached update', $state->getUpdate());
|
||||
}
|
||||
$this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
|
||||
$this->row('Update checker class', esc_html(get_class($this->updateChecker)));
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +132,7 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
if ( property_exists($update, $field) ) {
|
||||
$this->row(
|
||||
ucwords(str_replace('_', ' ', $field)),
|
||||
isset($update->$field) ? htmlentities($update->$field) : null
|
||||
isset($update->$field) ? esc_html($update->$field) : null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -160,11 +168,18 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
|
||||
public function row($name, $value) {
|
||||
if ( is_object($value) || is_array($value) ) {
|
||||
$value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
|
||||
//This is specifically for debugging, so print_r() is fine.
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
||||
$value = '<pre>' . esc_html(print_r($value, true)) . '</pre>';
|
||||
} else if ($value === null) {
|
||||
$value = '<code>null</code>';
|
||||
}
|
||||
printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
|
||||
printf(
|
||||
'<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>',
|
||||
esc_html($name),
|
||||
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above.
|
||||
$value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin\UpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin\UpdateChecker;
|
||||
|
||||
if ( !class_exists(PluginExtension::class, false) ):
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin\UpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin\UpdateChecker;
|
||||
|
||||
if ( !class_exists(PluginPanel::class, false) ):
|
||||
|
||||
|
|
@ -12,19 +12,25 @@ if ( !class_exists(PluginPanel::class, false) ):
|
|||
protected $updateChecker;
|
||||
|
||||
protected function displayConfigHeader() {
|
||||
$this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
|
||||
$this->row('Plugin file', esc_html($this->updateChecker->pluginFile));
|
||||
parent::displayConfigHeader();
|
||||
}
|
||||
|
||||
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(
|
||||
'<input type="button" name="puc-request-info-button" id="%1$s" value="%2$s" class="button button-secondary" />',
|
||||
esc_attr($buttonId),
|
||||
esc_attr('Request Info')
|
||||
);
|
||||
}
|
||||
return $requestInfoButton;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Theme\UpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Theme\UpdateChecker;
|
||||
|
||||
if ( !class_exists(ThemePanel::class, false) ):
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ if ( !class_exists(ThemePanel::class, false) ):
|
|||
protected $updateChecker;
|
||||
|
||||
protected function displayConfigHeader() {
|
||||
$this->row('Theme directory', htmlentities($this->updateChecker->directoryName));
|
||||
$this->row('Theme directory', esc_html($this->updateChecker->directoryName));
|
||||
parent::displayConfigHeader();
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(InstalledPackage::class, false) ):
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use LogicException;
|
||||
use stdClass;
|
||||
|
|
@ -15,6 +15,12 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
* @access public
|
||||
*/
|
||||
abstract class Metadata {
|
||||
/**
|
||||
* Additional dynamic properties, usually copied from the API response.
|
||||
*
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
protected $extraProperties = array();
|
||||
|
||||
/**
|
||||
* Create an instance of this class from a JSON document.
|
||||
|
|
@ -135,6 +141,22 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
protected function getPrefixedFilter($tag) {
|
||||
return 'puc_' . $tag;
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
$this->extraProperties[$name] = $value;
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
return isset($this->extraProperties[$name]) ? $this->extraProperties[$name] : null;
|
||||
}
|
||||
|
||||
public function __isset($name) {
|
||||
return isset($this->extraProperties[$name]);
|
||||
}
|
||||
|
||||
public function __unset($name) {
|
||||
unset($this->extraProperties[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(OAuthSignature::class, false) ):
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\PucFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\PucFactory;
|
||||
|
||||
if ( !class_exists(Package::class, false) ):
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ if ( !class_exists(Package::class, false) ):
|
|||
//This can happen if the filename points to something that is not a plugin.
|
||||
$this->updateChecker->triggerError(
|
||||
sprintf(
|
||||
"Can't to read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
||||
"Cannot read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
||||
$this->updateChecker->pluginFile
|
||||
),
|
||||
E_USER_WARNING
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Metadata;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Metadata;
|
||||
|
||||
if ( !class_exists(PluginInfo::class, false) ):
|
||||
|
||||
|
|
@ -39,6 +39,7 @@ if ( !class_exists(PluginInfo::class, false) ):
|
|||
public $downloaded;
|
||||
public $active_installs;
|
||||
public $last_updated;
|
||||
public $autoupdate = false;
|
||||
|
||||
public $id = 0; //The native WP.org API returns numeric plugin IDs, but they're not used for anything.
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
if ( !class_exists('Ui', false) ):
|
||||
if ( !class_exists(Ui::class, false) ):
|
||||
/**
|
||||
* Additional UI elements for plugins.
|
||||
*/
|
||||
|
|
@ -187,7 +187,7 @@ if ( !class_exists('Ui', false) ):
|
|||
}
|
||||
}
|
||||
|
||||
wp_redirect(add_query_arg(
|
||||
wp_safe_redirect(add_query_arg(
|
||||
array(
|
||||
'puc_update_check_result' => $status,
|
||||
'puc_slug' => $this->updateChecker->slug,
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Update as BaseUpdate;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Update as BaseUpdate;
|
||||
|
||||
if ( !class_exists(Update::class, false) ):
|
||||
|
||||
|
|
@ -20,9 +20,10 @@ if ( !class_exists(Update::class, false) ):
|
|||
public $requires_php = false;
|
||||
public $icons = array();
|
||||
public $filename; //Plugin filename relative to the plugins directory.
|
||||
public $autoupdate = false;
|
||||
|
||||
protected static $extraFields = array(
|
||||
'id', 'homepage', 'tested', 'requires_php', 'upgrade_notice', 'icons', 'filename',
|
||||
'id', 'homepage', 'tested', 'requires_php', 'upgrade_notice', 'icons', 'filename', 'autoupdate',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -86,6 +87,7 @@ if ( !class_exists(Update::class, false) ):
|
|||
$update->tested = $this->tested;
|
||||
$update->requires_php = $this->requires_php;
|
||||
$update->plugin = $this->filename;
|
||||
$update->autoupdate = $this->autoupdate;
|
||||
|
||||
if ( !empty($this->upgrade_notice) ) {
|
||||
$update->upgrade_notice = $this->upgrade_notice;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker as BaseUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Scheduler;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\UpdateChecker as BaseUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Scheduler;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
if ( !class_exists(UpdateChecker::class, false) ):
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*/
|
||||
class UpdateChecker extends BaseUpdateChecker {
|
||||
protected $updateTransient = 'update_plugins';
|
||||
protected $translationType = 'plugin';
|
||||
protected $componentType = 'plugin';
|
||||
|
||||
public $pluginAbsolutePath = ''; //Full path of the main plugin file.
|
||||
public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !class_exists(PucFactory::class, false) ):
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
throw new \RuntimeException(sprintf(
|
||||
'The update checker cannot determine if "%s" is a plugin or a theme. ' .
|
||||
'This is a bug. Please contact the PUC developer.',
|
||||
htmlentities($fullPath)
|
||||
esc_html($fullPath)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
*
|
||||
* Normalize a filesystem path. Introduced in WP 3.9.
|
||||
* Copying here allows use of the class on earlier versions.
|
||||
* This version adapted from WP 4.8.2 (unchanged since 4.5.0)
|
||||
* This version adapted from WP 4.8.2 (unchanged since 4.5.6)
|
||||
*
|
||||
* @param string $path Path to normalize.
|
||||
* @return string Normalized path.
|
||||
|
|
@ -239,7 +239,7 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
|
||||
//URI was not found so throw an error.
|
||||
throw new \RuntimeException(
|
||||
sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath))
|
||||
sprintf('Unable to locate URI in header of "%s"', esc_html($fullPath))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(Scheduler::class, false) ):
|
||||
|
||||
|
|
@ -49,6 +49,7 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
} else {
|
||||
//Use a custom cron schedule.
|
||||
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
||||
//phpcs:ignore WordPress.WP.CronInterval.ChangeDetected -- WPCS fails to parse the callback.
|
||||
add_filter('cron_schedules', array($this, '_addCustomSchedule'));
|
||||
}
|
||||
|
||||
|
|
@ -79,12 +80,14 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
//Like WordPress itself, we check more often on certain pages.
|
||||
/** @see wp_update_plugins */
|
||||
add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
|
||||
//phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- Not actually code, just file names.
|
||||
//"load-update.php" and "load-plugins.php" or "load-themes.php".
|
||||
$this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
|
||||
foreach($this->hourlyCheckHooks as $hook) {
|
||||
add_action($hook, array($this, 'maybeCheckForUpdates'));
|
||||
}
|
||||
//This hook fires after a bulk update is complete.
|
||||
add_action('upgrader_process_complete', array($this, 'removeHooksIfLibraryGone'), 1, 0);
|
||||
add_action('upgrader_process_complete', array($this, 'upgraderProcessComplete'), 11, 2);
|
||||
|
||||
} else {
|
||||
|
|
@ -93,6 +96,22 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all hooks if this version of PUC has been deleted or overwritten.
|
||||
*
|
||||
* Callback for the "upgrader_process_complete" action.
|
||||
*/
|
||||
public function removeHooksIfLibraryGone() {
|
||||
//Cancel all further actions if the current version of PUC has been deleted or overwritten
|
||||
//by a different version during the upgrade. If we try to do anything more in that situation,
|
||||
//we could trigger a fatal error by trying to autoload a deleted class.
|
||||
clearstatcache();
|
||||
if ( !file_exists(__FILE__) ) {
|
||||
$this->removeHooks();
|
||||
$this->updateChecker->removeHooks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs upon the WP action upgrader_process_complete.
|
||||
*
|
||||
|
|
@ -106,16 +125,6 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
/** @noinspection PhpUnusedParameterInspection */
|
||||
$upgrader, $upgradeInfo
|
||||
) {
|
||||
//Cancel all further actions if the current version of PUC has been deleted or overwritten
|
||||
//by a different version during the upgrade. If we try to do anything more in that situation,
|
||||
//we could trigger a fatal error by trying to autoload a deleted class.
|
||||
clearstatcache();
|
||||
if ( !file_exists(__FILE__) ) {
|
||||
$this->removeHooks();
|
||||
$this->updateChecker->removeHooks();
|
||||
return;
|
||||
}
|
||||
|
||||
//Sanity check and limitation to relevant types.
|
||||
if (
|
||||
!is_array($upgradeInfo) || !isset($upgradeInfo['type'], $upgradeInfo['action'])
|
||||
|
|
@ -178,6 +187,21 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
$state = $this->updateChecker->getUpdateState();
|
||||
$shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
|
||||
|
||||
if ( $shouldCheck ) {
|
||||
//Sanity check: Do not proceed if one of the critical classes is missing.
|
||||
//That can happen - theoretically and extremely rarely - if maybeCheckForUpdates()
|
||||
//is called before the old version of our plugin has been fully deleted, or
|
||||
//called from an independent AJAX request during deletion.
|
||||
if ( !(
|
||||
class_exists(Utils::class)
|
||||
&& class_exists(Metadata::class)
|
||||
&& class_exists(Plugin\Update::class)
|
||||
&& class_exists(Theme\Update::class)
|
||||
) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Let plugin authors substitute their own algorithm.
|
||||
$shouldCheck = apply_filters(
|
||||
$this->updateChecker->getUniqueName('check_now'),
|
||||
|
|
@ -208,7 +232,7 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
//Check less frequently if it's already known that an update is available.
|
||||
$period = $this->throttledCheckPeriod * 3600;
|
||||
} else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
|
||||
//WordPress cron schedules are not exact, so lets do an update check even
|
||||
//WordPress cron schedules are not exact, so let's do an update check even
|
||||
//if slightly less than $checkPeriod hours have elapsed since the last check.
|
||||
$cronFuzziness = 20 * 60;
|
||||
$period = $this->checkPeriod * 3600 - $cronFuzziness;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(StateStore::class, false) ):
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
* @param Update|null $update
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdate(Update $update = null) {
|
||||
public function setUpdate($update = null) {
|
||||
$this->lazyLoad();
|
||||
$this->update = $update;
|
||||
return $this;
|
||||
|
|
@ -163,7 +163,12 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
|
||||
$state = get_site_option($this->optionName, null);
|
||||
|
||||
if ( !is_object($state) ) {
|
||||
if (
|
||||
!is_object($state)
|
||||
//Sanity check: If the Utils class is missing, the plugin is probably in the process
|
||||
//of being deleted (e.g. the old version gets deleted during an update).
|
||||
|| !class_exists(Utils::class)
|
||||
) {
|
||||
$this->lastCheck = 0;
|
||||
$this->checkedVersion = '';
|
||||
$this->update = null;
|
||||
|
|
@ -185,8 +190,9 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
$updateClass = $state->updateClass;
|
||||
}
|
||||
|
||||
if ( ($updateClass !== null) && class_exists($updateClass) ) {
|
||||
$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
|
||||
$factory = array($updateClass, 'fromObject');
|
||||
if ( ($updateClass !== null) && is_callable($factory) ) {
|
||||
$this->update = call_user_func($factory, $state->update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\InstalledPackage;
|
||||
|
||||
if ( !class_exists(Package::class, false) ):
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Update as BaseUpdate;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Update as BaseUpdate;
|
||||
|
||||
if ( !class_exists(Update::class, false) ):
|
||||
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker as BaseUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Scheduler;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\UpdateChecker as BaseUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Scheduler;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
if ( !class_exists(UpdateChecker::class, false) ):
|
||||
|
||||
class UpdateChecker extends BaseUpdateChecker {
|
||||
protected $filterSuffix = 'theme';
|
||||
protected $updateTransient = 'update_themes';
|
||||
protected $translationType = 'theme';
|
||||
protected $componentType = 'theme';
|
||||
|
||||
/**
|
||||
* @var string Theme directory name.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use stdClass;
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use stdClass;
|
||||
use WP_Error;
|
||||
|
|
@ -9,7 +9,16 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
abstract class UpdateChecker {
|
||||
protected $filterSuffix = '';
|
||||
protected $updateTransient = '';
|
||||
protected $translationType = ''; //"plugin" or "theme".
|
||||
|
||||
/**
|
||||
* @var string This can be "plugin" or "theme".
|
||||
*/
|
||||
protected $componentType = '';
|
||||
/**
|
||||
* @var string Currently the same as $componentType, but this is an implementation detail that
|
||||
* depends on how WP works internally, and could therefore change.
|
||||
*/
|
||||
protected $translationType = '';
|
||||
|
||||
/**
|
||||
* Set to TRUE to enable error reporting. Errors are raised using trigger_error()
|
||||
|
|
@ -74,6 +83,11 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*/
|
||||
protected $debugBarExtension = null;
|
||||
|
||||
/**
|
||||
* @var WpCliCheckTrigger|null
|
||||
*/
|
||||
protected $wpCliCheckTrigger = null;
|
||||
|
||||
public function __construct($metadataUrl, $directoryName, $slug = null, $checkPeriod = 12, $optionName = '') {
|
||||
$this->debugMode = (bool)(constant('WP_DEBUG'));
|
||||
$this->metadataUrl = $metadataUrl;
|
||||
|
|
@ -91,6 +105,10 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
}
|
||||
|
||||
if ( empty($this->translationType) ) {
|
||||
$this->translationType = $this->componentType;
|
||||
}
|
||||
|
||||
$this->package = $this->createInstalledPackage();
|
||||
$this->scheduler = $this->createScheduler($checkPeriod);
|
||||
$this->upgraderStatus = new UpgraderStatus();
|
||||
|
|
@ -103,6 +121,10 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
$this->installHooks();
|
||||
|
||||
if ( ($this->wpCliCheckTrigger === null) && defined('WP_CLI') ) {
|
||||
$this->wpCliCheckTrigger = new WpCliCheckTrigger($this->componentType, $this->scheduler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,6 +171,10 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
//Allow HTTP requests to the metadata URL even if it's on a local host.
|
||||
add_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10, 2);
|
||||
|
||||
//Potentially exclude information about this entity from core update check requests to api.wordpress.org.
|
||||
//phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args -- Doesn't modify timeouts.
|
||||
add_filter('http_request_args', array($this, 'excludeEntityFromWordPressAPI'), 10, 2);
|
||||
|
||||
//DebugBar integration.
|
||||
if ( did_action('plugins_loaded') ) {
|
||||
$this->maybeInitDebugBar();
|
||||
|
|
@ -170,6 +196,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
|
||||
remove_filter('upgrader_source_selection', array($this, 'fixDirectoryName'), 10);
|
||||
remove_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10);
|
||||
remove_filter('http_request_args', array($this, 'excludeEntityFromWordPressAPI'));
|
||||
remove_action('plugins_loaded', array($this, 'maybeInitDebugBar'));
|
||||
|
||||
remove_action('init', array($this, 'loadTextDomain'));
|
||||
|
|
@ -244,6 +271,76 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*/
|
||||
abstract protected function createScheduler($checkPeriod);
|
||||
|
||||
/**
|
||||
* Remove information about this plugin or theme from the requests that WordPress core sends
|
||||
* to api.wordpress.org when checking for updates.
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $url
|
||||
* @return array
|
||||
*/
|
||||
public function excludeEntityFromWordPressAPI($args, $url) {
|
||||
//Is this an api.wordpress.org update check request?
|
||||
$parsedUrl = wp_parse_url($url);
|
||||
if ( !isset($parsedUrl['host']) || (strtolower($parsedUrl['host']) !== 'api.wordpress.org') ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$typePluralised = $this->componentType . 's';
|
||||
$expectedPathPrefix = '/' . $typePluralised . '/update-check/1.'; //e.g. "/plugins/update-check/1.1/"
|
||||
if ( !isset($parsedUrl['path']) || !Utils::startsWith($parsedUrl['path'], $expectedPathPrefix) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
//Plugins and themes can disable this feature by using the filter below.
|
||||
if ( !apply_filters(
|
||||
$this->getUniqueName('remove_from_default_update_checks'),
|
||||
true, $this, $args, $url
|
||||
) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
if ( empty($args['body'][$typePluralised]) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$reportingItems = json_decode($args['body'][$typePluralised], true);
|
||||
if ( $reportingItems === null ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
//The list of installed items uses different key formats for plugins and themes.
|
||||
//Luckily, we can reuse the getUpdateListKey() method here.
|
||||
$updateListKey = $this->getUpdateListKey();
|
||||
if ( isset($reportingItems[$typePluralised][$updateListKey]) ) {
|
||||
unset($reportingItems[$typePluralised][$updateListKey]);
|
||||
}
|
||||
|
||||
if ( !empty($reportingItems['active']) ) {
|
||||
if ( is_array($reportingItems['active']) ) {
|
||||
foreach ($reportingItems['active'] as $index => $relativePath) {
|
||||
if ( $relativePath === $updateListKey ) {
|
||||
unset($reportingItems['active'][$index]);
|
||||
}
|
||||
}
|
||||
//Re-index the array.
|
||||
$reportingItems['active'] = array_values($reportingItems['active']);
|
||||
} else if ( $reportingItems['active'] === $updateListKey ) {
|
||||
//For themes, the "active" field is a string that contains the theme's directory name.
|
||||
//Pretend that the default theme is active so that we don't reveal the actual theme.
|
||||
if ( defined('WP_DEFAULT_THEME') ) {
|
||||
$reportingItems['active'] = WP_DEFAULT_THEME;
|
||||
}
|
||||
|
||||
//Unfortunately, it doesn't seem to be documented if we can safely remove the "active"
|
||||
//key. So when we don't know the default theme, we'll just leave it as is.
|
||||
}
|
||||
}
|
||||
|
||||
$args['body'][$typePluralised] = wp_json_encode($reportingItems);
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for updates. The results are stored in the DB option specified in $optionName.
|
||||
*
|
||||
|
|
@ -362,7 +459,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*
|
||||
* @param Metadata|null $update
|
||||
*/
|
||||
protected function fixSupportedWordpressVersion(Metadata $update = null) {
|
||||
protected function fixSupportedWordpressVersion($update = null) {
|
||||
if ( !isset($update->tested) || !preg_match('/^\d++\.\d++$/', $update->tested) ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -660,7 +757,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
|
||||
//Various options for the wp_remote_get() call. Plugins can filter these, too.
|
||||
$options = array(
|
||||
'timeout' => 10, //seconds
|
||||
'timeout' => wp_doing_cron() ? 10 : 3,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
),
|
||||
|
|
@ -676,7 +773,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
$result = wp_remote_get($url, $options);
|
||||
|
||||
$result = apply_filters($this->getUniqueName('request_metadata_http_result'), $result, $url, $options);
|
||||
|
||||
|
||||
//Try to parse the response
|
||||
$status = $this->validateApiResponse($result);
|
||||
$metadata = null;
|
||||
|
|
@ -902,25 +999,62 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
return $source;
|
||||
}
|
||||
|
||||
//Fix the remote source structure if necessary.
|
||||
//The update archive should contain a single directory that contains the rest of plugin/theme files.
|
||||
//Otherwise, WordPress will try to copy the entire working directory ($source == $remoteSource).
|
||||
//We can't rename $remoteSource because that would break WordPress code that cleans up temporary files
|
||||
//after update.
|
||||
if ( $this->isBadDirectoryStructure($remoteSource) ) {
|
||||
//Create a new directory using the plugin slug.
|
||||
$newDirectory = trailingslashit($remoteSource) . $this->slug . '/';
|
||||
|
||||
if ( !$wp_filesystem->is_dir($newDirectory) ) {
|
||||
$wp_filesystem->mkdir($newDirectory);
|
||||
|
||||
//Move all files to the newly created directory.
|
||||
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
||||
if ( is_array($sourceFiles) ) {
|
||||
$sourceFiles = array_keys($sourceFiles);
|
||||
$allMoved = true;
|
||||
foreach ($sourceFiles as $filename) {
|
||||
//Skip our newly created folder.
|
||||
if ( $filename === $this->slug ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$previousSource = trailingslashit($remoteSource) . $filename;
|
||||
$newSource = trailingslashit($newDirectory) . $filename;
|
||||
|
||||
if ( !$wp_filesystem->move($previousSource, $newSource, true) ) {
|
||||
$allMoved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $allMoved ) {
|
||||
//Rename source.
|
||||
$source = $newDirectory;
|
||||
} else {
|
||||
//Delete our newly created folder including all files in it.
|
||||
$wp_filesystem->rmdir($newDirectory, true);
|
||||
|
||||
//And return a relevant error.
|
||||
return new WP_Error(
|
||||
'puc-incorrect-directory-structure',
|
||||
sprintf(
|
||||
'The directory structure of the update was incorrect. All files should be inside ' .
|
||||
'a directory named <span class="code">%s</span>, not at the root of the ZIP archive. Plugin Update Checker tried to fix the directory structure, but failed.',
|
||||
esc_html($this->slug)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Rename the source to match the existing directory.
|
||||
$correctedSource = trailingslashit($remoteSource) . $this->directoryName . '/';
|
||||
if ( $source !== $correctedSource ) {
|
||||
//The update archive should contain a single directory that contains the rest of plugin/theme files.
|
||||
//Otherwise, WordPress will try to copy the entire working directory ($source == $remoteSource).
|
||||
//We can't rename $remoteSource because that would break WordPress code that cleans up temporary files
|
||||
//after update.
|
||||
if ( $this->isBadDirectoryStructure($remoteSource) ) {
|
||||
return new WP_Error(
|
||||
'puc-incorrect-directory-structure',
|
||||
sprintf(
|
||||
'The directory structure of the update is incorrect. All files should be inside ' .
|
||||
'a directory named <span class="code">%s</span>, not at the root of the ZIP archive.',
|
||||
htmlentities($this->slug)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** @var \WP_Upgrader_Skin $upgrader ->skin */
|
||||
$upgrader->skin->feedback(sprintf(
|
||||
'Renaming %s to %s…',
|
||||
'<span class="code">' . basename($source) . '</span>',
|
||||
|
|
@ -980,7 +1114,11 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* Initialize the update checker Debug Bar plugin/add-on thingy.
|
||||
*/
|
||||
public function maybeInitDebugBar() {
|
||||
if ( class_exists('Debug_Bar', false) && file_exists(dirname(__FILE__) . '/DebugBar') ) {
|
||||
if (
|
||||
class_exists('Debug_Bar', false)
|
||||
&& class_exists('Debug_Bar_Panel', false)
|
||||
&& file_exists(dirname(__FILE__) . '/DebugBar')
|
||||
) {
|
||||
$this->debugBarExtension = $this->createDebugBarExtension();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(UpgraderStatus::class, false) ):
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
* This class uses a few workarounds and heuristics to get the file name.
|
||||
*/
|
||||
class UpgraderStatus {
|
||||
private $currentType = null; //"plugin" or "theme".
|
||||
private $currentType = null; //This must be either "plugin" or "theme".
|
||||
private $currentId = null; //Plugin basename or theme directory name.
|
||||
|
||||
public function __construct() {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(Utils::class, false) ):
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use Parsedown;
|
||||
use PucReadmeParser;
|
||||
|
|
@ -12,6 +13,31 @@ if ( !class_exists(Api::class, false) ):
|
|||
const STRATEGY_STABLE_TAG = 'stable_tag';
|
||||
const STRATEGY_BRANCH = 'branch';
|
||||
|
||||
/**
|
||||
* Consider all releases regardless of their version number or prerelease/upcoming
|
||||
* release status.
|
||||
*/
|
||||
const RELEASE_FILTER_ALL = 3;
|
||||
|
||||
/**
|
||||
* Exclude releases that have the "prerelease" or "upcoming release" flag.
|
||||
*
|
||||
* This does *not* look for prerelease keywords like "beta" in the version number.
|
||||
* It only uses the data provided by the API. For example, on GitHub, you can
|
||||
* manually mark a release as a prerelease.
|
||||
*/
|
||||
const RELEASE_FILTER_SKIP_PRERELEASE = 1;
|
||||
|
||||
/**
|
||||
* If there are no release assets or none of them match the configured filter,
|
||||
* fall back to the automatically generated source code archive.
|
||||
*/
|
||||
const PREFER_RELEASE_ASSETS = 1;
|
||||
/**
|
||||
* Skip releases that don't have any matching release assets.
|
||||
*/
|
||||
const REQUIRE_RELEASE_ASSETS = 2;
|
||||
|
||||
protected $tagNameProperty = 'name';
|
||||
protected $slug = '';
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !interface_exists(BaseChecker::class, false) ):
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\OAuthSignature;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Utils;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\OAuthSignature;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Utils;
|
||||
|
||||
if ( !class_exists(BitBucketApi::class, false) ):
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
$url = $this->oauth->sign($url,'GET');
|
||||
}
|
||||
|
||||
$options = array('timeout' => 10);
|
||||
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||
if ( !empty($this->httpFilterName) ) {
|
||||
$options = apply_filters($this->httpFilterName, $options);
|
||||
}
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use Parsedown;
|
||||
|
||||
if ( !class_exists(GitHubApi::class, false) ):
|
||||
|
||||
class GitHubApi extends Api {
|
||||
use ReleaseAssetSupport;
|
||||
use ReleaseFilteringFeature;
|
||||
|
||||
/**
|
||||
* @var string GitHub username.
|
||||
*/
|
||||
|
|
@ -25,21 +29,6 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
*/
|
||||
protected $accessToken;
|
||||
|
||||
/**
|
||||
* @var bool Whether to download release assets instead of the auto-generated source code archives.
|
||||
*/
|
||||
protected $releaseAssetsEnabled = false;
|
||||
|
||||
/**
|
||||
* @var string|null Regular expression that's used to filter release assets by name. Optional.
|
||||
*/
|
||||
protected $assetFilterRegex = null;
|
||||
|
||||
/**
|
||||
* @var string|null The unchanging part of a release asset URL. Used to identify download attempts.
|
||||
*/
|
||||
protected $assetApiBaseUrl = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
|
@ -63,49 +52,103 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
* @return Reference|null
|
||||
*/
|
||||
public function getLatestRelease() {
|
||||
$release = $this->api('/repos/:user/:repo/releases/latest');
|
||||
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$reference = new Reference(array(
|
||||
'name' => $release->tag_name,
|
||||
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
||||
'downloadUrl' => $release->zipball_url,
|
||||
'updated' => $release->created_at,
|
||||
'apiResponse' => $release,
|
||||
));
|
||||
|
||||
if ( isset($release->assets[0]) ) {
|
||||
$reference->downloadCount = $release->assets[0]->download_count;
|
||||
}
|
||||
|
||||
if ( $this->releaseAssetsEnabled && isset($release->assets, $release->assets[0]) ) {
|
||||
//Use the first release asset that matches the specified regular expression.
|
||||
$matchingAssets = array_filter($release->assets, array($this, 'matchesAssetFilter'));
|
||||
if ( !empty($matchingAssets) ) {
|
||||
if ( $this->isAuthenticationEnabled() ) {
|
||||
/**
|
||||
* Keep in mind that we'll need to add an "Accept" header to download this asset.
|
||||
*
|
||||
* @see setUpdateDownloadHeaders()
|
||||
*/
|
||||
$reference->downloadUrl = $matchingAssets[0]->url;
|
||||
} else {
|
||||
//It seems that browser_download_url only works for public repositories.
|
||||
//Using an access_token doesn't help. Maybe OAuth would work?
|
||||
$reference->downloadUrl = $matchingAssets[0]->browser_download_url;
|
||||
}
|
||||
|
||||
$reference->downloadCount = $matchingAssets[0]->download_count;
|
||||
//The "latest release" endpoint returns one release and always skips pre-releases,
|
||||
//so we can only use it if that's compatible with the current filter settings.
|
||||
if (
|
||||
$this->shouldSkipPreReleases()
|
||||
&& (
|
||||
($this->releaseFilterMaxReleases === 1) || !$this->hasCustomReleaseFilter()
|
||||
)
|
||||
) {
|
||||
//Just get the latest release.
|
||||
$release = $this->api('/repos/:user/:repo/releases/latest');
|
||||
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
||||
return null;
|
||||
}
|
||||
$foundReleases = array($release);
|
||||
} else {
|
||||
//Get a list of the most recent releases.
|
||||
$foundReleases = $this->api(
|
||||
'/repos/:user/:repo/releases',
|
||||
array('per_page' => $this->releaseFilterMaxReleases)
|
||||
);
|
||||
if ( is_wp_error($foundReleases) || !is_array($foundReleases) ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty($release->body) ) {
|
||||
$reference->changelog = Parsedown::instance()->text($release->body);
|
||||
foreach ($foundReleases as $release) {
|
||||
//Always skip drafts.
|
||||
if ( isset($release->draft) && !empty($release->draft) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Skip pre-releases unless specifically included.
|
||||
if (
|
||||
$this->shouldSkipPreReleases()
|
||||
&& isset($release->prerelease)
|
||||
&& !empty($release->prerelease)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$versionNumber = ltrim($release->tag_name, 'v'); //Remove the "v" prefix from "v1.2.3".
|
||||
|
||||
//Custom release filtering.
|
||||
if ( !$this->matchesCustomReleaseFilter($versionNumber, $release) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$reference = new Reference(array(
|
||||
'name' => $release->tag_name,
|
||||
'version' => $versionNumber,
|
||||
'downloadUrl' => $release->zipball_url,
|
||||
'updated' => $release->created_at,
|
||||
'apiResponse' => $release,
|
||||
));
|
||||
|
||||
if ( isset($release->assets[0]) ) {
|
||||
$reference->downloadCount = $release->assets[0]->download_count;
|
||||
}
|
||||
|
||||
if ( $this->releaseAssetsEnabled ) {
|
||||
//Use the first release asset that matches the specified regular expression.
|
||||
if ( isset($release->assets, $release->assets[0]) ) {
|
||||
$matchingAssets = array_values(array_filter($release->assets, array($this, 'matchesAssetFilter')));
|
||||
} else {
|
||||
$matchingAssets = array();
|
||||
}
|
||||
|
||||
if ( !empty($matchingAssets) ) {
|
||||
if ( $this->isAuthenticationEnabled() ) {
|
||||
/**
|
||||
* Keep in mind that we'll need to add an "Accept" header to download this asset.
|
||||
*
|
||||
* @see setUpdateDownloadHeaders()
|
||||
*/
|
||||
$reference->downloadUrl = $matchingAssets[0]->url;
|
||||
} else {
|
||||
//It seems that browser_download_url only works for public repositories.
|
||||
//Using an access_token doesn't help. Maybe OAuth would work?
|
||||
$reference->downloadUrl = $matchingAssets[0]->browser_download_url;
|
||||
}
|
||||
|
||||
$reference->downloadCount = $matchingAssets[0]->download_count;
|
||||
} else if ( $this->releaseAssetPreference === Api::REQUIRE_RELEASE_ASSETS ) {
|
||||
//None of the assets match the filter, and we're not allowed
|
||||
//to fall back to the auto-generated source ZIP.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty($release->body) ) {
|
||||
$reference->changelog = Parsedown::instance()->text($release->body);
|
||||
}
|
||||
|
||||
return $reference;
|
||||
}
|
||||
|
||||
return $reference;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -205,7 +248,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
$baseUrl = $url;
|
||||
$url = $this->buildApiUrl($url, $queryParams);
|
||||
|
||||
$options = array('timeout' => 10);
|
||||
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||
if ( $this->isAuthenticationEnabled() ) {
|
||||
$options['headers'] = array('Authorization' => $this->getAuthorizationHeader());
|
||||
}
|
||||
|
|
@ -315,7 +358,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
protected function getUpdateDetectionStrategies($configBranch) {
|
||||
$strategies = array();
|
||||
|
||||
if ( $configBranch === 'master' ) {
|
||||
if ( $configBranch === 'master' || $configBranch === 'main') {
|
||||
//Use the latest release.
|
||||
$strategies[self::STRATEGY_LATEST_RELEASE] = array($this, 'getLatestRelease');
|
||||
//Failing that, use the tag with the highest version number.
|
||||
|
|
@ -323,7 +366,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
}
|
||||
|
||||
//Alternatively, just use the branch itself.
|
||||
$strategies[self::STRATEGY_BRANCH] = function() use ($configBranch) {
|
||||
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||
return $this->getBranch($configBranch);
|
||||
};
|
||||
|
||||
|
|
@ -331,43 +374,29 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* Enable updating via release assets.
|
||||
* Get the unchanging part of a release asset URL. Used to identify download attempts.
|
||||
*
|
||||
* If the latest release contains no usable assets, the update checker
|
||||
* will fall back to using the automatically generated ZIP archive.
|
||||
*
|
||||
* Private repositories will only work with WordPress 3.7 or later.
|
||||
*
|
||||
* @param string|null $fileNameRegex Optional. Use only those assets where the file name matches this regex.
|
||||
* @return string
|
||||
*/
|
||||
public function enableReleaseAssets($fileNameRegex = null) {
|
||||
$this->releaseAssetsEnabled = true;
|
||||
$this->assetFilterRegex = $fileNameRegex;
|
||||
$this->assetApiBaseUrl = sprintf(
|
||||
protected function getAssetApiBaseUrl() {
|
||||
return sprintf(
|
||||
'//api.github.com/repos/%1$s/%2$s/releases/assets/',
|
||||
$this->userName,
|
||||
$this->repositoryName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this asset match the file name regex?
|
||||
*
|
||||
* @param \stdClass $releaseAsset
|
||||
* @return bool
|
||||
*/
|
||||
protected function matchesAssetFilter($releaseAsset) {
|
||||
if ( $this->assetFilterRegex === null ) {
|
||||
//The default is to accept all assets.
|
||||
return true;
|
||||
protected function getFilterableAssetName($releaseAsset) {
|
||||
if ( isset($releaseAsset->name) ) {
|
||||
return $releaseAsset->name;
|
||||
}
|
||||
return isset($releaseAsset->name) && preg_match($this->assetFilterRegex, $releaseAsset->name);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param bool $result
|
||||
* @return bool
|
||||
* @internal
|
||||
*/
|
||||
public function addHttpRequestFilter($result) {
|
||||
if ( !$this->downloadFilterAdded && $this->isAuthenticationEnabled() ) {
|
||||
|
|
@ -383,6 +412,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
* Set the HTTP headers that are necessary to download updates from private repositories.
|
||||
*
|
||||
* See GitHub docs:
|
||||
*
|
||||
* @link https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
|
||||
* @link https://developer.github.com/v3/auth/#basic-authentication
|
||||
*
|
||||
|
|
@ -393,7 +423,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
*/
|
||||
public function setUpdateDownloadHeaders($requestArgs, $url = '') {
|
||||
//Is WordPress trying to download one of our release assets?
|
||||
if ( $this->releaseAssetsEnabled && (strpos($url, $this->assetApiBaseUrl) !== false) ) {
|
||||
if ( $this->releaseAssetsEnabled && (strpos($url, $this->getAssetApiBaseUrl()) !== false) ) {
|
||||
$requestArgs['headers']['Accept'] = 'application/octet-stream';
|
||||
}
|
||||
//Use Basic authentication, but only if the download is from our repository.
|
||||
|
|
@ -409,9 +439,9 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
* the authorization header to other hosts. We don't want that because it breaks
|
||||
* AWS downloads and can leak authorization information.
|
||||
*
|
||||
* @internal
|
||||
* @param string $location
|
||||
* @param array $headers
|
||||
* @internal
|
||||
*/
|
||||
public function removeAuthHeaderFromRedirects(&$location, &$headers) {
|
||||
$repoApiBaseUrl = $this->buildApiUrl('/repos/:user/:repo/', array());
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !class_exists(GitLabApi::class, false) ):
|
||||
|
||||
class GitLabApi extends Api {
|
||||
use ReleaseAssetSupport;
|
||||
use ReleaseFilteringFeature;
|
||||
|
||||
/**
|
||||
* @var string GitLab username.
|
||||
*/
|
||||
|
|
@ -30,12 +34,8 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
protected $accessToken;
|
||||
|
||||
/**
|
||||
* @var bool Whether to download release assets instead of the auto-generated source code archives.
|
||||
*/
|
||||
protected $releaseAssetsEnabled = false;
|
||||
|
||||
/**
|
||||
* @var bool Whether to download release asset package rather than release asset source.
|
||||
* @deprecated
|
||||
* @var bool No longer used.
|
||||
*/
|
||||
protected $releasePackageEnabled = false;
|
||||
|
||||
|
|
@ -105,76 +105,85 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
* @return Reference|null
|
||||
*/
|
||||
public function getLatestRelease() {
|
||||
$releases = $this->api('/:id/releases');
|
||||
$releases = $this->api('/:id/releases', array('per_page' => $this->releaseFilterMaxReleases));
|
||||
if ( is_wp_error($releases) || empty($releases) || !is_array($releases) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($releases as $release) {
|
||||
if ( true !== $release->upcoming_release ) {
|
||||
break 1; //Break the loop on the first release we find that isn't an upcoming release
|
||||
if (
|
||||
//Skip invalid/unsupported releases.
|
||||
!is_object($release)
|
||||
|| !isset($release->tag_name)
|
||||
//Skip upcoming releases.
|
||||
|| (
|
||||
!empty($release->upcoming_release)
|
||||
&& $this->shouldSkipPreReleases()
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$reference = new Reference(array(
|
||||
'name' => $release->tag_name,
|
||||
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
||||
'downloadUrl' => '',
|
||||
'updated' => $release->released_at,
|
||||
'apiResponse' => $release,
|
||||
));
|
||||
$download_url = false;
|
||||
$versionNumber = ltrim($release->tag_name, 'v'); //Remove the "v" prefix from "v1.2.3".
|
||||
|
||||
if ( $this->releasePackageEnabled && isset($release->assets, $release->assets->links) ) {
|
||||
/**
|
||||
* Use the first asset LINK that is a zip format file generated by a Gitlab Release Pipeline
|
||||
*
|
||||
* @link https://gist.github.com/timwiel/9dfd3526c768efad4973254085e065ce
|
||||
*/
|
||||
foreach ($release->assets->links as $link) {
|
||||
//TODO: Check the "format" property instead of the URL suffix.
|
||||
if ( 'zip' === substr($link->url, -3) ) {
|
||||
$download_url = $link->url;
|
||||
break 1;
|
||||
}
|
||||
//Apply custom filters.
|
||||
if ( !$this->matchesCustomReleaseFilter($versionNumber, $release) ) {
|
||||
continue;
|
||||
}
|
||||
if ( empty( $download_url ) ) {
|
||||
|
||||
$downloadUrl = $this->findReleaseDownloadUrl($release);
|
||||
if ( empty($downloadUrl) ) {
|
||||
//The latest release doesn't have valid download URL.
|
||||
return null;
|
||||
}
|
||||
if ( ! empty( $this->accessToken ) ) {
|
||||
$download_url = add_query_arg('private_token', $this->accessToken, $download_url);
|
||||
}
|
||||
$reference->downloadUrl = $download_url;
|
||||
return $reference;
|
||||
|
||||
} elseif ( isset($release->assets) ) {
|
||||
/**
|
||||
* Use the first asset SOURCE file that is a zip format from a Gitlab Release which should be a zip file
|
||||
*/
|
||||
foreach ($release->assets->sources as $source) {
|
||||
if ( 'zip' === $source->format ) {
|
||||
$download_url = $source->url;
|
||||
break 1;
|
||||
}
|
||||
if ( !empty($this->accessToken) ) {
|
||||
$downloadUrl = add_query_arg('private_token', $this->accessToken, $downloadUrl);
|
||||
}
|
||||
if ( empty( $download_url ) ) {
|
||||
return null;
|
||||
}
|
||||
if ( ! empty( $this->accessToken ) ) {
|
||||
$download_url = add_query_arg('private_token', $this->accessToken, $download_url);
|
||||
}
|
||||
$reference->downloadUrl = $download_url;
|
||||
return $reference;
|
||||
|
||||
return new Reference(array(
|
||||
'name' => $release->tag_name,
|
||||
'version' => $versionNumber,
|
||||
'downloadUrl' => $downloadUrl,
|
||||
'updated' => $release->released_at,
|
||||
'apiResponse' => $release,
|
||||
));
|
||||
}
|
||||
|
||||
//If we get this far without a return then obviosuly noi release download urls were found
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $release
|
||||
* @return string|null
|
||||
*/
|
||||
protected function findReleaseDownloadUrl($release) {
|
||||
if ( $this->releaseAssetsEnabled ) {
|
||||
if ( isset($release->assets, $release->assets->links) ) {
|
||||
//Use the first asset link where the URL matches the filter.
|
||||
foreach ($release->assets->links as $link) {
|
||||
if ( $this->matchesAssetFilter($link) ) {
|
||||
return $link->url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->releaseAssetPreference === Api::REQUIRE_RELEASE_ASSETS ) {
|
||||
//Falling back to source archives is not allowed, so give up.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//Use the first source code archive that's in ZIP format.
|
||||
foreach ($release->assets->sources as $source) {
|
||||
if ( isset($source->format) && ($source->format === 'zip') ) {
|
||||
return $source->url;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag that looks like the highest version number.
|
||||
*
|
||||
|
|
@ -251,7 +260,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
$baseUrl = $url;
|
||||
$url = $this->buildApiUrl($url, $queryParams);
|
||||
|
||||
$options = array('timeout' => 10);
|
||||
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||
if ( !empty($this->httpFilterName) ) {
|
||||
$options = apply_filters($this->httpFilterName, $options);
|
||||
}
|
||||
|
|
@ -365,7 +374,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||
}
|
||||
|
||||
$strategies[self::STRATEGY_BRANCH] = function() use ($configBranch) {
|
||||
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||
return $this->getBranch($configBranch);
|
||||
};
|
||||
|
||||
|
|
@ -377,16 +386,29 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
$this->accessToken = is_string($credentials) ? $credentials : null;
|
||||
}
|
||||
|
||||
public function enableReleaseAssets() {
|
||||
$this->releaseAssetsEnabled = true;
|
||||
$this->releasePackageEnabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use release assets that link to GitLab generic packages (e.g. .zip files)
|
||||
* instead of automatically generated source archives.
|
||||
*
|
||||
* This is included for backwards compatibility with older versions of PUC.
|
||||
*
|
||||
* @return void
|
||||
* @deprecated Use enableReleaseAssets() instead.
|
||||
* @noinspection PhpUnused -- Public API
|
||||
*/
|
||||
public function enableReleasePackages() {
|
||||
$this->releaseAssetsEnabled = false;
|
||||
$this->releasePackageEnabled = true;
|
||||
$this->enableReleaseAssets(
|
||||
/** @lang RegExp */ '/\.zip($|[?&#])/i',
|
||||
Api::REQUIRE_RELEASE_ASSETS
|
||||
);
|
||||
}
|
||||
|
||||
protected function getFilterableAssetName($releaseAsset) {
|
||||
if ( isset($releaseAsset->url) ) {
|
||||
return $releaseAsset->url;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
if ( !class_exists(PluginUpdateChecker::class, false) ):
|
||||
|
||||
|
|
@ -85,6 +85,21 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
$this->setInfoFromHeader($remoteHeader, $info);
|
||||
}
|
||||
|
||||
//Sanity check: Reject updates that don't have a version number.
|
||||
//This can happen when we're using a branch, and we either fail to retrieve the main plugin
|
||||
//file or the file doesn't have a "Version" header.
|
||||
if ( empty($info->version) ) {
|
||||
do_action(
|
||||
'puc_api_error',
|
||||
new \WP_Error(
|
||||
'puc-no-plugin-version',
|
||||
'Could not find the version number in the repository.'
|
||||
),
|
||||
null, null, $this->slug
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
|
||||
//a lot of useful information like the required/tested WP version, changelog, and so on.
|
||||
if ( $this->readmeTxtExistsLocally() ) {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !class_exists(Reference::class, false) ):
|
||||
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !trait_exists(ReleaseAssetSupport::class, false) ) :
|
||||
|
||||
trait ReleaseAssetSupport {
|
||||
/**
|
||||
* @var bool Whether to download release assets instead of the auto-generated
|
||||
* source code archives.
|
||||
*/
|
||||
protected $releaseAssetsEnabled = false;
|
||||
|
||||
/**
|
||||
* @var string|null Regular expression that's used to filter release assets
|
||||
* by file name or URL. Optional.
|
||||
*/
|
||||
protected $assetFilterRegex = null;
|
||||
|
||||
/**
|
||||
* How to handle releases that don't have any matching release assets.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $releaseAssetPreference = Api::PREFER_RELEASE_ASSETS;
|
||||
|
||||
/**
|
||||
* Enable updating via release assets.
|
||||
*
|
||||
* If the latest release contains no usable assets, the update checker
|
||||
* will fall back to using the automatically generated ZIP archive.
|
||||
*
|
||||
* @param string|null $nameRegex Optional. Use only those assets where
|
||||
* the file name or URL matches this regex.
|
||||
* @param int $preference Optional. How to handle releases that don't have
|
||||
* any matching release assets.
|
||||
*/
|
||||
public function enableReleaseAssets($nameRegex = null, $preference = Api::PREFER_RELEASE_ASSETS) {
|
||||
$this->releaseAssetsEnabled = true;
|
||||
$this->assetFilterRegex = $nameRegex;
|
||||
$this->releaseAssetPreference = $preference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable release assets.
|
||||
*
|
||||
* @return void
|
||||
* @noinspection PhpUnused -- Public API
|
||||
*/
|
||||
public function disableReleaseAssets() {
|
||||
$this->releaseAssetsEnabled = false;
|
||||
$this->assetFilterRegex = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the specified asset match the name regex?
|
||||
*
|
||||
* @param mixed $releaseAsset Data type and structure depend on the host/API.
|
||||
* @return bool
|
||||
*/
|
||||
protected function matchesAssetFilter($releaseAsset) {
|
||||
if ( $this->assetFilterRegex === null ) {
|
||||
//The default is to accept all assets.
|
||||
return true;
|
||||
}
|
||||
|
||||
$name = $this->getFilterableAssetName($releaseAsset);
|
||||
if ( !is_string($name) ) {
|
||||
return false;
|
||||
}
|
||||
return (bool)preg_match($this->assetFilterRegex, $releaseAsset->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the part of asset data that will be checked against the filter regex.
|
||||
*
|
||||
* @param mixed $releaseAsset
|
||||
* @return string|null
|
||||
*/
|
||||
abstract protected function getFilterableAssetName($releaseAsset);
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !trait_exists(ReleaseFilteringFeature::class, false) ) :
|
||||
|
||||
trait ReleaseFilteringFeature {
|
||||
/**
|
||||
* @var callable|null
|
||||
*/
|
||||
protected $releaseFilterCallback = null;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $releaseFilterMaxReleases = 1;
|
||||
/**
|
||||
* @var string One of the Api::RELEASE_FILTER_* constants.
|
||||
*/
|
||||
protected $releaseFilterByType = Api::RELEASE_FILTER_SKIP_PRERELEASE;
|
||||
|
||||
/**
|
||||
* Set a custom release filter.
|
||||
*
|
||||
* Setting a new filter will override the old filter, if any.
|
||||
*
|
||||
* @param callable $callback A callback that accepts a version number and a release
|
||||
* object, and returns a boolean.
|
||||
* @param int $releaseTypes One of the Api::RELEASE_FILTER_* constants.
|
||||
* @param int $maxReleases Optional. The maximum number of recent releases to examine
|
||||
* when trying to find a release that matches the filter. 1 to 100.
|
||||
* @return $this
|
||||
*/
|
||||
public function setReleaseFilter(
|
||||
$callback,
|
||||
$releaseTypes = Api::RELEASE_FILTER_SKIP_PRERELEASE,
|
||||
$maxReleases = 20
|
||||
) {
|
||||
if ( $maxReleases > 100 ) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The max number of releases is too high (%d). It must be 100 or less.',
|
||||
$maxReleases
|
||||
));
|
||||
} else if ( $maxReleases < 1 ) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The max number of releases is too low (%d). It must be at least 1.',
|
||||
$maxReleases
|
||||
));
|
||||
}
|
||||
|
||||
$this->releaseFilterCallback = $callback;
|
||||
$this->releaseFilterByType = $releaseTypes;
|
||||
$this->releaseFilterMaxReleases = $maxReleases;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter releases by their version number.
|
||||
*
|
||||
* @param string $regex A regular expression. The release version number must match this regex.
|
||||
* @param int $releaseTypes
|
||||
* @param int $maxReleasesToExamine
|
||||
* @return $this
|
||||
* @noinspection PhpUnused -- Public API
|
||||
*/
|
||||
public function setReleaseVersionFilter(
|
||||
$regex,
|
||||
$releaseTypes = Api::RELEASE_FILTER_SKIP_PRERELEASE,
|
||||
$maxReleasesToExamine = 20
|
||||
) {
|
||||
return $this->setReleaseFilter(
|
||||
function ($versionNumber) use ($regex) {
|
||||
return (preg_match($regex, $versionNumber) === 1);
|
||||
},
|
||||
$releaseTypes,
|
||||
$maxReleasesToExamine
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $versionNumber The detected release version number.
|
||||
* @param object $releaseObject Varies depending on the host/API.
|
||||
* @return bool
|
||||
*/
|
||||
protected function matchesCustomReleaseFilter($versionNumber, $releaseObject) {
|
||||
if ( !is_callable($this->releaseFilterCallback) ) {
|
||||
return true; //No custom filter.
|
||||
}
|
||||
return call_user_func($this->releaseFilterCallback, $versionNumber, $releaseObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldSkipPreReleases() {
|
||||
//Maybe this could be a bitfield in the future, if we need to support
|
||||
//more release types.
|
||||
return ($this->releaseFilterByType !== Api::RELEASE_FILTER_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasCustomReleaseFilter() {
|
||||
return isset($this->releaseFilterCallback) && is_callable($this->releaseFilterCallback);
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Utils;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Utils;
|
||||
|
||||
if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !trait_exists(VcsCheckerMethods::class, false) ) :
|
||||
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use WP_CLI;
|
||||
|
||||
/**
|
||||
* Triggers an update check when relevant WP-CLI commands are executed.
|
||||
*
|
||||
* When WP-CLI runs certain commands like "wp plugin status" or "wp theme list", it calls
|
||||
* wp_update_plugins() and wp_update_themes() to refresh update information. This class hooks into
|
||||
* the same commands and triggers an update check when they are executed.
|
||||
*
|
||||
* Note that wp_update_plugins() and wp_update_themes() do not perform an update check *every* time
|
||||
* they are called. They use a context-dependent delay between update checks. Similarly, this class
|
||||
* calls Scheduler::maybeCheckForUpdates(), which also dynamically decides whether to actually
|
||||
* run a check. If you want to force an update check, call UpdateChecker::checkForUpdates() instead.
|
||||
*/
|
||||
class WpCliCheckTrigger {
|
||||
/**
|
||||
* @var Scheduler
|
||||
*/
|
||||
private $scheduler;
|
||||
|
||||
/**
|
||||
* @var string 'plugin' or 'theme'
|
||||
*/
|
||||
private $componentType;
|
||||
|
||||
/**
|
||||
* @var bool Whether an update check was already triggered during the current request
|
||||
* or script execution.
|
||||
*/
|
||||
private $wasCheckTriggered = false;
|
||||
|
||||
public function __construct($componentType, Scheduler $scheduler) {
|
||||
if ( !in_array($componentType, ['plugin', 'theme']) ) {
|
||||
throw new \InvalidArgumentException('Invalid component type. Must be "plugin" or "theme".');
|
||||
}
|
||||
|
||||
$this->componentType = $componentType;
|
||||
$this->scheduler = $scheduler;
|
||||
|
||||
if ( !defined('WP_CLI') || !class_exists(WP_CLI::class, false) ) {
|
||||
return; //Nothing to do if WP-CLI is not available.
|
||||
}
|
||||
|
||||
/*
|
||||
* We can't hook directly into wp_update_plugins(), but we can hook into the WP-CLI
|
||||
* commands that call it. We'll use the "before_invoke:xyz" hook to trigger update checks.
|
||||
*/
|
||||
foreach ($this->getRelevantCommands() as $command) {
|
||||
WP_CLI::add_hook('before_invoke:' . $command, [$this, 'triggerUpdateCheckOnce']);
|
||||
}
|
||||
}
|
||||
|
||||
private function getRelevantCommands() {
|
||||
$result = [];
|
||||
foreach (['status', 'list', 'update'] as $subcommand) {
|
||||
$result[] = $this->componentType . ' ' . $subcommand;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a potential update check once.
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return mixed The input value, unchanged.
|
||||
* @internal This method is public so that it can be used as a WP-CLI hook callback.
|
||||
* It should not be called directly.
|
||||
*
|
||||
*/
|
||||
public function triggerUpdateCheckOnce($input = null) {
|
||||
if ( $this->wasCheckTriggered ) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
$this->wasCheckTriggered = true;
|
||||
$this->scheduler->maybeCheckForUpdates();
|
||||
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
89
README.md
89
README.md
|
|
@ -29,7 +29,7 @@ From the users' perspective, it works just like with plugins and themes hosted o
|
|||
Getting Started
|
||||
---------------
|
||||
|
||||
*Note:* In each of the below examples, part of the instructions are to create an instance of the update checker class. It's recommended to do this either during the `plugins_loaded` action or outside of any hooks. If you do it only during an `admin_*` action, then updates will not be visible to a wide variety of WordPress maanagement tools; they will only be visible to logged-in users on dashboard pages.
|
||||
*Note:* In each of the below examples, part of the instructions is to create an instance of the update checker class. It's recommended to do this either during the `plugins_loaded` action or outside of any hooks. If you do it only during an `admin_*` action, then updates will not be visible to a wide variety of WordPress management tools; they will only be visible to logged-in users on dashboard pages.
|
||||
|
||||
### Self-hosted Plugins and Themes
|
||||
|
||||
|
|
@ -252,8 +252,8 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
|||
|
||||
Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:
|
||||
```php
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Vcs\PluginUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Vcs\GitLabApi;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\PluginUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\GitLabApi;
|
||||
|
||||
$myUpdateChecker = new PluginUpdateChecker(
|
||||
new GitLabApi('https://myserver.com/user-name/repo-name/'),
|
||||
|
|
@ -264,8 +264,8 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
|||
```
|
||||
If you're using a self-hosted GitLab instance and [subgroups or nested groups](https://docs.gitlab.com/ce/user/group/subgroups/index.html), you have to tell the update checker which parts of the URL are subgroups:
|
||||
```php
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Vcs\PluginUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\Vcs\GitLabApi;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\PluginUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\GitLabApi;
|
||||
|
||||
$myUpdateChecker = new PluginUpdateChecker(
|
||||
new GitLabApi(
|
||||
|
|
@ -281,52 +281,41 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
|||
3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
|
||||
|
||||
#### How to Release a GitLab Update
|
||||
A Gitlab repository can be checked for updates in 4 different ways.
|
||||
|
||||
1. **Stable branch** (other than `master` or `main`):
|
||||
- Point the update checker at any stable, production-ready branch and PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version.
|
||||
- Add the following code:
|
||||
```php
|
||||
//Add the following code to your main plugin file or `functions.php` file to check for updates from a custom branch
|
||||
$myUpdateChecker->setBranch('stable-branch-name');
|
||||
```
|
||||
- Caveats:
|
||||
- If you set the branch to `main` (the default) or `master` (the historical default), the update checker will look for recent releases and tags first. It'll only use the `main` or `master` branch if it doesn't find anything else suitable.
|
||||
A GitLab repository can be checked for updates in 3 different ways.
|
||||
|
||||
2. **GitLab Releases using Generic Packages**:
|
||||
- Use a Gitlab CI/CD Pipeline to automatically generate your update on release using a Generic Package. The benefit of using Generic Package assets over the Source Code assets is that the code can already be built and production ready.
|
||||
- Add the following code:
|
||||
```php
|
||||
//Add the following code to your main plugin file or `functions.php` file to check for a new update from releases using generic packages
|
||||
$myUpdateChecker->getVcsApi()->enableReleasePackages();
|
||||
```
|
||||
- PUC will periodically check the release version (i.e. the tag name of the release) and will display a notification if the release is a greater version than the installed version.
|
||||
- The release tag name should loosely follow [SemVer](https://semver.org/) but these are all valid release names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5` However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead.
|
||||
- For more information about *Gitlab Release Generic Packages* refer to the following links:
|
||||
- **GitLab releases**
|
||||
|
||||
Create a new release using the "Releases" feature on GitLab. The tag name should match the version number. You can add a `v` prefix to the tag, like `v1.2.3`. Releases that are marked as ["Upcoming Release"](https://docs.gitlab.com/ee/user/project/releases/index.html#upcoming-releases) will be automatically ignored.
|
||||
|
||||
If you want to use custom release assets, call the `enableReleaseAssets()` method after creating the update checker instance:
|
||||
```php
|
||||
$myUpdateChecker->getVcsApi()->enableReleaseAssets();
|
||||
```
|
||||
|
||||
By default, PUC will use the first available asset link, regardless of type. You can pass a regular expression to `enableReleaseAssets()` to make it pick the first link where the URL matches the regex. For example:
|
||||
```php
|
||||
$myUpdateChecker->getVcsApi()->enableReleaseAssets('/\.zip($|[?&#])/i');
|
||||
```
|
||||
|
||||
**Tip:** You can use a Gitlab CI/CD Pipeline to automatically generate your update on release using a Generic Package. For more information about generic packages, refer to the following links:
|
||||
- [Gitlab CI/CD Release Documentation](https://docs.gitlab.com/ee/user/project/releases/#create-release-from-gitlab-ci)
|
||||
- [Gitlab Release Assets as Generic Package Documentation](https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/)
|
||||
- [Example .gitlab-ci.yml file using Release Generic Packages for generating a update package from the Sensei-LMS wordpress plugin](https://gist.github.com/timwiel/9dfd3526c768efad4973254085e065ce)
|
||||
|
||||
- **Tags**
|
||||
|
||||
3. **GitLab Releases using Source Code Assets**:
|
||||
- Create a new release using the "Releases" feature on Gitlab.
|
||||
- Add the following code:
|
||||
```php
|
||||
//Add the following code to your main plugin file or `functions.php` file to check for a new update from releases using release assets
|
||||
$myUpdateChecker->getVcsApi()->enableReleaseAssets();
|
||||
```
|
||||
- PUC will periodically check the release version (based on release tag name) and display a notification if the release version is greater than the installed version.
|
||||
- The release name should loosely follow [SemVer](https://semver.org/) but these are all valid release names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5` However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead.
|
||||
To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at recent tags and use the one that looks like the highest version number.
|
||||
|
||||
PUC doesn't require strict adherence to [SemVer](https://semver.org/). However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead.
|
||||
|
||||
- **Stable branch**
|
||||
|
||||
4. **Tags** (this is the default option):
|
||||
- To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`.
|
||||
- Optionally, add the following code:
|
||||
```php
|
||||
//Add the following code to your main plugin file or `functions.php` file to check for updates from the default branch
|
||||
$myUpdateChecker->setBranch('master'); //or 'main'
|
||||
```
|
||||
- PUC doesn't require strict adherence to [SemVer](https://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead.
|
||||
Point the update checker at any stable, production-ready branch:
|
||||
```php
|
||||
$myUpdateChecker->setBranch('stable-branch-name');
|
||||
```
|
||||
PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version. Caveat: Even if you set the branch to `main` (the default) or `master` (the historical default), the update checker will still look for recent releases and tags first.
|
||||
|
||||
Migrating from 4.x
|
||||
------------------
|
||||
|
|
@ -358,14 +347,14 @@ Other classes have also been renamed, usually by simply removing the `Puc_vXpY_`
|
|||
| Old class name | New class name |
|
||||
|-------------------------------------|----------------------------------------------------------------|
|
||||
| `Puc_v4_Factory` | `YahnisElsts\PluginUpdateChecker\v5\PucFactory` |
|
||||
| `Puc_v4p13_Factory` | `YahnisElsts\PluginUpdateChecker\v5p0\PucFactory` |
|
||||
| `Puc_v4p13_Plugin_UpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p0\Plugin\UpdateChecker` |
|
||||
| `Puc_v4p13_Theme_UpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p0\Theme\UpdateChecker` |
|
||||
| `Puc_v4p13_Vcs_PluginUpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p0\Vcs\PluginUpdateChecker` |
|
||||
| `Puc_v4p13_Vcs_ThemeUpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p0\Vcs\ThemeUpdateChecker` |
|
||||
| `Puc_v4p13_Vcs_GitHubApi` | `YahnisElsts\PluginUpdateChecker\v5p0\Vcs\GitHubApi` |
|
||||
| `Puc_v4p13_Vcs_GitLabApi` | `YahnisElsts\PluginUpdateChecker\v5p0\Vcs\GitLabApi` |
|
||||
| `Puc_v4p13_Vcs_BitBucketApi` | `YahnisElsts\PluginUpdateChecker\v5p0\Vcs\BitBucketApi` |
|
||||
| `Puc_v4p13_Factory` | `YahnisElsts\PluginUpdateChecker\v5p6\PucFactory` |
|
||||
| `Puc_v4p13_Plugin_UpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p6\Plugin\UpdateChecker` |
|
||||
| `Puc_v4p13_Theme_UpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p6\Theme\UpdateChecker` |
|
||||
| `Puc_v4p13_Vcs_PluginUpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p6\Vcs\PluginUpdateChecker` |
|
||||
| `Puc_v4p13_Vcs_ThemeUpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p6\Vcs\ThemeUpdateChecker` |
|
||||
| `Puc_v4p13_Vcs_GitHubApi` | `YahnisElsts\PluginUpdateChecker\v5p6\Vcs\GitHubApi` |
|
||||
| `Puc_v4p13_Vcs_GitLabApi` | `YahnisElsts\PluginUpdateChecker\v5p6\Vcs\GitLabApi` |
|
||||
| `Puc_v4p13_Vcs_BitBucketApi` | `YahnisElsts\PluginUpdateChecker\v5p6\Vcs\BitBucketApi` |
|
||||
|
||||
License Management
|
||||
------------------
|
||||
|
|
|
|||
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
function versionToInfix($versionNumber) {
|
||||
if ( !isValidVersion($versionNumber) ) {
|
||||
throw new InvalidArgumentException("Invalid version number: $versionNumber");
|
||||
}
|
||||
|
||||
$parts = explode('.', $versionNumber);
|
||||
return 'v' . $parts[0] . 'p' . $parts[1];
|
||||
}
|
||||
|
||||
function infixToVersion($infix) {
|
||||
$parts = explode('p', substr($infix, 1));
|
||||
$version = $parts[0] . '.' . $parts[1];
|
||||
if ( !isValidVersion($version) ) {
|
||||
throw new InvalidArgumentException("Invalid version infix: $infix");
|
||||
}
|
||||
return $version;
|
||||
}
|
||||
|
||||
function isValidVersion($version) {
|
||||
return preg_match('/^\d+\.\d+$/', $version);
|
||||
}
|
||||
|
||||
//Switch to the parent directory so that we can use relative paths where needed.
|
||||
$oldDir = getcwd();
|
||||
$repositoryRoot = __DIR__ . '/..';
|
||||
chdir($repositoryRoot);
|
||||
|
||||
function updateVersionNumbers($filePath, $oldVersion, $newVersion) {
|
||||
$content = file_get_contents($filePath);
|
||||
if ( $content === false ) {
|
||||
echo "Failed to read file: $filePath\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$content = preg_replace("/\b" . preg_quote($oldVersion, '/') . "\b/", $newVersion, $content);
|
||||
$content = preg_replace(
|
||||
"/\b" . preg_quote(versionToInfix($oldVersion), '/') . "\b/",
|
||||
versionToInfix($newVersion),
|
||||
$content
|
||||
);
|
||||
file_put_contents($filePath, $content);
|
||||
}
|
||||
|
||||
//Check for uncommitted changes.
|
||||
exec('git status --porcelain', $output, $returnCode);
|
||||
if ( $returnCode !== 0 ) {
|
||||
echo "Failed to check for uncommitted changes. Git not installed or not in a Git repository?\n";
|
||||
chdir($oldDir);
|
||||
exit(1);
|
||||
}
|
||||
if ( !empty($output) ) {
|
||||
echo "You have uncommitted changes. Please commit or stash them before running this script.\n";
|
||||
chdir($oldDir);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//Get the current version.
|
||||
$currentVersionDir = glob($repositoryRoot . '/Puc/v*p*')[0];
|
||||
if ( !is_dir($currentVersionDir) ) {
|
||||
echo "Failed to find the current version's subdirectory.\n";
|
||||
chdir($oldDir);
|
||||
exit(1);
|
||||
}
|
||||
$currentVersion = infixToVersion(basename($currentVersionDir));
|
||||
|
||||
//Ask the user for the new version number
|
||||
echo "Current version is $currentVersion. Enter new version number: ";
|
||||
$newVersion = trim(fgets(STDIN));
|
||||
if ( !isValidVersion($newVersion) ) {
|
||||
echo "Invalid version number: $newVersion\n";
|
||||
chdir($oldDir);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//Get the old and new version in vXpY and X.Y formats.
|
||||
$oldVersionInfix = basename($currentVersionDir);
|
||||
$newVersionInfix = versionToInfix($newVersion);
|
||||
$oldVersion = $currentVersion;
|
||||
|
||||
//Create a new branch for the version update.
|
||||
exec("git checkout -b \"version-bump-$newVersion\"");
|
||||
|
||||
//Rename the Puc/vXpY directory using Git.
|
||||
exec("git mv \"Puc/$oldVersionInfix\" \"Puc/$newVersionInfix\"");
|
||||
|
||||
//Define the list of directories to search
|
||||
$directoriesToSearch = ['css', 'js', 'Puc'];
|
||||
|
||||
//Replace old version infix and old version number in the source code
|
||||
foreach ($directoriesToSearch as $dir) {
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
|
||||
foreach ($iterator as $file) {
|
||||
if ( $file->isFile() ) {
|
||||
updateVersionNumbers($file->getPathname(), $oldVersion, $newVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Update version numbers in certain files that are not in the above subdirectories.
|
||||
$standaloneFiles = [
|
||||
'plugin-update-checker.php',
|
||||
'README.md',
|
||||
'languages/plugin-update-checker.pot',
|
||||
];
|
||||
foreach ($standaloneFiles as $standaloneFile) {
|
||||
updateVersionNumbers($repositoryRoot . '/' . $standaloneFile, $oldVersion, $newVersion);
|
||||
}
|
||||
|
||||
//Rename the loader file and update the version numbers.
|
||||
$oldLoaderFileName = "load-$oldVersionInfix.php";
|
||||
$newLoaderFileName = "load-$newVersionInfix.php";
|
||||
exec("git mv \"$oldLoaderFileName\" \"$newLoaderFileName\"");
|
||||
updateVersionNumbers($repositoryRoot . '/' . $newLoaderFileName, $oldVersion, $newVersion);
|
||||
|
||||
//Replace the old loader file name with new one in files that use it.
|
||||
//plugin-update-checker.php was already updated by the previous step, but we'll
|
||||
//include it here anyway in case the code order or loader naming scheme changes.
|
||||
$filesUsingLoader = ['plugin-update-checker.php', 'composer.json'];
|
||||
foreach ($filesUsingLoader as $fileName) {
|
||||
$fullFileName = $repositoryRoot . '/' . $fileName;
|
||||
$content = file_get_contents($fullFileName);
|
||||
$content = str_replace($oldLoaderFileName, $newLoaderFileName, $content);
|
||||
file_put_contents($fullFileName, $content);
|
||||
}
|
||||
|
||||
//Commit the changes.
|
||||
exec('git add .');
|
||||
exec("git commit -m \"Bump version number to $newVersion\"");
|
||||
|
||||
echo "Version number bumped to $newVersion.\n";
|
||||
|
||||
//Switch back to the original directory.
|
||||
chdir($oldDir);
|
||||
|
||||
|
|
@ -18,6 +18,6 @@
|
|||
"ext-json": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["load-v5p0.php"]
|
||||
"files": ["load-v5p6.php"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +1,52 @@
|
|||
{
|
||||
"name": "My Example Plugin",
|
||||
"version": "2.0",
|
||||
"download_url": "http://example.com/updates/example-plugin.zip",
|
||||
|
||||
"homepage": "http://example.com/",
|
||||
"requires": "4.5",
|
||||
"tested": "4.8",
|
||||
"last_updated": "2017-01-01 16:17:00",
|
||||
"upgrade_notice": "Here's why you should upgrade...",
|
||||
|
||||
"author": "Janis Elsts",
|
||||
"author_homepage": "http://example.com/",
|
||||
|
||||
"sections": {
|
||||
"description": "(Required) Plugin description. Basic HTML can be used in all sections.",
|
||||
"installation": "(Recommended) Installation instructions.",
|
||||
"changelog": "(Recommended) Changelog. <p>This section will be displayed by default when the user clicks 'View version x.y.z details'.</p>",
|
||||
"custom_section": "This is a custom section labeled 'Custom Section'."
|
||||
},
|
||||
|
||||
"icons" : {
|
||||
"1x" : "http://w-shadow.com/files/external-update-example/assets/icon-128x128.png",
|
||||
"2x" : "http://w-shadow.com/files/external-update-example/assets/icon-256x256.png"
|
||||
},
|
||||
|
||||
"banners": {
|
||||
"low": "http://w-shadow.com/files/external-update-example/assets/banner-772x250.png",
|
||||
"high": "http://w-shadow.com/files/external-update-example/assets/banner-1544x500.png"
|
||||
},
|
||||
|
||||
"translations": [
|
||||
{
|
||||
"language": "fr_FR",
|
||||
"version": "4.0",
|
||||
"updated": "2016-04-22 23:22:42",
|
||||
"package": "http://example.com/updates/translations/french-language-pack.zip"
|
||||
},
|
||||
{
|
||||
"language": "de_DE",
|
||||
"version": "5.0",
|
||||
"updated": "2016-04-22 23:22:42",
|
||||
"package": "http://example.com/updates/translations/german-language-pack.zip"
|
||||
}
|
||||
],
|
||||
|
||||
"rating": 90,
|
||||
"num_ratings": 123,
|
||||
|
||||
"downloaded": 1234,
|
||||
"active_installs": 12345
|
||||
{
|
||||
"name": "My Example Plugin",
|
||||
"version": "2.0",
|
||||
"download_url": "http://example.com/updates/example-plugin.zip",
|
||||
|
||||
"homepage": "http://example.com/",
|
||||
"requires": "4.5",
|
||||
"tested": "4.8",
|
||||
"last_updated": "2017-01-01 16:17:00",
|
||||
"upgrade_notice": "Here's why you should upgrade...",
|
||||
|
||||
"author": "Janis Elsts",
|
||||
"author_homepage": "http://example.com/",
|
||||
|
||||
"sections": {
|
||||
"description": "(Required) Plugin description. Basic HTML can be used in all sections.",
|
||||
"installation": "(Recommended) Installation instructions.",
|
||||
"changelog": "(Recommended) Changelog. <p>This section will be displayed by default when the user clicks 'View version x.y.z details'.</p>",
|
||||
"custom_section": "This is a custom section labeled 'Custom Section'."
|
||||
},
|
||||
|
||||
"icons" : {
|
||||
"1x" : "http://w-shadow.com/files/external-update-example/assets/icon-128x128.png",
|
||||
"2x" : "http://w-shadow.com/files/external-update-example/assets/icon-256x256.png"
|
||||
},
|
||||
|
||||
"banners": {
|
||||
"low": "http://w-shadow.com/files/external-update-example/assets/banner-772x250.png",
|
||||
"high": "http://w-shadow.com/files/external-update-example/assets/banner-1544x500.png"
|
||||
},
|
||||
|
||||
"translations": [
|
||||
{
|
||||
"language": "fr_FR",
|
||||
"version": "4.0",
|
||||
"updated": "2016-04-22 23:22:42",
|
||||
"package": "http://example.com/updates/translations/french-language-pack.zip"
|
||||
},
|
||||
{
|
||||
"language": "de_DE",
|
||||
"version": "5.0",
|
||||
"updated": "2016-04-22 23:22:42",
|
||||
"package": "http://example.com/updates/translations/german-language-pack.zip"
|
||||
}
|
||||
],
|
||||
|
||||
"rating": 90,
|
||||
"num_ratings": 123,
|
||||
|
||||
"downloaded": 1234,
|
||||
"active_installs": 12345
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "2.0",
|
||||
"details_url": "http://example.com/version-2.0-details.html",
|
||||
"download_url": "http://example.com/example-theme-2.0.zip"
|
||||
{
|
||||
"version": "2.0",
|
||||
"details_url": "http://example.com/version-2.0-details.html",
|
||||
"download_url": "http://example.com/example-theme-2.0.zip"
|
||||
}
|
||||
|
|
@ -14,6 +14,8 @@ jQuery(function($) {
|
|||
_wpnonce: panel.data('nonce')
|
||||
},
|
||||
function(data) {
|
||||
//The response contains HTML that should already be escaped in server-side code.
|
||||
//phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
|
||||
responseBox.html(data);
|
||||
},
|
||||
'html'
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,52 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2022-07-29 15:34+0300\n"
|
||||
"PO-Revision-Date: 2024-05-09 22:22+0000\n"
|
||||
"Last-Translator: theogk\n"
|
||||
"Language-Team: Ελληνικά\n"
|
||||
"Language: el\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
||||
"X-Generator: Loco https://localise.biz/\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"X-Loco-Version: 2.6.9; wp-6.5.3"
|
||||
|
||||
#: Puc/v5p4/Plugin/Ui.php:128
|
||||
msgid "Check for updates"
|
||||
msgstr "Έλεγχος για ενημερώσεις"
|
||||
|
||||
#: Puc/v5p4/Plugin/Ui.php:214
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "Το πρόσθετο %s είναι ενημερωμένο."
|
||||
|
||||
#: Puc/v5p4/Plugin/Ui.php:216
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "Μία νέα έκδοση είναι διαθέσιμη για το πρόσθετο %s."
|
||||
|
||||
#: Puc/v5p4/Plugin/Ui.php:218
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr ""
|
||||
"Δεν ήταν εφικτό να εκτελεστεί ο έλεγχος για νέες ενημερώσεις για το πρόσθετο "
|
||||
"%s."
|
||||
|
||||
#: Puc/v5p4/Plugin/Ui.php:224
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "Άγνωστο πρόβλημα του ενημερωτή προσθέτων \"%s\""
|
||||
|
||||
#: Puc/v5p4/Vcs/PluginUpdateChecker.php:100
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Δεν υπάρχει διαθέσιμο αρχείο αλλαγών."
|
||||
Binary file not shown.
|
|
@ -1,38 +1,50 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2016-02-17 14:21+0100\n"
|
||||
"PO-Revision-Date: 2016-10-28 14:30+0330\n"
|
||||
"Last-Translator: studio RVOLA <hello@rvola.com>\n"
|
||||
"Language-Team: Pro Style <info@prostyle.ir>\n"
|
||||
"POT-Creation-Date: 2025-06-12 23:40+0100\n"
|
||||
"PO-Revision-Date: 2025-06-12 23:49+0100\n"
|
||||
"Last-Translator: Pro Style <info@prostyle.ir>\n"
|
||||
"Language-Team: Alex Javadi <alex@aljm.org>\n"
|
||||
"Language: fa_IR\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 1.8.8\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
"X-Generator: Poedit 3.6\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: github-checker.php:120
|
||||
msgid "There is no changelog available."
|
||||
msgstr "شرحی برای تغییرات یافت نشد"
|
||||
#: Puc/v5p6/Plugin/Ui.php:56
|
||||
msgid "View details"
|
||||
msgstr "مشاهده جزئیات"
|
||||
|
||||
#: plugin-update-checker.php:637
|
||||
#: Puc/v5p6/Plugin/Ui.php:79
|
||||
#, php-format
|
||||
msgid "More information about %s"
|
||||
msgstr "اطلاعات بیشتر درباره %s"
|
||||
|
||||
# It had some “potential” grammar issues and also didn’t sound native.
|
||||
# P.S. I know the current translation is literally “Checking for new updates”, however, I thought it might sound more natural and known to others.
|
||||
#: Puc/v5p6/Plugin/Ui.php:130
|
||||
msgid "Check for updates"
|
||||
msgstr "بررسی برای بروزرسانی "
|
||||
msgstr "بررسی بروزرسانی جدید"
|
||||
|
||||
#: plugin-update-checker.php:681
|
||||
msgid "This plugin is up to date."
|
||||
msgstr "شما از آخرین نسخه استفاده میکنید . بهروز باشید"
|
||||
|
||||
#: plugin-update-checker.php:683
|
||||
msgid "A new version of this plugin is available."
|
||||
msgstr "نسخه جدیدی برای افزونه ارائه شده است ."
|
||||
|
||||
#: plugin-update-checker.php:685
|
||||
# The word “ناشناخته” is seems to be translated directly from the word (Un-known), rather than checking for the context.
|
||||
# I think “نامشخص” (unknown) might be a suitable version in this scenario.
|
||||
#: Puc/v5p6/Plugin/Ui.php:227
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "وضعیت ناشناخته برای بروزرسانی \"%s\""
|
||||
msgstr "وضعیت نامشخص برای بروزرسانی \"%s\""
|
||||
|
||||
# The previous translation was okay, however, it didn’t sound native to me.
|
||||
#: Puc/v5p6/Vcs/PluginUpdateChecker.php:113
|
||||
msgid "There is no changelog available."
|
||||
msgstr "آخرین تغییراتی یافت نشد."
|
||||
|
||||
#~ msgid "This plugin is up to date."
|
||||
#~ msgstr "شما از آخرین نسخه استفاده میکنید . بهروز باشید"
|
||||
|
||||
#~ msgid "A new version of this plugin is available."
|
||||
#~ msgstr "نسخه جدیدی برای افزونه ارائه شده است ."
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,57 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2024-12-09 11:45+0100\n"
|
||||
"PO-Revision-Date: 2024-12-09 12:20+0100\n"
|
||||
"Last-Translator: Aleksandar Urošević <urke.kg@gmail.com>\n"
|
||||
"Language-Team: \n"
|
||||
"Language: sr_RS\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Generator: Poedit 2.4.3\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:56
|
||||
msgid "View details"
|
||||
msgstr "Види детаље"
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:79
|
||||
#, php-format
|
||||
msgid "More information about %s"
|
||||
msgstr "Више информација о %s"
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:130
|
||||
msgid "Check for updates"
|
||||
msgstr "Провера ажурирања"
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "Додатак %s је у најновијем издању."
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:219
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "Доступно је ново издање за %s."
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:221
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "Није могуће утврдити да ли су доступне исправке за %s."
|
||||
|
||||
#: Puc/v5p5/Plugin/Ui.php:227
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "Непознат статус провере ажурирања \"%s\""
|
||||
|
||||
#: Puc/v5p5/Vcs/PluginUpdateChecker.php:113
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Белешке о изменама нису доступне."
|
||||
Binary file not shown.
|
|
@ -1,57 +1,57 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2022-01-29 12:09+0800\n"
|
||||
"PO-Revision-Date: 2022-01-29 12:10+0800\n"
|
||||
"POT-Creation-Date: 2025-11-21 10:40+0800\n"
|
||||
"PO-Revision-Date: 2025-11-21 10:40+0800\n"
|
||||
"Last-Translator: Seaton Jiang <hi@seatonjiang.com>\n"
|
||||
"Language-Team: \n"
|
||||
"Language: zh_CN\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 2.4.3\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||
"X-Generator: Poedit 3.8\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:54
|
||||
#: Puc/v5p6/Plugin/Ui.php:56
|
||||
msgid "View details"
|
||||
msgstr "查看详情"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:77
|
||||
#: Puc/v5p6/Plugin/Ui.php:79
|
||||
#, php-format
|
||||
msgid "More information about %s"
|
||||
msgstr "%s 的更多信息"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:128
|
||||
#: Puc/v5p6/Plugin/Ui.php:130
|
||||
msgid "Check for updates"
|
||||
msgstr "检查更新"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:214
|
||||
#: Puc/v5p6/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "%s 目前是最新版本。"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:216
|
||||
#: Puc/v5p6/Plugin/Ui.php:219
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "%s 当前有可用的更新。"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:218
|
||||
#: Puc/v5p6/Plugin/Ui.php:221
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "%s 无法确定是否有可用的更新。"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:224
|
||||
#: Puc/v5p6/Plugin/Ui.php:227
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "未知的更新检查状态:%s"
|
||||
|
||||
#: Puc/v4p11/Vcs/PluginUpdateChecker.php:100
|
||||
#: Puc/v5p6/Vcs/PluginUpdateChecker.php:113
|
||||
msgid "There is no changelog available."
|
||||
msgstr "没有可用的更新日志。"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,66 @@
|
|||
# Blank Plugin POT Template
|
||||
# Copyright 2025 ...
|
||||
# This file is distributed under the GNU General Public License v3 or later.
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Plugin Update Checker\n"
|
||||
"Report-Msgid-Bugs-To: Alex Lion <learnwithalex@gmail.com>\n"
|
||||
"POT-Creation-Date: 2025-09-19 14:05-0700\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: Alex Lion <learnwithalex@gmail.com>\n"
|
||||
"Language-Team: Alex Lion <learnwithalex@gmail.com>\n"
|
||||
"Language: zh_TW\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||
"X-Poedit-WPHeader: plugin-update-checker.php\n"
|
||||
"X-Textdomain-Support: yesX-Generator: Poedit 1.6.4\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: "
|
||||
"__;_e;esc_html_e;esc_html_x:1,2c;esc_html__;esc_attr_e;esc_attr_x:1,2c;esc_attr__;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2;_n_noop:1,2;__ngettext:1,2;__ngettext_noop:1,2;_c,_nc:4c,1,2\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"X-Poedit-Bookmarks: \n"
|
||||
"X-Generator: Poedit 3.7\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:56
|
||||
msgid "View details"
|
||||
msgstr "檢視詳細資料"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:79
|
||||
#, php-format
|
||||
msgid "More information about %s"
|
||||
msgstr "進一步了解 %s 的相關資訊"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:130
|
||||
msgid "Check for updates"
|
||||
msgstr "檢查更新"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "%s 外掛已為最新版本。"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:219
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "%s 外掛已有新版本可供更新。"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:221
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "無法確定 %s 是否有可用的更新。"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:227
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "未知的更新檢查程式狀態: %s"
|
||||
|
||||
#: Puc/v5p6/Vcs/PluginUpdateChecker.php:113
|
||||
msgid "There is no changelog available."
|
||||
msgstr "目前沒有可供檢閱的變更記錄。"
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2022-07-29 15:34+0300\n"
|
||||
"POT-Creation-Date: 2025-05-20 15:27+0300\n"
|
||||
"PO-Revision-Date: 2016-01-10 20:59+0100\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
|
@ -11,39 +11,39 @@ msgstr ""
|
|||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Generator: Poedit 3.1.1\n"
|
||||
"X-Generator: Poedit 3.6\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v5p0/Plugin/Ui.php:128
|
||||
#: Puc/v5p6/Plugin/Ui.php:130
|
||||
msgid "Check for updates"
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p0/Plugin/Ui.php:214
|
||||
#: Puc/v5p6/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p0/Plugin/Ui.php:216
|
||||
#: Puc/v5p6/Plugin/Ui.php:219
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p0/Plugin/Ui.php:218
|
||||
#: Puc/v5p6/Plugin/Ui.php:221
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p0/Plugin/Ui.php:224
|
||||
#: Puc/v5p6/Plugin/Ui.php:227
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p0/Vcs/PluginUpdateChecker.php:100
|
||||
#: Puc/v5p6/Vcs/PluginUpdateChecker.php:113
|
||||
msgid "There is no changelog available."
|
||||
msgstr ""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2017 Jānis Elsts
|
||||
Copyright (c) 2023 Jānis Elsts
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory as MajorFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p0\PucFactory as MinorFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\PucFactory as MinorFactory;
|
||||
|
||||
require __DIR__ . '/Puc/v5p0/Autoloader.php';
|
||||
require __DIR__ . '/Puc/v5p6/Autoloader.php';
|
||||
new Autoloader();
|
||||
|
||||
require __DIR__ . '/Puc/v5p0/PucFactory.php';
|
||||
require __DIR__ . '/Puc/v5p6/PucFactory.php';
|
||||
require __DIR__ . '/Puc/v5/PucFactory.php';
|
||||
|
||||
//Register classes defined in this version with the factory.
|
||||
|
|
@ -26,9 +26,9 @@ foreach (
|
|||
)
|
||||
as $pucGeneralClass => $pucVersionedClass
|
||||
) {
|
||||
MajorFactory::addVersion($pucGeneralClass, $pucVersionedClass, '5.0');
|
||||
MajorFactory::addVersion($pucGeneralClass, $pucVersionedClass, '5.6');
|
||||
//Also add it to the minor-version factory in case the major-version factory
|
||||
//was already defined by another, older version of the update checker.
|
||||
MinorFactory::addVersion($pucGeneralClass, $pucVersionedClass, '5.0');
|
||||
MinorFactory::addVersion($pucGeneralClass, $pucVersionedClass, '5.6');
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="PUC_PHPCS_Settings">
|
||||
<description>PHPCS settings for Plugin Update Checker</description>
|
||||
|
||||
<arg name="basepath" value="."/>
|
||||
<arg name="warning-severity" value="5"/>
|
||||
<arg name="error-severity" value="5"/>
|
||||
<arg value="sp"/>
|
||||
|
||||
<!-- Check the current directory by default -->
|
||||
<file>./</file>
|
||||
|
||||
<!-- Include the WordPress-VIP-Go standard -->
|
||||
<rule ref="WordPress-VIP-Go">
|
||||
<!-- This library is not exclusive to WP VIP, so it doesn't use vip_safe_wp_remote_get() and such. -->
|
||||
<exclude name="WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get" />
|
||||
</rule>
|
||||
|
||||
<!-- Exclude external and third-party libraries -->
|
||||
<exclude-pattern type="relative">^vendor/*</exclude-pattern>
|
||||
</ruleset>
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Update Checker Library 5.0
|
||||
* Plugin Update Checker Library 5.6
|
||||
* http://w-shadow.com/
|
||||
*
|
||||
* Copyright 2022 Janis Elsts
|
||||
* Copyright 2025 Janis Elsts
|
||||
* Released under the MIT license. See license.txt for details.
|
||||
*/
|
||||
|
||||
require dirname(__FILE__) . '/load-v5p0.php';
|
||||
require dirname(__FILE__) . '/load-v5p6.php';
|
||||
|
|
@ -648,7 +648,7 @@ class Parsedown
|
|||
#
|
||||
# Setext
|
||||
|
||||
protected function blockSetextHeader($Line, array $Block = null)
|
||||
protected function blockSetextHeader($Line, $Block = null)
|
||||
{
|
||||
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
||||
{
|
||||
|
|
@ -786,7 +786,7 @@ class Parsedown
|
|||
#
|
||||
# Table
|
||||
|
||||
protected function blockTable($Line, array $Block = null)
|
||||
protected function blockTable($Line, $Block = null)
|
||||
{
|
||||
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -241,7 +241,11 @@ class PucReadmeParser {
|
|||
}
|
||||
|
||||
function sanitize_text( $text ) { // not fancy
|
||||
$text = strip_tags($text);
|
||||
$text = function_exists('wp_strip_all_tags')
|
||||
? wp_strip_all_tags($text)
|
||||
//phpcs:ignore WordPressVIPMinimum.Functions.StripTags.StripTagsOneParameter -- Using wp_strip_all_tags() if available
|
||||
: strip_tags($text);
|
||||
|
||||
$text = esc_html($text);
|
||||
$text = trim($text);
|
||||
return $text;
|
||||
|
|
|
|||
Loading…
Reference in New Issue