PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.12
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.12
3.13.3 3.13.2 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 All 261 releases
wpfunnels / includes / core / rest-api / Controllers / class-settings-controller.php

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

787 lines 27.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Settings controller
4 *
5 * @package WPFunnels\Rest\Controllers
6 */
7 namespace WPFunnels\Rest\Controllers;
8
9 use GuzzleHttp\Psr7\Request;
10 use WP_Error;
11 use WP_REST_Request;
12 use WP_REST_Response;
13 use WP_REST_Server;
14 use WPFunnels\Wpfnl_functions;
15 use WPFunnels\lms\helper\Wpfnl_lms_learndash_functions;
16 use WPFunnels\Wpfnl;
17 use Elementor\Core\Kits\Manager;
18 class SettingsController extends Wpfnl_REST_Controller {
19
20 /**
21 * Endpoint namespace.
22 *
23 * @var string
24 */
25 protected $namespace = 'wpfunnels/v1';
26
27 /**
28 * Route base.
29 *
30 * @var string
31 */
32 protected $rest_base = 'settings/(?P<group_id>[\w-]+)';
33
34
35 protected $rest_wc_plugin_active_base = 'settings/activate_wc_plugins';
36 protected $rest_mrm_plugin_active_base = 'settings/activate_mrm_plugins';
37
38 protected $rest_funnel_settings = 'settings';
39
40 public function update_items_permissions_check( $request ) {
41 $permission = current_user_can('wpf_manage_funnels');
42 if ( ! Wpfnl_functions::wpfnl_rest_check_manager_permissions( 'settings' ) ) {
43 return new WP_Error( 'wpfunnels_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'wpfnl' ), array( 'status' => rest_authorization_required_code() ) );
44 }
45 return true;
46 }
47
48 /**
49 * Makes sure the current user has access to READ the settings APIs.
50 *
51 * @param WP_REST_Request $request Full data about the request.
52 *
53 * @return WP_Error|boolean
54 * @since 3.0.0
55 */
56 public function get_items_permissions_check( $request ) {
57 if ( ! Wpfnl_functions::wpfnl_rest_check_manager_permissions( 'settings' ) ) {
58 return new WP_Error( 'wpfunnels_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'wpfnl' ), array( 'status' => rest_authorization_required_code() ) );
59 }
60 return true;
61 }
62
63 public function register_routes()
64 {
65 register_rest_route(
66 $this->namespace, '/' . $this->rest_base . '/(?P<settings_id>[\w-]+)', array(
67 'args' => array(
68 'settings_id' => array(
69 'description' => __( 'Settings group ID.', 'wpfnl' ),
70 'type' => 'string',
71 )
72 ),
73 // array(
74 // 'methods' => WP_REST_Server::READABLE,
75 // 'callback' => array( $this, 'get_item' ),
76 // 'permission_callback' => array( $this, 'get_items_permissions_check' ),
77 // ),
78 array(
79 'methods' => WP_REST_Server::EDITABLE,
80 'callback' => array( $this, 'update_settings' ),
81 'permission_callback' => array( $this, 'update_items_permissions_check' ),
82 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
83 )
84 )
85 );
86
87 register_rest_route(
88 $this->namespace, '/' . $this->rest_wc_plugin_active_base , array(
89 array(
90 'methods' => WP_REST_Server::EDITABLE,
91 'callback' => array( $this, 'activate_wc_plugins' ),
92 'permission_callback' => array( $this, 'update_items_permissions_check' ),
93 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
94 )
95 )
96 );
97
98 register_rest_route(
99 $this->namespace, '/' . $this->rest_mrm_plugin_active_base , array(
100 array(
101 'methods' => WP_REST_Server::EDITABLE,
102 'callback' => array( $this, 'activate_mrm_plugins' ),
103 'permission_callback' => array( $this, 'update_items_permissions_check' ),
104 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
105 )
106 )
107 );
108
109
110 register_rest_route(
111 $this->namespace, '/' . $this->rest_funnel_settings . '/is-lms/(?P<funnel_id>[\w-]+)' , array(
112 array(
113 'methods' => 'GET',
114 'callback' => array( $this, 'is_lms' ),
115 'permission_callback' => array( $this, 'update_items_permissions_check' ),
116 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
117 )
118 )
119 );
120
121 register_rest_route(
122 $this->namespace, '/' . $this->rest_funnel_settings . '/activate-plugins' , array(
123 array(
124 'methods' => 'POST',
125 'callback' => array( $this, 'activate_plugins' ),
126 'permission_callback' => array( $this, 'update_items_permissions_check' ),
127 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
128 )
129 )
130 );
131
132 register_rest_route(
133 $this->namespace, '/' . $this->rest_funnel_settings . '/create-contact' , array(
134 array(
135 'methods' => 'POST',
136 'callback' => array( $this, 'create_contact' ),
137 'permission_callback' => array( $this, 'update_items_permissions_check' ),
138 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
139 )
140 )
141 );
142
143 register_rest_route(
144 $this->namespace, '/' . $this->rest_funnel_settings . '/save-setup-wizard-settings' , array(
145 array(
146 'methods' => 'POST',
147 'callback' => array( $this, 'save_setup_wizard_settings' ),
148 'permission_callback' => array( $this, 'update_items_permissions_check' ),
149 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
150 )
151 )
152 );
153
154 register_rest_route(
155 $this->namespace, '/' . $this->rest_funnel_settings . '/update-funnel-type' , array(
156 array(
157 'methods' => 'POST',
158 'callback' => array( $this, 'update_funnel_type' ),
159 'permission_callback' => array( $this, 'update_items_permissions_check' ),
160 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
161 )
162 )
163 );
164
165 register_rest_route(
166 $this->namespace, '/' . $this->rest_funnel_settings . '/update-builder-type' , array(
167 array(
168 'methods' => 'POST',
169 'callback' => array( $this, 'update_builder_type' ),
170 'permission_callback' => array( $this, 'update_items_permissions_check' ),
171 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
172 )
173 )
174 );
175
176 register_rest_route(
177 $this->namespace, '/' . $this->rest_funnel_settings . '/get-funnel-type-id/(?P<funnel_id>[\w-]+)' , array(
178 array(
179 'methods' => 'GET',
180 'callback' => array( $this, 'get_funnel_type_id' ),
181 'permission_callback' => array( $this, 'update_items_permissions_check' ),
182 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
183 )
184 )
185 );
186
187 register_rest_route(
188 $this->namespace, '/' . $this->rest_funnel_settings . '/canvas-view-mode' , array(
189 array(
190 'methods' => 'POST',
191 'callback' => array( $this, 'update_canvas_view_mode' ),
192 'permission_callback' => array( $this, 'update_items_permissions_check' ),
193 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
194 )
195 )
196 );
197
198 }
199
200
201 /**
202 * Get all settings in a group.
203 *
204 * @param string $group_id Group ID.
205 *
206 * @return array|WP_Error
207 */
208 public function get_group_settings( $group_id ) {
209 if ( empty( $group_id ) ) {
210 return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'wpfnl' ), array( 'status' => 404 ) );
211 }
212 if ( ! $this->is_allowed_settings_group( $group_id ) ) {
213 return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'wpfnl' ), array( 'status' => 403 ) );
214 }
215 $settings = Wpfnl_functions::get_admin_settings( $group_id );
216 if ( empty( $settings ) ) {
217 return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'wpfnl' ), array( 'status' => 404 ) );
218 }
219
220 $filtered_settings = array();
221 foreach ($settings as $key => $setting) {
222 $filtered_settings[] = array(
223 'id' => $key,
224 'value' => $setting
225 );
226 }
227 return $filtered_settings;
228 }
229
230
231 /**
232 * Get setting data.
233 *
234 * @param string $group_id Group ID.
235 * @param string $setting_id Setting ID.
236 *
237 * @return stdClass|WP_Error
238 * @since 3.0.0
239 */
240 public function get_setting( $group_id, $setting_id ) {
241 if ( empty( $setting_id ) ) {
242 return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'wpfnl' ), array( 'status' => 404 ) );
243 }
244
245 $settings = $this->get_group_settings( $group_id );
246
247 if ( is_wp_error( $settings ) ) {
248 return $settings;
249 }
250
251 $array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id );
252
253 if ( empty( $array_key ) ) {
254 return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'wpfnl' ), array( 'status' => 404 ) );
255 }
256
257 $setting = $settings[ $array_key[0] ];
258 return $setting;
259 }
260
261
262 /**
263 * Active required plugin based on slug
264 *
265 * @param $plugin_name
266 *
267 * @return WP_Error|WP_REST_Response
268 * @since 1.0.0
269 */
270 public function activate_wc_plugins( \WP_REST_Request $request ) {
271 if( !function_exists('activate_plugin') ) {
272 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
273 }
274
275
276
277 $permission = $request['permission'];
278 $islms = $request['islms'];
279 $isWc = $request['isWc'];
280
281 $plugin_slug_arr = array(
282 'woocommerce/woocommerce.php' => false,
283 'cart-lift/cart-lift.php' => false,
284 'sfwd-lms/sfwd_lms.php' => false,
285 );
286 $should_activated = array(
287 'woocommerce/woocommerce.php' => false,
288 'cart-lift/cart-lift.php' => false,
289 'sfwd-lms/sfwd_lms.php' => false,
290 );
291 if($permission == '' ){
292 unset($should_activated[ 'cart-lift/cart-lift.php' ]);
293 unset($plugin_slug_arr[ 'cart-lift/cart-lift.php' ]);
294 }
295
296 if($permission == '' ){
297 unset($should_activated[ 'cart-lift/cart-lift.php' ]);
298 unset($plugin_slug_arr[ 'cart-lift/cart-lift.php' ]);
299 }
300
301 if( $isWc == 'no' ){
302 unset($should_activated[ 'woocommerce/woocommerce.php' ]);
303 unset($plugin_slug_arr[ 'woocommerce/woocommerce.php' ]);
304 }
305 if( $islms == '' ){
306 unset($should_activated[ 'sfwd-lms/sfwd_lms.php' ]);
307 unset($plugin_slug_arr[ 'sfwd-lms/sfwd_lms.php' ]);
308 }
309
310 foreach ( $plugin_slug_arr as $slug => $is_silent ) {
311 $data = activate_plugin( $slug, '', false, $is_silent );
312 if ( !is_wp_error( $data ) ) {
313 $should_activated[ $slug ] = true;
314
315 }
316 }
317 delete_transient( '_wc_activation_redirect' );
318
319 foreach ( $should_activated as $slug => $is_activated ) {
320 if(!$is_activated) {
321 $settings['success'] = false;
322 return rest_ensure_response( $settings );
323 }
324 }
325
326 $settings['success'] = true;
327 return rest_ensure_response( $settings );
328 }
329 /**
330 * Active required plugin based on slug
331 *
332 * @param $plugin_name
333 *
334 * @return WP_Error|WP_REST_Response
335 * @since 1.0.0
336 */
337 public function activate_mrm_plugins( \WP_REST_Request $request ) {
338 if( !function_exists('activate_plugin') ) {
339 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
340 }
341 $plugins = isset( $request['plugins'] ) ? $request['plugins'] : [];
342 $plugin_slug_arr = [];
343 $should_activated = [];
344 if( !empty($plugins) ){
345 foreach( $plugins as $plugin ){
346 if( 'mail-mint' == $plugin ) {
347 $plugin_slug_arr['mail-mint/mail-mint.php'] = false;
348 $should_activated['mail-mint/mail-mint.php'] = false;
349 }
350 }
351 }
352 foreach ( $plugin_slug_arr as $slug => $is_silent ) {
353 $data = activate_plugin( $slug, '', false, $is_silent );
354
355 if ( !is_wp_error( $data ) ) {
356 $should_activated[ $slug ] = true;
357 }
358 }
359 delete_transient( '_wc_activation_redirect' );
360 foreach ( $should_activated as $slug => $is_activated ) {
361 if(!$is_activated) {
362 $settings['success'] = false;
363 return rest_ensure_response( $settings );
364 }
365 }
366
367 $settings['success'] = true;
368 return rest_ensure_response( $settings );
369 }
370
371
372 /**
373 * Disable activation redirect
374 */
375 public function disable_wc_activation_redirect() {
376 delete_transient( '_wc_activation_redirect' );
377 }
378
379
380
381 /**
382 * Activate required plugins
383 *
384 * @param $plugin_name
385 */
386 public function active_plugin($plugin_slug,$permission = 1) {
387 $plugin_slug_arr = array();
388
389 switch ($plugin_slug) {
390 case 'elementor':
391 $plugin_slug_arr = array(
392 'elementor/elementor.php' => true,
393 );
394 break;
395 case 'gutenberg':
396 if($permission == 1){
397 $plugin_slug_arr = array(
398 'qubely/qubely.php' => true,
399 );
400 }
401 break;
402 case 'divi-builder':
403 $is_divi_installed = Wpfnl_functions::wpfnl_check_is_plugin_installed( $plugin_slug.'/divi-builder.php' );
404 $is_divi_theme_active = Wpfnl_functions::wpfnl_is_theme_active( 'Divi' );
405 if( $is_divi_installed ){
406 $plugin_slug_arr = array(
407 'divi-builder/divi-builder.php' => true,
408 );
409 }
410 break;
411
412 }
413 if($plugin_slug_arr) {
414 foreach ( $plugin_slug_arr as $slug => $is_silent ) {
415 $activate[ $slug ] = activate_plugin( $slug, '', false, $is_silent );
416 }
417 }
418
419 if(is_plugin_active( 'elementor/elementor.php' )){
420 Manager::create_default_kit();
421 }
422 }
423
424
425 /**
426 * Validate a settings group_id against WPFunnels-owned option keys.
427 *
428 * The `group_id` path parameter is passed straight into get_option()/update_option(),
429 * so it MUST be restricted to plugin-owned option names. Without this guard a request
430 * could target arbitrary WordPress options (e.g. `wp_user_roles`) and escalate privileges.
431 *
432 * @param string $group_id Option key supplied via the route.
433 *
434 * @return bool True when the key is a WPFunnels-owned option, false otherwise.
435 * @since 3.12.9
436 */
437 protected function is_allowed_settings_group( $group_id ) {
438 if ( ! is_string( $group_id ) || '' === $group_id ) {
439 return false;
440 }
441
442 $allowed = array(
443 '_wpfunnels_general_settings',
444 '_wpfunnels_permalink_settings',
445 '_wpfunnels_optin_settings',
446 '_wpfunnels_advanced_settings',
447 '_wpfunnels_integrations',
448 '_wpfunnels_notification_settings',
449 '_wpfunnels_lms_settings',
450 '_wpfunnels_recaptcha_setting',
451 '_wpfunnels_google_map_api_key',
452 '_wpfunnels_user_roles',
453 );
454
455 if ( in_array( $group_id, $allowed, true ) ) {
456 return true;
457 }
458
459 // Defense in depth: only allow plugin-prefixed option keys so add-ons that
460 // register their own `_wpfunnels_*` settings groups keep working, while any
461 // WordPress core / third-party option name is rejected.
462 return 0 === strpos( $group_id, '_wpfunnels_' );
463 }
464
465
466 /**
467 * Update a single setting in a group.
468 *
469 * @param WP_REST_Request $request Request data.
470 *
471 * @return WP_Error|WP_REST_Response
472 * @since 1.0.0
473 */
474 public function update_settings( $request ) {
475 if( isset( $request['settings_id'], $request['group_id'] )){
476 if ( ! $this->is_allowed_settings_group( $request['group_id'] ) ) {
477 return new WP_Error( 'rest_setting_group_invalid', __( 'Invalid setting group.', 'wpfnl' ), array( 'status' => 403 ) );
478 }
479 if( $request['settings_id'] === 'permalink') {
480 $default = Wpfnl_functions::get_permalink_settings();
481 $settings = Wpfnl_functions::get_admin_settings( '_wpfunnels_permalink_settings', $default);
482 } elseif( $request['settings_id'] === 'optin') {
483 $default = Wpfnl_functions::get_optin_settings();
484 $settings = Wpfnl_functions::get_admin_settings( '_wpfunnels_optin_settings', $default);
485 } elseif ($request['settings_id'] === 'funnel_type') {
486 $default = Wpfnl_functions::get_general_settings();
487 $settings = Wpfnl_functions::get_admin_settings( $request['group_id'], $default);
488 }
489 else {
490 $default = Wpfnl_functions::get_general_settings();
491 $settings = Wpfnl_functions::get_admin_settings( $request['group_id'], $default );
492 }
493
494 if ( !$settings ) {
495 return new WP_Error( 'rest_setting_invalid', __( 'Invalid setting.', 'wpfnl' ), array( 'status' => 404 ) );
496 }
497 if ( empty( $settings ) ) {
498 return new WP_Error( 'rest_setting_invalid', __( 'Invalid setting.', 'wpfnl' ), array( 'status' => 404 ) );
499 }
500
501 if($request['type'] !== 'ignore_activation' ) {
502 $this->active_plugin($request['slug'],$request['permission']);
503 }
504
505 if($request['settings_id'] === 'permalink') {
506 $settings['structure'] = $request['settings'];
507 $settings['funnel_base'] = $request['funnelBase'];
508 $settings['step_base'] = $request['stepBase'];
509 Wpfnl_functions::update_admin_settings('_wpfunnels_permalink_saved', true);
510 Wpfnl_functions::update_admin_settings($request['group_id'], $settings);
511
512 }else {
513 if( 'funnel_type' === $request['settings_id'] ) {
514 $general_settings = get_option( '_wpfunnels_general_settings' );
515 $settings[$request['settings_id']] = isset($general_settings['funnel_type']) ? $general_settings['funnel_type'] : 'sales';
516 }else{
517 $settings[$request['settings_id']] = $request['value'];
518 }
519
520 Wpfnl_functions::update_admin_settings($request['group_id'], $settings);
521
522 }
523 }
524 $settings['success'] = true;
525 $settings = $this->prepare_item_for_response( $settings, $request );
526 delete_option(WPFNL_TEMPLATES_OPTION_KEY);
527 delete_transient('wpfunnels_remote_template_data_' . WPFNL_VERSION);
528 return rest_ensure_response( $settings );
529 }
530
531
532 /**
533 * Check lms or not
534 */
535 public function is_lms( $request ){
536
537 $response = [
538 'success' => false,
539 'is_lms' => false,
540 ];
541
542 if( $request['funnel_id'] ){
543 $funnel_id = $request['funnel_id'];
544 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
545 if( Wpfnl_functions::is_lms_addon_active() && $type == 'lms' ){
546 $response['success'] = true;
547 $response['is_lms'] = true;
548 }else{
549 $response['success'] = true;
550 $response['is_lms'] = false;
551 }
552 }
553 return rest_ensure_response( $response );
554 }
555
556
557 /**
558 * Update funnel type
559 *
560 * @param Array $request
561 *
562 * @return Array
563 * @since 2.5.3
564 */
565 public function update_funnel_type( $request ){
566
567 $response = [
568 'success' => false,
569 ];
570
571 if( $request['type'] ){
572 $type = $request['type'];
573 $general_settings = get_option( '_wpfunnels_general_settings' );
574 $general_settings['funnel_type'] = $type;
575 update_option('_wpfunnels_general_settings', $general_settings );
576 $response = [
577 'success' => true,
578 ];
579 }
580 return rest_ensure_response( $response );
581 }
582
583
584 /**
585 * Update funnel builder
586 *
587 * @param Array $request
588 *
589 * @return Array
590 * @since 2.5.3
591 */
592 public function update_builder_type( $request ){
593
594 $response = [
595 'success' => false,
596 ];
597
598 if( $request['builder'] ){
599 $builder = $request['builder'];
600 $general_settings = get_option( '_wpfunnels_general_settings' );
601 $general_settings['builder'] = $builder;
602 update_option('_wpfunnels_general_settings', $general_settings );
603 $response = [
604 'success' => true,
605 ];
606 }
607 return rest_ensure_response( $response );
608 }
609
610
611 /**
612 * Remember which canvas layout the current user last switched to.
613 *
614 * Stored per user rather than in the shared settings, so one admin flipping
615 * the view switcher does not change the canvas for the rest of the team. The
616 * site-wide default in Settings still applies to anyone who never switched.
617 *
618 * @param WP_REST_Request $request The REST request object.
619 *
620 * @return WP_REST_Response
621 * @since 3.12.13
622 */
623 public function update_canvas_view_mode( $request ) {
624 $mode = isset( $request['mode'] ) ? sanitize_text_field( $request['mode'] ) : '';
625 $user_id = get_current_user_id();
626
627 if ( ! $user_id || ! in_array( $mode, Wpfnl_functions::get_funnel_builder_modes(), true ) ) {
628 return rest_ensure_response( array( 'success' => false ) );
629 }
630
631 update_user_meta( $user_id, Wpfnl_functions::CANVAS_VIEW_MODE_META_KEY, $mode );
632
633 if ( 'vertical' === $mode ) {
634 do_action( 'wpfunnels_vertical_mode_used' );
635 }
636
637 return rest_ensure_response(
638 array(
639 'success' => true,
640 'mode' => $mode,
641 )
642 );
643 }
644
645
646 /**
647 * Activates plugins.
648 *
649 * @param WP_REST_Request $request The REST request object.
650 */
651 public function activate_plugins( $request ){
652 $response = [
653 'success' => false,
654 ];
655
656 if( !isset( $request['plugins'] )){
657 rest_ensure_response( $response );
658 }
659
660 $plugins = $request['plugins'];
661 $activatePluginInstance = new \WPFunnels\Admin\SetupWizard\ActivatePlugin( $plugins );
662 $response = $activatePluginInstance->activate_plugins();
663 return rest_ensure_response( $response );
664 }
665
666
667 /**
668 * Save setup wizard settings
669 *
670 * @param WP_REST_Request $request The REST request object containing name and value.
671 *
672 * @return WP_REST_Response Response object with success status and message.
673 * @since 2.5.20
674 */
675 public function save_setup_wizard_settings( $request ){
676 $response = [
677 'success' => false,
678 ];
679
680 // Validate required parameters.
681 if( !isset( $request['name'],$request['value'] )){
682 rest_ensure_response( $response );
683 }
684
685 if( 'builder' === $request['name'] || 'funnel_type' === $request['name'] ){
686 // Get and process the value using the appropriate method.
687 $name = sanitize_text_field($request['name']);
688 $value = sanitize_text_field($request['value']);
689
690 // Process the value based on the name.
691 if( 'builder' === $name ){
692 $value = 'qubely' === $value ? 'gutenberg' : $value;
693 }
694
695 // Update the setting.
696 $settings = Wpfnl_functions::get_general_settings();
697 $settings[$name] = $value;
698 update_option('_wpfunnels_general_settings', $settings );
699
700 if( 'builder' === $name ){
701 delete_option(WPFNL_TEMPLATES_OPTION_KEY.'_wc');
702 delete_option(WPFNL_TEMPLATES_OPTION_KEY.'_lms');
703 delete_transient('wpfunnels_remote_template_data_wc_' . WPFNL_VERSION);
704 delete_transient('wpfunnels_remote_template_data_lms_' . WPFNL_VERSION);
705 delete_transient('wpfunnels_remote_template_data_lead_' . WPFNL_VERSION);
706 delete_transient('wpfunnels_remote_template_data_store_checkout_' . WPFNL_VERSION);
707 }
708
709 $response = [
710 'success' => true,
711 ];
712 }
713 return rest_ensure_response( $response );
714 }
715
716
717 /**
718 * Create contact to Mail Mint.
719 *
720 * @param WP_REST_Request $request The REST request object.
721 */
722 public function create_contact( $request ){
723 $response = [
724 'success' => false,
725 ];
726
727 if( !isset( $request['email'] )){
728 rest_ensure_response( $response );
729 }
730
731 $email = sanitize_text_field($request['email']);
732 $name = isset($request['name']) ? sanitize_text_field($request['name']) : '';
733 $createContactInstance = new \WPFunnels\Admin\SetupWizard\CreateContact($email, $name );
734 $response = $createContactInstance->create_contact_via_webhook();
735 update_option( 'wpfunnels_activation_email', $email );
736 $createContactInstance->send_contact_to_appsero();
737 return rest_ensure_response( $response );
738 }
739
740
741
742 /**
743 * Get funnel type id
744 */
745 public function get_funnel_type_id( $request ){
746
747 $response = [
748 'success' => false,
749 'type_id' => '',
750 ];
751
752 if( $request['funnel_id'] ){
753 $funnel_id = $request['funnel_id'];
754 $type = get_post_meta( $funnel_id, '_wpfnl_funnel_type', true );
755 $term = get_term_by('slug', $type, 'template_type');
756 if( $term ){
757 $response['success'] = true;
758 $response['type_id'] = $term->term_id;
759 }
760 }
761
762 return rest_ensure_response( $response );
763 }
764
765
766
767
768 /**
769 * Prepare a single setting object for response.
770 *
771 * @param object $item Setting object.
772 * @param WP_REST_Request $request Request object.
773 *
774 * @return WP_REST_Response $response Response data.
775 * @since 3.0.0
776 */
777 public function prepare_item_for_response( $item, $request ) {
778 $data = $this->add_additional_fields_to_object( $item, $request );
779 $response = rest_ensure_response( $data );
780 $response->add_links( $this->prepare_links( $request['settings_id'] ) );
781 return $response;
782 }
783
784
785
786 }
787