Below is a detailed description of the hooks and filters available in the Payment Page plugin, tailored for advanced developers. Each hook and filter includes its name, purpose, and usage examples.
Action Hooks
payment_page_after_payment
Purpose: Triggered after a payment is successfully processed.
Usage: Allows developers to execute additional actions like logging the transaction, notifying users, or updating external systems.
Example:
add_action('payment_page_after_payment', 'log_payment_details', 10, 2);
function log_payment_details($transaction_id, $amount) {
// Log the transaction details
error_log("Transaction processed. ID: $transaction_id, Amount: $amount");
}
payment_page_settings_saved
Purpose: Called after the plugin settings are saved.
Usage: Use this hook to perform actions like clearing caches, sending notifications, or validating settings.
Example:
add_action('payment_page_settings_saved', 'clear_cache_after_settings_change');
function clear_cache_after_settings_change() {
// Clear cached data after settings are updated
my_cache_clear_function();
}
payment_page_gateway_initialized
Purpose: Invoked when a payment gateway is initialized.
Usage: Perform setup actions, such as validating configurations or preparing necessary resources.
Example:
add_action('payment_page_gateway_initialized', 'check_gateway_configuration');
function check_gateway_configuration($gateway) {
// Check if gateway configuration is correct
if (!isset($gateway['api_key'])) {
// Handle missing API key
error_log("API key is missing for the gateway.");
}
}
payment_page_before_payment
Purpose: Triggered before a payment is processed.
Usage: Useful for running validation checks or modifying the payment request before it's sent to the gateway.
Example:
add_action('payment_page_before_payment', 'validate_payment_request', 10, 1);
function validate_payment_request($payment_data) {
// Perform validation on payment data
if ($payment_data['amount'] <= 0) {
wp_die('Invalid payment amount.');
}
}
payment_page_gateway_disabling
Purpose: Executed when a payment gateway is being disabled.
Usage: Perform cleanup actions or notify users about the change.
Example:
add_action('payment_page_gateway_disabling', 'notify_gateway_disabling', 10, 1);
function notify_gateway_disabling($gateway_name) {
// Notify users when a gateway is disabled
wp_mail('admin@example.com', 'Gateway Disabled', "$gateway_name has been disabled.");
}
Filter Hooks
payment_page_gateway_options
Purpose: Allows modification of the list of available payment gateways.
Usage: Customize which gateways are available to the user, adding or removing options as necessary.
Example:
add_filter('payment_page_gateway_options', 'add_custom_gateway', 10, 1);
function add_custom_gateway($gateways) {
// Add a custom payment gateway
$gateways[] = 'custom_gateway';
return $gateways;
}
payment_page_settings
Purpose: Filters the settings before they are saved.
Usage: Validate or modify settings to ensure they meet specific criteria.
Example:
add_filter('payment_page_settings', 'sanitize_settings_data', 10, 1);
function sanitize_settings_data($settings) {
// Sanitize the API key setting
$settings['api_key'] = sanitize_text_field($settings['api_key']);
return $settings;
}
payment_page_transaction_response
Purpose: Filters the response from payment gateways before it is processed by the plugin.
Usage: Modify response data for logging, notifications, or error handling.
Example:
add_filter('payment_page_transaction_response', 'process_transaction_response', 10, 1);
function process_transaction_response($response) {
// Modify the response to include additional data
$response['processed_time'] = current_time('mysql');
return $response;
}
payment_page_form_fields
Purpose: Allows modification of form fields rendered on the payment page.
Usage: Customize the payment form by adding or removing fields based on user needs.
Example:
add_filter('payment_page_form_fields', 'add_custom_form_fields', 10, 1);
function add_custom_form_fields($fields) {
// Add a custom input field to the payment form
$fields['custom_field'] = '<input type="text" name="custom_field" placeholder="Enter something...">';
return $fields;
}
payment_page_payment_methods
Purpose: Filters the list of payment methods available to users during checkout.
Usage: Add, remove, or modify payment methods based on specific criteria or conditions.
Example:
add_filter('payment_page_payment_methods', 'modify_payment_methods', 10, 1);
function modify_payment_methods($methods) {
// Remove 'check' as a payment method
if (($key = array_search('check', $methods)) !== false) {
unset($methods[$key]);
}
return $methods;
}
This section provides advanced developers with a detailed understanding of the available hooks and filters in the Payment Page plugin, including practical examples of how they can be implemented. If you need further elaboration on any specific hook or filter, or if you have additional questions, feel free to .