Completed
Branch new-addon-api (b7bde0)
by
unknown
18:29 queued 08:41
created

ThirdPartyPluginHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadPlugins() 0 4 1
A wpApiBasicAuth() 0 15 6
1
<?php
2
3
namespace EventEspresso\core\services\addon\api;
4
5
use EventEspresso\core\services\request\RequestInterface;
6
7
class ThirdPartyPluginHandler
8
{
9
10
    /**
11
     * @var RequestInterface $request
12
     */
13
    private $request;
14
15
16
    /**
17
     * ThirdPartyPluginHandler constructor.
18
     *
19
     * @param RequestInterface $request
20
     */
21
    public function __construct(RequestInterface $request)
22
    {
23
        $this->request = $request;
24
    }
25
26
27
    public function loadPlugins()
28
    {
29
        $this->wpApiBasicAuth();
30
    }
31
32
33
    private function wpApiBasicAuth()
34
    {
35
        // if the WP API basic auth plugin isn't already loaded, load it now.
36
        // We want it for mobile apps. Just include the entire plugin
37
        // also, don't load the basic auth when a plugin is getting activated, because
38
        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
39
        // and causes a fatal error
40
        if (($this->request->isWordPressApi() || $this->request->isApi())
41
            && ! $this->request->isActivation()
42
            && ! function_exists('json_basic_auth_handler')
43
            && ! function_exists('json_basic_auth_error')
44
        ) {
45
            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
46
        }
47
    }
48
}
49