| 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 |
|