PluginProbe
ManageWP Worker / trunk
ManageWP Worker vtrunk
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / WordPress / Provider / Theme.php

Theme.php in ManageWP Worker trunk, at src/MWP/WordPress/Provider/Theme.php

88 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_WordPress_Provider_Theme implements MWP_WordPress_Provider_Interface
12 {
13 const STATUS_ACTIVE = 'active';
14
15 const STATUS_INACTIVE = 'inactive';
16
17 const STATUS_INHERITED = 'inherited';
18
19 private $context;
20
21 public function __construct(MWP_WordPress_Context $context)
22 {
23 $this->context = $context;
24 }
25
26 public function fetch(array $options = array())
27 {
28 $rawThemes = $this->context->getThemes();
29 $currentTheme = $this->context->getCurrentTheme();
30 $activeThemeSlug = $currentTheme['Stylesheet'];
31 $themes = array();
32
33 $themeInfo = array(
34 'name' => 'Name',
35 // Absolute path to theme directory.
36 'root' => 'Theme Root',
37 // Absolute URL to theme directory.
38 'rootUri' => 'Theme Root URI',
39
40 'version' => 'Version',
41 'description' => 'Description',
42 'author' => 'Author',
43 'authorUri' => 'Author URI',
44 'status' => 'Status',
45 'parent' => 'Parent Theme',
46 );
47
48 if (empty($options['fetchDescription'])) {
49 unset($themeInfo['description']);
50 }
51
52 foreach ($rawThemes as $rawTheme) {
53 $theme = array(
54 // Theme directory, followed by slash and slug, to keep it consistent with plugin info; ie. "twentytwelve/twentytwelve".
55 'basename' => $rawTheme['Template'].'/'.$rawTheme['Stylesheet'],
56 // A.k.a. "stylesheet", for some reason. This is the theme identifier; ie. "twentytwelve".
57 'slug' => $rawTheme['Stylesheet'],
58 'children' => array(),
59 );
60
61 foreach ($themeInfo as $property => $info) {
62 if (empty($rawTheme[$info])) {
63 $theme[$property] = null;
64 continue;
65 }
66
67 $theme[$property] = $this->context->seemsUtf8($rawTheme[$info]) ? $rawTheme[$info] : utf8_encode($rawTheme[$info]);
68 }
69
70 // Check if this is the active theme
71 $theme['active'] = ($theme['slug'] === $activeThemeSlug);
72
73 $themes[$theme['name']] = $theme;
74 }
75
76 foreach ($themes as &$theme) {
77 if (empty($theme['parent']) || empty($themes[$theme['parent']])) {
78 continue;
79 }
80
81 $themes[$theme['parent']]['children'][] = $theme['slug'];
82 $theme['parent'] = $themes[$theme['parent']]['slug'];
83 }
84
85 return array_values($themes);
86 }
87 }
88