A hook is a small piece of code that allows you to insert more code (plugin) in the middle of certain Osclass’ actions.
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.
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');
Name of the hook : Description
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_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”
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.
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.
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.
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 : 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_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.
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_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 : 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
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 : 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
before_sitemap : Run before generating the sitemap
after_sitemap : Run after generating the sitemap
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.
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).
add_admin_toolbar_menus : Run at the end of AdminToolbar::add_menus(), you can add more actions to toolbar before render it.
In Osclass 8.2.0, many new theme hooks has been introduced for better customization options and plugins integration.
Header
Footer
Home page
Item page
Search page
Item loop
User dashboard page
User items page
Public profile page
Publish & edit page
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
Edit post hooks