PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.2
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.2
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.2, at admin-legacy-core/api/common-settings.php

136 lines 3.1 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
74 return $options;
75 }
76
77 /**
78 * Init Hooks.
79 *
80 * @since 1.0.0
81 * @return void
82 */
83 public function register_routes() {
84
85 $namespace = $this->get_api_namespace();
86
87 register_rest_route(
88 $namespace,
89 $this->rest_base,
90 array(
91 array(
92 'methods' => \WP_REST_Server::READABLE,
93 'callback' => array( $this, 'get_common_settings' ),
94 'permission_callback' => array( $this, 'get_items_permissions_check' ),
95 'args' => array(),
96 ),
97 'schema' => array( $this, 'get_public_item_schema' ),
98 )
99 );
100 }
101
102 /**
103 * Get common settings.
104 *
105 * @param WP_REST_Request $request Full details about the request.
106 */
107 public function get_common_settings( $request ) {
108
109 $settings = GlobalSettings::get_global_settings_fields();
110 $options = AdminHelper::get_options();
111
112 $global_settings = array(
113 'settings' => $settings,
114 'options' => $options,
115 );
116
117 return $global_settings;
118 }
119
120 /**
121 * Check whether a given request has permission to read notes.
122 *
123 * @param WP_REST_Request $request Full details about the request.
124 * @return WP_Error|boolean
125 */
126 public function get_items_permissions_check( $request ) {
127
128 // Security: Settings endpoint requires cartflows_manage_settings to prevent sensitive data exposure.
129 if ( ! current_user_can( 'cartflows_manage_settings' ) ) {
130 return new \WP_Error( 'cartflows_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'cartflows' ), array( 'status' => rest_authorization_required_code() ) );
131 }
132
133 return true;
134 }
135 }
136