$skin->plugin_info) ) { //This case is tricky because Bulk_Plugin_Upgrader_Skin (etc) doesn't actually store the plugin //filename anywhere. Instead, it has the plugin headers in $plugin_info. So the best we can //do is compare those headers to the headers of installed plugins. $pluginFile = $this->identifyPluginByHeaders($skin->plugin_info); } if ( $pluginFile !== null ) { return array('plugin', $pluginFile); } elseif ( $themeDirectoryName !== null ) { return array('theme', $themeDirectoryName); } return array(null, null); } /** * Identify an installed plugin based on its headers. * * @param array $searchHeaders The plugin file header to look for. * @return string|null Plugin basename ("foo/bar.php"), or NULL if we can't identify the plugin. */ private function identifyPluginByHeaders($searchHeaders) { if ( !function_exists('get_plugins') ){ /** @noinspection PhpIncludeInspection */ require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); } $installedPlugins = get_plugins(); $matches = array(); foreach($installedPlugins as $pluginBasename => $headers) { $diff1 = array_diff_assoc($headers, $searchHeaders); $diff2 = array_diff_assoc($searchHeaders, $headers); if ( empty($diff1) && empty($diff2) ) { $matches[] = $pluginBasename; } } //It's possible (though very unlikely) that there could be two plugins with identical //headers. In that case, we can't unambiguously identify the plugin that's being upgraded. if ( count($matches) !== 1 ) { return null; } return reset($matches); } /** * @access private * * @param mixed $input * @param array $hookExtra * @return mixed Returns $input unaltered. */ public function setUpgradedThing($input, $hookExtra) { if ( !empty($hookExtra['plugin']) && is_string($hookExtra['plugin']) ) { $this->currentId = $hookExtra['plugin']; $this->currentType = 'plugin'; } elseif ( !empty($hookExtra['theme']) && is_string($hookExtra['theme']) ) { $this->currentId = $hookExtra['theme']; $this->currentType = 'theme'; } else { $this->currentType = null; $this->currentId = null; } return $input; } /** * @access private * * @param array $options * @return array */ public function setUpgradedPluginFromOptions($options) { if ( isset($options['hook_extra']['plugin']) && is_string($options['hook_extra']['plugin']) ) { $this->currentType = 'plugin'; $this->currentId = $options['hook_extra']['plugin']; } else { $this->currentType = null; $this->currentId = null; } return $options; } /** * @access private * * @param mixed $input * @return mixed Returns $input unaltered. */ public function clearUpgradedThing($input = null) { $this->currentId = null; $this->currentType = null; return $input; } } endif;