Hooks

From OSClass

Contents

Hooks

A hook is a small piece of code that allows you to insert more code (plugin) in the middle of certain OSClass' actions.

Usage of hooks

To use a hook add the following code to your plugin file :

osc_add_hook('hook_name', 'function_name');

Substitute 'hook_name' by the name of the hook you want to attach 'function_name', and 'function_name' with the name of your function.

Special hooks

There exists some special hooks

// This is a hack to show a Configure link at plugins table (you could also use some other hook to show a custom option panel);

osc_add_hook(__FILE__ . "_configure", 'function_name');

// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel);

osc_add_hook(__FILE__ . "_uninstall", 'function_name');

List of hooks

Name of the hook : Description


Item/Ad related

show_item : Run at the beginning of item's detail page. $item is passed as argument. NOTE: This will be execute BEFORE the header

item_detail : Run at the middle of item's detail page. $item is passed as argument. USE THIS is you want to make an attributes plugins

activate_item : Run when an item is activated. $id is passed as argument

deactivate_item : Run when an item is deactivated. $id is passed as argument

enable_item : Run when an item is enaable. $id is passed as argument

disable_item : Run when an item is disable. $id is passed as argument

posted_item : Run when an item is posted. $item is passed as argument

edited_item : Run when an item is edited. $item is passed as argument

new_item : Run at the form for publishing new items

add_comment : When some user add a comment to an item. $item is passed as argument

location : Run at item's detail page. Just after item_detail hook

item_form : Run at publish new item form. USE this if you want to make an attributes plugin. $catId is passed as argument

post_item : Run before a publish new item page is loaded

before_item_edit : Run before a edit item page is loaded

item_edit : Run at editing item form. Same as item_form/item_detail. $item is passed as argument

item_edit_post : Run after submitting the information when editing an item

item_form_post : Run after submitting the information when publishing an item. $catId, and $id are passed as argument

after_item_post : Run after 'item_form_post' and some other actions (send emails,...)

delete_item : When an item is deleted. $id is passed as argument

item_premium_on : When an item is marked as premium

item_premium_off : When an item is unmarked as premium

item_spam_on : When an item is marked as spam (since 2.4)

item_spam_off : When an item is unmarked as spam (since 2.4)

Comment related

edit_comment : $id is passed as argument

enable_comment : $id is passed as argument

disable_comment : $id is passed as argument

activate_comment : $id is passed as argument

deactivate_comment : $id is passed as argument

delete_comment : $id is passed as argument


add_comment : $id is passed as argument

User related

register_user : Run when an user complete the registration process. $user is passed as argument

validate_user : Run when an user gets validated (if they didn't do it automatically)

logout_user : Run when an user logout on your site. $userId is passed as argument

user_register_form : Run after the form for users registration. Useful if you want to add special requirements to your users

user_register_completed : Run after registration of an user is completed.

user_form : Run after the form of user's profile

delete_user : When an user is deleted. $id is passed as argument


Search related

search : Run at search page. Object $search is passed as argument

search_form : Run at the search's form, so you could add your own filters and options. $catId is passed as argument

search_conditions : Run when the search is submitted, useful to add new conditions to search


Feed related

feed : Run at feed page. $feed is passed as argument

feed_XYZ : Run at XYZ's feed page (see extra feeds plugin). $items is passed as argument


HTML related

before_error_page : Run before generating an error page

after_error_page : Run after generating an error page

header : Run at header

footer : Run at footer

admin_menu : Run in the middle of the admin's menu. Useful to add your custom options to OSClass/Plugins

admin_header : Run at the header in the admin panel

admin_footer : Run at the footer in the admin panel

user_menu : Run in the middle of the user's account menu. Useful to add custom options to user's account menu

before_html : Before the html is displayed on the browser

after_html : After the html is 'displayed'. Note: This run is on the server, it's run after the HTML code is sent to the browser, since some resources are loaded externally (JS, CSS, images,...) it's run before the HTML complete its load process.


Cron

cron : Run at manual cron system

cron_hourly : Run at manual cron system hourly

cron_daily : Run at manual cron system daily

cron_weekly : Run at manual cron system weekly


Sitemap related

before_sitemap : Run before generating the sitemap

after_sitemap : Run after generating the sitemap


Others

delete_locale : When a locale is deleted. $locale is passed as argument

delete_category : Run at category deletion


before_rewrite_rules : Run before the rewrite rules are generated, a pointer to the rewrite object is passed


after_rewrite_rules : Run after the rewrite rules are generated, a pointer to the rewrite object is passed