Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2010, 11:27 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default plugin question- how to override code in a hook location

So I'm now to using plugins in place of direct php file edits. I have code I want to put into a hook location but I need to execute my code and NOT execute the existing code... for example I make a pligin in: example_hook_location
My code is:
PHP Code:
$x 5
But the existing code in the php file where the hook is:
PHP Code:
$x 6
When I add my code via the plugin the result is basically:

PHP Code:
$x 5;
$x 6
Which leaves x with the same value of '6' as if my code never ran to begin with. How do I get around this? It seems like this would be a common issue when using plugins.

--------------- Added [DATE]1277949347[/DATE] at [TIME]1277949347[/TIME] ---------------

In more detail what I want to do is "If" something is true use my custom code for a query, otherwise (if false) use the existing code... One of the hook locations I want to do this with is:
forumdisplay_query_threadscount

I'd be much obliged for pointers on how to do this, I read an article on plugins but it was very old and couldn't find much dealing with my issue in the search.
Reply With Quote
  #2  
Old 07-03-2010, 06:53 AM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I know this is probably something you've looked at already, but are you able to define the variable at a later hook to override the previous variable?

If not, why not just add another hook in the location? This seems the easiest method...
Reply With Quote
  #3  
Old 07-03-2010, 07:06 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would mist likely have to replicate the query from the file in your plugin and use your variable with that. No way to do what you are asking that I am aware of, unless you could do it in a later hook.
Reply With Quote
  #4  
Old 07-03-2010, 08:55 AM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Or just add:

PHP Code:
($hook vBulletinHook::fetch_hook('hook_name')) ? eval($hook) : false
into the file, then add:
Code:
<hook>hook_name</hook>
into hooks_vbulletin.xml (includes/xml) under whichever category it fits best, probably forumdisplay.

Code:
<hooktype type="forumdisplay">
		<hook>forumdisplay_start</hook>
		<hook>forumdisplay_moderator</hook>
		<hook>forumdisplay_loggedinuser</hook>
		<hook>forumdisplay_announcement_query</hook>
		<hook>forumdisplay_announcement</hook>
		<hook>forumdisplay_sort</hook>
		<hook>forumdisplay_query_threadscount</hook>
		<hook>forumdisplay_query_threadid</hook>
		<hook>forumdisplay_query</hook>
		<hook>forumdisplay_complete</hook>
	</hooktype>
(insert under bold)
Reply With Quote
  #5  
Old 07-03-2010, 09:56 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That kind of defeats the purpose of using plugin hooks. Why not just do the code in the file? You would have to re-do it on an upgrade anyway.
Reply With Quote
  #6  
Old 07-03-2010, 12:09 PM
James Birkett James Birkett is offline
 
Join Date: Jun 2009
Posts: 633
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Because by putting in a plugin hook all he is doing is creating a way of accessing the variable, he can disable/enable the plugin at his will.
Reply With Quote
  #7  
Old 07-03-2010, 12:25 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And he still needs to re-do the files on every upgrade. 6 to 1, a half dozen to the other.
Reply With Quote
  #8  
Old 07-03-2010, 04:18 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the ideas... I guess it's not worth doing if I have to make another hook location because the code edits aren't that hard, I just thought maybe I could make the edits via hooks so i could release a product file instead of manual changes for a mod I made.

Oh well... at least (i think) I've figured out how hooks work for future mods.
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 10:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04244 seconds
  • Memory Usage 2,232KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete