Code Duplication    Length = 11-11 lines in 5 locations

includes/api/class-wc-rest-product-attributes-controller.php 3 locations

@@ 144-154 (lines=11) @@
141
	 * @param  WP_REST_Request $request Full details about the request.
142
	 * @return WP_Error|boolean
143
	 */
144
	public function get_item_permissions_check( $request ) {
145
		if ( ! $this->get_taxonomy( $request ) ) {
146
			return new WP_Error( "woocommerce_rest_taxonomy_invalid", __( "Resource doesn't exist.", 'woocommerce' ), array( 'status' => 404 ) );
147
		}
148
149
		if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) {
150
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
151
		}
152
153
		return true;
154
	}
155
156
	/**
157
	 * Check if a given request has access to update a attribute.
@@ 162-172 (lines=11) @@
159
	 * @param  WP_REST_Request $request Full details about the request.
160
	 * @return WP_Error|boolean
161
	 */
162
	public function update_item_permissions_check( $request ) {
163
		if ( ! $this->get_taxonomy( $request ) ) {
164
			return new WP_Error( "woocommerce_rest_taxonomy_invalid", __( "Resource doesn't exist.", 'woocommerce' ), array( 'status' => 404 ) );
165
		}
166
167
		if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) {
168
			return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
169
		}
170
171
		return true;
172
	}
173
174
	/**
175
	 * Check if a given request has access to delete a attribute.
@@ 180-190 (lines=11) @@
177
	 * @param  WP_REST_Request $request Full details about the request.
178
	 * @return WP_Error|boolean
179
	 */
180
	public function delete_item_permissions_check( $request ) {
181
		if ( ! $this->get_taxonomy( $request ) ) {
182
			return new WP_Error( "woocommerce_rest_taxonomy_invalid", __( "Resource doesn't exist.", 'woocommerce' ), array( 'status' => 404 ) );
183
		}
184
185
		if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) {
186
			return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you cannot delete resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
187
		}
188
189
		return true;
190
	}
191
192
	/**
193
	 * Check if a given request has access batch create, update and delete items.

includes/abstracts/abstract-wc-rest-shipping-zones-controller.php 2 locations

@@ 61-71 (lines=11) @@
58
	 * @param  WP_REST_Request $request Full details about the request.
59
	 * @return WP_Error|boolean
60
	 */
61
	public function get_items_permissions_check( $request ) {
62
		if ( ! wc_shipping_enabled() ) {
63
			return new WP_Error( 'rest_no_route', __( 'Shipping is disabled.' ), array( 'status' => 404 ) );
64
		}
65
66
		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
67
			return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
68
		}
69
70
		return true;
71
	}
72
73
	/**
74
	 * Check whether a given request has permission to edit Shipping Zones.
@@ 79-89 (lines=11) @@
76
	 * @param  WP_REST_Request $request Full details about the request.
77
	 * @return WP_Error|boolean
78
	 */
79
	public function update_items_permissions_check( $request ) {
80
		if ( ! wc_shipping_enabled() ) {
81
			return new WP_Error( 'rest_no_route', __( 'Shipping is disabled.' ), array( 'status' => 404 ) );
82
		}
83
84
		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
85
			return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
86
		}
87
88
		return true;
89
	}
90
}
91