| Server IP : 146.59.209.152 / Your IP : 216.73.216.152 Web Server : Apache System : Linux webm009.cluster131.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : monpetu ( 144298) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/monpetu/www/ipprint/wp-content/plugins/cartflows/admin-core/api/ |
Upload File : |
<?php
/**
* CartFlows Common Settings Data Query.
*
* @package CartFlows
*/
namespace CartflowsAdmin\AdminCore\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use CartflowsAdmin\AdminCore\Api\ApiBase;
use CartflowsAdmin\AdminCore\Inc\AdminHelper;
use CartflowsAdmin\AdminCore\Inc\GlobalSettings;
/**
* Class Admin_Query.
*/
class CommonSettings extends ApiBase {
/**
* Route base.
*
* @var string
*/
protected $rest_base = '/admin/commonsettings/';
/**
* Instance
*
* @access private
* @var object Class object.
* @since 1.0.0
*/
private static $instance;
/**
* Initiator
*
* @since 1.0.0
* @return object initialized object of class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
public function __construct() {
add_filter( 'cartflows_admin_global_data_options', array( $this, 'add_other_option_data' ), 10, 1 );
}
/**
* Add flow meta options.
*
* @param array $options options.
* @return array.
*/
public function add_other_option_data( $options ) {
$options['cartflows_delete_plugin_data'] = get_option( 'cartflows_delete_plugin_data' );
$options['cartflows_stats_report_emails'] = get_option( 'cartflows_stats_report_emails', 'enable' );
$options['cf_usage_optin'] = get_site_option( 'cf_usage_optin', 'no' );
$options['cartflows_stats_report_email_ids'] = get_option( 'cartflows_stats_report_email_ids', get_option( 'admin_email' ) );
// The toggle field expects an 'enable'/'disable' string (backComp). Older code paths
// may have stored a boolean true (set by 3.0 migration); coerce to 'enable' so the
// switch reflects the correct on-state without changing what is persisted.
$legacy_admin_raw = get_option( 'cartflows-legacy-admin', 'disable' );
$options['cartflows-legacy-admin'] = in_array( $legacy_admin_raw, array( true, 1, '1', 'enable', 'yes' ), true ) ? 'enable' : 'disable';
return $options;
}
/**
* Init Hooks.
*
* @since 1.0.0
* @return void
*/
public function register_routes() {
$namespace = $this->get_api_namespace();
register_rest_route(
$namespace,
$this->rest_base,
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_common_settings' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => array(),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}
/**
* Get common settings.
*
* @param WP_REST_Request $request Full details about the request.
*/
public function get_common_settings( $request ) {
$settings = GlobalSettings::get_global_settings_fields();
$options = AdminHelper::get_options();
$global_settings = array(
'settings' => $settings,
'options' => $options,
);
return $global_settings;
}
/**
* Check whether a given request has permission to read notes.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
// Security: Settings endpoint requires cartflows_manage_settings to prevent sensitive data exposure.
if ( ! current_user_can( 'cartflows_manage_settings' ) ) {
return new \WP_Error( 'cartflows_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'cartflows' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
}