class-whitelabel.php
2.49 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* WhiteLabel.
*
* @package Smush\Core
*/
namespace Smush\Core\Modules\Helpers;
use WPMUDEV_Dashboard;
defined( 'ABSPATH' ) || exit;
/**
* Class WhiteLabel
*/
class WhiteLabel {
/**
* Whether to activate white label.
*
* @return bool
*/
public function enabled() {
return $this->hide_branding();
}
/**
* Whether to hide branding or not.
*
* @return bool
*/
public function hide_branding() {
return apply_filters( 'wpmudev_branding_hide_branding', false );
}
/**
* Whether to hide doc link or not.
*
* @return bool
*/
public function hide_doc_link() {
return apply_filters( 'wpmudev_branding_hide_doc_link', false );
}
/**
* Whether to custom plugin labels or not.
*
* @param int $plugin_id Plugin id.
*
* @return bool
*/
private function plugin_enabled( $plugin_id ) {
if ( ! $this->enabled() ) {
return false;
}
if (
! class_exists( '\WPMUDEV_Dashboard' ) ||
empty( WPMUDEV_Dashboard::$whitelabel ) ||
! method_exists( WPMUDEV_Dashboard::$whitelabel, 'get_settings' )
) {
return false;
}
$whitelabel_settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
return ! empty( $whitelabel_settings['labels_enabled'] ) && ! empty( $whitelabel_settings['labels_config'][ $plugin_id ] );
}
/**
* Get custom plugin label.
*
* @param int $plugin_id Plugin id.
* @return bool|string
*/
public function get_plugin_name( $plugin_id ) {
if ( ! $this->plugin_enabled( $plugin_id ) ) {
return false;
}
$whitelabel_settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
if ( empty( $whitelabel_settings['labels_config'][ $plugin_id ]['name'] ) ) {
return false;
}
return $whitelabel_settings['labels_config'][ $plugin_id ]['name'];
}
/**
* Get custom plugin logo url.
*
* @param int $plugin_id Plugin id.
* @return bool|string
*/
public function get_plugin_logo( $plugin_id ) {
if ( ! $this->plugin_enabled( $plugin_id ) ) {
return false;
}
$whitelabel_settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
$plugin_settings = $whitelabel_settings['labels_config'][ $plugin_id ];
if ( empty( $plugin_settings['icon_type'] ) ) {
return false;
}
if ( 'link' === $plugin_settings['icon_type'] && ! empty( $plugin_settings['icon_url'] ) ) {
return $plugin_settings['icon_url'];
}
if ( 'upload' === $plugin_settings['icon_type'] && ! empty( $plugin_settings['thumb_id'] ) ) {
return wp_get_attachment_image_url( $plugin_settings['thumb_id'], 'full' );
}
return false;
}
}