Answers.Body: <p>I found the answer on this thread: <a href="https://civicrm.stackexchange.com/questions/26540/when-editing-my-own-profile-visible-under-my-contact-dashboard-it-does-not-ente">When editing my own profile visible under my contact dashboard, it does not enter CiviCRM &quot;civicrm_post&quot;API hook?</a></p>
  <p>Look at the answer by Hassan Farooq</p>
  <p>The solution was that you need to add following before your functions:
  <code>require_once(ABSPATH . 'wp-includes/pluggable.php');</code></p>
  <p>So the working code in my wordpress plugin looks like this:</p>
  <pre><code>require_once(ABSPATH . 'wp-includes/pluggable.php');
  add_filter( 'civicrm_post', 'my_customhook_civicrm_post', 10, 4  );
  function my_customhook_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
      if ($op == &quot;create&quot; &amp;&amp; $objectName == &quot;Individual&quot;) {
          // DO SOMETHING WHEN INDIVIDUAL CONTACT IS CREATED              
      }
  }
  </code></pre>
  <p>I have no idea what it does or why it is needed, but is solved my problem!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-06T22:20:07.867Z
Answers.LastActivityDate: 2024-08-06T22:25:55.353Z
Answers.LastEditDate: 2024-08-06T22:25:55.353Z
Answers.UserDisplayName: jsherk
Body: <p>So I was trying to use the CiviCRM hooks in my WordPress plugin, and tried multiple variations, but nothing seemed to work.</p>
  <p>This is what I was doing in my wordpress plugin:</p>
  <pre><code>add_filter( 'civicrm_post', 'my_customhook_civicrm_post', 10, 4  );
  function my_customhook_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
      if ($op == &quot;create&quot; &amp;&amp; $objectName == &quot;Individual&quot;) {
          // DO SOMETHING WHEN INDIVIDUAL CONTACT IS CREATED              
      }
  }
  </code></pre>
  <p>But even with all sorts of variations, I could not get it to work.</p>
  <p>I found the solution in a random obscure post, and I will answer my own question below with the solution.</p>
  
Tags: <wordpress><plugin>
Title: CiviCRM hooks not working in WordPress
ThreadText: # CiviCRM hooks not working in WordPress
  
  (Asked by: username_0 on 2024-08-06)
  
  So I was trying to use the CiviCRM hooks in my WordPress plugin, and tried multiple variations, but nothing seemed to work.
  
  This is what I was doing in my wordpress plugin:
  
  ```
  add_filter( 'civicrm_post', 'my_customhook_civicrm_post', 10, 4  );
  function my_customhook_civicrm_post($op, $objectName, $objectId, &$objectRef) {
      if ($op == "create" && $objectName == "Individual") {
          // DO SOMETHING WHEN INDIVIDUAL CONTACT IS CREATED              
      }
  }
  
  ```
  
  But even with all sorts of variations, I could not get it to work.
  
  I found the solution in a random obscure post, and I will answer my own question below with the solution.
  
  **Tags:** wordpress, plugin
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-08-06. Score: 3 | Accepted answer
  
  I found the answer on this thread: [When editing my own profile visible under my contact dashboard, it does not enter CiviCRM "civicrm\_post"API hook?](https://civicrm.stackexchange.com/questions/26540/when-editing-my-own-profile-visible-under-my-contact-dashboard-it-does-not-ente)
  
  Look at the answer by Hassan Farooq
  
  The solution was that you need to add following before your functions:
  `require_once(ABSPATH . 'wp-includes/pluggable.php');`
  
  So the working code in my wordpress plugin looks like this:
  
  ```
  require_once(ABSPATH . 'wp-includes/pluggable.php');
  add_filter( 'civicrm_post', 'my_customhook_civicrm_post', 10, 4  );
  function my_customhook_civicrm_post($op, $objectName, $objectId, &$objectRef) {
      if ($op == "create" && $objectName == "Individual") {
          // DO SOMETHING WHEN INDIVIDUAL CONTACT IS CREATED              
      }
  }
  
  ```
  
  I have no idea what it does or why it is needed, but is solved my problem!
  
  
  ---
  
  