Code Duplication    Length = 9-9 lines in 7 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-order-notes-controller.php 2 locations

@@ 128-136 (lines=9) @@
125
	 * @param  WP_REST_Request $request Full details about the request.
126
	 * @return WP_Error|boolean
127
	 */
128
	public function get_item_permissions_check( $request ) {
129
		$post = get_post( (int) $request['order_id'] );
130
131
		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
132
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
133
		}
134
135
		return true;
136
	}
137
138
	/**
139
	 * Check if a given request has access delete a order note.
@@ 144-152 (lines=9) @@
141
	 * @param  WP_REST_Request $request Full details about the request.
142
	 * @return boolean
143
	 */
144
	public function delete_item_permissions_check( $request ) {
145
		$post = get_post( (int) $request['order_id'] );
146
147
		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
148
			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
149
		}
150
151
		return true;
152
	}
153
154
	/**
155
	 * Get order notes from an order.

includes/api/class-wc-rest-product-reviews-controller.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['product_id'] );
88
89
		if ( $post && ! wc_rest_check_post_permissions( 'product', '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 reviews from a product.

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.