PHP Class PluginUpdateChecker_1_3_1, bp-reply-by-email

Author: Janis Elsts
Show file Open project: r-a-y/bp-reply-by-email

Public Properties

Property Type Description
$checkPeriod Plugin slug.
$debugMode Where to store the update info.
$metadataUrl
$optionName How often to check for updates (in hours).
$pluginFile The URL of the plugin's metadata file.
$slug Plugin filename relative to the plugins directory.

Public Methods

Method Description
__construct ( string $metadataUrl, string $pluginFile, string $slug = '', integer $checkPeriod = 12, string $optionName = '' ) Class constructor.
_addCustomSchedule ( array $schedules ) : array Add our custom schedule to the array of Cron schedules used by WP.
_removeUpdaterCron ( ) : void Remove the scheduled cron event that the library uses to check for updates.
addCheckForUpdatesLink ( array $pluginMeta, string $pluginFile, array | null $pluginData = null, string | null $status = null ) : array Add a "Check for updates" link to the plugin row in the "Plugins" page. By default, the new link will appear after the "Visit plugin site" link.
addFilter ( string $tag, callable $callback, integer $priority = 10, integer $acceptedArgs = 1 ) Register a callback for one of the update checker filters.
addHttpRequestArgFilter ( callable $callback ) : void Register a callback for filtering arguments passed to wp_remote_get().
addQueryArgFilter ( callable $callback ) : void Register a callback for filtering query arguments.
addResultFilter ( callable $callback ) : void Register a callback for filtering the plugin info retrieved from the external API.
checkForUpdates ( ) : PluginUpdate | null Check for plugin updates.
displayManualCheckResult ( ) Display the results of a manual update check.
getCronHookName ( ) : string Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
getInstalledVersion ( ) : string Get the currently installed version of the plugin.
getUpdate ( ) : PluginUpdate | null Get the details of the currently available update, if any.
getUpdateState ( ) : StdClass | null Load the update checker state from the DB.
handleManualCheck ( ) : void Check for updates when the user clicks the "Check for updates" link.
initDebugBarPanel ( ) Initialize the update checker Debug Bar plugin/add-on thingy.
injectInfo ( mixed $result, string $action = null, array | object $args = null ) : mixed Intercept plugins_api() calls that request information about our plugin and use the configured API endpoint to satisfy them.
injectUpdate ( StdClass $updates ) : StdClass Insert the latest update (if any) into the update list maintained by WP.
maybeCheckForUpdates ( ) : void Check for updates only if the configured check interval has already elapsed.
renameGithubDirectory ( string $source, string $remote_source ) : string Github .zip packages appends the branch name to the plugin's folder name.
requestInfo ( array $queryArgs = [] ) : PluginInfo Retrieve plugin info from the configured API endpoint.
requestUpdate ( ) : PluginUpdate Retrieve the latest update (if any) from the configured API endpoint.
resetUpdateState ( ) Reset update checker state - i.e. last check time, cached update data and so on.
sslVerify ( mixed $args, string $url ) : mixed Callback function for the 'http_request_args' filter.

Protected Methods

Method Description
installHooks ( ) : void Install the hooks required to run periodic update checks and inject update info into WP data structures.

Private Methods

Method Description
setUpdateState ( StdClass $state ) : void Persist the update checker state to the DB.

Method Details

__construct() public method

Class constructor.
public __construct ( string $metadataUrl, string $pluginFile, string $slug = '', integer $checkPeriod = 12, string $optionName = '' )
$metadataUrl string The URL of the plugin's metadata file.
$pluginFile string Fully qualified path to the main plugin file.
$slug string The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
$checkPeriod integer How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
$optionName string Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.

_addCustomSchedule() public method

Add our custom schedule to the array of Cron schedules used by WP.
public _addCustomSchedule ( array $schedules ) : array
$schedules array
return array

_removeUpdaterCron() public method

Remove the scheduled cron event that the library uses to check for updates.
public _removeUpdaterCron ( ) : void
return void

addFilter() public method

Identical to add_filter(), except it automatically adds the "puc_" prefix and the "-$plugin_slug" suffix to the filter name. For example, "request_info_result" becomes "puc_request_info_result-your_plugin_slug".
public addFilter ( string $tag, callable $callback, integer $priority = 10, integer $acceptedArgs = 1 )
$tag string
$callback callable
$priority integer
$acceptedArgs integer

addHttpRequestArgFilter() public method

