Put all^ PUC classes in namespaces.
^ Except dependencies like Parsedown. The readme is now out of date. The legacy version of Parsedown was removed because we no longer need to support PHP versions older than 5.3. The stub file that loads ParsedownModern.php stays in place because it has the "class_exists" check.
This commit is contained in:
parent
90bee76fa9
commit
4b6127f0f2
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
if ( !class_exists('Puc_v4_Factory', false) ):
|
|
||||||
|
|
||||||
class Puc_v4_Factory extends Puc_v5p0_Factory { }
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5;
|
||||||
|
|
||||||
|
if ( !class_exists(PucFactory::class, false) ):
|
||||||
|
|
||||||
|
class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p0\PucFactory {
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
@ -1,25 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Autoloader', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
class Puc_v5p0_Autoloader {
|
if ( !class_exists(Autoloader::class, false) ):
|
||||||
private $prefix = '';
|
|
||||||
private $rootDir = '';
|
class Autoloader {
|
||||||
private $libraryDir = '';
|
const DEFAULT_NS_PREFIX = 'YahnisElsts\\PluginUpdateChecker\\';
|
||||||
|
|
||||||
|
private $prefix;
|
||||||
|
private $rootDir;
|
||||||
|
private $libraryDir;
|
||||||
|
|
||||||
private $staticMap;
|
private $staticMap;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->rootDir = dirname(__FILE__) . '/';
|
$this->rootDir = dirname(__FILE__) . '/';
|
||||||
|
|
||||||
if ( version_compare(PHP_VERSION, '5.3', '>=') && __NAMESPACE__ ) {
|
|
||||||
$namespaceWithSlash = __NAMESPACE__ . '\\';
|
$namespaceWithSlash = __NAMESPACE__ . '\\';
|
||||||
} else {
|
$this->prefix = $namespaceWithSlash;
|
||||||
$namespaceWithSlash = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$nameParts = explode('_', substr(__CLASS__, strlen($namespaceWithSlash)), 3);
|
|
||||||
$this->prefix = $namespaceWithSlash . $nameParts[0] . '_' . $nameParts[1] . '_';
|
|
||||||
|
|
||||||
$this->libraryDir = $this->rootDir . '../..';
|
$this->libraryDir = $this->rootDir . '../..';
|
||||||
if ( !self::isPhar() ) {
|
if ( !self::isPhar() ) {
|
||||||
|
|
@ -27,11 +25,31 @@ if ( !class_exists('Puc_v5p0_Autoloader', false) ):
|
||||||
}
|
}
|
||||||
$this->libraryDir = $this->libraryDir . '/';
|
$this->libraryDir = $this->libraryDir . '/';
|
||||||
|
|
||||||
$this->staticMap = array(
|
//Usually, dependencies like Parsedown are in the global namespace,
|
||||||
$namespaceWithSlash . 'PucReadmeParser' => 'vendor/PucReadmeParser.php',
|
//but if someone adds a custom namespace to the entire library, they
|
||||||
$namespaceWithSlash . 'Parsedown' => 'vendor/Parsedown.php',
|
//will be in the same namespace as this class.
|
||||||
$namespaceWithSlash . 'Puc_v4_Factory' => 'Puc/v4/Factory.php',
|
$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'));
|
spl_autoload_register(array($this, 'autoload'));
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +67,6 @@ if ( !class_exists('Puc_v5p0_Autoloader', false) ):
|
||||||
|
|
||||||
public function autoload($className) {
|
public function autoload($className) {
|
||||||
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
include($this->libraryDir . $this->staticMap[$className]);
|
include($this->libraryDir . $this->staticMap[$className]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +77,6 @@ if ( !class_exists('Puc_v5p0_Autoloader', false) ):
|
||||||
$path = $this->rootDir . $path . '.php';
|
$path = $this->rootDir . $path . '.php';
|
||||||
|
|
||||||
if ( file_exists($path) ) {
|
if ( file_exists($path) ) {
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
include $path;
|
include $path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_DebugBar_Extension', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
|
|
||||||
class Puc_v5p0_DebugBar_Extension {
|
use YahnisElsts\PluginUpdateChecker\v5p0\PucFactory;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker;
|
||||||
|
|
||||||
|
if ( !class_exists(Extension::class, false) ):
|
||||||
|
|
||||||
|
class Extension {
|
||||||
const RESPONSE_BODY_LENGTH_LIMIT = 4000;
|
const RESPONSE_BODY_LENGTH_LIMIT = 4000;
|
||||||
|
|
||||||
/** @var Puc_v5p0_UpdateChecker */
|
/** @var UpdateChecker */
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
protected $panelClass = 'Puc_v5p0_DebugBar_Panel';
|
protected $panelClass = Panel::class;
|
||||||
|
|
||||||
public function __construct($updateChecker, $panelClass = null) {
|
public function __construct($updateChecker, $panelClass = null) {
|
||||||
$this->updateChecker = $updateChecker;
|
$this->updateChecker = $updateChecker;
|
||||||
|
|
@ -79,7 +84,7 @@ if ( !class_exists('Puc_v5p0_DebugBar_Extension', false) ):
|
||||||
|
|
||||||
foreach (array_values($errors) as $num => $item) {
|
foreach (array_values($errors) as $num => $item) {
|
||||||
$wpError = $item['error'];
|
$wpError = $item['error'];
|
||||||
/** @var WP_Error $wpError */
|
/** @var \WP_Error $wpError */
|
||||||
printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
|
printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
|
||||||
|
|
||||||
echo '<dl>';
|
echo '<dl>';
|
||||||
|
|
@ -92,7 +97,7 @@ if ( !class_exists('Puc_v5p0_DebugBar_Extension', false) ):
|
||||||
if ( isset($item['httpResponse']) ) {
|
if ( isset($item['httpResponse']) ) {
|
||||||
if ( is_wp_error($item['httpResponse']) ) {
|
if ( is_wp_error($item['httpResponse']) ) {
|
||||||
$httpError = $item['httpResponse'];
|
$httpError = $item['httpResponse'];
|
||||||
/** @var WP_Error $httpError */
|
/** @var \WP_Error $httpError */
|
||||||
printf(
|
printf(
|
||||||
'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
|
'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
|
||||||
esc_html($httpError->get_error_message()),
|
esc_html($httpError->get_error_message()),
|
||||||
|
|
@ -163,11 +168,11 @@ if ( !class_exists('Puc_v5p0_DebugBar_Extension', false) ):
|
||||||
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
|
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
|
||||||
|
|
||||||
//Where is the library located inside the WordPress directory structure?
|
//Where is the library located inside the WordPress directory structure?
|
||||||
$absolutePath = Puc_v5p0_Factory::normalizePath($absolutePath);
|
$absolutePath = PucFactory::normalizePath($absolutePath);
|
||||||
|
|
||||||
$pluginDir = Puc_v5p0_Factory::normalizePath(WP_PLUGIN_DIR);
|
$pluginDir = PucFactory::normalizePath(WP_PLUGIN_DIR);
|
||||||
$muPluginDir = Puc_v5p0_Factory::normalizePath(WPMU_PLUGIN_DIR);
|
$muPluginDir = PucFactory::normalizePath(WPMU_PLUGIN_DIR);
|
||||||
$themeDir = Puc_v5p0_Factory::normalizePath(get_theme_root());
|
$themeDir = PucFactory::normalizePath(get_theme_root());
|
||||||
|
|
||||||
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
||||||
//It's part of a plugin.
|
//It's part of a plugin.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
|
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker;
|
||||||
|
|
||||||
class Puc_v5p0_DebugBar_Panel extends Debug_Bar_Panel {
|
if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false) ):
|
||||||
/** @var Puc_v5p0_UpdateChecker */
|
|
||||||
|
class Panel extends \Debug_Bar_Panel {
|
||||||
|
/** @var UpdateChecker */
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_DebugBar_PluginExtension', false) ):
|
|
||||||
|
|
||||||
class Puc_v5p0_DebugBar_PluginExtension extends Puc_v5p0_DebugBar_Extension {
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
/** @var Puc_v5p0_Plugin_UpdateChecker */
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin\UpdateChecker;
|
||||||
|
|
||||||
|
if ( !class_exists(PluginExtension::class, false) ):
|
||||||
|
|
||||||
|
class PluginExtension extends Extension {
|
||||||
|
/** @var UpdateChecker */
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
public function __construct($updateChecker) {
|
public function __construct($updateChecker) {
|
||||||
parent::__construct($updateChecker, 'Puc_v5p0_DebugBar_PluginPanel');
|
parent::__construct($updateChecker, PluginPanel::class);
|
||||||
|
|
||||||
add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
|
add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_DebugBar_PluginPanel', false) ):
|
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin\UpdateChecker;
|
||||||
|
|
||||||
class Puc_v5p0_DebugBar_PluginPanel extends Puc_v5p0_DebugBar_Panel {
|
if ( !class_exists(PluginPanel::class, false) ):
|
||||||
|
|
||||||
|
class PluginPanel extends Panel {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Plugin_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_DebugBar_ThemePanel', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
|
|
||||||
class Puc_v5p0_DebugBar_ThemePanel extends Puc_v5p0_DebugBar_Panel {
|
use YahnisElsts\PluginUpdateChecker\v5p0\Theme\UpdateChecker;
|
||||||
|
|
||||||
|
if ( !class_exists(ThemePanel::class, false) ):
|
||||||
|
|
||||||
|
class ThemePanel extends Panel {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Theme_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_InstalledPackage', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
if ( !class_exists(InstalledPackage::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a currently installed plugin or theme.
|
* This class represents a currently installed plugin or theme.
|
||||||
|
|
@ -7,9 +9,9 @@ if ( !class_exists('Puc_v5p0_InstalledPackage', false) ):
|
||||||
* Not to be confused with the "package" field in WP update API responses that contains
|
* Not to be confused with the "package" field in WP update API responses that contains
|
||||||
* the download URL of a the new version.
|
* the download URL of a the new version.
|
||||||
*/
|
*/
|
||||||
abstract class Puc_v5p0_InstalledPackage {
|
abstract class InstalledPackage {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
use LogicException;
|
||||||
|
use stdClass;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
|
if ( !class_exists(Metadata::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base container for holding information about updates and plugin metadata.
|
* A base container for holding information about updates and plugin metadata.
|
||||||
|
|
@ -8,7 +14,7 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
* @copyright 2016
|
* @copyright 2016
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
abstract class Puc_v5p0_Metadata {
|
abstract class Metadata {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of this class from a JSON document.
|
* Create an instance of this class from a JSON document.
|
||||||
|
|
@ -17,7 +23,7 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
* @param string $json
|
* @param string $json
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
|
public static function fromJson($json) {
|
||||||
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,7 +33,7 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected static function createFromJson($json, $target) {
|
protected static function createFromJson($json, $target) {
|
||||||
/** @var StdClass $apiResponse */
|
/** @var \StdClass $apiResponse */
|
||||||
$apiResponse = json_decode($json);
|
$apiResponse = json_decode($json);
|
||||||
if ( empty($apiResponse) || !is_object($apiResponse) ){
|
if ( empty($apiResponse) || !is_object($apiResponse) ){
|
||||||
$errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
|
$errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
|
||||||
|
|
@ -53,10 +59,10 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
/**
|
/**
|
||||||
* No validation by default! Subclasses should check that the required fields are present.
|
* No validation by default! Subclasses should check that the required fields are present.
|
||||||
*
|
*
|
||||||
* @param StdClass $apiResponse
|
* @param \StdClass $apiResponse
|
||||||
* @return bool|WP_Error
|
* @return bool|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
|
protected function validateMetadata($apiResponse) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,10 +70,10 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
* Create a new instance by copying the necessary fields from another object.
|
* Create a new instance by copying the necessary fields from another object.
|
||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
* @param StdClass|self $object The source object.
|
* @param \StdClass|self $object The source object.
|
||||||
* @return self The new copy.
|
* @return self The new copy.
|
||||||
*/
|
*/
|
||||||
public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
|
public static function fromObject($object) {
|
||||||
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +83,7 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
* avoids the "incomplete object" problem if the cached value is loaded
|
* avoids the "incomplete object" problem if the cached value is loaded
|
||||||
* before this class.
|
* before this class.
|
||||||
*
|
*
|
||||||
* @return StdClass
|
* @return \StdClass
|
||||||
*/
|
*/
|
||||||
public function toStdClass() {
|
public function toStdClass() {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
|
|
@ -95,8 +101,8 @@ if ( !class_exists('Puc_v5p0_Metadata', false) ):
|
||||||
/**
|
/**
|
||||||
* Copy known fields from one object to another.
|
* Copy known fields from one object to another.
|
||||||
*
|
*
|
||||||
* @param StdClass|self $from
|
* @param \StdClass|self $from
|
||||||
* @param StdClass|self $to
|
* @param \StdClass|self $to
|
||||||
*/
|
*/
|
||||||
protected function copyFields($from, $to) {
|
protected function copyFields($from, $to) {
|
||||||
$fields = $this->getFieldNames();
|
$fields = $this->getFieldNames();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_OAuthSignature', false) ):
|
if ( !class_exists(OAuthSignature::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic signature generator for zero-legged OAuth 1.0.
|
* A basic signature generator for zero-legged OAuth 1.0.
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_OAuthSignature {
|
class OAuthSignature {
|
||||||
private $consumerKey = '';
|
private $consumerKey = '';
|
||||||
private $consumerSecret = '';
|
private $consumerSecret = '';
|
||||||
|
|
||||||
|
|
@ -85,7 +86,7 @@ if ( !class_exists('Puc_v5p0_OAuthSignature', false) ):
|
||||||
if ( is_callable('random_bytes') ) {
|
if ( is_callable('random_bytes') ) {
|
||||||
try {
|
try {
|
||||||
$rand = random_bytes(16);
|
$rand = random_bytes(16);
|
||||||
} catch (Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
//Fall back to mt_rand (below).
|
//Fall back to mt_rand (below).
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Plugin_Package', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
class Puc_v5p0_Plugin_Package extends Puc_v5p0_InstalledPackage {
|
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\PucFactory;
|
||||||
|
|
||||||
|
if ( !class_exists(Package::class, false) ):
|
||||||
|
|
||||||
|
class Package extends InstalledPackage {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Plugin_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
|
|
@ -140,7 +145,6 @@ if ( !class_exists('Puc_v5p0_Plugin_Package', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists('get_plugin_data') ) {
|
if ( !function_exists('get_plugin_data') ) {
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
|
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
|
||||||
}
|
}
|
||||||
return get_plugin_data($this->pluginAbsolutePath, false, false);
|
return get_plugin_data($this->pluginAbsolutePath, false, false);
|
||||||
|
|
@ -170,8 +174,8 @@ if ( !class_exists('Puc_v5p0_Plugin_Package', false) ):
|
||||||
$pluginPath = realpath($this->pluginAbsolutePath);
|
$pluginPath = realpath($this->pluginAbsolutePath);
|
||||||
//If realpath() fails, just normalize the syntax instead.
|
//If realpath() fails, just normalize the syntax instead.
|
||||||
if (($muPluginDir === false) || ($pluginPath === false)) {
|
if (($muPluginDir === false) || ($pluginPath === false)) {
|
||||||
$muPluginDir = Puc_v5p0_Factory::normalizePath(WPMU_PLUGIN_DIR);
|
$muPluginDir = PucFactory::normalizePath(WPMU_PLUGIN_DIR);
|
||||||
$pluginPath = Puc_v5p0_Factory::normalizePath($this->pluginAbsolutePath);
|
$pluginPath = PucFactory::normalizePath($this->pluginAbsolutePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
|
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Plugin_Info', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Metadata;
|
||||||
|
|
||||||
|
if ( !class_exists(PluginInfo::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A container class for holding and transforming various plugin metadata.
|
* A container class for holding and transforming various plugin metadata.
|
||||||
|
|
@ -8,7 +12,7 @@ if ( !class_exists('Puc_v5p0_Plugin_Info', false) ):
|
||||||
* @copyright 2016
|
* @copyright 2016
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Plugin_Info extends Puc_v5p0_Metadata {
|
class PluginInfo extends Metadata {
|
||||||
//Most fields map directly to the contents of the plugin's info.json file.
|
//Most fields map directly to the contents of the plugin's info.json file.
|
||||||
//See the relevant docs for a description of their meaning.
|
//See the relevant docs for a description of their meaning.
|
||||||
public $name;
|
public $name;
|
||||||
|
|
@ -64,8 +68,8 @@ if ( !class_exists('Puc_v5p0_Plugin_Info', false) ):
|
||||||
/**
|
/**
|
||||||
* Very, very basic validation.
|
* Very, very basic validation.
|
||||||
*
|
*
|
||||||
* @param StdClass $apiResponse
|
* @param \StdClass $apiResponse
|
||||||
* @return bool|WP_Error
|
* @return bool|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function validateMetadata($apiResponse) {
|
protected function validateMetadata($apiResponse) {
|
||||||
if (
|
if (
|
||||||
|
|
@ -73,7 +77,7 @@ if ( !class_exists('Puc_v5p0_Plugin_Info', false) ):
|
||||||
|| empty($apiResponse->name)
|
|| empty($apiResponse->name)
|
||||||
|| empty($apiResponse->version)
|
|| empty($apiResponse->version)
|
||||||
) {
|
) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'puc-invalid-metadata',
|
'puc-invalid-metadata',
|
||||||
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
||||||
);
|
);
|
||||||
|
|
@ -88,7 +92,7 @@ if ( !class_exists('Puc_v5p0_Plugin_Info', false) ):
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function toWpFormat(){
|
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
|
//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.
|
//as those returned by the native WordPress.org API. These can be assigned directly.
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Plugin_Ui', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
|
if ( !class_exists('Ui', false) ):
|
||||||
/**
|
/**
|
||||||
* Additional UI elements for plugins.
|
* Additional UI elements for plugins.
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Plugin_Ui {
|
class Ui {
|
||||||
private $updateChecker;
|
private $updateChecker;
|
||||||
private $manualCheckErrorTransient = '';
|
private $manualCheckErrorTransient = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Puc_v5p0_Plugin_UpdateChecker $updateChecker
|
* @param UpdateChecker $updateChecker
|
||||||
*/
|
*/
|
||||||
public function __construct($updateChecker) {
|
public function __construct($updateChecker) {
|
||||||
$this->updateChecker = $updateChecker;
|
$this->updateChecker = $updateChecker;
|
||||||
|
|
@ -172,7 +174,7 @@ if ( !class_exists('Puc_v5p0_Plugin_Ui', false) ):
|
||||||
|
|
||||||
foreach ($lastRequestApiErrors as $item) {
|
foreach ($lastRequestApiErrors as $item) {
|
||||||
$wpError = $item['error'];
|
$wpError = $item['error'];
|
||||||
/** @var WP_Error $wpError */
|
/** @var \WP_Error $wpError */
|
||||||
if ( !in_array($wpError->get_error_code(), $questionableErrorCodes) ) {
|
if ( !in_array($wpError->get_error_code(), $questionableErrorCodes) ) {
|
||||||
$foundCriticalErrors = true;
|
$foundCriticalErrors = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -254,7 +256,7 @@ if ( !class_exists('Puc_v5p0_Plugin_Ui', false) ):
|
||||||
}
|
}
|
||||||
foreach ($errors as $item) {
|
foreach ($errors as $item) {
|
||||||
$wpError = $item['error'];
|
$wpError = $item['error'];
|
||||||
/** @var WP_Error $wpError */
|
/** @var \WP_Error $wpError */
|
||||||
$output .= sprintf(
|
$output .= sprintf(
|
||||||
$formatString,
|
$formatString,
|
||||||
$wpError->get_error_message(),
|
$wpError->get_error_message(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Plugin_Update', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Update as BaseUpdate;
|
||||||
|
|
||||||
|
if ( !class_exists(Update::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple container class for holding information about an available update.
|
* A simple container class for holding information about an available update.
|
||||||
|
|
@ -8,7 +12,7 @@ if ( !class_exists('Puc_v5p0_Plugin_Update', false) ):
|
||||||
* @copyright 2016
|
* @copyright 2016
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Plugin_Update extends Puc_v5p0_Update {
|
class Update extends BaseUpdate {
|
||||||
public $id = 0;
|
public $id = 0;
|
||||||
public $homepage;
|
public $homepage;
|
||||||
public $upgrade_notice;
|
public $upgrade_notice;
|
||||||
|
|
@ -25,13 +29,13 @@ if ( !class_exists('Puc_v5p0_Plugin_Update', false) ):
|
||||||
* Create a new instance of PluginUpdate from its JSON-encoded representation.
|
* Create a new instance of PluginUpdate from its JSON-encoded representation.
|
||||||
*
|
*
|
||||||
* @param string $json
|
* @param string $json
|
||||||
* @return Puc_v5p0_Plugin_Update|null
|
* @return self|null
|
||||||
*/
|
*/
|
||||||
public static function fromJson($json){
|
public static function fromJson($json){
|
||||||
//Since update-related information is simply a subset of the full plugin info,
|
//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
|
//we can parse the update JSON as if it was a plugin info string, then copy over
|
||||||
//the parts that we care about.
|
//the parts that we care about.
|
||||||
$pluginInfo = Puc_v5p0_Plugin_Info::fromJson($json);
|
$pluginInfo = PluginInfo::fromJson($json);
|
||||||
if ( $pluginInfo !== null ) {
|
if ( $pluginInfo !== null ) {
|
||||||
return self::fromPluginInfo($pluginInfo);
|
return self::fromPluginInfo($pluginInfo);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -43,18 +47,18 @@ if ( !class_exists('Puc_v5p0_Plugin_Update', false) ):
|
||||||
* Create a new instance of PluginUpdate based on an instance of PluginInfo.
|
* 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.
|
* Basically, this just copies a subset of fields from one object to another.
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Plugin_Info $info
|
* @param PluginInfo $info
|
||||||
* @return Puc_v5p0_Plugin_Update
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function fromPluginInfo($info){
|
public static function fromPluginInfo($info){
|
||||||
return self::fromObject($info);
|
return static::fromObject($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance by copying the necessary fields from another object.
|
* Create a new instance by copying the necessary fields from another object.
|
||||||
*
|
*
|
||||||
* @param StdClass|Puc_v5p0_Plugin_Info|Puc_v5p0_Plugin_Update $object The source object.
|
* @param \StdClass|PluginInfo|self $object The source object.
|
||||||
* @return Puc_v5p0_Plugin_Update The new copy.
|
* @return self The new copy.
|
||||||
*/
|
*/
|
||||||
public static function fromObject($object) {
|
public static function fromObject($object) {
|
||||||
$update = new self();
|
$update = new self();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker as BaseUpdateChecker;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Scheduler;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
|
|
||||||
|
if ( !class_exists(UpdateChecker::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom plugin update checker.
|
* A custom plugin update checker.
|
||||||
|
|
@ -8,7 +15,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
* @copyright 2018
|
* @copyright 2018
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Plugin_UpdateChecker extends Puc_v5p0_UpdateChecker {
|
class UpdateChecker extends BaseUpdateChecker {
|
||||||
protected $updateTransient = 'update_plugins';
|
protected $updateTransient = 'update_plugins';
|
||||||
protected $translationType = 'plugin';
|
protected $translationType = 'plugin';
|
||||||
|
|
||||||
|
|
@ -17,7 +24,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
|
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Plugin_Package
|
* @var Package
|
||||||
*/
|
*/
|
||||||
protected $package;
|
protected $package;
|
||||||
|
|
||||||
|
|
@ -68,17 +75,17 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
//Details: https://github.com/YahnisElsts/plugin-update-checker/issues/138#issuecomment-335590964
|
//Details: https://github.com/YahnisElsts/plugin-update-checker/issues/138#issuecomment-335590964
|
||||||
add_action('uninstall_' . $this->pluginFile, array($this, 'removeHooks'));
|
add_action('uninstall_' . $this->pluginFile, array($this, 'removeHooks'));
|
||||||
|
|
||||||
$this->extraUi = new Puc_v5p0_Plugin_Ui($this);
|
$this->extraUi = new Ui($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of the scheduler.
|
* Create an instance of the scheduler.
|
||||||
*
|
*
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
* @return Puc_v5p0_Scheduler
|
* @return Scheduler
|
||||||
*/
|
*/
|
||||||
protected function createScheduler($checkPeriod) {
|
protected function createScheduler($checkPeriod) {
|
||||||
$scheduler = new Puc_v5p0_Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
$scheduler = new Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
||||||
register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
|
register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
|
||||||
return $scheduler;
|
return $scheduler;
|
||||||
}
|
}
|
||||||
|
|
@ -124,13 +131,13 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
* @uses wp_remote_get()
|
* @uses wp_remote_get()
|
||||||
*
|
*
|
||||||
* @param array $queryArgs Additional query arguments to append to the request. Optional.
|
* @param array $queryArgs Additional query arguments to append to the request. Optional.
|
||||||
* @return Puc_v5p0_Plugin_Info
|
* @return PluginInfo
|
||||||
*/
|
*/
|
||||||
public function requestInfo($queryArgs = array()) {
|
public function requestInfo($queryArgs = array()) {
|
||||||
list($pluginInfo, $result) = $this->requestMetadata('Puc_v5p0_Plugin_Info', 'request_info', $queryArgs);
|
list($pluginInfo, $result) = $this->requestMetadata('PluginInfo', 'request_info', $queryArgs);
|
||||||
|
|
||||||
if ( $pluginInfo !== null ) {
|
if ( $pluginInfo !== null ) {
|
||||||
/** @var Puc_v5p0_Plugin_Info $pluginInfo */
|
/** @var PluginInfo $pluginInfo */
|
||||||
$pluginInfo->filename = $this->pluginFile;
|
$pluginInfo->filename = $this->pluginFile;
|
||||||
$pluginInfo->slug = $this->slug;
|
$pluginInfo->slug = $this->slug;
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +151,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
*
|
*
|
||||||
* @uses PluginUpdateChecker::requestInfo()
|
* @uses PluginUpdateChecker::requestInfo()
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Update|null An instance of Plugin_Update, or NULL when no updates are available.
|
* @return Update|null An instance of Plugin Update, or NULL when no updates are available.
|
||||||
*/
|
*/
|
||||||
public function requestUpdate() {
|
public function requestUpdate() {
|
||||||
//For the sake of simplicity, this function just calls requestInfo()
|
//For the sake of simplicity, this function just calls requestInfo()
|
||||||
|
|
@ -153,7 +160,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
if ( $pluginInfo === null ){
|
if ( $pluginInfo === null ){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$update = Puc_v5p0_Plugin_Update::fromPluginInfo($pluginInfo);
|
$update = Update::fromPluginInfo($pluginInfo);
|
||||||
|
|
||||||
$update = $this->filterUpdateResult($update);
|
$update = $this->filterUpdateResult($update);
|
||||||
|
|
||||||
|
|
@ -197,9 +204,9 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param stdClass|null $updates
|
* @param \stdClass|null $updates
|
||||||
* @param stdClass $updateToAdd
|
* @param \stdClass $updateToAdd
|
||||||
* @return stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
protected function addUpdateToList($updates, $updateToAdd) {
|
protected function addUpdateToList($updates, $updateToAdd) {
|
||||||
if ( $this->package->isMuPlugin() ) {
|
if ( $this->package->isMuPlugin() ) {
|
||||||
|
|
@ -211,8 +218,8 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param stdClass|null $updates
|
* @param \stdClass|null $updates
|
||||||
* @return stdClass|null
|
* @return \stdClass|null
|
||||||
*/
|
*/
|
||||||
protected function removeUpdateFromList($updates) {
|
protected function removeUpdateFromList($updates) {
|
||||||
$updates = parent::removeUpdateFromList($updates);
|
$updates = parent::removeUpdateFromList($updates);
|
||||||
|
|
@ -246,7 +253,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
'banners' => array(),
|
'banners' => array(),
|
||||||
'banners_rtl' => array(),
|
'banners_rtl' => array(),
|
||||||
'tested' => '',
|
'tested' => '',
|
||||||
'compatibility' => new stdClass(),
|
'compatibility' => new \stdClass(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +262,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
* Alias for isBeingUpgraded().
|
* Alias for isBeingUpgraded().
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isPluginBeingUpgraded($upgrader = null) {
|
public function isPluginBeingUpgraded($upgrader = null) {
|
||||||
|
|
@ -265,7 +272,7 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Is there an update being installed for this plugin, right now?
|
* Is there an update being installed for this plugin, right now?
|
||||||
*
|
*
|
||||||
* @param WP_Upgrader|null $upgrader
|
* @param \WP_Upgrader|null $upgrader
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isBeingUpgraded($upgrader = null) {
|
public function isBeingUpgraded($upgrader = null) {
|
||||||
|
|
@ -281,12 +288,12 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
* Uses cached update data. To retrieve update information straight from
|
* Uses cached update data. To retrieve update information straight from
|
||||||
* the metadata URL, call requestUpdate() instead.
|
* the metadata URL, call requestUpdate() instead.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Plugin_Update|null
|
* @return Update|null
|
||||||
*/
|
*/
|
||||||
public function getUpdate() {
|
public function getUpdate() {
|
||||||
$update = parent::getUpdate();
|
$update = parent::getUpdate();
|
||||||
if ( isset($update) ) {
|
if ( isset($update) ) {
|
||||||
/** @var Puc_v5p0_Plugin_Update $update */
|
/** @var Update $update */
|
||||||
$update->filename = $this->pluginFile;
|
$update->filename = $this->pluginFile;
|
||||||
}
|
}
|
||||||
return $update;
|
return $update;
|
||||||
|
|
@ -391,20 +398,20 @@ if ( !class_exists('Puc_v5p0_Plugin_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createDebugBarExtension() {
|
protected function createDebugBarExtension() {
|
||||||
return new Puc_v5p0_DebugBar_PluginExtension($this);
|
return new DebugBar\PluginExtension($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a package instance that represents this plugin or theme.
|
* Create a package instance that represents this plugin or theme.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_InstalledPackage
|
* @return InstalledPackage
|
||||||
*/
|
*/
|
||||||
protected function createInstalledPackage() {
|
protected function createInstalledPackage() {
|
||||||
return new Puc_v5p0_Plugin_Package($this->pluginAbsolutePath, $this);
|
return new Package($this->pluginAbsolutePath, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Puc_v5p0_Plugin_Package
|
* @return Package
|
||||||
*/
|
*/
|
||||||
public function getInstalledPackage() {
|
public function getInstalledPackage() {
|
||||||
return $this->package;
|
return $this->package;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Factory', false) ):
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
|
if ( !class_exists(PucFactory::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory that builds update checker instances.
|
* A factory that builds update checker instances.
|
||||||
|
|
@ -11,7 +18,7 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
* At the moment it can only build instances of the UpdateChecker class. Other classes are
|
* 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.
|
* intended mainly for internal use and refer directly to specific implementations.
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Factory {
|
class PucFactory {
|
||||||
protected static $classVersions = array();
|
protected static $classVersions = array();
|
||||||
protected static $sorted = false;
|
protected static $sorted = false;
|
||||||
|
|
||||||
|
|
@ -23,7 +30,7 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
*
|
*
|
||||||
* @param string $fullPath Full path to the main plugin file or the theme's style.css.
|
* @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.
|
* @param array $args Optional arguments. Keys should match the argument names of the buildUpdateChecker() method.
|
||||||
* @return Puc_v5p0_Plugin_UpdateChecker|Puc_v5p0_Theme_UpdateChecker|Puc_v5p0_Vcs_BaseChecker
|
* @return Plugin\UpdateChecker|Theme\UpdateChecker|Vcs\BaseChecker
|
||||||
*/
|
*/
|
||||||
public static function buildFromHeader($fullPath, $args = array()) {
|
public static function buildFromHeader($fullPath, $args = array()) {
|
||||||
$fullPath = self::normalizePath($fullPath);
|
$fullPath = self::normalizePath($fullPath);
|
||||||
|
|
@ -44,7 +51,6 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
$metadataUrl = self::getServiceURI($fullPath);
|
$metadataUrl = self::getServiceURI($fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection PhpUndefinedVariableInspection These variables are created by extract(), above. */
|
|
||||||
return self::buildUpdateChecker($metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile);
|
return self::buildUpdateChecker($metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,15 +60,15 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
* This method automatically detects if you're using it for a plugin or a theme and chooses
|
* 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).
|
* the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
|
||||||
*
|
*
|
||||||
* @see Puc_v5p0_UpdateChecker::__construct
|
* @see UpdateChecker::__construct
|
||||||
*
|
*
|
||||||
* @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
|
* @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 $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 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 int $checkPeriod How often to check for updates (in hours).
|
||||||
* @param string $optionName Where to store book-keeping info about update checks.
|
* @param string $optionName Where to store bookkeeping info about update checks.
|
||||||
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
|
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
|
||||||
* @return Puc_v5p0_Plugin_UpdateChecker|Puc_v5p0_Theme_UpdateChecker|Puc_v5p0_Vcs_BaseChecker
|
* @return Plugin\UpdateChecker|Theme\UpdateChecker|Vcs\BaseChecker
|
||||||
*/
|
*/
|
||||||
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
||||||
$fullPath = self::normalizePath($fullPath);
|
$fullPath = self::normalizePath($fullPath);
|
||||||
|
|
@ -77,7 +83,7 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
$type = 'Theme';
|
$type = 'Theme';
|
||||||
$id = $themeDirectory;
|
$id = $themeDirectory;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(sprintf(
|
throw new \RuntimeException(sprintf(
|
||||||
'The update checker cannot determine if "%s" is a plugin or a theme. ' .
|
'The update checker cannot determine if "%s" is a plugin or a theme. ' .
|
||||||
'This is a bug. Please contact the PUC developer.',
|
'This is a bug. Please contact the PUC developer.',
|
||||||
htmlentities($fullPath)
|
htmlentities($fullPath)
|
||||||
|
|
@ -90,10 +96,10 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
$apiClass = null;
|
$apiClass = null;
|
||||||
if ( empty($service) ) {
|
if ( empty($service) ) {
|
||||||
//The default is to get update information from a remote JSON file.
|
//The default is to get update information from a remote JSON file.
|
||||||
$checkerClass = $type . '_UpdateChecker';
|
$checkerClass = $type . '\\UpdateChecker';
|
||||||
} else {
|
} else {
|
||||||
//You can also use a VCS repository like GitHub.
|
//You can also use a VCS repository like GitHub.
|
||||||
$checkerClass = 'Vcs_' . $type . 'UpdateChecker';
|
$checkerClass = 'Vcs\\' . $type . 'UpdateChecker';
|
||||||
$apiClass = $service . 'Api';
|
$apiClass = $service . 'Api';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,11 +117,6 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the current namespace to the class name(s).
|
|
||||||
if ( version_compare(PHP_VERSION, '5.3', '>=') ) {
|
|
||||||
$checkerClass = __NAMESPACE__ . '\\' . $checkerClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !isset($apiClass) ) {
|
if ( !isset($apiClass) ) {
|
||||||
//Plain old update checker.
|
//Plain old update checker.
|
||||||
return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
|
return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
|
||||||
|
|
@ -131,10 +132,6 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( version_compare(PHP_VERSION, '5.3', '>=') && (strpos($apiClass, '\\') === false) ) {
|
|
||||||
$apiClass = __NAMESPACE__ . '\\' . $apiClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new $checkerClass(
|
return new $checkerClass(
|
||||||
new $apiClass($metadataUrl),
|
new $apiClass($metadataUrl),
|
||||||
$id,
|
$id,
|
||||||
|
|
@ -241,7 +238,7 @@ if ( !class_exists('Puc_v5p0_Factory', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
//URI was not found so throw an error.
|
//URI was not found so throw an error.
|
||||||
throw new RuntimeException(
|
throw new \RuntimeException(
|
||||||
sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath))
|
sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Scheduler', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
|
if ( !class_exists(Scheduler::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scheduler decides when and how often to check for updates.
|
* The scheduler decides when and how often to check for updates.
|
||||||
* It calls @see Puc_v5p0_UpdateChecker::checkForUpdates() to perform the actual checks.
|
* It calls @see UpdateChecker::checkForUpdates() to perform the actual checks.
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Scheduler {
|
class Scheduler {
|
||||||
public $checkPeriod = 12; //How often to check for updates (in hours).
|
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 $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
|
||||||
public $throttledCheckPeriod = 72;
|
public $throttledCheckPeriod = 72;
|
||||||
|
|
@ -13,7 +17,7 @@ if ( !class_exists('Puc_v5p0_Scheduler', false) ):
|
||||||
protected $hourlyCheckHooks = array('load-update.php');
|
protected $hourlyCheckHooks = array('load-update.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
|
|
@ -22,7 +26,7 @@ if ( !class_exists('Puc_v5p0_Scheduler', false) ):
|
||||||
/**
|
/**
|
||||||
* Scheduler constructor.
|
* Scheduler constructor.
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_UpdateChecker $updateChecker
|
* @param UpdateChecker $updateChecker
|
||||||
* @param int $checkPeriod How often to check for updates (in hours).
|
* @param int $checkPeriod How often to check for updates (in hours).
|
||||||
* @param array $hourlyHooks
|
* @param array $hourlyHooks
|
||||||
*/
|
*/
|
||||||
|
|
@ -89,7 +93,7 @@ if ( !class_exists('Puc_v5p0_Scheduler', false) ):
|
||||||
* We look at the parameters to decide whether to call maybeCheckForUpdates() or not.
|
* 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.
|
* We also check if the update checker has been removed by the update.
|
||||||
*
|
*
|
||||||
* @param WP_Upgrader $upgrader WP_Upgrader instance
|
* @param \WP_Upgrader $upgrader WP_Upgrader instance
|
||||||
* @param array $upgradeInfo extra information about the upgrade
|
* @param array $upgradeInfo extra information about the upgrade
|
||||||
*/
|
*/
|
||||||
public function upgraderProcessComplete(
|
public function upgraderProcessComplete(
|
||||||
|
|
@ -130,7 +134,7 @@ if ( !class_exists('Puc_v5p0_Scheduler', false) ):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_a($this->updateChecker, 'Puc_v5p0_Plugin_UpdateChecker') ) {
|
if ( is_a($this->updateChecker, Plugin\UpdateChecker::class) ) {
|
||||||
if ( 'plugin' !== $upgradeInfo['type'] || !isset($upgradeInfo['plugins']) ) {
|
if ( 'plugin' !== $upgradeInfo['type'] || !isset($upgradeInfo['plugins']) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
if ( !class_exists(StateStore::class, false) ):
|
||||||
|
|
||||||
class Puc_v5p0_StateStore {
|
class StateStore {
|
||||||
/**
|
/**
|
||||||
* @var int Last update check timestamp.
|
* @var int Last update check timestamp.
|
||||||
*/
|
*/
|
||||||
|
|
@ -14,7 +15,7 @@ if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
||||||
protected $checkedVersion = '';
|
protected $checkedVersion = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Update|null Cached update.
|
* @var Update|null Cached update.
|
||||||
*/
|
*/
|
||||||
protected $update = null;
|
protected $update = null;
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null|Puc_v5p0_Update
|
* @return null|Update
|
||||||
*/
|
*/
|
||||||
public function getUpdate() {
|
public function getUpdate() {
|
||||||
$this->lazyLoad();
|
$this->lazyLoad();
|
||||||
|
|
@ -73,10 +74,10 @@ if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Puc_v5p0_Update|null $update
|
* @param Update|null $update
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setUpdate(Puc_v5p0_Update $update = null) {
|
public function setUpdate(Update $update = null) {
|
||||||
$this->lazyLoad();
|
$this->lazyLoad();
|
||||||
$this->update = $update;
|
$this->update = $update;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -127,7 +128,7 @@ if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
$state = new stdClass();
|
$state = new \stdClass();
|
||||||
|
|
||||||
$state->lastCheck = $this->lastCheck;
|
$state->lastCheck = $this->lastCheck;
|
||||||
$state->checkedVersion = $this->checkedVersion;
|
$state->checkedVersion = $this->checkedVersion;
|
||||||
|
|
@ -138,7 +139,7 @@ if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
||||||
$updateClass = get_class($this->update);
|
$updateClass = get_class($this->update);
|
||||||
$state->updateClass = $updateClass;
|
$state->updateClass = $updateClass;
|
||||||
$prefix = $this->getLibPrefix();
|
$prefix = $this->getLibPrefix();
|
||||||
if ( Puc_v5p0_Utils::startsWith($updateClass, $prefix) ) {
|
if ( Utils::startsWith($updateClass, $prefix) ) {
|
||||||
$state->updateBaseClass = substr($updateClass, strlen($prefix));
|
$state->updateBaseClass = substr($updateClass, strlen($prefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,8 +170,8 @@ if ( !class_exists('Puc_v5p0_StateStore', false) ):
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastCheck = intval(Puc_v5p0_Utils::get($state, 'lastCheck', 0));
|
$this->lastCheck = intval(Utils::get($state, 'lastCheck', 0));
|
||||||
$this->checkedVersion = Puc_v5p0_Utils::get($state, 'checkedVersion', '');
|
$this->checkedVersion = Utils::get($state, 'checkedVersion', '');
|
||||||
$this->update = null;
|
$this->update = null;
|
||||||
|
|
||||||
if ( isset($state->update) ) {
|
if ( isset($state->update) ) {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Theme_Package', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||||
|
|
||||||
class Puc_v5p0_Theme_Package extends Puc_v5p0_InstalledPackage {
|
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||||
|
|
||||||
|
if ( !class_exists(Package::class, false) ):
|
||||||
|
|
||||||
|
class Package extends InstalledPackage {
|
||||||
/**
|
/**
|
||||||
* @var string Theme directory name.
|
* @var string Theme directory name.
|
||||||
*/
|
*/
|
||||||
protected $stylesheet;
|
protected $stylesheet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var WP_Theme Theme object.
|
* @var \WP_Theme Theme object.
|
||||||
*/
|
*/
|
||||||
protected $theme;
|
protected $theme;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Theme_Update', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||||
|
|
||||||
class Puc_v5p0_Theme_Update extends Puc_v5p0_Update {
|
use YahnisElsts\PluginUpdateChecker\v5p0\Update as BaseUpdate;
|
||||||
|
|
||||||
|
if ( !class_exists(Update::class, false) ):
|
||||||
|
|
||||||
|
class Update extends BaseUpdate {
|
||||||
public $details_url = '';
|
public $details_url = '';
|
||||||
|
|
||||||
protected static $extraFields = array('details_url');
|
protected static $extraFields = array('details_url');
|
||||||
|
|
@ -44,8 +48,8 @@ if ( !class_exists('Puc_v5p0_Theme_Update', false) ):
|
||||||
/**
|
/**
|
||||||
* Create a new instance by copying the necessary fields from another object.
|
* Create a new instance by copying the necessary fields from another object.
|
||||||
*
|
*
|
||||||
* @param StdClass|Puc_v5p0_Theme_Update $object The source object.
|
* @param \StdClass|self $object The source object.
|
||||||
* @return Puc_v5p0_Theme_Update The new copy.
|
* @return self The new copy.
|
||||||
*/
|
*/
|
||||||
public static function fromObject($object) {
|
public static function fromObject($object) {
|
||||||
$update = new self();
|
$update = new self();
|
||||||
|
|
@ -56,14 +60,14 @@ if ( !class_exists('Puc_v5p0_Theme_Update', false) ):
|
||||||
/**
|
/**
|
||||||
* Basic validation.
|
* Basic validation.
|
||||||
*
|
*
|
||||||
* @param StdClass $apiResponse
|
* @param \StdClass $apiResponse
|
||||||
* @return bool|WP_Error
|
* @return bool|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function validateMetadata($apiResponse) {
|
protected function validateMetadata($apiResponse) {
|
||||||
$required = array('version', 'details_url');
|
$required = array('version', 'details_url');
|
||||||
foreach($required as $key) {
|
foreach($required as $key) {
|
||||||
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
|
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'tuc-invalid-metadata',
|
'tuc-invalid-metadata',
|
||||||
sprintf('The theme metadata is missing the required "%s" key.', $key)
|
sprintf('The theme metadata is missing the required "%s" key.', $key)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Theme_UpdateChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||||
|
|
||||||
class Puc_v5p0_Theme_UpdateChecker extends Puc_v5p0_UpdateChecker {
|
use YahnisElsts\PluginUpdateChecker\v5p0\UpdateChecker as BaseUpdateChecker;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\InstalledPackage;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Scheduler;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\DebugBar;
|
||||||
|
|
||||||
|
if ( !class_exists(UpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
class UpdateChecker extends BaseUpdateChecker {
|
||||||
protected $filterSuffix = 'theme';
|
protected $filterSuffix = 'theme';
|
||||||
protected $updateTransient = 'update_themes';
|
protected $updateTransient = 'update_themes';
|
||||||
protected $translationType = 'theme';
|
protected $translationType = 'theme';
|
||||||
|
|
@ -39,13 +46,13 @@ if ( !class_exists('Puc_v5p0_Theme_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Retrieve the latest update (if any) from the configured API endpoint.
|
* Retrieve the latest update (if any) from the configured API endpoint.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Update|null An instance of Update, or NULL when no updates are available.
|
* @return Update|null An instance of Update, or NULL when no updates are available.
|
||||||
*/
|
*/
|
||||||
public function requestUpdate() {
|
public function requestUpdate() {
|
||||||
list($themeUpdate, $result) = $this->requestMetadata('Puc_v5p0_Theme_Update', 'request_update');
|
list($themeUpdate, $result) = $this->requestMetadata(Update::class, 'request_update');
|
||||||
|
|
||||||
if ( $themeUpdate !== null ) {
|
if ( $themeUpdate !== null ) {
|
||||||
/** @var Puc_v5p0_Theme_Update $themeUpdate */
|
/** @var Update $themeUpdate */
|
||||||
$themeUpdate->slug = $this->slug;
|
$themeUpdate->slug = $this->slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,16 +78,16 @@ if ( !class_exists('Puc_v5p0_Theme_UpdateChecker', false) ):
|
||||||
* Create an instance of the scheduler.
|
* Create an instance of the scheduler.
|
||||||
*
|
*
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
* @return Puc_v5p0_Scheduler
|
* @return Scheduler
|
||||||
*/
|
*/
|
||||||
protected function createScheduler($checkPeriod) {
|
protected function createScheduler($checkPeriod) {
|
||||||
return new Puc_v5p0_Scheduler($this, $checkPeriod, array('load-themes.php'));
|
return new Scheduler($this, $checkPeriod, array('load-themes.php'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is there an update being installed right now for this theme?
|
* 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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isBeingUpgraded($upgrader = null) {
|
public function isBeingUpgraded($upgrader = null) {
|
||||||
|
|
@ -88,7 +95,7 @@ if ( !class_exists('Puc_v5p0_Theme_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createDebugBarExtension() {
|
protected function createDebugBarExtension() {
|
||||||
return new Puc_v5p0_DebugBar_Extension($this, 'Puc_v5p0_DebugBar_ThemePanel');
|
return new DebugBar\Extension($this, DebugBar\ThemePanel::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -142,10 +149,10 @@ if ( !class_exists('Puc_v5p0_Theme_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Create a package instance that represents this plugin or theme.
|
* Create a package instance that represents this plugin or theme.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_InstalledPackage
|
* @return InstalledPackage
|
||||||
*/
|
*/
|
||||||
protected function createInstalledPackage() {
|
protected function createInstalledPackage() {
|
||||||
return new Puc_v5p0_Theme_Package($this->stylesheet, $this);
|
return new Package($this->stylesheet, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Update', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
if ( !class_exists(Update::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple container class for holding information about an available update.
|
* A simple container class for holding information about an available update.
|
||||||
|
|
@ -7,7 +11,7 @@ if ( !class_exists('Puc_v5p0_Update', false) ):
|
||||||
* @author Janis Elsts
|
* @author Janis Elsts
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
abstract class Puc_v5p0_Update extends Puc_v5p0_Metadata {
|
abstract class Update extends Metadata {
|
||||||
public $slug;
|
public $slug;
|
||||||
public $version;
|
public $version;
|
||||||
public $download_url;
|
public $download_url;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
use stdClass;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
abstract class Puc_v5p0_UpdateChecker {
|
if ( !class_exists(UpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
abstract class UpdateChecker {
|
||||||
protected $filterSuffix = '';
|
protected $filterSuffix = '';
|
||||||
protected $updateTransient = '';
|
protected $updateTransient = '';
|
||||||
protected $translationType = ''; //"plugin" or "theme".
|
protected $translationType = ''; //"plugin" or "theme".
|
||||||
|
|
@ -36,22 +40,22 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
public $slug = '';
|
public $slug = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_InstalledPackage
|
* @var InstalledPackage
|
||||||
*/
|
*/
|
||||||
protected $package;
|
protected $package;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Scheduler
|
* @var Scheduler
|
||||||
*/
|
*/
|
||||||
public $scheduler;
|
public $scheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_UpgraderStatus
|
* @var UpgraderStatus
|
||||||
*/
|
*/
|
||||||
protected $upgraderStatus;
|
protected $upgraderStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_StateStore
|
* @var StateStore
|
||||||
*/
|
*/
|
||||||
protected $updateState;
|
protected $updateState;
|
||||||
|
|
||||||
|
|
@ -66,7 +70,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
protected $cachedMetadataHost = 0;
|
protected $cachedMetadataHost = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_DebugBar_Extension|null
|
* @var DebugBar\Extension|null
|
||||||
*/
|
*/
|
||||||
protected $debugBarExtension = null;
|
protected $debugBarExtension = null;
|
||||||
|
|
||||||
|
|
@ -89,8 +93,8 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
|
|
||||||
$this->package = $this->createInstalledPackage();
|
$this->package = $this->createInstalledPackage();
|
||||||
$this->scheduler = $this->createScheduler($checkPeriod);
|
$this->scheduler = $this->createScheduler($checkPeriod);
|
||||||
$this->upgraderStatus = new Puc_v5p0_UpgraderStatus();
|
$this->upgraderStatus = new UpgraderStatus();
|
||||||
$this->updateState = new Puc_v5p0_StateStore($this->optionName);
|
$this->updateState = new StateStore($this->optionName);
|
||||||
|
|
||||||
if ( did_action('init') ) {
|
if ( did_action('init') ) {
|
||||||
$this->loadTextDomain();
|
$this->loadTextDomain();
|
||||||
|
|
@ -218,12 +222,12 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Create a package instance that represents this plugin or theme.
|
* Create a package instance that represents this plugin or theme.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_InstalledPackage
|
* @return InstalledPackage
|
||||||
*/
|
*/
|
||||||
abstract protected function createInstalledPackage();
|
abstract protected function createInstalledPackage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Puc_v5p0_InstalledPackage
|
* @return InstalledPackage
|
||||||
*/
|
*/
|
||||||
public function getInstalledPackage() {
|
public function getInstalledPackage() {
|
||||||
return $this->package;
|
return $this->package;
|
||||||
|
|
@ -236,14 +240,14 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
* and substitute their own scheduler.
|
* and substitute their own scheduler.
|
||||||
*
|
*
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
* @return Puc_v5p0_Scheduler
|
* @return Scheduler
|
||||||
*/
|
*/
|
||||||
abstract protected function createScheduler($checkPeriod);
|
abstract protected function createScheduler($checkPeriod);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for updates. The results are stored in the DB option specified in $optionName.
|
* Check for updates. The results are stored in the DB option specified in $optionName.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Update|null
|
* @return Update|null
|
||||||
*/
|
*/
|
||||||
public function checkForUpdates() {
|
public function checkForUpdates() {
|
||||||
$installedVersion = $this->getInstalledVersion();
|
$installedVersion = $this->getInstalledVersion();
|
||||||
|
|
@ -277,7 +281,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Load the update checker state from the DB.
|
* Load the update checker state from the DB.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_StateStore
|
* @return StateStore
|
||||||
*/
|
*/
|
||||||
public function getUpdateState() {
|
public function getUpdateState() {
|
||||||
return $this->updateState->lazyLoad();
|
return $this->updateState->lazyLoad();
|
||||||
|
|
@ -302,7 +306,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
* Uses cached update data. To retrieve update information straight from
|
* Uses cached update data. To retrieve update information straight from
|
||||||
* the metadata URL, call requestUpdate() instead.
|
* the metadata URL, call requestUpdate() instead.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Update|null
|
* @return Update|null
|
||||||
*/
|
*/
|
||||||
public function getUpdate() {
|
public function getUpdate() {
|
||||||
$update = $this->updateState->getUpdate();
|
$update = $this->updateState->getUpdate();
|
||||||
|
|
@ -323,16 +327,17 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
*
|
*
|
||||||
* Subclasses should run the update through filterUpdateResult before returning it.
|
* Subclasses should run the update through filterUpdateResult before returning it.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Update An instance of Update, or NULL when no updates are available.
|
* @return Update An instance of Update, or NULL when no updates are available.
|
||||||
*/
|
*/
|
||||||
abstract public function requestUpdate();
|
abstract public function requestUpdate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the result of a requestUpdate() call.
|
* Filter the result of a requestUpdate() call.
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Update|null $update
|
* @template T of Update
|
||||||
|
* @param T|null $update
|
||||||
* @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
|
* @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
|
||||||
* @return Puc_v5p0_Update
|
* @return T
|
||||||
*/
|
*/
|
||||||
protected function filterUpdateResult($update, $httpResult = null) {
|
protected function filterUpdateResult($update, $httpResult = null) {
|
||||||
//Let plugins/themes modify the update.
|
//Let plugins/themes modify the update.
|
||||||
|
|
@ -355,9 +360,9 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
* "Compatibility: Unknown".
|
* "Compatibility: Unknown".
|
||||||
* The function mimics how wordpress.org API crafts the "tested" field out of "Tested up to".
|
* The function mimics how wordpress.org API crafts the "tested" field out of "Tested up to".
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Metadata|null $update
|
* @param Metadata|null $update
|
||||||
*/
|
*/
|
||||||
protected function fixSupportedWordpressVersion(Puc_v5p0_Metadata $update = null) {
|
protected function fixSupportedWordpressVersion(Metadata $update = null) {
|
||||||
if ( !isset($update->tested) || !preg_match('/^\d++\.\d++$/', $update->tested) ) {
|
if ( !isset($update->tested) || !preg_match('/^\d++\.\d++$/', $update->tested) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -462,7 +467,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
* Store API errors that are generated when checking for updates.
|
* Store API errors that are generated when checking for updates.
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
* @param WP_Error $error
|
* @param \WP_Error $error
|
||||||
* @param array|null $httpResponse
|
* @param array|null $httpResponse
|
||||||
* @param string|null $url
|
* @param string|null $url
|
||||||
* @param string|null $slug
|
* @param string|null $slug
|
||||||
|
|
@ -515,8 +520,8 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Insert the latest update (if any) into the update list maintained by WP.
|
* Insert the latest update (if any) into the update list maintained by WP.
|
||||||
*
|
*
|
||||||
* @param stdClass $updates Update list.
|
* @param \stdClass $updates Update list.
|
||||||
* @return stdClass Modified update list.
|
* @return \stdClass Modified update list.
|
||||||
*/
|
*/
|
||||||
public function injectUpdate($updates) {
|
public function injectUpdate($updates) {
|
||||||
//Is there an update to insert?
|
//Is there an update to insert?
|
||||||
|
|
@ -543,9 +548,9 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param stdClass|null $updates
|
* @param \stdClass|null $updates
|
||||||
* @param stdClass|array $updateToAdd
|
* @param \stdClass|array $updateToAdd
|
||||||
* @return stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
protected function addUpdateToList($updates, $updateToAdd) {
|
protected function addUpdateToList($updates, $updateToAdd) {
|
||||||
if ( !is_object($updates) ) {
|
if ( !is_object($updates) ) {
|
||||||
|
|
@ -558,8 +563,8 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param stdClass|null $updates
|
* @param \stdClass|null $updates
|
||||||
* @return stdClass|null
|
* @return \stdClass|null
|
||||||
*/
|
*/
|
||||||
protected function removeUpdateFromList($updates) {
|
protected function removeUpdateFromList($updates) {
|
||||||
if ( isset($updates, $updates->response) ) {
|
if ( isset($updates, $updates->response) ) {
|
||||||
|
|
@ -572,8 +577,8 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
* See this post for more information:
|
* 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/
|
* @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
|
* @param \stdClass|null $updates
|
||||||
* @return stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
protected function addNoUpdateItem($updates) {
|
protected function addNoUpdateItem($updates) {
|
||||||
if ( !is_object($updates) ) {
|
if ( !is_object($updates) ) {
|
||||||
|
|
@ -635,10 +640,10 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
|
* Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
|
||||||
*
|
*
|
||||||
* @param string $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
* @param class-string<Update> $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
||||||
* @param string $filterRoot
|
* @param string $filterRoot
|
||||||
* @param array $queryArgs Additional query arguments.
|
* @param array $queryArgs Additional query arguments.
|
||||||
* @return array [Puc_v5p0_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get().
|
* @return array<Metadata|null, array|WP_Error> A metadata instance and the value returned by wp_remote_get().
|
||||||
*/
|
*/
|
||||||
protected function requestMetadata($metaClass, $filterRoot, $queryArgs = array()) {
|
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()).
|
//Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
|
||||||
|
|
@ -879,12 +884,12 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
*
|
*
|
||||||
* @param string $source The directory to copy to /wp-content/plugins or /wp-content/themes. Usually a subdirectory of $remoteSource.
|
* @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 string $remoteSource WordPress has extracted the update to this directory.
|
||||||
* @param WP_Upgrader $upgrader
|
* @param \WP_Upgrader $upgrader
|
||||||
* @return string|WP_Error
|
* @return string|WP_Error
|
||||||
*/
|
*/
|
||||||
public function fixDirectoryName($source, $remoteSource, $upgrader) {
|
public function fixDirectoryName($source, $remoteSource, $upgrader) {
|
||||||
global $wp_filesystem;
|
global $wp_filesystem;
|
||||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
/** @var \WP_Filesystem_Base $wp_filesystem */
|
||||||
|
|
||||||
//Basic sanity checks.
|
//Basic sanity checks.
|
||||||
if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
|
if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
|
||||||
|
|
@ -914,7 +919,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var WP_Upgrader_Skin $upgrader ->skin */
|
/** @var \WP_Upgrader_Skin $upgrader ->skin */
|
||||||
$upgrader->skin->feedback(sprintf(
|
$upgrader->skin->feedback(sprintf(
|
||||||
'Renaming %s to %s…',
|
'Renaming %s to %s…',
|
||||||
'<span class="code">' . basename($source) . '</span>',
|
'<span class="code">' . basename($source) . '</span>',
|
||||||
|
|
@ -938,7 +943,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
/**
|
/**
|
||||||
* Is there an update being installed right now, for this plugin or theme?
|
* 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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
abstract public function isBeingUpgraded($upgrader = null);
|
abstract public function isBeingUpgraded($upgrader = null);
|
||||||
|
|
@ -952,7 +957,7 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
*/
|
*/
|
||||||
protected function isBadDirectoryStructure($remoteSource) {
|
protected function isBadDirectoryStructure($remoteSource) {
|
||||||
global $wp_filesystem;
|
global $wp_filesystem;
|
||||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
/** @var \WP_Filesystem_Base $wp_filesystem */
|
||||||
|
|
||||||
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
||||||
if ( is_array($sourceFiles) ) {
|
if ( is_array($sourceFiles) ) {
|
||||||
|
|
@ -980,13 +985,13 @@ if ( !class_exists('Puc_v5p0_UpdateChecker', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createDebugBarExtension() {
|
protected function createDebugBarExtension() {
|
||||||
return new Puc_v5p0_DebugBar_Extension($this);
|
return new DebugBar\Extension($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display additional configuration details in the Debug Bar panel.
|
* Display additional configuration details in the Debug Bar panel.
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_DebugBar_Panel $panel
|
* @param DebugBar\Panel $panel
|
||||||
*/
|
*/
|
||||||
public function onDisplayConfiguration($panel) {
|
public function onDisplayConfiguration($panel) {
|
||||||
//Do nothing. Subclasses can use this to add additional info to the panel.
|
//Do nothing. Subclasses can use this to add additional info to the panel.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
if ( !class_exists(UpgraderStatus::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class that helps figure out which plugin or theme WordPress is upgrading.
|
* A utility class that helps figure out which plugin or theme WordPress is upgrading.
|
||||||
|
|
@ -8,7 +10,7 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
* Core classes like Plugin_Upgrader don't expose the plugin file name during an in-progress update (AFAICT).
|
* 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.
|
* This class uses a few workarounds and heuristics to get the file name.
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_UpgraderStatus {
|
class UpgraderStatus {
|
||||||
private $currentType = null; //"plugin" or "theme".
|
private $currentType = null; //"plugin" or "theme".
|
||||||
private $currentId = null; //Plugin basename or theme directory name.
|
private $currentId = null; //Plugin basename or theme directory name.
|
||||||
|
|
||||||
|
|
@ -27,7 +29,7 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
* and upgrader implementations are liable to change without notice.
|
* and upgrader implementations are liable to change without notice.
|
||||||
*
|
*
|
||||||
* @param string $pluginFile The plugin to check.
|
* @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.
|
* @return bool True if the plugin identified by $pluginFile is being upgraded.
|
||||||
*/
|
*/
|
||||||
public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
|
public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
|
||||||
|
|
@ -38,7 +40,7 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
* Is there an update being installed for a specific theme?
|
* Is there an update being installed for a specific theme?
|
||||||
*
|
*
|
||||||
* @param string $stylesheet Theme directory name.
|
* @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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
|
public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
|
||||||
|
|
@ -50,7 +52,7 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param Plugin_Upgrader|WP_Upgrader|null $upgrader
|
* @param \Plugin_Upgrader|\WP_Upgrader|null $upgrader
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isBeingUpgraded($type, $id, $upgrader = null) {
|
protected function isBeingUpgraded($type, $id, $upgrader = null) {
|
||||||
|
|
@ -76,7 +78,7 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
* ['plugin', 'plugin-dir-name/plugin.php']
|
* ['plugin', 'plugin-dir-name/plugin.php']
|
||||||
* ['theme', 'theme-dir-name']
|
* ['theme', 'theme-dir-name']
|
||||||
*
|
*
|
||||||
* @param Plugin_Upgrader|WP_Upgrader $upgrader
|
* @param \Plugin_Upgrader|\WP_Upgrader $upgrader
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getThingBeingUpgradedBy($upgrader) {
|
private function getThingBeingUpgradedBy($upgrader) {
|
||||||
|
|
@ -89,13 +91,13 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
$themeDirectoryName = null;
|
$themeDirectoryName = null;
|
||||||
|
|
||||||
$skin = $upgrader->skin;
|
$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();
|
$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 !== '') ) {
|
if ( isset($skin->plugin) && is_string($skin->plugin) && ($skin->plugin !== '') ) {
|
||||||
$pluginFile = $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 !== '') ) {
|
if ( isset($skin->theme) && is_string($skin->theme) && ($skin->theme !== '') ) {
|
||||||
$themeDirectoryName = $skin->theme;
|
$themeDirectoryName = $skin->theme;
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +124,6 @@ if ( !class_exists('Puc_v5p0_UpgraderStatus', false) ):
|
||||||
*/
|
*/
|
||||||
private function identifyPluginByHeaders($searchHeaders) {
|
private function identifyPluginByHeaders($searchHeaders) {
|
||||||
if ( !function_exists('get_plugins') ){
|
if ( !function_exists('get_plugins') ){
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Utils', false) ):
|
if ( !class_exists(Utils::class, false) ):
|
||||||
|
|
||||||
class Puc_v5p0_Utils {
|
class Utils {
|
||||||
/**
|
/**
|
||||||
* Get a value from a nested array or object based on a path.
|
* Get a value from a nested array or object based on a path.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
abstract class Puc_v5p0_Vcs_Api {
|
use Parsedown;
|
||||||
|
use PucReadmeParser;
|
||||||
|
|
||||||
|
if ( !class_exists(Api::class, false) ):
|
||||||
|
|
||||||
|
abstract class Api {
|
||||||
const STRATEGY_LATEST_RELEASE = 'latest_release';
|
const STRATEGY_LATEST_RELEASE = 'latest_release';
|
||||||
const STRATEGY_LATEST_TAG = 'latest_tag';
|
const STRATEGY_LATEST_TAG = 'latest_tag';
|
||||||
const STRATEGY_STABLE_TAG = 'stable_tag';
|
const STRATEGY_STABLE_TAG = 'stable_tag';
|
||||||
|
|
@ -38,7 +43,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
protected $localDirectory = null;
|
protected $localDirectory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puc_v5p0_Vcs_Api constructor.
|
* Api constructor.
|
||||||
*
|
*
|
||||||
* @param string $repositoryUrl
|
* @param string $repositoryUrl
|
||||||
* @param array|string|null $credentials
|
* @param array|string|null $credentials
|
||||||
|
|
@ -59,7 +64,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
* 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.
|
* @param string $configBranch Start looking in this branch.
|
||||||
* @return null|Puc_v5p0_Vcs_Reference
|
* @return null|Reference
|
||||||
*/
|
*/
|
||||||
public function chooseReference($configBranch) {
|
public function chooseReference($configBranch) {
|
||||||
$strategies = $this->getUpdateDetectionStrategies($configBranch);
|
$strategies = $this->getUpdateDetectionStrategies($configBranch);
|
||||||
|
|
@ -145,7 +150,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
* Get a branch.
|
* Get a branch.
|
||||||
*
|
*
|
||||||
* @param string $branchName
|
* @param string $branchName
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
abstract public function getBranch($branchName);
|
abstract public function getBranch($branchName);
|
||||||
|
|
||||||
|
|
@ -153,7 +158,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
* Get a specific tag.
|
* Get a specific tag.
|
||||||
*
|
*
|
||||||
* @param string $tagName
|
* @param string $tagName
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
abstract public function getTag($tagName);
|
abstract public function getTag($tagName);
|
||||||
|
|
||||||
|
|
@ -161,7 +166,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
* Get the tag that looks like the highest version number.
|
* Get the tag that looks like the highest version number.
|
||||||
* (Implementations should skip pre-release versions if possible.)
|
* (Implementations should skip pre-release versions if possible.)
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
abstract public function getLatestTag();
|
abstract public function getLatestTag();
|
||||||
|
|
||||||
|
|
@ -187,7 +192,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
/**
|
/**
|
||||||
* Check if a tag appears to be named like a version number.
|
* Check if a tag appears to be named like a version number.
|
||||||
*
|
*
|
||||||
* @param stdClass $tag
|
* @param \stdClass $tag
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isVersionTag($tag) {
|
protected function isVersionTag($tag) {
|
||||||
|
|
@ -199,8 +204,8 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
* Sort a list of tags as if they were version numbers.
|
* Sort a list of tags as if they were version numbers.
|
||||||
* Tags that don't look like version number will be removed.
|
* Tags that don't look like version number will be removed.
|
||||||
*
|
*
|
||||||
* @param stdClass[] $tags Array of tag objects.
|
* @param \stdClass[] $tags Array of tag objects.
|
||||||
* @return stdClass[] Filtered array of tags sorted in descending order.
|
* @return \stdClass[] Filtered array of tags sorted in descending order.
|
||||||
*/
|
*/
|
||||||
protected function sortTagsByVersion($tags) {
|
protected function sortTagsByVersion($tags) {
|
||||||
//Keep only those tags that look like version numbers.
|
//Keep only those tags that look like version numbers.
|
||||||
|
|
@ -214,8 +219,8 @@ if ( !class_exists('Puc_v5p0_Vcs_Api') ):
|
||||||
/**
|
/**
|
||||||
* Compare two tags as if they were version number.
|
* Compare two tags as if they were version number.
|
||||||
*
|
*
|
||||||
* @param stdClass $tag1 Tag object.
|
* @param \stdClass $tag1 Tag object.
|
||||||
* @param stdClass $tag2 Another tag object.
|
* @param \stdClass $tag2 Another tag object.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function compareTagNames($tag1, $tag2) {
|
protected function compareTagNames($tag1, $tag2) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !interface_exists('Puc_v5p0_Vcs_BaseChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
interface Puc_v5p0_Vcs_BaseChecker {
|
if ( !interface_exists(BaseChecker::class, false) ):
|
||||||
|
|
||||||
|
interface BaseChecker {
|
||||||
/**
|
/**
|
||||||
* Set the repository branch to use for updates. Defaults to 'master'.
|
* Set the repository branch to use for updates. Defaults to 'master'.
|
||||||
*
|
*
|
||||||
|
|
@ -19,7 +21,7 @@ if ( !interface_exists('Puc_v5p0_Vcs_BaseChecker', false) ):
|
||||||
public function setAuthentication($credentials);
|
public function setAuthentication($credentials);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Puc_v5p0_Vcs_Api
|
* @return Api
|
||||||
*/
|
*/
|
||||||
public function getVcsApi();
|
public function getVcsApi();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
|
||||||
|
|
||||||
class Puc_v5p0_Vcs_BitBucketApi extends Puc_v5p0_Vcs_Api {
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\OAuthSignature;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Utils;
|
||||||
|
|
||||||
|
if ( !class_exists(BitBucketApi::class, false) ):
|
||||||
|
|
||||||
|
class BitBucketApi extends Api {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_OAuthSignature
|
* @var OAuthSignature
|
||||||
*/
|
*/
|
||||||
private $oauth = null;
|
private $oauth = null;
|
||||||
|
|
||||||
|
|
@ -23,7 +29,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
$this->username = $matches['username'];
|
$this->username = $matches['username'];
|
||||||
$this->repository = $matches['repository'];
|
$this->repository = $matches['repository'];
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
throw new \InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($repositoryUrl, $credentials);
|
parent::__construct($repositoryUrl, $credentials);
|
||||||
|
|
@ -60,7 +66,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
$ref = $branch->target->hash;
|
$ref = $branch->target->hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Puc_v5p0_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $ref,
|
'name' => $ref,
|
||||||
'updated' => $branch->target->date,
|
'updated' => $branch->target->date,
|
||||||
'downloadUrl' => $this->getDownloadUrl($branch->name),
|
'downloadUrl' => $this->getDownloadUrl($branch->name),
|
||||||
|
|
@ -71,7 +77,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
* Get a specific tag.
|
* Get a specific tag.
|
||||||
*
|
*
|
||||||
* @param string $tagName
|
* @param string $tagName
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getTag($tagName) {
|
public function getTag($tagName) {
|
||||||
$tag = $this->api('/refs/tags/' . $tagName);
|
$tag = $this->api('/refs/tags/' . $tagName);
|
||||||
|
|
@ -79,7 +85,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Puc_v5p0_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'version' => ltrim($tag->name, 'v'),
|
'version' => ltrim($tag->name, 'v'),
|
||||||
'updated' => $tag->target->date,
|
'updated' => $tag->target->date,
|
||||||
|
|
@ -90,7 +96,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
/**
|
/**
|
||||||
* Get the tag that looks like the highest version number.
|
* Get the tag that looks like the highest version number.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getLatestTag() {
|
public function getLatestTag() {
|
||||||
$tags = $this->api('/refs/tags?sort=-target.date');
|
$tags = $this->api('/refs/tags?sort=-target.date');
|
||||||
|
|
@ -104,7 +110,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
//Return the first result.
|
//Return the first result.
|
||||||
if ( !empty($versionTags) ) {
|
if ( !empty($versionTags) ) {
|
||||||
$tag = $versionTags[0];
|
$tag = $versionTags[0];
|
||||||
return new Puc_v5p0_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'version' => ltrim($tag->name, 'v'),
|
'version' => ltrim($tag->name, 'v'),
|
||||||
'updated' => $tag->target->date,
|
'updated' => $tag->target->date,
|
||||||
|
|
@ -118,7 +124,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
* Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
|
* Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
|
||||||
*
|
*
|
||||||
* @param string $branch
|
* @param string $branch
|
||||||
* @return null|Puc_v5p0_Vcs_Reference
|
* @return null|Reference
|
||||||
*/
|
*/
|
||||||
protected function getStableTag($branch) {
|
protected function getStableTag($branch) {
|
||||||
$remoteReadme = $this->getRemoteReadme($branch);
|
$remoteReadme = $this->getRemoteReadme($branch);
|
||||||
|
|
@ -184,11 +190,11 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $version
|
* @param string $version
|
||||||
* @return mixed|WP_Error
|
* @return mixed|\WP_Error
|
||||||
*/
|
*/
|
||||||
public function api($url, $version = '2.0') {
|
public function api($url, $version = '2.0') {
|
||||||
$url = ltrim($url, '/');
|
$url = ltrim($url, '/');
|
||||||
$isSrcResource = Puc_v5p0_Utils::startsWith($url, 'src/');
|
$isSrcResource = Utils::startsWith($url, 'src/');
|
||||||
|
|
||||||
$url = implode('/', array(
|
$url = implode('/', array(
|
||||||
'https://api.bitbucket.org',
|
'https://api.bitbucket.org',
|
||||||
|
|
@ -227,7 +233,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
return $document;
|
return $document;
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = new WP_Error(
|
$error = new \WP_Error(
|
||||||
'puc-bitbucket-http-error',
|
'puc-bitbucket-http-error',
|
||||||
sprintf('BitBucket API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
sprintf('BitBucket API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||||
);
|
);
|
||||||
|
|
@ -243,7 +249,7 @@ if ( !class_exists('Puc_v5p0_Vcs_BitBucketApi', false) ):
|
||||||
parent::setAuthentication($credentials);
|
parent::setAuthentication($credentials);
|
||||||
|
|
||||||
if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
|
if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
|
||||||
$this->oauth = new Puc_v5p0_OAuthSignature(
|
$this->oauth = new OAuthSignature(
|
||||||
$credentials['consumer_key'],
|
$credentials['consumer_key'],
|
||||||
$credentials['consumer_secret']
|
$credentials['consumer_secret']
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
use Parsedown;
|
||||||
|
|
||||||
class Puc_v5p0_Vcs_GitHubApi extends Puc_v5p0_Vcs_Api {
|
if ( !class_exists(GitHubApi::class, false) ):
|
||||||
|
|
||||||
|
class GitHubApi extends Api {
|
||||||
/**
|
/**
|
||||||
* @var string GitHub username.
|
* @var string GitHub username.
|
||||||
*/
|
*/
|
||||||
|
|
@ -48,7 +51,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
$this->userName = $matches['username'];
|
$this->userName = $matches['username'];
|
||||||
$this->repositoryName = $matches['repository'];
|
$this->repositoryName = $matches['repository'];
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
throw new \InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($repositoryUrl, $accessToken);
|
parent::__construct($repositoryUrl, $accessToken);
|
||||||
|
|
@ -57,7 +60,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
/**
|
/**
|
||||||
* Get the latest release from GitHub.
|
* Get the latest release from GitHub.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getLatestRelease() {
|
public function getLatestRelease() {
|
||||||
$release = $this->api('/repos/:user/:repo/releases/latest');
|
$release = $this->api('/repos/:user/:repo/releases/latest');
|
||||||
|
|
@ -65,7 +68,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reference = new Puc_v5p0_Vcs_Reference(array(
|
$reference = new Reference(array(
|
||||||
'name' => $release->tag_name,
|
'name' => $release->tag_name,
|
||||||
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
||||||
'downloadUrl' => $release->zipball_url,
|
'downloadUrl' => $release->zipball_url,
|
||||||
|
|
@ -108,7 +111,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
/**
|
/**
|
||||||
* Get the tag that looks like the highest version number.
|
* Get the tag that looks like the highest version number.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getLatestTag() {
|
public function getLatestTag() {
|
||||||
$tags = $this->api('/repos/:user/:repo/tags');
|
$tags = $this->api('/repos/:user/:repo/tags');
|
||||||
|
|
@ -123,7 +126,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = $versionTags[0];
|
$tag = $versionTags[0];
|
||||||
return new Puc_v5p0_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'version' => ltrim($tag->name, 'v'),
|
'version' => ltrim($tag->name, 'v'),
|
||||||
'downloadUrl' => $tag->zipball_url,
|
'downloadUrl' => $tag->zipball_url,
|
||||||
|
|
@ -135,7 +138,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
* Get a branch by name.
|
* Get a branch by name.
|
||||||
*
|
*
|
||||||
* @param string $branchName
|
* @param string $branchName
|
||||||
* @return null|Puc_v5p0_Vcs_Reference
|
* @return null|Reference
|
||||||
*/
|
*/
|
||||||
public function getBranch($branchName) {
|
public function getBranch($branchName) {
|
||||||
$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
|
$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
|
||||||
|
|
@ -143,7 +146,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reference = new Puc_v5p0_Vcs_Reference(array(
|
$reference = new Reference(array(
|
||||||
'name' => $branch->name,
|
'name' => $branch->name,
|
||||||
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
||||||
'apiResponse' => $branch,
|
'apiResponse' => $branch,
|
||||||
|
|
@ -161,7 +164,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
*
|
*
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @param string $ref Reference name (e.g. branch or tag).
|
* @param string $ref Reference name (e.g. branch or tag).
|
||||||
* @return StdClass|null
|
* @return \StdClass|null
|
||||||
*/
|
*/
|
||||||
public function getLatestCommit($filename, $ref = 'master') {
|
public function getLatestCommit($filename, $ref = 'master') {
|
||||||
$commits = $this->api(
|
$commits = $this->api(
|
||||||
|
|
@ -196,7 +199,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return mixed|WP_Error
|
* @return mixed|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function api($url, $queryParams = array()) {
|
protected function api($url, $queryParams = array()) {
|
||||||
$baseUrl = $url;
|
$baseUrl = $url;
|
||||||
|
|
@ -223,7 +226,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
return $document;
|
return $document;
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = new WP_Error(
|
$error = new \WP_Error(
|
||||||
'puc-github-http-error',
|
'puc-github-http-error',
|
||||||
sprintf('GitHub API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
sprintf('GitHub API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||||
);
|
);
|
||||||
|
|
@ -297,7 +300,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
*/
|
*/
|
||||||
public function getTag($tagName) {
|
public function getTag($tagName) {
|
||||||
//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
|
//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) {
|
public function setAuthentication($credentials) {
|
||||||
|
|
@ -350,7 +353,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitHubApi', false) ):
|
||||||
/**
|
/**
|
||||||
* Does this asset match the file name regex?
|
* Does this asset match the file name regex?
|
||||||
*
|
*
|
||||||
* @param stdClass $releaseAsset
|
* @param \stdClass $releaseAsset
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function matchesAssetFilter($releaseAsset) {
|
protected function matchesAssetFilter($releaseAsset) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
if ( !class_exists(GitLabApi::class, false) ):
|
||||||
|
|
||||||
class Puc_v5p0_Vcs_GitLabApi extends Puc_v5p0_Vcs_Api {
|
class GitLabApi extends Api {
|
||||||
/**
|
/**
|
||||||
* @var string GitLab username.
|
* @var string GitLab username.
|
||||||
*/
|
*/
|
||||||
|
|
@ -59,7 +60,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
//This is probably a repository in a subgroup, e.g. "/organization/category/repo".
|
//This is probably a repository in a subgroup, e.g. "/organization/category/repo".
|
||||||
$parts = explode('/', trim($path, '/'));
|
$parts = explode('/', trim($path, '/'));
|
||||||
if ( count($parts) < 3 ) {
|
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);
|
$lastPart = array_pop($parts);
|
||||||
$this->userName = implode('/', $parts);
|
$this->userName = implode('/', $parts);
|
||||||
|
|
@ -76,7 +77,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
|
|
||||||
//We need at least /user-name/repository-name/
|
//We need at least /user-name/repository-name/
|
||||||
if ( count($segments) < 2 ) {
|
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.
|
//Get the username and repository name.
|
||||||
|
|
@ -101,7 +102,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
/**
|
/**
|
||||||
* Get the latest release from GitLab.
|
* Get the latest release from GitLab.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getLatestRelease() {
|
public function getLatestRelease() {
|
||||||
$releases = $this->api('/:id/releases');
|
$releases = $this->api('/:id/releases');
|
||||||
|
|
@ -118,7 +119,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reference = new Puc_v5p0_Vcs_Reference(array(
|
$reference = new Reference(array(
|
||||||
'name' => $release->tag_name,
|
'name' => $release->tag_name,
|
||||||
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
||||||
'downloadUrl' => '',
|
'downloadUrl' => '',
|
||||||
|
|
@ -177,7 +178,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
/**
|
/**
|
||||||
* Get the tag that looks like the highest version number.
|
* Get the tag that looks like the highest version number.
|
||||||
*
|
*
|
||||||
* @return Puc_v5p0_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getLatestTag() {
|
public function getLatestTag() {
|
||||||
$tags = $this->api('/:id/repository/tags');
|
$tags = $this->api('/:id/repository/tags');
|
||||||
|
|
@ -191,7 +192,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = $versionTags[0];
|
$tag = $versionTags[0];
|
||||||
return new Puc_v5p0_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'version' => ltrim($tag->name, 'v'),
|
'version' => ltrim($tag->name, 'v'),
|
||||||
'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name),
|
'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name),
|
||||||
|
|
@ -203,7 +204,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
* Get a branch by name.
|
* Get a branch by name.
|
||||||
*
|
*
|
||||||
* @param string $branchName
|
* @param string $branchName
|
||||||
* @return null|Puc_v5p0_Vcs_Reference
|
* @return null|Reference
|
||||||
*/
|
*/
|
||||||
public function getBranch($branchName) {
|
public function getBranch($branchName) {
|
||||||
$branch = $this->api('/:id/repository/branches/' . $branchName);
|
$branch = $this->api('/:id/repository/branches/' . $branchName);
|
||||||
|
|
@ -211,7 +212,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reference = new Puc_v5p0_Vcs_Reference(array(
|
$reference = new Reference(array(
|
||||||
'name' => $branch->name,
|
'name' => $branch->name,
|
||||||
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
||||||
'apiResponse' => $branch,
|
'apiResponse' => $branch,
|
||||||
|
|
@ -244,7 +245,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @return mixed|WP_Error
|
* @return mixed|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function api($url, $queryParams = array()) {
|
protected function api($url, $queryParams = array()) {
|
||||||
$baseUrl = $url;
|
$baseUrl = $url;
|
||||||
|
|
@ -267,7 +268,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
return json_decode($body);
|
return json_decode($body);
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = new WP_Error(
|
$error = new \WP_Error(
|
||||||
'puc-gitlab-http-error',
|
'puc-gitlab-http-error',
|
||||||
sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||||
);
|
);
|
||||||
|
|
@ -353,7 +354,7 @@ if ( !class_exists('Puc_v5p0_Vcs_GitLabApi', false) ):
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getTag($tagName) {
|
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) {
|
protected function getUpdateDetectionStrategies($configBranch) {
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
|
||||||
|
|
||||||
class Puc_v5p0_Vcs_PluginUpdateChecker extends Puc_v5p0_Plugin_UpdateChecker implements Puc_v5p0_Vcs_BaseChecker {
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Plugin;
|
||||||
|
|
||||||
|
if ( !class_exists(PluginUpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
class PluginUpdateChecker extends Plugin\UpdateChecker implements BaseChecker {
|
||||||
/**
|
/**
|
||||||
* @var string The branch where to look for updates. Defaults to "master".
|
* @var string The branch where to look for updates. Defaults to "master".
|
||||||
*/
|
*/
|
||||||
protected $branch = 'master';
|
protected $branch = 'master';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Vcs_Api Repository API client.
|
* @var Api Repository API client.
|
||||||
*/
|
*/
|
||||||
protected $api = null;
|
protected $api = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puc_v5p0_Vcs_PluginUpdateChecker constructor.
|
* PluginUpdateChecker constructor.
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Vcs_Api $api
|
* @param Api $api
|
||||||
* @param string $pluginFile
|
* @param string $pluginFile
|
||||||
* @param string $slug
|
* @param string $slug
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
|
|
@ -42,7 +47,7 @@ if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
||||||
$api = $this->api;
|
$api = $this->api;
|
||||||
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
||||||
|
|
||||||
$info = new Puc_v5p0_Plugin_Info();
|
$info = new Plugin\PluginInfo();
|
||||||
$info->filename = $this->pluginFile;
|
$info->filename = $this->pluginFile;
|
||||||
$info->slug = $this->slug;
|
$info->slug = $this->slug;
|
||||||
|
|
||||||
|
|
@ -68,7 +73,7 @@ if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
||||||
//There's probably a network problem or an authentication error.
|
//There's probably a network problem or an authentication error.
|
||||||
do_action(
|
do_action(
|
||||||
'puc_api_error',
|
'puc_api_error',
|
||||||
new WP_Error(
|
new \WP_Error(
|
||||||
'puc-no-update-source',
|
'puc-no-update-source',
|
||||||
'Could not retrieve version information from the repository. '
|
'Could not retrieve version information from the repository. '
|
||||||
. 'This usually means that the update checker either can\'t connect '
|
. 'This usually means that the update checker either can\'t connect '
|
||||||
|
|
@ -127,7 +132,7 @@ if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
||||||
* Copy plugin metadata from a file header to a Plugin Info object.
|
* Copy plugin metadata from a file header to a Plugin Info object.
|
||||||
*
|
*
|
||||||
* @param array $fileHeader
|
* @param array $fileHeader
|
||||||
* @param Puc_v5p0_Plugin_Info $pluginInfo
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
*/
|
*/
|
||||||
protected function setInfoFromHeader($fileHeader, $pluginInfo) {
|
protected function setInfoFromHeader($fileHeader, $pluginInfo) {
|
||||||
$headerToPropertyMap = array(
|
$headerToPropertyMap = array(
|
||||||
|
|
@ -160,7 +165,7 @@ if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
||||||
* Copy plugin metadata from the remote readme.txt file.
|
* Copy plugin metadata from the remote readme.txt file.
|
||||||
*
|
*
|
||||||
* @param string $ref GitHub tag or branch where to look for the readme.
|
* @param string $ref GitHub tag or branch where to look for the readme.
|
||||||
* @param Puc_v5p0_Plugin_Info $pluginInfo
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
*/
|
*/
|
||||||
protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
|
protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
|
||||||
$readme = $this->api->getRemoteReadme($ref);
|
$readme = $this->api->getRemoteReadme($ref);
|
||||||
|
|
@ -193,7 +198,7 @@ if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
||||||
* and file names are described here:
|
* and file names are described here:
|
||||||
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons
|
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Plugin_Info $pluginInfo
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
*/
|
*/
|
||||||
protected function setIconsFromLocalAssets($pluginInfo) {
|
protected function setIconsFromLocalAssets($pluginInfo) {
|
||||||
$icons = $this->getLocalAssetUrls(array(
|
$icons = $this->getLocalAssetUrls(array(
|
||||||
|
|
@ -222,7 +227,7 @@ if ( !class_exists('Puc_v5p0_Vcs_PluginUpdateChecker') ):
|
||||||
* and file names are described here:
|
* and file names are described here:
|
||||||
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-headers
|
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-headers
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Plugin_Info $pluginInfo
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
*/
|
*/
|
||||||
protected function setBannersFromLocalAssets($pluginInfo) {
|
protected function setBannersFromLocalAssets($pluginInfo) {
|
||||||
$banners = $this->getLocalAssetUrls(array(
|
$banners = $this->getLocalAssetUrls(array(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_Reference', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
|
if ( !class_exists(Reference::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a VCS branch or tag. It's intended as a read only, short-lived container
|
* This class represents a VCS branch or tag. It's intended as a read only, short-lived container
|
||||||
|
|
@ -13,7 +15,7 @@ if ( !class_exists('Puc_v5p0_Vcs_Reference', false) ):
|
||||||
* @property string|null $changelog
|
* @property string|null $changelog
|
||||||
* @property int|null $downloadCount
|
* @property int|null $downloadCount
|
||||||
*/
|
*/
|
||||||
class Puc_v5p0_Vcs_Reference {
|
class Reference {
|
||||||
private $properties = array();
|
private $properties = array();
|
||||||
|
|
||||||
public function __construct($properties = array()) {
|
public function __construct($properties = array()) {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v5p0_Vcs_ThemeUpdateChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p0\Vcs;
|
||||||
|
|
||||||
class Puc_v5p0_Vcs_ThemeUpdateChecker extends Puc_v5p0_Theme_UpdateChecker implements Puc_v5p0_Vcs_BaseChecker {
|
use YahnisElsts\PluginUpdateChecker\v5p0\Theme;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\Utils;
|
||||||
|
|
||||||
|
if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
class ThemeUpdateChecker extends Theme\UpdateChecker implements BaseChecker {
|
||||||
/**
|
/**
|
||||||
* @var string The branch where to look for updates. Defaults to "master".
|
* @var string The branch where to look for updates. Defaults to "master".
|
||||||
*/
|
*/
|
||||||
protected $branch = 'master';
|
protected $branch = 'master';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v5p0_Vcs_Api Repository API client.
|
* @var Api Repository API client.
|
||||||
*/
|
*/
|
||||||
protected $api = null;
|
protected $api = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puc_v5p0_Vcs_ThemeUpdateChecker constructor.
|
* ThemeUpdateChecker constructor.
|
||||||
*
|
*
|
||||||
* @param Puc_v5p0_Vcs_Api $api
|
* @param Api $api
|
||||||
* @param null $stylesheet
|
* @param null $stylesheet
|
||||||
* @param null $customSlug
|
* @param null $customSlug
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
|
|
@ -36,7 +41,7 @@ if ( !class_exists('Puc_v5p0_Vcs_ThemeUpdateChecker', false) ):
|
||||||
$api = $this->api;
|
$api = $this->api;
|
||||||
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
||||||
|
|
||||||
$update = new Puc_v5p0_Theme_Update();
|
$update = new Theme\Update();
|
||||||
$update->slug = $this->slug;
|
$update->slug = $this->slug;
|
||||||
|
|
||||||
//Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
|
//Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
|
||||||
|
|
@ -47,7 +52,7 @@ if ( !class_exists('Puc_v5p0_Vcs_ThemeUpdateChecker', false) ):
|
||||||
} else {
|
} else {
|
||||||
do_action(
|
do_action(
|
||||||
'puc_api_error',
|
'puc_api_error',
|
||||||
new WP_Error(
|
new \WP_Error(
|
||||||
'puc-no-update-source',
|
'puc-no-update-source',
|
||||||
'Could not retrieve version information from the repository. '
|
'Could not retrieve version information from the repository. '
|
||||||
. 'This usually means that the update checker either can\'t connect '
|
. 'This usually means that the update checker either can\'t connect '
|
||||||
|
|
@ -61,13 +66,13 @@ if ( !class_exists('Puc_v5p0_Vcs_ThemeUpdateChecker', false) ):
|
||||||
//Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata
|
//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.
|
//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));
|
$remoteHeader = $this->package->getFileHeader($api->getRemoteFile('style.css', $ref));
|
||||||
$update->version = Puc_v5p0_Utils::findNotEmpty(array(
|
$update->version = Utils::findNotEmpty(array(
|
||||||
$remoteHeader['Version'],
|
$remoteHeader['Version'],
|
||||||
Puc_v5p0_Utils::get($updateSource, 'version'),
|
Utils::get($updateSource, 'version'),
|
||||||
));
|
));
|
||||||
|
|
||||||
//The details URL defaults to the Theme URI header or the repository URL.
|
//The details URL defaults to the Theme URI header or the repository URL.
|
||||||
$update->details_url = Puc_v5p0_Utils::findNotEmpty(array(
|
$update->details_url = Utils::findNotEmpty(array(
|
||||||
$remoteHeader['ThemeURI'],
|
$remoteHeader['ThemeURI'],
|
||||||
$this->package->getHeaderValue('ThemeURI'),
|
$this->package->getHeaderValue('ThemeURI'),
|
||||||
$this->metadataUrl,
|
$this->metadataUrl,
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
||||||
Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:
|
Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:
|
||||||
```php
|
```php
|
||||||
$myUpdateChecker = new Puc_v5p0_Vcs_PluginUpdateChecker(
|
$myUpdateChecker = new Puc_v5p0_Vcs_PluginUpdateChecker(
|
||||||
new Puc_v5p0_Vcs_GitLabApi('https://myserver.com/user-name/repo-name/'),
|
new GitLabApi('https://myserver.com/user-name/repo-name/'),
|
||||||
__FILE__,
|
__FILE__,
|
||||||
'unique-plugin-or-theme-slug'
|
'unique-plugin-or-theme-slug'
|
||||||
);
|
);
|
||||||
|
|
@ -253,7 +253,7 @@ BitBucket doesn't have an equivalent to GitHub's releases, so the process is sli
|
||||||
If you're using a self-hosted GitLab instance and [subgroups or nested groups](https://docs.gitlab.com/ce/user/group/subgroups/index.html), you have to tell the update checker which parts of the URL are subgroups:
|
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
|
```php
|
||||||
$myUpdateChecker = new Puc_v5p0_Vcs_PluginUpdateChecker(
|
$myUpdateChecker = new Puc_v5p0_Vcs_PluginUpdateChecker(
|
||||||
new Puc_v5p0_Vcs_GitLabApi('https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/', null, 'subgroup-level1/subgroup-level2/subgroup-level3'),
|
new GitLabApi('https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/', null, 'subgroup-level1/subgroup-level2/subgroup-level3'),
|
||||||
__FILE__,
|
__FILE__,
|
||||||
'unique-plugin-or-theme-slug'
|
'unique-plugin-or-theme-slug'
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
<?php
|
|
||||||
require dirname(__FILE__) . '/Puc/v5p0/Autoloader.php';
|
|
||||||
new Puc_v5p0_Autoloader();
|
|
||||||
|
|
||||||
require dirname(__FILE__) . '/Puc/v5p0/Factory.php';
|
|
||||||
require dirname(__FILE__) . '/Puc/v5/Factory.php';
|
|
||||||
|
|
||||||
//Register classes defined in this version with the factory.
|
|
||||||
foreach (
|
|
||||||
array(
|
|
||||||
'Plugin_UpdateChecker' => 'Puc_v5p0_Plugin_UpdateChecker',
|
|
||||||
'Theme_UpdateChecker' => 'Puc_v5p0_Theme_UpdateChecker',
|
|
||||||
|
|
||||||
'Vcs_PluginUpdateChecker' => 'Puc_v5p0_Vcs_PluginUpdateChecker',
|
|
||||||
'Vcs_ThemeUpdateChecker' => 'Puc_v5p0_Vcs_ThemeUpdateChecker',
|
|
||||||
|
|
||||||
'GitHubApi' => 'Puc_v5p0_Vcs_GitHubApi',
|
|
||||||
'BitBucketApi' => 'Puc_v5p0_Vcs_BitBucketApi',
|
|
||||||
'GitLabApi' => 'Puc_v5p0_Vcs_GitLabApi',
|
|
||||||
)
|
|
||||||
as $pucGeneralClass => $pucVersionedClass
|
|
||||||
) {
|
|
||||||
Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '5.0');
|
|
||||||
//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_v5p0_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '5.0');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p0;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory as MajorFactory;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p0\PucFactory as MinorFactory;
|
||||||
|
|
||||||
|
require __DIR__ . '/Puc/v5p0/Autoloader.php';
|
||||||
|
new Autoloader();
|
||||||
|
|
||||||
|
require __DIR__ . '/Puc/v5p0/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.0');
|
||||||
|
//Also add it to the minor-version factory in case the major-version factory
|
||||||
|
//was already defined by another, older version of the update checker.
|
||||||
|
MinorFactory::addVersion($pucGeneralClass, $pucVersionedClass, '5.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,9 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Parsedown', false) ) {
|
if ( !class_exists('Parsedown', false) ) {
|
||||||
//Load the Parsedown version that's compatible with the current PHP version.
|
|
||||||
if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
|
|
||||||
require __DIR__ . '/ParsedownModern.php';
|
require __DIR__ . '/ParsedownModern.php';
|
||||||
} else {
|
|
||||||
require __DIR__ . '/ParsedownLegacy.php';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue