Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Plugin Hooks (enable/disable)

Quote Reply
Plugin Hooks (enable/disable)
There is a checkbox to enable/disable hooks on Plugin Details.

Do "I" have to run/not_run my plugin code based on this setting? or does my plugin *not* get called automatically if this checkbox is set to "disable"?

I ask because I see in Andy's SearchFeed plugin, he has this code in Install.pm
Code:
$mgr->install_options ( 'SearchFeed_Results', [ ['Active', '1', 'Set to 0 if you don\'t want this plugin to be active, or 1 if you want the results to be grabbed...', 'TEXT', [], [], '' ] ] );

and this in his hook...
Code:
my $opts = Links::Plugins->get_plugin_user_cfg ('SearchFeed_Results');
my $inc = $opts->{Active};

if ($inc == 0) { return $results; }
if ($inc == 1 and $results->{link_hits} > 0) { return $results; }


I have *not* added ANY special option to enable/disable my plugin, yet I still have the checkboxes in Plugin Details.

So, do I have to add an option to run/not run my hook?
Or, can I just grab the GT setting on this hook and run/ not run based on that?

How do I access the enabled disabled setting from plugin config options?
Code:
'ZipCodeSearch' => {
'hooks' => [
[
'add_link',
'PRE',
'Plugins::ZipCodeSearch::add_link_hook',
'1'
],
[
'modify_link',
'PRE',
'Plugins::ZipCodeSearch::modify_link_hook',
'1'
]
],

I hope you understand what I am asking.

Thanks,
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Plugin Hooks (enable/disable) In reply to
Doh! Why do I always figure this out *after* posting the question?

I see now that Andy's plugin allows for the plugin to be enabled and a "section" of code to *not* run.

Nevermind.

Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Plugin Hooks (enable/disable) In reply to
Can I have a Plugin Hook default to 'disabled' via install.pm?

Thanks
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Plugin Hooks (enable/disable) In reply to
bump

Quote:
Can I have a Plugin Hook default to 'disabled' via install.pm?

I have 2 hooks that I am adding via plugin installer and I want them DISABLED or off by default.
Code:
$mgr->install_hooks('MyPlugin', [['add_link', 'PRE', 'Plugins::MyPlugin::add_link_hook', '0']]);

I tried adding the 0 as that 4th argument, but no luck disabling hook on install.

Maybe something along these lines?
Code:
my $opts = Links::Plugins->get_plugin_user_cfg('MyPlugin');
$opts->{'add_link'} = 0;
Links::Plugins::set_plugin_user_cfg ('MyPlugin', $opts);

Which probably wont work because the plugin is BEING installed and maybe config isn't ready?

Please advise. Thanks

Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com

Last edited by:

rgbworld: Jun 18, 2006, 8:06 PM
Quote Reply
Re: [rgbworld] Plugin Hooks (enable/disable) In reply to
Sorry to bring this back up, but I still would like to disable a hook when a plugin gets installed.
That is the plugin installs a hook, but I want it to be disabled or unchecked in setup (by default).

Additionally, I need to check if that hook is enabled or not.

Any ideas are appreciated. I know I can get_plugin_user_cfg(), and that the hook is in there.
Is the last argument of the hook wrt to plugin.cfg the enabled/disabled flag?

If so, I should just be able to get it's value. If not, where is the plugin enabled flag?

Thanks again,
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Plugin Hooks (enable/disable) In reply to
Yes.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [rgbworld] Plugin Hooks (enable/disable) In reply to
Were you able to get this working? I thought I had replied to it but don't see that I did.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Plugin Hooks (enable/disable) In reply to
I have not figured out how to have a hook installed
but disabled when a plugin is 1st installed.

I was however able to get the enabled/disabled state of a hook.
I copied sub get_plugin_user_cfg(), renamed it get_plugin_hook_cfg()
Code:
sub hook_enabled {
# ------------------------------------------------------------------
# Results in 1 or 0 and indictes whether or not the hook is enabled.
#
my $name = $_[0];

my $plugin_hooks = get_plugin_hook_cfg('CAPTCHA');
my $enabled = $plugin_hooks->{$name};

if ($enabled) {
return ('1');
}
return ('0');
}

sub get_plugin_hook_cfg {
# --------------------------------------------------------------
# Returns the hook config hash for a given plugin.
#
my $class = ($_[0] eq 'Links::Plugins') ? shift : '';
my $plugin_name = shift || return;
my $cfg = GT::Plugins->load_cfg ( $CFG->{admin_root_path} . '/Plugins' );
exists $cfg->{$plugin_name} or return {};
(ref $cfg->{$plugin_name}->{user} eq 'ARRAY') or return {};

my $opts = {};
foreach my $opt (@{$cfg->{$plugin_name}->{hooks}}) {
$opts->{$opt->[0]} = $opt->[3];
}
return $opts;
}

I was just going to state in the readme that all hooks are enabled,
and that the ones that are not wanted, should be disabled.

I would prefer to install them as disabled though.
I am uncertain where I would put the disabling code in the install.pm.
It would have to be AFTER plugin.cfg gets written.

I was going to copy/modify set_plugin_user_cfg(), but I am pretty nervous
about doing that because I would hate to mess up plugin.cfg as it is used by every plugin.

Thanks,
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com