trait-dashboard-api.php
2.58 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
109
<?php
/**
* WPMUDEV Dashboard API methods.
*
* @link https://wordpress.org/plugins/broken-link-checker/
* @since 2.0.0
*
* @author WPMUDEV (https://wpmudev.com)
* @package WPMUDEV_BLC\Core\Traits
*
* @copyright (c) 2022, Incsub (http://incsub.com)
*/
namespace WPMUDEV_BLC\Core\Traits;
// Abort if called directly.
defined( 'WPINC' ) || die;
/**
* Class Enqueue
*
* @package WPMUDEV_BLC\Core\Traits
*/
trait Dashboard_API {
/**
* Returns WPMUDEV Dashboard API object
*
* @return \WPMUDEV_Dashboard_Api|null
*/
public static function get_dashboard_api() {
if ( class_exists( 'WPMUDEV_Dashboard' ) && ! empty( \WPMUDEV_Dashboard::$api ) ) {
return \WPMUDEV_Dashboard::$api;
}
return null;
}
/**
* Returns WPMU DEV membership type
*
* Possible return values:
* 'free' - Free hub membership.
* 'single' - Single membership (i.e. only 1 project is licensed)
* 'unit' - One or more projects licensed
* 'full' - Full membership, no restrictions.
* 'paused' - Membership access is paused.
* 'expired' - Expired membership.
* '' - (empty string) If user is not logged in or with an unknown type.
*
* @return string
*/
public static function get_membership_type() {
$api = self::get_dashboard_api();
if ( $api ) {
$result = null;
if ( is_callable( array( $api, 'get_membership_status' ) ) ) {
$result = $api->get_membership_status();
} elseif ( is_callable( array( $api, 'get_membership_type' ) ) ) {
$result = $api->get_membership_type();
}
if ( ! \is_null( $result ) ) {
$result = strval( apply_filters( 'wpmudev_blc_dashboard_membership_type', $result ) );
return $result;
}
}
return null;
}
/**
* Returns a boolean. True if site is connected to hub or false if not.
*
* @return bool
*/
public static function site_connected() {
return apply_filters( 'wpmudev_blc_dashboard_site_connected', ! empty( self::get_membership_type() ) );
/*
* Until we get BLC project ID we will keep using Dashboard's get_membership_status().
*/
/*
$has_access = false;
if ( class_exists( 'WPMUDEV_Dashboard' ) && method_exists( WPMUDEV_Dashboard::$upgrader, 'user_can_install' ) ) {
$has_access = WPMUDEV_Dashboard::$upgrader->user_can_install( XXXX, true );
}
return apply_filters( 'wpmudev_blc_dashboard_site_connected', $has_access );
*/
}
/**
* Returns the Hub site id.
*
* @return int|null
*/
public static function get_site_id() {
$api = self::get_dashboard_api();
if ( $api instanceof \WPMUDEV_Dashboard_Api ) {
return $api->get_site_id();
}
return null;
}
}