@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function get_instance() |
25 | 25 | { |
26 | - if( null === static::$instance ) |
|
26 | + if (null === static::$instance) |
|
27 | 27 | { |
28 | 28 | static::$instance = new static(); |
29 | 29 | } |
@@ -36,21 +36,21 @@ discard block |
||
36 | 36 | * @param [array] $args |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function register_shortcode( $args ) |
|
39 | + public function register_shortcode($args) |
|
40 | 40 | { |
41 | 41 | $config = $this->prepare_config($args); |
42 | 42 | |
43 | - if($this->shortcode_exists($args['id'])) |
|
43 | + if ($this->shortcode_exists($args['id'])) |
|
44 | 44 | { |
45 | 45 | throw new \RuntimeException("A shortcode with id '{$args['id']}' has already been registered"); |
46 | 46 | } |
47 | 47 | |
48 | 48 | $this->shortcodes[$args['id']] = $config; |
49 | 49 | |
50 | - if($config['is_shortcode']) |
|
50 | + if ($config['is_shortcode']) |
|
51 | 51 | { |
52 | 52 | $self = $this; // Needed for backward compatibility |
53 | - \add_shortcode( $args['id'], function($atts, $content = null) use ($args, $self) { |
|
53 | + \add_shortcode($args['id'], function($atts, $content = null) use ($args, $self) { |
|
54 | 54 | // TODO: merge $atts with defaults using shortcode_atts() |
55 | 55 | $atts['content'] = $content; |
56 | 56 | return call_user_func_array($args['render'], array($self->decode_atts($atts))); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * Enqueue the popup stylesheet. This needs to be separated from the editor |
90 | 90 | * stylesheet since it is not part of the editor. |
91 | 91 | */ |
92 | - \wp_enqueue_style('amarkal-shortcode',\Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-shortcode-popup.min.css')); |
|
92 | + \wp_enqueue_style('amarkal-shortcode', \Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-shortcode-popup.min.css')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | // Attributes are JSON encoded and then URL encoded in the shortcode editor, so |
110 | 110 | // we need to reverse that |
111 | - foreach($atts as $name => $value) |
|
111 | + foreach ($atts as $name => $value) |
|
112 | 112 | { |
113 | 113 | $decoded_atts[$name] = $this->decode_att($value); |
114 | 114 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | // If the value is null, it is most likely because the attribute is not JSON encoded. |
123 | 123 | // We return the uncoded value for backward compatibility, where attributes are not JSON encoded. |
124 | - if(null === $decoded) { |
|
124 | + if (null === $decoded) { |
|
125 | 125 | $decoded = $this->decode_non_json_encodede_att($value); |
126 | 126 | } |
127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | private function decode_non_json_encodede_att($value) |
132 | 132 | { |
133 | - if(false !== \strpos($value, ',')) { |
|
133 | + if (false !== \strpos($value, ',')) { |
|
134 | 134 | return \explode(',', $value); |
135 | 135 | } |
136 | 136 | return $value; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | private function prepare_json_object() |
144 | 144 | { |
145 | 145 | $json = array(); |
146 | - foreach($this->shortcodes as $id => $shortcode) |
|
146 | + foreach ($this->shortcodes as $id => $shortcode) |
|
147 | 147 | { |
148 | 148 | $popup = new Popup($shortcode); |
149 | 149 | $json[$id] = $shortcode; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | 'cmd' => '', |
165 | 165 | 'width' => 550, |
166 | 166 | 'height' => 450, |
167 | - 'render' => function(){}, |
|
167 | + 'render' => function() {}, |
|
168 | 168 | 'fields' => array(), |
169 | 169 | 'is_shortcode' => true, |
170 | 170 | 'show_placeholder' => true, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | /** |
178 | 178 | * Check if a shortcode with the given ID has already been registered |
179 | 179 | */ |
180 | - private function shortcode_exists( $id ) |
|
180 | + private function shortcode_exists($id) |
|
181 | 181 | { |
182 | 182 | return array_key_exists($id, $this->shortcodes); |
183 | 183 | } |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | * Validate that the provided arguments have the required arguments as |
187 | 187 | * specified in self::required_args() |
188 | 188 | */ |
189 | - private function validate_args( $args ) |
|
189 | + private function validate_args($args) |
|
190 | 190 | { |
191 | - foreach($this->required_args() as $arg) |
|
191 | + foreach ($this->required_args() as $arg) |
|
192 | 192 | { |
193 | - if(!array_key_exists($arg, $args)) |
|
193 | + if (!array_key_exists($arg, $args)) |
|
194 | 194 | { |
195 | 195 | throw new \RuntimeException("Missing required argument '$arg'"); |
196 | 196 | } |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | * @param [array] $args |
204 | 204 | * @return array |
205 | 205 | */ |
206 | - private function prepare_config( $args ) |
|
206 | + private function prepare_config($args) |
|
207 | 207 | { |
208 | 208 | $this->validate_args($args); |
209 | 209 | $config = array_merge($this->default_args(), $args); |
210 | 210 | |
211 | - if($config['template'] === null) |
|
211 | + if ($config['template'] === null) |
|
212 | 212 | { |
213 | - $config['template'] = $this->generate_template($config['id'],$config['fields']); |
|
213 | + $config['template'] = $this->generate_template($config['id'], $config['fields']); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $config; |
@@ -229,17 +229,17 @@ discard block |
||
229 | 229 | $template = "[$tag"; |
230 | 230 | $self_enclosing = true; |
231 | 231 | |
232 | - foreach($fields as $field) |
|
232 | + foreach ($fields as $field) |
|
233 | 233 | { |
234 | 234 | $name = $field['name']; |
235 | - if('content' !== $name) |
|
235 | + if ('content' !== $name) |
|
236 | 236 | { |
237 | 237 | $template .= " $name=\"{{{$name}}}\""; |
238 | 238 | } |
239 | 239 | else $self_enclosing = false; |
240 | 240 | } |
241 | 241 | |
242 | - if($self_enclosing) |
|
242 | + if ($self_enclosing) |
|
243 | 243 | { |
244 | 244 | $template .= "/]"; |
245 | 245 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | private function required_args() |
257 | 257 | { |
258 | - return array('id','title','fields'); |
|
258 | + return array('id', 'title', 'fields'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | */ |
264 | 264 | private function __construct() |
265 | 265 | { |
266 | - \add_filter('mce_external_plugins',array($this,'enqueue_script')); |
|
267 | - \add_action('admin_init', array($this,'enqueue_editor_style')); |
|
268 | - \add_action('admin_enqueue_scripts', array($this,'enqueue_scripts')); |
|
269 | - \add_action('wp_enqueue_scripts', array($this,'enqueue_scripts')); |
|
266 | + \add_filter('mce_external_plugins', array($this, 'enqueue_script')); |
|
267 | + \add_action('admin_init', array($this, 'enqueue_editor_style')); |
|
268 | + \add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
269 | + \add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | \ No newline at end of file |