Skip to content

Commit 025efb4

Browse files
jrfnlschlessera
authored andcommitted
QA: abstract a 3x duplicate closure to a function (#76)
* QA: abstract a 3x duplicate closure to a function By the time the same code is used three times, it really shouldn't be a closure anymore, but a proper function. * Turn stand-alone function into a closure
1 parent a97a6cc commit 025efb4

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

language-command.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,22 @@
1010
require_once $wpcli_language_autoloader;
1111
}
1212

13+
$wpcli_language_check_requirements = function() {
14+
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
15+
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
16+
}
17+
};
18+
1319
WP_CLI::add_command( 'language core', 'Core_Language_Command', array(
14-
'before_invoke' => function() {
15-
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
16-
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
17-
}
18-
})
20+
'before_invoke' => $wpcli_language_check_requirements )
1921
);
2022

2123
WP_CLI::add_command( 'language plugin', 'Plugin_Language_Command', array(
22-
'before_invoke' => function() {
23-
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
24-
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
25-
}
26-
})
24+
'before_invoke' => $wpcli_language_check_requirements )
2725
);
2826

2927
WP_CLI::add_command( 'language theme', 'Theme_Language_Command', array(
30-
'before_invoke' => function() {
31-
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
32-
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
33-
}
34-
})
28+
'before_invoke' => $wpcli_language_check_requirements )
3529
);
3630

3731
WP_CLI::add_hook( 'after_add_command:site', function () {

0 commit comments

Comments
 (0)