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-list-modules-handler.php

class-merchant-list-modules-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-list-modules-handler.php

88 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant List Modules Handler.
4 *
5 * Handles the merchant/list-modules ability.
6 * Returns all modules with their type, status, and available operations.
7 *
8 * @package Merchant
9 * @since 2.3.0
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Merchant_List_Modules_Handler
18 *
19 * Discovers and lists all Merchant modules with enriched metadata
20 * for AI clients: module type, campaign count, available operations,
21 * pro status, and activation state.
22 *
23 * @since 2.3.0
24 */
25 class Merchant_List_Modules_Handler extends Merchant_Abstract_Handler {
26
27 /**
28 * Handle the list-modules request.
29 *
30 * @param array<string, mixed> $params { filter?: string, section?: string }
31 *
32 * @return array<string, mixed> Response envelope.
33 */
34 public function handle( $params ) {
35 $filter = isset( $params['filter'] ) ? $params['filter'] : '';
36 $section = isset( $params['section'] ) ? $params['section'] : '';
37
38 $modules_data = Merchant_Admin_Modules::$modules_data;
39 $active_map = get_option( 'merchant-modules', array() );
40 $modules = array();
41 $active_count = 0;
42
43 foreach ( $modules_data as $module_id => $data ) {
44 // Exclude internal modules.
45 if ( Merchant_Abilities_Registry::is_excluded( $module_id ) ) {
46 continue;
47 }
48
49 $is_active = ! empty( $active_map[ $module_id ] );
50
51 // Apply status filter.
52 if ( 'active' === $filter && ! $is_active ) {
53 continue;
54 }
55 if ( 'inactive' === $filter && $is_active ) {
56 continue;
57 }
58
59 // Apply section filter.
60 if ( '' !== $section && isset( $data['section'] ) && $data['section'] !== $section ) {
61 continue;
62 }
63
64 if ( $is_active ) {
65 ++$active_count;
66 }
67
68 $module_entry = array(
69 'module_id' => $module_id,
70 'is_active' => $is_active,
71 'is_pro' => ! empty( $data['pro'] ),
72 'section' => isset( $data['section'] ) ? $data['section'] : '',
73 );
74
75 $modules[] = $module_entry;
76 }
77
78 return array(
79 'success' => true,
80 'data' => array(
81 'modules' => $modules,
82 'total_count' => count( $modules ),
83 'active_count' => $active_count,
84 ),
85 );
86 }
87 }
88