PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 2.8.17 2.8.18 All 259 releases
wpfunnels / includes / core / rest-api / Controllers / ImportExportController.php

ImportExportController.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at includes/core/rest-api/Controllers/ImportExportController.php

99 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPFunnels\Rest\Controllers;
4
5 use Error;
6 use WPFunnels\Export\Wpfnl_Export;
7 use WP_Error;
8 use WP_REST_Request;
9 use WPFunnels\Wpfnl_functions;
10
11
12 class ImportExportController extends Wpfnl_REST_Controller
13 {
14
15 /**
16 * Endpoint namespace.
17 *
18 * @var string
19 * @since 1.9.3
20 */
21 protected $namespace = 'wpfunnels/v1';
22
23 /**
24 * Route base.
25 *
26 * @var string
27 * @since 1.9.3
28 */
29 protected $rest_base = 'import-export';
30
31 /**
32 * check if user has valid permission
33 *
34 * @param $request
35 * @return bool|WP_Error
36 * @since 1.9.3
37 */
38 public function update_items_permissions_check($request)
39 {
40 if (!Wpfnl_functions::wpfnl_rest_check_manager_permissions( 'steps', 'edit' )) {
41 return new WP_Error('wpfunnels_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'wpfnl'), ['status' => rest_authorization_required_code()]);
42 }
43 return true;
44 }
45
46
47 /**
48 * register rest routes
49 *
50 * @since 1.9.3
51 */
52 public function register_routes()
53 {
54 register_rest_route($this->namespace, '/' . $this->rest_base . '/bulk-export-funnel', [
55 [
56 'methods' => \WP_REST_Server::EDITABLE,
57 'callback' => [
58 $this,
59 'bulk_export_funnel'
60 ],
61 'permission_callback' => [
62 $this,
63 'update_items_permissions_check'
64 ],
65 ],
66 ]);
67 }
68
69 /**
70 * Export selected funnels
71 *
72 * @param array $payload Funnel ids and status.
73 *
74 * @return array|\WP_Rest_Response|\WP_Error
75 * @since 1.9.3
76 */
77 public function bulk_export_funnel ( $payload ){
78
79 $controller_class = Wpfnl_Export::getInstance();
80
81 return $controller_class->bulk_export_funnel( $payload );
82 }
83
84
85 /**
86 * Prepare a single setting object for response.
87 *
88 * @param object $item Setting object.
89 * @param WP_REST_Request $request Request object.
90 * @return \WP_REST_Response $response Response data.
91 * @since 1.9.3
92 */
93 public function prepare_item_for_response($item, $request)
94 {
95 $data = $this->add_additional_fields_to_object($item, $request);
96 return rest_ensure_response($data);
97 }
98 }
99