How to alter a function in a contributed module? I am using a module Simple hierarchical select in my website.

I have a taxonomy in which I have some parent terms and there children terms, I am getting two select list with this module. In one select list I am getting all parent terms, and the module is filtering the second select list as per the parent selected, showing children terms of parent term selected in select list 1.

I need to add some condition to the values I am getting in the select lists to alter this function shs_json_term_get_children using custom module. 

The function declaration in the module is:


  function shs_json_term_get_children($vid, $parent = array(), $settings
  = array()) {}


So I tried using:


  function hook_shs_json_term_get_children_alter($vid, $parent =
  array(), $settings = array()) {}


and 


  function hook_shs_json_term_get_children_alter(&amp;$vid, $parent =
  array(), $settings = array()) {}


but neither worked.

Any suggestions?
As far as I know, you can only alter the functionality the module exposes using hooks defined by that module, and you cannot alter just any function defined in the module. For instance, shs_json_term_get_children is just a callback, and you cannot alter it.

The SHS module defines several hooks that are listed in the shs.api.php file. For instance, there is a hook called hook_shs_term_get_children_alter, that allows you to modify the list of terms displayed to the user: http://cgit.drupalcode.org/shs/tree/shs.api.php?h=7.x-1.x#n73

/**
 * Alter the list of terms within a level of the term hierarchy.
 *
 * @param array $terms
 *   List of terms displayed to the user (single hierarchy level).
 * @param array $alter_options
 *   - vid: ID of vocabulary or field name
 *   - parent: ID of parent term
 *   - settings: Additional settings (for example "language", etc.,)
 */
function hook_shs_term_get_children_alter(&amp;$terms, &amp;$alter_options) {
}


In your module, you would need to implement that hook like that:

function YOURMODULENAME_shs_term_get_children_alter(&amp;$terms, &amp;$alter_options) {
  // Your code here.
}