Code Duplication    Length = 9-9 lines in 5 locations

includes/abstracts/abstract-wc-rest-posts-controller.php 3 locations

@@ 79-87 (lines=9) @@
76
	 * @param  WP_REST_Request $request Full details about the request.
77
	 * @return WP_Error|boolean
78
	 */
79
	public function get_item_permissions_check( $request ) {
80
		$post = get_post( (int) $request['id'] );
81
82
		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
83
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
84
		}
85
86
		return true;
87
	}
88
89
	/**
90
	 * Check if a given request has access to update an item.
@@ 95-103 (lines=9) @@
92
	 * @param  WP_REST_Request $request Full details about the request.
93
	 * @return WP_Error|boolean
94
	 */
95
	public function update_item_permissions_check( $request ) {
96
		$post = get_post( $request['id'] );
97
98
		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $post->ID ) ) {
99
			return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
100
		}
101
102
		return true;
103
	}
104
105
	/**
106
	 * Check if a given request has access to delete an item.
@@ 111-119 (lines=9) @@
108
	 * @param  WP_REST_Request $request Full details about the request.
109
	 * @return bool|WP_Error
110
	 */
111
	public function delete_item_permissions_check( $request ) {
112
		$post = get_post( $request['id'] );
113
114
		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
115
			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
116
		}
117
118
		return true;
119
	}
120
121
	/**
122
	 * Check if a given request has access batch create, update and delete items.

includes/api/class-wc-rest-webhook-deliveries.php 1 location

@@ 86-94 (lines=9) @@
83
	 * @param  WP_REST_Request $request Full details about the request.
84
	 * @return WP_Error|boolean
85
	 */
86
	public function get_item_permissions_check( $request ) {
87
		$post = get_post( (int) $request['webhook_id'] );
88
89
		if ( $post && ! wc_rest_check_post_permissions( 'shop_webhook', 'read', $post->ID ) ) {
90
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
91
		}
92
93
		return true;
94
	}
95
96
	/**
97
	 * Get all webhook deliveries.

includes/api/class-wc-rest-product-reviews-controller.php 1 location

@@ 129-137 (lines=9) @@
126
	 * @param  WP_REST_Request $request Full details about the request.
127
	 * @return WP_Error|boolean
128
	 */
129
	public function get_item_permissions_check( $request ) {
130
		$post = get_post( (int) $request['product_id'] );
131
132
		if ( $post && ! wc_rest_check_post_permissions( 'product', 'read', $post->ID ) ) {
133
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
134
		}
135
136
		return true;
137
	}
138
139
	/**
140
	 * Check if a given request has access to create a new product review.