Code Duplication    Length = 15-15 lines in 2 locations

class.json-api-endpoints.php 1 location

@@ 1725-1739 (lines=15) @@
1722
	 * @param string $context                'display' or 'edit'
1723
	 * @return bool
1724
	 */
1725
	function current_user_can_access_post_type( $post_type, $context = 'display' ) {
1726
		$post_type_object = get_post_type_object( $post_type );
1727
		if ( ! $post_type_object ) {
1728
			return false;
1729
		}
1730
1731
		switch ( $context ) {
1732
			case 'edit':
1733
				return current_user_can( $post_type_object->cap->edit_posts );
1734
			case 'display':
1735
				return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts );
1736
			default:
1737
				return false;
1738
		}
1739
	}
1740
1741
	function is_post_type_allowed( $post_type ) {
1742
		// if the post type is empty, that's fine, WordPress will default to post

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

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