1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the WPFoundation library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015-2016 LIN3S <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LIN3S\WPFoundation\Configuration\Theme; |
13
|
|
|
|
14
|
|
|
use LIN3S\WPFoundation\Configuration\Acf\Wysiwyg; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract class of theme that implements the interface. |
18
|
|
|
* This class avoids the use of callbacks in the constructor. |
19
|
|
|
* |
20
|
|
|
* @author Beñat Espiña <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
abstract class Theme implements ThemeInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Constructor. |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
$this->acf(); |
30
|
|
|
$this->classes(); |
31
|
|
|
$this->templateSelector(); |
|
|
|
|
32
|
|
|
$this->xmlrpc(); |
33
|
|
|
add_theme_support('post-thumbnails'); |
|
|
|
|
34
|
|
|
add_filter('timber_context', [$this, 'context']); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* All about ACF configuration should be instantiated here. |
39
|
|
|
*/ |
40
|
|
|
protected function acf() |
41
|
|
|
{ |
42
|
|
|
new Wysiwyg([ |
43
|
|
|
'lin3s' => [1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink']], |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Filters the selectable templates. |
49
|
|
|
*/ |
50
|
|
|
private function templateSelector() |
51
|
|
|
{ |
52
|
|
|
$self = $this; |
53
|
|
|
add_filter('theme_page_templates', function () use ($self) { |
|
|
|
|
54
|
|
|
return $self->templates([]); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Enables or disables XML-RPC feature. |
60
|
|
|
*/ |
61
|
|
|
private function xmlrpc() |
62
|
|
|
{ |
63
|
|
|
$xmlrpc = !defined('XMLRPC_ENABLED') || XMLRPC_ENABLED === true |
64
|
|
|
? '__return_true' |
65
|
|
|
: '__return_false'; |
66
|
|
|
add_filter('xmlrpc_enabled', $xmlrpc); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: