PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 4.0.0
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v4.0.0
4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / data / utils / class-theme-installer.php
superb-blocks / src / data / utils Last commit date
wizard 1 month ago class-addons-template-util.php 1 month ago class-allowed-template-html-util.php 1 month ago class-base-exception.php 1 month ago class-cache-constants.php 1 month ago class-cache-exception.php 1 month ago class-key-exception.php 1 month ago class-keytypes.php 1 month ago class-option-exception.php 1 month ago class-quiet-skin.php 1 month ago class-request-exception.php 1 month ago class-script-translations.php 1 month ago class-settings-exception.php 1 month ago class-theme-installer-exception.php 1 month ago class-theme-installer.php 1 month ago
class-theme-installer.php
80 lines
1 <?php
2
3 namespace SuperbAddons\Data\Utils;
4
5 defined('ABSPATH') || exit();
6
7 use Exception;
8 use SuperbAddons\Data\Utils\QuietSkin;
9
10 require_once(ABSPATH . 'wp-admin/includes/theme-install.php');
11 require_once(ABSPATH . 'wp-admin/includes/file.php');
12 require_once(ABSPATH . 'wp-admin/includes/misc.php');
13 require_once(ABSPATH . 'wp-admin/includes/theme.php');
14 require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
15
16 class ThemeInstaller
17 {
18 public static function Install($theme)
19 {
20 $activated = self::ActivateTheme($theme);
21 if ($activated) {
22 return true;
23 }
24
25 $themes_api = \themes_api(
26 'theme_information',
27 array(
28 'slug' => $theme,
29 'fields' => array(
30 'description' => false,
31 'sections' => false,
32 'requires' => false,
33 'rating' => false,
34 'ratings' => false,
35 'downloaded' => false,
36 'last_updated' => false,
37 'added' => false,
38 'tags' => false,
39 'compatibility' => false,
40 'homepage' => false,
41 'donate_link' => false,
42 ),
43 )
44 );
45
46 if (is_wp_error($themes_api)) {
47 return false;
48 }
49
50 $upgrader = new \Theme_Upgrader(new QuietSkin());
51
52 $installation_result = $upgrader->install($themes_api->download_link);
53
54 if (!$installation_result || is_wp_error($installation_result)) {
55 return false;
56 }
57
58 return self::ActivateTheme($theme);
59 }
60
61 private static function ActivateTheme($theme_slug)
62 {
63 // Activate theme
64 $theme = wp_get_theme($theme_slug);
65 if ($theme->exists()) {
66 if (function_exists('validate_theme_requirements')) {
67 $validated = validate_theme_requirements($theme_slug);
68 if (is_wp_error($validated)) {
69 throw new ThemeInstallerException(esc_html(wp_strip_all_tags($validated->get_error_message())));
70 }
71 }
72
73 switch_theme($theme->get_stylesheet());
74 return true;
75 }
76
77 return false;
78 }
79 }
80