Answers.Body: <p>OK, it was my stupid fault. The function isn't only called when a contact is created - it's called when any event happens (eg cron job). So the important line is the conditional statement (which should be the first line of the function) which decides whether the function should continue. In my case, this conditional line was:</p>
  
  <p>IF ( ($objectName != 'Individual' &amp;&amp; $objectName != 'Organization') || $op != 'create') { return; }</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-09T20:45:50.340Z
Answers.LastActivityDate: 2017-03-09T20:45:50.340Z
Answers.UserDisplayName: Jern
Body: <p>I have set up a hook to assign a group to new contacts when they are created. I have set it up the old-fashioned way, ie with a function called joomla_civicrm_post in a file called civicrmHooks.php in the php override directory. But the function is called every time the master cron job fires, whereas I expected/wanted it to be called when a new contact is created. Have I missed something obvious? Should this work? Or do I have to implement the hook as a Joomla plugin in order to get it to trigger correctly? Thanks.</p>
  
  <p>Joomla 3.6.5, CiviCRM 4.7.16, php 5.6.30</p>
  
Tags: <hooks><cron>
Title: hook civicrm_post not triggering as expected (Joomla)
ThreadText: # hook civicrm_post not triggering as expected (Joomla)
  
  (Asked by: username_0 on 2017-03-05)
  
  I have set up a hook to assign a group to new contacts when they are created. I have set it up the old-fashioned way, ie with a function called joomla\_civicrm\_post in a file called civicrmHooks.php in the php override directory. But the function is called every time the master cron job fires, whereas I expected/wanted it to be called when a new contact is created. Have I missed something obvious? Should this work? Or do I have to implement the hook as a Joomla plugin in order to get it to trigger correctly? Thanks.
  
  Joomla 3.6.5, CiviCRM 4.7.16, php 5.6.30
  
  **Tags:** hooks, cron
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-03-09. Score: 0 | Accepted answer
  
  OK, it was my stupid fault. The function isn't only called when a contact is created - it's called when any event happens (eg cron job). So the important line is the conditional statement (which should be the first line of the function) which decides whether the function should continue. In my case, this conditional line was:
  
  IF ( ($objectName != 'Individual' && $objectName != 'Organization') || $op != 'create') { return; }
  
  
  ---
  
  