$metadataUrl
$metadataUrl :
__construct(string $metadataUrl, string $pluginFile, string $slug = '', integer $checkPeriod = 12, $pluginName = '', string $optionName = '', string $muPluginFile = '')
Class constructor.
string | $metadataUrl | The URL of the plugin's metadata file. |
string | $pluginFile | Fully qualified path to the main plugin file. |
string | $slug | The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug. |
integer | $checkPeriod | How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks. |
$pluginName | ||
string | $optionName | Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'. |
string | $muPluginFile | Optional. The plugin filename relative to the mu-plugins directory. |
requestInfo(array $queryArgs = array()) : \PluginInfo
Retrieve plugin info from the configured API endpoint.
array | $queryArgs | Additional query arguments to append to the request. Optional. |
requestUpdate() : \PluginUpdate
Retrieve the latest update (if any) from the configured API endpoint.
An instance of PluginUpdate, or NULL when no updates are available.
checkForUpdates() : \PluginUpdate|null
Check for plugin updates.
The results are stored in the DB option specified in $optionName.
maybeCheckForUpdates()
Check for updates if the configured check interval has already elapsed.
Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
You can override the default behaviour by using the "puc_check_now-$slug" filter. The filter callback will be passed three parameters:
This method is declared public because it's a hook callback. Calling it directly is not recommended.
fixDirectoryName(string $source, string $remoteSource, \WP_Upgrader $upgrader) : string|\WP_Error
Rename the update directory to match the existing plugin directory.
When WordPress installs a plugin or theme update, it assumes that the ZIP file will contain exactly one directory, and that the directory name will be the same as the directory where the plugin/theme is currently installed.
GitHub and other repositories provide ZIP downloads, but they often use directory names like "project-branch" or "project-tag-hash". We need to change the name to the actual plugin folder.
string | $source | The directory to copy to /wp-content/plugins. Usually a subdirectory of $remoteSource. |
string | $remoteSource | WordPress has extracted the update to this directory. |
\WP_Upgrader | $upgrader |
getUpdate() : \PluginUpdate|null
Get the details of the currently available update, if any.
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.
addCheckForUpdatesLink(array $pluginMeta, string $pluginFile) : 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.
You can change the link text by using the "puc_manual_check_link-$slug" filter. Returning an empty string from the filter will disable the link.
array | $pluginMeta | Array of meta links. |
string | $pluginFile |
addHttpRequestArgFilter(callable $callback) : void
Register a callback for filtering arguments passed to wp_remote_get().
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.
callable | $callback |
addResultFilter(callable $callback) : void
Register a callback for filtering the plugin info retrieved from the external API.
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.
callable | $callback |
addFilter(string $tag, callable $callback, integer $priority = 10, integer $acceptedArgs = 1)
Register a callback for one of the update checker filters.
Identical to addfilter(), 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".
string | $tag | |
callable | $callback | |
integer | $priority | |
integer | $acceptedArgs |