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
defender-security / src / integrations / class-dashboard-whitelabel.php

class-dashboard-whitelabel.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/integrations/class-dashboard-whitelabel.php

165 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles interactions with the Dashboard for white label.
4 *
5 * @package WP_Defender\Integrations
6 */
7
8 namespace WP_Defender\Integrations;
9
10 use WPMUDEV_Dashboard;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 die;
14 }
15
16 /**
17 * Dashboard integration module for whitelabel.
18 *
19 * @since 3.2.0
20 */
21 class Dashboard_Whitelabel {
22
23 /**
24 * Holds dashboard plugin white-label filter values.
25 *
26 * @var array
27 */
28 private $wpmudev_branding;
29
30 /**
31 * Constructor for the class.
32 * Initializes the object by setting the value of the $wpmudev_branding property
33 * by applying the 'wpmudev_branding' filter to an empty array.
34 *
35 * @return void
36 */
37 public function __construct() {
38 $this->wpmudev_branding = apply_filters( 'wpmudev_branding', array() );
39 }
40
41 /**
42 * Hide or show branding.
43 *
44 * @return bool True to hide and false for show.
45 */
46 public function is_hide_branding(): bool {
47 return isset( $this->wpmudev_branding['hide_branding'] ) && $this->wpmudev_branding['hide_branding'];
48 }
49
50 /**
51 * Get branding logo.
52 *
53 * @return string URL of whitelabel logo or default logo.
54 */
55 public function get_branding_logo(): string {
56 if ( $this->is_hide_branding() && '' !== trim( $this->wpmudev_branding['hero_image'] ) ) {
57 return $this->wpmudev_branding['hero_image'];
58 }
59
60 return defender_asset_url( '/assets/email-images/logo.png' );
61 }
62
63 /**
64 * Boolean to check before change footer text.
65 *
66 * @return bool True to change and false for use default.
67 */
68 public function is_change_footer(): bool {
69 return isset( $this->wpmudev_branding['change_footer'] ) && $this->wpmudev_branding['change_footer'];
70 }
71
72 /**
73 * Footer text either custom text or default text.
74 *
75 * @return string Text to show in email content footer.
76 */
77 public function get_footer_text(): string {
78 if ( $this->is_change_footer() && $this->is_set_footer_text() ) {
79 return $this->wpmudev_branding['footer_text'];
80 }
81
82 return esc_html__( 'The WPMU DEV Team.', 'defender-security' );
83 }
84
85 /**
86 * Check if whitelabel feature is allowed for the membership.
87 *
88 * @return bool
89 * @since 4.5.0
90 */
91 public function can_whitelabel(): bool {
92 if (
93 class_exists( '\WPMUDEV_Dashboard' ) &&
94 is_object( WPMUDEV_Dashboard::$whitelabel ) &&
95 method_exists( WPMUDEV_Dashboard::$whitelabel, 'can_whitelabel' ) &&
96 WPMUDEV_Dashboard::$whitelabel->can_whitelabel()
97 ) {
98 return true;
99 }
100
101 return false;
102 }
103
104 /**
105 * Check if whitelabel footer text is set.
106 *
107 * @return bool
108 * @since 4.5.0
109 */
110 public function is_set_footer_text(): bool {
111 $text = $this->wpmudev_branding['footer_text'] ?? '';
112
113 return trim( $text ) !== '';
114 }
115
116 /**
117 * Whether to custom plugin labels or not.
118 *
119 * @param int $plugin_id Plugin id.
120 *
121 * @return bool
122 * @since 4.5.0
123 */
124 private function plugin_enabled( $plugin_id ) {
125 if (
126 ! class_exists( '\WPMUDEV_Dashboard' ) ||
127 null === WPMUDEV_Dashboard::$whitelabel ||
128 ! method_exists( WPMUDEV_Dashboard::$whitelabel, 'get_settings' )
129 ) {
130 return false;
131 }
132 $whitelabel_settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
133
134 return isset( $whitelabel_settings['labels_enabled'] )
135 && false !== (bool) $whitelabel_settings['labels_enabled']
136 && isset( $whitelabel_settings['labels_config'][ $plugin_id ] )
137 && is_array( $whitelabel_settings['labels_config'][ $plugin_id ] )
138 && array() !== $whitelabel_settings['labels_config'][ $plugin_id ];
139 }
140
141 /**
142 * Get custom plugin label.
143 *
144 * @param int $plugin_id Plugin id.
145 *
146 * @return bool|string
147 * @since 4.5.0
148 */
149 public function get_plugin_name( $plugin_id ) {
150 if ( ! $this->plugin_enabled( $plugin_id ) ) {
151 return false;
152 }
153 $whitelabel_settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
154 if (
155 ! isset( $whitelabel_settings['labels_config'][ $plugin_id ]['name'] )
156 || ! is_string( $whitelabel_settings['labels_config'][ $plugin_id ]['name'] )
157 || '' === trim( $whitelabel_settings['labels_config'][ $plugin_id ]['name'] )
158 ) {
159 return false;
160 }
161
162 return $whitelabel_settings['labels_config'][ $plugin_id ]['name'];
163 }
164 }
165