Compare commits
No commits in common. "master" and "v4.10" have entirely different histories.
|
|
@ -1,6 +0,0 @@
|
|||
/.editorconfig export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/build/ export-ignore
|
||||
/examples/ export-ignore
|
||||
/phpcs.xml export-ignore
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
if ( !class_exists('Puc_v4_Factory', false) ):
|
||||
|
||||
class Puc_v4_Factory extends Puc_v4p10_Factory { }
|
||||
|
||||
endif;
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
if ( !class_exists('Puc_v4p10_Autoloader', false) ):
|
||||
|
||||
class Puc_v4p10_Autoloader {
|
||||
private $prefix = '';
|
||||
private $rootDir = '';
|
||||
private $libraryDir = '';
|
||||
|
||||
private $staticMap;
|
||||
|
||||
public function __construct() {
|
||||
$this->rootDir = dirname(__FILE__) . '/';
|
||||
$nameParts = explode('_', __CLASS__, 3);
|
||||
$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
|
||||
|
||||
$this->libraryDir = $this->rootDir . '../..';
|
||||
if ( !self::isPhar() ) {
|
||||
$this->libraryDir = realpath($this->libraryDir);
|
||||
}
|
||||
$this->libraryDir = $this->libraryDir . '/';
|
||||
|
||||
$this->staticMap = array(
|
||||
'PucReadmeParser' => 'vendor/PucReadmeParser.php',
|
||||
'Parsedown' => 'vendor/Parsedown.php',
|
||||
'Puc_v4_Factory' => 'Puc/v4/Factory.php',
|
||||
);
|
||||
|
||||
spl_autoload_register(array($this, 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this file is running as part of a Phar archive.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isPhar() {
|
||||
//Check if the current file path starts with "phar://".
|
||||
static $pharProtocol = 'phar://';
|
||||
return (substr(__FILE__, 0, strlen($pharProtocol)) === $pharProtocol);
|
||||
}
|
||||
|
||||
public function autoload($className) {
|
||||
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include ($this->libraryDir . $this->staticMap[$className]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($className, $this->prefix) === 0) {
|
||||
$path = substr($className, strlen($this->prefix));
|
||||
$path = str_replace('_', '/', $path);
|
||||
$path = $this->rootDir . $path . '.php';
|
||||
|
||||
if (file_exists($path)) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,17 +1,12 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
if ( !class_exists('Puc_v4p10_DebugBar_Extension', false) ):
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\PucFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\UpdateChecker;
|
||||
|
||||
if ( !class_exists(Extension::class, false) ):
|
||||
|
||||
class Extension {
|
||||
class Puc_v4p10_DebugBar_Extension {
|
||||
const RESPONSE_BODY_LENGTH_LIMIT = 4000;
|
||||
|
||||
/** @var UpdateChecker */
|
||||
/** @var Puc_v4p10_UpdateChecker */
|
||||
protected $updateChecker;
|
||||
protected $panelClass = Panel::class;
|
||||
protected $panelClass = 'Puc_v4p10_DebugBar_Panel';
|
||||
|
||||
public function __construct($updateChecker, $panelClass = null) {
|
||||
$this->updateChecker = $updateChecker;
|
||||
|
|
@ -19,14 +14,10 @@ if ( !class_exists(Extension::class, false) ):
|
|||
$this->panelClass = $panelClass;
|
||||
}
|
||||
|
||||
if ( (strpos($this->panelClass, '\\') === false) ) {
|
||||
$this->panelClass = __NAMESPACE__ . '\\' . $this->panelClass;
|
||||
}
|
||||
|
||||
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
||||
add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
|
||||
|
||||
add_action('wp_ajax_puc_v5_debug_check_now', array($this, 'ajaxCheckNow'));
|
||||
add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -47,17 +38,17 @@ if ( !class_exists(Extension::class, false) ):
|
|||
*/
|
||||
public function enqueuePanelDependencies() {
|
||||
wp_enqueue_style(
|
||||
'puc-debug-bar-style-v5',
|
||||
'puc-debug-bar-style-v4',
|
||||
$this->getLibraryUrl("/css/puc-debug-bar.css"),
|
||||
array('debug-bar'),
|
||||
'20221008'
|
||||
'20171124'
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'puc-debug-bar-js-v5',
|
||||
'puc-debug-bar-js-v4',
|
||||
$this->getLibraryUrl("/js/debug-bar.js"),
|
||||
array('jquery'),
|
||||
'20221008'
|
||||
'20170516'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -66,16 +57,14 @@ if ( !class_exists(Extension::class, false) ):
|
|||
* the update checking process works as expected.
|
||||
*/
|
||||
public function ajaxCheckNow() {
|
||||
//phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is checked in preAjaxRequest().
|
||||
if ( !isset($_POST['uid']) || ($_POST['uid'] !== $this->updateChecker->getUniqueName('uid')) ) {
|
||||
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
|
||||
return;
|
||||
}
|
||||
$this->preAjaxRequest();
|
||||
$update = $this->updateChecker->checkForUpdates();
|
||||
if ( $update !== null ) {
|
||||
echo "An update is available:";
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- For debugging output.
|
||||
echo '<pre>', esc_html(print_r($update, true)), '</pre>';
|
||||
echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
|
||||
} else {
|
||||
echo 'No updates found.';
|
||||
}
|
||||
|
|
@ -86,8 +75,8 @@ if ( !class_exists(Extension::class, false) ):
|
|||
|
||||
foreach (array_values($errors) as $num => $item) {
|
||||
$wpError = $item['error'];
|
||||
/** @var \WP_Error $wpError */
|
||||
printf('<h4>%d) %s</h4>', intval($num + 1), esc_html($wpError->get_error_message()));
|
||||
/** @var WP_Error $wpError */
|
||||
printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
|
||||
|
||||
echo '<dl>';
|
||||
printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
|
||||
|
|
@ -99,7 +88,7 @@ if ( !class_exists(Extension::class, false) ):
|
|||
if ( isset($item['httpResponse']) ) {
|
||||
if ( is_wp_error($item['httpResponse']) ) {
|
||||
$httpError = $item['httpResponse'];
|
||||
/** @var \WP_Error $httpError */
|
||||
/** @var WP_Error $httpError */
|
||||
printf(
|
||||
'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
|
||||
esc_html($httpError->get_error_message()),
|
||||
|
|
@ -109,8 +98,8 @@ if ( !class_exists(Extension::class, false) ):
|
|||
//Status code.
|
||||
printf(
|
||||
'<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
|
||||
esc_html(wp_remote_retrieve_response_code($item['httpResponse'])),
|
||||
esc_html(wp_remote_retrieve_response_message($item['httpResponse']))
|
||||
wp_remote_retrieve_response_code($item['httpResponse']),
|
||||
wp_remote_retrieve_response_message($item['httpResponse'])
|
||||
);
|
||||
|
||||
//Headers.
|
||||
|
|
@ -149,9 +138,7 @@ if ( !class_exists(Extension::class, false) ):
|
|||
}
|
||||
check_ajax_referer('puc-ajax');
|
||||
|
||||
//phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting -- Part of a debugging feature.
|
||||
error_reporting(E_ALL);
|
||||
//phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted
|
||||
@ini_set('display_errors', 'On');
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +148,7 @@ if ( !class_exists(Extension::class, false) ):
|
|||
public function removeHooks() {
|
||||
remove_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
||||
remove_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
|
||||
remove_action('wp_ajax_puc_v5_debug_check_now', array($this, 'ajaxCheckNow'));
|
||||
remove_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -172,11 +159,11 @@ if ( !class_exists(Extension::class, false) ):
|
|||
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
|
||||
|
||||
//Where is the library located inside the WordPress directory structure?
|
||||
$absolutePath = PucFactory::normalizePath($absolutePath);
|
||||
$absolutePath = Puc_v4p10_Factory::normalizePath($absolutePath);
|
||||
|
||||
$pluginDir = PucFactory::normalizePath(WP_PLUGIN_DIR);
|
||||
$muPluginDir = PucFactory::normalizePath(WPMU_PLUGIN_DIR);
|
||||
$themeDir = PucFactory::normalizePath(get_theme_root());
|
||||
$pluginDir = Puc_v4p10_Factory::normalizePath(WP_PLUGIN_DIR);
|
||||
$muPluginDir = Puc_v4p10_Factory::normalizePath(WPMU_PLUGIN_DIR);
|
||||
$themeDir = Puc_v4p10_Factory::normalizePath(get_theme_root());
|
||||
|
||||
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
||||
//It's part of a plugin.
|
||||
|
|
@ -1,12 +1,9 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\UpdateChecker;
|
||||
if ( !class_exists('Puc_v4p10_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
|
||||
|
||||
if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false) ):
|
||||
|
||||
class Panel extends \Debug_Bar_Panel {
|
||||
/** @var UpdateChecker */
|
||||
class Puc_v4p10_DebugBar_Panel extends Debug_Bar_Panel {
|
||||
/** @var Puc_v4p10_UpdateChecker */
|
||||
protected $updateChecker;
|
||||
|
||||
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
||||
|
|
@ -23,7 +20,7 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
|
||||
public function render() {
|
||||
printf(
|
||||
'<div class="puc-debug-bar-panel-v5" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
|
||||
'<div class="puc-debug-bar-panel-v4" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
|
||||
esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
|
||||
esc_attr($this->updateChecker->slug),
|
||||
esc_attr($this->updateChecker->getUniqueName('uid')),
|
||||
|
|
@ -41,11 +38,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', esc_html($this->updateChecker->slug));
|
||||
$this->row('DB option', esc_html($this->updateChecker->optionName));
|
||||
$this->row('Slug', htmlentities($this->updateChecker->slug));
|
||||
$this->row('DB option', htmlentities($this->updateChecker->optionName));
|
||||
|
||||
$requestInfoButton = $this->getMetadataButton();
|
||||
$this->row('Metadata URL', esc_html($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
|
||||
$this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
|
||||
|
||||
$scheduler = $this->updateChecker->scheduler;
|
||||
if ( $scheduler->checkPeriod > 0 ) {
|
||||
|
|
@ -86,22 +83,14 @@ 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();
|
||||
$checkButtonId = $this->updateChecker->getUniqueName('check-now-button');
|
||||
$checkNowButton = '';
|
||||
if ( function_exists('get_submit_button') ) {
|
||||
$checkNowButton = get_submit_button(
|
||||
'Check Now',
|
||||
'secondary',
|
||||
'puc-check-now-button',
|
||||
false,
|
||||
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')
|
||||
array('id' => $this->updateChecker->getUniqueName('check-now-button'))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -115,10 +104,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', esc_html($state->getCheckedVersion()));
|
||||
$this->row('Checked version', htmlentities($state->getCheckedVersion()));
|
||||
$this->row('Cached update', $state->getUpdate());
|
||||
}
|
||||
$this->row('Update checker class', esc_html(get_class($this->updateChecker)));
|
||||
$this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
|
|
@ -130,10 +119,7 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
$fields = $this->getUpdateFields();
|
||||
foreach($fields as $field) {
|
||||
if ( property_exists($update, $field) ) {
|
||||
$this->row(
|
||||
ucwords(str_replace('_', ' ', $field)),
|
||||
isset($update->$field) ? esc_html($update->$field) : null
|
||||
);
|
||||
$this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
|
|
@ -168,18 +154,11 @@ if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false
|
|||
|
||||
public function row($name, $value) {
|
||||
if ( is_object($value) || is_array($value) ) {
|
||||
//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>';
|
||||
$value = '<pre>' . htmlentities(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>',
|
||||
esc_html($name),
|
||||
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above.
|
||||
$value
|
||||
);
|
||||
printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
if ( !class_exists('Puc_v4p10_DebugBar_PluginExtension', false) ):
|
||||
|
||||
class Puc_v4p10_DebugBar_PluginExtension extends Puc_v4p10_DebugBar_Extension {
|
||||
/** @var Puc_v4p10_Plugin_UpdateChecker */
|
||||
protected $updateChecker;
|
||||
|
||||
public function __construct($updateChecker) {
|
||||
parent::__construct($updateChecker, 'Puc_v4p10_DebugBar_PluginPanel');
|
||||
|
||||
add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request plugin info and output it.
|
||||
*/
|
||||
public function ajaxRequestInfo() {
|
||||
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
|
||||
return;
|
||||
}
|
||||
$this->preAjaxRequest();
|
||||
$info = $this->updateChecker->requestInfo();
|
||||
if ( $info !== null ) {
|
||||
echo 'Successfully retrieved plugin info from the metadata URL:';
|
||||
echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
|
||||
} else {
|
||||
echo 'Failed to retrieve plugin info from the metadata URL.';
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
if ( !class_exists('Puc_v4p10_DebugBar_PluginPanel', false) ):
|
||||
|
||||
class Puc_v4p10_DebugBar_PluginPanel extends Puc_v4p10_DebugBar_Panel {
|
||||
/**
|
||||
* @var Puc_v4p10_Plugin_UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
protected function displayConfigHeader() {
|
||||
$this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
|
||||
parent::displayConfigHeader();
|
||||
}
|
||||
|
||||
protected function getMetadataButton() {
|
||||
$requestInfoButton = '';
|
||||
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'))
|
||||
);
|
||||
}
|
||||
return $requestInfoButton;
|
||||
}
|
||||
|
||||
protected function getUpdateFields() {
|
||||
return array_merge(
|
||||
parent::getUpdateFields(),
|
||||
array('homepage', 'upgrade_notice', 'tested',)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
if ( !class_exists('Puc_v4p10_DebugBar_ThemePanel', false) ):
|
||||
|
||||
class Puc_v4p10_DebugBar_ThemePanel extends Puc_v4p10_DebugBar_Panel {
|
||||
/**
|
||||
* @var Puc_v4p10_Theme_UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
protected function displayConfigHeader() {
|
||||
$this->row('Theme directory', htmlentities($this->updateChecker->directoryName));
|
||||
parent::displayConfigHeader();
|
||||
}
|
||||
|
||||
protected function getUpdateFields() {
|
||||
return array_merge(parent::getUpdateFields(), array('details_url'));
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,12 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !class_exists(PucFactory::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Factory', false) ):
|
||||
|
||||
/**
|
||||
* A factory that builds update checker instances.
|
||||
|
|
@ -18,7 +11,7 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
* At the moment it can only build instances of the UpdateChecker class. Other classes are
|
||||
* intended mainly for internal use and refer directly to specific implementations.
|
||||
*/
|
||||
class PucFactory {
|
||||
class Puc_v4p10_Factory {
|
||||
protected static $classVersions = array();
|
||||
protected static $sorted = false;
|
||||
|
||||
|
|
@ -30,7 +23,7 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
*
|
||||
* @param string $fullPath Full path to the main plugin file or the theme's style.css.
|
||||
* @param array $args Optional arguments. Keys should match the argument names of the buildUpdateChecker() method.
|
||||
* @return Plugin\UpdateChecker|Theme\UpdateChecker|Vcs\BaseChecker
|
||||
* @return Puc_v4p10_Plugin_UpdateChecker|Puc_v4p10_Theme_UpdateChecker|Puc_v4p10_Vcs_BaseChecker
|
||||
*/
|
||||
public static function buildFromHeader($fullPath, $args = array()) {
|
||||
$fullPath = self::normalizePath($fullPath);
|
||||
|
|
@ -51,6 +44,7 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
$metadataUrl = self::getServiceURI($fullPath);
|
||||
}
|
||||
|
||||
/** @noinspection PhpUndefinedVariableInspection These variables are created by extract(), above. */
|
||||
return self::buildUpdateChecker($metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile);
|
||||
}
|
||||
|
||||
|
|
@ -60,15 +54,15 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
* This method automatically detects if you're using it for a plugin or a theme and chooses
|
||||
* the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
|
||||
*
|
||||
* @see UpdateChecker::__construct
|
||||
* @see Puc_v4p10_UpdateChecker::__construct
|
||||
*
|
||||
* @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
|
||||
* @param string $fullPath Full path to the main plugin file or to the theme directory.
|
||||
* @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
|
||||
* @param int $checkPeriod How often to check for updates (in hours).
|
||||
* @param string $optionName Where to store bookkeeping info about update checks.
|
||||
* @param string $optionName Where to store book-keeping info about update checks.
|
||||
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
|
||||
* @return Plugin\UpdateChecker|Theme\UpdateChecker|Vcs\BaseChecker
|
||||
* @return Puc_v4p10_Plugin_UpdateChecker|Puc_v4p10_Theme_UpdateChecker|Puc_v4p10_Vcs_BaseChecker
|
||||
*/
|
||||
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
||||
$fullPath = self::normalizePath($fullPath);
|
||||
|
|
@ -83,10 +77,10 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
$type = 'Theme';
|
||||
$id = $themeDirectory;
|
||||
} else {
|
||||
throw new \RuntimeException(sprintf(
|
||||
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.',
|
||||
esc_html($fullPath)
|
||||
htmlentities($fullPath)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -96,25 +90,25 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
$apiClass = null;
|
||||
if ( empty($service) ) {
|
||||
//The default is to get update information from a remote JSON file.
|
||||
$checkerClass = $type . '\\UpdateChecker';
|
||||
$checkerClass = $type . '_UpdateChecker';
|
||||
} else {
|
||||
//You can also use a VCS repository like GitHub.
|
||||
$checkerClass = 'Vcs\\' . $type . 'UpdateChecker';
|
||||
$checkerClass = 'Vcs_' . $type . 'UpdateChecker';
|
||||
$apiClass = $service . 'Api';
|
||||
}
|
||||
|
||||
$checkerClass = self::getCompatibleClassVersion($checkerClass);
|
||||
if ( $checkerClass === null ) {
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||
trigger_error(
|
||||
esc_html(sprintf(
|
||||
sprintf(
|
||||
'PUC %s does not support updates for %ss %s',
|
||||
self::$latestCompatibleVersion,
|
||||
htmlentities(self::$latestCompatibleVersion),
|
||||
strtolower($type),
|
||||
$service ? ('hosted on ' . $service) : 'using JSON metadata'
|
||||
)),
|
||||
$service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
|
||||
),
|
||||
E_USER_ERROR
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( !isset($apiClass) ) {
|
||||
|
|
@ -124,12 +118,12 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
//VCS checker + an API client.
|
||||
$apiClass = self::getCompatibleClassVersion($apiClass);
|
||||
if ( $apiClass === null ) {
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||
trigger_error(esc_html(sprintf(
|
||||
trigger_error(sprintf(
|
||||
'PUC %s does not support %s',
|
||||
self::$latestCompatibleVersion,
|
||||
$service
|
||||
)), E_USER_ERROR);
|
||||
htmlentities(self::$latestCompatibleVersion),
|
||||
htmlentities($service)
|
||||
), E_USER_ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new $checkerClass(
|
||||
|
|
@ -147,7 +141,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.6)
|
||||
* This version adapted from WP 4.8.2 (unchanged since 4.5.0)
|
||||
*
|
||||
* @param string $path Path to normalize.
|
||||
* @return string Normalized path.
|
||||
|
|
@ -238,8 +232,8 @@ 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"', esc_html($fullPath))
|
||||
throw new RuntimeException(
|
||||
sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -253,8 +247,8 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
$service = null;
|
||||
|
||||
//Which hosting service does the URL point to?
|
||||
$host = (string)(wp_parse_url($metadataUrl, PHP_URL_HOST));
|
||||
$path = (string)(wp_parse_url($metadataUrl, PHP_URL_PATH));
|
||||
$host = parse_url($metadataUrl, PHP_URL_HOST);
|
||||
$path = parse_url($metadataUrl, PHP_URL_PATH);
|
||||
|
||||
//Check if the path looks like "/user-name/repository".
|
||||
//For GitLab.com it can also be "/user/group1/group2/.../repository".
|
||||
|
|
@ -334,8 +328,8 @@ if ( !class_exists(PucFactory::class, false) ):
|
|||
*/
|
||||
public static function addVersion($generalClass, $versionedClass, $version) {
|
||||
if ( empty(self::$myMajorVersion) ) {
|
||||
$lastNamespaceSegment = substr(__NAMESPACE__, strrpos(__NAMESPACE__, '\\') + 1);
|
||||
self::$myMajorVersion = substr(ltrim($lastNamespaceSegment, 'v'), 0, 1);
|
||||
$nameParts = explode('_', __CLASS__, 3);
|
||||
self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
|
||||
}
|
||||
|
||||
//Store the greatest version number that matches our major version.
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(InstalledPackage::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_InstalledPackage', false) ):
|
||||
|
||||
/**
|
||||
* This class represents a currently installed plugin or theme.
|
||||
|
|
@ -9,9 +7,9 @@ if ( !class_exists(InstalledPackage::class, false) ):
|
|||
* Not to be confused with the "package" field in WP update API responses that contains
|
||||
* the download URL of a the new version.
|
||||
*/
|
||||
abstract class InstalledPackage {
|
||||
abstract class Puc_v4p10_InstalledPackage {
|
||||
/**
|
||||
* @var UpdateChecker
|
||||
* @var Puc_v4p10_UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
|
|
@ -1,11 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use LogicException;
|
||||
use stdClass;
|
||||
use WP_Error;
|
||||
|
||||
if ( !class_exists(Metadata::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Metadata', false) ):
|
||||
|
||||
/**
|
||||
* A base container for holding information about updates and plugin metadata.
|
||||
|
|
@ -14,13 +8,7 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
* @copyright 2016
|
||||
* @access public
|
||||
*/
|
||||
abstract class Metadata {
|
||||
/**
|
||||
* Additional dynamic properties, usually copied from the API response.
|
||||
*
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
protected $extraProperties = array();
|
||||
abstract class Puc_v4p10_Metadata {
|
||||
|
||||
/**
|
||||
* Create an instance of this class from a JSON document.
|
||||
|
|
@ -29,7 +17,7 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
* @param string $json
|
||||
* @return self
|
||||
*/
|
||||
public static function fromJson($json) {
|
||||
public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
|
||||
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
||||
}
|
||||
|
||||
|
|
@ -39,21 +27,19 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
* @return bool
|
||||
*/
|
||||
protected static function createFromJson($json, $target) {
|
||||
/** @var \StdClass $apiResponse */
|
||||
/** @var StdClass $apiResponse */
|
||||
$apiResponse = json_decode($json);
|
||||
if ( empty($apiResponse) || !is_object($apiResponse) ){
|
||||
$errorMessage = "Failed to parse update metadata. Try validating your .json file with https://jsonlint.com/";
|
||||
$errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
|
||||
do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- For plugin developers.
|
||||
trigger_error(esc_html($errorMessage), E_USER_NOTICE);
|
||||
trigger_error($errorMessage, E_USER_NOTICE);
|
||||
return false;
|
||||
}
|
||||
|
||||
$valid = $target->validateMetadata($apiResponse);
|
||||
if ( is_wp_error($valid) ){
|
||||
do_action('puc_api_error', $valid);
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- For plugin developers.
|
||||
trigger_error(esc_html($valid->get_error_message()), E_USER_NOTICE);
|
||||
trigger_error($valid->get_error_message(), E_USER_NOTICE);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -67,10 +53,10 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
/**
|
||||
* No validation by default! Subclasses should check that the required fields are present.
|
||||
*
|
||||
* @param \StdClass $apiResponse
|
||||
* @return bool|\WP_Error
|
||||
* @param StdClass $apiResponse
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
protected function validateMetadata($apiResponse) {
|
||||
protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -78,10 +64,10 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
* Create a new instance by copying the necessary fields from another object.
|
||||
*
|
||||
* @abstract
|
||||
* @param \StdClass|self $object The source object.
|
||||
* @param StdClass|self $object The source object.
|
||||
* @return self The new copy.
|
||||
*/
|
||||
public static function fromObject($object) {
|
||||
public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
|
||||
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +77,7 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
* avoids the "incomplete object" problem if the cached value is loaded
|
||||
* before this class.
|
||||
*
|
||||
* @return \StdClass
|
||||
* @return StdClass
|
||||
*/
|
||||
public function toStdClass() {
|
||||
$object = new stdClass();
|
||||
|
|
@ -109,8 +95,8 @@ if ( !class_exists(Metadata::class, false) ):
|
|||
/**
|
||||
* Copy known fields from one object to another.
|
||||
*
|
||||
* @param \StdClass|self $from
|
||||
* @param \StdClass|self $to
|
||||
* @param StdClass|self $from
|
||||
* @param StdClass|self $to
|
||||
*/
|
||||
protected function copyFields($from, $to) {
|
||||
$fields = $this->getFieldNames();
|
||||
|
|
@ -141,22 +127,6 @@ 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,12 +1,11 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(OAuthSignature::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_OAuthSignature', false) ):
|
||||
|
||||
/**
|
||||
* A basic signature generator for zero-legged OAuth 1.0.
|
||||
*/
|
||||
class OAuthSignature {
|
||||
class Puc_v4p10_OAuthSignature {
|
||||
private $consumerKey = '';
|
||||
private $consumerSecret = '';
|
||||
|
||||
|
|
@ -26,10 +25,10 @@ if ( !class_exists(OAuthSignature::class, false) ):
|
|||
$parameters = array();
|
||||
|
||||
//Parse query parameters.
|
||||
$query = wp_parse_url($url, PHP_URL_QUERY);
|
||||
$query = parse_url($url, PHP_URL_QUERY);
|
||||
if ( !empty($query) ) {
|
||||
parse_str($query, $parsedParams);
|
||||
if ( is_array($parsedParams) ) {
|
||||
if ( is_array($parameters) ) {
|
||||
$parameters = $parsedParams;
|
||||
}
|
||||
//Remove the query string from the URL. We'll replace it later.
|
||||
|
|
@ -86,13 +85,12 @@ if ( !class_exists(OAuthSignature::class, false) ):
|
|||
if ( is_callable('random_bytes') ) {
|
||||
try {
|
||||
$rand = random_bytes(16);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
//Fall back to mt_rand (below).
|
||||
}
|
||||
}
|
||||
if ( $rand === null ) {
|
||||
//phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand
|
||||
$rand = function_exists('wp_rand') ? wp_rand() : mt_rand();
|
||||
$rand = mt_rand();
|
||||
}
|
||||
|
||||
return md5($mt . '_' . $rand);
|
||||
|
|
@ -1,9 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Metadata;
|
||||
|
||||
if ( !class_exists(PluginInfo::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Plugin_Info', false) ):
|
||||
|
||||
/**
|
||||
* A container class for holding and transforming various plugin metadata.
|
||||
|
|
@ -12,7 +8,7 @@ if ( !class_exists(PluginInfo::class, false) ):
|
|||
* @copyright 2016
|
||||
* @access public
|
||||
*/
|
||||
class PluginInfo extends Metadata {
|
||||
class Puc_v4p10_Plugin_Info extends Puc_v4p10_Metadata {
|
||||
//Most fields map directly to the contents of the plugin's info.json file.
|
||||
//See the relevant docs for a description of their meaning.
|
||||
public $name;
|
||||
|
|
@ -39,7 +35,6 @@ 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.
|
||||
|
||||
|
|
@ -69,8 +64,8 @@ if ( !class_exists(PluginInfo::class, false) ):
|
|||
/**
|
||||
* Very, very basic validation.
|
||||
*
|
||||
* @param \StdClass $apiResponse
|
||||
* @return bool|\WP_Error
|
||||
* @param StdClass $apiResponse
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
protected function validateMetadata($apiResponse) {
|
||||
if (
|
||||
|
|
@ -78,7 +73,7 @@ if ( !class_exists(PluginInfo::class, false) ):
|
|||
|| empty($apiResponse->name)
|
||||
|| empty($apiResponse->version)
|
||||
) {
|
||||
return new \WP_Error(
|
||||
return new WP_Error(
|
||||
'puc-invalid-metadata',
|
||||
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
||||
);
|
||||
|
|
@ -93,7 +88,7 @@ if ( !class_exists(PluginInfo::class, false) ):
|
|||
* @return object
|
||||
*/
|
||||
public function toWpFormat(){
|
||||
$info = new \stdClass;
|
||||
$info = new stdClass;
|
||||
|
||||
//The custom update API is built so that many fields have the same name and format
|
||||
//as those returned by the native WordPress.org API. These can be assigned directly.
|
||||
|
|
@ -1,14 +1,9 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
if ( !class_exists('Puc_v4p10_Plugin_Package', false) ):
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\InstalledPackage;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\PucFactory;
|
||||
|
||||
if ( !class_exists(Package::class, false) ):
|
||||
|
||||
class Package extends InstalledPackage {
|
||||
class Puc_v4p10_Plugin_Package extends Puc_v4p10_InstalledPackage {
|
||||
/**
|
||||
* @var UpdateChecker
|
||||
* @var Puc_v4p10_Plugin_UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
|
|
@ -51,7 +46,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(
|
||||
"Cannot read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
||||
"Can't to read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
||||
$this->updateChecker->pluginFile
|
||||
),
|
||||
E_USER_WARNING
|
||||
|
|
@ -145,6 +140,7 @@ if ( !class_exists(Package::class, false) ):
|
|||
}
|
||||
|
||||
if ( !function_exists('get_plugin_data') ) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
|
||||
}
|
||||
return get_plugin_data($this->pluginAbsolutePath, false, false);
|
||||
|
|
@ -174,8 +170,8 @@ if ( !class_exists(Package::class, false) ):
|
|||
$pluginPath = realpath($this->pluginAbsolutePath);
|
||||
//If realpath() fails, just normalize the syntax instead.
|
||||
if (($muPluginDir === false) || ($pluginPath === false)) {
|
||||
$muPluginDir = PucFactory::normalizePath(WPMU_PLUGIN_DIR);
|
||||
$pluginPath = PucFactory::normalizePath($this->pluginAbsolutePath);
|
||||
$muPluginDir = Puc_v4p10_Factory::normalizePath(WPMU_PLUGIN_DIR);
|
||||
$pluginPath = Puc_v4p10_Factory::normalizePath($this->pluginAbsolutePath);
|
||||
}
|
||||
|
||||
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
if ( !class_exists(Ui::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Plugin_Ui', false) ):
|
||||
/**
|
||||
* Additional UI elements for plugins.
|
||||
*/
|
||||
class Ui {
|
||||
class Puc_v4p10_Plugin_Ui {
|
||||
private $updateChecker;
|
||||
private $manualCheckErrorTransient = '';
|
||||
|
||||
/**
|
||||
* @param UpdateChecker $updateChecker
|
||||
* @param Puc_v4p10_Plugin_UpdateChecker $updateChecker
|
||||
*/
|
||||
public function __construct($updateChecker) {
|
||||
$this->updateChecker = $updateChecker;
|
||||
|
|
@ -158,9 +156,8 @@ if ( !class_exists(Ui::class, false) ):
|
|||
if ( $shouldCheck ) {
|
||||
$update = $this->updateChecker->checkForUpdates();
|
||||
$status = ($update === null) ? 'no_update' : 'update_available';
|
||||
$lastRequestApiErrors = $this->updateChecker->getLastRequestApiErrors();
|
||||
|
||||
if ( ($update === null) && !empty($lastRequestApiErrors) ) {
|
||||
if ( ($update === null) && !empty($this->lastRequestApiErrors) ) {
|
||||
//Some errors are not critical. For example, if PUC tries to retrieve the readme.txt
|
||||
//file from GitHub and gets a 404, that's an API error, but it doesn't prevent updates
|
||||
//from working. Maybe the plugin simply doesn't have a readme.
|
||||
|
|
@ -172,9 +169,9 @@ if ( !class_exists(Ui::class, false) ):
|
|||
'puc-bitbucket-http-error',
|
||||
);
|
||||
|
||||
foreach ($lastRequestApiErrors as $item) {
|
||||
foreach ($this->lastRequestApiErrors as $item) {
|
||||
$wpError = $item['error'];
|
||||
/** @var \WP_Error $wpError */
|
||||
/** @var WP_Error $wpError */
|
||||
if ( !in_array($wpError->get_error_code(), $questionableErrorCodes) ) {
|
||||
$foundCriticalErrors = true;
|
||||
break;
|
||||
|
|
@ -183,11 +180,11 @@ if ( !class_exists(Ui::class, false) ):
|
|||
|
||||
if ( $foundCriticalErrors ) {
|
||||
$status = 'error';
|
||||
set_site_transient($this->manualCheckErrorTransient, $lastRequestApiErrors, 60);
|
||||
set_site_transient($this->manualCheckErrorTransient, $this->lastRequestApiErrors, 60);
|
||||
}
|
||||
}
|
||||
|
||||
wp_safe_redirect(add_query_arg(
|
||||
wp_redirect(add_query_arg(
|
||||
array(
|
||||
'puc_update_check_result' => $status,
|
||||
'puc_slug' => $this->updateChecker->slug,
|
||||
|
|
@ -206,9 +203,8 @@ if ( !class_exists(Ui::class, false) ):
|
|||
* You can change the result message by using the "puc_manual_check_message-$slug" filter.
|
||||
*/
|
||||
public function displayManualCheckResult() {
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended -- Just displaying a message.
|
||||
if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->updateChecker->slug) ) {
|
||||
$status = sanitize_key($_GET['puc_update_check_result']);
|
||||
$status = strval($_GET['puc_update_check_result']);
|
||||
$title = $this->updateChecker->getInstalledPackage()->getPluginTitle();
|
||||
$noticeClass = 'updated notice-success';
|
||||
$details = '';
|
||||
|
|
@ -224,29 +220,16 @@ if ( !class_exists(Ui::class, false) ):
|
|||
$details = $this->formatManualCheckErrors(get_site_transient($this->manualCheckErrorTransient));
|
||||
delete_site_transient($this->manualCheckErrorTransient);
|
||||
} else {
|
||||
$message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), $status);
|
||||
$message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), htmlentities($status));
|
||||
$noticeClass = 'error notice-error';
|
||||
}
|
||||
|
||||
$message = esc_html($message);
|
||||
|
||||
//Plugins can replace the message with their own, including adding HTML.
|
||||
$message = apply_filters(
|
||||
$this->updateChecker->getUniqueName('manual_check_message'),
|
||||
$message,
|
||||
$status
|
||||
);
|
||||
|
||||
printf(
|
||||
'<div class="notice %s is-dismissible"><p>%s</p>%s</div>',
|
||||
esc_attr($noticeClass),
|
||||
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Was escaped above, and plugins can add HTML.
|
||||
$message,
|
||||
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Contains HTML. Content should already be escaped.
|
||||
$noticeClass,
|
||||
apply_filters($this->updateChecker->getUniqueName('manual_check_message'), $message, $status),
|
||||
$details
|
||||
);
|
||||
}
|
||||
//phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -270,11 +253,11 @@ if ( !class_exists(Ui::class, false) ):
|
|||
}
|
||||
foreach ($errors as $item) {
|
||||
$wpError = $item['error'];
|
||||
/** @var \WP_Error $wpError */
|
||||
/** @var WP_Error $wpError */
|
||||
$output .= sprintf(
|
||||
$formatString,
|
||||
esc_html($wpError->get_error_message()),
|
||||
esc_html($wpError->get_error_code())
|
||||
$wpError->get_error_message(),
|
||||
$wpError->get_error_code()
|
||||
);
|
||||
}
|
||||
if ( $showAsList ) {
|
||||
|
|
@ -1,9 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Update as BaseUpdate;
|
||||
|
||||
if ( !class_exists(Update::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Plugin_Update', false) ):
|
||||
|
||||
/**
|
||||
* A simple container class for holding information about an available update.
|
||||
|
|
@ -12,7 +8,7 @@ if ( !class_exists(Update::class, false) ):
|
|||
* @copyright 2016
|
||||
* @access public
|
||||
*/
|
||||
class Update extends BaseUpdate {
|
||||
class Puc_v4p10_Plugin_Update extends Puc_v4p10_Update {
|
||||
public $id = 0;
|
||||
public $homepage;
|
||||
public $upgrade_notice;
|
||||
|
|
@ -20,23 +16,22 @@ 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', 'autoupdate',
|
||||
'id', 'homepage', 'tested', 'requires_php', 'upgrade_notice', 'icons', 'filename',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new instance of PluginUpdate from its JSON-encoded representation.
|
||||
*
|
||||
* @param string $json
|
||||
* @return self|null
|
||||
* @return Puc_v4p10_Plugin_Update|null
|
||||
*/
|
||||
public static function fromJson($json){
|
||||
//Since update-related information is simply a subset of the full plugin info,
|
||||
//we can parse the update JSON as if it was a plugin info string, then copy over
|
||||
//the parts that we care about.
|
||||
$pluginInfo = PluginInfo::fromJson($json);
|
||||
$pluginInfo = Puc_v4p10_Plugin_Info::fromJson($json);
|
||||
if ( $pluginInfo !== null ) {
|
||||
return self::fromPluginInfo($pluginInfo);
|
||||
} else {
|
||||
|
|
@ -48,18 +43,18 @@ if ( !class_exists(Update::class, false) ):
|
|||
* Create a new instance of PluginUpdate based on an instance of PluginInfo.
|
||||
* Basically, this just copies a subset of fields from one object to another.
|
||||
*
|
||||
* @param PluginInfo $info
|
||||
* @return static
|
||||
* @param Puc_v4p10_Plugin_Info $info
|
||||
* @return Puc_v4p10_Plugin_Update
|
||||
*/
|
||||
public static function fromPluginInfo($info){
|
||||
return static::fromObject($info);
|
||||
return self::fromObject($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance by copying the necessary fields from another object.
|
||||
*
|
||||
* @param \StdClass|PluginInfo|self $object The source object.
|
||||
* @return self The new copy.
|
||||
* @param StdClass|Puc_v4p10_Plugin_Info|Puc_v4p10_Plugin_Update $object The source object.
|
||||
* @return Puc_v4p10_Plugin_Update The new copy.
|
||||
*/
|
||||
public static function fromObject($object) {
|
||||
$update = new self();
|
||||
|
|
@ -87,7 +82,6 @@ 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,12 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
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) ):
|
||||
if ( !class_exists('Puc_v4p10_Plugin_UpdateChecker', false) ):
|
||||
|
||||
/**
|
||||
* A custom plugin update checker.
|
||||
|
|
@ -15,16 +8,16 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* @copyright 2018
|
||||
* @access public
|
||||
*/
|
||||
class UpdateChecker extends BaseUpdateChecker {
|
||||
class Puc_v4p10_Plugin_UpdateChecker extends Puc_v4p10_UpdateChecker {
|
||||
protected $updateTransient = 'update_plugins';
|
||||
protected $componentType = 'plugin';
|
||||
protected $translationType = '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.
|
||||
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
|
||||
|
||||
/**
|
||||
* @var Package
|
||||
* @var Puc_v4p10_Plugin_Package
|
||||
*/
|
||||
protected $package;
|
||||
|
||||
|
|
@ -57,8 +50,8 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
if ( $slugUsedBy ) {
|
||||
$this->triggerError(sprintf(
|
||||
'Plugin slug "%s" is already in use by %s. Slugs must be unique.',
|
||||
$slug,
|
||||
$slugUsedBy
|
||||
htmlentities($slug),
|
||||
htmlentities($slugUsedBy)
|
||||
), E_USER_ERROR);
|
||||
}
|
||||
add_filter($slugCheckFilter, array($this, 'getAbsolutePath'));
|
||||
|
|
@ -75,17 +68,17 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
//Details: https://github.com/YahnisElsts/plugin-update-checker/issues/138#issuecomment-335590964
|
||||
add_action('uninstall_' . $this->pluginFile, array($this, 'removeHooks'));
|
||||
|
||||
$this->extraUi = new Ui($this);
|
||||
$this->extraUi = new Puc_v4p10_Plugin_Ui($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the scheduler.
|
||||
*
|
||||
* @param int $checkPeriod
|
||||
* @return Scheduler
|
||||
* @return Puc_v4p10_Scheduler
|
||||
*/
|
||||
protected function createScheduler($checkPeriod) {
|
||||
$scheduler = new Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
||||
$scheduler = new Puc_v4p10_Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
||||
register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
|
||||
return $scheduler;
|
||||
}
|
||||
|
|
@ -131,17 +124,13 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* @uses wp_remote_get()
|
||||
*
|
||||
* @param array $queryArgs Additional query arguments to append to the request. Optional.
|
||||
* @return PluginInfo
|
||||
* @return Puc_v4p10_Plugin_Info
|
||||
*/
|
||||
public function requestInfo($queryArgs = array()) {
|
||||
list($pluginInfo, $result) = $this->requestMetadata(
|
||||
PluginInfo::class,
|
||||
'request_info',
|
||||
$queryArgs
|
||||
);
|
||||
list($pluginInfo, $result) = $this->requestMetadata('Puc_v4p10_Plugin_Info', 'request_info', $queryArgs);
|
||||
|
||||
if ( $pluginInfo !== null ) {
|
||||
/** @var PluginInfo $pluginInfo */
|
||||
/** @var Puc_v4p10_Plugin_Info $pluginInfo */
|
||||
$pluginInfo->filename = $this->pluginFile;
|
||||
$pluginInfo->slug = $this->slug;
|
||||
}
|
||||
|
|
@ -153,9 +142,9 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Retrieve the latest update (if any) from the configured API endpoint.
|
||||
*
|
||||
* @uses UpdateChecker::requestInfo()
|
||||
* @uses PluginUpdateChecker::requestInfo()
|
||||
*
|
||||
* @return Update|null An instance of Plugin Update, or NULL when no updates are available.
|
||||
* @return Puc_v4p10_Update|null An instance of Plugin_Update, or NULL when no updates are available.
|
||||
*/
|
||||
public function requestUpdate() {
|
||||
//For the sake of simplicity, this function just calls requestInfo()
|
||||
|
|
@ -164,7 +153,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
if ( $pluginInfo === null ){
|
||||
return null;
|
||||
}
|
||||
$update = Update::fromPluginInfo($pluginInfo);
|
||||
$update = Puc_v4p10_Plugin_Update::fromPluginInfo($pluginInfo);
|
||||
|
||||
$update = $this->filterUpdateResult($update);
|
||||
|
||||
|
|
@ -208,9 +197,9 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $updates
|
||||
* @param \stdClass $updateToAdd
|
||||
* @return \stdClass
|
||||
* @param stdClass|null $updates
|
||||
* @param stdClass $updateToAdd
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function addUpdateToList($updates, $updateToAdd) {
|
||||
if ( $this->package->isMuPlugin() ) {
|
||||
|
|
@ -222,8 +211,8 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $updates
|
||||
* @return \stdClass|null
|
||||
* @param stdClass|null $updates
|
||||
* @return stdClass|null
|
||||
*/
|
||||
protected function removeUpdateFromList($updates) {
|
||||
$updates = parent::removeUpdateFromList($updates);
|
||||
|
|
@ -257,7 +246,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
'banners' => array(),
|
||||
'banners_rtl' => array(),
|
||||
'tested' => '',
|
||||
'compatibility' => new \stdClass(),
|
||||
'compatibility' => new stdClass(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -266,7 +255,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* Alias for isBeingUpgraded().
|
||||
*
|
||||
* @deprecated
|
||||
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @return bool
|
||||
*/
|
||||
public function isPluginBeingUpgraded($upgrader = null) {
|
||||
|
|
@ -276,7 +265,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Is there an update being installed for this plugin, right now?
|
||||
*
|
||||
* @param \WP_Upgrader|null $upgrader
|
||||
* @param WP_Upgrader|null $upgrader
|
||||
* @return bool
|
||||
*/
|
||||
public function isBeingUpgraded($upgrader = null) {
|
||||
|
|
@ -292,12 +281,12 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* Uses cached update data. To retrieve update information straight from
|
||||
* the metadata URL, call requestUpdate() instead.
|
||||
*
|
||||
* @return Update|null
|
||||
* @return Puc_v4p10_Plugin_Update|null
|
||||
*/
|
||||
public function getUpdate() {
|
||||
$update = parent::getUpdate();
|
||||
if ( isset($update) ) {
|
||||
/** @var Update $update */
|
||||
/** @var Puc_v4p10_Plugin_Update $update */
|
||||
$update->filename = $this->pluginFile;
|
||||
}
|
||||
return $update;
|
||||
|
|
@ -402,20 +391,20 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
protected function createDebugBarExtension() {
|
||||
return new DebugBar\PluginExtension($this);
|
||||
return new Puc_v4p10_DebugBar_PluginExtension($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a package instance that represents this plugin or theme.
|
||||
*
|
||||
* @return InstalledPackage
|
||||
* @return Puc_v4p10_InstalledPackage
|
||||
*/
|
||||
protected function createInstalledPackage() {
|
||||
return new Package($this->pluginAbsolutePath, $this);
|
||||
return new Puc_v4p10_Plugin_Package($this->pluginAbsolutePath, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Package
|
||||
* @return Puc_v4p10_Plugin_Package
|
||||
*/
|
||||
public function getInstalledPackage() {
|
||||
return $this->package;
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(Scheduler::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Scheduler', false) ):
|
||||
|
||||
/**
|
||||
* The scheduler decides when and how often to check for updates.
|
||||
* It calls @see UpdateChecker::checkForUpdates() to perform the actual checks.
|
||||
* It calls @see Puc_v4p10_UpdateChecker::checkForUpdates() to perform the actual checks.
|
||||
*/
|
||||
class Scheduler {
|
||||
class Puc_v4p10_Scheduler {
|
||||
public $checkPeriod = 12; //How often to check for updates (in hours).
|
||||
public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
|
||||
public $throttledCheckPeriod = 72;
|
||||
|
|
@ -15,7 +13,7 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
protected $hourlyCheckHooks = array('load-update.php');
|
||||
|
||||
/**
|
||||
* @var UpdateChecker
|
||||
* @var Puc_v4p10_UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
|
|
@ -24,7 +22,7 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
/**
|
||||
* Scheduler constructor.
|
||||
*
|
||||
* @param UpdateChecker $updateChecker
|
||||
* @param Puc_v4p10_UpdateChecker $updateChecker
|
||||
* @param int $checkPeriod How often to check for updates (in hours).
|
||||
* @param array $hourlyHooks
|
||||
*/
|
||||
|
|
@ -49,22 +47,13 @@ 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'));
|
||||
}
|
||||
|
||||
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
|
||||
//Randomly offset the schedule to help prevent update server traffic spikes. Without this
|
||||
//most checks may happen during times of day when people are most likely to install new plugins.
|
||||
$upperLimit = max($this->checkPeriod * 3600 - 15 * 60, 1);
|
||||
if ( function_exists('wp_rand') ) {
|
||||
$randomOffset = wp_rand(0, $upperLimit);
|
||||
} else {
|
||||
//This constructor may be called before wp_rand() is available.
|
||||
//phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand
|
||||
$randomOffset = rand(0, $upperLimit);
|
||||
}
|
||||
$firstCheckTime = time() - $randomOffset;
|
||||
$firstCheckTime = time() - rand(0, max($this->checkPeriod * 3600 - 15 * 60, 1));
|
||||
$firstCheckTime = apply_filters(
|
||||
$this->updateChecker->getUniqueName('first_check_time'),
|
||||
$firstCheckTime
|
||||
|
|
@ -80,14 +69,12 @@ 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 {
|
||||
|
|
@ -97,11 +84,18 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove all hooks if this version of PUC has been deleted or overwritten.
|
||||
* Runs upon the WP action upgrader_process_complete.
|
||||
*
|
||||
* Callback for the "upgrader_process_complete" action.
|
||||
* We look at the parameters to decide whether to call maybeCheckForUpdates() or not.
|
||||
* We also check if the update checker has been removed by the update.
|
||||
*
|
||||
* @param WP_Upgrader $upgrader WP_Upgrader instance
|
||||
* @param array $upgradeInfo extra information about the upgrade
|
||||
*/
|
||||
public function removeHooksIfLibraryGone() {
|
||||
public function upgraderProcessComplete(
|
||||
/** @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.
|
||||
|
|
@ -109,22 +103,9 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
if ( !file_exists(__FILE__) ) {
|
||||
$this->removeHooks();
|
||||
$this->updateChecker->removeHooks();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs upon the WP action upgrader_process_complete.
|
||||
*
|
||||
* We look at the parameters to decide whether to call maybeCheckForUpdates() or not.
|
||||
* We also check if the update checker has been removed by the update.
|
||||
*
|
||||
* @param \WP_Upgrader $upgrader WP_Upgrader instance
|
||||
* @param array $upgradeInfo extra information about the upgrade
|
||||
*/
|
||||
public function upgraderProcessComplete(
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
$upgrader, $upgradeInfo
|
||||
) {
|
||||
//Sanity check and limitation to relevant types.
|
||||
if (
|
||||
!is_array($upgradeInfo) || !isset($upgradeInfo['type'], $upgradeInfo['action'])
|
||||
|
|
@ -135,7 +116,7 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
|
||||
//Filter out notifications of upgrades that should have no bearing upon whether or not our
|
||||
//current info is up-to-date.
|
||||
if ( is_a($this->updateChecker, Theme\UpdateChecker::class) ) {
|
||||
if ( is_a($this->updateChecker, 'Puc_v4p10_Theme_UpdateChecker') ) {
|
||||
if ( 'theme' !== $upgradeInfo['type'] || !isset($upgradeInfo['themes']) ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -149,7 +130,7 @@ if ( !class_exists(Scheduler::class, false) ):
|
|||
}
|
||||
}
|
||||
|
||||
if ( is_a($this->updateChecker, Plugin\UpdateChecker::class) ) {
|
||||
if ( is_a($this->updateChecker, 'Puc_v4p10_Plugin_UpdateChecker') ) {
|
||||
if ( 'plugin' !== $upgradeInfo['type'] || !isset($upgradeInfo['plugins']) ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -187,21 +168,6 @@ 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'),
|
||||
|
|
@ -232,7 +198,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 let's do an update check even
|
||||
//WordPress cron schedules are not exact, so lets 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,9 +1,8 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(StateStore::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_StateStore', false) ):
|
||||
|
||||
class StateStore {
|
||||
class Puc_v4p10_StateStore {
|
||||
/**
|
||||
* @var int Last update check timestamp.
|
||||
*/
|
||||
|
|
@ -15,7 +14,7 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
protected $checkedVersion = '';
|
||||
|
||||
/**
|
||||
* @var Update|null Cached update.
|
||||
* @var Puc_v4p10_Update|null Cached update.
|
||||
*/
|
||||
protected $update = null;
|
||||
|
||||
|
|
@ -66,7 +65,7 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* @return null|Update
|
||||
* @return null|Puc_v4p10_Update
|
||||
*/
|
||||
public function getUpdate() {
|
||||
$this->lazyLoad();
|
||||
|
|
@ -74,10 +73,10 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Update|null $update
|
||||
* @param Puc_v4p10_Update|null $update
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdate($update = null) {
|
||||
public function setUpdate(Puc_v4p10_Update $update = null) {
|
||||
$this->lazyLoad();
|
||||
$this->update = $update;
|
||||
return $this;
|
||||
|
|
@ -128,7 +127,7 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
}
|
||||
|
||||
public function save() {
|
||||
$state = new \stdClass();
|
||||
$state = new stdClass();
|
||||
|
||||
$state->lastCheck = $this->lastCheck;
|
||||
$state->checkedVersion = $this->checkedVersion;
|
||||
|
|
@ -139,7 +138,7 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
$updateClass = get_class($this->update);
|
||||
$state->updateClass = $updateClass;
|
||||
$prefix = $this->getLibPrefix();
|
||||
if ( Utils::startsWith($updateClass, $prefix) ) {
|
||||
if ( Puc_v4p10_Utils::startsWith($updateClass, $prefix) ) {
|
||||
$state->updateBaseClass = substr($updateClass, strlen($prefix));
|
||||
}
|
||||
}
|
||||
|
|
@ -163,20 +162,15 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
|
||||
$state = get_site_option($this->optionName, null);
|
||||
|
||||
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)
|
||||
) {
|
||||
if ( !is_object($state) ) {
|
||||
$this->lastCheck = 0;
|
||||
$this->checkedVersion = '';
|
||||
$this->update = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->lastCheck = intval(Utils::get($state, 'lastCheck', 0));
|
||||
$this->checkedVersion = Utils::get($state, 'checkedVersion', '');
|
||||
$this->lastCheck = intval(Puc_v4p10_Utils::get($state, 'lastCheck', 0));
|
||||
$this->checkedVersion = Puc_v4p10_Utils::get($state, 'checkedVersion', '');
|
||||
$this->update = null;
|
||||
|
||||
if ( isset($state->update) ) {
|
||||
|
|
@ -186,13 +180,12 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
$updateClass = null;
|
||||
if ( isset($state->updateBaseClass) ) {
|
||||
$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
|
||||
} else if ( isset($state->updateClass) ) {
|
||||
} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
|
||||
$updateClass = $state->updateClass;
|
||||
}
|
||||
|
||||
$factory = array($updateClass, 'fromObject');
|
||||
if ( ($updateClass !== null) && is_callable($factory) ) {
|
||||
$this->update = call_user_func($factory, $state->update);
|
||||
if ( $updateClass !== null ) {
|
||||
$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -206,8 +199,8 @@ if ( !class_exists(StateStore::class, false) ):
|
|||
}
|
||||
|
||||
private function getLibPrefix() {
|
||||
//This assumes that the current class is at the top of the versioned namespace.
|
||||
return __NAMESPACE__ . '\\';
|
||||
$parts = explode('_', __CLASS__, 3);
|
||||
return $parts[0] . '_' . $parts[1] . '_';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,18 +1,14 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
if ( !class_exists('Puc_v4p10_Theme_Package', false) ):
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\InstalledPackage;
|
||||
|
||||
if ( !class_exists(Package::class, false) ):
|
||||
|
||||
class Package extends InstalledPackage {
|
||||
class Puc_v4p10_Theme_Package extends Puc_v4p10_InstalledPackage {
|
||||
/**
|
||||
* @var string Theme directory name.
|
||||
*/
|
||||
protected $stylesheet;
|
||||
|
||||
/**
|
||||
* @var \WP_Theme Theme object.
|
||||
* @var WP_Theme Theme object.
|
||||
*/
|
||||
protected $theme;
|
||||
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
if ( !class_exists('Puc_v4p10_Theme_Update', false) ):
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Update as BaseUpdate;
|
||||
|
||||
if ( !class_exists(Update::class, false) ):
|
||||
|
||||
class Update extends BaseUpdate {
|
||||
class Puc_v4p10_Theme_Update extends Puc_v4p10_Update {
|
||||
public $details_url = '';
|
||||
|
||||
protected static $extraFields = array('details_url');
|
||||
|
|
@ -48,8 +44,8 @@ if ( !class_exists(Update::class, false) ):
|
|||
/**
|
||||
* Create a new instance by copying the necessary fields from another object.
|
||||
*
|
||||
* @param \StdClass|self $object The source object.
|
||||
* @return self The new copy.
|
||||
* @param StdClass|Puc_v4p10_Theme_Update $object The source object.
|
||||
* @return Puc_v4p10_Theme_Update The new copy.
|
||||
*/
|
||||
public static function fromObject($object) {
|
||||
$update = new self();
|
||||
|
|
@ -60,14 +56,14 @@ if ( !class_exists(Update::class, false) ):
|
|||
/**
|
||||
* Basic validation.
|
||||
*
|
||||
* @param \StdClass $apiResponse
|
||||
* @return bool|\WP_Error
|
||||
* @param StdClass $apiResponse
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
protected function validateMetadata($apiResponse) {
|
||||
$required = array('version', 'details_url');
|
||||
foreach($required as $key) {
|
||||
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
|
||||
return new \WP_Error(
|
||||
return new WP_Error(
|
||||
'tuc-invalid-metadata',
|
||||
sprintf('The theme metadata is missing the required "%s" key.', $key)
|
||||
);
|
||||
|
|
@ -1,18 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
if ( !class_exists('Puc_v4p10_Theme_UpdateChecker', false) ):
|
||||
|
||||
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 {
|
||||
class Puc_v4p10_Theme_UpdateChecker extends Puc_v4p10_UpdateChecker {
|
||||
protected $filterSuffix = 'theme';
|
||||
protected $updateTransient = 'update_themes';
|
||||
protected $componentType = 'theme';
|
||||
protected $translationType = 'theme';
|
||||
|
||||
/**
|
||||
* @var string Theme directory name.
|
||||
|
|
@ -46,13 +39,13 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Retrieve the latest update (if any) from the configured API endpoint.
|
||||
*
|
||||
* @return Update|null An instance of Update, or NULL when no updates are available.
|
||||
* @return Puc_v4p10_Update|null An instance of Update, or NULL when no updates are available.
|
||||
*/
|
||||
public function requestUpdate() {
|
||||
list($themeUpdate, $result) = $this->requestMetadata(Update::class, 'request_update');
|
||||
list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p10_Theme_Update', 'request_update');
|
||||
|
||||
if ( $themeUpdate !== null ) {
|
||||
/** @var Update $themeUpdate */
|
||||
/** @var Puc_v4p10_Theme_Update $themeUpdate */
|
||||
$themeUpdate->slug = $this->slug;
|
||||
}
|
||||
|
||||
|
|
@ -78,16 +71,16 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* Create an instance of the scheduler.
|
||||
*
|
||||
* @param int $checkPeriod
|
||||
* @return Scheduler
|
||||
* @return Puc_v4p10_Scheduler
|
||||
*/
|
||||
protected function createScheduler($checkPeriod) {
|
||||
return new Scheduler($this, $checkPeriod, array('load-themes.php'));
|
||||
return new Puc_v4p10_Scheduler($this, $checkPeriod, array('load-themes.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there an update being installed right now for this theme?
|
||||
*
|
||||
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @return bool
|
||||
*/
|
||||
public function isBeingUpgraded($upgrader = null) {
|
||||
|
|
@ -95,7 +88,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
protected function createDebugBarExtension() {
|
||||
return new DebugBar\Extension($this, DebugBar\ThemePanel::class);
|
||||
return new Puc_v4p10_DebugBar_Extension($this, 'Puc_v4p10_DebugBar_ThemePanel');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,10 +142,10 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Create a package instance that represents this plugin or theme.
|
||||
*
|
||||
* @return InstalledPackage
|
||||
* @return Puc_v4p10_InstalledPackage
|
||||
*/
|
||||
protected function createInstalledPackage() {
|
||||
return new Package($this->stylesheet, $this);
|
||||
return new Puc_v4p10_Theme_Package($this->stylesheet, $this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,9 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use stdClass;
|
||||
|
||||
if ( !class_exists(Update::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Update', false) ):
|
||||
|
||||
/**
|
||||
* A simple container class for holding information about an available update.
|
||||
|
|
@ -11,7 +7,7 @@ if ( !class_exists(Update::class, false) ):
|
|||
* @author Janis Elsts
|
||||
* @access public
|
||||
*/
|
||||
abstract class Update extends Metadata {
|
||||
abstract class Puc_v4p10_Update extends Puc_v4p10_Metadata {
|
||||
public $slug;
|
||||
public $version;
|
||||
public $download_url;
|
||||
|
|
@ -1,24 +1,11 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use stdClass;
|
||||
use WP_Error;
|
||||
if ( !class_exists('Puc_v4p10_UpdateChecker', false) ):
|
||||
|
||||
if ( !class_exists(UpdateChecker::class, false) ):
|
||||
|
||||
abstract class UpdateChecker {
|
||||
abstract class Puc_v4p10_UpdateChecker {
|
||||
protected $filterSuffix = '';
|
||||
protected $updateTransient = '';
|
||||
|
||||
/**
|
||||
* @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 = '';
|
||||
protected $translationType = ''; //"plugin" or "theme".
|
||||
|
||||
/**
|
||||
* Set to TRUE to enable error reporting. Errors are raised using trigger_error()
|
||||
|
|
@ -49,22 +36,22 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
public $slug = '';
|
||||
|
||||
/**
|
||||
* @var InstalledPackage
|
||||
* @var Puc_v4p10_InstalledPackage
|
||||
*/
|
||||
protected $package;
|
||||
|
||||
/**
|
||||
* @var Scheduler
|
||||
* @var Puc_v4p10_Scheduler
|
||||
*/
|
||||
public $scheduler;
|
||||
|
||||
/**
|
||||
* @var UpgraderStatus
|
||||
* @var Puc_v4p10_UpgraderStatus
|
||||
*/
|
||||
protected $upgraderStatus;
|
||||
|
||||
/**
|
||||
* @var StateStore
|
||||
* @var Puc_v4p10_StateStore
|
||||
*/
|
||||
protected $updateState;
|
||||
|
||||
|
|
@ -79,15 +66,10 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
protected $cachedMetadataHost = 0;
|
||||
|
||||
/**
|
||||
* @var DebugBar\Extension|null
|
||||
* @var Puc_v4p10_DebugBar_Extension|null
|
||||
*/
|
||||
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;
|
||||
|
|
@ -105,14 +87,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();
|
||||
$this->updateState = new StateStore($this->optionName);
|
||||
$this->upgraderStatus = new Puc_v4p10_UpgraderStatus();
|
||||
$this->updateState = new Puc_v4p10_StateStore($this->optionName);
|
||||
|
||||
if ( did_action('init') ) {
|
||||
$this->loadTextDomain();
|
||||
|
|
@ -121,10 +99,6 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
$this->installHooks();
|
||||
|
||||
if ( ($this->wpCliCheckTrigger === null) && defined('WP_CLI') ) {
|
||||
$this->wpCliCheckTrigger = new WpCliCheckTrigger($this->componentType, $this->scheduler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -171,10 +145,6 @@ 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();
|
||||
|
|
@ -196,7 +166,6 @@ 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'));
|
||||
|
|
@ -237,7 +206,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*/
|
||||
public function allowMetadataHost($allow, $host) {
|
||||
if ( $this->cachedMetadataHost === 0 ) {
|
||||
$this->cachedMetadataHost = wp_parse_url($this->metadataUrl, PHP_URL_HOST);
|
||||
$this->cachedMetadataHost = parse_url($this->metadataUrl, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
if ( is_string($this->cachedMetadataHost) && (strtolower($host) === strtolower($this->cachedMetadataHost)) ) {
|
||||
|
|
@ -249,12 +218,12 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Create a package instance that represents this plugin or theme.
|
||||
*
|
||||
* @return InstalledPackage
|
||||
* @return Puc_v4p10_InstalledPackage
|
||||
*/
|
||||
abstract protected function createInstalledPackage();
|
||||
|
||||
/**
|
||||
* @return InstalledPackage
|
||||
* @return Puc_v4p10_InstalledPackage
|
||||
*/
|
||||
public function getInstalledPackage() {
|
||||
return $this->package;
|
||||
|
|
@ -267,84 +236,14 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* and substitute their own scheduler.
|
||||
*
|
||||
* @param int $checkPeriod
|
||||
* @return Scheduler
|
||||
* @return Puc_v4p10_Scheduler
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return Update|null
|
||||
* @return Puc_v4p10_Update|null
|
||||
*/
|
||||
public function checkForUpdates() {
|
||||
$installedVersion = $this->getInstalledVersion();
|
||||
|
|
@ -378,7 +277,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Load the update checker state from the DB.
|
||||
*
|
||||
* @return StateStore
|
||||
* @return Puc_v4p10_StateStore
|
||||
*/
|
||||
public function getUpdateState() {
|
||||
return $this->updateState->lazyLoad();
|
||||
|
|
@ -403,7 +302,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* Uses cached update data. To retrieve update information straight from
|
||||
* the metadata URL, call requestUpdate() instead.
|
||||
*
|
||||
* @return Update|null
|
||||
* @return Puc_v4p10_Update|null
|
||||
*/
|
||||
public function getUpdate() {
|
||||
$update = $this->updateState->getUpdate();
|
||||
|
|
@ -424,17 +323,16 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*
|
||||
* Subclasses should run the update through filterUpdateResult before returning it.
|
||||
*
|
||||
* @return Update An instance of Update, or NULL when no updates are available.
|
||||
* @return Puc_v4p10_Update An instance of Update, or NULL when no updates are available.
|
||||
*/
|
||||
abstract public function requestUpdate();
|
||||
|
||||
/**
|
||||
* Filter the result of a requestUpdate() call.
|
||||
*
|
||||
* @template T of Update
|
||||
* @param T|null $update
|
||||
* @param Puc_v4p10_Update|null $update
|
||||
* @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
|
||||
* @return T
|
||||
* @return Puc_v4p10_Update
|
||||
*/
|
||||
protected function filterUpdateResult($update, $httpResult = null) {
|
||||
//Let plugins/themes modify the update.
|
||||
|
|
@ -457,9 +355,9 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* "Compatibility: Unknown".
|
||||
* The function mimics how wordpress.org API crafts the "tested" field out of "Tested up to".
|
||||
*
|
||||
* @param Metadata|null $update
|
||||
* @param Puc_v4p10_Metadata|null $update
|
||||
*/
|
||||
protected function fixSupportedWordpressVersion($update = null) {
|
||||
protected function fixSupportedWordpressVersion(Puc_v4p10_Metadata $update = null) {
|
||||
if ( !isset($update->tested) || !preg_match('/^\d++\.\d++$/', $update->tested) ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -529,8 +427,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*/
|
||||
public function triggerError($message, $errorType) {
|
||||
if ( $this->isDebugModeEnabled() ) {
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Only happens in debug mode.
|
||||
trigger_error(esc_html($message), $errorType);
|
||||
trigger_error($message, $errorType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -565,7 +462,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* Store API errors that are generated when checking for updates.
|
||||
*
|
||||
* @internal
|
||||
* @param \WP_Error $error
|
||||
* @param WP_Error $error
|
||||
* @param array|null $httpResponse
|
||||
* @param string|null $url
|
||||
* @param string|null $slug
|
||||
|
|
@ -618,8 +515,8 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Insert the latest update (if any) into the update list maintained by WP.
|
||||
*
|
||||
* @param \stdClass $updates Update list.
|
||||
* @return \stdClass Modified update list.
|
||||
* @param stdClass $updates Update list.
|
||||
* @return stdClass Modified update list.
|
||||
*/
|
||||
public function injectUpdate($updates) {
|
||||
//Is there an update to insert?
|
||||
|
|
@ -646,9 +543,9 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $updates
|
||||
* @param \stdClass|array $updateToAdd
|
||||
* @return \stdClass
|
||||
* @param stdClass|null $updates
|
||||
* @param stdClass|array $updateToAdd
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function addUpdateToList($updates, $updateToAdd) {
|
||||
if ( !is_object($updates) ) {
|
||||
|
|
@ -661,8 +558,8 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $updates
|
||||
* @return \stdClass|null
|
||||
* @param stdClass|null $updates
|
||||
* @return stdClass|null
|
||||
*/
|
||||
protected function removeUpdateFromList($updates) {
|
||||
if ( isset($updates, $updates->response) ) {
|
||||
|
|
@ -675,8 +572,8 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
* See this post for more information:
|
||||
* @link https://make.wordpress.org/core/2020/07/30/recommended-usage-of-the-updates-api-to-support-the-auto-updates-ui-for-plugins-and-themes-in-wordpress-5-5/
|
||||
*
|
||||
* @param \stdClass|null $updates
|
||||
* @return \stdClass
|
||||
* @param stdClass|null $updates
|
||||
* @return stdClass
|
||||
*/
|
||||
protected function addNoUpdateItem($updates) {
|
||||
if ( !is_object($updates) ) {
|
||||
|
|
@ -738,10 +635,10 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
|
||||
*
|
||||
* @param class-string<Update> $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
||||
* @param string $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
||||
* @param string $filterRoot
|
||||
* @param array $queryArgs Additional query arguments.
|
||||
* @return array<Metadata|null, array|WP_Error> A metadata instance and the value returned by wp_remote_get().
|
||||
* @return array [Puc_v4p10_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get().
|
||||
*/
|
||||
protected function requestMetadata($metaClass, $filterRoot, $queryArgs = array()) {
|
||||
//Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
|
||||
|
|
@ -757,7 +654,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
|
||||
//Various options for the wp_remote_get() call. Plugins can filter these, too.
|
||||
$options = array(
|
||||
'timeout' => wp_doing_cron() ? 10 : 3,
|
||||
'timeout' => 10, //seconds
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
),
|
||||
|
|
@ -773,14 +670,11 @@ 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;
|
||||
if ( !is_wp_error($status) ){
|
||||
if ( (strpos($metaClass, '\\') === false) ) {
|
||||
$metaClass = __NAMESPACE__ . '\\' . $metaClass;
|
||||
}
|
||||
$metadata = call_user_func(array($metaClass, 'fromJson'), $result['body']);
|
||||
} else {
|
||||
do_action('puc_api_error', $status, $result, $url, $this->slug);
|
||||
|
|
@ -982,12 +876,12 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*
|
||||
* @param string $source The directory to copy to /wp-content/plugins or /wp-content/themes. Usually a subdirectory of $remoteSource.
|
||||
* @param string $remoteSource WordPress has extracted the update to this directory.
|
||||
* @param \WP_Upgrader $upgrader
|
||||
* @param WP_Upgrader $upgrader
|
||||
* @return string|WP_Error
|
||||
*/
|
||||
public function fixDirectoryName($source, $remoteSource, $upgrader) {
|
||||
global $wp_filesystem;
|
||||
/** @var \WP_Filesystem_Base $wp_filesystem */
|
||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
||||
|
||||
//Basic sanity checks.
|
||||
if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
|
||||
|
|
@ -999,62 +893,25 @@ 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>',
|
||||
|
|
@ -1078,7 +935,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
/**
|
||||
* Is there an update being installed right now, for this plugin or theme?
|
||||
*
|
||||
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function isBeingUpgraded($upgrader = null);
|
||||
|
|
@ -1092,7 +949,7 @@ if ( !class_exists(UpdateChecker::class, false) ):
|
|||
*/
|
||||
protected function isBadDirectoryStructure($remoteSource) {
|
||||
global $wp_filesystem;
|
||||
/** @var \WP_Filesystem_Base $wp_filesystem */
|
||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
||||
|
||||
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
||||
if ( is_array($sourceFiles) ) {
|
||||
|
|
@ -1114,23 +971,19 @@ 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)
|
||||
&& class_exists('Debug_Bar_Panel', false)
|
||||
&& file_exists(dirname(__FILE__) . '/DebugBar')
|
||||
) {
|
||||
if ( class_exists('Debug_Bar', false) && file_exists(dirname(__FILE__) . '/DebugBar') ) {
|
||||
$this->debugBarExtension = $this->createDebugBarExtension();
|
||||
}
|
||||
}
|
||||
|
||||
protected function createDebugBarExtension() {
|
||||
return new DebugBar\Extension($this);
|
||||
return new Puc_v4p10_DebugBar_Extension($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display additional configuration details in the Debug Bar panel.
|
||||
*
|
||||
* @param DebugBar\Panel $panel
|
||||
* @param Puc_v4p10_DebugBar_Panel $panel
|
||||
*/
|
||||
public function onDisplayConfiguration($panel) {
|
||||
//Do nothing. Subclasses can use this to add additional info to the panel.
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(UpgraderStatus::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_UpgraderStatus', false) ):
|
||||
|
||||
/**
|
||||
* A utility class that helps figure out which plugin or theme WordPress is upgrading.
|
||||
|
|
@ -10,8 +8,8 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
* Core classes like Plugin_Upgrader don't expose the plugin file name during an in-progress update (AFAICT).
|
||||
* This class uses a few workarounds and heuristics to get the file name.
|
||||
*/
|
||||
class UpgraderStatus {
|
||||
private $currentType = null; //This must be either "plugin" or "theme".
|
||||
class Puc_v4p10_UpgraderStatus {
|
||||
private $currentType = null; //"plugin" or "theme".
|
||||
private $currentId = null; //Plugin basename or theme directory name.
|
||||
|
||||
public function __construct() {
|
||||
|
|
@ -29,7 +27,7 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
* and upgrader implementations are liable to change without notice.
|
||||
*
|
||||
* @param string $pluginFile The plugin to check.
|
||||
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @return bool True if the plugin identified by $pluginFile is being upgraded.
|
||||
*/
|
||||
public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
|
||||
|
|
@ -40,7 +38,7 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
* Is there an update being installed for a specific theme?
|
||||
*
|
||||
* @param string $stylesheet Theme directory name.
|
||||
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||
* @return bool
|
||||
*/
|
||||
public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
|
||||
|
|
@ -52,7 +50,7 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
*
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param \Plugin_Upgrader|\WP_Upgrader|null $upgrader
|
||||
* @param Plugin_Upgrader|WP_Upgrader|null $upgrader
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBeingUpgraded($type, $id, $upgrader = null) {
|
||||
|
|
@ -78,7 +76,7 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
* ['plugin', 'plugin-dir-name/plugin.php']
|
||||
* ['theme', 'theme-dir-name']
|
||||
*
|
||||
* @param \Plugin_Upgrader|\WP_Upgrader $upgrader
|
||||
* @param Plugin_Upgrader|WP_Upgrader $upgrader
|
||||
* @return array
|
||||
*/
|
||||
private function getThingBeingUpgradedBy($upgrader) {
|
||||
|
|
@ -91,13 +89,13 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
$themeDirectoryName = null;
|
||||
|
||||
$skin = $upgrader->skin;
|
||||
if ( isset($skin->theme_info) && ($skin->theme_info instanceof \WP_Theme) ) {
|
||||
if ( isset($skin->theme_info) && ($skin->theme_info instanceof WP_Theme) ) {
|
||||
$themeDirectoryName = $skin->theme_info->get_stylesheet();
|
||||
} elseif ( $skin instanceof \Plugin_Upgrader_Skin ) {
|
||||
} elseif ( $skin instanceof Plugin_Upgrader_Skin ) {
|
||||
if ( isset($skin->plugin) && is_string($skin->plugin) && ($skin->plugin !== '') ) {
|
||||
$pluginFile = $skin->plugin;
|
||||
}
|
||||
} elseif ( $skin instanceof \Theme_Upgrader_Skin ) {
|
||||
} elseif ( $skin instanceof Theme_Upgrader_Skin ) {
|
||||
if ( isset($skin->theme) && is_string($skin->theme) && ($skin->theme !== '') ) {
|
||||
$themeDirectoryName = $skin->theme;
|
||||
}
|
||||
|
|
@ -124,6 +122,7 @@ if ( !class_exists(UpgraderStatus::class, false) ):
|
|||
*/
|
||||
private function identifyPluginByHeaders($searchHeaders) {
|
||||
if ( !function_exists('get_plugins') ){
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
||||
}
|
||||
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(Utils::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Utils', false) ):
|
||||
|
||||
class Utils {
|
||||
class Puc_v4p10_Utils {
|
||||
/**
|
||||
* Get a value from a nested array or object based on a path.
|
||||
*
|
||||
|
|
@ -1,43 +1,7 @@
|
|||
<?php
|
||||
if ( !class_exists('Puc_v4p10_Vcs_Api') ):
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use Parsedown;
|
||||
use PucReadmeParser;
|
||||
|
||||
if ( !class_exists(Api::class, false) ):
|
||||
|
||||
abstract class Api {
|
||||
const STRATEGY_LATEST_RELEASE = 'latest_release';
|
||||
const STRATEGY_LATEST_TAG = 'latest_tag';
|
||||
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;
|
||||
|
||||
abstract class Puc_v4p10_Vcs_Api {
|
||||
protected $tagNameProperty = 'name';
|
||||
protected $slug = '';
|
||||
|
||||
|
|
@ -57,19 +21,13 @@ if ( !class_exists(Api::class, false) ):
|
|||
*/
|
||||
protected $httpFilterName = '';
|
||||
|
||||
/**
|
||||
* @var string The filter applied to the list of update detection strategies that
|
||||
* are used to find the latest version.
|
||||
*/
|
||||
protected $strategyFilterName = '';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $localDirectory = null;
|
||||
|
||||
/**
|
||||
* Api constructor.
|
||||
* Puc_v4p10_Vcs_Api constructor.
|
||||
*
|
||||
* @param string $repositoryUrl
|
||||
* @param array|string|null $credentials
|
||||
|
|
@ -87,41 +45,12 @@ if ( !class_exists(Api::class, false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* Figure out which reference (i.e. tag or branch) contains the latest version.
|
||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
||||
*
|
||||
* @param string $configBranch Start looking in this branch.
|
||||
* @return null|Reference
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
public function chooseReference($configBranch) {
|
||||
$strategies = $this->getUpdateDetectionStrategies($configBranch);
|
||||
|
||||
if ( !empty($this->strategyFilterName) ) {
|
||||
$strategies = apply_filters(
|
||||
$this->strategyFilterName,
|
||||
$strategies,
|
||||
$this->slug
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($strategies as $strategy) {
|
||||
$reference = call_user_func($strategy);
|
||||
if ( !empty($reference) ) {
|
||||
return $reference;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an ordered list of strategies that can be used to find the latest version.
|
||||
*
|
||||
* The update checker will try each strategy in order until one of them
|
||||
* returns a valid reference.
|
||||
*
|
||||
* @param string $configBranch
|
||||
* @return array<callable> Array of callables that return Vcs_Reference objects.
|
||||
*/
|
||||
abstract protected function getUpdateDetectionStrategies($configBranch);
|
||||
abstract public function chooseReference($configBranch);
|
||||
|
||||
/**
|
||||
* Get the readme.txt file from the remote repository and parse it
|
||||
|
|
@ -176,7 +105,7 @@ if ( !class_exists(Api::class, false) ):
|
|||
* Get a branch.
|
||||
*
|
||||
* @param string $branchName
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
abstract public function getBranch($branchName);
|
||||
|
||||
|
|
@ -184,7 +113,7 @@ if ( !class_exists(Api::class, false) ):
|
|||
* Get a specific tag.
|
||||
*
|
||||
* @param string $tagName
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
abstract public function getTag($tagName);
|
||||
|
||||
|
|
@ -192,7 +121,7 @@ if ( !class_exists(Api::class, false) ):
|
|||
* Get the tag that looks like the highest version number.
|
||||
* (Implementations should skip pre-release versions if possible.)
|
||||
*
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
abstract public function getLatestTag();
|
||||
|
||||
|
|
@ -218,7 +147,7 @@ if ( !class_exists(Api::class, false) ):
|
|||
/**
|
||||
* Check if a tag appears to be named like a version number.
|
||||
*
|
||||
* @param \stdClass $tag
|
||||
* @param stdClass $tag
|
||||
* @return bool
|
||||
*/
|
||||
protected function isVersionTag($tag) {
|
||||
|
|
@ -230,8 +159,8 @@ if ( !class_exists(Api::class, false) ):
|
|||
* Sort a list of tags as if they were version numbers.
|
||||
* Tags that don't look like version number will be removed.
|
||||
*
|
||||
* @param \stdClass[] $tags Array of tag objects.
|
||||
* @return \stdClass[] Filtered array of tags sorted in descending order.
|
||||
* @param stdClass[] $tags Array of tag objects.
|
||||
* @return stdClass[] Filtered array of tags sorted in descending order.
|
||||
*/
|
||||
protected function sortTagsByVersion($tags) {
|
||||
//Keep only those tags that look like version numbers.
|
||||
|
|
@ -245,8 +174,8 @@ if ( !class_exists(Api::class, false) ):
|
|||
/**
|
||||
* Compare two tags as if they were version number.
|
||||
*
|
||||
* @param \stdClass $tag1 Tag object.
|
||||
* @param \stdClass $tag2 Another tag object.
|
||||
* @param stdClass $tag1 Tag object.
|
||||
* @param stdClass $tag2 Another tag object.
|
||||
* @return int
|
||||
*/
|
||||
protected function compareTagNames($tag1, $tag2) {
|
||||
|
|
@ -295,6 +224,7 @@ if ( !class_exists(Api::class, false) ):
|
|||
return null;
|
||||
}
|
||||
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
return Parsedown::instance()->text($changelog);
|
||||
}
|
||||
|
||||
|
|
@ -350,13 +280,6 @@ if ( !class_exists(Api::class, false) ):
|
|||
$this->httpFilterName = $filterName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filterName
|
||||
*/
|
||||
public function setStrategyFilterName($filterName) {
|
||||
$this->strategyFilterName = $filterName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $directory
|
||||
*/
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
if ( !interface_exists('Puc_v4p10_Vcs_BaseChecker', false) ):
|
||||
|
||||
if ( !interface_exists(BaseChecker::class, false) ):
|
||||
|
||||
interface BaseChecker {
|
||||
interface Puc_v4p10_Vcs_BaseChecker {
|
||||
/**
|
||||
* Set the repository branch to use for updates. Defaults to 'master'.
|
||||
*
|
||||
|
|
@ -21,7 +19,7 @@ if ( !interface_exists(BaseChecker::class, false) ):
|
|||
public function setAuthentication($credentials);
|
||||
|
||||
/**
|
||||
* @return Api
|
||||
* @return Puc_v4p10_Vcs_Api
|
||||
*/
|
||||
public function getVcsApi();
|
||||
}
|
||||
|
|
@ -1,15 +1,9 @@
|
|||
<?php
|
||||
if ( !class_exists('Puc_v4p10_Vcs_BitBucketApi', false) ):
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\OAuthSignature;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Utils;
|
||||
|
||||
if ( !class_exists(BitBucketApi::class, false) ):
|
||||
|
||||
class BitBucketApi extends Api {
|
||||
class Puc_v4p10_Vcs_BitBucketApi extends Puc_v4p10_Vcs_Api {
|
||||
/**
|
||||
* @var OAuthSignature
|
||||
* @var Puc_v4p10_OAuthSignature
|
||||
*/
|
||||
private $oauth = null;
|
||||
|
||||
|
|
@ -24,32 +18,39 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
private $repository;
|
||||
|
||||
public function __construct($repositoryUrl, $credentials = array()) {
|
||||
$path = wp_parse_url($repositoryUrl, PHP_URL_PATH);
|
||||
$path = parse_url($repositoryUrl, PHP_URL_PATH);
|
||||
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
||||
$this->username = $matches['username'];
|
||||
$this->repository = $matches['repository'];
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
||||
throw new InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
||||
}
|
||||
|
||||
parent::__construct($repositoryUrl, $credentials);
|
||||
}
|
||||
|
||||
protected function getUpdateDetectionStrategies($configBranch) {
|
||||
$strategies = array(
|
||||
self::STRATEGY_STABLE_TAG => function () use ($configBranch) {
|
||||
return $this->getStableTag($configBranch);
|
||||
},
|
||||
);
|
||||
/**
|
||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
||||
*
|
||||
* @param string $configBranch Start looking in this branch.
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
public function chooseReference($configBranch) {
|
||||
$updateSource = null;
|
||||
|
||||
if ( ($configBranch === 'master' || $configBranch === 'main') ) {
|
||||
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||
//Check if there's a "Stable tag: 1.2.3" header that points to a valid tag.
|
||||
$updateSource = $this->getStableTag($configBranch);
|
||||
|
||||
//Look for version-like tags.
|
||||
if ( !$updateSource && ($configBranch === 'master') ) {
|
||||
$updateSource = $this->getLatestTag();
|
||||
}
|
||||
//If all else fails, use the specified branch itself.
|
||||
if ( !$updateSource ) {
|
||||
$updateSource = $this->getBranch($configBranch);
|
||||
}
|
||||
|
||||
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||
return $this->getBranch($configBranch);
|
||||
};
|
||||
return $strategies;
|
||||
return $updateSource;
|
||||
}
|
||||
|
||||
public function getBranch($branchName) {
|
||||
|
|
@ -58,16 +59,8 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
return null;
|
||||
}
|
||||
|
||||
//The "/src/{stuff}/{path}" endpoint doesn't seem to handle branch names that contain slashes.
|
||||
//If we don't encode the slash, we get a 404. If we encode it as "%2F", we get a 401.
|
||||
//To avoid issues, if the branch name is not URL-safe, let's use the commit hash instead.
|
||||
$ref = $branch->name;
|
||||
if ((urlencode($ref) !== $ref) && isset($branch->target->hash)) {
|
||||
$ref = $branch->target->hash;
|
||||
}
|
||||
|
||||
return new Reference(array(
|
||||
'name' => $ref,
|
||||
return new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $branch->name,
|
||||
'updated' => $branch->target->date,
|
||||
'downloadUrl' => $this->getDownloadUrl($branch->name),
|
||||
));
|
||||
|
|
@ -77,7 +70,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
* Get a specific tag.
|
||||
*
|
||||
* @param string $tagName
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
public function getTag($tagName) {
|
||||
$tag = $this->api('/refs/tags/' . $tagName);
|
||||
|
|
@ -85,7 +78,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
return null;
|
||||
}
|
||||
|
||||
return new Reference(array(
|
||||
return new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $tag->name,
|
||||
'version' => ltrim($tag->name, 'v'),
|
||||
'updated' => $tag->target->date,
|
||||
|
|
@ -96,7 +89,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
/**
|
||||
* Get the tag that looks like the highest version number.
|
||||
*
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
public function getLatestTag() {
|
||||
$tags = $this->api('/refs/tags?sort=-target.date');
|
||||
|
|
@ -110,7 +103,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
//Return the first result.
|
||||
if ( !empty($versionTags) ) {
|
||||
$tag = $versionTags[0];
|
||||
return new Reference(array(
|
||||
return new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $tag->name,
|
||||
'version' => ltrim($tag->name, 'v'),
|
||||
'updated' => $tag->target->date,
|
||||
|
|
@ -124,7 +117,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
* Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
|
||||
*
|
||||
* @param string $branch
|
||||
* @return null|Reference
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
protected function getStableTag($branch) {
|
||||
$remoteReadme = $this->getRemoteReadme($branch);
|
||||
|
|
@ -190,11 +183,11 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
*
|
||||
* @param string $url
|
||||
* @param string $version
|
||||
* @return mixed|\WP_Error
|
||||
* @return mixed|WP_Error
|
||||
*/
|
||||
public function api($url, $version = '2.0') {
|
||||
$url = ltrim($url, '/');
|
||||
$isSrcResource = Utils::startsWith($url, 'src/');
|
||||
$isSrcResource = Puc_v4p10_Utils::startsWith($url, 'src/');
|
||||
|
||||
$url = implode('/', array(
|
||||
'https://api.bitbucket.org',
|
||||
|
|
@ -210,7 +203,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
$url = $this->oauth->sign($url,'GET');
|
||||
}
|
||||
|
||||
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||
$options = array('timeout' => 10);
|
||||
if ( !empty($this->httpFilterName) ) {
|
||||
$options = apply_filters($this->httpFilterName, $options);
|
||||
}
|
||||
|
|
@ -233,7 +226,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
return $document;
|
||||
}
|
||||
|
||||
$error = new \WP_Error(
|
||||
$error = new WP_Error(
|
||||
'puc-bitbucket-http-error',
|
||||
sprintf('BitBucket API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||
);
|
||||
|
|
@ -249,7 +242,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
parent::setAuthentication($credentials);
|
||||
|
||||
if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
|
||||
$this->oauth = new OAuthSignature(
|
||||
$this->oauth = new Puc_v4p10_OAuthSignature(
|
||||
$credentials['consumer_key'],
|
||||
$credentials['consumer_secret']
|
||||
);
|
||||
|
|
@ -260,7 +253,7 @@ if ( !class_exists(BitBucketApi::class, false) ):
|
|||
|
||||
public function signDownloadUrl($url) {
|
||||
//Add authentication data to download URLs. Since OAuth signatures incorporate
|
||||
//timestamps, we have to do this immediately before inserting the update. Otherwise,
|
||||
//timestamps, we have to do this immediately before inserting the update. Otherwise
|
||||
//authentication could fail due to a stale timestamp.
|
||||
if ( $this->oauth ) {
|
||||
$url = $this->oauth->sign($url);
|
||||
|
|
@ -1,15 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use Parsedown;
|
||||
|
||||
if ( !class_exists(GitHubApi::class, false) ):
|
||||
|
||||
class GitHubApi extends Api {
|
||||
use ReleaseAssetSupport;
|
||||
use ReleaseFilteringFeature;
|
||||
if ( !class_exists('Puc_v4p10_Vcs_GitHubApi', false) ):
|
||||
|
||||
class Puc_v4p10_Vcs_GitHubApi extends Puc_v4p10_Vcs_Api {
|
||||
/**
|
||||
* @var string GitHub username.
|
||||
*/
|
||||
|
|
@ -29,18 +22,33 @@ 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
|
||||
*/
|
||||
private $downloadFilterAdded = false;
|
||||
|
||||
public function __construct($repositoryUrl, $accessToken = null) {
|
||||
$path = wp_parse_url($repositoryUrl, PHP_URL_PATH);
|
||||
$path = parse_url($repositoryUrl, PHP_URL_PATH);
|
||||
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
||||
$this->userName = $matches['username'];
|
||||
$this->repositoryName = $matches['repository'];
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
||||
throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
||||
}
|
||||
|
||||
parent::__construct($repositoryUrl, $accessToken);
|
||||
|
|
@ -49,112 +57,59 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
/**
|
||||
* Get the latest release from GitHub.
|
||||
*
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
public function getLatestRelease() {
|
||||
//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;
|
||||
}
|
||||
$release = $this->api('/repos/:user/:repo/releases/latest');
|
||||
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($foundReleases as $release) {
|
||||
//Always skip drafts.
|
||||
if ( isset($release->draft) && !empty($release->draft) ) {
|
||||
continue;
|
||||
}
|
||||
$reference = new Puc_v4p10_Vcs_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,
|
||||
));
|
||||
|
||||
//Skip pre-releases unless specifically included.
|
||||
if (
|
||||
$this->shouldSkipPreReleases()
|
||||
&& isset($release->prerelease)
|
||||
&& !empty($release->prerelease)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if ( isset($release->assets[0]) ) {
|
||||
$reference->downloadCount = $release->assets[0]->download_count;
|
||||
}
|
||||
|
||||
$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')));
|
||||
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 {
|
||||
$matchingAssets = array();
|
||||
//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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
$reference->downloadCount = $matchingAssets[0]->download_count;
|
||||
}
|
||||
|
||||
if ( !empty($release->body) ) {
|
||||
$reference->changelog = Parsedown::instance()->text($release->body);
|
||||
}
|
||||
|
||||
return $reference;
|
||||
}
|
||||
|
||||
return null;
|
||||
if ( !empty($release->body) ) {
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
$reference->changelog = Parsedown::instance()->text($release->body);
|
||||
}
|
||||
|
||||
return $reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag that looks like the highest version number.
|
||||
*
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
public function getLatestTag() {
|
||||
$tags = $this->api('/repos/:user/:repo/tags');
|
||||
|
|
@ -169,7 +124,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
}
|
||||
|
||||
$tag = $versionTags[0];
|
||||
return new Reference(array(
|
||||
return new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $tag->name,
|
||||
'version' => ltrim($tag->name, 'v'),
|
||||
'downloadUrl' => $tag->zipball_url,
|
||||
|
|
@ -181,7 +136,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
* Get a branch by name.
|
||||
*
|
||||
* @param string $branchName
|
||||
* @return null|Reference
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
public function getBranch($branchName) {
|
||||
$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
|
||||
|
|
@ -189,7 +144,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
return null;
|
||||
}
|
||||
|
||||
$reference = new Reference(array(
|
||||
$reference = new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $branch->name,
|
||||
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
||||
'apiResponse' => $branch,
|
||||
|
|
@ -207,7 +162,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
*
|
||||
* @param string $filename
|
||||
* @param string $ref Reference name (e.g. branch or tag).
|
||||
* @return \StdClass|null
|
||||
* @return StdClass|null
|
||||
*/
|
||||
public function getLatestCommit($filename, $ref = 'master') {
|
||||
$commits = $this->api(
|
||||
|
|
@ -242,13 +197,13 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
*
|
||||
* @param string $url
|
||||
* @param array $queryParams
|
||||
* @return mixed|\WP_Error
|
||||
* @return mixed|WP_Error
|
||||
*/
|
||||
protected function api($url, $queryParams = array()) {
|
||||
$baseUrl = $url;
|
||||
$url = $this->buildApiUrl($url, $queryParams);
|
||||
|
||||
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||
$options = array('timeout' => 10);
|
||||
if ( $this->isAuthenticationEnabled() ) {
|
||||
$options['headers'] = array('Authorization' => $this->getAuthorizationHeader());
|
||||
}
|
||||
|
|
@ -269,7 +224,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
return $document;
|
||||
}
|
||||
|
||||
$error = new \WP_Error(
|
||||
$error = new WP_Error(
|
||||
'puc-github-http-error',
|
||||
sprintf('GitHub API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||
);
|
||||
|
|
@ -343,7 +298,7 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
*/
|
||||
public function getTag($tagName) {
|
||||
//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
|
||||
throw new \LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
||||
throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
||||
}
|
||||
|
||||
public function setAuthentication($credentials) {
|
||||
|
|
@ -355,52 +310,72 @@ if ( !class_exists(GitHubApi::class, false) ):
|
|||
add_filter('upgrader_pre_download', array($this, 'addHttpRequestFilter'), 10, 1); //WP 3.7+
|
||||
}
|
||||
|
||||
protected function getUpdateDetectionStrategies($configBranch) {
|
||||
$strategies = array();
|
||||
/**
|
||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
||||
*
|
||||
* @param string $configBranch Start looking in this branch.
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
public function chooseReference($configBranch) {
|
||||
$updateSource = null;
|
||||
|
||||
if ( $configBranch === 'master' || $configBranch === 'main') {
|
||||
if ( $configBranch === 'master' ) {
|
||||
//Use the latest release.
|
||||
$strategies[self::STRATEGY_LATEST_RELEASE] = array($this, 'getLatestRelease');
|
||||
//Failing that, use the tag with the highest version number.
|
||||
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||
$updateSource = $this->getLatestRelease();
|
||||
if ( $updateSource === null ) {
|
||||
//Failing that, use the tag with the highest version number.
|
||||
$updateSource = $this->getLatestTag();
|
||||
}
|
||||
}
|
||||
//Alternatively, just use the branch itself.
|
||||
if ( empty($updateSource) ) {
|
||||
$updateSource = $this->getBranch($configBranch);
|
||||
}
|
||||
|
||||
//Alternatively, just use the branch itself.
|
||||
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||
return $this->getBranch($configBranch);
|
||||
};
|
||||
|
||||
return $strategies;
|
||||
return $updateSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unchanging part of a release asset URL. Used to identify download attempts.
|
||||
* Enable updating via release assets.
|
||||
*
|
||||
* @return string
|
||||
* 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.
|
||||
*/
|
||||
protected function getAssetApiBaseUrl() {
|
||||
return sprintf(
|
||||
public function enableReleaseAssets($fileNameRegex = null) {
|
||||
$this->releaseAssetsEnabled = true;
|
||||
$this->assetFilterRegex = $fileNameRegex;
|
||||
$this->assetApiBaseUrl = sprintf(
|
||||
'//api.github.com/repos/%1$s/%2$s/releases/assets/',
|
||||
$this->userName,
|
||||
$this->repositoryName
|
||||
);
|
||||
}
|
||||
|
||||
protected function getFilterableAssetName($releaseAsset) {
|
||||
if ( isset($releaseAsset->name) ) {
|
||||
return $releaseAsset->name;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return null;
|
||||
return isset($releaseAsset->name) && preg_match($this->assetFilterRegex, $releaseAsset->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param bool $result
|
||||
* @return bool
|
||||
* @internal
|
||||
*/
|
||||
public function addHttpRequestFilter($result) {
|
||||
if ( !$this->downloadFilterAdded && $this->isAuthenticationEnabled() ) {
|
||||
//phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args -- The callback doesn't change the timeout.
|
||||
add_filter('http_request_args', array($this, 'setUpdateDownloadHeaders'), 10, 2);
|
||||
add_action('requests-requests.before_redirect', array($this, 'removeAuthHeaderFromRedirects'), 10, 4);
|
||||
$this->downloadFilterAdded = true;
|
||||
|
|
@ -412,7 +387,6 @@ 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
|
||||
*
|
||||
|
|
@ -423,7 +397,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->getAssetApiBaseUrl()) !== false) ) {
|
||||
if ( $this->releaseAssetsEnabled && (strpos($url, $this->assetApiBaseUrl) !== false) ) {
|
||||
$requestArgs['headers']['Accept'] = 'application/octet-stream';
|
||||
}
|
||||
//Use Basic authentication, but only if the download is from our repository.
|
||||
|
|
@ -439,9 +413,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,13 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !class_exists(GitLabApi::class, false) ):
|
||||
|
||||
class GitLabApi extends Api {
|
||||
use ReleaseAssetSupport;
|
||||
use ReleaseFilteringFeature;
|
||||
if ( !class_exists('Puc_v4p10_Vcs_GitLabApi', false) ):
|
||||
|
||||
class Puc_v4p10_Vcs_GitLabApi extends Puc_v4p10_Vcs_Api {
|
||||
/**
|
||||
* @var string GitLab username.
|
||||
*/
|
||||
|
|
@ -33,26 +28,20 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
*/
|
||||
protected $accessToken;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @var bool No longer used.
|
||||
*/
|
||||
protected $releasePackageEnabled = false;
|
||||
|
||||
public function __construct($repositoryUrl, $accessToken = null, $subgroup = null) {
|
||||
//Parse the repository host to support custom hosts.
|
||||
$port = wp_parse_url($repositoryUrl, PHP_URL_PORT);
|
||||
$port = parse_url($repositoryUrl, PHP_URL_PORT);
|
||||
if ( !empty($port) ) {
|
||||
$port = ':' . $port;
|
||||
}
|
||||
$this->repositoryHost = wp_parse_url($repositoryUrl, PHP_URL_HOST) . $port;
|
||||
$this->repositoryHost = parse_url($repositoryUrl, PHP_URL_HOST) . $port;
|
||||
|
||||
if ( $this->repositoryHost !== 'gitlab.com' ) {
|
||||
$this->repositoryProtocol = wp_parse_url($repositoryUrl, PHP_URL_SCHEME);
|
||||
$this->repositoryProtocol = parse_url($repositoryUrl, PHP_URL_SCHEME);
|
||||
}
|
||||
|
||||
//Find the repository information
|
||||
$path = wp_parse_url($repositoryUrl, PHP_URL_PATH);
|
||||
$path = parse_url($repositoryUrl, PHP_URL_PATH);
|
||||
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
||||
$this->userName = $matches['username'];
|
||||
$this->repositoryName = $matches['repository'];
|
||||
|
|
@ -60,7 +49,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
//This is probably a repository in a subgroup, e.g. "/organization/category/repo".
|
||||
$parts = explode('/', trim($path, '/'));
|
||||
if ( count($parts) < 3 ) {
|
||||
throw new \InvalidArgumentException('Invalid GitLab.com repository URL: "' . $repositoryUrl . '"');
|
||||
throw new InvalidArgumentException('Invalid GitLab.com repository URL: "' . $repositoryUrl . '"');
|
||||
}
|
||||
$lastPart = array_pop($parts);
|
||||
$this->userName = implode('/', $parts);
|
||||
|
|
@ -77,7 +66,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
|
||||
//We need at least /user-name/repository-name/
|
||||
if ( count($segments) < 2 ) {
|
||||
throw new \InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"');
|
||||
throw new InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"');
|
||||
}
|
||||
|
||||
//Get the username and repository name.
|
||||
|
|
@ -102,92 +91,16 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
/**
|
||||
* Get the latest release from GitLab.
|
||||
*
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
public function getLatestRelease() {
|
||||
$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 (
|
||||
//Skip invalid/unsupported releases.
|
||||
!is_object($release)
|
||||
|| !isset($release->tag_name)
|
||||
//Skip upcoming releases.
|
||||
|| (
|
||||
!empty($release->upcoming_release)
|
||||
&& $this->shouldSkipPreReleases()
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$versionNumber = ltrim($release->tag_name, 'v'); //Remove the "v" prefix from "v1.2.3".
|
||||
|
||||
//Apply custom filters.
|
||||
if ( !$this->matchesCustomReleaseFilter($versionNumber, $release) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$downloadUrl = $this->findReleaseDownloadUrl($release);
|
||||
if ( empty($downloadUrl) ) {
|
||||
//The latest release doesn't have valid download URL.
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( !empty($this->accessToken) ) {
|
||||
$downloadUrl = add_query_arg('private_token', $this->accessToken, $downloadUrl);
|
||||
}
|
||||
|
||||
return new Reference(array(
|
||||
'name' => $release->tag_name,
|
||||
'version' => $versionNumber,
|
||||
'downloadUrl' => $downloadUrl,
|
||||
'updated' => $release->released_at,
|
||||
'apiResponse' => $release,
|
||||
));
|
||||
}
|
||||
|
||||
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;
|
||||
return $this->getLatestTag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag that looks like the highest version number.
|
||||
*
|
||||
* @return Reference|null
|
||||
* @return Puc_v4p10_Vcs_Reference|null
|
||||
*/
|
||||
public function getLatestTag() {
|
||||
$tags = $this->api('/:id/repository/tags');
|
||||
|
|
@ -201,7 +114,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
}
|
||||
|
||||
$tag = $versionTags[0];
|
||||
return new Reference(array(
|
||||
return new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $tag->name,
|
||||
'version' => ltrim($tag->name, 'v'),
|
||||
'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name),
|
||||
|
|
@ -213,7 +126,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
* Get a branch by name.
|
||||
*
|
||||
* @param string $branchName
|
||||
* @return null|Reference
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
public function getBranch($branchName) {
|
||||
$branch = $this->api('/:id/repository/branches/' . $branchName);
|
||||
|
|
@ -221,7 +134,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
return null;
|
||||
}
|
||||
|
||||
$reference = new Reference(array(
|
||||
$reference = new Puc_v4p10_Vcs_Reference(array(
|
||||
'name' => $branch->name,
|
||||
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
||||
'apiResponse' => $branch,
|
||||
|
|
@ -254,13 +167,13 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
*
|
||||
* @param string $url
|
||||
* @param array $queryParams
|
||||
* @return mixed|\WP_Error
|
||||
* @return mixed|WP_Error
|
||||
*/
|
||||
protected function api($url, $queryParams = array()) {
|
||||
$baseUrl = $url;
|
||||
$url = $this->buildApiUrl($url, $queryParams);
|
||||
|
||||
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||
$options = array('timeout' => 10);
|
||||
if ( !empty($this->httpFilterName) ) {
|
||||
$options = apply_filters($this->httpFilterName, $options);
|
||||
}
|
||||
|
|
@ -277,7 +190,7 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
return json_decode($body);
|
||||
}
|
||||
|
||||
$error = new \WP_Error(
|
||||
$error = new WP_Error(
|
||||
'puc-gitlab-http-error',
|
||||
sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||
);
|
||||
|
|
@ -363,52 +276,34 @@ if ( !class_exists(GitLabApi::class, false) ):
|
|||
* @return void
|
||||
*/
|
||||
public function getTag($tagName) {
|
||||
throw new \LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
||||
throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
||||
}
|
||||
|
||||
protected function getUpdateDetectionStrategies($configBranch) {
|
||||
$strategies = array();
|
||||
/**
|
||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
||||
*
|
||||
* @param string $configBranch Start looking in this branch.
|
||||
* @return null|Puc_v4p10_Vcs_Reference
|
||||
*/
|
||||
public function chooseReference($configBranch) {
|
||||
$updateSource = null;
|
||||
|
||||
if ( ($configBranch === 'main') || ($configBranch === 'master') ) {
|
||||
$strategies[self::STRATEGY_LATEST_RELEASE] = array($this, 'getLatestRelease');
|
||||
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||
// GitLab doesn't handle releases the same as GitHub so just use the latest tag
|
||||
if ( $configBranch === 'master' ) {
|
||||
$updateSource = $this->getLatestTag();
|
||||
}
|
||||
|
||||
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||
return $this->getBranch($configBranch);
|
||||
};
|
||||
if ( empty($updateSource) ) {
|
||||
$updateSource = $this->getBranch($configBranch);
|
||||
}
|
||||
|
||||
return $strategies;
|
||||
return $updateSource;
|
||||
}
|
||||
|
||||
public function setAuthentication($credentials) {
|
||||
parent::setAuthentication($credentials);
|
||||
$this->accessToken = is_string($credentials) ? $credentials : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->enableReleaseAssets(
|
||||
/** @lang RegExp */ '/\.zip($|[?&#])/i',
|
||||
Api::REQUIRE_RELEASE_ASSETS
|
||||
);
|
||||
}
|
||||
|
||||
protected function getFilterableAssetName($releaseAsset) {
|
||||
if ( isset($releaseAsset->url) ) {
|
||||
return $releaseAsset->url;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,18 +1,21 @@
|
|||
<?php
|
||||
if ( !class_exists('Puc_v4p10_Vcs_PluginUpdateChecker') ):
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin;
|
||||
|
||||
if ( !class_exists(PluginUpdateChecker::class, false) ):
|
||||
|
||||
class PluginUpdateChecker extends Plugin\UpdateChecker implements BaseChecker {
|
||||
use VcsCheckerMethods;
|
||||
class Puc_v4p10_Vcs_PluginUpdateChecker extends Puc_v4p10_Plugin_UpdateChecker implements Puc_v4p10_Vcs_BaseChecker {
|
||||
/**
|
||||
* @var string The branch where to look for updates. Defaults to "master".
|
||||
*/
|
||||
protected $branch = 'master';
|
||||
|
||||
/**
|
||||
* PluginUpdateChecker constructor.
|
||||
* @var Puc_v4p10_Vcs_Api Repository API client.
|
||||
*/
|
||||
protected $api = null;
|
||||
|
||||
/**
|
||||
* Puc_v4p10_Vcs_PluginUpdateChecker constructor.
|
||||
*
|
||||
* @param Api $api
|
||||
* @param Puc_v4p10_Vcs_Api $api
|
||||
* @param string $pluginFile
|
||||
* @param string $slug
|
||||
* @param int $checkPeriod
|
||||
|
|
@ -21,11 +24,10 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
*/
|
||||
public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
||||
$this->api = $api;
|
||||
$this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
|
||||
|
||||
parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
|
||||
|
||||
$this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
|
||||
$this->api->setStrategyFilterName($this->getUniqueName('vcs_update_detection_strategies'));
|
||||
$this->api->setSlug($this->slug);
|
||||
}
|
||||
|
||||
|
|
@ -39,13 +41,11 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
$api = $this->api;
|
||||
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
||||
|
||||
$info = new Plugin\PluginInfo();
|
||||
$info = new Puc_v4p10_Plugin_Info();
|
||||
$info->filename = $this->pluginFile;
|
||||
$info->slug = $this->slug;
|
||||
|
||||
$this->setInfoFromHeader($this->package->getPluginHeader(), $info);
|
||||
$this->setIconsFromLocalAssets($info);
|
||||
$this->setBannersFromLocalAssets($info);
|
||||
|
||||
//Pick a branch or tag.
|
||||
$updateSource = $api->chooseReference($this->branch);
|
||||
|
|
@ -65,7 +65,7 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
//There's probably a network problem or an authentication error.
|
||||
do_action(
|
||||
'puc_api_error',
|
||||
new \WP_Error(
|
||||
new WP_Error(
|
||||
'puc-no-update-source',
|
||||
'Could not retrieve version information from the repository. '
|
||||
. 'This usually means that the update checker either can\'t connect '
|
||||
|
|
@ -85,21 +85,6 @@ 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() ) {
|
||||
|
|
@ -139,7 +124,7 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
* Copy plugin metadata from a file header to a Plugin Info object.
|
||||
*
|
||||
* @param array $fileHeader
|
||||
* @param Plugin\PluginInfo $pluginInfo
|
||||
* @param Puc_v4p10_Plugin_Info $pluginInfo
|
||||
*/
|
||||
protected function setInfoFromHeader($fileHeader, $pluginInfo) {
|
||||
$headerToPropertyMap = array(
|
||||
|
|
@ -172,7 +157,7 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
* Copy plugin metadata from the remote readme.txt file.
|
||||
*
|
||||
* @param string $ref GitHub tag or branch where to look for the readme.
|
||||
* @param Plugin\PluginInfo $pluginInfo
|
||||
* @param Puc_v4p10_Plugin_Info $pluginInfo
|
||||
*/
|
||||
protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
|
||||
$readme = $this->api->getRemoteReadme($ref);
|
||||
|
|
@ -198,77 +183,35 @@ if ( !class_exists(PluginUpdateChecker::class, false) ):
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add icons from the currently installed version to a Plugin Info object.
|
||||
*
|
||||
* The icons should be in a subdirectory named "assets". Supported image formats
|
||||
* and file names are described here:
|
||||
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons
|
||||
*
|
||||
* @param Plugin\PluginInfo $pluginInfo
|
||||
*/
|
||||
protected function setIconsFromLocalAssets($pluginInfo) {
|
||||
$icons = $this->getLocalAssetUrls(array(
|
||||
'icon.svg' => 'svg',
|
||||
'icon-256x256.png' => '2x',
|
||||
'icon-256x256.jpg' => '2x',
|
||||
'icon-128x128.png' => '1x',
|
||||
'icon-128x128.jpg' => '1x',
|
||||
));
|
||||
|
||||
if ( !empty($icons) ) {
|
||||
//The "default" key seems to be used only as last-resort fallback in WP core (5.8/5.9),
|
||||
//but we'll set it anyway in case some code somewhere needs it.
|
||||
reset($icons);
|
||||
$firstKey = key($icons);
|
||||
$icons['default'] = $icons[$firstKey];
|
||||
|
||||
$pluginInfo->icons = $icons;
|
||||
}
|
||||
public function setBranch($branch) {
|
||||
$this->branch = $branch;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add banners from the currently installed version to a Plugin Info object.
|
||||
*
|
||||
* The banners should be in a subdirectory named "assets". Supported image formats
|
||||
* and file names are described here:
|
||||
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-headers
|
||||
*
|
||||
* @param Plugin\PluginInfo $pluginInfo
|
||||
*/
|
||||
protected function setBannersFromLocalAssets($pluginInfo) {
|
||||
$banners = $this->getLocalAssetUrls(array(
|
||||
'banner-772x250.png' => 'high',
|
||||
'banner-772x250.jpg' => 'high',
|
||||
'banner-1544x500.png' => 'low',
|
||||
'banner-1544x500.jpg' => 'low',
|
||||
));
|
||||
|
||||
if ( !empty($banners) ) {
|
||||
$pluginInfo->banners = $banners;
|
||||
}
|
||||
public function setAuthentication($credentials) {
|
||||
$this->api->setAuthentication($credentials);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $filesToKeys
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function getLocalAssetUrls($filesToKeys) {
|
||||
$assetDirectory = $this->package->getAbsoluteDirectoryPath() . DIRECTORY_SEPARATOR . 'assets';
|
||||
if ( !is_dir($assetDirectory) ) {
|
||||
return array();
|
||||
}
|
||||
$assetBaseUrl = trailingslashit(plugins_url('', $assetDirectory . '/imaginary.file'));
|
||||
public function getVcsApi() {
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
$foundAssets = array();
|
||||
foreach ($filesToKeys as $fileName => $key) {
|
||||
$fullBannerPath = $assetDirectory . DIRECTORY_SEPARATOR . $fileName;
|
||||
if ( !isset($icons[$key]) && is_file($fullBannerPath) ) {
|
||||
$foundAssets[$key] = $assetBaseUrl . $fileName;
|
||||
}
|
||||
public function getUpdate() {
|
||||
$update = parent::getUpdate();
|
||||
|
||||
if ( isset($update) && !empty($update->download_url) ) {
|
||||
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
||||
}
|
||||
|
||||
return $foundAssets;
|
||||
return $update;
|
||||
}
|
||||
|
||||
public function onDisplayConfiguration($panel) {
|
||||
parent::onDisplayConfiguration($panel);
|
||||
$panel->row('Branch', $this->branch);
|
||||
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
||||
$panel->row('API client', get_class($this->api));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !class_exists(Reference::class, false) ):
|
||||
if ( !class_exists('Puc_v4p10_Vcs_Reference', false) ):
|
||||
|
||||
/**
|
||||
* This class represents a VCS branch or tag. It's intended as a read only, short-lived container
|
||||
|
|
@ -15,7 +13,7 @@ if ( !class_exists(Reference::class, false) ):
|
|||
* @property string|null $changelog
|
||||
* @property int|null $downloadCount
|
||||
*/
|
||||
class Reference {
|
||||
class Puc_v4p10_Vcs_Reference {
|
||||
private $properties = array();
|
||||
|
||||
public function __construct($properties = array()) {
|
||||
|
|
@ -1,19 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
if ( !class_exists('Puc_v4p10_Vcs_ThemeUpdateChecker', false) ):
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Theme;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Utils;
|
||||
|
||||
if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
||||
|
||||
class ThemeUpdateChecker extends Theme\UpdateChecker implements BaseChecker {
|
||||
use VcsCheckerMethods;
|
||||
class Puc_v4p10_Vcs_ThemeUpdateChecker extends Puc_v4p10_Theme_UpdateChecker implements Puc_v4p10_Vcs_BaseChecker {
|
||||
/**
|
||||
* @var string The branch where to look for updates. Defaults to "master".
|
||||
*/
|
||||
protected $branch = 'master';
|
||||
|
||||
/**
|
||||
* ThemeUpdateChecker constructor.
|
||||
* @var Puc_v4p10_Vcs_Api Repository API client.
|
||||
*/
|
||||
protected $api = null;
|
||||
|
||||
/**
|
||||
* Puc_v4p10_Vcs_ThemeUpdateChecker constructor.
|
||||
*
|
||||
* @param Api $api
|
||||
* @param Puc_v4p10_Vcs_Api $api
|
||||
* @param null $stylesheet
|
||||
* @param null $customSlug
|
||||
* @param int $checkPeriod
|
||||
|
|
@ -21,11 +24,10 @@ if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
|||
*/
|
||||
public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
||||
$this->api = $api;
|
||||
$this->api->setHttpFilterName($this->getUniqueName('request_update_options'));
|
||||
|
||||
parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName);
|
||||
|
||||
$this->api->setHttpFilterName($this->getUniqueName('request_update_options'));
|
||||
$this->api->setStrategyFilterName($this->getUniqueName('vcs_update_detection_strategies'));
|
||||
$this->api->setSlug($this->slug);
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +35,7 @@ if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
|||
$api = $this->api;
|
||||
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
||||
|
||||
$update = new Theme\Update();
|
||||
$update = new Puc_v4p10_Theme_Update();
|
||||
$update->slug = $this->slug;
|
||||
|
||||
//Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
|
||||
|
|
@ -44,7 +46,7 @@ if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
|||
} else {
|
||||
do_action(
|
||||
'puc_api_error',
|
||||
new \WP_Error(
|
||||
new WP_Error(
|
||||
'puc-no-update-source',
|
||||
'Could not retrieve version information from the repository. '
|
||||
. 'This usually means that the update checker either can\'t connect '
|
||||
|
|
@ -58,13 +60,13 @@ if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
|||
//Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata
|
||||
//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
|
||||
$remoteHeader = $this->package->getFileHeader($api->getRemoteFile('style.css', $ref));
|
||||
$update->version = Utils::findNotEmpty(array(
|
||||
$update->version = Puc_v4p10_Utils::findNotEmpty(array(
|
||||
$remoteHeader['Version'],
|
||||
Utils::get($updateSource, 'version'),
|
||||
Puc_v4p10_Utils::get($updateSource, 'version'),
|
||||
));
|
||||
|
||||
//The details URL defaults to the Theme URI header or the repository URL.
|
||||
$update->details_url = Utils::findNotEmpty(array(
|
||||
$update->details_url = Puc_v4p10_Utils::findNotEmpty(array(
|
||||
$remoteHeader['ThemeURI'],
|
||||
$this->package->getHeaderValue('ThemeURI'),
|
||||
$this->metadataUrl,
|
||||
|
|
@ -78,6 +80,39 @@ if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
|||
$update = $this->filterUpdateResult($update);
|
||||
return $update;
|
||||
}
|
||||
|
||||
//FIXME: This is duplicated code. Both theme and plugin subclasses that use VCS share these methods.
|
||||
|
||||
public function setBranch($branch) {
|
||||
$this->branch = $branch;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAuthentication($credentials) {
|
||||
$this->api->setAuthentication($credentials);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVcsApi() {
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
public function getUpdate() {
|
||||
$update = parent::getUpdate();
|
||||
|
||||
if ( isset($update) && !empty($update->download_url) ) {
|
||||
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
public function onDisplayConfiguration($panel) {
|
||||
parent::onDisplayConfiguration($panel);
|
||||
$panel->row('Branch', $this->branch);
|
||||
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
||||
$panel->row('API client', get_class($this->api));
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5;
|
||||
|
||||
if ( !class_exists(PucFactory::class, false) ):
|
||||
|
||||
class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p6\PucFactory {
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
if ( !class_exists(Autoloader::class, false) ):
|
||||
|
||||
class Autoloader {
|
||||
const DEFAULT_NS_PREFIX = 'YahnisElsts\\PluginUpdateChecker\\';
|
||||
|
||||
private $prefix;
|
||||
private $rootDir;
|
||||
private $libraryDir;
|
||||
|
||||
private $staticMap;
|
||||
|
||||
public function __construct() {
|
||||
$this->rootDir = dirname(__FILE__) . '/';
|
||||
|
||||
$namespaceWithSlash = __NAMESPACE__ . '\\';
|
||||
$this->prefix = $namespaceWithSlash;
|
||||
|
||||
$this->libraryDir = $this->rootDir . '../..';
|
||||
if ( !self::isPhar() ) {
|
||||
$this->libraryDir = realpath($this->libraryDir);
|
||||
}
|
||||
$this->libraryDir = $this->libraryDir . '/';
|
||||
|
||||
//Usually, dependencies like Parsedown are in the global namespace,
|
||||
//but if someone adds a custom namespace to the entire library, they
|
||||
//will be in the same namespace as this class.
|
||||
$isCustomNamespace = (
|
||||
substr($namespaceWithSlash, 0, strlen(self::DEFAULT_NS_PREFIX)) !== self::DEFAULT_NS_PREFIX
|
||||
);
|
||||
$libraryPrefix = $isCustomNamespace ? $namespaceWithSlash : '';
|
||||
|
||||
$this->staticMap = array(
|
||||
$libraryPrefix . 'PucReadmeParser' => 'vendor/PucReadmeParser.php',
|
||||
$libraryPrefix . 'Parsedown' => 'vendor/Parsedown.php',
|
||||
);
|
||||
|
||||
//Add the generic, major-version-only factory class to the static map.
|
||||
$versionSeparatorPos = strrpos(__NAMESPACE__, '\\v');
|
||||
if ( $versionSeparatorPos !== false ) {
|
||||
$versionSegment = substr(__NAMESPACE__, $versionSeparatorPos + 1);
|
||||
$pointPos = strpos($versionSegment, 'p');
|
||||
if ( ($pointPos !== false) && ($pointPos > 1) ) {
|
||||
$majorVersionSegment = substr($versionSegment, 0, $pointPos);
|
||||
$majorVersionNs = __NAMESPACE__ . '\\' . $majorVersionSegment;
|
||||
$this->staticMap[$majorVersionNs . '\\PucFactory'] =
|
||||
'Puc/' . $majorVersionSegment . '/Factory.php';
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register(array($this, 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this file is running as part of a Phar archive.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isPhar() {
|
||||
//Check if the current file path starts with "phar://".
|
||||
static $pharProtocol = 'phar://';
|
||||
return (substr(__FILE__, 0, strlen($pharProtocol)) === $pharProtocol);
|
||||
}
|
||||
|
||||
public function autoload($className) {
|
||||
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
||||
include($this->libraryDir . $this->staticMap[$className]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strpos($className, $this->prefix) === 0 ) {
|
||||
$path = substr($className, strlen($this->prefix));
|
||||
$path = str_replace(array('_', '\\'), '/', $path);
|
||||
$path = $this->rootDir . $path . '.php';
|
||||
|
||||
if ( file_exists($path) ) {
|
||||
include $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin\UpdateChecker;
|
||||
|
||||
if ( !class_exists(PluginExtension::class, false) ):
|
||||
|
||||
class PluginExtension extends Extension {
|
||||
/** @var UpdateChecker */
|
||||
protected $updateChecker;
|
||||
|
||||
public function __construct($updateChecker) {
|
||||
parent::__construct($updateChecker, PluginPanel::class);
|
||||
|
||||
add_action('wp_ajax_puc_v5_debug_request_info', array($this, 'ajaxRequestInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request plugin info and output it.
|
||||
*/
|
||||
public function ajaxRequestInfo() {
|
||||
//phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is checked in preAjaxRequest().
|
||||
if ( !isset($_POST['uid']) || ($_POST['uid'] !== $this->updateChecker->getUniqueName('uid')) ) {
|
||||
return;
|
||||
}
|
||||
$this->preAjaxRequest();
|
||||
$info = $this->updateChecker->requestInfo();
|
||||
if ( $info !== null ) {
|
||||
echo 'Successfully retrieved plugin info from the metadata URL:';
|
||||
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- For debugging output.
|
||||
echo '<pre>', esc_html(print_r($info, true)), '</pre>';
|
||||
} else {
|
||||
echo 'Failed to retrieve plugin info from the metadata URL.';
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Plugin\UpdateChecker;
|
||||
|
||||
if ( !class_exists(PluginPanel::class, false) ):
|
||||
|
||||
class PluginPanel extends Panel {
|
||||
/**
|
||||
* @var UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
protected function displayConfigHeader() {
|
||||
$this->row('Plugin file', esc_html($this->updateChecker->pluginFile));
|
||||
parent::displayConfigHeader();
|
||||
}
|
||||
|
||||
protected function getMetadataButton() {
|
||||
$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' => $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;
|
||||
}
|
||||
|
||||
protected function getUpdateFields() {
|
||||
return array_merge(
|
||||
parent::getUpdateFields(),
|
||||
array('homepage', 'upgrade_notice', 'tested',)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\DebugBar;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Theme\UpdateChecker;
|
||||
|
||||
if ( !class_exists(ThemePanel::class, false) ):
|
||||
|
||||
class ThemePanel extends Panel {
|
||||
/**
|
||||
* @var UpdateChecker
|
||||
*/
|
||||
protected $updateChecker;
|
||||
|
||||
protected function displayConfigHeader() {
|
||||
$this->row('Theme directory', esc_html($this->updateChecker->directoryName));
|
||||
parent::displayConfigHeader();
|
||||
}
|
||||
|
||||
protected function getUpdateFields() {
|
||||
return array_merge(parent::getUpdateFields(), array('details_url'));
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
<?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;
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
<?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,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6\Vcs;
|
||||
|
||||
if ( !trait_exists(VcsCheckerMethods::class, false) ) :
|
||||
|
||||
trait VcsCheckerMethods {
|
||||
/**
|
||||
* @var string The branch where to look for updates. Defaults to "master".
|
||||
*/
|
||||
protected $branch = 'master';
|
||||
|
||||
/**
|
||||
* @var Api Repository API client.
|
||||
*/
|
||||
protected $api = null;
|
||||
|
||||
public function setBranch($branch) {
|
||||
$this->branch = $branch;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set authentication credentials.
|
||||
*
|
||||
* @param array|string $credentials
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuthentication($credentials) {
|
||||
$this->api->setAuthentication($credentials);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Api
|
||||
*/
|
||||
public function getVcsApi() {
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
public function getUpdate() {
|
||||
$update = parent::getUpdate();
|
||||
|
||||
if ( isset($update) && !empty($update->download_url) ) {
|
||||
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
public function onDisplayConfiguration($panel) {
|
||||
parent::onDisplayConfiguration($panel);
|
||||
$panel->row('Branch', $this->branch);
|
||||
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
||||
$panel->row('API client', get_class($this->api));
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
191
README.md
191
README.md
|
|
@ -19,8 +19,7 @@ From the users' perspective, it works just like with plugins and themes hosted o
|
|||
- [BitBucket Integration](#bitbucket-integration)
|
||||
- [How to Release an Update](#how-to-release-an-update-2)
|
||||
- [GitLab Integration](#gitlab-integration)
|
||||
- [How to Release a GitLab Update](#how-to-release-a-gitlab-update)
|
||||
- [Migrating from 4.x](#migrating-from-4x)
|
||||
- [How to Release an Update](#how-to-release-an-update-3)
|
||||
- [License Management](#license-management)
|
||||
- [Resources](#resources)
|
||||
|
||||
|
|
@ -29,7 +28,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 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.
|
||||
*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.
|
||||
|
||||
### Self-hosted Plugins and Themes
|
||||
|
||||
|
|
@ -41,7 +40,7 @@ Getting Started
|
|||
{
|
||||
"name" : "Plugin Name",
|
||||
"version" : "2.0",
|
||||
"download_url" : "https://example.com/plugin-name-2.0.zip",
|
||||
"download_url" : "http://example.com/plugin-name-2.0.zip",
|
||||
"sections" : {
|
||||
"description" : "Plugin description here. You can use HTML."
|
||||
}
|
||||
|
|
@ -54,8 +53,8 @@ Getting Started
|
|||
```json
|
||||
{
|
||||
"version": "2.0",
|
||||
"details_url": "https://example.com/version-2.0-details.html",
|
||||
"download_url": "https://example.com/example-theme-2.0.zip"
|
||||
"details_url": "http://example.com/version-2.0-details.html",
|
||||
"download_url": "http://example.com/example-theme-2.0.zip"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -65,10 +64,8 @@ Getting Started
|
|||
|
||||
```php
|
||||
require 'path/to/plugin-update-checker/plugin-update-checker.php';
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||
'https://example.com/path/to/details.json',
|
||||
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
||||
'http://example.com/path/to/details.json',
|
||||
__FILE__, //Full path to the main plugin file or functions.php.
|
||||
'unique-plugin-or-theme-slug'
|
||||
);
|
||||
|
|
@ -99,19 +96,17 @@ By default, the library will check the specified URL for changes every 12 hours.
|
|||
|
||||
```php
|
||||
require 'plugin-update-checker/plugin-update-checker.php';
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
||||
'https://github.com/user-name/repo-name/',
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
);
|
||||
|
||||
//Set the branch that contains the stable release.
|
||||
$myUpdateChecker->setBranch('stable-branch-name');
|
||||
|
||||
//Optional: If you're using a private repository, specify the access token like this:
|
||||
$myUpdateChecker->setAuthentication('your-token-here');
|
||||
|
||||
//Optional: Set the branch that contains the stable release.
|
||||
$myUpdateChecker->setBranch('stable-branch-name');
|
||||
```
|
||||
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.
|
||||
|
||||
|
|
@ -132,7 +127,7 @@ This library supports a couple of different ways to release updates on GitHub. P
|
|||
|
||||
To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
|
||||
|
||||
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 GitHub releases or branches instead.
|
||||
PUC doesn't require strict adherence to [SemVer](http://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 GitHub releases or branches instead.
|
||||
|
||||
- **Stable branch**
|
||||
|
||||
|
|
@ -180,9 +175,7 @@ The library will pull update details from the following parts of a release/tag/b
|
|||
|
||||
```php
|
||||
require 'plugin-update-checker/plugin-update-checker.php';
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
||||
'https://bitbucket.org/user-name/repo-name',
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
|
|
@ -221,7 +214,7 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
|||
|
||||
You can skip the "stable tag" bit and just create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at the most recent tags and pick the one that looks like the highest version number.
|
||||
|
||||
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.
|
||||
PUC doesn't require strict adherence to [SemVer](http://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.
|
||||
|
||||
- **Stable branch**
|
||||
|
||||
|
|
@ -234,13 +227,11 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
|||
### GitLab Integration
|
||||
|
||||
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
||||
2. Add the following code to the main plugin file or `functions.php` and define how you want to check for updates from Gitlab (refer to: [Gitlab: How to Release an Update](#how-to-release-a-gitlab-update)):
|
||||
2. Add the following code to the main plugin file or `functions.php`:
|
||||
|
||||
```php
|
||||
require 'plugin-update-checker/plugin-update-checker.php';
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
||||
'https://gitlab.com/user-name/repo-name/',
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
|
|
@ -248,125 +239,63 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
|||
|
||||
//Optional: If you're using a private repository, specify the access token like this:
|
||||
$myUpdateChecker->setAuthentication('your-token-here');
|
||||
```
|
||||
|
||||
Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:
|
||||
```php
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\PluginUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\GitLabApi;
|
||||
|
||||
$myUpdateChecker = new PluginUpdateChecker(
|
||||
new GitLabApi('https://myserver.com/user-name/repo-name/'),
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
);
|
||||
//Optional: Add setAuthentication(...) and setBranch(...) as shown above.
|
||||
```
|
||||
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\v5p6\Vcs\PluginUpdateChecker;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\Vcs\GitLabApi;
|
||||
|
||||
$myUpdateChecker = new PluginUpdateChecker(
|
||||
new GitLabApi(
|
||||
'https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/',
|
||||
null,
|
||||
'subgroup-level1/subgroup-level2/subgroup-level3'
|
||||
),
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
);
|
||||
```
|
||||
|
||||
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 3 different ways.
|
||||
|
||||
- **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**
|
||||
|
||||
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**
|
||||
|
||||
Point the update checker at any stable, production-ready branch:
|
||||
```php
|
||||
//Optional: Set the branch that contains the stable release.
|
||||
$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.
|
||||
|
||||
Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:
|
||||
```php
|
||||
$myUpdateChecker = new Puc_v4p10_Vcs_PluginUpdateChecker(
|
||||
new Puc_v4p10_Vcs_GitLabApi('https://myserver.com/user-name/repo-name/'),
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
);
|
||||
//Optional: Add setAuthentication(...) and setBranch(...) as shown above.
|
||||
```
|
||||
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
|
||||
$myUpdateChecker = new Puc_v4p10_Vcs_PluginUpdateChecker(
|
||||
new Puc_v4p10_Vcs_GitLabApi('https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/', null, 'subgroup-level1/subgroup-level2/subgroup-level3'),
|
||||
__FILE__,
|
||||
'unique-plugin-or-theme-slug'
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Migrating from 4.x
|
||||
------------------
|
||||
#### How to Release an Update
|
||||
|
||||
Older versions of the library didn't use namespaces. Code that was written for those versions will need to be updated to work with the current version. At a minimum, you'll need to change the factory class name.
|
||||
GitLab doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:
|
||||
|
||||
- **Tags**
|
||||
|
||||
To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
|
||||
|
||||
PUC doesn't require strict adherence to [SemVer](http://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.
|
||||
|
||||
Old code:
|
||||
```php
|
||||
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
||||
'https://example.com/info.json',
|
||||
__FILE__,
|
||||
'my-slug'
|
||||
);
|
||||
```
|
||||
|
||||
New code:
|
||||
```php
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||
'https://example.com/info.json',
|
||||
__FILE__,
|
||||
'my-slug'
|
||||
);
|
||||
```
|
||||
|
||||
Other classes have also been renamed, usually by simply removing the `Puc_vXpY_` prefix and converting `Category_Thing` to `Category\Thing`. Here's a table of the most commonly used classes and their new names:
|
||||
|
||||
| Old class name | New class name |
|
||||
|-------------------------------------|----------------------------------------------------------------|
|
||||
| `Puc_v4_Factory` | `YahnisElsts\PluginUpdateChecker\v5\PucFactory` |
|
||||
| `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` |
|
||||
- **Stable branch**
|
||||
|
||||
Point the update checker at a stable, production-ready branch:
|
||||
```php
|
||||
$updateChecker->setBranch('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: If you set the branch to `master` (the default), the update checker will look for recent releases and tags first. It'll only use the `master` branch if it doesn't find anything else suitable.
|
||||
|
||||
License Management
|
||||
------------------
|
||||
|
||||
Currently, the update checker doesn't have any built-in license management features. It only provides some hooks that you can use to, for example, append license keys to update requests (`$updateChecker->addQueryArgFilter()`). If you're looking for ways to manage and verify licenses, please post your feedback in [this issue](https://github.com/YahnisElsts/plugin-update-checker/issues/222).
|
||||
Currently, the update checker doesn't have any built-in license management features. It only provides some hooks that you can use to, for example, append license keys to update requests (`$updateChecker->addQueryArgFilter()`). If you're looking for ways to manage and verify licenses, please post your feedback in [this issue](https://github.com/YahnisElsts/plugin-update-checker/issues/222).
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
- [This blog post](https://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/) has more information about the update checker API. *Slightly out of date.*
|
||||
- [This blog post](http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/) has more information about the update checker API. *Slightly out of date.*
|
||||
- [Debug Bar](https://wordpress.org/plugins/debug-bar/) - useful for testing and debugging the update checker.
|
||||
- [Update format reference](https://docs.google.com/spreadsheets/d/1eOBbW7Go2qEQXReOOCdidMTf_tDYRq4JfegcO1CBPIs/edit?usp=sharing) - describes all fields supported by the JSON-based update information format used by the update checker. Only covers plugins. Themes use a similar but more limited format.
|
||||
- [Securing download links](https://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
|
||||
- [A GUI for entering download credentials](https://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
|
||||
- [Theme Update Checker](https://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/) - an older, theme-only variant of this update checker.
|
||||
- [Securing download links](http://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
|
||||
- [A GUI for entering download credentials](http://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
|
||||
- [Theme Update Checker](http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/) - an older, theme-only variant of this update checker.
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
<?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);
|
||||
|
||||
|
|
@ -9,15 +9,15 @@
|
|||
{
|
||||
"name": "Yahnis Elsts",
|
||||
"email": "whiteshadow@w-shadow.com",
|
||||
"homepage": "https://w-shadow.com/",
|
||||
"homepage": "http://w-shadow.com/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6.20",
|
||||
"php": ">=5.2.0",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["load-v5p6.php"]
|
||||
"files": ["load-v4p10.php"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
.puc-debug-bar-panel-v5 pre {
|
||||
.puc-debug-bar-panel-v4 pre {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ jQuery(function($) {
|
|||
|
||||
function runAjaxAction(button, action) {
|
||||
button = $(button);
|
||||
var panel = button.closest('.puc-debug-bar-panel-v5');
|
||||
var panel = button.closest('.puc-debug-bar-panel-v4');
|
||||
var responseBox = button.closest('td').find('.puc-ajax-response');
|
||||
|
||||
responseBox.text('Processing...').show();
|
||||
|
|
@ -14,21 +14,19 @@ 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'
|
||||
);
|
||||
}
|
||||
|
||||
$('.puc-debug-bar-panel-v5 input[name="puc-check-now-button"]').on('click', function() {
|
||||
runAjaxAction(this, 'puc_v5_debug_check_now');
|
||||
$('.puc-debug-bar-panel-v4 input[name="puc-check-now-button"]').click(function() {
|
||||
runAjaxAction(this, 'puc_v4_debug_check_now');
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.puc-debug-bar-panel-v5 input[name="puc-request-info-button"]').on('click', function() {
|
||||
runAjaxAction(this, 'puc_v5_debug_request_info');
|
||||
$('.puc-debug-bar-panel-v4 input[name="puc-request-info-button"]').click(function() {
|
||||
runAjaxAction(this, 'puc_v4_debug_request_info');
|
||||
return false;
|
||||
});
|
||||
|
||||
|
|
@ -36,7 +34,7 @@ jQuery(function($) {
|
|||
// Debug Bar uses the panel class name as part of its link and container IDs. This means we can
|
||||
// end up with multiple identical IDs if more than one plugin uses the update checker library.
|
||||
// Fix it by replacing the class name with the plugin slug.
|
||||
var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v5');
|
||||
var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v4');
|
||||
panels.each(function() {
|
||||
var panel = $(this);
|
||||
var uid = panel.data('uid');
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,52 +0,0 @@
|
|||
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,50 +1,38 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\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"
|
||||
"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"
|
||||
"Language: fa_IR\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 3.6\n"
|
||||
"X-Generator: Poedit 1.8.8\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:56
|
||||
msgid "View details"
|
||||
msgstr "مشاهده جزئیات"
|
||||
#: github-checker.php:120
|
||||
msgid "There is no changelog available."
|
||||
msgstr "شرحی برای تغییرات یافت نشد"
|
||||
|
||||
#: 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
|
||||
#: plugin-update-checker.php:637
|
||||
msgid "Check for updates"
|
||||
msgstr "بررسی بروزرسانی جدید"
|
||||
msgstr "بررسی برای بروزرسانی "
|
||||
|
||||
# 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
|
||||
#: 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
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%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 "نسخه جدیدی برای افزونه ارائه شده است ."
|
||||
msgstr "وضعیت ناشناخته برای بروزرسانی \"%s\""
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,48 +1,38 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2020-08-08 14:36+0300\n"
|
||||
"PO-Revision-Date: 2022-05-20 00:17+0200\n"
|
||||
"POT-Creation-Date: 2016-06-29 20:21+0100\n"
|
||||
"PO-Revision-Date: 2017-01-15 12:24+0100\n"
|
||||
"Last-Translator: Igor Lückel <info@igorlueckel.de>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 3.0\n"
|
||||
"X-Generator: Poedit 1.5.5\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"Last-Translator: d79\n"
|
||||
"Language: it_IT\n"
|
||||
"X-Poedit-KeywordsList: __;_e\n"
|
||||
"Language: de_DE\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:128
|
||||
#: github-checker.php:137
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Non c'è alcuna sezione di aggiornamento disponibile"
|
||||
|
||||
#: plugin-update-checker.php:852
|
||||
msgid "Check for updates"
|
||||
msgstr "Verifica aggiornamenti"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:213
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "Il plugin %s è aggiornato."
|
||||
#: plugin-update-checker.php:896
|
||||
msgid "This plugin is up to date."
|
||||
msgstr "Il plugin è aggiornato"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:215
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "Una nuova versione del plugin %s è disponibile."
|
||||
#: plugin-update-checker.php:898
|
||||
msgid "A new version of this plugin is available."
|
||||
msgstr "Una nuova versione del plugin è disponibile"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "Non è possibile verificare se c'è un aggiornamento disponibile per %s."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:223
|
||||
#: plugin-update-checker.php:900
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "Stato di controllo aggiornamenti sconosciuto \"%s\""
|
||||
|
||||
#: Puc/v4p11/Vcs/PluginUpdateChecker.php:98
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Non c'è alcun registro delle modifiche disponibile."
|
||||
msgstr "Si è verificato un problema sconosciuto \"%s\""
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,48 +0,0 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2020-08-08 14:36+0300\n"
|
||||
"PO-Revision-Date: 2021-12-20 17:59+0200\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 2.2\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"Last-Translator: \n"
|
||||
"Language: ru_RU\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:128
|
||||
msgid "Check for updates"
|
||||
msgstr "Проверить обновления"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:213
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "Плагин %s обновлён."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:215
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "Новая версия %s доступна."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "Не удалось определить, доступны ли обновления для %s."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:223
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "Неизвестный статус средства проверки обновлений \"%s\""
|
||||
|
||||
#: Puc/v4p11/Vcs/PluginUpdateChecker.php:98
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Журнал изменений отсутствует."
|
||||
Binary file not shown.
|
|
@ -1,57 +0,0 @@
|
|||
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,48 +0,0 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||
"PO-Revision-Date: 2021-11-15 19:07+0300\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 3.0\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"Last-Translator: Emre Erkan <kara@karalamalar.net>\n"
|
||||
"Language: tr\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||
msgid "Check for updates"
|
||||
msgstr "Güncellemeleri kontrol et"
|
||||
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "%s eklentisi güncel."
|
||||
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "%s eklentisinin yeni bir sürümü mevcut."
|
||||
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "%s için güncelleme olup olmadığı belirlenemedi."
|
||||
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "Bilinmeyen güncelleme denetleyicisi durumu \"%s\""
|
||||
|
||||
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Kullanılabilir bir değişiklik yok."
|
||||
Binary file not shown.
|
|
@ -1,48 +0,0 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2020-08-08 14:36+0300\n"
|
||||
"PO-Revision-Date: 2021-12-20 17:55+0200\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 2.2\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"Last-Translator: \n"
|
||||
"Language: uk_UA\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:128
|
||||
msgid "Check for updates"
|
||||
msgstr "Перевірити оновлення"
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:213
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "Плагін %s оновлено."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:215
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "Нова версія %s доступна."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "Не вдалося визначити, чи доступні оновлення для %s."
|
||||
|
||||
#: Puc/v4p11/Plugin/Ui.php:223
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "Невідомий статус перевірки оновлень \"%s\""
|
||||
|
||||
#: Puc/v4p11/Vcs/PluginUpdateChecker.php:98
|
||||
msgid "There is no changelog available."
|
||||
msgstr "Немає доступного журналу змін."
|
||||
Binary file not shown.
|
|
@ -1,57 +1,48 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\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"
|
||||
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||
"PO-Revision-Date: 2020-08-04 08:10+0800\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"
|
||||
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||
"X-Generator: Poedit 3.8\n"
|
||||
"X-Generator: Poedit 2.4\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"Last-Translator: Seaton Jiang <seaton@vtrois.com>\n"
|
||||
"Language: zh_CN\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
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||
msgid "Check for updates"
|
||||
msgstr "检查更新"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:217
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr "%s 目前是最新版本。"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:219
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr "%s 当前有可用的更新。"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:221
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr "%s 无法确定是否有可用的更新。"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:227
|
||||
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr "未知的更新检查状态:%s"
|
||||
|
||||
#: Puc/v5p6/Vcs/PluginUpdateChecker.php:113
|
||||
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||
msgid "There is no changelog available."
|
||||
msgstr "没有可用的更新日志。"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,66 +0,0 @@
|
|||
# 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,48 +2,48 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plugin-update-checker\n"
|
||||
"POT-Creation-Date: 2025-05-20 15:27+0300\n"
|
||||
"POT-Creation-Date: 2020-08-08 14:36+0300\n"
|
||||
"PO-Revision-Date: 2016-01-10 20:59+0100\n"
|
||||
"Last-Translator: \n"
|
||||
"Last-Translator: Tamás András Horváth <htomy92@gmail.com>\n"
|
||||
"Language-Team: \n"
|
||||
"Language: en_US\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 3.6\n"
|
||||
"X-Generator: Poedit 2.4\n"
|
||||
"X-Poedit-Basepath: ..\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:130
|
||||
#: Puc/v4p10/Plugin/Ui.php:128
|
||||
msgid "Check for updates"
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:217
|
||||
#: Puc/v4p10/Plugin/Ui.php:213
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "The %s plugin is up to date."
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:219
|
||||
#: Puc/v4p10/Plugin/Ui.php:215
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "A new version of the %s plugin is available."
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:221
|
||||
#: Puc/v4p10/Plugin/Ui.php:217
|
||||
#, php-format
|
||||
msgctxt "the plugin title"
|
||||
msgid "Could not determine if updates are available for %s."
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p6/Plugin/Ui.php:227
|
||||
#: Puc/v4p10/Plugin/Ui.php:223
|
||||
#, php-format
|
||||
msgid "Unknown update checker status \"%s\""
|
||||
msgstr ""
|
||||
|
||||
#: Puc/v5p6/Vcs/PluginUpdateChecker.php:113
|
||||
#: Puc/v4p10/Vcs/PluginUpdateChecker.php:98
|
||||
msgid "There is no changelog available."
|
||||
msgstr ""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2023 Jānis Elsts
|
||||
Copyright (c) 2017 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:
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
require dirname(__FILE__) . '/Puc/v4p10/Autoloader.php';
|
||||
new Puc_v4p10_Autoloader();
|
||||
|
||||
require dirname(__FILE__) . '/Puc/v4p10/Factory.php';
|
||||
require dirname(__FILE__) . '/Puc/v4/Factory.php';
|
||||
|
||||
//Register classes defined in this version with the factory.
|
||||
foreach (
|
||||
array(
|
||||
'Plugin_UpdateChecker' => 'Puc_v4p10_Plugin_UpdateChecker',
|
||||
'Theme_UpdateChecker' => 'Puc_v4p10_Theme_UpdateChecker',
|
||||
|
||||
'Vcs_PluginUpdateChecker' => 'Puc_v4p10_Vcs_PluginUpdateChecker',
|
||||
'Vcs_ThemeUpdateChecker' => 'Puc_v4p10_Vcs_ThemeUpdateChecker',
|
||||
|
||||
'GitHubApi' => 'Puc_v4p10_Vcs_GitHubApi',
|
||||
'BitBucketApi' => 'Puc_v4p10_Vcs_BitBucketApi',
|
||||
'GitLabApi' => 'Puc_v4p10_Vcs_GitLabApi',
|
||||
)
|
||||
as $pucGeneralClass => $pucVersionedClass
|
||||
) {
|
||||
Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.10');
|
||||
//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.
|
||||
Puc_v4p10_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.10');
|
||||
}
|
||||
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace YahnisElsts\PluginUpdateChecker\v5p6;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory as MajorFactory;
|
||||
use YahnisElsts\PluginUpdateChecker\v5p6\PucFactory as MinorFactory;
|
||||
|
||||
require __DIR__ . '/Puc/v5p6/Autoloader.php';
|
||||
new Autoloader();
|
||||
|
||||
require __DIR__ . '/Puc/v5p6/PucFactory.php';
|
||||
require __DIR__ . '/Puc/v5/PucFactory.php';
|
||||
|
||||
//Register classes defined in this version with the factory.
|
||||
foreach (
|
||||
array(
|
||||
'Plugin\\UpdateChecker' => Plugin\UpdateChecker::class,
|
||||
'Theme\\UpdateChecker' => Theme\UpdateChecker::class,
|
||||
|
||||
'Vcs\\PluginUpdateChecker' => Vcs\PluginUpdateChecker::class,
|
||||
'Vcs\\ThemeUpdateChecker' => Vcs\ThemeUpdateChecker::class,
|
||||
|
||||
'GitHubApi' => Vcs\GitHubApi::class,
|
||||
'BitBucketApi' => Vcs\BitBucketApi::class,
|
||||
'GitLabApi' => Vcs\GitLabApi::class,
|
||||
)
|
||||
as $pucGeneralClass => $pucVersionedClass
|
||||
) {
|
||||
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.6');
|
||||
}
|
||||
|
||||
21
phpcs.xml
21
phpcs.xml
|
|
@ -1,21 +0,0 @@
|
|||
<?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.6
|
||||
* Plugin Update Checker Library 4.10
|
||||
* http://w-shadow.com/
|
||||
*
|
||||
* Copyright 2025 Janis Elsts
|
||||
* Copyright 2020 Janis Elsts
|
||||
* Released under the MIT license. See license.txt for details.
|
||||
*/
|
||||
|
||||
require dirname(__FILE__) . '/load-v5p6.php';
|
||||
require dirname(__FILE__) . '/load-v4p10.php';
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
if ( !class_exists('Parsedown', false) ) {
|
||||
require __DIR__ . '/ParsedownModern.php';
|
||||
//Load the Parsedown version that's compatible with the current PHP version.
|
||||
if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
|
||||
require __DIR__ . '/ParsedownModern.php';
|
||||
} else {
|
||||
require __DIR__ . '/ParsedownLegacy.php';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -648,7 +648,7 @@ class Parsedown
|
|||
#
|
||||
# Setext
|
||||
|
||||
protected function blockSetextHeader($Line, $Block = null)
|
||||
protected function blockSetextHeader($Line, array $Block = null)
|
||||
{
|
||||
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
||||
{
|
||||
|
|
@ -786,7 +786,7 @@ class Parsedown
|
|||
#
|
||||
# Table
|
||||
|
||||
protected function blockTable($Line, $Block = null)
|
||||
protected function blockTable($Line, array $Block = null)
|
||||
{
|
||||
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -241,11 +241,7 @@ class PucReadmeParser {
|
|||
}
|
||||
|
||||
function sanitize_text( $text ) { // not fancy
|
||||
$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 = strip_tags($text);
|
||||
$text = esc_html($text);
|
||||
$text = trim($text);
|
||||
return $text;
|
||||
|
|
|
|||
Loading…
Reference in New Issue