vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   plugin question- how to override code in a hook location (https://vborg.vbsupport.ru/showthread.php?t=245619)

BirdOPrey5 06-30-2010 11:27 PM

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.

James Birkett 07-03-2010 06:53 AM

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...

Boofo 07-03-2010 07:06 AM

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.

James Birkett 07-03-2010 08:55 AM

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)

Boofo 07-03-2010 09:56 AM

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.

James Birkett 07-03-2010 12:09 PM

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.

Boofo 07-03-2010 12:25 PM

And he still needs to re-do the files on every upgrade. 6 to 1, a half dozen to the other.

BirdOPrey5 07-03-2010 04:18 PM

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.


All times are GMT. The time now is 11:19 AM.

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.01101 seconds
  • Memory Usage 1,734KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete