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
	 * Get a single item.

includes/api/class-wc-rest-order-notes-controller.php 2 locations

@@ 121-129 (lines=9) @@
118
	 * @param  WP_REST_Request $request Full details about the request.
119
	 * @return WP_Error|boolean
120
	 */
121
	public function get_item_permissions_check( $request ) {
122
		$post = get_post( (int) $request['order_id'] );
123
124
		if ( $post && ! wc_rest_check_post_permissions( 'shop_order', 'read', $post->ID ) ) {
125
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
126
		}
127
128
		return true;
129
	}
130
131
	/**
132
	 * Check if a given request has access delete a order note.
@@ 137-145 (lines=9) @@
134
	 * @param  WP_REST_Request $request Full details about the request.
135
	 * @return boolean
136
	 */
137
	public function delete_item_permissions_check( $request ) {
138
		$post = get_post( (int) $request['order_id'] );
139
140
		if ( $post && ! wc_rest_check_post_permissions( 'shop_order', 'delete', $post->ID ) ) {
141
			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
142
		}
143
144
		return true;
145
	}
146
147
	/**
148
	 * 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.