The callback function should take one argument - an associative array of arguments - and return a modified array or arguments. See the WP documentation on wp_remote_get() for details on what arguments are available and how they work.
public addHttpRequestArgFilter ( callable $callback ) : void
$callback callable
return void

addQueryArgFilter() public method

The callback function should take one argument - an associative array of query arguments. It should return a modified array of query arguments.
public addQueryArgFilter ( callable $callback ) : void
$callback callable
return void

addResultFilter() public method

The callback function should take two arguments. If the plugin info was retrieved successfully, the first argument passed will be an instance of PluginInfo. Otherwise, it will be NULL. The second argument will be the corresponding return value of wp_remote_get (see WP docs for details). The callback function should return a new or modified instance of PluginInfo or NULL.
public addResultFilter ( callable $callback ) : void
$callback callable
return void

checkForUpdates() public method

The results are stored in the DB option specified in $optionName.
public checkForUpdates ( ) : PluginUpdate | null
return PluginUpdate | null

displayManualCheckResult() public method

Display the results of a manual update check.
See also: self::handleManualCheck() You can change the result message by using the "puc_manual_check_message-$slug" filter.

getCronHookName() public method

Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
public getCronHookName ( ) : string
return string

getInstalledVersion() public method

Get the currently installed version of the plugin.
public getInstalledVersion ( ) : string
return string Version number.

getUpdate() public method

If no updates are available, or if the last known update version is below or equal to the currently installed version, this method will return NULL. Uses cached update data. To retrieve update information straight from the metadata URL, call requestUpdate() instead.
public getUpdate ( ) : PluginUpdate | null
return PluginUpdate | null

getUpdateState() public method

Load the update checker state from the DB.
public getUpdateState ( ) : StdClass | null
return StdClass | null

handleManualCheck() public method

Check for updates when the user clicks the "Check for updates" link.
See also: self::addCheckForUpdatesLink()
public handleManualCheck ( ) : void
return void

initDebugBarPanel() public method

Initialize the update checker Debug Bar plugin/add-on thingy.
public initDebugBarPanel ( )

injectInfo() public method

Intercept plugins_api() calls that request information about our plugin and use the configured API endpoint to satisfy them.
See also: plugins_api()
public injectInfo ( mixed $result, string $action = null, array | object $args = null ) : mixed
$result mixed
$action string
$args array | object
return mixed

injectUpdate() public method

Insert the latest update (if any) into the update list maintained by WP.
public injectUpdate ( StdClass $updates ) : StdClass
$updates StdClass Update list.
return StdClass Modified update list.

installHooks() protected method

Install the hooks required to run periodic update checks and inject update info into WP data structures.
protected installHooks ( ) : void
return void

maybeCheckForUpdates() public method

Check for updates only if the configured check interval has already elapsed.
public maybeCheckForUpdates ( ) : void
return void

renameGithubDirectory() public method

This isn't desirable. So we check to see if our plugin is hosted on Github. If so, we remove the branch name from the plugin's folder name to resemble WP convention.
public renameGithubDirectory ( string $source, string $remote_source ) : string
$source string Temporary location of the extracted folder. Contains the plugin folder name with the Github branch appended.
$remote_source string Temporary parent location. One level up from the extracted folder.
return string Location of the extracted folder

requestInfo() public method

Retrieve plugin info from the configured API endpoint.
public requestInfo ( array $queryArgs = [] ) : PluginInfo
$queryArgs array Additional query arguments to append to the request. Optional.
return PluginInfo

requestUpdate() public method

Retrieve the latest update (if any) from the configured API endpoint.
public requestUpdate ( ) : PluginUpdate
return PluginUpdate An instance of PluginUpdate, or NULL when no updates are available.

resetUpdateState() public method

Call this when your plugin is being uninstalled, or if you want to clear the update cache.
public resetUpdateState ( )

sslVerify() public method

Check if download request is from Github. If so, set the 'sslverify' flag to false to allow the download to bypass SSL certificate verification.
public sslVerify ( mixed $args, string $url ) : mixed
$args mixed
$url string
return mixed

Property Details

$checkPeriod public property

Plugin slug.
public $checkPeriod

$debugMode public property

Where to store the update info.
public $debugMode

$metadataUrl public property

public $metadataUrl

$optionName public property

How often to check for updates (in hours).
public $optionName

$pluginFile public property

The URL of the plugin's metadata file.
public $pluginFile

$slug public property

Plugin filename relative to the plugins directory.
public $slug