PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/traits/theme.php +63 -3 3.0.1 → 6.3.0 View file →
@@ -1,28 +1,58 @@
1 1 <?php
2 +/**
3 + * Helper functions for theme support.
4 + *
5 + * @package WP_Defender\Traits
6 + */
2 7
3 8 namespace WP_Defender\Traits;
4 9
10 +use WP_Theme;
11 +
5 12 trait Theme {
6 13
7 14 /**
15 + * No use get_theme_root().
16 + *
17 + * @return string
18 + */
19 + public function get_path_of_themes_dir(): string {
20 + return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR;
21 + }
22 +
23 + /**
8 24 * Get all installed themes.
9 25 *
10 26 * @return array
11 27 */
12 - public function get_themes() {
28 + public function get_themes(): array {
13 29 if ( ! function_exists( 'wp_get_themes' ) ) {
14 - require_once( ABSPATH . '/wp-includes/theme.php' );
30 + require_once ABSPATH . '/wp-includes/theme.php';
15 31 }
32 +
16 33 return wp_get_themes();
17 34 }
18 35
19 36 /**
37 + * Get theme's details.
38 + *
39 + * @return WP_Theme
40 + */
41 + public function get_theme(): WP_Theme {
42 + if ( ! function_exists( 'wp_get_themes' ) ) {
43 + require_once ABSPATH . '/wp-includes/theme.php';
44 + }
45 +
46 + return wp_get_theme();
47 + }
48 +
49 + /**
20 50 * Get all slugs
21 51 *
22 52 * @return array
23 53 */
24 - public function get_theme_slugs() {
54 + public function get_theme_slugs(): array {
25 55 $slugs = array();
26 56 foreach ( $this->get_themes() as $slug => $theme ) {
27 57 if ( is_object( $theme->parent() ) ) {
28 58 continue;
@@ -30,6 +60,36 @@
30 60 $slugs[] = $slug;
31 61 }
32 62
33 63 return $slugs;
64 + }
65 +
66 + /**
67 + * Check if the given theme file path is the active theme.
68 + *
69 + * @param string $file_path The absolute file path to the theme file.
70 + *
71 + * @return bool Returns true if the given theme file path is the active theme, false otherwise.
72 + */
73 + public function is_active_theme( $file_path ): bool {
74 + $active_theme = $this->get_theme();
75 + $theme_dir = $this->get_path_of_themes_dir();
76 + $abs_path = $theme_dir;
77 + $abs_path = defender_replace_line( $abs_path );
78 + // Without the first slash.
79 + $rev_file = str_replace( $abs_path, '', $file_path );
80 + $theme_data = explode( '/', $rev_file );
81 + $theme_slug = $theme_data[0];
82 + // Checking if the given theme is a child theme.
83 + if ( false !== stripos( $theme_slug, '-child' ) ) {
84 + $theme_slug = str_replace( '-child', '', $theme_slug );
85 + }
86 + // Checking if the active theme is a parent theme.
87 + if ( is_object( $active_theme->parent() ) ) {
88 + $active_theme_slug = $active_theme->parent()->get_stylesheet();
89 + } else {
90 + $active_theme_slug = $active_theme->get_stylesheet();
91 + }
92 +
93 + return $theme_slug === $active_theme_slug;
34 94 }
35 95 }