Completed
Push — master ( aa0bf0...04495e )
by ྅༻ Ǭɀħ
02:50
created
includes/functions-plugins.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @since 1.5
16 16
  */
17 17
 
18
-if ( !isset( $yourls_filters ) ) {
18
+if (!isset($yourls_filters)) {
19 19
     $yourls_filters = [];
20 20
 }
21 21
 /*
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * $yourls_filters['hook']['array of priorities']['serialized function names']['array of ['array (functions, accepted_args, filter or action)]']
24 24
  */
25 25
 
26
-if ( !isset( $yourls_actions ) ) {
26
+if (!isset($yourls_actions)) {
27 27
     $yourls_actions = [];
28 28
 }
29 29
 /*
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
  * @param string   $type
49 49
  * @global array   $yourls_filters Storage for all of the filters
50 50
  */
51
-function yourls_add_filter( $hook, $function_name, $priority = 10, $accepted_args = NULL, $type = 'filter' ) {
51
+function yourls_add_filter($hook, $function_name, $priority = 10, $accepted_args = NULL, $type = 'filter') {
52 52
     global $yourls_filters;
53 53
     // At this point, we cannot check if the function exists, as it may well be defined later (which is OK)
54
-    $id = yourls_filter_unique_id( $hook, $function_name, $priority );
54
+    $id = yourls_filter_unique_id($hook, $function_name, $priority);
55 55
 
56
-    $yourls_filters[ $hook ][ $priority ][ $id ] = [
56
+    $yourls_filters[$hook][$priority][$id] = [
57 57
         'function'      => $function_name,
58 58
         'accepted_args' => $accepted_args,
59 59
         'type'          => $type,
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
  * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
74 74
  * @param int $accepted_args optional. The number of arguments the function accept (default 1).
75 75
  */
76
-function yourls_add_action( $hook, $function_name, $priority = 10, $accepted_args = 1 ) {
77
-	yourls_add_filter( $hook, $function_name, $priority, $accepted_args, 'action' );
76
+function yourls_add_action($hook, $function_name, $priority = 10, $accepted_args = 1) {
77
+	yourls_add_filter($hook, $function_name, $priority, $accepted_args, 'action');
78 78
 }
79 79
 
80 80
 /**
@@ -88,28 +88,28 @@  discard block
 block discarded – undo
88 88
  * @param int|bool $priority used in counting how many hooks were applied.  If === false and $function is an object reference, we return the unique id only if it already has one, false otherwise.
89 89
  * @return string unique ID for usage as array key
90 90
  */
91
-function yourls_filter_unique_id( $hook, $function, $priority ) {
91
+function yourls_filter_unique_id($hook, $function, $priority) {
92 92
     // If function then just skip all of the tests and not overwrite the following.
93
-    if ( is_string( $function ) ) {
93
+    if (is_string($function)) {
94 94
         return $function;
95 95
     }
96 96
 
97
-    if ( is_object( $function ) ) {
97
+    if (is_object($function)) {
98 98
         // Closures are currently implemented as objects
99
-        $function = [ $function, '' ];
99
+        $function = [$function, ''];
100 100
     }
101 101
     else {
102
-        $function = (array)$function;
102
+        $function = (array) $function;
103 103
     }
104 104
 
105 105
     // Object Class Calling
106
-    if ( is_object( $function[ 0 ] ) ) {
107
-        return spl_object_hash( $function[ 0 ] ).$function[ 1 ];
106
+    if (is_object($function[0])) {
107
+        return spl_object_hash($function[0]).$function[1];
108 108
     }
109 109
 
110 110
     // Static Calling
111
-    if ( is_string( $function[ 0 ] ) ) {
112
-        return $function[ 0 ].'::'.$function[ 1 ];
111
+    if (is_string($function[0])) {
112
+        return $function[0].'::'.$function[1];
113 113
     }
114 114
     // TODO: missing final return;
115 115
 }
@@ -134,39 +134,39 @@  discard block
 block discarded – undo
134 134
  * @param mixed $value the value of the element before filtering
135 135
  * @return mixed
136 136
  */
137
-function yourls_apply_filter( $hook, $value = '' ) {
137
+function yourls_apply_filter($hook, $value = '') {
138 138
     global $yourls_filters;
139
-    if ( !isset( $yourls_filters[ $hook ] ) ) {
139
+    if (!isset($yourls_filters[$hook])) {
140 140
         return $value;
141 141
     }
142 142
 
143 143
     $args = func_get_args();
144 144
 
145 145
     // Sort filters by priority
146
-    ksort( $yourls_filters[ $hook ] );
146
+    ksort($yourls_filters[$hook]);
147 147
 
148 148
     // Loops through each filter
149
-    reset( $yourls_filters[ $hook ] );
149
+    reset($yourls_filters[$hook]);
150 150
     do {
151
-        foreach ( (array)current( $yourls_filters[ $hook ] ) as $the_ ) {
152
-            if ( !is_null( $the_[ 'function' ] ) ) {
153
-                $args[ 1 ] = $value;
154
-                $count = $the_[ 'accepted_args' ];
155
-                if ( is_null( $count ) ) {
156
-                    $_value = call_user_func_array( $the_[ 'function' ], array_slice( $args, 1 ) );
151
+        foreach ((array) current($yourls_filters[$hook]) as $the_) {
152
+            if (!is_null($the_['function'])) {
153
+                $args[1] = $value;
154
+                $count = $the_['accepted_args'];
155
+                if (is_null($count)) {
156
+                    $_value = call_user_func_array($the_['function'], array_slice($args, 1));
157 157
                 }
158 158
                 else {
159
-                    $_value = call_user_func_array( $the_[ 'function' ], array_slice( $args, 1, (int)$count ) );
159
+                    $_value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $count));
160 160
                 }
161 161
             }
162
-            if ( $the_[ 'type' ] == 'filter' ) {
162
+            if ($the_['type'] == 'filter') {
163 163
                 $value = $_value;
164 164
             }
165 165
         }
166
-    } while ( next( $yourls_filters[ $hook ] ) !== false );
166
+    } while (next($yourls_filters[$hook]) !== false);
167 167
 
168 168
     // TODO: Missing final return - Why not just return all the time? It's up receiving code to use or not.
169
-    if ( $the_[ 'type' ] == 'filter' ) {
169
+    if ($the_['type'] == 'filter') {
170 170
         return $value;
171 171
     }
172 172
 }
@@ -177,33 +177,33 @@  discard block
 block discarded – undo
177 177
  * @param string $hook the name of the YOURLS action
178 178
  * @param mixed $arg action arguments
179 179
  */
180
-function yourls_do_action( $hook, $arg = '' ) {
180
+function yourls_do_action($hook, $arg = '') {
181 181
     global $yourls_actions;
182 182
 
183 183
     // Keep track of actions that are "done"
184
-    if ( !isset( $yourls_actions ) ) {
184
+    if (!isset($yourls_actions)) {
185 185
         $yourls_actions = [];
186 186
     }
187
-    if ( !isset( $yourls_actions[ $hook ] ) ) {
188
-        $yourls_actions[ $hook ] = 1;
187
+    if (!isset($yourls_actions[$hook])) {
188
+        $yourls_actions[$hook] = 1;
189 189
     }
190 190
     else {
191
-        ++$yourls_actions[ $hook ];
191
+        ++$yourls_actions[$hook];
192 192
     }
193 193
 
194 194
     $args = [];
195
-    if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[ 0 ] ) && is_object( $arg[ 0 ] ) ) { // array(&$this)
196
-        $args[] =& $arg[ 0 ];
195
+    if (is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0])) { // array(&$this)
196
+        $args[] = & $arg[0];
197 197
     }
198 198
     else {
199 199
         $args[] = $arg;
200 200
     }
201 201
 
202
-    for ( $a = 2 ; $a < func_num_args() ; $a++ ) {
203
-        $args[] = func_get_arg( $a );
202
+    for ($a = 2; $a < func_num_args(); $a++) {
203
+        $args[] = func_get_arg($a);
204 204
     }
205 205
 
206
-    yourls_apply_filter( $hook, $args );
206
+    yourls_apply_filter($hook, $args);
207 207
 }
208 208
 
209 209
 /**
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
  * @param string $hook Name of the action hook.
213 213
  * @return int The number of times action hook <tt>$hook</tt> is fired
214 214
  */
215
-function yourls_did_action( $hook ) {
215
+function yourls_did_action($hook) {
216 216
     global $yourls_actions;
217
-    return empty( $yourls_actions[ $hook ] ) ? 0 : $yourls_actions[ $hook ];
217
+    return empty($yourls_actions[$hook]) ? 0 : $yourls_actions[$hook];
218 218
 }
219 219
 
220 220
 /**
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
  * @param int $priority optional. The priority of the function (default: 10).
234 234
  * @return bool Whether the function was registered as a filter before it was removed.
235 235
  */
236
-function yourls_remove_filter( $hook, $function_to_remove, $priority = 10 ) {
236
+function yourls_remove_filter($hook, $function_to_remove, $priority = 10) {
237 237
     global $yourls_filters;
238 238
 
239
-    $function_to_remove = yourls_filter_unique_id( $hook, $function_to_remove, $priority );
239
+    $function_to_remove = yourls_filter_unique_id($hook, $function_to_remove, $priority);
240 240
 
241
-    $remove = isset( $yourls_filters[ $hook ][ $priority ][ $function_to_remove ] );
241
+    $remove = isset($yourls_filters[$hook][$priority][$function_to_remove]);
242 242
 
243
-    if ( $remove === true ) {
244
-        unset ( $yourls_filters[ $hook ][ $priority ][ $function_to_remove ] );
245
-        if ( empty( $yourls_filters[ $hook ][ $priority ] ) ) {
246
-            unset( $yourls_filters[ $hook ] );
243
+    if ($remove === true) {
244
+        unset ($yourls_filters[$hook][$priority][$function_to_remove]);
245
+        if (empty($yourls_filters[$hook][$priority])) {
246
+            unset($yourls_filters[$hook]);
247 247
         }
248 248
     }
249 249
     return $remove;
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
  * @param int      $priority           optional. The priority of the function (default: 10).
259 259
  * @return bool                        Whether the function was registered as an action before it was removed.
260 260
  */
261
-function yourls_remove_action( $hook, $function_to_remove, $priority = 10 ) {
262
-    return yourls_remove_filter( $hook, $function_to_remove, $priority );
261
+function yourls_remove_action($hook, $function_to_remove, $priority = 10) {
262
+    return yourls_remove_filter($hook, $function_to_remove, $priority);
263 263
 }
264 264
 
265 265
 /**
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
  * @param int|false $priority optional. The priority of the functions to remove
272 272
  * @return bool true when it's finished
273 273
  */
274
-function yourls_remove_all_actions( $hook, $priority = false ) {
275
-    return yourls_remove_all_filters( $hook, $priority );
274
+function yourls_remove_all_actions($hook, $priority = false) {
275
+    return yourls_remove_all_filters($hook, $priority);
276 276
 }
277 277
 
278 278
 /**
@@ -283,15 +283,15 @@  discard block
 block discarded – undo
283 283
  * @param int|false $priority optional. The priority of the functions to remove
284 284
  * @return bool true when it's finished
285 285
  */
286
-function yourls_remove_all_filters( $hook, $priority = false ) {
286
+function yourls_remove_all_filters($hook, $priority = false) {
287 287
     global $yourls_filters;
288 288
 
289
-    if ( isset( $yourls_filters[ $hook ] ) ) {
290
-        if ( $priority === false ) {
291
-            unset( $yourls_filters[ $hook ] );
289
+    if (isset($yourls_filters[$hook])) {
290
+        if ($priority === false) {
291
+            unset($yourls_filters[$hook]);
292 292
         }
293
-        elseif ( isset( $yourls_filters[ $hook ][ $priority ] ) ) {
294
-            unset( $yourls_filters[ $hook ][ $priority ] );
293
+        elseif (isset($yourls_filters[$hook][$priority])) {
294
+            unset($yourls_filters[$hook][$priority]);
295 295
         }
296 296
     }
297 297
 
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
  * @return int|bool Optionally returns the priority on that hook for the specified function.
307 307
  * @global array         $yourls_filters    storage for all of the filters
308 308
  */
309
-function yourls_has_filter( $hook, $function_to_check = false ) {
309
+function yourls_has_filter($hook, $function_to_check = false) {
310 310
     global $yourls_filters;
311 311
 
312
-    $has = !empty( $yourls_filters[ $hook ] );
313
-    if ( false === $function_to_check || false === $has ) {
312
+    $has = !empty($yourls_filters[$hook]);
313
+    if (false === $function_to_check || false === $has) {
314 314
         return $has;
315 315
     }
316 316
 
317
-    if ( !$idx = yourls_filter_unique_id( $hook, $function_to_check, false ) ) {
317
+    if (!$idx = yourls_filter_unique_id($hook, $function_to_check, false)) {
318 318
         return false;
319 319
     }
320 320
 
321
-    foreach ( array_keys( $yourls_filters[ $hook ] ) as $priority ) {
322
-        if ( isset( $yourls_filters[ $hook ][ $priority ][ $idx ] ) ) {
321
+    foreach (array_keys($yourls_filters[$hook]) as $priority) {
322
+        if (isset($yourls_filters[$hook][$priority][$idx])) {
323 323
             return $priority;
324 324
         }
325 325
     }
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
  * @param callable|false $function_to_check
332 332
  * @return bool|int
333 333
  */
334
-function yourls_has_action( $hook, $function_to_check = false ) {
335
-    return yourls_has_filter( $hook, $function_to_check );
334
+function yourls_has_action($hook, $function_to_check = false) {
335
+    return yourls_has_filter($hook, $function_to_check);
336 336
 }
337 337
 
338 338
 /**
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
  * @return int Number of activated plugins
342 342
  */
343 343
 function yourls_has_active_plugins() {
344
-    return count( yourls_get_db()->get_plugins() );
344
+    return count(yourls_get_db()->get_plugins());
345 345
 }
346 346
 
347 347
 /**
@@ -350,16 +350,16 @@  discard block
 block discarded – undo
350 350
  * @return array Array of [/plugindir/plugin.php]=>array('Name'=>'Ozh', 'Title'=>'Hello', )
351 351
  */
352 352
 function yourls_get_plugins() {
353
-    $plugins = (array)glob( YOURLS_PLUGINDIR.'/*/plugin.php' );
353
+    $plugins = (array) glob(YOURLS_PLUGINDIR.'/*/plugin.php');
354 354
 
355
-    if ( is_array( $plugins ) ) {
356
-        foreach ( $plugins as $key => $plugin ) {
357
-            $plugins[ yourls_plugin_basename( $plugin ) ] = yourls_get_plugin_data( $plugin );
358
-            unset( $plugins[ $key ] );
355
+    if (is_array($plugins)) {
356
+        foreach ($plugins as $key => $plugin) {
357
+            $plugins[yourls_plugin_basename($plugin)] = yourls_get_plugin_data($plugin);
358
+            unset($plugins[$key]);
359 359
         }
360 360
     }
361 361
 
362
-    return empty( $plugins ) ? [] : $plugins;
362
+    return empty($plugins) ? [] : $plugins;
363 363
 }
364 364
 
365 365
 /**
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
  * @param string $plugin Physical path to plugin file
369 369
  * @return bool
370 370
  */
371
-function yourls_is_active_plugin( $plugin ) {
371
+function yourls_is_active_plugin($plugin) {
372 372
     return yourls_has_active_plugins() > 0 ?
373
-        in_array( yourls_plugin_basename( $plugin ), yourls_get_db()->get_plugins() )
373
+        in_array(yourls_plugin_basename($plugin), yourls_get_db()->get_plugins())
374 374
         : false;
375 375
 }
376 376
 
@@ -401,27 +401,27 @@  discard block
 block discarded – undo
401 401
  * @param string $file Physical path to plugin file
402 402
  * @return array Array of 'Field'=>'Value' from plugin comment header lines of the form "Field: Value"
403 403
  */
404
-function yourls_get_plugin_data( $file ) {
405
-    $fp = fopen( $file, 'r' ); // assuming $file is readable, since yourls_load_plugins() filters this
406
-    $data = fread( $fp, 8192 ); // get first 8kb
407
-    fclose( $fp );
404
+function yourls_get_plugin_data($file) {
405
+    $fp = fopen($file, 'r'); // assuming $file is readable, since yourls_load_plugins() filters this
406
+    $data = fread($fp, 8192); // get first 8kb
407
+    fclose($fp);
408 408
 
409 409
     // Capture all the header within first comment block
410
-    if ( !preg_match( '!.*?/\*(.*?)\*/!ms', $data, $matches ) )
410
+    if (!preg_match('!.*?/\*(.*?)\*/!ms', $data, $matches))
411 411
         return [];
412 412
 
413 413
     // Capture each line with "Something: some text"
414
-    unset( $data );
415
-    $lines = preg_split( "[\n|\r]", $matches[ 1 ] );
416
-    unset( $matches );
414
+    unset($data);
415
+    $lines = preg_split("[\n|\r]", $matches[1]);
416
+    unset($matches);
417 417
 
418 418
     $plugin_data = [];
419
-    foreach ( $lines as $line ) {
420
-        if ( !preg_match( '!(\s*)?\*?(\s*)?(.*?):\s+(.*)!', $line, $matches ) ) {
419
+    foreach ($lines as $line) {
420
+        if (!preg_match('!(\s*)?\*?(\s*)?(.*?):\s+(.*)!', $line, $matches)) {
421 421
             continue;
422 422
         }
423 423
 
424
-        $plugin_data[ trim($matches[3]) ] = yourls_esc_html(trim($matches[4]));
424
+        $plugin_data[trim($matches[3])] = yourls_esc_html(trim($matches[4]));
425 425
     }
426 426
 
427 427
     return $plugin_data;
@@ -440,15 +440,15 @@  discard block
 block discarded – undo
440 440
  */
441 441
 function yourls_load_plugins() {
442 442
     // Don't load plugins when installing or updating
443
-    if ( yourls_is_installing() OR yourls_is_upgrading() OR !yourls_is_installed() ) {
443
+    if (yourls_is_installing() OR yourls_is_upgrading() OR !yourls_is_installed()) {
444 444
         return [
445 445
             'loaded' => false,
446 446
             'info'   => 'install/upgrade'
447 447
         ];
448 448
     }
449 449
 
450
-    $active_plugins = (array)yourls_get_option( 'active_plugins' );
451
-    if ( empty( $active_plugins ) ) {
450
+    $active_plugins = (array) yourls_get_option('active_plugins');
451
+    if (empty($active_plugins)) {
452 452
         return [
453 453
             'loaded' => false,
454 454
             'info'   => 'no active plugin'
@@ -456,25 +456,25 @@  discard block
 block discarded – undo
456 456
     }
457 457
 
458 458
     $plugins = [];
459
-    foreach ( $active_plugins as $key => $plugin ) {
460
-        if ( yourls_validate_plugin_file( YOURLS_PLUGINDIR.'/'.$plugin ) ) {
461
-            include_once( YOURLS_PLUGINDIR.'/'.$plugin );
459
+    foreach ($active_plugins as $key => $plugin) {
460
+        if (yourls_validate_plugin_file(YOURLS_PLUGINDIR.'/'.$plugin)) {
461
+            include_once(YOURLS_PLUGINDIR.'/'.$plugin);
462 462
             $plugins[] = $plugin;
463
-            unset( $active_plugins[ $key ] );
463
+            unset($active_plugins[$key]);
464 464
         }
465 465
     }
466 466
 
467 467
     // Replace active plugin list with list of plugins we just activated
468
-    yourls_get_db()->set_plugins( $plugins );
469
-    $info = count( $plugins ).' activated';
468
+    yourls_get_db()->set_plugins($plugins);
469
+    $info = count($plugins).' activated';
470 470
 
471 471
     // $active_plugins should be empty now, if not, a plugin could not be find: remove it
472
-    $missing_count = count( $active_plugins );
473
-    if ( $missing_count > 0 ) {
474
-        yourls_update_option( 'active_plugins', $plugins );
475
-        $message = yourls_n( 'Could not find and deactivate plugin :', 'Could not find and deactivate plugins :', $missing_count );
476
-        $missing = '<strong>'.implode( '</strong>, <strong>', $active_plugins ).'</strong>';
477
-        yourls_add_notice( $message.' '.$missing );
472
+    $missing_count = count($active_plugins);
473
+    if ($missing_count > 0) {
474
+        yourls_update_option('active_plugins', $plugins);
475
+        $message = yourls_n('Could not find and deactivate plugin :', 'Could not find and deactivate plugins :', $missing_count);
476
+        $missing = '<strong>'.implode('</strong>, <strong>', $active_plugins).'</strong>';
477
+        yourls_add_notice($message.' '.$missing);
478 478
         $info .= ', '.$missing_count.' removed';
479 479
     }
480 480
 
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
  * @param string $file Full pathname to a file
491 491
  * @return bool
492 492
  */
493
-function yourls_validate_plugin_file( $file ) {
494
-    return false === strpos( $file, '..' )
495
-           && false === strpos( $file, './' )
496
-           && 'plugin.php' === substr( $file, -10 )
497
-           && is_readable( $file );
493
+function yourls_validate_plugin_file($file) {
494
+    return false === strpos($file, '..')
495
+           && false === strpos($file, './')
496
+           && 'plugin.php' === substr($file, -10)
497
+           && is_readable($file);
498 498
 }
499 499
 
500 500
 /**
@@ -503,37 +503,37 @@  discard block
 block discarded – undo
503 503
  * @param string $plugin Plugin filename (full or relative to plugins directory)
504 504
  * @return string|true  string if error or true if success
505 505
  */
506
-function yourls_activate_plugin( $plugin ) {
506
+function yourls_activate_plugin($plugin) {
507 507
     // validate file
508
-    $plugin = yourls_plugin_basename( $plugin );
509
-    $plugindir = yourls_sanitize_filename( YOURLS_PLUGINDIR );
510
-    if ( !yourls_validate_plugin_file( $plugindir.'/'.$plugin ) ) {
511
-        return yourls__( 'Not a valid plugin file' );
508
+    $plugin = yourls_plugin_basename($plugin);
509
+    $plugindir = yourls_sanitize_filename(YOURLS_PLUGINDIR);
510
+    if (!yourls_validate_plugin_file($plugindir.'/'.$plugin)) {
511
+        return yourls__('Not a valid plugin file');
512 512
     }
513 513
 
514 514
     // check not activated already
515 515
     $ydb = yourls_get_db();
516
-    if ( yourls_is_active_plugin( $plugin ) ) {
517
-        return yourls__( 'Plugin already activated' );
516
+    if (yourls_is_active_plugin($plugin)) {
517
+        return yourls__('Plugin already activated');
518 518
     }
519 519
 
520 520
     // attempt activation. TODO: uber cool fail proof sandbox like in WP.
521 521
     ob_start();
522
-    include_once( $plugindir.'/'.$plugin );
523
-    if ( ob_get_length() > 0 ) {
522
+    include_once($plugindir.'/'.$plugin);
523
+    if (ob_get_length() > 0) {
524 524
         // there was some output: error
525 525
         // @codeCoverageIgnoreStart
526 526
         $output = ob_get_clean();
527
-        return yourls_s( 'Plugin generated unexpected output. Error was: <br/><pre>%s</pre>', $output );
527
+        return yourls_s('Plugin generated unexpected output. Error was: <br/><pre>%s</pre>', $output);
528 528
         // @codeCoverageIgnoreEnd
529 529
     }
530 530
     ob_end_clean();
531 531
 
532 532
     // so far, so good: update active plugin list
533
-    $ydb->add_plugin( $plugin );
534
-    yourls_update_option( 'active_plugins', $ydb->get_plugins() );
535
-    yourls_do_action( 'activated_plugin', $plugin );
536
-    yourls_do_action( 'activated_'.$plugin );
533
+    $ydb->add_plugin($plugin);
534
+    yourls_update_option('active_plugins', $ydb->get_plugins());
535
+    yourls_do_action('activated_plugin', $plugin);
536
+    yourls_do_action('activated_'.$plugin);
537 537
 
538 538
     return true;
539 539
 }
@@ -544,26 +544,26 @@  discard block
 block discarded – undo
544 544
  * @param string $plugin Plugin filename (full relative to plugins directory)
545 545
  * @return string|true  string if error or true if success
546 546
  */
547
-function yourls_deactivate_plugin( $plugin ) {
548
-    $plugin = yourls_plugin_basename( $plugin );
547
+function yourls_deactivate_plugin($plugin) {
548
+    $plugin = yourls_plugin_basename($plugin);
549 549
 
550 550
     // Check plugin is active
551
-    if ( !yourls_is_active_plugin( $plugin ) ) {
552
-        return yourls__( 'Plugin not active' );
551
+    if (!yourls_is_active_plugin($plugin)) {
552
+        return yourls__('Plugin not active');
553 553
     }
554 554
 
555 555
     // Deactivate the plugin
556 556
     global $ydb;
557 557
     $plugins = $ydb->get_plugins();
558
-    $key = array_search( $plugin, $plugins );
559
-    if ( $key !== false ) {
560
-        array_splice( $plugins, $key, 1 );
558
+    $key = array_search($plugin, $plugins);
559
+    if ($key !== false) {
560
+        array_splice($plugins, $key, 1);
561 561
     }
562 562
 
563
-    $ydb->set_plugins( $plugins );
564
-    yourls_update_option( 'active_plugins', $plugins );
565
-    yourls_do_action( 'deactivated_plugin', $plugin );
566
-    yourls_do_action( 'deactivated_'.$plugin );
563
+    $ydb->set_plugins($plugins);
564
+    yourls_update_option('active_plugins', $plugins);
565
+    yourls_do_action('deactivated_plugin', $plugin);
566
+    yourls_do_action('deactivated_'.$plugin);
567 567
 
568 568
     return true;
569 569
 }
@@ -573,8 +573,8 @@  discard block
 block discarded – undo
573 573
  * @param string $file
574 574
  * @return string
575 575
  */
576
-function yourls_plugin_basename( $file ) {
577
-	return trim( str_replace( yourls_sanitize_filename( YOURLS_PLUGINDIR ), '', yourls_sanitize_filename( $file ) ), '/' );
576
+function yourls_plugin_basename($file) {
577
+	return trim(str_replace(yourls_sanitize_filename(YOURLS_PLUGINDIR), '', yourls_sanitize_filename($file)), '/');
578 578
 }
579 579
 
580 580
 /**
@@ -582,12 +582,12 @@  discard block
 block discarded – undo
582 582
  * @param string $file
583 583
  * @return string
584 584
  */
585
-function yourls_plugin_url( $file ) {
586
-    $url = YOURLS_PLUGINURL.'/'.yourls_plugin_basename( $file );
587
-    if ( yourls_is_ssl() or yourls_needs_ssl() ) {
588
-        $url = str_replace( 'http://', 'https://', $url );
585
+function yourls_plugin_url($file) {
586
+    $url = YOURLS_PLUGINURL.'/'.yourls_plugin_basename($file);
587
+    if (yourls_is_ssl() or yourls_needs_ssl()) {
588
+        $url = str_replace('http://', 'https://', $url);
589 589
     }
590
-    return (string)yourls_apply_filter( 'plugin_url', $url, $file );
590
+    return (string) yourls_apply_filter('plugin_url', $url, $file);
591 591
 }
592 592
 
593 593
 /**
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
  */
598 598
 function yourls_list_plugin_admin_pages() {
599 599
     $plugin_links = [];
600
-    foreach ( yourls_get_db()->get_plugin_pages() as $plugin => $page ) {
601
-        $plugin_links[ $plugin ] = [
602
-            'url'    => yourls_admin_url( 'plugins.php?page='.$page[ 'slug' ] ),
603
-            'anchor' => $page[ 'title' ],
600
+    foreach (yourls_get_db()->get_plugin_pages() as $plugin => $page) {
601
+        $plugin_links[$plugin] = [
602
+            'url'    => yourls_admin_url('plugins.php?page='.$page['slug']),
603
+            'anchor' => $page['title'],
604 604
         ];
605 605
     }
606 606
     return $plugin_links;
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
  * @param string   $title
613 613
  * @param callable $function
614 614
  */
615
-function yourls_register_plugin_page( $slug, $title, $function ) {
616
-    yourls_get_db()->add_plugin_page( $slug, $title, $function );
615
+function yourls_register_plugin_page($slug, $title, $function) {
616
+    yourls_get_db()->add_plugin_page($slug, $title, $function);
617 617
 }
618 618
 
619 619
 /**
@@ -621,20 +621,20 @@  discard block
 block discarded – undo
621 621
  *
622 622
  * @param string $plugin_page
623 623
  */
624
-function yourls_plugin_admin_page( $plugin_page ) {
624
+function yourls_plugin_admin_page($plugin_page) {
625 625
     // Check the plugin page is actually registered
626 626
     $pages = yourls_get_db()->get_plugin_pages();
627
-    if ( !isset( $pages[ $plugin_page ] ) ) {
628
-        yourls_die( yourls__( 'This page does not exist. Maybe a plugin you thought was activated is inactive?' ), yourls__( 'Invalid link' ) );
627
+    if (!isset($pages[$plugin_page])) {
628
+        yourls_die(yourls__('This page does not exist. Maybe a plugin you thought was activated is inactive?'), yourls__('Invalid link'));
629 629
     }
630 630
 
631 631
     // Draw the page itself
632
-    yourls_do_action( 'load-'.$plugin_page );
633
-    yourls_html_head( 'plugin_page_'.$plugin_page, $pages[ $plugin_page ][ 'title' ] );
632
+    yourls_do_action('load-'.$plugin_page);
633
+    yourls_html_head('plugin_page_'.$plugin_page, $pages[$plugin_page]['title']);
634 634
     yourls_html_logo();
635 635
     yourls_html_menu();
636 636
 
637
-    call_user_func( $pages[ $plugin_page ][ 'function' ] );
637
+    call_user_func($pages[$plugin_page]['function']);
638 638
 
639 639
     yourls_html_footer();
640 640
 }
@@ -649,22 +649,22 @@  discard block
 block discarded – undo
649 649
  * @param array $plugin_b
650 650
  * @return int 0, 1 or -1, see uasort()
651 651
  */
652
-function yourls_plugins_sort_callback( $plugin_a, $plugin_b ) {
653
-    $orderby = yourls_apply_filter( 'plugins_sort_callback', 'Plugin Name' );
654
-    $order = yourls_apply_filter( 'plugins_sort_callback', 'ASC' );
652
+function yourls_plugins_sort_callback($plugin_a, $plugin_b) {
653
+    $orderby = yourls_apply_filter('plugins_sort_callback', 'Plugin Name');
654
+    $order = yourls_apply_filter('plugins_sort_callback', 'ASC');
655 655
 
656
-    $a = isset( $plugin_a[ $orderby ] ) ? $plugin_a[ $orderby ] : '';
657
-    $b = isset( $plugin_b[ $orderby ] ) ? $plugin_b[ $orderby ] : '';
656
+    $a = isset($plugin_a[$orderby]) ? $plugin_a[$orderby] : '';
657
+    $b = isset($plugin_b[$orderby]) ? $plugin_b[$orderby] : '';
658 658
 
659
-    if ( $a == $b ) {
659
+    if ($a == $b) {
660 660
         return 0;
661 661
     }
662 662
 
663
-    if ( 'DESC' == $order ) {
664
-        return ( $a < $b ) ? 1 : -1;
663
+    if ('DESC' == $order) {
664
+        return ($a < $b) ? 1 : -1;
665 665
     }
666 666
     else {
667
-        return ( $a < $b ) ? -1 : 1;
667
+        return ($a < $b) ? -1 : 1;
668 668
     }
669 669
 }
670 670
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
  * @return void
686 686
  */
687 687
 function yourls_shutdown() {
688
-    yourls_do_action( 'shutdown' );
688
+    yourls_do_action('shutdown');
689 689
 }
690 690
 
691 691
 /**
Please login to merge, or discard this patch.