Code Duplication    Length = 56-60 lines in 5 locations

includes/abstracts/abstract-wc-rest-terms-controller.php 1 location

@@ 34-93 (lines=60) @@
31
	/**
32
	 * Register the routes for terms.
33
	 */
34
	public function register_routes() {
35
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
36
			array(
37
				'methods'             => WP_REST_Server::READABLE,
38
				'callback'            => array( $this, 'get_items' ),
39
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
				'args'                => $this->get_collection_params(),
41
			),
42
			array(
43
				'methods'             => WP_REST_Server::CREATABLE,
44
				'callback'            => array( $this, 'create_item' ),
45
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
46
				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
47
					'name' => array(
48
						'required' => true,
49
					),
50
				) ),
51
			),
52
			'schema' => array( $this, 'get_public_item_schema' ),
53
		));
54
55
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
56
			array(
57
				'methods'             => WP_REST_Server::READABLE,
58
				'callback'            => array( $this, 'get_item' ),
59
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
60
				'args'                => array(
61
					'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
62
				),
63
			),
64
			array(
65
				'methods'             => WP_REST_Server::EDITABLE,
66
				'callback'            => array( $this, 'update_item' ),
67
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
68
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
69
			),
70
			array(
71
				'methods'             => WP_REST_Server::DELETABLE,
72
				'callback'            => array( $this, 'delete_item' ),
73
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
74
				'args'                => array(
75
					'force' => array(
76
						'default'     => false,
77
						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
78
					),
79
				),
80
			),
81
			'schema' => array( $this, 'get_public_item_schema' ),
82
		) );
83
84
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
85
			array(
86
				'methods'             => WP_REST_Server::EDITABLE,
87
				'callback'            => array( $this, 'batch_items' ),
88
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
89
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
90
			),
91
			'schema' => array( $this, 'get_public_batch_schema' ),
92
		) );
93
	}
94
95
	/**
96
	 * Check if a given request has access to read the terms.

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

@@ 56-115 (lines=60) @@
53
	/**
54
	 * Register the routes for coupons.
55
	 */
56
	public function register_routes() {
57
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
58
			array(
59
				'methods'             => WP_REST_Server::READABLE,
60
				'callback'            => array( $this, 'get_items' ),
61
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
62
				'args'                => $this->get_collection_params(),
63
			),
64
			array(
65
				'methods'             => WP_REST_Server::CREATABLE,
66
				'callback'            => array( $this, 'create_item' ),
67
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
68
				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
69
					'code' => array(
70
						'required' => true,
71
					),
72
				) ),
73
			),
74
			'schema' => array( $this, 'get_public_item_schema' ),
75
		) );
76
77
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
78
			array(
79
				'methods'             => WP_REST_Server::READABLE,
80
				'callback'            => array( $this, 'get_item' ),
81
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
82
				'args'                => array(
83
					'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
84
				),
85
			),
86
			array(
87
				'methods'         => WP_REST_Server::EDITABLE,
88
				'callback'        => array( $this, 'update_item' ),
89
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
90
				'args'            => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
91
			),
92
			array(
93
				'methods'             => WP_REST_Server::DELETABLE,
94
				'callback'            => array( $this, 'delete_item' ),
95
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
96
				'args'                => array(
97
					'force' => array(
98
						'default'     => false,
99
						'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
100
					),
101
				),
102
			),
103
			'schema' => array( $this, 'get_public_item_schema' ),
104
		) );
105
106
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
107
			array(
108
				'methods'             => WP_REST_Server::EDITABLE,
109
				'callback'            => array( $this, 'batch_items' ),
110
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
111
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
112
			),
113
			'schema' => array( $this, 'get_public_batch_schema' ),
114
		) );
115
	}
116
117
	/**
118
	 * Query args.

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

@@ 49-108 (lines=60) @@
46
	/**
47
	 * Register the routes for product attributes.
48
	 */
49
	public function register_routes() {
50
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
51
			array(
52
				'methods'             => WP_REST_Server::READABLE,
53
				'callback'            => array( $this, 'get_items' ),
54
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
55
				'args'                => $this->get_collection_params(),
56
			),
57
			array(
58
				'methods'             => WP_REST_Server::CREATABLE,
59
				'callback'            => array( $this, 'create_item' ),
60
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
61
				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
62
					'name' => array(
63
						'required' => true,
64
					),
65
				) ),
66
			),
67
			'schema' => array( $this, 'get_public_item_schema' ),
68
		));
