Code Duplication    Length = 15-15 lines in 2 locations

sal/class.json-api-site-base.php 1 location

@@ 219-233 (lines=15) @@
216
		return $post;
217
	}
218
219
	public function current_user_can_access_post_type( $post_type, $context ) {
220
		$post_type_object = $this->get_post_type_object( $post_type );
221
		if ( ! $post_type_object ) {
222
			return false;
223
		}
224
225
		switch( $context ) {
226
			case 'edit':
227
				return current_user_can( $post_type_object->cap->edit_posts );
228
			case 'display':
229
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
230
			default:
231
				return false;
232
		}
233
	}
234
235
	protected function get_post_type_object( $post_type ) {
236
		return get_post_type_object( $post_type );

class.json-api-endpoints.php 1 location

@@ 1743-1757 (lines=15) @@
1740
	 * @param string $context                'display' or 'edit'
1741
	 * @return bool
1742
	 */
1743
	function current_user_can_access_post_type( $post_type, $context = 'display' ) {
1744
		$post_type_object = get_post_type_object( $post_type );
1745
		if ( ! $post_type_object ) {
1746
			return false;
1747
		}
1748
1749
		switch ( $context ) {
1750
			case 'edit':
1751
				return current_user_can( $post_type_object->cap->edit_posts );
1752
			case 'display':
1753
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
1754
			default:
1755
				return false;
1756
		}
1757
	}
1758
1759
	function is_post_type_allowed( $post_type ) {
1760
		// if the post type is empty, that's fine, WordPress will default to post