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', 'priority');
Substitute ‘hook_name’ by the name of the hook you want to attach ‘function_name’, and ‘function_name’ with the name of your function. ‘priority’ is number 1-10 that identifies priority/order to include/run function in hook.
If you want to run function at the end, use priority 10. If you want to run function at start, use priority 1.
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
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. Example if you execute function abc_my_func via ajax, then hook name will be “ajax_abc_my_func”.
ajax_admin_my_hook : Run when AJAX request sent from admin.
ajax_custom: Run as ajax action “custom_ajax”
Item/Ad related
pre_item_post : Run before an item is posted.
pre_item_add : Run before an item is posted. $aItem, $flash_error are passed as argument.
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
renew_item : Run when an item is renewed. $id is passed as argument
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. $cat_id and $item_id are passed as arguments
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
before_delete_item: Before item is being removed. $item is passed as argument (from Osclass 8.1.2)
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.
regenerated_image : Run after 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 : Run when editing of comment is complete. $id is passed as argument
edit_comment_reply: Run when editing of comment that is reply to other comment is complete. $id of parent comment is passed as argument (from Osclass 8.0.3). Executed after edit_comment is executed.
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)
before_login : Run before user login is created.
after_login : Run when user is successfully loged in. $user and $url_redirect are passed as params.
logout : Run when an user logout on your site.
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_profile_form : Run before update button of user’s profile
user_forgot_password_form : Run inside user forgot password form (Osclass 8.3 or later)
user_recover_form : Run inside user recover password form (Osclass 8.3 or later)
user_form : Run after the form of user’s profile
delete_user : Run before user is removed. In time of running hook, user record is still available in user table. $id is passed as argument
activate_user: Run after user has been activated. $id is passed as argument
dectivate_user: Run after user has been deactivated. $id is passed as argument
enable_user: Run after user has been enabled. $id is passed as argument
disable_user: Run after user has been disabled. $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.
highlight_class : Run in item loop (loop-single.php) and used to add specific class to listing.
RSS feed related
rss_before : Runs at start of RSS feed (after description is added)
rss_after : Runs at end of RSS feed (before closing channel)
rss_item : Runs in items loop. Item ID is passed as argument.
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
admin_users_table : Run ad addTableHeader function in datatables
user_menu : Run in the middle of the user’s account menu. Useful to add custom options to user’s account menu
user_menu_before, user_menu_top, user_menu_bottom, user_menu_after : Additional user menu hooks, available from Osclass v8.3.0
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
user_locale_changed: Run when locale has been changed. $locale_code is passed as argument
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.
alert_created : Run when alert is created via ajax (does not mean successfully created!)
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.
structured_data_header: Run at header structured data block.
structured_data_footer: Run at footer structured data block.
before_auto_upgrade: Run before auto-upgrade starts osclass upgrade.
after_auto_upgrade: Run after auto-upgrade starts osclass upgrade. $result is passed as argument.
after_upgrade: Run after osclass upgrade has finished. $error is passed as argument.
admin_items_header, admin_items_actions, admin_items_form_left_top, admin_items_form_left_middle, admin_items_form_right_top: Run in item edit page in backoffice. osc_item() is available in hook. (Osclass 8.0.2).
admin_dashboard_top, admin_dashboard_bottom: Run in backoffice dashboard page (Osclass 8.0.3).
admin_dashboard_col1_top, admin_dashboard_col1_bot, admin_dashboard_col2_top, admin_dashboard_col2_ bot , admin_dashboard_col3_top, admin_dashboard_col3_ bot : Run in admin dashboard (home) page (Osclass 8.2.0)
admin_dashboard_setting_top, admin_dashboard_setting_col1, admin_dashboard_setting_col2, admin_dashboard_setting_col3: Run at admin dashboard settings page (Osclass 8.2.0)
admin_translations_list_top, admin_translations_list_bottom: Run in backoffice translations list page (Osclass 8.0.3).
admin_translations_edit_top, admin_translations_edit_bottom, admin_translations_edit_buttons_top, admin_translations_edit_buttons_middle, admin_translations_edit_buttons_bottom, admin_translations_edit_catalog, admin_translations_edit_stats, admin_translations_edit_options, admin_translations_edit_form, admin_translations_edit_actions: Run in backoffice translations edit page (Osclass 8.0.3).
pre_send_email: Run at start of send mail function. $params are passed as arguments. (Osclass 8.0.2).
before_send_email: Run right before mail is being sent in send mail function. $params, $mail are passed as arguments. (Osclass 8.0.2).
after_send_email: Run when email was sent successfully in send mail function. $params, $mail are passed as arguments. (Osclass 8.0.2).
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.
New design theme hooks
In Osclass 8.2.0, many new theme hooks has been introduced for better customization options and plugins integration.
Header
- header_top
- header_links
- header_bottom
- header_after
Footer
- footer_pre
- footer_top
- footer_links
- footer_after
Home page
- home_search_pre
- home_search_top
- home_search_bottom
- home_search_after
- home_top
- home_latest
- home_premium
- home_bottom
Item page
- item_top
- item_title
- item_images
- item_meta
- item_description
- item_contact
- item_comment
- item_comment_form
- item_bottom
- item_sidebar_top
- item_sidebar_bottom
Search page
- search_items_top
- search_items_filter
- search_items_bottom
- search_sidebar_pre
- search_sidebar_top
- search_sidebar_bottom
- search_sidebar_after
Item loop
- item_loop_top
- item_loop_title_after
- item_loop_description_after
- item_loop_bottom
User dashboard page
- user_dashboard_top
- user_dashboard_bottom
- user_dashboard_links
User items page
- user_items_top
- user_items_bottom
- user_items_button
- user_items_action
- user_items_search_form_top (Osclass 8.3)
- user_items_search_form_bottom (Osclass 8.3)
Public profile page
- user_profile_top
- user_profile_sidebar
- user_public_profile_items_top
- user_public_profile_sidebar_top
- user_public_profile_sidebar_bottom
- user_public_profile_search_form_top (Osclass 8.3)
- user_public_profile_search_form_bottom (Osclass 8.3)
Publish & edit page
- item_publish_top
- item_publish_category
- item_publish_description
- item_publish_price
- item_publish_location
- item_publish_seller
- item_publish_images
- item_publish_hook
- item_publish_buttons
- item_publish_bottom (for recaptcha, right before buttons)
- item_publish_after
Themes those support these new hooks must have constant THEME_COMPATIBLE_WITH_OSCLASS_HOOKS defined and set to value 820 or higher.
For publish & edit page, there are item_post and item_edit hooks automatically generated with variants and linked to these hooks. Hooks are being executed with ajax calls just when any functions are hooked to them.
Publish post hooks
- item_form (original)
- item_form_top
- item_form_category
- item_form_description
- item_form_price
- item_form_location
- item_form_seller
- item_form_images
- item_form_hook
- item_form_buttons
- item_form_bottom
- item_form_after
Edit post hooks
- item_edit (original)
- item_edit_top
- item_edit_category
- item_edit_description
- item_edit_price
- item_edit_location
- item_edit_seller
- item_edit_images
- item_edit_hook
- item_edit_buttons
- item_edit_bottom
- item_edit_after