69
70
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
71
			array(
72
				'methods'             => WP_REST_Server::READABLE,
73
				'callback'            => array( $this, 'get_item' ),
74
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
75
				'args'                => array(
76
					'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
77
				),
78
			),
79
			array(
80
				'methods'             => WP_REST_Server::EDITABLE,
81
				'callback'            => array( $this, 'update_item' ),
82
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
83
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
84
			),
85
			array(
86
				'methods'             => WP_REST_Server::DELETABLE,
87
				'callback'            => array( $this, 'delete_item' ),
88
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
89
				'args'                => array(
90
					'force' => array(
91
						'default'     => false,
92
						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
93
					),
94
				),
95
			),
96
			'schema' => array( $this, 'get_public_item_schema' ),
97
		) );
98
99
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
100
			array(
101
				'methods'             => WP_REST_Server::EDITABLE,
102
				'callback'            => array( $this, 'batch_items' ),
103
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
104
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
105
			),
106
			'schema' => array( $this, 'get_public_batch_schema' ),
107
		) );
108
	}
109
110
	/**
111
	 * Check if a given request has access to read the attributes.

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

@@ 56-112 (lines=57) @@
53
	/**
54
	 * Register the routes for orders.
55
	 */
56
	public function register_routes() {
57
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
58
			array(
59
				'methods'             => WP_REST_Server::READABLE,
60
				'callback'            => array( $this, 'get_items' ),
61
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
62
				'args'                => $this->get_collection_params(),
63
			),
64
			array(
65
				'methods'             => WP_REST_Server::CREATABLE,
66
				'callback'            => array( $this, 'create_item' ),
67
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
68
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
69
			),
70
			'schema' => array( $this, 'get_public_item_schema' ),
71
		) );
72
73
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
74
			array(
75
				'methods'             => WP_REST_Server::READABLE,
76
				'callback'            => array( $this, 'get_item' ),
77
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
78
				'args'                => array(
79
					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
80
				),
81
			),
82
			array(
83
				'methods'             => WP_REST_Server::EDITABLE,
84
				'callback'            => array( $this, 'update_item' ),
85
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
86
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
87
			),
88
			array(
89
				'methods'             => WP_REST_Server::DELETABLE,
90
				'callback'            => array( $this, 'delete_item' ),
91
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
92
				'args'                => array(
93
					'force' => array(
94
						'default'     => false,
95
						'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
96
					),
97
					'reassign' => array(),
98
				),
99
			),
100
			'schema' => array( $this, 'get_public_item_schema' ),
101
		) );
102
103
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
104
			array(
105
				'methods'             => WP_REST_Server::EDITABLE,
106
				'callback'            => array( $this, 'batch_items' ),
107
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
108
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
109
			),
110
			'schema' => array( $this, 'get_public_batch_schema' ),
111
		) );
112
	}
113
114
	/**
115
	 * Prepare a single order output for response.

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

@@ 42-97 (lines=56) @@
39
	/**
40
	 * Register the routes for taxes.
41
	 */
42
	public function register_routes() {
43
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
44
			array(
45
				'methods'             => WP_REST_Server::READABLE,
46
				'callback'            => array( $this, 'get_items' ),
47
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
48
				'args'                => $this->get_collection_params(),
49
			),
50
			array(
51
				'methods'             => WP_REST_Server::CREATABLE,
52
				'callback'            => array( $this, 'create_item' ),
53
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
54
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
55
			),
56
			'schema' => array( $this, 'get_public_item_schema' ),
57
		) );
58
59
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
60
			array(
61
				'methods'             => WP_REST_Server::READABLE,
62
				'callback'            => array( $this, 'get_item' ),
63
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
64
				'args'                => array(
65
					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
66
				),
67
			),
68
			array(
69
				'methods'             => WP_REST_Server::EDITABLE,
70
				'callback'            => array( $this, 'update_item' ),
71
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
72
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
73
			),
74
			array(
75
				'methods'             => WP_REST_Server::DELETABLE,
76
				'callback'            => array( $this, 'delete_item' ),
77
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
78
				'args'                => array(
79
					'force' => array(
80
						'default'     => false,
81
						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
82
					),
83
				),
84
			),
85
			'schema' => array( $this, 'get_public_item_schema' ),
86
		) );
87
88
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
89
			array(
90
				'methods'             => WP_REST_Server::EDITABLE,
91
				'callback'            => array( $this, 'batch_items' ),
92
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
93
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
94
			),
95
			'schema' => array( $this, 'get_public_batch_schema' ),
96
		) );
97
	}
98
99
	/**
100
	 * Check whether a given request has permission to read taxes.