Skip to content

Commit c6ea46f

Browse files
committed
add capability checks for other ajax callbacks
1 parent ac18e03 commit c6ea46f

5 files changed

Lines changed: 35 additions & 0 deletions

File tree

classes/actions/class-content-scan.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function register_hooks() {
4545
* @return void
4646
*/
4747
public function ajax_scan() {
48+
49+
if ( ! \current_user_can( 'manage_options' ) ) {
50+
\wp_send_json_error( [ 'message' => \esc_html__( 'You do not have permission to scan posts.', 'progress-planner' ) ] );
51+
}
52+
4853
// Check the nonce.
4954
if ( ! \check_ajax_referer( 'progress_planner', 'nonce', false ) ) {
5055
\wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] );
@@ -71,6 +76,11 @@ public function ajax_scan() {
7176
* @return void
7277
*/
7378
public function ajax_reset_posts_data() {
79+
80+
if ( ! \current_user_can( 'manage_options' ) ) {
81+
\wp_send_json_error( [ 'message' => \esc_html__( 'You do not have permission to reset posts data.', 'progress-planner' ) ] );
82+
}
83+
7484
// Check the nonce.
7585
if ( ! \check_ajax_referer( 'progress_planner', 'nonce', false ) ) {
7686
\wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] );

classes/admin/class-page-settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function should_show_setting( $page_type ) {
128128
* @return void
129129
*/
130130
public function store_settings_form_options() {
131+
132+
if ( ! \current_user_can( 'manage_options' ) ) {
133+
\wp_send_json_error( [ 'message' => \esc_html__( 'You do not have permission to update settings.', 'progress-planner' ) ] );
134+
}
135+
131136
// Check the nonce.
132137
\check_admin_referer( 'progress_planner' );
133138

classes/class-suggested-tasks.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ public function suggested_task_action() {
232232
\wp_send_json_error( [ 'message' => \esc_html__( 'Task not found.', 'progress-planner' ) ] );
233233
}
234234

235+
$provider = \progress_planner()->get_suggested_tasks()->get_tasks_manager()->get_task_provider( $task->get_provider_id() );
236+
237+
if ( ! $provider ) {
238+
\wp_send_json_error( [ 'message' => \esc_html__( 'Provider not found.', 'progress-planner' ) ] );
239+
}
240+
241+
if ( ! $provider->capability_required() ) {
242+
\wp_send_json_error( [ 'message' => \esc_html__( 'You do not have permission to complete this task.', 'progress-planner' ) ] );
243+
}
244+
235245
$updated = false;
236246

237247
switch ( $action ) {

classes/suggested-tasks/providers/class-email-sending.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ protected function is_there_sending_email_override() {
255255
* @return void
256256
*/
257257
public function ajax_test_email_sending() {
258+
259+
if ( ! $this->capability_required() ) {
260+
\wp_send_json_error( [ 'message' => \esc_html__( 'You do not have permission to test email sending.', 'progress-planner' ) ] );
261+
}
262+
258263
// Check the nonce.
259264
\check_admin_referer( 'progress_planner' );
260265

classes/utils/class-onboard.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function on_activate_plugin( $plugin ) {
5858
* @return void
5959
*/
6060
public function save_onboard_response() {
61+
62+
if ( ! \current_user_can( 'manage_options' ) ) {
63+
\wp_send_json_error( [ 'message' => \esc_html__( 'You do not have permission to update settings.', 'progress-planner' ) ] );
64+
}
65+
6166
// Check the nonce.
6267
if ( ! \check_ajax_referer( 'progress_planner', 'nonce', false ) ) {
6368
\wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] );

0 commit comments

Comments
 (0)