PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 0.3
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v0.3
1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 All 26 releases
flywp / includes / Api / Themes.php

Themes.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 0.3, at includes/Api/Themes.php

82 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP\Api;
4
5 class Themes {
6
7 /**
8 * API constructor.
9 */
10 public function __construct() {
11 flywp()->router->get( 'themes', [ $this, 'respond' ] );
12 }
13
14 /**
15 * Handle request.
16 *
17 * @return void
18 */
19 public function respond( $args ) {
20 $response = [];
21
22 $themes = wp_get_themes();
23 $updates = get_site_transient( 'update_themes' );
24
25 foreach ( $themes as $key => $theme ) {
26 $update = $this->get_update( $key, $updates );
27
28 $response[] = [
29 'name' => $key,
30 'version' => $theme->get( 'Version' ),
31 'description' => $theme->get( 'Description' ),
32 'theme_uri' => $theme->get( 'ThemeURI' ),
33 'author' => $theme->get( 'Author' ),
34 'author_uri' => $theme->get( 'AuthorURI' ),
35 'status' => $this->get_status( $theme ),
36 'update_available' => $update ? true : false,
37 'new_version' => $update ? $update['new_version'] : null,
38 ];
39 }
40
41 wp_send_json( $response );
42 }
43
44 /**
45 * Get theme active status.
46 *
47 * @param string $file
48 *
49 * @return string
50 */
51 private function get_status( $theme ) {
52 if ( $theme->get_stylesheet_directory() === get_stylesheet_directory() ) {
53 return 'active';
54 }
55
56 if ( $theme->get_stylesheet_directory() === get_stylesheet_directory() ) {
57 return 'parent';
58 }
59
60 return 'inactive';
61 }
62
63 /**
64 * Check if a theme has an update available.
65 *
66 * @param string $key
67 * @param object $updates
68 *
69 * @return array|bool
70 */
71 private function get_update( $key, $updates ) {
72 if ( isset( $updates->response[ $key ] ) ) {
73 return [
74 'new_version' => $updates->response[ $key ]['new_version'],
75 'package' => $updates->response[ $key ]['package'],
76 ];
77 }
78
79 return false;
80 }
81 }
82