PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.0
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.0
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / jwt / rest-api / lp-rest-function.php

lp-rest-function.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.0, at inc/jwt/rest-api/lp-rest-function.php

45 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Check permissions of posts on REST API.
5 *
6 * @param [type] $post_type Post type.
7 * @param string $context Request context.
8 * @param integer $object_id Post ID.
9 * @return void
10 */
11 function lp_rest_check_post_permissions( $post_type, $context = 'read', $object_id = 0 ) {
12 $contexts = array(
13 'read' => 'read_private_posts',
14 'create' => 'publish_posts',
15 'edit' => 'edit_post',
16 'delete' => 'delete_post',
17 'batch' => 'edit_others_posts',
18 );
19
20 if ( 'revision' === $post_type ) {
21 $permission = false;
22 } else {
23 $cap = $contexts[ $context ];
24 $post_type_object = get_post_type_object( $post_type );
25 $permission = current_user_can( $post_type_object->cap->$cap, $object_id );
26 }
27
28 return apply_filters( 'lp_rest_check_permissions', $permission, $context, $object_id, $post_type );
29 }
30
31 function lp_jwt_prepare_date_response( $date_gmt, $date = null ) {
32 // Use the date if passed.
33 if ( isset( $date ) ) {
34 return mysql_to_rfc3339( $date );
35 }
36
37 // Return null if $date_gmt is empty/zeros.
38 if ( '0000-00-00 00:00:00' === $date_gmt ) {
39 return null;
40 }
41
42 // Return the formatted datetime.
43 return mysql_to_rfc3339( $date_gmt );
44 }
45