PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / admin-legacy-core / api / step-data.php

step-data.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.0, at admin-legacy-core/api/step-data.php

155 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Flow data.
4 *
5 * @package CartFlows
6 */
7
8 namespace CartflowsAdmin\AdminLegacyCore\Api;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 use CartflowsAdmin\AdminLegacyCore\Api\ApiBase;
16 use CartflowsAdmin\AdminLegacyCore\Inc\AdminHelper;
17 use CartflowsAdmin\AdminLegacyCore\Inc\StepMeta;
18
19 /**
20 * Class StepData.
21 */
22 class StepData extends ApiBase {
23
24 /**
25 * Route base.
26 *
27 * @var string
28 */
29 protected $rest_base = '/admin/step-data/';
30
31 /**
32 * Instance
33 *
34 * @access private
35 * @var object Class object.
36 * @since 1.0.0
37 */
38 private static $instance;
39
40 /**
41 * Initiator
42 *
43 * @since 1.0.0
44 * @return object initialized object of class.
45 */
46 public static function get_instance() {
47 if ( ! isset( self::$instance ) ) {
48 self::$instance = new self();
49 }
50 return self::$instance;
51 }
52
53 /**
54 * Init Hooks.
55 *
56 * @since 1.0.0
57 * @return void
58 */
59 public function register_routes() {
60
61 $namespace = $this->get_api_namespace();
62
63 register_rest_route(
64 $namespace,
65 $this->rest_base . '(?P<id>[\d-]+)',
66 array(
67 'args' => array(
68 'id' => array(
69 'description' => __( 'Step ID.', 'cartflows' ),
70 'type' => 'integer',
71 ),
72 ),
73 array(
74 'methods' => \WP_REST_Server::READABLE,
75 'callback' => array( $this, 'get_item' ),
76 'permission_callback' => array( $this, 'get_item_permissions_check' ),
77 ),
78 'schema' => array( $this, 'get_public_item_schema' ),
79 )
80 );
81 }
82
83 /**
84 * Get step data.
85 *
86 * @param WP_REST_Request $request Full details about the request.
87 * @return WP_Error|boolean
88 */
89 public function get_item( $request ) {
90
91 $step_id = absint( $request->get_param( 'id' ) );
92
93 // Validate the post type to prevent accessing non-step posts.
94 if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type( $step_id ) ) {
95 return new \WP_Error( 'cartflows_invalid_step', __( 'Invalid step ID.', 'cartflows' ), array( 'status' => 404 ) );
96 }
97
98 $meta_options = array();
99 $meta_options = AdminHelper::get_step_meta_options( $step_id );
100
101 $step_type = $meta_options['type'];
102 $flow_id = get_post_meta( $step_id, 'wcf-flow-id', true );
103 $edit_step = get_edit_post_link( $step_id, 'edit' );
104 $view_step = get_permalink( $step_id );
105 $page_builder_edit = \Cartflows_Helper::get_page_builder_edit_link( $step_id );
106
107 /* Get Settings */
108 $settings_data = StepMeta::get_meta_settings( $step_id, $step_type );
109
110 $meta_options['options']['step_post_name'] = get_post_field( 'post_name', $step_id, 'edit' );
111
112 /* Prepare data */
113 $data = apply_filters(
114 'cartflows_admin_' . $step_type . '_step_data',
115 array(
116 'id' => $step_id,
117 'flow_title' => get_the_title( $flow_id ),
118 'title' => get_the_title( $step_id ),
119 'type' => $step_type,
120 'tabs' => isset( $settings_data['tabs'] ) ? $settings_data['tabs'] : '',
121 'settings_data' => isset( $settings_data['settings'] ) ? $settings_data['settings'] : '',
122 'page_settings' => isset( $settings_data['page_settings'] ) ? $settings_data['page_settings'] : '',
123 'design_settings' => isset( $settings_data['design_settings'] ) ? $settings_data['design_settings'] : '',
124 'options' => isset( $meta_options['options'] ) ? $meta_options['options'] : '',
125 'view' => $view_step,
126 'edit' => $edit_step,
127 'page_builder_edit' => $page_builder_edit,
128 // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
129 // 'slug' => get_post_field( 'post_name', $step_id, 'edit' ),
130 ),
131 $step_id
132 );
133
134 $response = new \WP_REST_Response( $data );
135 $response->set_status( 200 );
136
137 return $response;
138 }
139
140 /**
141 * Check whether a given request has permission to read notes.
142 *
143 * @param WP_REST_Request $request Full details about the request.
144 * @return WP_Error|boolean
145 */
146 public function get_item_permissions_check( $request ) {
147
148 if ( ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
149 return new \WP_Error( 'cartflows_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'cartflows' ), array( 'status' => rest_authorization_required_code() ) );
150 }
151
152 return true;
153 }
154 }
155