I create a new plugin and I try to use hook for adding extra tab in the contents, my question is how to get $contactID?

add_action('civicrm_tabs', ' civitest_civicrm_tabs');

function civitest_civicrm_tabs( &$tabs, $contactID ) {

  // unset the contribition tab, i.e. remove it from the page
  unset( $tabs[1] );

  // let's add a new "contribution" tab with a different name and put it last
  // this is just a demo, in the real world, you would create a url which would
  // return an html snippet etc.
  $url = CRM_Utils_System::url( 'civicrm/contact/view/contribution',
                                "reset=1&snippet=1&force=1&cid=$contactID" );
  $tabs[] = array( 'id'    => 'mySupercoolTab',
                   'url'   => $url,
                   'title' => 'Contribution Tab Renamed',
                   'weight' => 300 );

Thank you


2 Answers 2


hook_civicrm_tabs is now deprecated and you should use https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tabset.

Also note:

// $url should return in 4.4 and prior an HTML snippet e.g. '<div><p>....';
// in 4.5 and higher this needs to be encoded in json. E.g. json_encode(array('content' => <html form snippet as previously provided>));
// or CRM_Core_Page_AJAX::returnJsonResponse($content) where $content is the html code
// in the first cases you need to echo the return and then exit, if you use CRM_Core_Page method you do not need to worry about this.

Some example code:

function koba_civicrm_tabset($tabsetName, &$tabs, $context) {
  //check if the tab set is Event manage
  if ($tabsetName == 'civicrm/event/manage') {
    // Remove "Mond aan mond reclame" tab
    // Remove "Location" tab: we use a contact subtype for location because it has better integration
    // Remove "Personal campaign pages": we don't use this

    // Add a Beheer Bijscholingen tab, a tab that shows a Drupal view
    if (!empty($context)) {
      $eventID = $context['event_id'];
      $url = CRM_Utils_System::url('admin/sitename/bijscholingen/json');
      $result = views_get_view_result('beheer_sitename_bijscholingen', 'page', $eventID);
      $count = count($result);
      $tabs['beheer'] = array(
          'weight' => 300,
          'count' => $count,
          'title' => ts('Beheer'),
          'link' => $url,
          'valid' => 1,
          'active' => 1,
          'current' => false,

The hook_civicrm_tabs is called by CiviCRM and provide the contactID argument. You don't need to use add_action(...) to call the hook.

Your example should work as is if you put it in a CiviCRM extension called civitest.

If you need help getting started with extension development, you can start with CiviCRM Wiki

  • 1
    This depends a bit on how the code is packaged. For a WordPress plugin, one would explicitly register the function using add_action(). For a Civi extension or Drupal module, there's no equivalent to add_action() because everything is based off naming conventions.
    – Tim Otten
    Jan 20, 2016 at 17:56

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.