1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the WPFoundation library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015-present 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
|
|
|
/** |
15
|
|
|
* Abstract class of theme that implements the interface. |
16
|
|
|
* This class avoids the use of callbacks in the constructor. |
17
|
|
|
* |
18
|
|
|
* @author Beñat Espiña <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
abstract class Theme implements ThemeInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Constructor. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
$this->classes(); |
28
|
|
|
$this->templateSelector(); |
|
|
|
|
29
|
|
|
$this->xmlrpc(); |
30
|
|
|
add_theme_support('post-thumbnails'); |
|
|
|
|
31
|
|
|
add_filter('timber_context', [$this, 'context']); |
|
|
|
|
32
|
|
|
|
33
|
|
|
// @deprecated since version 1.6, will be removed in 2.0. Extend the ACF class in your project and instantiate |
34
|
|
|
// inside your project Theme. |
35
|
|
|
$this->acf(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Filters the selectable templates. |
40
|
|
|
*/ |
41
|
|
|
private function templateSelector() |
42
|
|
|
{ |
43
|
|
|
$self = $this; |
44
|
|
|
add_filter('theme_page_templates', function () use ($self) { |
|
|
|
|
45
|
|
|
return $self->templates([]); |
46
|
|
|
}); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Enables or disables XML-RPC feature. |
51
|
|
|
*/ |
52
|
|
|
private function xmlrpc() |
53
|
|
|
{ |
54
|
|
|
$xmlrpc = !defined('XMLRPC_ENABLED') || XMLRPC_ENABLED === true |
55
|
|
|
? '__return_true' |
56
|
|
|
: '__return_false'; |
57
|
|
|
add_filter('xmlrpc_enabled', $xmlrpc); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @deprecated since version 1.6, will be removed in 2.0. Extend the ACF class in your project and instantiate |
62
|
|
|
* inside your project Theme |
63
|
|
|
*/ |
64
|
|
|
protected function acf() |
65
|
|
|
{ |
66
|
|
|
$customToolbars = [ |
67
|
|
|
'lin3s' => [1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink']], |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
add_filter('acf/fields/wysiwyg/toolbars', function (array $toolbars) use ($customToolbars) { |
|
|
|
|
71
|
|
|
return array_merge($toolbars, $customToolbars); |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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: