PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.3
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.3
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 / common-settings.php

common-settings.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.3, at admin-legacy-core/api/common-settings.php

139 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Common Settings Data Query.
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\GlobalSettings;
18
19 /**
20 * Class Admin_Query.
21 */
22 class CommonSettings extends ApiBase {
23
24 /**
25 * Route base.
26 *
27 * @var string
28 */
29 protected $rest_base = '/admin/commonsettings/';
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 * Constructor
55 */
56 public function __construct() {
57
58 add_filter( 'cartflows_admin_global_data_options', array( $this, 'add_other_option_data' ), 10, 1 );
59 }
60
61 /**
62 * Add flow meta options.
63 *
64 * @param array $options options.
65 * @return array.
66 */
67 public function add_other_option_data( $options ) {
68
69 $options['cartflows_delete_plugin_data'] = get_option( 'cartflows_delete_plugin_data' );
70 $options['cartflows_stats_report_emails'] = get_option( 'cartflows_stats_report_emails', 'enable' );
71 $options['cf_usage_optin'] = get_option( 'cf_usage_optin', 'no' );
72 $options['cartflows_stats_report_email_ids'] = get_option( 'cartflows_stats_report_email_ids', get_option( 'admin_email' ) );
73 // One-shot toggle: always renders as off (we never persist it). Explicit
74 // 'disable' so ToggleField's first click flips it straight to 'enable'.
75 $options['cartflows-switch-to-new-ui'] = 'disable';
76
77 return $options;
78 }
79
80 /**
81 * Init Hooks.
82 *
83 * @since 1.0.0
84 * @return void
85 */
86 public function register_routes() {
87
88 $namespace = $this->get_api_namespace();
89
90 register_rest_route(
91 $namespace,
92 $this->rest_base,
93 array(
94 array(
95 'methods' => \WP_REST_Server::READABLE,
96 'callback' => array( $this, 'get_common_settings' ),
97 'permission_callback' => array( $this, 'get_items_permissions_check' ),
98 'args' => array(),
99 ),
100 'schema' => array( $this, 'get_public_item_schema' ),
101 )
102 );
103 }
104
105 /**
106 * Get common settings.
107 *
108 * @param WP_REST_Request $request Full details about the request.
109 */
110 public function get_common_settings( $request ) {
111
112 $settings = GlobalSettings::get_global_settings_fields();
113 $options = AdminHelper::get_options();
114
115 $global_settings = array(
116 'settings' => $settings,
117 'options' => $options,
118 );
119
120 return $global_settings;
121 }
122
123 /**
124 * Check whether a given request has permission to read notes.
125 *
126 * @param WP_REST_Request $request Full details about the request.
127 * @return WP_Error|boolean
128 */
129 public function get_items_permissions_check( $request ) {
130
131 // Security: Settings endpoint requires cartflows_manage_settings to prevent sensitive data exposure.
132 if ( ! current_user_can( 'cartflows_manage_settings' ) ) {
133 return new \WP_Error( 'cartflows_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'cartflows' ), array( 'status' => rest_authorization_required_code() ) );
134 }
135
136 return true;
137 }
138 }
139