Body: <p>I'm using CiviCRM 5.57.3 to implement some voucher management functionality <a href="https://civicrm.stackexchange.com/questions/43410/recording-membership-benefits-specifically-vouchers">See this question</a>.</p>
  <p>I'm now trying to get a hook working, to set my voucher ID in the custom field. I've create a file <em>civicrmHooks.php</em> in my &quot;Custom PHP Directory&quot; and tried to simply log something:</p>
  <pre><code>&lt;?php
  
  // Implements hook_civicrm_pre
  
  add_filter( 'civicrm_post', 'gutschein_id_custom_callback', 10, 4 );
  
  function gutschein_id_custom_callback( $op, $groupID, $entityID, &amp;$params ) {
    // your code here
    Civi::log()-&gt;debug(__FUNCTION__);
  }
  
  Civi::dispatcher()-&gt;addListener('hook_civicrm_post', &quot;myextension_buildForm&quot;, $priority);
  
  function myextension_buildForm($event) {
    Civi::log()-&gt;debug(__FUNCTION__);
  }
  ?&gt;
  </code></pre>
  <p>I've tried registering the hook using both methods described in the documentation <a href="https://docs.civicrm.org/dev/en/latest/hooks/usage/wordpress/" rel="nofollow noreferrer">Hooks in Wordpress</a> <a href="https://docs.civicrm.org/dev/en/latest/hooks/usage/symfony/#events" rel="nofollow noreferrer">Symfony Event Listener</a>. Using the <em>civicrm_custom</em> hook did not change anything.</p>
  <p>However, I'm unable to get anything in the CiviCRM log. Is there anything I'm overseeing?
  Thank you!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-02T20:40:25.150Z
Comments.Text: I've partially solved this by creating a small extension. That way I can get the hooks to be invoked. I'm now using the _custom hook. And I get the custom field values in $param. However, I don't get the custom_fields unique id in the param list. Which is what I wanted to use in my key...
Comments.UserDisplayName: Flavio C
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-03T08:57:14.763Z
Comments.Text: Extensions are much preferred - the 'custom php directory' is rarely used now.  If I'm understanding you correctly, the id you want is `$entityID`, not in `$params`
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-04T12:45:46.823Z
Comments.Text: Thank you, yes I did notice that and I was getting it to work with an extension. However I had to look for another solution, because what I was trying to do seems impossible to do.
  Thank you!
Comments.UserDisplayName: Flavio C
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-06T09:28:18.160Z
Comments.Text: OK - what is it that you're trying to do?
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-07T10:41:04.537Z
Comments.Text: I was trying to auto-generate the voucher ID with some kind of unique id. I thought that I might be able to access the id field of the custom field, but it was not available in any of the hooks I was trying.
Comments.UserDisplayName: Flavio C
Tags: <custom-fields><hooks>
Title: unable to get hook_civicrm_post and _custom to work
ThreadText: # unable to get hook_civicrm_post and _custom to work
  
  (Asked by: username_0 on 2023-02-02)
  
  I'm using CiviCRM 5.57.3 to implement some voucher management functionality [See this question](https://civicrm.stackexchange.com/questions/43410/recording-membership-benefits-specifically-vouchers).
  
  I'm now trying to get a hook working, to set my voucher ID in the custom field. I've create a file *civicrmHooks.php* in my "Custom PHP Directory" and tried to simply log something:
  
  ```
  <?php
  
  // Implements hook_civicrm_pre
  
  add_filter( 'civicrm_post', 'gutschein_id_custom_callback', 10, 4 );
  
  function gutschein_id_custom_callback( $op, $groupID, $entityID, &$params ) {
    // your code here
    Civi::log()->debug(__FUNCTION__);
  }
  
  Civi::dispatcher()->addListener('hook_civicrm_post', "myextension_buildForm", $priority);
  
  function myextension_buildForm($event) {
    Civi::log()->debug(__FUNCTION__);
  }
  ?>
  
  ```
  
  I've tried registering the hook using both methods described in the documentation [Hooks in Wordpress](https://docs.civicrm.org/dev/en/latest/hooks/usage/wordpress/) [Symfony Event Listener](https://docs.civicrm.org/dev/en/latest/hooks/usage/symfony/#events). Using the *civicrm\_custom* hook did not change anything.
  
  However, I'm unable to get anything in the CiviCRM log. Is there anything I'm overseeing?
  Thank you!
  
  **Tags:** custom-fields, hooks
  
  > **Comments:**
  > **username_0**: I've partially solved this by creating a small extension. That way I can get the hooks to be invoked. I'm now using the _custom hook. And I get the custom field values in $param. However, I don't get the custom_fields unique id in the param list. Which is what I wanted to use in my key...  
  > **username_1**: Extensions are much preferred - the 'custom php directory' is rarely used now.  If I'm understanding you correctly, the id you want is `$entityID`, not in `$params`  
  > **username_0**: Thank you, yes I did notice that and I was getting it to work with an extension. However I had to look for another solution, because what I was trying to do seems impossible to do. Thank you!  
  > **username_1**: OK - what is it that you're trying to do?  
  > **username_0**: I was trying to auto-generate the voucher ID with some kind of unique id. I thought that I might be able to access the id field of the custom field, but it was not available in any of the hooks I was trying.  
  
  ---
  
  ## 0 answers
  
  