Skip to content

Commit 102919f

Browse files
authored
Merge pull request #29 from WebDevStudios/feature/coding-standards-fixes
Clean up some things, update docblocks, etc
2 parents c7c6611 + de14abf commit 102919f

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed

wds-required-plugins.php

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @subpackage Project
3131
* @since Unknown
3232
*/
33-
class WDS_Required_Plugins {
33+
final class WDS_Required_Plugins {
3434

3535
/**
3636
* Instance of this class.
@@ -45,7 +45,7 @@ class WDS_Required_Plugins {
4545
/**
4646
* Whether text-domain has been registered.
4747
*
48-
* @var boolean
48+
* @var bool
4949
*
5050
* @author Justin Sternberg
5151
* @since Unknown
@@ -83,7 +83,7 @@ class WDS_Required_Plugins {
8383
*
8484
* @var array
8585
*/
86-
public $incompatibilities = array();
86+
public $incompatibilities = [];
8787

8888
/**
8989
* Creates or returns an instance of this class.
@@ -107,27 +107,26 @@ public static function init() {
107107
* @since 0.1.0
108108
* @author Unknown
109109
*
110-
* @return void
111110
*/
112111
private function __construct() {
113112
if ( $this->incompatible() ) {
114113
return;
115114
}
116115

117116
// Attempt activation + load text domain in the admin.
118-
add_action( 'admin_init', array( $this, 'activate_if_not' ) );
119-
add_action( 'admin_init', array( $this, 'required_text_markup' ) );
120-
add_filter( 'extra_plugin_headers', array( $this, 'add_required_plugin_header' ) );
117+
add_action( 'admin_init', [ $this, 'activate_if_not' ] );
118+
add_action( 'admin_init', [ $this, 'required_text_markup' ] );
119+
add_filter( 'extra_plugin_headers', [ $this, 'add_required_plugin_header' ] );
121120

122121
// Filter plugin links to remove deactivate option.
123-
add_filter( 'plugin_action_links', array( $this, 'filter_plugin_links' ), 10, 2 );
124-
add_filter( 'network_admin_plugin_action_links', array( $this, 'filter_plugin_links' ), 10, 2 );
122+
add_filter( 'plugin_action_links', [ $this, 'filter_plugin_links' ], 10, 2 );
123+
add_filter( 'network_admin_plugin_action_links', [ $this, 'filter_plugin_links' ], 10, 2 );
125124

126125
// Remove plugins from the plugins.
127-
add_filter( 'all_plugins', array( $this, 'maybe_remove_plugins_from_list' ) );
126+
add_filter( 'all_plugins', [ $this, 'maybe_remove_plugins_from_list' ] );
128127

129128
// Load text domain.
130-
add_action( 'plugins_loaded', array( $this, 'l10n' ) );
129+
add_action( 'plugins_loaded', [ $this, 'l10n' ] );
131130
}
132131

133132
/**
@@ -136,18 +135,18 @@ private function __construct() {
136135
* @author Aubrey Portwood
137136
* @since 1.0.0
138137
*
139-
* @return boolean True if we are incompatible with something, false if not.
138+
* @return bool True if we are incompatible with something, false if not.
140139
*/
141140
public function incompatible() {
142141

143142
// Our tests.
144-
$this->incompatibilities = array(
143+
$this->incompatibilities = [
145144

146145
/*
147146
* WP Migrate DB Pro is performing an AJAX migration.
148147
*/
149148
(bool) $this->is_wpmdb(),
150-
);
149+
];
151150

152151
/**
153152
* Add or filter your incompatibility tests here.
@@ -177,7 +176,7 @@ public function incompatible() {
177176
* @author Aubrey Portwood
178177
* @since 1.0.0
179178
*
180-
* @return boolean True if we find wpmdb set as the action.
179+
* @return bool True if we find wpmdb set as the action.
181180
*/
182181
public function is_wpmdb() {
183182

@@ -190,7 +189,6 @@ public function is_wpmdb() {
190189
*
191190
* @since 0.1.1
192191
* @author Unknown
193-
* @return void Early bails when we don't need to activate it.
194192
*/
195193
public function activate_if_not() {
196194

@@ -225,10 +223,8 @@ public function activate_if_not() {
225223
* @author Aubrey Portwood <aubrey@webdevstudios.com>
226224
* @since 1.0.1 Added Exception if plugin not found.
227225
*
228-
* @param string $plugin The plugin to activate.
229-
* @param boolean $network Whether we are activating a network-required plugin.
230-
*
231-
* @return void
226+
* @param string $plugin The plugin to activate.
227+
* @param bool $network Whether we are activating a network-required plugin.
232228
*
233229
* @throws Exception If we can't activate a required plugin.
234230
*/
@@ -243,9 +239,9 @@ public function maybe_activate_plugin( $plugin, $network = false ) {
243239
* @author Justin Sternberg
244240
* @since Unknown
245241
*
246-
* @param boolean $auto_activate Should we auto-activate the plugin, true by default.
247-
* @param string $plugin The plugin being activated.
248-
* @param string $network On what network?
242+
* @param bool $auto_activate Should we auto-activate the plugin, true by default.
243+
* @param string $plugin The plugin being activated.
244+
* @param string $network On what network?
249245
*/
250246
$auto_activate = apply_filters( 'wds_required_plugin_auto_activate', true, $plugin, $network );
251247
if ( ! $auto_activate ) {
@@ -260,9 +256,9 @@ public function maybe_activate_plugin( $plugin, $network = false ) {
260256
* @author Justin Sternberg
261257
* @since Unknown
262258
*
263-
* @param boolean $is_multisite The value of is_multisite().
264-
* @param string $plugin The plugin being activated.
265-
* @param string $network The network.
259+
* @param bool $is_multisite The value of is_multisite().
260+
* @param string $plugin The plugin being activated.
261+
* @param string $network The network.
266262
*/
267263
$is_multisite = apply_filters( 'wds_required_plugin_network_activate', is_multisite(), $plugin, $network );
268264

@@ -306,10 +302,10 @@ public function maybe_activate_plugin( $plugin, $network = false ) {
306302
* @author Justin Sternberg
307303
* @since Unknown
308304
*
309-
* @param boolean $log_not_found Whether the plugin is indeed found or not,
310-
* default to true in the normal case. Set to false
311-
* if you would like to override that and not log it,
312-
* for instance, if it's intentional.
305+
* @param bool $log_not_found Whether the plugin is indeed found or not,
306+
* default to true in the normal case. Set to false
307+
* if you would like to override that and not log it,
308+
* for instance, if it's intentional.
313309
*/
314310
$log_not_found = apply_filters( 'wds_required_plugin_log_if_not_found', true, $plugin, $result, $network );
315311

@@ -335,7 +331,7 @@ public function maybe_activate_plugin( $plugin, $network = false ) {
335331
* @since 1.1.0
336332
* @author Aubrey Portwood <aubrey@webdevstudios.com>
337333
*
338-
* @param boolean $stop_not_found Set to false to not halt execution if a plugin is not found.
334+
* @param bool $stop_not_found Set to false to not halt execution if a plugin is not found.
339335
*/
340336
$stop_not_found = apply_filters( 'wds_required_plugin_stop_if_not_found', false, $plugin, $result, $network );
341337

@@ -383,25 +379,25 @@ public function required_text_markup() {
383379
*
384380
* @since 0.1.0
385381
*
386-
* @param array $actions Array of actions avaible.
387-
* @param string $plugin Slug of plugin.
382+
* @param array $actions Array of actions avaible.
383+
* @param string $plugin Slug of plugin.
388384
*
389385
* @author Justin Sternberg
390386
* @author Brad Parbs
391387
* @author Aubrey Portwood Added documentation for filters.
392388
*
393389
* @return array
394390
*/
395-
public function filter_plugin_links( $actions = array(), $plugin ) {
391+
public function filter_plugin_links( $actions = [], $plugin ) {
396392

397393
// Get our required plugins for network + normal.
398394
$required_plugins = array_unique( array_merge( $this->get_required_plugins(), $this->get_network_required_plugins() ) );
399395

400396
// Replace these action keys with what we have set for required text.
401-
$action_keys = array(
397+
$action_keys = [
402398
'deactivate',
403399
'network_active',
404-
);
400+
];
405401

406402
foreach ( $action_keys as $key ) {
407403

@@ -414,8 +410,8 @@ public function filter_plugin_links( $actions = array(), $plugin ) {
414410
* @author Brad Parbs
415411
* @since Unknown
416412
*
417-
* @param boolean $remove Should we remove it? Default to true.
418-
* @param string $plugin What plugin we're talking about.
413+
* @param bool $remove Should we remove it? Default to true.
414+
* @param string $plugin What plugin we're talking about.
419415
*/
420416
$wds_required_plugin_network_activate = apply_filters( 'wds_required_plugin_network_activate', true, $plugin );
421417

@@ -440,8 +436,8 @@ public function filter_plugin_links( $actions = array(), $plugin ) {
440436
* @author Brad Parbs
441437
* @author Aubrey Portwood Made it so mu-plugins are also unseen.
442438
*
443-
* @param array $plugins Array of plugins.
444-
* @return array Array of plugins.
439+
* @param array $plugins Array of plugins.
440+
* @return array Array of plugins.
445441
*/
446442
public function maybe_remove_plugins_from_list( $plugins ) {
447443

@@ -512,11 +508,11 @@ public function get_required_plugins() {
512508
*
513509
* @var array
514510
*/
515-
$required_plugins = apply_filters( 'wds_required_plugins', array() );
511+
$required_plugins = apply_filters( 'wds_required_plugins', [] );
516512
if ( ! is_array( $required_plugins ) ) {
517513

518514
// The person who filtered this broke it.
519-
return array();
515+
return [];
520516
}
521517

522518
$required_plugins = array_merge( $required_plugins, $this->get_header_required_plugins() );
@@ -559,11 +555,11 @@ public function get_network_required_plugins() {
559555
*
560556
* @var array
561557
*/
562-
$required_plugins = apply_filters( 'wds_network_required_plugins', array() );
558+
$required_plugins = apply_filters( 'wds_network_required_plugins', [] );
563559
if ( ! is_array( $required_plugins ) ) {
564560

565561
// The person who filtered this broke it.
566-
return array();
562+
return [];
567563
}
568564

569565
return $required_plugins;
@@ -576,7 +572,6 @@ public function get_network_required_plugins() {
576572
* @author Brad Parbs
577573
* @since 0.1.1
578574
*
579-
* @return void Early bails when it's un-necessary.
580575
*/
581576
public function l10n() {
582577

@@ -620,7 +615,7 @@ public function l10n() {
620615

621616
// If we still didn't load, assume our text domain is right where we are.
622617
$locale = apply_filters( 'plugin_locale', get_locale(), 'wds-required-plugins' );
623-
$mofile = dirname( __FILE__ ) . '/languages/wds-required-plugins-' . $locale . '.mo';
618+
$mofile = __DIR__ . '/languages/wds-required-plugins-' . $locale . '.mo';
624619
load_textdomain( 'wds-required-plugins', $mofile );
625620
self::$l10n_done = true;
626621
}
@@ -631,7 +626,7 @@ public function l10n() {
631626
* @since 1.2.0
632627
* @author Zach Owen
633628
*
634-
* @param array $extra_headers Extra headers filtered in WP core.
629+
* @param array $extra_headers Extra headers filtered in WP core.
635630
* @return array
636631
*/
637632
public function add_required_plugin_header( $extra_headers ) {

0 commit comments

Comments
 (0)