Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions includes/Api/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function () {
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
'validate_callback' => [ $this, 'validate_flag_input' ],
],
]
);
Expand Down Expand Up @@ -98,4 +99,28 @@ public function post_flags( $request ) {
}
}

/**
* Validates flag input from POST method.
*
* @param \WP_REST_Request $param Request object.
*
* @return bool
*/
public function validate_flag_input( $param ) {
$input_data = $param->get_json_params();
$valid_keys = [ 'id', 'name', 'enabled' ];

if ( ! isset( $input_data ) || ! is_array( $input_data ) || 0 === count( $input_data ) ) {
return false;
}

foreach ( $input_data as $flag_key => $flag ) {
foreach ( $valid_keys as $key => $value ) {
if ( ! array_key_exists( $value, $flag ) ) {
return false;
}
}
}
return true;
}
}