Skip to content

Commit ba8c206

Browse files
committed
feat: Refactoring of command names and arguments
1 parent 4cb8a0a commit ba8c206

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

src/SecureCommand.php

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class SecureCommand extends WP_CLI_Command {
7979
* $ wp secure disable_directory_browsing
8080
* Success: Directory Browsing security rule is now active.
8181
*
82+
* @subcommand disable-directory-browsing
83+
*
8284
* @when before_wp_load
8385
*/
8486
public function disable_directory_browsing($args, $assoc_args) : void {
@@ -121,15 +123,15 @@ public function disable_directory_browsing($args, $assoc_args) : void {
121123
*
122124
* @when before_wp_load
123125
*
124-
* @subcommand block-php
126+
* @subcommand block-php-execution
125127
*/
126128
public function block_php($args, $assoc_args) : void {
127129

128130
$block_part = $args[0];
129131

130132
// Failure first.
131133
if ( ! in_array( $block_part,
132-
array( 'plugins', 'uploads', 'includes', 'themes', 'all' ),
134+
array( 'plugins', 'uploads', 'wp-includes', 'themes', 'all' ),
133135
true )
134136
) {
135137
WP_CLI::error( sprintf( 'Invalid block part "%s" was provided. Allowed values are "plugins", "uploads", "includes", "themes" or "all"',
@@ -142,11 +144,11 @@ public function block_php($args, $assoc_args) : void {
142144
}
143145
if ( 'all' === $block_part || 'uploads' === $block_part ) {
144146
WP_CLI::debug( 'Securing the uploads folder.', 'secure');
145-
( new BlockPhpExecutionInWpIncludes( $assoc_args ) )->output();
147+
( new BlockPhpExecutionInUploads( $assoc_args ) )->output();
146148
}
147-
if ( 'all' === $block_part || 'includes' === $block_part ) {
149+
if ( 'all' === $block_part || 'wp-includes' === $block_part ) {
148150
WP_CLI::debug( 'Securing the includes folder.', 'secure');
149-
( new BlockPhpExecutionInUploads( $assoc_args ) )->output();
151+
( new BlockPhpExecutionInWpIncludes( $assoc_args ) )->output();
150152
}
151153
if ( 'all' === $block_part || 'themes' === $block_part ) {
152154
WP_CLI::debug( 'Securing the themes folder.', 'secure');
@@ -155,14 +157,14 @@ public function block_php($args, $assoc_args) : void {
155157
}
156158

157159
/**
158-
* Blocks direct access to sensitive files.
160+
* Blocks direct access to various sensitive files and directories
159161
*
160162
* Blocks direct access to readme.html, readme.txt, wp-config.php and wp-admin/install.php files.
161163
*
162164
* ## OPTIONS
163165
*
164166
* <block-part>
165-
* : Required. accepts: files, directories, htaccess, xmlrpc or all.
167+
* : This option is required. Accepts one of the following values: sensitive-files, sensitive-directories, htaccess, xmlrpc or all.
166168
*
167169
* [--remove]
168170
* : Removes the rule from .htaccess or nginx.conf.
@@ -195,15 +197,15 @@ public function block_access($args, $assoc_args): void {
195197
$block_part = $args[0];
196198

197199
// Failure first.
198-
if ( ! in_array( $block_part, array( 'files', 'directories', 'htaccess', 'xmlrpc', 'all' ), true ) ) {
200+
if ( ! in_array( $block_part, array( 'sensitive-files', 'sensitive-directories', 'htaccess', 'xmlrpc', 'all' ), true ) ) {
199201
WP_CLI::error( sprintf( 'Invalid block part "%s" was provided. Allowed values are "files", "directories", "htaccess", "xmlrpc" or "all"', $block_part ) );
200202
}
201203

202-
if ( 'all' === $block_part || 'files' === $block_part ) {
204+
if ( 'all' === $block_part || 'sensitive-files' === $block_part ) {
203205
WP_CLI::debug( 'Blocking access to the sensitive files.', 'secure');
204206
(new BlockAccessToSensitiveFiles($assoc_args))->output();
205207
}
206-
if ( 'all' === $block_part || 'directories' === $block_part ) {
208+
if ( 'all' === $block_part || 'sensitive-directories' === $block_part ) {
207209
WP_CLI::debug( 'Blocking access to the directories.', 'secure');
208210
( new BlockAccessToSensitiveDirectories( $assoc_args ) )->output();
209211
}
@@ -217,15 +219,6 @@ public function block_access($args, $assoc_args): void {
217219
}
218220
}
219221

220-
/**
221-
* Blocks direct access to sensitive directories.
222-
*
223-
* Blocks direct access to files in .git, svn and vendor directories
224-
*/
225-
public function block_access_to_sensitive_directories($args, $assoc_args) : void {
226-
227-
}
228-
229222
/**
230223
* Blocks author scanning
231224
*
@@ -252,6 +245,8 @@ public function block_access_to_sensitive_directories($args, $assoc_args) : void
252245
* $ wp secure block_author_scanning
253246
* Success: Block Author Scanning rule has been deployed.
254247
*
248+
* @subcommand block-author-scanning
249+
*
255250
* @when before_wp_load
256251
*/
257252
public function block_author_scanning($args, $assoc_args) : void {
@@ -297,30 +292,28 @@ public function flush($args, $assoc_args) : void {
297292
*
298293
* @return void
299294
*
295+
* @subcommand integrity-scan
300296
* @when before_wp_load
301297
*/
302298
public function integrityscan($args, $assoc_args) : void {
303299
WP_CLI::runcommand('core verify-checksums');
304300
}
305301

306302
/**
307-
* Disable the file editor in Wordpress.
303+
* Disable the file editor in WordPress
308304
*
309-
* @return void
310-
*/
311-
public function disable_file_editor() : void {
312-
WP_CLI::runcommand('config set DISALLOW_FILE_EDIT true');
313-
}
314-
315-
/**
316-
* Enable the file editor in Wordpress.
305+
* @subcommand disable-directory-browsing
317306
*
307+
* @param $args
308+
* @param $assoc_args
309+
*
310+
* @when before_wp_load
318311
* @return void
319312
*/
320-
public function allow_file_editor() : void {
321-
WP_CLI::runcommand('config set DISALLOW_FILE_EDIT false');
313+
public function disable_file_editor($args, $assoc_args) : void {
314+
WP_CLI::runcommand('config set DISALLOW_FILE_EDIT' . !isset($assoc_args['remove']));
322315
}
323-
}
316+
324317
/**
325318
* Fix all directory and file permissions of the wordpress installation
326319
*
@@ -332,10 +325,12 @@ public function allow_file_editor() : void {
332325
* $ wp secure fix_permissions
333326
* Success: All permission are reset to wordpress default.
334327
*
328+
* @subcommand fix-permissions
335329
* @when before_wp_load
336330
*/
337331
public function fix_permissions($args, $assoc_args) : void {
338332
(new FixFileAndDirPermissions($assoc_args))->fixPermissions();
333+
339334
WP_CLI::success("Permission successfully updated.");
340335
}
341336
}

0 commit comments

Comments
 (0)