PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.0
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.0
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / abilities / handlers / class-merchant-get-settings-handler.php

class-merchant-get-settings-handler.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.0, at inc/abilities/handlers/class-merchant-get-settings-handler.php

76 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant Get Settings Handler.
4 *
5 * Handles the merchant/get-module-settings ability.
6 * Returns a module's settings with optional field schemas.
7 *
8 * @package Merchant
9 * @since 2.3.0
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Merchant_Get_Settings_Handler
18 *
19 * Reads module settings using the schema generator.
20 * Works on both active and inactive modules (inactive
21 * modules include is_active: false in the response).
22 *
23 * @since 2.3.0
24 */
25 class Merchant_Get_Settings_Handler extends Merchant_Abstract_Handler {
26
27 /**
28 * Schema generator instance.
29 *
30 * @var Merchant_Schema_Generator
31 */
32 private $schema_generator;
33
34 /**
35 * Constructor.
36 *
37 * @param Merchant_Schema_Generator $schema_generator Schema generator instance.
38 */
39 public function __construct( $schema_generator ) {
40 $this->schema_generator = $schema_generator;
41 }
42
43 /**
44 * Handle the get-module-settings request.
45 *
46 * @param array<string, mixed> $params { module_id: string, include_schema?: bool }
47 *
48 * @return array<string, mixed>|WP_Error Response envelope or WP_Error on failure.
49 */
50 public function handle( $params ) {
51 $module_id = isset( $params['module_id'] ) ? $params['module_id'] : '';
52 $include_schema = isset( $params['include_schema'] ) ? $this->parse_bool( $params['include_schema'], true ) : true;
53
54 $error = $this->preflight( $module_id );
55 if ( null !== $error ) {
56 return $error;
57 }
58
59 // Check activation status.
60 $active_modules = get_option( 'merchant-modules', array() );
61 $is_active = ! empty( $active_modules[ $module_id ] );
62
63 // Generate settings via schema generator.
64 $settings = $this->schema_generator->generate( $module_id, $include_schema );
65
66 return array(
67 'success' => true,
68 'data' => array(
69 'module_id' => $module_id,
70 'is_active' => $is_active,
71 'settings' => $settings,
72 ),
73 );
74 }
75 }
76