| @@ -1,44 +1,44 @@ | ||
| 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 | -} | |
| 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 | +} | |