# flywp/1.8.0/includes/Api/Themes.php

FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel, version 1.8.0. 87 lines.

- Page: https://pluginprobe.com/plugins/flywp/1.8.0/code/includes/Api/Themes.php
- Raw: https://pluginprobe.com/plugins/flywp/1.8.0/raw/includes/Api/Themes.php
- Modified: 2023-12-28T09:58:22+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/flywp/1.8.0/code/includes/Api/Themes.php#L10-L20`.

```php
<?php

namespace FlyWP\Api;

class Themes {

    /**
     * API constructor.
     */
    public function __construct() {
        flywp()->router->get( 'themes', [ $this, 'respond' ] );
    }

    /**
     * Handle request.
     *
     * @return void
     */
    public function respond( $args ) {
        $response = [];

        // Update the update cache if requested.
        if ( isset( $args['force'] ) && $args['force'] === 'true' ) {
            wp_update_themes();
        }

        $themes  = wp_get_themes();
        $updates = get_site_transient( 'update_themes' );

        foreach ( $themes as $key => $theme ) {
            $update = $this->get_update( $key, $updates );

            $response[] = [
                'name'                 => $key,
                'version'              => $theme->get( 'Version' ),
                'description'          => $theme->get( 'Description' ),
                'theme_uri'            => $theme->get( 'ThemeURI' ),
                'author'               => $theme->get( 'Author' ),
                'author_uri'           => $theme->get( 'AuthorURI' ),
                'status'               => $this->get_status( $theme ),
                'update_available'     => $update ? true : false,
                'new_version'          => $update && isset( $update['new_version'] ) ? $update['new_version'] : null,
            ];
        }

        wp_send_json( $response );
    }

    /**
     * Get theme active status.
     *
     * @param string $file
     *
     * @return string
     */
    private function get_status( $theme ) {
        if ( $theme->get_stylesheet_directory() === get_stylesheet_directory() ) {
            return 'active';
        }

        if ( $theme->get_stylesheet_directory() === get_stylesheet_directory() ) {
            return 'parent';
        }

        return 'inactive';
    }

    /**
     * Check if a theme has an update available.
     *
     * @param string $key
     * @param object $updates
     *
     * @return array|bool
     */
    private function get_update( $key, $updates ) {
        if ( isset( $updates->response[ $key ] ) ) {
            return [
                'new_version' => $updates->response[ $key ]['new_version'],
                'package'     => $updates->response[ $key ]['package'],
            ];
        }

        return false;
    }
}

```
