Answers.Body: <p>The hooks run in php not javascript, so it won't log anything to the js console.</p>
  <p>If you want to log, use <code>\Civi::log()-&gt;debug('hello');</code> and then look in the <a href="https://civicrm.stackexchange.com/questions/15931/where-are-the-configandlog-and-templates-c-directories">ConfigAndLog</a> directory in the logs there.</p>
  <p>Or use <code>error_log('Hello');</code> and then check whereever that goes (usually the web server log).</p>
  <p>Or even more low-level:</p>
  <pre><code>$fp = fopen('/path/to/my-own-log-file', 'w');
  fwrite($fp, 'Hello');
  fclose($fp);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-21T08:47:11.447Z
Answers.Text: I added the \Civi::log() line and now can see the output in the civicrm ConfigAndLog file. Thanks for the tip.
Answers.UserDisplayName: tikis.tacos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-21T05:13:51.313Z
Answers.LastActivityDate: 2023-06-21T05:13:51.313Z
Answers.UserDisplayName: Demerit
Body: <p>I am writing a custom plugin for wordpress that stores contact data when a new individual is created in CiviCRM. I wrote a test function to see if the 'civicrm_post' hook fires when a new individual is created, but the body inside the function doesn't execute (ie. nothing is logged to console)</p>
  <p>This is the code:</p>
  <pre><code>function appeal_generator_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
          echo &quot;&lt;script&gt; console.log('contact has been adjusted') &lt;/script&gt;&quot;;
  }
  
  add_action( &quot;civicrm_post&quot;, &quot;appeal_generator_civicrm_post&quot;, 10, 4 );
  </code></pre>
  <p>I have also tried the postCommit hook as well as copy-pasted the demo code for the civicrm_post hook that is on the civicrm website, but nothing executes when a new individual is created.</p>
  <p>I have checked that the plugin is correctly setup within the /wp-content/plugins directory and that it is activated on wordpress, and there are no errors in the server logs.</p>
  <p>Is there a different hook I should be using or is there a setup issue with the plugin?</p>
  
Tags: <wordpress><hooks>
Title: civicrm_post hook not firing upon contact creation
ThreadText: # civicrm_post hook not firing upon contact creation
  
  (Asked by: username_0 on 2023-06-21)
  
  I am writing a custom plugin for wordpress that stores contact data when a new individual is created in CiviCRM. I wrote a test function to see if the 'civicrm_post' hook fires when a new individual is created, but the body inside the function doesn't execute (ie. nothing is logged to console)
  This is the code:
  function appeal_generator_civicrm_post($op, $objectName, $objectId, &$objectRef) {
          echo "";
  }
  
  add_action( "civicrm_post", "appeal_generator_civicrm_post", 10, 4 );
  
  I have also tried the postCommit hook as well as copy-pasted the demo code for the civicrm_post hook that is on the civicrm website, but nothing executes when a new individual is created.
  I have checked that the plugin is correctly setup within the /wp-content/plugins directory and that it is activated on wordpress, and there are no errors in the server logs.
  Is there a different hook I should be using or is there a setup issue with the plugin?
  
  **Tags:** wordpress, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-06-21. Score: 3 | Accepted answer
  
  The hooks run in php not javascript, so it won't log anything to the js console.
  If you want to log, use \Civi::log()->debug('hello'); and then look in the ConfigAndLog directory in the logs there.
  Or use error_log('Hello'); and then check whereever that goes (usually the web server log).
  Or even more low-level:
  $fp = fopen('/path/to/my-own-log-file', 'w');
  fwrite($fp, 'Hello');
  fclose($fp);
  
  > **Comments:**
  > **username_0**: I added the \Civi::log() line and now can see the output in the civicrm ConfigAndLog file. Thanks for the tip.  
  
  ---
  
  