Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[How to] Add new/custom hook locations
Brad
Join Date: Nov 2001
Posts: 4,765

 

Show Printable Version Email this Page Subscription
Brad Brad is offline 06-08-2005, 10:00 PM

This guide will teach you how to add your own hook locations to your scripts/default vBulletin source code. Note that I assume that you are working within the vBulletin.php files or you have included vBulletin's global.php.

Adding custom hook locations -

Method one:

See paul's thread here for the best method, if you are going to release your modification to the public this is the way you should go:

https://vborg.vbsupport.ru/showthread.php?t=83390

Method two:

All hooks listed in this drop down live in the .xml file located at /vbroot/includes/xml/hooks_vbulletin.xml

Find this bit of code at the very top of the file:

HTML Code:
<hooks>
	
	<hooktype type="admindata">
		<hook>admindata_start</hook>
		<hook>admindata_presave</hook>
		<hook>admindata_postsave</hook>
		<hook>admindata_delete</hook>
	</hooktype>

Looks simple eh? Heres what these tags do

<hooks> - anything between this tag and </hooks> will be included in the drop down

<hooktype type="name"> - The name of your hook group, you should group all common hooks under a group so you can find them quickly. Make sure you don't use a name already used by a default hooktype.

<hook> - The name of your hook, this must be the same as the hook's name in the php code

Here is an example of my .xml file, I added three custom hooks under a new hooktype:

HTML Code:
<hooks>
	
	<hooktype type="loo_custom">
		<hook>loo_custom1</hook>
		<hook>loo_custom2</hook>
		<hook>loo_custom3</hook>
	</hooktype>
The php code:

Adding a hook location to the php code is easy, just make sure you use the correct hook name! Use this bit of php anywhere after your call to global.php to call your custom hook. Also note that you must use the $hook var!

PHP Code:
($hook vBulletinHook::fetch_hook('hook_name')) ? eval($hook) : false
Here is an example of my custom hooks working in vBulletin's index.php file:

PHP Code:
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

($hook vBulletinHook::fetch_hook('forumhome_start')) ? eval($hook) : false;
(
$hook vBulletinHook::fetch_hook('loo_custom1')) ? eval($hook) : false;
(
$hook vBulletinHook::fetch_hook('loo_custom2')) ? eval($hook) : false;
(
$hook vBulletinHook::fetch_hook('loo_custom3')) ? eval($hook) : false
As you can see I added them right under a current hook, which mostly defeats the purpose of making custom hooks. But for this post they serve their purpose

Now all you need to do is browse to your admincp's add new plug-in page and test your new hook location! I use this just to make sure it is working correctly:

PHP Code:
echo('Testing hook_name hook'); 
If that outputs its text above the vBulletin header then you are good to go!.
Reply With Quote
  #12  
Old 07-07-2005, 08:28 PM
rjordan's Avatar
rjordan rjordan is offline
 
Join Date: Sep 2004
Posts: 326
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Tomato (A), tomato (o). Same idea.

It would be nice to have something that could be considered "unofficially standard" so if anyone created an update script that searched for custom hooks, a universal pattern could be looked for. Granted that this would be completely up to the forum admin. Thus, the suggested $customhook rather than $hook for the variable name.
Reply With Quote
  #13  
Old 01-08-2007, 04:57 PM
punchbowl punchbowl is offline
 
Join Date: Nov 2006
Posts: 505
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

fantastic article - cheers
Reply With Quote
  #14  
Old 02-27-2007, 02:34 PM
aim aim is offline
 
Join Date: Jun 2006
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Brad View Post
...
The php code:

Adding a hook location to the php code is easy, just make sure you use the correct hook name! Use this bit of php anywhere after your call to global.php to call your custom hook. Also note that you must use the $hook var!

PHP Code:
($hook vBulletinHook::fetch_hook('hook_name')) ? eval($hook) : false
...
I already implemented hooks as advised in this thread and they also work.

But today I noticed Warnings in the Webserver-Logfile concerning the Lines the Hooks where called:

PHP Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify the
declaration of [runtime function name](). If you would like to enable
call-time pass-by-reference, you can set allow_call_time_pass_reference
to true in your INI file. However, future versions may not support this
any longer. in .../includes/init.php(403) :
eval()'d code on line 52, ....

Does this mean that future PHP-versions won't support the vBulletin-Hook-System?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:29 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08085 seconds
  • Memory Usage 2,246KB
  • Queries Executed 18 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_html
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (3)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete