/** * @param Theme_Upgrader $upgrader * @param array $extra */ public function hooks_theme_install_or_update($upgrader, $extra) { if (!isset($extra['type']) || 'theme' !== $extra['type']) { return; } if ('install' === $extra['action']) { $slug = $upgrader->theme_info(); if (!$slug) { return; } wp_clean_themes_cache(); $theme = wp_get_theme($slug); $name = $theme->name; $version = $theme->version; aal_insert_log(array('action' => 'installed', 'object_type' => 'Theme', 'object_name' => $name, 'object_subtype' => $version)); } if ('update' === $extra['action']) { 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']; $version = $theme_data['Version']; aal_insert_log(array('action' => 'updated', 'object_type' => 'Theme', 'object_name' => $name, 'object_subtype' => $version)); } } }
/** * Theme install of update * * @since 0.1.0 * * @param Theme_Upgrader $upgrader * @param array $extra */ public function theme_install_or_update($upgrader, $extra) { // Bail if not a theme if (!isset($extra['type']) || 'theme' !== $extra['type']) { return; } // Install if ('install' === $extra['action']) { // Bail if no theme found $slug = $upgrader->theme_info(); if (empty($slug)) { return; } wp_clean_themes_cache(); $theme = wp_get_theme($slug); $name = $theme->name; $version = $theme->version; // Insert activity wp_insert_user_activity(array('object_type' => $this->object_type, 'object_subtype' => $version, 'object_name' => $name, 'action' => 'install')); // Update } elseif ('update' === $extra['action']) { // Get theme slugs if (isset($extra['bulk']) && true == $extra['bulk']) { $slugs = $extra['themes']; } else { $slugs = array($upgrader->skin->theme); } // Activity for each 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']; $version = $theme_data['Version']; // Insert activity wp_insert_user_activity(array('object_type' => $this->object_type, 'object_subtype' => $version, 'object_name' => $name, 'action' => 'update')); } } }
private function install_themes($themes) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once ABSPATH . 'wp-admin/includes/theme.php'; require_once $GLOBALS['ithemes_sync_path'] . '/upgrader-skin.php'; $upgrader = new Theme_Upgrader(new Ithemes_Sync_Upgrader_Skin()); $results = array(); foreach ((array) $themes as $theme) { Ithemes_Sync_Functions::set_time_limit(300); if (preg_match('{^(http|https|ftp)://}i', $theme)) { $result = $upgrader->install($theme); } else { $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false))); if (is_wp_error($api)) { $result = $api; } else { $result = $upgrader->install($api->download_link); } } if (is_wp_error($result)) { $results[$theme]['error'] = array('error_code' => $result->get_error_code(), 'error_details' => $result->get_error_message()); } else { $results[$theme]['result'] = $result; $theme_info = $upgrader->theme_info(); $results[$theme]['name'] = $theme_info->get('Name'); $results[$theme]['version'] = $theme_info->get('Version'); if (is_object($theme_info) && is_callable(array($theme_info, 'get_stylesheet'))) { $results[$theme]['slug'] = basename($theme_info->get_stylesheet()); } else { if (isset($upgrader->result) && !empty($upgrader->result['destination_name'])) { $results[$theme]['slug'] = $upgrader->result['destination_name']; } } if (true === $result) { $results[$theme]['success'] = true; } } } Ithemes_Sync_Functions::refresh_theme_updates(); return $results; }