{"id":5059,"date":"2026-04-24T12:38:45","date_gmt":"2026-04-24T10:38:45","guid":{"rendered":"https:\/\/cevento-plugin.com\/docs\/002-hooks\/"},"modified":"2026-04-24T12:38:45","modified_gmt":"2026-04-24T10:38:45","slug":"002-hooks","status":"publish","type":"docs","link":"https:\/\/cevento-plugin.com\/en\/docs\/002-hooks\/","title":{"rendered":"Hooks"},"content":{"rendered":"\n<h2 id=\"bookings\">Bookings\n<\/h2><p>The following action hooks can be used to react to booking status changes:<\/p>\n<pre><code class=\"language-php\">add_action('cevento\/booking_received', function ($event, $booking) {\n    \/\/ Execute something when a new booking is received\n}, 10, 2);\n\nadd_action('cevento\/booking_confirmed', function ($event, $booking) {\n    \/\/ Execute something when the booking is confirmed\n}, 10, 2);\n\nadd_action('cevento\/booking_cancel', function ($event, $booking) {\n    \/\/ Execute something when the booking is cancelled\n}, 10, 2);<\/code><\/pre>\n<p>Do you have specific form fields that &ndash; if selected &ndash; should occupy more than one place when booked? The <code>cevento\/booking_places<\/code> filter can be used to determine the number of spots a booking should occupy:<\/p>\n<pre><code class=\"language-php\">add_filter('cevento\/booking_places', function ($spots, $fieldBag, $event) {\n    return 1;\n}, 10, 3);<\/code><\/pre>\n<h2 id=\"form-validation\">Form Validation<\/h2>\n<p>Form validation hooks are always called with an instance of <code>Cevento\\Form\\FieldBag<\/code>. This instance can be used to access individual fields and their values as well as trigger validation errors.<\/p>\n<pre><code class=\"language-php\"><?php add_action('cevento\/validate', function ($fieldBag, $event) {\n    \/\/ Retrieve field by label or key\n    $nameField = $fieldBag->getField('Name');\n\n    \/\/ Get field value\n    $nameValue = $nameField-&gt;getValue();\n\n    \/\/ Trigger a dynamic validation error for a specific field\n    if (strlen($nameValue) addError('The name must be at least 3 characters long.');\n    }\n\n    \/\/ Add a global error displayed above the form\n    $fieldBag-&gt;addGlobalError('Any global error message can be displayed here.');\n}, 10, 2);\n\nadd_action('cevento\/validate\/form=1', function ($fieldBag, $event) {\n    \/\/ Specific validation rules for the form with ID 1 can be added here\n});<\/code><\/pre>\n<h2 id=\"form-fields\">Form Fields<\/h2>\n<p>The following filters can be used to customize form fields. This allows you to dynamically change custom field settings right before the form is rendered:<\/p>\n<pre><code class=\"language-php\">add_filter('cevento\/prepare_field\/field_80799639', 'CallbackHandler', 10, 1);\nadd_filter('cevento\/prepare_field', function ($fieldConfig) {\n    return $fieldConfig;\n}, 10, 1);<\/code><\/pre>\n<h2 id=\"event-post-conversion\">Event Post Conversion<\/h2>\n<p>When converting an event into a post, only the content and title are transferred by default. The following hooks can be used to dynamically adjust categories or the content of the resulting post:<\/p>\n<pre><code class=\"language-php\">add_filter('cevento\/event_to_post_terms', function ($terms, $evt) {\n    return $terms; \/\/ Array of post term IDs\n});\n\nadd_filter('cevento\/event_to_post_content', function ($content, $evt) {\n    return $content; \/\/ Any HTML string, by default the event's HTML content\n});<\/code><\/pre>\n\n\n","protected":false},"featured_media":0,"parent":0,"template":"","meta":{"_acf_changed":false},"thema":[682],"class_list":["post-5059","docs","type-docs","status-publish","hentry","thema-development"],"acf":{"excerpt":"Action & Filter Hooks","toc":"<ol class=\"toc\">\n<li><a href=\"#bookings\"  uk-scroll=\"offset: 120\">Bookings<\/a><\/li>\n<li><a href=\"#form-validation\"  uk-scroll=\"offset: 120\">Form Validation<\/a><\/li>\n<li><a href=\"#form-fields\"  uk-scroll=\"offset: 120\">Form Fields<\/a><\/li>\n<li><a href=\"#event-post-conversion\"  uk-scroll=\"offset: 120\">Event Post Conversion<\/a><\/li>\n<\/ol>\n"},"_links":{"self":[{"href":"https:\/\/cevento-plugin.com\/en\/wp-json\/wp\/v2\/docs\/5059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cevento-plugin.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/cevento-plugin.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"wp:attachment":[{"href":"https:\/\/cevento-plugin.com\/en\/wp-json\/wp\/v2\/media?parent=5059"}],"wp:term":[{"taxonomy":"thema","embeddable":true,"href":"https:\/\/cevento-plugin.com\/en\/wp-json\/wp\/v2\/thema?post=5059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}