本文整理汇总了PHP中WP_Upgrader::theme_info方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Upgrader::theme_info方法的具体用法?PHP WP_Upgrader::theme_info怎么用?PHP WP_Upgrader::theme_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Upgrader
的用法示例。
在下文中一共展示了WP_Upgrader::theme_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callback_upgrader_process_complete
/**
* Log plugin installations
*
* @action transition_post_status
*
* @param \WP_Upgrader $upgrader
* @param array $extra
*
* @return bool
*/
public function callback_upgrader_process_complete($upgrader, $extra)
{
$logs = array();
$success = !is_wp_error($upgrader->skin->result);
$error = null;
if (!$success) {
$errors = $upgrader->skin->result->errors;
list($error) = reset($errors);
}
// This would have failed down the road anyway
if (!isset($extra['type'])) {
return false;
}
$type = $extra['type'];
$action = $extra['action'];
if (!in_array($type, array('plugin', 'theme'))) {
return false;
}
if ('install' === $action) {
if ('plugin' === $type) {
$path = $upgrader->plugin_info();
if (!$path) {
return false;
}
$data = get_plugin_data($upgrader->skin->result['local_destination'] . '/' . $path);
$slug = $upgrader->result['destination_name'];
$name = $data['Name'];
$version = $data['Version'];
} else {
// theme
$slug = $upgrader->theme_info();
if (!$slug) {
return false;
}
wp_clean_themes_cache();
$theme = wp_get_theme($slug);
$name = $theme->name;
$version = $theme->version;
}
$action = 'installed';
$message = _x('Installed %1$s: %2$s %3$s', 'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', 'stream');
$logs[] = compact('slug', 'name', 'version', 'message', 'action');
} elseif ('update' === $action) {
$action = 'updated';
$message = _x('Updated %1$s: %2$s %3$s', 'Plugin/theme update. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', 'stream');
if ('plugin' === $type) {
if (isset($extra['bulk']) && true === $extra['bulk']) {
$slugs = $extra['plugins'];
} else {
$slugs = array($upgrader->skin->plugin);
}
$_plugins = $this->get_plugins();
foreach ($slugs as $slug) {
$plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $slug);
$name = $plugin_data['Name'];
$version = $plugin_data['Version'];
$old_version = $_plugins[$slug]['Version'];
$logs[] = compact('slug', 'name', 'old_version', 'version', 'message', 'action');
}
} else {
// theme
if (isset($extra['bulk']) && true === $extra['bulk']) {
$slugs = $extra['themes'];
} else {
$slugs = array($upgrader->skin->theme);
}
foreach ($slugs as $slug) {
$theme = wp_get_theme($slug);
$stylesheet = $theme['Stylesheet Dir'] . '/style.css';
$theme_data = get_file_data($stylesheet, array('Version' => 'Version'));
$name = $theme['Name'];
$old_version = $theme['Version'];
$version = $theme_data['Version'];
$logs[] = compact('slug', 'name', 'old_version', 'version', 'message', 'action');
}
}
} else {
return false;
}
$context = $type . 's';
foreach ($logs as $log) {
$name = isset($log['name']) ? $log['name'] : null;
$version = isset($log['version']) ? $log['version'] : null;
$slug = isset($log['slug']) ? $log['slug'] : null;
$old_version = isset($log['old_version']) ? $log['old_version'] : null;
$message = isset($log['message']) ? $log['message'] : null;
$action = isset($log['action']) ? $log['action'] : null;
$this->log($message, compact('type', 'name', 'version', 'slug', 'success', 'error', 'old_version'), null, $context, $action);
}
return true;
//.........这里部分代码省略.........