Code Duplication    Length = 15-15 lines in 2 locations

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

@@ 157-171 (lines=15) @@
154
		return $post;
155
	}
156
157
	public function current_user_can_access_post_type( $post_type, $context ) {
158
		$post_type_object = $this->get_post_type_object( $post_type );
159
		if ( ! $post_type_object ) {
160
			return false;
161
		}
162
163
		switch( $context ) {
164
			case 'edit':
165
				return current_user_can( $post_type_object->cap->edit_posts );
166
			case 'display':
167
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
168
			default:
169
				return false;
170
		}
171
	}
172
173
	protected function get_post_type_object( $post_type ) {
174
		return get_post_type_object( $post_type );

class.json-api-endpoints.php 1 location

@@ 1563-1577 (lines=15) @@
1560
	* @param string $context                'display' or 'edit'
1561
	* @return bool
1562
	*/
1563
	function current_user_can_access_post_type( $post_type, $context='display' ) {
1564
		$post_type_object = get_post_type_object( $post_type );
1565
		if ( ! $post_type_object ) {
1566
			return false;
1567
		}
1568
1569
		switch( $context ) {
1570
			case 'edit':
1571
				return current_user_can( $post_type_object->cap->edit_posts );
1572
			case 'display':
1573
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
1574
			default:
1575
				return false;
1576
		}
1577
	}
1578
1579
	function is_post_type_allowed( $post_type ) {
1580
		// if the post type is empty, that's fine, WordPress will default to post