1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ShortcodeUI Class. |
4
|
|
|
* |
5
|
|
|
* @package BrightNucleus\Shortcode |
6
|
|
|
* @author Alain Schlesser <[email protected]> |
7
|
|
|
* @license GPL-2.0+ |
8
|
|
|
* @link http://www.brightnucleus.com/ |
9
|
|
|
* @copyright 2015-2016 Alain Schlesser, Bright Nucleus |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BrightNucleus\Shortcode; |
13
|
|
|
|
14
|
|
|
use Assert; |
15
|
|
|
use BrightNucleus\Config\ConfigInterface; |
16
|
|
|
use BrightNucleus\Config\ConfigTrait; |
17
|
|
|
use BrightNucleus\Dependency\DependencyManagerInterface as DependencyManager; |
18
|
|
|
use BrightNucleus\Exception\RuntimeException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Shortcode UI Class. |
22
|
|
|
* |
23
|
|
|
* @since 0.1.0 |
24
|
|
|
* |
25
|
|
|
* @package BrightNucleus\Shortcode |
26
|
|
|
* @author Alain Schlesser <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class ShortcodeUI implements ShortcodeUIInterface { |
29
|
|
|
|
30
|
|
|
use ConfigTrait; |
31
|
|
|
use CheckNeedTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Name of the shortcode handler. |
35
|
|
|
* |
36
|
|
|
* @since 0.1.0 |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $shortcode_tag; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Dependencies to be enqueued. |
44
|
|
|
* |
45
|
|
|
* @since 0.1.0 |
46
|
|
|
* |
47
|
|
|
* @var DependencyManager |
48
|
|
|
*/ |
49
|
|
|
protected $dependencies; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Instantiate Basic Shortcode UI. |
53
|
|
|
* |
54
|
|
|
* @since 1.0. |
55
|
|
|
* |
56
|
|
|
* @param string $shortcode_tag Tag of the Shortcode. |
57
|
|
|
* @param ConfigInterface $config Configuration settings. |
58
|
|
|
* @param DependencyManager|null $dependencies Optional. Dependencies that |
59
|
|
|
* need to be enqueued. |
60
|
|
|
* @throws RuntimeException If the config could not be processed. |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
63
|
|
|
$shortcode_tag, |
64
|
|
|
ConfigInterface $config, |
65
|
|
|
DependencyManager $dependencies = null |
66
|
|
|
) { |
67
|
|
|
Assert\that( $shortcode_tag )->string()->notEmpty(); |
68
|
|
|
|
69
|
|
|
$this->processConfig( $config ); |
70
|
|
|
|
71
|
|
|
$this->shortcode_tag = $shortcode_tag; |
72
|
|
|
$this->dependencies = $dependencies; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Register the shortcode UI handler function with WordPress. |
77
|
|
|
* |
78
|
|
|
* @since 0.1.0 |
79
|
|
|
* |
80
|
|
|
* @param mixed $context Data about the context in which the call is made. |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function register( $context = null ) { |
84
|
|
|
if ( ! $this->is_needed() ) { |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
\shortcode_ui_register_for_shortcode( |
89
|
|
|
$this->shortcode_tag, |
90
|
|
|
$this->config |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.