Code Duplication    Length = 15-15 lines in 2 locations

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

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

class.json-api-endpoints.php 1 location

@@ 1617-1631 (lines=15) @@
1614
	* @param string $context                'display' or 'edit'
1615
	* @return bool
1616
	*/
1617
	function current_user_can_access_post_type( $post_type, $context='display' ) {
1618
		$post_type_object = get_post_type_object( $post_type );
1619
		if ( ! $post_type_object ) {
1620
			return false;
1621
		}
1622
1623
		switch( $context ) {
1624
			case 'edit':
1625
				return current_user_can( $post_type_object->cap->edit_posts );
1626
			case 'display':
1627
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
1628
			default:
1629
				return false;
1630
		}
1631
	}
1632
1633
	function is_post_type_allowed( $post_type ) {
1634
		// if the post type is empty, that's fine, WordPress will default to post