ulgm_rest_api_should_get_essays_data
Filters whether to fetch essay data in the REST API, allowing modification of the decision.
add_filter( 'ulgm_rest_api_should_get_essays_data', $callback, 10, 1 );
Description
Filters whether the ULGM REST API should retrieve essay data. Allows developers to conditionally prevent data retrieval based on custom logic or the provided data payload, returning an empty array if prevented.
Usage
add_filter( 'ulgm_rest_api_should_get_essays_data', 'your_function_name', 10, 1 );
Parameters
-
$data(mixed) - This parameter is a boolean value that determines whether or not the essay data should be retrieved.
Return Value
The filtered value.
Examples
// Prevent fetching essay data if the current user is not an administrator.
add_filter( 'ulgm_rest_api_should_get_essays_data', function( $get_data, $data ) {
// Check if the current user is an administrator.
if ( ! current_user_can( 'manage_options' ) ) {
// If not an administrator, prevent data fetching.
return false;
}
// If the user is an administrator, allow data fetching.
return $get_data;
}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/reports/group-essays.php:1028
public function get_essays_data() {
$data = $_POST;
// validate inputs
$lesson_ID = absint( $data['lessonId'] );
$course_ID = absint( $data['courseId'] );
$group_ID = absint( $data['groupId'] );
$quiz_ID = absint( $data['quizId'] );
$status = $data['status'];
// Maybe prevent data load.
$get_data = apply_filters( 'ulgm_rest_api_should_get_essays_data', true, $data );
if ( ! $get_data ) {
return array();
}
$essays_table = $this->essays_table( $lesson_ID, $course_ID, $group_ID, $quiz_ID, $status );
$essays_table = apply_filters( 'ulgm_rest_api_get_essays_data', $essays_table, $_POST );
return $essays_table;
}