*/ class Wp_Database_Tools_Themes { /** * Plugins in the installation. * * @since 1.0.0 * @access protected * @var array $data The general data of database. */ protected $themes; public function __construct() { $this->init(); } protected function init() { $this->format_themes(); } protected function format_themes() { $themes_data = array(); foreach ( wp_get_themes() as $key => $theme ) { // Check marketplace. $marketplace = 'unknown'; if ( str_contains( $theme['AuthorURI'], 'codecanyon' ) || str_contains( $theme['ThemeURI'], 'codecanyon' ) ) { $marketplace = 'https://codecanyon.net'; } if ( str_contains( $theme['AuthorURI'], 'themeforest' ) || str_contains( $theme['ThemeURI'], 'themeforest' ) ) { $marketplace = 'https://themeforest.net'; } if ( str_contains( $theme['AuthorURI'], 'wordpress.org' ) || str_contains( $theme['ThemeURI'], 'wordpress.org' ) ) { $marketplace = 'https://wordpress.org'; } $themes_data[ $key ]['name'] = $theme->get( 'Name' ) ?? $key; $themes_data[ $key ]['marketplace'] = $marketplace; $themes_data[ $key ]['slug'] = $key; $themes_data[ $key ]['initials'] = $this->get_initials( $key ); $themes_data[ $key ]['status'] = $this->get_theme_status( $key ); $themes_data[ $key ]['author'] = $theme->get( 'Author' ) ?? null; $themes_data[ $key ]['author_name'] = $theme->get( 'Author' ) ?? null; $themes_data[ $key ]['author_url'] = $theme->get( 'ThemeURI' ) ?? null; $themes_data[ $key ]['version'] = $theme['Version'] ?? null; } $this->themes = $themes_data; } /** * Get's the activation status for a plugin. * * @since 5.5.0 * * @param string $plugin The plugin file to check. * @return string 'active' . 'inactive' or 'uninstalled'. * @author Patricia Alvarez */ protected function get_theme_status( $theme ) { if ( $theme === get_option( 'template' ) ) { return 'active'; } elseif ( file_exists( get_theme_root() . '/' . $theme ) ) { return 'inactive'; } } /** * Get's the initials. * * @since 1.0.0 * * @param string $plugin The plugin file to check. * @return string 'active' . 'inactive' or 'uninstalled'. * @author Patricia Alvarez */ public function get_initials( $input ) { $words = preg_split( '/[\s,_-]+/', $input ); $initials = ''; foreach ( $words as $input => $word ) { $initials .= substr( $word, 0, 1 ); } return $initials; } /** * Get's the activation status for a plugin. * * @since 5.5.0 * * @return string 'active' . 'inactive' or 'uninstalled'. * @author Patricia Alvarez */ public function get_themes() { return $this->themes; } }