Add-on Hook System

From SocialStrap Wiki
Jump to: navigation, search

Basic hook attachment model inside addon

attach($eventName, $priority, $callback)


$this->attach('hook_view_sidebar', 5, function($view) {
	echo 'Hello on sidebar';

Available Hooks

system hooks

hook_app_init $app = array('front', 'view')


hook_app_heartbeat $out = array('notification_count', 'notification_html', 'new_messages')

since v1.4:

hook_app_preadduser $profile

hook_app_postadduser $profile

since v1.8:

hook_app_share $controller

view-render hooks

view_head $view

view_body $view (placed at the bottom of the page, add your javascript code here)

hook_view_sidebar $view

hook_view_sidebar_apps $view

since v3.0:

hook_view_post_before_content $post

hook_view_post_after_content $post

hook_view_comment_before_content $comment

hook_view_comment_after_content $comment

data-manipulation hooks

hook_data_renderoutput $data = array('content', 'context') context: default, sidebar, message, comment, post

hook_data_presavepost $post $array('content', 'meta')

hook_data_postcontent $post (full post data)

hook_data_presavecomment $content

hook_data_comments $comments array

since v1.4:

hook_data_postfetchposts $posts

since v1.5:

hook_data_prefixfetchposts $posts

since v1.10:

hook_data_notificationsfix $notifications

hook_data_aftersavepost $post $array('post_id', 'content')

hook_data_aftersavecomment $comment $array('comment_id', 'content')

since v4.3:

hook_api_preoutput $vars

event hooks

since v4.0:

hook_like $resource

hook_unlike $resource

hook_follow $resource

hook_unfollow $resource

hook_joingroup $resource

hook_leavegroup $resource

hook_connection_created $resource

hook_connection_removed $resource

hook_profile_view $resource

hook_image_upload $resource

hook_profile_picture_update $profile_id

hook_cover_picture_update $profile_id

hook_background_update $profile_id

hook_firsttimelogin $profile_id

hook_login $profile_id

hook_beforelogout $profile_id

hook_afterlogout $profile_id

hook_shareposttowall $post_id

hook_email_prepare $resource

hook_email_sent $resource

form overrides

form_* (example form_SettingsStyle) $form

// sample code inside addon's hook.php
// override AddGroup form and remove alnum validator from screen name

$this->attach('form_AddGroup', 10, function(&$form) {



There are two post meta flags introduced in v4.0 "no_content_edit" and "no_privacy_edit". If post is saved with this post_meta records, user will not be able to edit content and/or privacy later on. This can be used when creating auto-posts (posts created by the system on user's behalf) to prevent user from editing auto-generated content.