| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle Dashboard based functionalities of WPMUDEV class. |
| 4 |
* |
| 5 |
* @package WP_Defender\Behavior |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Traits; |
| 9 |
|
| 10 |
/** |
| 11 |
* Traits to handle Dashboard based functionalities of WPMUDEV class. |
| 12 |
*/ |
| 13 |
trait Defender_Dashboard_Client { |
| 14 |
/** |
| 15 |
* Get membership status. |
| 16 |
* |
| 17 |
* @return bool |
| 18 |
*/ |
| 19 |
public function is_pro() { |
| 20 |
return $this->get_apikey() !== false; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Check if user is a paid one in WPMU DEV. |
| 25 |
* |
| 26 |
* @return bool |
| 27 |
*/ |
| 28 |
public function is_member() { |
| 29 |
if ( |
| 30 |
class_exists( 'WPMUDEV_Dashboard' ) |
| 31 |
&& method_exists( 'WPMUDEV_Dashboard_Api', 'get_membership_projects' ) |
| 32 |
) { |
| 33 |
if ( method_exists( 'WPMUDEV_Dashboard_Api', 'get_membership_status' ) ) { |
| 34 |
$type = \WPMUDEV_Dashboard::$api->get_membership_status(); |
| 35 |
} elseif ( method_exists( 'WPMUDEV_Dashboard_Api', 'get_membership_type' ) ) { |
| 36 |
$type = \WPMUDEV_Dashboard::$api->get_membership_type(); |
| 37 |
} else { |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
$projects = \WPMUDEV_Dashboard::$api->get_membership_projects(); |
| 42 |
$def_pid = 1081723; |
| 43 |
|
| 44 |
if ( |
| 45 |
( 'unit' === $type && in_array( $def_pid, $projects, true ) ) |
| 46 |
|| ( 'single' === $type && $def_pid === $projects ) |
| 47 |
) { |
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
if ( function_exists( 'is_wpmudev_member' ) ) { |
| 52 |
return is_wpmudev_member(); |
| 53 |
} |
| 54 |
|
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Check if user is a WPMU DEV admin. |
| 63 |
* |
| 64 |
* @since 2.6.3 |
| 65 |
* |
| 66 |
* @return bool |
| 67 |
*/ |
| 68 |
public function is_wpmu_dev_admin() { |
| 69 |
if ( |
| 70 |
class_exists( 'WPMUDEV_Dashboard' ) |
| 71 |
&& method_exists( 'WPMUDEV_Dashboard_Site', 'allowed_user' ) |
| 72 |
) { |
| 73 |
$user_id = get_current_user_id(); |
| 74 |
|
| 75 |
return \WPMUDEV_Dashboard::$site->allowed_user( $user_id ); |
| 76 |
} |
| 77 |
|
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Bring the plugin menu title. |
| 83 |
* |
| 84 |
* @return string Menu title. |
| 85 |
*/ |
| 86 |
public function get_menu_title() { |
| 87 |
if ( $this->is_pro() ) { |
| 88 |
$menu_title = esc_html__( 'Defender Pro', 'wpdef' ); |
| 89 |
} else { |
| 90 |
// Check if it's Pro but user logged the WPMU DEV Dashboard out. |
| 91 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 92 |
$menu_title = file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . WP_DEFENDER_PRO_PATH ) |
| 93 |
&& is_plugin_active( WP_DEFENDER_PRO_PATH ) |
| 94 |
? esc_html__( 'Defender Pro', 'wpdef' ) |
| 95 |
: esc_html__( 'Defender', 'wpdef' ); |
| 96 |
} |
| 97 |
|
| 98 |
return $menu_title; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Return icon svg image. |
| 103 |
* |
| 104 |
* @return string |
| 105 |
*/ |
| 106 |
public function get_menu_icon() { |
| 107 |
ob_start(); |
| 108 |
?> |
| 109 |
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 110 |
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.99999 2.08899L3 4.21792V9.99502H9.99912V18.001H10C13.47 18.001 17 13.9231 17 11.0045V9.99501H9.99999V2.08899ZM10 0L1 2.73862V11.0045C1 15.1125 5.49 20 10 20C14.51 20 19 15.1225 19 11.0045V2.73862L10 0Z" fill="#F0F6FC" fill-opacity="0.6"/> |
| 111 |
</svg> |
| 112 |
<?php |
| 113 |
$svg = ob_get_clean(); |
| 114 |
|
| 115 |
return 'data:image/svg+xml;base64,' . base64_encode( $svg ); |
| 116 |
} |
| 117 |
} |
| 118 |
|