Skip to content

Commit 9854d0e

Browse files
committed
Add a secondary capability for search-purposes, and more verbose notices if editing (and now searching) are unavailable due to missing capabilities.
1 parent bb7c66d commit 9854d0e

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

includes/Base/class-rest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct() {
2828
* @return bool
2929
*/
3030
public function permission_callback() {
31-
return current_user_can( String_Locator::$default_capability );
31+
return current_user_can( String_Locator::$search_capability );
3232
}
3333

3434
}

includes/class-string-locator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ class String_Locator {
2020
*/
2121
public static $default_capability = 'edit_themes';
2222

23+
/**
24+
* The capability required to perform searches, but not necessarily edit files.
25+
*
26+
* We use the `edit_users` capability here, although this is not technically the most ideal,
27+
* all other relevant capabilities are disabled in one way or another when certain features
28+
* are used to disable things like the plugin or theme editing.
29+
*
30+
* The use of `edit_users` may also cause other problems, but we do not want to allow any user
31+
* access to search the entire filesystem, or database, without some sort of restriction.
32+
*
33+
* @var string
34+
*/
35+
public static $search_capability = 'edit_users';
36+
2337
/**
2438
* An array containing all notices to display.
2539
*

views/search.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<?php do_action( 'string_locator_view_search_pre_form' ); ?>
4242

43-
<?php if ( ! current_user_can( 'edit_themes' ) ) : ?>
43+
<?php if ( ! current_user_can( String_Locator::$default_capability ) ) : ?>
4444
<div class="notice notice-warning inline">
4545
<p>
4646
<strong>
@@ -50,6 +50,26 @@
5050
<p>
5151
<?php esc_html_e( 'Because this site is configured to not allow direct file editing, the String Locator plugin has limited functionality and may noy allow you to directly edit files with your string in them.', 'string-locator' ); ?>
5252
</p>
53+
<p>
54+
<?php esc_html_e( sprintf( 'To edit files, you need to have the `%s` capability.', String_Locator::$default_capability ), 'string-locator' ); ?>
55+
</p>
56+
</div>
57+
<?php endif; ?>
58+
59+
<?php if ( ! current_user_can( String_Locator::$search_capability ) ) : ?>
60+
<div class="notice notice-warning inline">
61+
<p>
62+
<strong>
63+
<?php esc_html_e( 'String Locator is restricted.', 'string-locator' ); ?>
64+
</strong>
65+
</p>
66+
<p>
67+
<?php esc_html_e( 'Your user does not have the needed capabilities to edit, or search through files on this site.', 'string-locator' ); ?>
68+
</p>
69+
70+
<p>
71+
<?php esc_html_e( sprintf( 'To use the search feature, you need to have the `%s` capability.', String_Locator::$search_capability ), 'string-locator' ); ?>
72+
</p>
5373
</div>
5474
<?php endif; ?>
5575

0 commit comments

Comments
 (0)