Skip to content

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

// Throws UnAuthorizedException on failure
Request::verify_nonce($_POST['_wpnonce'], 'my_action');

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

// Reads the axios-encoded request payload
$data = Request::get_axios_data(); // ?array

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);