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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
<?php if ( ! defined( 'ABSPATH' ) ) { die( '-1' ); }
/** * WPBakery WPBakery Page Builder Main manager. * * @package WPBakeryPageBuilder * @since 4.2 */
/** * Vc mapper new class. On maintenance * Allows to bind hooks for shortcodes. * @since 4.2 */ class Vc_Mapper { /** * @since 4.2 * Stores mapping activities list which where called before initialization * @var array */ protected $init_activity = array(); /** * * * @since 4.9 * * @var array */ protected $element_activities = array();
protected $hasAccess = array();
protected $checkForAccess = true;
/** * @since 4.2 */ public function __construct() { }
/** * Include params list objects and calls all stored activity methods. * * @since 4.2 * @access public */ public function init() { do_action( 'vc_mapper_init_before' ); require_once vc_path_dir( 'PARAMS_DIR', 'load.php' ); WPBMap::setInit(); require_once vc_path_dir( 'CONFIG_DIR', 'lean-map.php' ); $this->callActivities(); do_action( 'vc_mapper_init_after' ); }
/** * This method is called by VC objects methods if it is called before VC initialization. * * @param $object - mame of class object * @param $method - method name * @param array $params - list of attributes for object method * @since 4.2 * @access public * * @see WPBMAP */ public function addActivity( $object, $method, $params = array() ) { $this->init_activity[] = array( $object, $method, $params, ); }
/** * This method is called by VC objects methods if it is called before VC initialization. * * @param $tag - shortcode tag of element * @param $method - method name * @param array $params - list of attributes for object method * @since 4.9 * @access public * * @see WPBMAP */ public function addElementActivity( $tag, $method, $params = array() ) { if ( ! isset( $this->element_activities[ $tag ] ) ) { $this->element_activities[ $tag ] = array(); } $this->element_activities[ $tag ][] = array( $method, $params, ); }
/** * Call all stored activities. * * Called by init method. List of activities stored by $init_activity are created by other objects called after * initialization. * * @since 4.2 * @access public */ protected function callActivities() { do_action( 'vc_mapper_call_activities_before' ); foreach ( $this->init_activity as $activity ) { list( $object, $method, $params ) = $activity; if ( 'mapper' === $object ) { switch ( $method ) { case 'map': $currentScope = WPBMap::getScope(); if ( isset( $params['scope'] ) ) { WPBMap::setScope( $params['scope'] ); } WPBMap::map( $params['tag'], $params['attributes'] ); WPBMap::setScope( $currentScope ); break; case 'drop_param': WPBMap::dropParam( $params['name'], $params['attribute_name'] ); break; case 'add_param': WPBMap::addParam( $params['name'], $params['attribute'] ); break; case 'mutate_param': WPBMap::mutateParam( $params['name'], $params['attribute'] ); break; case 'drop_all_shortcodes': WPBMap::dropAllShortcodes(); break; case 'drop_shortcode': WPBMap::dropShortcode( $params['name'] ); break; case 'modify': WPBMap::modify( $params['name'], $params['setting_name'], $params['value'] ); break; } } } }
/** * Does user has access to modify/clone/delete/add shortcode * * @param $shortcode * * @return bool * @since 4.5 * @todo fix_roles and maybe remove/@deprecate this */ public function userHasAccess( $shortcode ) { if ( $this->isCheckForAccess() ) { if ( isset( $this->hasAccess[ $shortcode ] ) ) { return $this->hasAccess[ $shortcode ]; } else { $this->hasAccess[ $shortcode ] = vc_user_access_check_shortcode_edit( $shortcode ); }
return $this->hasAccess[ $shortcode ]; }
return true; }
/** * @return bool * @since 4.5 * @todo fix_roles and maybe remove/@deprecate this */ public function isCheckForAccess() { return $this->checkForAccess; }
/** * @param bool $checkForAccess * @since 4.5 * * @todo fix_roles and maybe remove/@deprecate this */ public function setCheckForAccess( $checkForAccess ) { $this->checkForAccess = $checkForAccess; }
/** * @param $tag * @throws \Exception */ public function callElementActivities( $tag ) { do_action( 'vc_mapper_call_activities_before' ); if ( isset( $this->element_activities[ $tag ] ) ) { foreach ( $this->element_activities[ $tag ] as $activity ) { list( $method, $params ) = $activity; switch ( $method ) { case 'drop_param': WPBMap::dropParam( $params['name'], $params['attribute_name'] ); break; case 'add_param': WPBMap::addParam( $params['name'], $params['attribute'] ); break; case 'mutate_param': WPBMap::mutateParam( $params['name'], $params['attribute'] ); break; case 'drop_shortcode': WPBMap::dropShortcode( $params['name'] ); break; case 'modify': WPBMap::modify( $params['name'], $params['setting_name'], $params['value'] ); break; } } } } }
|