Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/includes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static function clearTransients()
delete_transient('beans_bamboo_display_current');
delete_transient('beans_liana_display_current');
delete_transient('beans_core_user_current_loginkey');
delete_transient('beans_liana_rule');
}

/**
Expand Down Expand Up @@ -345,6 +346,69 @@ public static function getDisplay()
return $display;
}

/**
* Retrieve rules from the STEM API.
* Fetch active rules from the Liana API endpoint.
*
* @param int $limit Optional limit for the number of rules to retrieve, defaults to 30
* @return array The rules object containing active rules
*
* @since 4.0.7
*/
public static function getRules($limit = 30)
{
$rules = self::requestTransientAPI(
'GET',
'liana/rule',
'STEM',
'v3',
array('limit' => $limit)
);

// If rules is empty return an empty array
if (empty($rules)) {
self::log('Helper: Liana Rules are empty');
return array();
}

// Format rules by UID for easier access
$formatted_rules = array();
if (isset($rules['data']) && is_array($rules['data'])) {
foreach ($rules['data'] as $rule) {
if (isset($rule['uid'])) {
$formatted_rules[$rule['uid']] = $rule;
}
}
}

return $formatted_rules;
}

/**
* Retrieve a single rule by UID from the STEM API.
*
* @param string $uid The unique identifier of the rule
* @return array|null The rule object or null if not found
*
* @since 4.0.7
*/
public static function getRule($uid)
{
$rule = self::requestTransientAPI(
'GET',
"liana/rule/{$uid}",
'STEM',
'v3'
);

if (empty($rule)) {
self::log("Helper: Rule with UID {$uid} not found");
return null;
}

return $rule;
}


/**
* Get a value from the PHP $_SESSION or WC_Session.
Expand Down