Code Duplication    Length = 15-15 lines in 2 locations

class.json-api-endpoints.php 1 location

@@ 1713-1727 (lines=15) @@
1710
	 * @param string $context                'display' or 'edit'
1711
	 * @return bool
1712
	 */
1713
	function current_user_can_access_post_type( $post_type, $context = 'display' ) {
1714
		$post_type_object = get_post_type_object( $post_type );
1715
		if ( ! $post_type_object ) {
1716
			return false;
1717
		}
1718
1719
		switch ( $context ) {
1720
			case 'edit':
1721
				return current_user_can( $post_type_object->cap->edit_posts );
1722
			case 'display':
1723
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
1724
			default:
1725
				return false;
1726
		}
1727
	}
1728
1729
	function is_post_type_allowed( $post_type ) {
1730
		// if the post type is empty, that's fine, WordPress will default to post

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

@@ 199-213 (lines=15) @@
196
		return $post;
197
	}
198
199
	public function current_user_can_access_post_type( $post_type, $context ) {
200
		$post_type_object = $this->get_post_type_object( $post_type );
201
		if ( ! $post_type_object ) {
202
			return false;
203
		}
204
205
		switch( $context ) {
206
			case 'edit':
207
				return current_user_can( $post_type_object->cap->edit_posts );
208
			case 'display':
209
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
210
			default:
211
				return false;
212
		}
213
	}
214
215
	protected function get_post_type_object( $post_type ) {
216
		return get_post_type_object( $post_type );