@@ -6,7 +6,7 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | // Load module functions |
12 | 12 | require_once 'functions.php'; |
13 | 13 | \ No newline at end of file |
@@ -17,7 +17,9 @@ |
||
17 | 17 | /** |
18 | 18 | * Prevent loading the library more than once |
19 | 19 | */ |
20 | -if( defined( 'AMARKAL_SHORTCODE' ) ) return false; |
|
20 | +if( defined( 'AMARKAL_SHORTCODE' ) ) { |
|
21 | + return false; |
|
22 | +} |
|
21 | 23 | define( 'AMARKAL_SHORTCODE', true ); |
22 | 24 | |
23 | 25 | if(!function_exists('amarkal_register_shortcode')) |
@@ -12,17 +12,17 @@ |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Prevent direct file access |
15 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
15 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Prevent loading the library more than once |
19 | 19 | */ |
20 | -if( defined( 'AMARKAL_SHORTCODE' ) ) return false; |
|
21 | -define( 'AMARKAL_SHORTCODE', true ); |
|
20 | +if (defined('AMARKAL_SHORTCODE')) return false; |
|
21 | +define('AMARKAL_SHORTCODE', true); |
|
22 | 22 | |
23 | -if(!function_exists('amarkal_register_shortcode')) |
|
23 | +if (!function_exists('amarkal_register_shortcode')) |
|
24 | 24 | { |
25 | - function amarkal_register_shortcode( $args ) |
|
25 | + function amarkal_register_shortcode($args) |
|
26 | 26 | { |
27 | 27 | $manager = Amarkal\Shortcode\Manager::get_instance(); |
28 | 28 | $manager->register_shortcode($args); |
@@ -184,15 +184,15 @@ |
||
184 | 184 | if('content' !== $name) |
185 | 185 | { |
186 | 186 | $template .= " $name=\"{{{$name}}}\""; |
187 | + } else { |
|
188 | + $self_enclosing = false; |
|
187 | 189 | } |
188 | - else $self_enclosing = false; |
|
189 | 190 | } |
190 | 191 | |
191 | 192 | if($self_enclosing) |
192 | 193 | { |
193 | 194 | $template .= "/]"; |
194 | - } |
|
195 | - else { |
|
195 | + } else { |
|
196 | 196 | $template .= "]{{content}}[/$tag]"; |
197 | 197 | } |
198 | 198 |
@@ -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,20 +36,20 @@ 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 | - \add_shortcode( $args['id'], function($atts, $content = null) use ($args) { |
|
52 | + \add_shortcode($args['id'], function($atts, $content = null) use ($args) { |
|
53 | 53 | // TODO: merge $atts with defaults using shortcode_atts() |
54 | 54 | $atts['content'] = $content; |
55 | 55 | call_user_func_array($args['render'], array($atts)); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function enqueue_popup_style() |
85 | 85 | { |
86 | - \wp_enqueue_style('amarkal-shortcode',\Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-shortcode-popup.min.css')); |
|
86 | + \wp_enqueue_style('amarkal-shortcode', \Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-shortcode-popup.min.css')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | private function prepare_json_object() |
104 | 104 | { |
105 | 105 | $json = array(); |
106 | - foreach($this->shortcodes as $id => $shortcode) |
|
106 | + foreach ($this->shortcodes as $id => $shortcode) |
|
107 | 107 | { |
108 | 108 | $popup = new Popup($shortcode); |
109 | 109 | $json[$id] = $shortcode; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | 'cmd' => '', |
125 | 125 | 'width' => 550, |
126 | 126 | 'height' => 450, |
127 | - 'render' => function(){}, |
|
127 | + 'render' => function() {}, |
|
128 | 128 | 'fields' => array(), |
129 | 129 | 'is_shortcode' => true, |
130 | 130 | 'show_placeholder' => true, |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * Check if a shortcode with the given ID has already been registered |
139 | 139 | */ |
140 | - private function shortcode_exists( $id ) |
|
140 | + private function shortcode_exists($id) |
|
141 | 141 | { |
142 | 142 | return array_key_exists($id, $this->shortcodes); |
143 | 143 | } |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | * Validate that the provided arguments have the required arguments as |
147 | 147 | * specified in self::required_args() |
148 | 148 | */ |
149 | - private function validate_args( $args ) |
|
149 | + private function validate_args($args) |
|
150 | 150 | { |
151 | - foreach($this->required_args() as $arg) |
|
151 | + foreach ($this->required_args() as $arg) |
|
152 | 152 | { |
153 | - if(!array_key_exists($arg, $args)) |
|
153 | + if (!array_key_exists($arg, $args)) |
|
154 | 154 | { |
155 | 155 | throw new \RuntimeException("Missing required argument '$arg'"); |
156 | 156 | } |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | * @param [array] $args |
164 | 164 | * @return array |
165 | 165 | */ |
166 | - private function prepare_config( $args ) |
|
166 | + private function prepare_config($args) |
|
167 | 167 | { |
168 | 168 | $this->validate_args($args); |
169 | 169 | $config = array_merge($this->default_args(), $args); |
170 | 170 | |
171 | - if($config['template'] === null) |
|
171 | + if ($config['template'] === null) |
|
172 | 172 | { |
173 | - $config['template'] = $this->generate_template($config['id'],$config['fields']); |
|
173 | + $config['template'] = $this->generate_template($config['id'], $config['fields']); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $config; |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | $template = "[$tag"; |
190 | 190 | $self_enclosing = true; |
191 | 191 | |
192 | - foreach($fields as $field) |
|
192 | + foreach ($fields as $field) |
|
193 | 193 | { |
194 | 194 | $name = $field['name']; |
195 | - if('content' !== $name) |
|
195 | + if ('content' !== $name) |
|
196 | 196 | { |
197 | 197 | $template .= " $name=\"{{{$name}}}\""; |
198 | 198 | } |
199 | 199 | else $self_enclosing = false; |
200 | 200 | } |
201 | 201 | |
202 | - if($self_enclosing) |
|
202 | + if ($self_enclosing) |
|
203 | 203 | { |
204 | 204 | $template .= "/]"; |
205 | 205 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | */ |
216 | 216 | private function required_args() |
217 | 217 | { |
218 | - return array('id','title','fields'); |
|
218 | + return array('id', 'title', 'fields'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | */ |
224 | 224 | private function __construct() |
225 | 225 | { |
226 | - \add_filter('mce_external_plugins',array($this,'enqueue_script')); |
|
227 | - \add_action('admin_init', array($this,'enqueue_editor_style')); |
|
228 | - \add_action('admin_enqueue_scripts', array($this,'enqueue_popup_style')); |
|
229 | - \add_action('wp_enqueue_scripts', array($this,'enqueue_popup_style')); |
|
226 | + \add_filter('mce_external_plugins', array($this, 'enqueue_script')); |
|
227 | + \add_action('admin_init', array($this, 'enqueue_editor_style')); |
|
228 | + \add_action('admin_enqueue_scripts', array($this, 'enqueue_popup_style')); |
|
229 | + \add_action('wp_enqueue_scripts', array($this, 'enqueue_popup_style')); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | \ No newline at end of file |
@@ -6,13 +6,13 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Load module functions. If this amarkal module has not been loaded, |
13 | 13 | * functions.php will not return false. |
14 | 14 | */ |
15 | -if(false !== (require_once 'functions.php')) |
|
15 | +if (false !== (require_once 'functions.php')) |
|
16 | 16 | { |
17 | 17 | // Load required classes if not using composer |
18 | 18 | require_once 'Manager.php'; |
@@ -26,7 +26,7 @@ |
||
26 | 26 | /** |
27 | 27 | * Render the popup |
28 | 28 | * |
29 | - * @return void |
|
29 | + * @return string |
|
30 | 30 | */ |
31 | 31 | public function render() |
32 | 32 | { |