Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/cookiead.../includes
File: plugin-update-checker.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Plugin Update Checker Library 3.2
[2] Fix | Delete
* http://w-shadow.com/
[3] Fix | Delete
*
[4] Fix | Delete
* Copyright 2016 Janis Elsts
[5] Fix | Delete
* Released under the MIT license. See license.txt for details.
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
if ( !class_exists('CookieAdminUpdateChecker_3_2', false) ):
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* A custom plugin update checker.
[12] Fix | Delete
*
[13] Fix | Delete
* @author Janis Elsts
[14] Fix | Delete
* @copyright 2016
[15] Fix | Delete
* @version 3.2
[16] Fix | Delete
* @access public
[17] Fix | Delete
*/
[18] Fix | Delete
class CookieAdminUpdateChecker_3_2 {
[19] Fix | Delete
public $metadataUrl = ''; //The URL of the plugin's metadata file.
[20] Fix | Delete
public $pluginAbsolutePath = ''; //Full path of the main plugin file.
[21] Fix | Delete
public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
[22] Fix | Delete
public $slug = ''; //Plugin slug.
[23] Fix | Delete
public $optionName = ''; //Where to store the update info.
[24] Fix | Delete
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
[25] Fix | Delete
[26] Fix | Delete
public $debugMode = false; //Set to TRUE to enable error reporting. Errors are raised using trigger_error()
[27] Fix | Delete
//and should be logged to the standard PHP error log.
[28] Fix | Delete
public $scheduler;
[29] Fix | Delete
[30] Fix | Delete
protected $upgraderStatus;
[31] Fix | Delete
[32] Fix | Delete
private $debugBarPlugin = null;
[33] Fix | Delete
private $cachedInstalledVersion = null;
[34] Fix | Delete
[35] Fix | Delete
private $metadataHost = ''; //The host component of $metadataUrl.
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Class constructor.
[39] Fix | Delete
*
[40] Fix | Delete
* @param string $metadataUrl The URL of the plugin's metadata file.
[41] Fix | Delete
* @param string $pluginFile Fully qualified path to the main plugin file.
[42] Fix | Delete
* @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
[43] Fix | Delete
* @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
[44] Fix | Delete
* @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
[45] Fix | Delete
* @param string $muPluginFile Optional. The plugin filename relative to the mu-plugins directory.
[46] Fix | Delete
*/
[47] Fix | Delete
public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = ''){
[48] Fix | Delete
$this->metadataUrl = $metadataUrl;
[49] Fix | Delete
$this->pluginAbsolutePath = $pluginFile;
[50] Fix | Delete
$this->pluginFile = plugin_basename($this->pluginAbsolutePath);
[51] Fix | Delete
$this->muPluginFile = $muPluginFile;
[52] Fix | Delete
$this->slug = $slug;
[53] Fix | Delete
$this->optionName = $optionName;
[54] Fix | Delete
$this->debugMode = (bool)(constant('WP_DEBUG'));
[55] Fix | Delete
[56] Fix | Delete
//If no slug is specified, use the name of the main plugin file as the slug.
[57] Fix | Delete
//For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
[58] Fix | Delete
if ( empty($this->slug) ){
[59] Fix | Delete
$this->slug = basename($this->pluginFile, '.php');
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
//Plugin slugs must be unique.
[63] Fix | Delete
$slugCheckFilter = 'puc_is_slug_in_use-' . $this->slug;
[64] Fix | Delete
$slugUsedBy = apply_filters($slugCheckFilter, false);
[65] Fix | Delete
if ( $slugUsedBy ) {
[66] Fix | Delete
$this->triggerError(sprintf(
[67] Fix | Delete
'Plugin slug "%s" is already in use by %s. Slugs must be unique.',
[68] Fix | Delete
htmlentities($this->slug),
[69] Fix | Delete
htmlentities($slugUsedBy)
[70] Fix | Delete
), E_USER_ERROR);
[71] Fix | Delete
}
[72] Fix | Delete
add_filter($slugCheckFilter, array($this, 'getAbsolutePath'));
[73] Fix | Delete
[74] Fix | Delete
[75] Fix | Delete
if ( empty($this->optionName) ){
[76] Fix | Delete
$this->optionName = 'external_updates-' . $this->slug;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
//Backwards compatibility: If the plugin is a mu-plugin but no $muPluginFile is specified, assume
[80] Fix | Delete
//it's the same as $pluginFile given that it's not in a subdirectory (WP only looks in the base dir).
[81] Fix | Delete
if ( (strpbrk($this->pluginFile, '/\\') === false) && $this->isUnknownMuPlugin() ) {
[82] Fix | Delete
$this->muPluginFile = $this->pluginFile;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
$this->scheduler = $this->createScheduler($checkPeriod);
[86] Fix | Delete
$this->upgraderStatus = new CookieAdmin_PucUpgraderStatus_3_2();
[87] Fix | Delete
[88] Fix | Delete
$this->installHooks();
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Create an instance of the scheduler.
[93] Fix | Delete
*
[94] Fix | Delete
* This is implemented as a method to make it possible for plugins to subclass the update checker
[95] Fix | Delete
* and substitute their own scheduler.
[96] Fix | Delete
*
[97] Fix | Delete
* @param int $checkPeriod
[98] Fix | Delete
* @return CookieAdmin_PucScheduler_3_2
[99] Fix | Delete
*/
[100] Fix | Delete
protected function createScheduler($checkPeriod) {
[101] Fix | Delete
return new CookieAdmin_PucScheduler_3_2($this, $checkPeriod);
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Install the hooks required to run periodic update checks and inject update info
[106] Fix | Delete
* into WP data structures.
[107] Fix | Delete
*
[108] Fix | Delete
* @return void
[109] Fix | Delete
*/
[110] Fix | Delete
protected function installHooks(){
[111] Fix | Delete
//Override requests for plugin information
[112] Fix | Delete
add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
[113] Fix | Delete
[114] Fix | Delete
//Insert our update info into the update array maintained by WP.
[115] Fix | Delete
add_filter('site_transient_update_plugins', array($this,'injectUpdate')); //WP 3.0+
[116] Fix | Delete
add_filter('transient_update_plugins', array($this,'injectUpdate')); //WP 2.8+
[117] Fix | Delete
add_filter('site_transient_update_plugins', array($this, 'injectTranslationUpdates'));
[118] Fix | Delete
[119] Fix | Delete
add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 2);
[120] Fix | Delete
add_action('admin_init', array($this, 'handleManualCheck'));
[121] Fix | Delete
add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
[122] Fix | Delete
[123] Fix | Delete
//Clear the version number cache when something - anything - is upgraded or WP clears the update cache.
[124] Fix | Delete
add_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
[125] Fix | Delete
add_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
[126] Fix | Delete
//Clear translation updates when WP clears the update cache.
[127] Fix | Delete
//This needs to be done directly because the library doesn't actually remove obsolete plugin updates,
[128] Fix | Delete
//it just hides them (see getUpdate()). We can't do that with translations - too much disk I/O.
[129] Fix | Delete
add_action('delete_site_transient_update_plugins', array($this, 'clearCachedTranslationUpdates'));
[130] Fix | Delete
[131] Fix | Delete
if ( did_action('plugins_loaded') ) {
[132] Fix | Delete
$this->initDebugBarPanel();
[133] Fix | Delete
} else {
[134] Fix | Delete
add_action('plugins_loaded', array($this, 'initDebugBarPanel'));
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
//Rename the update directory to be the same as the existing directory.
[138] Fix | Delete
add_filter('upgrader_source_selection', array($this, 'fixDirectoryName'), 10, 3);
[139] Fix | Delete
[140] Fix | Delete
//Enable language support (i18n).
[141] Fix | Delete
load_plugin_textdomain('plugin-update-checker', false, plugin_basename(dirname(__FILE__)) . '/languages');
[142] Fix | Delete
[143] Fix | Delete
//Allow HTTP requests to the metadata URL even if it's on a local host.
[144] Fix | Delete
$this->metadataHost = @parse_url($this->metadataUrl, PHP_URL_HOST);
[145] Fix | Delete
add_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10, 2);
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Explicitly allow HTTP requests to the metadata URL.
[150] Fix | Delete
*
[151] Fix | Delete
* WordPress has a security feature where the HTTP API will reject all requests that are sent to
[152] Fix | Delete
* another site hosted on the same server as the current site (IP match), a local host, or a local
[153] Fix | Delete
* IP, unless the host exactly matches the current site.
[154] Fix | Delete
*
[155] Fix | Delete
* This feature is opt-in (at least in WP 4.4). Apparently some people enable it.
[156] Fix | Delete
*
[157] Fix | Delete
* That can be a problem when you're developing your plugin and you decide to host the update information
[158] Fix | Delete
* on the same server as your test site. Update requests will mysteriously fail.
[159] Fix | Delete
*
[160] Fix | Delete
* We fix that by adding an exception for the metadata host.
[161] Fix | Delete
*
[162] Fix | Delete
* @param bool $allow
[163] Fix | Delete
* @param string $host
[164] Fix | Delete
* @return bool
[165] Fix | Delete
*/
[166] Fix | Delete
public function allowMetadataHost($allow, $host) {
[167] Fix | Delete
if ( strtolower($host) === strtolower($this->metadataHost) ) {
[168] Fix | Delete
return true;
[169] Fix | Delete
}
[170] Fix | Delete
return $allow;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Retrieve plugin info from the configured API endpoint.
[175] Fix | Delete
*
[176] Fix | Delete
* @uses wp_remote_get()
[177] Fix | Delete
*
[178] Fix | Delete
* @param array $queryArgs Additional query arguments to append to the request. Optional.
[179] Fix | Delete
* @return CookieAdminInfo_3_2
[180] Fix | Delete
*/
[181] Fix | Delete
public function requestInfo($queryArgs = array()){
[182] Fix | Delete
//Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
[183] Fix | Delete
$installedVersion = $this->getInstalledVersion();
[184] Fix | Delete
$queryArgs['installed_version'] = ($installedVersion !== null) ? $installedVersion : '';
[185] Fix | Delete
$queryArgs = apply_filters('puc_request_info_query_args-'.$this->slug, $queryArgs);
[186] Fix | Delete
[187] Fix | Delete
//Various options for the wp_remote_get() call. Plugins can filter these, too.
[188] Fix | Delete
$options = array(
[189] Fix | Delete
'timeout' => 10, //seconds
[190] Fix | Delete
'headers' => array(
[191] Fix | Delete
'Accept' => 'application/json'
[192] Fix | Delete
),
[193] Fix | Delete
);
[194] Fix | Delete
$options = apply_filters('puc_request_info_options-'.$this->slug, $options);
[195] Fix | Delete
[196] Fix | Delete
//The plugin info should be at 'http://your-api.com/url/here/$slug/info.json'
[197] Fix | Delete
$url = $this->metadataUrl;
[198] Fix | Delete
if ( !empty($queryArgs) ){
[199] Fix | Delete
$url = add_query_arg($queryArgs, $url);
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
$result = wp_remote_get(
[203] Fix | Delete
$url,
[204] Fix | Delete
$options
[205] Fix | Delete
);
[206] Fix | Delete
[207] Fix | Delete
//Try to parse the response
[208] Fix | Delete
$status = $this->validateApiResponse($result);
[209] Fix | Delete
$pluginInfo = null;
[210] Fix | Delete
if ( !is_wp_error($status) ){
[211] Fix | Delete
$pluginInfo = CookieAdminInfo_3_2::fromJson($result['body']);
[212] Fix | Delete
if ( $pluginInfo !== null ) {
[213] Fix | Delete
$pluginInfo->filename = $this->pluginFile;
[214] Fix | Delete
$pluginInfo->slug = $this->slug;
[215] Fix | Delete
}
[216] Fix | Delete
} else {
[217] Fix | Delete
$this->triggerError(
[218] Fix | Delete
sprintf('The URL %s does not point to a valid plugin metadata file. ', $url)
[219] Fix | Delete
. $status->get_error_message(),
[220] Fix | Delete
E_USER_WARNING
[221] Fix | Delete
);
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
$pluginInfo = apply_filters('puc_request_info_result-'.$this->slug, $pluginInfo, $result);
[225] Fix | Delete
return $pluginInfo;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Check if $result is a successful update API response.
[230] Fix | Delete
*
[231] Fix | Delete
* @param array|WP_Error $result
[232] Fix | Delete
* @return true|WP_Error
[233] Fix | Delete
*/
[234] Fix | Delete
private function validateApiResponse($result) {
[235] Fix | Delete
if ( is_wp_error($result) ) { /** @var WP_Error $result */
[236] Fix | Delete
return new WP_Error($result->get_error_code(), 'WP HTTP Error: ' . $result->get_error_message());
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
if ( !isset($result['response']['code']) ) {
[240] Fix | Delete
return new WP_Error('puc_no_response_code', 'wp_remote_get() returned an unexpected result.');
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( $result['response']['code'] !== 200 ) {
[244] Fix | Delete
return new WP_Error(
[245] Fix | Delete
'puc_unexpected_response_code',
[246] Fix | Delete
'HTTP response code is ' . $result['response']['code'] . ' (expected: 200)'
[247] Fix | Delete
);
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
if ( empty($result['body']) ) {
[251] Fix | Delete
return new WP_Error('puc_empty_response', 'The metadata file appears to be empty.');
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
return true;
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Retrieve the latest update (if any) from the configured API endpoint.
[259] Fix | Delete
*
[260] Fix | Delete
* @uses CookieAdminUpdateChecker::requestInfo()
[261] Fix | Delete
*
[262] Fix | Delete
* @return CookieAdminUpdate_3_2 An instance of CookieAdminUpdate, or NULL when no updates are available.
[263] Fix | Delete
*/
[264] Fix | Delete
public function requestUpdate(){
[265] Fix | Delete
//For the sake of simplicity, this function just calls requestInfo()
[266] Fix | Delete
//and transforms the result accordingly.
[267] Fix | Delete
$pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
[268] Fix | Delete
if ( $pluginInfo == null ){
[269] Fix | Delete
return null;
[270] Fix | Delete
}
[271] Fix | Delete
$update = CookieAdminUpdate_3_2::fromCookieAdminInfo($pluginInfo);
[272] Fix | Delete
[273] Fix | Delete
//Keep only those translation updates that apply to this site.
[274] Fix | Delete
$update->translations = $this->filterApplicableTranslations($update->translations);
[275] Fix | Delete
[276] Fix | Delete
return $update;
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Filter a list of translation updates and return a new list that contains only updates
[281] Fix | Delete
* that apply to the current site.
[282] Fix | Delete
*
[283] Fix | Delete
* @param array $translations
[284] Fix | Delete
* @return array
[285] Fix | Delete
*/
[286] Fix | Delete
private function filterApplicableTranslations($translations) {
[287] Fix | Delete
$languages = array_flip(array_values(get_available_languages()));
[288] Fix | Delete
$installedTranslations = wp_get_installed_translations('plugins');
[289] Fix | Delete
if ( isset($installedTranslations[$this->slug]) ) {
[290] Fix | Delete
$installedTranslations = $installedTranslations[$this->slug];
[291] Fix | Delete
} else {
[292] Fix | Delete
$installedTranslations = array();
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
$applicableTranslations = array();
[296] Fix | Delete
foreach($translations as $translation) {
[297] Fix | Delete
//Does it match one of the available core languages?
[298] Fix | Delete
$isApplicable = array_key_exists($translation->language, $languages);
[299] Fix | Delete
//Is it more recent than an already-installed translation?
[300] Fix | Delete
if ( isset($installedTranslations[$translation->language]) ) {
[301] Fix | Delete
$updateTimestamp = strtotime($translation->updated);
[302] Fix | Delete
$installedTimestamp = strtotime($installedTranslations[$translation->language]['PO-Revision-Date']);
[303] Fix | Delete
$isApplicable = $updateTimestamp > $installedTimestamp;
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
if ( $isApplicable ) {
[307] Fix | Delete
$applicableTranslations[] = $translation;
[308] Fix | Delete
}
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
return $applicableTranslations;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Get the currently installed version of the plugin.
[316] Fix | Delete
*
[317] Fix | Delete
* @return string Version number.
[318] Fix | Delete
*/
[319] Fix | Delete
public function getInstalledVersion(){
[320] Fix | Delete
if ( isset($this->cachedInstalledVersion) ) {
[321] Fix | Delete
return $this->cachedInstalledVersion;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
$pluginHeader = $this->getPluginHeader();
[325] Fix | Delete
if ( isset($pluginHeader['Version']) ) {
[326] Fix | Delete
$this->cachedInstalledVersion = $pluginHeader['Version'];
[327] Fix | Delete
return $pluginHeader['Version'];
[328] Fix | Delete
} else {
[329] Fix | Delete
//This can happen if the filename points to something that is not a plugin.
[330] Fix | Delete
$this->triggerError(
[331] Fix | Delete
sprintf(
[332] Fix | Delete
"Can't to read the Version header for '%s'. The filename is incorrect or is not a plugin.",
[333] Fix | Delete
$this->pluginFile
[334] Fix | Delete
),
[335] Fix | Delete
E_USER_WARNING
[336] Fix | Delete
);
[337] Fix | Delete
return null;
[338] Fix | Delete
}
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Get plugin's metadata from its file header.
[343] Fix | Delete
*
[344] Fix | Delete
* @return array
[345] Fix | Delete
*/
[346] Fix | Delete
protected function getPluginHeader() {
[347] Fix | Delete
if ( !is_file($this->pluginAbsolutePath) ) {
[348] Fix | Delete
//This can happen if the plugin filename is wrong.
[349] Fix | Delete
$this->triggerError(
[350] Fix | Delete
sprintf(
[351] Fix | Delete
"Can't to read the plugin header for '%s'. The file does not exist.",
[352] Fix | Delete
$this->pluginFile
[353] Fix | Delete
),
[354] Fix | Delete
E_USER_WARNING
[355] Fix | Delete
);
[356] Fix | Delete
return array();
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
if ( !function_exists('get_plugin_data') ){
[360] Fix | Delete
/** @noinspection PhpIncludeInspection */
[361] Fix | Delete
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
[362] Fix | Delete
}
[363] Fix | Delete
return get_plugin_data($this->pluginAbsolutePath, false, false);
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
/**
[367] Fix | Delete
* Check for plugin updates.
[368] Fix | Delete
* The results are stored in the DB option specified in $optionName.
[369] Fix | Delete
*
[370] Fix | Delete
* @return CookieAdminUpdate_3_2|null
[371] Fix | Delete
*/
[372] Fix | Delete
public function checkForUpdates(){
[373] Fix | Delete
$installedVersion = $this->getInstalledVersion();
[374] Fix | Delete
//Fail silently if we can't find the plugin or read its header.
[375] Fix | Delete
if ( $installedVersion === null ) {
[376] Fix | Delete
$this->triggerError(
[377] Fix | Delete
sprintf('Skipping update check for %s - installed version unknown.', $this->pluginFile),
[378] Fix | Delete
E_USER_WARNING
[379] Fix | Delete
);
[380] Fix | Delete
return null;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
$state = $this->getUpdateState();
[384] Fix | Delete
if ( empty($state) ){
[385] Fix | Delete
$state = new stdClass;
[386] Fix | Delete
$state->lastCheck = 0;
[387] Fix | Delete
$state->checkedVersion = '';
[388] Fix | Delete
$state->update = null;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
$state->lastCheck = time();
[392] Fix | Delete
$state->checkedVersion = $installedVersion;
[393] Fix | Delete
$this->setUpdateState($state); //Save before checking in case something goes wrong
[394] Fix | Delete
[395] Fix | Delete
$state->update = $this->requestUpdate();
[396] Fix | Delete
$this->setUpdateState($state);
[397] Fix | Delete
[398] Fix | Delete
return $this->getUpdate();
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
/**
[402] Fix | Delete
* Load the update checker state from the DB.
[403] Fix | Delete
*
[404] Fix | Delete
* @return stdClass|null
[405] Fix | Delete
*/
[406] Fix | Delete
public function getUpdateState() {
[407] Fix | Delete
$state = get_site_option($this->optionName, null);
[408] Fix | Delete
if ( empty($state) || !is_object($state)) {
[409] Fix | Delete
$state = null;
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
if ( isset($state, $state->update) && is_object($state->update) ) {
[413] Fix | Delete
$state->update = CookieAdminUpdate_3_2::fromObject($state->update);
[414] Fix | Delete
}
[415] Fix | Delete
return $state;
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
[419] Fix | Delete
/**
[420] Fix | Delete
* Persist the update checker state to the DB.
[421] Fix | Delete
*
[422] Fix | Delete
* @param StdClass $state
[423] Fix | Delete
* @return void
[424] Fix | Delete
*/
[425] Fix | Delete
private function setUpdateState($state) {
[426] Fix | Delete
if ( isset($state->update) && is_object($state->update) && method_exists($state->update, 'toStdClass') ) {
[427] Fix | Delete
$update = $state->update; /** @var CookieAdminUpdate_3_2 $update */
[428] Fix | Delete
$state->update = $update->toStdClass();
[429] Fix | Delete
}
[430] Fix | Delete
update_site_option($this->optionName, $state);
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
/**
[434] Fix | Delete
* Reset update checker state - i.e. last check time, cached update data and so on.
[435] Fix | Delete
*
[436] Fix | Delete
* Call this when your plugin is being uninstalled, or if you want to
[437] Fix | Delete
* clear the update cache.
[438] Fix | Delete
*/
[439] Fix | Delete
public function resetUpdateState() {
[440] Fix | Delete
delete_site_option($this->optionName);
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Intercept plugins_api() calls that request information about our plugin and
[445] Fix | Delete
* use the configured API endpoint to satisfy them.
[446] Fix | Delete
*
[447] Fix | Delete
* @see plugins_api()
[448] Fix | Delete
*
[449] Fix | Delete
* @param mixed $result
[450] Fix | Delete
* @param string $action
[451] Fix | Delete
* @param array|object $args
[452] Fix | Delete
* @return mixed
[453] Fix | Delete
*/
[454] Fix | Delete
public function injectInfo($result, $action = null, $args = null){
[455] Fix | Delete
$relevant = ($action == 'plugin_information') && isset($args->slug) && (
[456] Fix | Delete
($args->slug == $this->slug) || ($args->slug == dirname($this->pluginFile))
[457] Fix | Delete
);
[458] Fix | Delete
if ( !$relevant ) {
[459] Fix | Delete
return $result;
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
$pluginInfo = $this->requestInfo();
[463] Fix | Delete
$pluginInfo = apply_filters('puc_pre_inject_info-' . $this->slug, $pluginInfo);
[464] Fix | Delete
if ( $pluginInfo ) {
[465] Fix | Delete
return $pluginInfo->toWpFormat();
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
return $result;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
/**
[472] Fix | Delete
* Insert the latest update (if any) into the update list maintained by WP.
[473] Fix | Delete
*
[474] Fix | Delete
* @param StdClass $updates Update list.
[475] Fix | Delete
* @return StdClass Modified update list.
[476] Fix | Delete
*/
[477] Fix | Delete
public function injectUpdate($updates){
[478] Fix | Delete
//Is there an update to insert?
[479] Fix | Delete
$update = $this->getUpdate();
[480] Fix | Delete
[481] Fix | Delete
//No update notifications for mu-plugins unless explicitly enabled. The MU plugin file
[482] Fix | Delete
//is usually different from the main plugin file so the update wouldn't show up properly anyway.
[483] Fix | Delete
if ( $this->isUnknownMuPlugin() ) {
[484] Fix | Delete
$update = null;
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
if ( !empty($update) ) {
[488] Fix | Delete
//Let plugins filter the update info before it's passed on to WordPress.
[489] Fix | Delete
$update = apply_filters('puc_pre_inject_update-' . $this->slug, $update);
[490] Fix | Delete
$updates = $this->addUpdateToList($updates, $update);
[491] Fix | Delete
} else {
[492] Fix | Delete
//Clean up any stale update info.
[493] Fix | Delete
$updates = $this->removeUpdateFromList($updates);
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
return $updates;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function