PluginProbe
Parse.ly / 3.24.2
Parse.ly v3.24.2
3.24.3 3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 All 107 releases
← All changes | src/class-permissions.php +22 -12 3.19.1 → 3.24.2 View file →
@@ -9,8 +9,10 @@
9 9 declare(strict_types=1);
10 10
11 11 namespace Parsely;
12 12
13 +use Parsely\Content_Helper\Suggestion_Defaults;
14 +
13 15 /**
14 16 * Class implementing user/role permissions functionality.
15 17 *
16 18 * @since 3.16.0
@@ -44,14 +46,15 @@
44 46 }
45 47
46 48 /**
47 49 * Returns whether the current user has the permission to access the
48 - * specified Content Helper feature.
50 + * specified Content Intelligence feature.
49 51 *
50 52 * @since 3.16.0
53 + * @since 3.24.2 Post-specific checks always require the `edit_post` capability.
51 54 *
52 55 * @param string $feature_name The feature's name.
53 - * @param Parsely_Options_Content_Helper $pch_options The Content Helper options.
56 + * @param Parsely_Options_Content_Helper $pch_options The Content Intelligence options.
54 57 * @param int|false $post_id The post ID, if the check is for a specific post.
55 58 * @return bool Whether the current user can access the specified feature.
56 59 */
57 60 public static function current_user_can_use_pch_feature(
@@ -58,8 +61,14 @@
58 61 string $feature_name,
59 62 $pch_options,
60 63 $post_id = false
61 64 ): bool {
65 + // Post-specific checks always require edit access, whatever the filter
66 + // below returns.
67 + if ( (int) $post_id > 0 && ! current_user_can( 'edit_post', (int) $post_id ) ) {
68 + return false;
69 + }
70 +
62 71 if ( isset( $pch_options[ $feature_name ] ) ) {
63 72 /**
64 73 * The feature's options.
65 74 *
@@ -73,12 +82,13 @@
73 82 $current_user = wp_get_current_user();
74 83 $user_roles = $current_user->roles;
75 84
76 85 /**
77 - * Filters whether the current user can use the specified Content Helper
78 - * feature.
86 + * Filters whether the current user can use the specified Content
87 + * Intelligence feature.
79 88 *
80 89 * This filter can be used to override the default permissions check.
90 + * It cannot grant access to a post that the user cannot edit.
81 91 *
82 92 * @since 3.16.2
83 93 *
84 94 * @param ?bool $current_user_can_use_pch_feature Whether the current user can use the feature.
@@ -138,19 +148,14 @@
138 148 if ( 0 === count( array_intersect( $user_roles, $allowed_roles ) ) ) {
139 149 return false;
140 150 }
141 151
142 - // Check if the user can edit the post.
143 - if ( (int) $post_id > 0 ) {
144 - return current_user_can( 'edit_post', $post_id );
145 - }
146 -
147 152 return true;
148 153 }
149 154
150 155 /**
151 - * Returns a JSON-encoded string with the Content Helper permissions for the
152 - * current user.
156 + * Returns a JSON-encoded string with the Content Intelligence permissions
157 + * for the current user.
153 158 *
154 159 * @since 3.16.0
155 160 *
156 161 * @param Parsely_Options_Content_Helper $pch_options The options to check against.
@@ -178,9 +183,9 @@
178 183 return is_string( $result ) ? $result : '{}';
179 184 }
180 185
181 186 /**
182 - * Builds and returns a permissions settings array for the Content Helper,
187 + * Builds and returns a permissions settings array for Content Intelligence,
183 188 * based on the passed values.
184 189 *
185 190 * @since 3.16.0
186 191 *
@@ -200,12 +205,17 @@
200 205 ),
201 206 'title_suggestions' => array(
202 207 'enabled' => $enabled,
203 208 'allowed_user_roles' => $allowed_user_roles,
209 + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE,
210 + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA,
204 211 ),
205 212 'excerpt_suggestions' => array(
206 213 'enabled' => $enabled,
207 214 'allowed_user_roles' => $allowed_user_roles,
215 + 'default_length' => Suggestion_Defaults::DEFAULT_LENGTH,
216 + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE,
217 + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA,
208 218 ),
209 219 'traffic_boost' => array(
210 220 'enabled' => $enabled,
211 221 'allowed_user_roles' => $allowed_user_roles,