Helpers¶
Static utility classes for common cross-cutting concerns.
Request¶
Barberklingen\BasePlugin\Helpers\Request
Stateless helpers for reading and validating request data.
Reading parameters¶
use Barberklingen\BasePlugin\Helpers\Request;
// From $_REQUEST (falls back through POST, GET)
$value = Request::request('my_param', 'default');
$value = Request::post('my_param');
$value = Request::get('my_param');
// Required — throws MissingRequestParamException if absent
$value = Request::required('my_param');
Nonce verification¶
Auth header¶
// Returns true if the Authorization header matches $auth_key
Request::verify_auth_header($auth_key, 'Authorization');
User authorization¶
// Checks that the current user owns the given subscription/order
Request::can_user_manage_subscription($subscription); // bool
Request::can_user_manage_order($order); // bool
Axios support¶
DateHelper¶
Barberklingen\BasePlugin\Helpers\DateHelper
use Barberklingen\BasePlugin\Helpers\DateHelper;
DateHelper::format_timestamp(time(), DateHelper::DATETIME_FORMAT); // '2024-01-15 09:00:00'
DateHelper::format_date_string('2024-01-15', DateHelper::DATE_FORMAT);
DateHelper::i18n(time()); // Localised date string using date_i18n()
Constants: DATETIME_FORMAT = 'Y-m-d H:i:s', DATE_FORMAT = 'Y-m-d'
RenewalHelper¶
Barberklingen\BasePlugin\Helpers\RenewalHelper
Utilities for managing subscription renewal dates.
use Barberklingen\BasePlugin\Helpers\RenewalHelper;
// Align a timestamp to 03:00:00 (standard renewal time)
$timestamp = RenewalHelper::align_hours($timestamp);
// Set the next payment date on a subscription (validates it's in the future)
RenewalHelper::set_renewal_date($subscription, '2024-06-01');
// Throws if date is today or in the past
// Removes trial_end if it conflicts with the new renewal date
The standard renewal hour 03:00:00 is stored in RenewalHelper::$RENEWAL_HOURS.
WCAdminRequest¶
Barberklingen\BasePlugin\Helpers\WCAdminRequest
Detects the current admin screen context and abstracts HPOS vs legacy storage differences.
use Barberklingen\BasePlugin\Helpers\WCAdminRequest;
// HPOS detection (result is cached)
WCAdminRequest::is_HPOS_enabled(); // bool
// Get screen IDs that work regardless of HPOS
WCAdminRequest::get_edit_order_screen_id();
WCAdminRequest::get_edit_subscription_screen_id();
// Current screen checks
WCAdminRequest::is_edit_order_screen(); // bool
WCAdminRequest::is_edit_subscription_screen(); // bool
WCAdminRequest::is_current_admin_screen('woocommerce_page_wc-settings'); // bool
// Bulk action hooks (HPOS vs legacy table)
WCAdminRequest::get_orders_bulk_actions_list_hook();
WCAdminRequest::get_subscriptions_bulk_actions_list_hook();
// Safe entity fetchers — accept WC_Order, WC_Subscription, WP_Post, or int
WCAdminRequest::get_order($entity);
WCAdminRequest::get_subscription($entity);
SQLHelper¶
Barberklingen\BasePlugin\Helpers\SQLHelper
use Barberklingen\BasePlugin\Helpers\SQLHelper;
// Build a simple SELECT query
$sql = SQLHelper::create_query_helper('my_table', ['status' => 'active'], 10);
// Build a WHERE clause with operators
$where = SQLHelper::prepare_where_query([
'status' => 'active',
'count' => ['compare' => '>', 'value' => 5],
'deleted' => null, // generates IS NULL
]);
ArrayHelper¶
Barberklingen\BasePlugin\Helpers\ArrayHelper
use Barberklingen\BasePlugin\Helpers\ArrayHelper;
$batches = ArrayHelper::to_batches($items, 50); // array of arrays, each max 50 items
ExceptionHelper¶
Barberklingen\BasePlugin\HelpersxceptionHelper
use Barberklingen\BasePlugin\HelpersxceptionHelper;
// Extracts the full message from Guzzle exceptions (which nest the response body)
$message = ExceptionHelper::getMessage($exception);
PackageVersion¶
Barberklingen\BasePlugin\Helpers\PackageVersion
Resolves the installed version of a Composer package. Composer 2 is read through its runtime API, Composer 1 through vendor/composer/installed.json — the two write that file in different shapes, and both are handled.
use Barberklingen\BasePlugin\Helpers\PackageVersion;
PackageVersion::get(); // "2.6.23", or null when unresolved
PackageVersion::get_reference(); // commit the package was installed from
PackageVersion::describe(); // "2.6.23", or "dev-master (a1b2c3d)" for branch installs
PackageVersion::get('barberklingen/woocommerce-klaviyo'); // any installed package
Any package installed alongside this one can be looked up, so a package that wants to show its own version in a system status report uses this rather than implementing the lookup again:
The reported commit is the one Composer installed from: an entry can carry both a source and a dist reference, and installation-source says which of them applies. The vendor directory is found by walking up from the helper, so the lookup does not depend on how deep the package sits; it stops at the nearest vendor/composer/installed.json, which is the installation that owns the file.