PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.5.2
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.5.2
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 1.5.2, at includes/Api/Themes.php

87 lines 2.3 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 // Update the update cache if requested.
23 if ( isset( $args['force'] ) && $args['force'] === 'true' ) {
24 wp_update_themes();
25 }
26
27 $themes = wp_get_themes();
28 $updates = get_site_transient( 'update_themes' );
29
30 foreach ( $themes as $key => $theme ) {
31 $update = $this->get_update( $key, $updates );
32
33 $response[] = [
34 'name' => $key,
35 'version' => $theme->get( 'Version' ),
36 'description' => $theme->get( 'Description' ),
37 'theme_uri' => $theme->get( 'ThemeURI' ),
38 'author' => $theme->get( 'Author' ),
39 'author_uri' => $theme->get( 'AuthorURI' ),
40 'status' => $this->get_status( $theme ),
41 'update_available' => $update ? true : false,
42 'new_version' => $update && isset( $update['new_version'] ) ? $update['new_version'] : null,
43 ];
44 }
45
46 wp_send_json( $response );
47 }
48
49 /**
50 * Get theme active status.
51 *
52 * @param string $file
53 *
54 * @return string
55 */
56 private function get_status( $theme ) {
57 if ( $theme->get_stylesheet_directory() === get_stylesheet_directory() ) {
58 return 'active';
59 }
60
61 if ( $theme->get_stylesheet_directory() === get_stylesheet_directory() ) {
62 return 'parent';
63 }
64
65 return 'inactive';
66 }
67
68 /**
69 * Check if a theme has an update available.
70 *
71 * @param string $key
72 * @param object $updates
73 *
74 * @return array|bool
75 */
76 private function get_update( $key, $updates ) {
77 if ( isset( $updates->response[ $key ] ) ) {
78 return [
79 'new_version' => $updates->response[ $key ]['new_version'],
80 'package' => $updates->response[ $key ]['package'],
81 ];
82 }
83
84 return false;
85 }
86 }
87