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 "<script> console.log('contact has been adjusted') </script>";

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?

1 Answer 1


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');
  • I added the \Civi::log() line and now can see the output in the civicrm ConfigAndLog file. Thanks for the tip. Jun 21, 2023 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.