Hooks (actions and filters)
Hooks (Actions und Filter) zum Erweitern und Anpassen des Plugin-Verhaltens. Alle verwenden den Namespace polski/.
Widerrufs-Hooks
Section titled “Widerrufs-Hooks”polski/withdrawal/days
Section titled “polski/withdrawal/days”Filtert die Anzahl der Tage für den Vertragswiderruf.
/** * @param int $days Number of days for withdrawal (default 14) */apply_filters('polski/withdrawal/days', int $days): int;Beispiel:
add_filter('polski/withdrawal/days', function (int $days): int { return 30; // Extend to 30 days});polski/withdrawal/excluded_categories
Section titled “polski/withdrawal/excluded_categories”Filtert die vom Widerrufsrecht ausgeschlossenen Produktkategorien.
/** * @param array $categories Array of category IDs */apply_filters('polski/withdrawal/excluded_categories', array $categories): array;Beispiel:
add_filter('polski/withdrawal/excluded_categories', function (array $categories): array { $categories[] = 15; // "Digital products" category ID $categories[] = 22; // "Hygiene products" category ID return $categories;});polski/withdrawal/form_fields
Section titled “polski/withdrawal/form_fields”Filtert die Felder des Widerrufsformulars.
/** * @param array $fields Array of form fields */apply_filters('polski/withdrawal/form_fields', array $fields): array;Beispiel:
add_filter('polski/withdrawal/form_fields', function (array $fields): array { $fields['reason'] = [ 'type' => 'textarea', 'label' => 'Withdrawal reason', 'required' => false, ]; return $fields;});polski/withdrawal/email_sent
Section titled “polski/withdrawal/email_sent”Action, die nach dem Versand der E-Mail zur Widerrufsbestätigung ausgelöst wird.
/** * @param int $order_id Order ID * @param array $form_data Form data */do_action('polski/withdrawal/email_sent', int $order_id, array $form_data): void;Beispiel:
add_action('polski/withdrawal/email_sent', function (int $order_id, array $form_data): void { // Log withdrawals to external system wp_remote_post('https://api.crm.pl/withdrawals', [ 'body' => wp_json_encode([ 'order_id' => $order_id, 'date' => current_time('mysql'), ]), ]);}, 10, 2);Preis-Hooks
Section titled “Preis-Hooks”polski/price/unit_format
Section titled “polski/price/unit_format”Filtert das Anzeigeformat des Grundpreises.
/** * @param string $format Unit price format * @param float $unit_price Unit price * @param string $unit Unit of measurement (kg, l, m, pcs) * @param int $product_id Product ID */apply_filters('polski/price/unit_format', string $format, float $unit_price, string $unit, int $product_id): string;Beispiel:
add_filter('polski/price/unit_format', function (string $format, float $unit_price, string $unit, int $product_id): string { return sprintf('%s / %s', wc_price($unit_price), $unit);}, 10, 4);polski/price/vat_label
Section titled “polski/price/vat_label”Filtert das neben dem Preis angezeigte MwSt.-Label.
/** * @param string $label Label text * @param string $tax_status Product tax status */apply_filters('polski/price/vat_label', string $label, string $tax_status): string;Beispiel:
add_filter('polski/price/vat_label', function (string $label, string $tax_status): string { if ($tax_status === 'taxable') { return 'gross (incl. VAT)'; } return 'VAT exempt';}, 10, 2);Omnibus-Hooks
Section titled “Omnibus-Hooks”polski/omnibus/lowest_price
Section titled “polski/omnibus/lowest_price”Filtert den niedrigsten Preis der letzten 30 Tage (Omnibus-Richtlinie).
/** * @param float $price Lowest price * @param int $product_id Product ID * @param int $days Number of days back */apply_filters('polski/omnibus/lowest_price', float $price, int $product_id, int $days): float;Beispiel:
add_filter('polski/omnibus/lowest_price', function (float $price, int $product_id, int $days): float { // Skip products from the "Outlet" category if (has_term('outlet', 'product_cat', $product_id)) { return 0.0; // Do not display Omnibus price } return $price;}, 10, 3);polski/omnibus/display_format
Section titled “polski/omnibus/display_format”Filtert das Anzeigeformat des Omnibus-Preises.
/** * @param string $html HTML with price * @param float $price Lowest price * @param int $product_id Product ID */apply_filters('polski/omnibus/display_format', string $html, float $price, int $product_id): string;Beispiel:
add_filter('polski/omnibus/display_format', function (string $html, float $price, int $product_id): string { return sprintf( '<small class="omnibus-price">Lowest price from 30 days: %s</small>', wc_price($price) );}, 10, 3);polski/omnibus/price_recorded
Section titled “polski/omnibus/price_recorded”Action, die nach dem Speichern eines Preises in der Omnibus-Historie ausgelöst wird.
/** * @param int $product_id Product ID * @param float $price Saved price */do_action('polski/omnibus/price_recorded', int $product_id, float $price): void;KSeF-Hooks
Section titled “KSeF-Hooks”polski/ksef/invoice_data
Section titled “polski/ksef/invoice_data”Filtert die Rechnungsdaten vor dem Versand an KSeF.
/** * @param array $data Invoice data * @param WC_Order $order Order object */apply_filters('polski/ksef/invoice_data', array $data, WC_Order $order): array;Beispiel:
add_filter('polski/ksef/invoice_data', function (array $data, WC_Order $order): array { $data['additional_info'] = 'Automatically generated invoice'; return $data;}, 10, 2);polski/ksef/invoice_sent
Section titled “polski/ksef/invoice_sent”Action, die nach dem erfolgreichen Versand einer Rechnung an KSeF ausgelöst wird.
/** * @param int $order_id Order ID * @param string $ksef_id KSeF reference number * @param array $response KSeF API response */do_action('polski/ksef/invoice_sent', int $order_id, string $ksef_id, array $response): void;Beispiel:
add_action('polski/ksef/invoice_sent', function (int $order_id, string $ksef_id, array $response): void { update_post_meta($order_id, '_ksef_reference', $ksef_id); $order = wc_get_order($order_id); $order->add_order_note(sprintf('Invoice sent to KSeF: %s', $ksef_id));}, 10, 3);DSA-Hooks
Section titled “DSA-Hooks”polski/dsa/report_fields
Section titled “polski/dsa/report_fields”Filtert die Formularfelder der DSA-Meldung.
/** * @param array $fields Form fields */apply_filters('polski/dsa/report_fields', array $fields): array;Beispiel:
add_filter('polski/dsa/report_fields', function (array $fields): array { $fields['screenshot'] = [ 'type' => 'file', 'label' => 'Screenshot', 'required' => false, 'accept' => '.jpg,.png,.pdf', ]; return $fields;});polski/dsa/report_submitted
Section titled “polski/dsa/report_submitted”Action, die nach dem Einreichen einer DSA-Meldung ausgelöst wird.
/** * @param int $report_id Report ID * @param array $data Report data */do_action('polski/dsa/report_submitted', int $report_id, array $data): void;DOI-Hooks - Double Opt-in
Section titled “DOI-Hooks - Double Opt-in”polski/doi/verification_email
Section titled “polski/doi/verification_email”Filtert den Inhalt der DOI-Bestätigungs-E-Mail.
/** * @param string $message Email content * @param string $email Email address to verify * @param string $url Verification URL */apply_filters('polski/doi/verification_email', string $message, string $email, string $url): string;Beispiel:
add_filter('polski/doi/verification_email', function (string $message, string $email, string $url): string { return sprintf( 'Hello! Confirm your registration by clicking: <a href="%s">Confirm account</a>', esc_url($url) );}, 10, 3);polski/doi/verified
Section titled “polski/doi/verified”Action, die nach erfolgreicher DOI-Bestätigung ausgelöst wird.
/** * @param int $user_id User ID * @param string $email Email address */do_action('polski/doi/verified', int $user_id, string $email): void;Cache-Hooks
Section titled “Cache-Hooks”polski/cache/should_flush
Section titled “polski/cache/should_flush”Filtert die Entscheidung über das Leeren des Plugin-Caches.
/** * @param bool $should_flush Whether to flush cache * @param string $group Cache group (omnibus, badges, search) */apply_filters('polski/cache/should_flush', bool $should_flush, string $group): bool;Beispiel:
add_filter('polski/cache/should_flush', function (bool $should_flush, string $group): bool { // Do not flush search cache during import if ($group === 'search' && defined('WP_IMPORTING') && WP_IMPORTING) { return false; } return $should_flush;}, 10, 2);polski/cache/ttl
Section titled “polski/cache/ttl”Filtert die Cache-Lebensdauer (TTL) in Sekunden.
/** * @param int $ttl Time in seconds * @param string $group Cache group */apply_filters('polski/cache/ttl', int $ttl, string $group): int;Checkbox-Hooks
Section titled “Checkbox-Hooks”polski/checkboxes/render
Section titled “polski/checkboxes/render”Filtert das gerenderte Checkbox-HTML.
/** * @param string $html Checkbox HTML * @param array $checkbox Checkbox data * @param string $location Location (checkout, registration, contact) */apply_filters('polski/checkboxes/render', string $html, array $checkbox, string $location): string;polski/checkboxes/validated
Section titled “polski/checkboxes/validated”Action, die nach der Checkbox-Validierung ausgelöst wird.
/** * @param array $checkboxes Validated checkboxes * @param bool $valid Validation result */do_action('polski/checkboxes/validated', array $checkboxes, bool $valid): void;E-Mail-Hooks
Section titled “E-Mail-Hooks”polski/email/template
Section titled “polski/email/template”Filtert den Pfad der E-Mail-Vorlage.
/** * @param string $template Template path * @param string $type Email type (withdrawal, doi, waitlist) */apply_filters('polski/email/template', string $template, string $type): string;Beispiel:
add_filter('polski/email/template', function (string $template, string $type): string { if ($type === 'withdrawal') { return get_stylesheet_directory() . '/polski/emails/withdrawal.php'; } return $template;}, 10, 2);polski/email/headers
Section titled “polski/email/headers”Filtert die E-Mail-Header.
/** * @param array $headers Email headers * @param string $type Email type */apply_filters('polski/email/headers', array $headers, string $type): array;Hooks für Rechtsseiten
Section titled “Hooks für Rechtsseiten”polski/legal_page/template_data
Section titled “polski/legal_page/template_data”Filtert die in die Vorlage der Rechtsseite eingefügten Daten.
/** * @param array $data Template data * @param string $type Page type (terms, privacy, withdrawal, dsa_report) */apply_filters('polski/legal_page/template_data', array $data, string $type): array;Beispiel:
add_filter('polski/legal_page/template_data', function (array $data, string $type): array { if ($type === 'terms') { $data['delivery_info'] = 'Delivery within 2-5 business days.'; } return $data;}, 10, 2);polski/legal_page/generated
Section titled “polski/legal_page/generated”Action, die nach dem Erstellen einer Rechtsseite ausgelöst wird.
/** * @param int $page_id Page ID * @param string $type Page type */do_action('polski/legal_page/generated', int $page_id, string $type): void;Best Practices
Section titled “Best Practices”- Typen verwenden - deklarieren Sie in Callbacks die Typen von Parametern und Rückgabewerten
- Priorität - die Standardpriorität ist 10, verwenden Sie eine höhere (z. B. 20), um das Standardverhalten zu überschreiben
- Namespace - erstellen Sie in Ihren Plugins keine Hooks im Namespace
polski/, um Konflikte zu vermeiden - Kompatibilität - prüfen Sie vor der Verwendung, ob ein Hook existiert:
has_filter('polski/omnibus/lowest_price') - Dokumentation - dokumentieren Sie Ihre Callbacks mit PHPDoc-Kommentaren
Probleme melden: github.com/wppoland/polski/issues