Hooks

From Osclass Enterprise
Jump to: navigation, search

Hooks

A hook is a small piece of code that allows you to insert more code (plugin) in the middle of certain Osclass Enterprise' 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 are 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


Init related

init inits on the front end useful for enqueueing scripts and styles

init_admin inits on the admin end useful for enqueueing scripts and styles

Ajax related

ajax_my_hook : Run when AJAX request sent from frontend.

ajax_admin_my_hook : Run when AJAX request sent from admin.

Item/Ad related

pre_item_post : Run before an item is posted.

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 enable. $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 DEPRECATED removed in v3.2 use edited_item instead

item_form_post : Run after submitting the information when publishing an item. $catId, and $id are passed as argument DEPRECATED removed in v3.2 use posted_item instead

after_item_post : Run after 'item_form_post' and some other actions (send emails,...) DEPRECATED removed in v3.2 use posted_item instead


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)

item_contact_form : Run at the contact item publisher form, so you could add your own filters and options (since 3.1)

hook_email_item_inquiry : Run when an inquiry email is sent. $item is passed as argument.

hook_email_item_validation : Run when an inquiry email is validated. $item is passed as argument.

hook_email_item_validation_non_register_user : $item is passed as an argument.

hook_email_new_item_non_register_user : $item is passed as an argument.

Resource related

regenerate_image : Run before an image is regenerated. $resource is passed as an argument.

delete_resource : Run after a resource is deleted. $resource is passed as an argument.

uploaded_file : Run after a file is uploaded. $resource is passed as an argument.

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

hook_email_new_comment_user : Run when email sent to user after a new comment is posted. $item is passed as argument.

hook_email_new_comment_admin  : Run when email sent to after a new comment is posted. $item is passed as argument.

hook_email_comment_validated : $comment is passed as argument.

User related

before_user_register : Run before the user registration form is processed.

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

register_email_taken : Run when email used at register is already exist (*3.1*)

pre_user_post : Run before an user complete the registration, or edit his account (*3.1*)

user_register_completed : $userId is passed as an argument.

user_edit_completed : $userId is passed as an argument.

hook_email_admin_new_user : Run when admin emailed after user account activated.

hook_email_user_registration : Run when a user registration email is created, just before the "validate_user" hook.

hook_email_user_validation : Run when a non-admin user is validated, or when activation is resent. $user, $input are sent as arguments.

hook_email_send_friend : Run when a friend email is sent. $item is passed as argument.

hook_email_user_forgot_password : Run when user requests new password. $user, $password_url are sent as arguments.

hook_email_contact_user : Run when contact email sent to user. $id, $yourEmail, $yourName, $phoneNumber, $message are sent as arguments.

Search related

before_search : Run before a search request.

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

custom_query : Run when a custom query is processed. $key and $value are passed as arguments.

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 Enterprise/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

admin_register_form : Run after the form for contact site administrator. Useful if you want to add special requirements to your contacts.

contact_form : Run at the contact admin form, so you could add your own filters and options (contact.php) (since 3.1)

init : Run after frontend has finished loading.

init_admin : Run after admin has finished loading.

theme_activate : Run when a theme is activated. $theme is passed as an argument.

before_show_pagination_admin : Run before pagination on admin pages.

after_show_pagination_admin : Run after pagination on admin pages.

hook_email_alert_validation : Run when alert email validated. $alert, $email, $secret are passed as arguments.

hook_email_new_email : Run when user email is changed. $new_email, $validation_url are passed as arguments.

hook_alert_email_instant : Run when an instant alert is sent. $user, $ads, $s_search are passed as arguments.

hook_alert_email_hourly : Run when an hourly alert is sent. $user, $ads, $s_search are passed as arguments.

hook_alert_email_daily : Run when a daily alert is sent. $user, $ads, $s_search are passed as arguments.

hook_alert_email_weekly : Run when a weekly alert is sent. $user, $ads, $s_search are passed as arguments.

Admin panel hooks

Admin toolbar

add_admin_toolbar_menus : Run at the end of AdminToolbar::add_menus(), you can add more actions to toolbar before render it.

main_dashboard : Improves support for some external plugins that need to hook to the Main Dashboard - osc_run_hook('main_dashboard');