PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
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
← All changes | inc/modules/class-add-module.php +126 -3 2.2.82.3.2 View file →
@@ -36,8 +36,18 @@
36 36 */
37 37 public $module_data = array();
38 38
39 39 /**
40 + * AI prompt examples shown in the "Ask AI" popup for this module.
41 + *
42 + * Subclasses set this in their constructor with a 'blurb' string
43 + * and a 'prompts' array of example prompts.
44 + *
45 + * @var array
46 + */
47 + protected $ai_examples = array();
48 +
49 + /**
40 50 * Module options.
41 51 *
42 52 */
43 53 public $module_options_path = '';
@@ -51,8 +61,63 @@
51 61
52 62 protected $has_analytics = false;
53 63
54 64 /**
65 + * Option group definitions cache.
66 + *
67 + * @var array<int, array<string, mixed>>|null
68 + */
69 + protected $option_groups = null;
70 +
71 + /**
72 + * Initialize the module's option group definitions.
73 + *
74 + * Subclasses override this to define their settings panels.
75 + * Each element in the returned array corresponds to one settings
76 + * section in the admin UI.
77 + *
78 + * @return array<int, array<string, mixed>> Array of option group arrays, each with 'module', 'title', and 'fields' keys.
79 + */
80 + protected function init_option_groups() {
81 + return array();
82 + }
83 +
84 + /**
85 + * Get the module's option group definitions.
86 + *
87 + * Returns cached definitions if available. On first call,
88 + * initializes from the subclass and applies the filter for
89 + * third-party extensibility.
90 + *
91 + * @return array<int, array<string, mixed>> Filtered option group definitions.
92 + */
93 + public function get_option_groups() {
94 + if ( $this->option_groups !== null ) {
95 + return $this->option_groups;
96 + }
97 +
98 + $groups = $this->init_option_groups();
99 +
100 + /**
101 + * Filter a module's option group definitions.
102 + *
103 + * Allows third-party plugins to add, remove, or modify
104 + * the field definitions for any module.
105 + *
106 + * @param array<int, array<string, mixed>> $groups Array of option group arrays.
107 + *
108 + * @since 2.3.0
109 + */
110 + $this->option_groups = apply_filters(
111 + "merchant_{$this->module_id}_option_groups",
112 + $groups
113 + );
114 +
115 + return $this->option_groups;
116 + }
117 +
118 +
119 + /**
55 120 * Constructor.
56 121 *
57 122 */
58 123 public function __construct() {
@@ -92,8 +157,24 @@
92 157 return $this->has_analytics;
93 158 }
94 159
95 160 /**
161 + * Get the module's AI prompt examples.
162 + *
163 + * @return array Array with 'blurb' and 'prompts' keys, or an empty array if the module has none.
164 + */
165 + public function get_ai_examples() {
166 + /**
167 + * Filter a module's AI prompt examples.
168 + *
169 + * @param array $ai_examples Array with 'blurb' and 'prompts' keys.
170 + *
171 + * @since 2.3.0
172 + */
173 + return apply_filters( "merchant_{$this->module_id}_ai_examples", $this->ai_examples );
174 + }
175 +
176 + /**
96 177 * Get all analytics metrics and allow modules to filter them.
97 178 *
98 179 * @return array List of available metrics.
99 180 */
@@ -237,16 +318,58 @@
237 318
238 319 /**
239 320 * Add module options.
240 321 *
322 + * For migrated modules (those with option groups defined),
323 + * renders settings directly from get_option_groups().
324 + * Unmigrated modules fall back to including $module_options_path.
325 + *
326 + * @param string $module_path Default file path.
327 + * @param string $merchant_module Module ID being rendered.
328 + *
329 + * @return string File path to include, or empty string if already rendered.
241 330 */
242 331 public function add_module_options( $module_path, $merchant_module ) {
243 - if ( $this->module_id === $merchant_module ) {
244 - return $this->module_options_path;
332 + if ( $this->module_id !== $merchant_module ) {
333 + return $module_path;
245 334 }
246 335
247 - return $module_path;
336 + $groups = $this->get_option_groups();
337 +
338 + if ( ! empty( $groups ) ) {
339 + $this->before_render_option_groups();
340 +
341 + foreach ( $groups as $group ) {
342 + Merchant_Admin_Options::create( $group );
343 + }
344 +
345 + $this->after_render_option_groups();
346 +
347 + return '';
348 + }
349 +
350 + return $this->module_options_path;
248 351 }
352 +
353 + /**
354 + * Called before option groups are rendered in the admin.
355 + *
356 + * Override in subclasses that need to fire actions
357 + * before settings fields (e.g., help banners).
358 + *
359 + * @return void
360 + */
361 + protected function before_render_option_groups() {}
362 +
363 + /**
364 + * Called after option groups are rendered in the admin.
365 + *
366 + * Override in subclasses that need to fire actions
367 + * after settings fields.
368 + *
369 + * @return void
370 + */
371 + protected function after_render_option_groups() {}
249 372
250 373 /**
251 374 * Display error message if the shortcode is placed in the wrong place.
252 375 *