-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththeme-checker.php
59 lines (54 loc) · 2.53 KB
/
theme-checker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Plugin Name: WordPress Theme Checker
* Description: Allows you to use a shortcode to display a form where users can enter a WordPress website URL and check the active theme name on that website, including information from the WordPress.org repository if available.
* Version: 1.0
* Author: Stefan Pejcic
*/
function theme_checker_shortcode($atts) {
$output = '<form method="post" action="">';
$output .= '<label for="url">Enter WordPress website URL:</label>';
$output .= '<input type="text" name="url" id="url" value="" required>';
$output .= '<input type="submit" value="Check Theme">';
$output .= '</form>';
if (isset($_POST['url'])) {
$url = esc_url($_POST['url']);
$response = wp_remote_get($url);
if (is_wp_error($response)) {
$output .= '<p>Unable to retrieve WordPress theme information.</p>';
} else {
$html = wp_remote_retrieve_body($response);
if (stripos($html, 'wp-content/themes/') !== false) {
preg_match('#wp-content/themes/([^/]+)#', $html, $matches);
$theme = $matches[1];
$output .= '<p>The active theme on this WordPress website is: ' . $theme . '</p>';
$theme_info = wp_remote_get('https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=' . $theme);
if (!is_wp_error($theme_info)) {
$theme_info = json_decode(wp_remote_retrieve_body($theme_info));
if (isset($theme_info->screenshot_url)) {
$output .= '<p><img src="' . $theme_info->screenshot_url . '" alt="Screenshot"></p>';
}
if (isset($theme_info->name)) {
$output .= '<p><strong>Name:</strong> ' . $theme_info->name . '</p>';
}
if (isset($theme_info->version)) {
$output .= '<p><strong>Version:</strong> ' . $theme_info->version . '</p>';
}
if (isset($theme_info->author)) {
$output .= '<p><strong>Author:</strong> ' . $theme_info->author . '</p>';
}
if (isset($theme_info->homepage)) {
$output .= '<p><strong>Homepage:</strong> <a href="' . $theme_info->homepage . '" target="_blank">' . $theme_info->homepage . '</a></p>';
}
if (isset($theme_info->description)) {
$output .= '<p><strong>Description:</strong> ' . $theme_info->description . '</p>';
}
}
} else {
$output .= '<p>Unable to retrieve theme information. Please check the URL and try again.</p>';
}
}
}
return $output;
}
add_shortcode('theme-checker', 'theme_checker_shortcode');