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
2 answers

woocommerce get product id when product is add to cart

I need to do extra step in the backend when a product is add to cart. I need to get the product ID juste after it's add to the cart. I use the woocommerce hook woocommerce_add_to_cart add_action('woocommerce_add_to_cart', 'attach_item'); function…
MathieuB
  • 505
  • 2
  • 8
  • 20
2
votes
1 answer

Universal Post Commit Git Hook

I was wondering fi there was a simple way to set up a post commit git hook so that it would run regardless of the repo that it is run with (It is my understanding that the applied hook comes from a hook/ folder in the git directory). Thank you!
Zubatman
  • 1,235
  • 3
  • 17
  • 34
2
votes
1 answer

Plugin system with events or hooks?

I've created a plugin system for a software in php. In order for a plugin to alter the behaviour of the programm I wrote this (simplified) code: class PluginController { /* ... */ public function addHook($name, $function, $priority = 10) { …
Mario A
  • 3,286
  • 1
  • 17
  • 22
2
votes
2 answers

Remove some categories from the URL Permalink structure /%category%/?

In Wordpress Permalink : I use /%category%/%postname%/ With categories like « News », « Formation », « Events » etc.. (true categories) But I have some categories only for display features like « slider1 », « homepagedisplay » or some child…
NIF
  • 462
  • 2
  • 7
  • 23
2
votes
0 answers

Can python requests have hooks per sessions or global hooks?

I have a plan to use https://github.com/shellycloud/forwardmachine And I want to use requests to contact those servers that were forwarded I thought of using requests hooks, but I don't want to pass them in each request. I want something…
Fruch
  • 408
  • 5
  • 18
2
votes
0 answers

How can i determine target control/window when WindowFromDC returns null?

I am new to win32 programming.I am intercepting an application from my application using MadHookc, by hooking dll funceions. I am hooking the ExtTextOutW function to get the text used for display in the application. Hookign ExtTextOutW gives me near…
Anonymous
  • 1,726
  • 4
  • 22
  • 47
2
votes
1 answer

What function would I need to hook (using easy hook) to prevent minimize of a third party application?

I'm trying to write a simple thing that prevents a third party application from being able to minimize. I'm going to use EasyHook as I think that's the easiest way of doing this. My code is going to be in C#. I've been looking at the examples in the…
TheKrush
  • 81
  • 1
  • 6
2
votes
1 answer

How to access other module data table SugarCRM

I am writing logic hook and I need to update 1 module fields by using other module elements. ignore_update_c)||$bean->ignore_update_c…
2
votes
0 answers

Add Fabric.framework with theos

Can you help me add Fabric.framework to theos. I want to use this Framework to folow logs or crash my tweak from Farbic. Add CoreMotion Framework With Theos Add Twitter.framework to Theos on iPhone Copy Fabric framework to Xcode in your Mac.…
caophuocthanh
  • 31
  • 1
  • 6
2
votes
3 answers

WordPress publish_post hook not firing for custom post type

I'm currently doing some work with the WP Job Board Manager plugin and I'm wanting to create a function that will fire when a new job is published. The first thing I did was to create the general hook to find out what the post type was: function…
MarkP
  • 2,546
  • 5
  • 31
  • 48
2
votes
1 answer

How to grab Credit Card Type from Payment Gateway in WooCommerce to display on orders page

I use FirstData for my WooCommerce payment processing. When I pull up orders in WooCommerce, it says: "Payment by Credit Card" but it does not tell me what type of credit card. I just need to know if it was Visa, Mastercard, Discover, or AMEX. We…
AZ Slim
  • 21
  • 2
2
votes
0 answers

Will Windows always allow hooks and/or the journal record?

I'm writing a keylogger/mouse tracker for use in an opensource input heatmapping application basically identical to Razer's newest heatmapping software, but for use with any hardware/OS (using Qt's amazing cross platform SDK). As you would imagine,…
user4336026
2
votes
1 answer

When I call SpecFlow hook [BeforeScenario] test class non static properties in the test class value is not saved

I want to initialize my WebDriver property that in my test class and when I want to use it in the scenario it is 'Null'. In the example here, when I try to navigate to some url I get null exception. Example: [BeforeScenario] private void…
Udiy
  • 65
  • 2
2
votes
1 answer

How to change the sorting of a view using hook_views_pre_view()?

I've got the following: function view_sorter_views_pre_view(&$view) { // don't need $items if ($view->name == 'MOST_RECENT') { $insert = array(); $insert[order] = 'DESC'; //SORT ORDER $insert[id] = 'title'; …
rockstardev
  • 13,479
  • 39
  • 164
  • 296
2
votes
1 answer

How to add a hook to Keyboard (HookProc)

I was trying to make a simple keylog test, but my program doesn't work as expected and I don't know why. In my program i had a low level keyboard hook and attach a simple process to it. The process just opens/creates a file and writes "Hello World"…
Alter
  • 3,332
  • 4
  • 31
  • 56