Questions tagged [hook]

A hook refers to replacing or extending a system or application's default behavior with a custom behavior for a specific event. For keyboard hooks prefer the tag [keyhook]. For git related hooking use the tag [githooks] alone. For hooking web services use the tag [webhooks] instead. For React hooks use tag[react-hooks].

What is it?

A hook refers to replacing or extending the default behavior with a custom behavior for specific events. The events may be operating system events, but also application events that are meant to be extended with hooks.

The hook may fully replace the default behavior. It may also just extend the default behavior for example by adding a listening or monitoring activity without changing the default behavior, or add an extra effect on the top of it.

Hooking and programming techniques

"Hook" is commonly used to describe replacing a function pointer in an existing data structure with a new function pointer that points to new code. This new code can extend the default behavior by calling the old function pointer before or after the new code executes, or the new code can replace / disable the existing behavior by not calling the old pointer.

Hooking is similar in concept to OOP inheritance, but is usually more dynamic (determined at runtime) than OOP inheritance.

Essentially it's a place in code that allows you to tap in to a module to either provide different behavior or to react when something happens. Hooks often (but not always) use callback functions. For example, you might hook an event system using hookEvent(Events.STARTUP, myCallbackFunction). You are passing a function pointer to the hookEvent function, so it knows what function to call when the event occurs.

How does it work?

Typically hooks are inserted while software is already running, but hooking is a tactic that can also be employed prior to the application being started. There are two techniques to achieve this:

  • Physical modification
  • Runtime modification

Related tags and disambiguation

  • For the hooks related to keyboard events, prefer the tag
  • For the hooking git events, you must use the tag preferably without the
  • For hooking web services with web service callbacks prefer the tag
  • For React hooks, prefer the tag

More Information

5710 questions
2
votes
1 answer

Microsoft UI Automation/Get The Item That The User Clicks

I am trying to figure out what item (for example document, web page tab, window, picture, folder) the user has clicked on. I started by using the following code when I detect a global left mouse click: System.Drawing.Point MousePoint =…
Jonathan
  • 147
  • 1
  • 2
  • 10
2
votes
0 answers

Pass custom image on add to cart

I'm trying to replicate the behavior that this site has: http://pixers.es/fotomurales/hermosa-mujer-ejemplo-de-la-acuarela-59301559 As you can see you can select a certain portion of the image to buy it. If you select any size and click add to cart…
propcode
  • 299
  • 1
  • 5
  • 15
2
votes
1 answer

Can it possible to make liferay-ui:search-container rows as non editable in Life ray?

I have a page where I need to set assign the site roles for user in my custom portlet. So I am able to get the "User existing roles" in one list and all "Available site roles" in another list. So how can I do conditioning Or any validation that I…
Prasad
  • 1,164
  • 1
  • 10
  • 27
2
votes
2 answers

How can I get the user site roles in liferay

I wanted to know the list of site role names assigned for the user. So I tried as follows, List userRolesList = RoleLocalServiceUtil.getUserRoles(userid); if (userRolesList != null) { for (Role role : userRolesList)…
Vinod
  • 2,263
  • 9
  • 55
  • 104
2
votes
1 answer

execute a function when password changed in Wordpress

For increase security i'm looking for a way to run a custom function when an Admin user change it's password in Wordpress CMS. please help me. thank you.
Ehsan
  • 2,273
  • 8
  • 36
  • 70
2
votes
1 answer

Why is Detours lib not working on virtual methods?

I'm trying to intercept the construction/destruction of every object on my system. For this I'm using Detours Lib to create the runtime patch. It seem to work the some way as FastCode approach does. And I think it should have the same limitation…
Rodrigo Farias Rezino
  • 2,687
  • 3
  • 33
  • 60
2
votes
2 answers

How to assign a Site Administration role for a user in liferay programatically?

I am creating the user programatically by calling the UserLocalServiceUtil.addUser(....) and able to assign the site for the created user by calling UserLocalServiceUtil.addRoleUser(userSiteId, userId) It is working fine. I am able to assign the…
Vinod
  • 2,263
  • 9
  • 55
  • 104
2
votes
1 answer

Issue with customizing user administration in liferay portal

I wanted to do some enhancements in the forms used for adding and editing the users. In my requirement I am using only sites so I don't want to use Organizations and User groups sections. I want to hide some sections in the user creation and editing…
Vinod
  • 2,263
  • 9
  • 55
  • 104
2
votes
1 answer

Woocommerce Product Addons Filter Addon's by value

I have a product on my site that allows users to select what items they would like included with their order from a list of product addons. The default is 0 and the user can input any number to include that addon in their order. I'm using the…
Craig Harshbarger
  • 1,863
  • 3
  • 18
  • 29
2
votes
2 answers

Wordpress overwrite contact form mail_2 body

Currently I am facing a problem to overwrite the body content of the mail_2 in the hook wpcf7_before_send_mail. I am trying to rewrite a wpcf7 shortcode to a more proper presentation of the content with some html modifications. The problem is that I…
directory
  • 3,093
  • 8
  • 45
  • 85
2
votes
0 answers

Message not being processed in SetWindowsHookEx hook

I would like to create a DLL which, when loaded into a process, adds an "Always on top" item to the applications Sysmenu. I created a hook trying both SetWindowsHookEx(WH_CALLWNDPROC,...) and SetWindowsHookEx(WM_GETMESSAGE,...), and from there add…
cracksman
  • 61
  • 5
2
votes
2 answers

Woocommerce Reorder single page hooks, description showing twice

I'm making a woocommerce theme and I'm having trouble reordering the single page hooks. I want the product short description to appear under the product title. I've been able to move the short description under the title using the remove / add…
Mark
  • 21
  • 2
2
votes
1 answer

How to dynamically change the price of a product in Woocommerce - WordPress?

I need to change the price of my products in my store, with a 10% discount, if my customer is from some specific place, so, I wrote this code: add_filter('woocommerce_price_html', 'my_price_edit'); function my_price_edit() { $product = new…
2
votes
1 answer

git push --force/-f - how to get each branch

This has to do with using git's push.default matching setting from git < 2.0. Also, forking the repo in this particular instance is not applicable. We use github at work and since it does not allow a pre-receive hook, we have to try and mitigate…
hellatan
  • 3,517
  • 2
  • 29
  • 37
2
votes
1 answer

Integrate ElFinder with existing permission system

Is there a way to integrate elfinder with my current user permissions system? I would need some kind of hook which would be triggered before e.g. a file gets deleted. There I should be able to abort the delete command and return some kind of…
Sidney Widmer
  • 389
  • 1
  • 2
  • 10