| 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() && ! empty( 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 |
empty( 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 ! empty( $whitelabel_settings['labels_enabled'] ) |
| 135 |
&& ! empty( $whitelabel_settings['labels_config'][ $plugin_id ] ); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Get custom plugin label. |
| 140 |
* |
| 141 |
* @param int $plugin_id Plugin id. |
| 142 |
* |
| 143 |
* @return bool|string |
| 144 |
* @since 4.5.0 |
| 145 |
*/ |
| 146 |
public function get_plugin_name( $plugin_id ) { |
| 147 |
if ( ! $this->plugin_enabled( $plugin_id ) ) { |
| 148 |
return false; |
| 149 |
} |
| 150 |
$whitelabel_settings = WPMUDEV_Dashboard::$whitelabel->get_settings(); |
| 151 |
if ( empty( $whitelabel_settings['labels_config'][ $plugin_id ]['name'] ) ) { |
| 152 |
return false; |
| 153 |
} |
| 154 |
|
| 155 |
return $whitelabel_settings['labels_config'][ $plugin_id ]['name']; |
| 156 |
} |
| 157 |
} |
| 158 |
|