1 balupton Aug 02, 2007 10:39
3 edb Mar 14, 2008 01:59
Okay finally got this working, only differently. I added the setting directly to GetDefaultSettings() because I generally don't bother with $r = foo and return $r, but whatever: add a setting to GetDefaultSettings:
'link_love' => array(
'label' => $this->T_('Show Support?'),
'type' => 'checkbox',
'defaultvalue' => '0',
'note' => T_('Adds a credit link for this plugin to your page footer.'),
),
I then discovered by process of educated guess work and a wee bit of elimination that SkinBeginHtmlHead is a nice function to use to tweak the credits array with, like so:
/* add a link-back, if allowed, to the credits_array */
function SkinBeginHtmlHead() {
if ( $this->Settings->get('link_love') ) {
global $credit_links;
$credit_links = array_merge( $credit_links, array( array( $this->get_help_url(), $this->name ) ) );
return true;
}
}
Obviously if you are actually using the SkinBeginHtmlHead function then you wouldn't return out of it unless you've already done the bits you need to do, but yeah y'all can probably figure that part out... And clearly this depends on the blog owner still having credits_array in their skin, which is why it's even easier to dream of some link-love if your plugin is a widget maker.
In a widget maker you use a similar setting in your GetDefaultSettings function:
'link_love' => array(
'label' => $this->T_('Show Support?'),
'type' => 'checkbox',
'defaultvalue' => '0',
'note' => T_('Adds a credit link for this plugin under the widget.'),
),
Then you add a little P tag to the bottom of your SkinTag function, like this:
if( $this->Settings->get('link_love') ) {
echo $params['notes_start'];
echo '<p><a href="'.$this->help_url.'">'.$this->name.' '.T_('widget by').' '.$this->author.'</a></p>';
echo $params['notes_end']."\n";
}
4 afwas Mar 14, 2008 02:12
Very nice EdB,
If I didn't give you rep star points yesterday you'd have gotten them today. ;)
You can even use the BBcode in your Avatar to make the text smaller if you've got nothing to say.
5 edb Mar 14, 2008 02:49
Oh snap! I didn't notice the points thing. So now you got 'em back ;)
Yeah I like the idea of a nice simple way to ask for a bit of link-love, so I've had this thread in my watched list for a while. The widget maker version is pretty easy, but acrolink doesn't make a widget so ... Bob's your uncle!
6 afwas Mar 16, 2008 22:14
EdB,
I have a fatal error with your widget thing. This more or less works:
// EdB's Linklove support
if( $params[ 'link_love' ] )
{
echo $params[ 'notes_start' ];
echo '<p><a href="'.$this->help_url.'">'.$this->name.' '.T_( 'widget by' ).' '.$this->author.'</a></p>';
echo $params[ 'notes_end' ]."\n";
}
although I am still investigating.
I hope ¥åßßå can shed his light on this and explain a little, since I want to use the settings (not the params) also in another thing (lottery) and I don't know how and where to initialize, which seems the problem with EdB's code also.
7 edb Mar 17, 2008 00:36
Okay cool. I think it worked in the plugin I put it in because that particular setting doesn't go to the widget if the admin enables widget-level settings, but I'll test it and see and probably do an upgrade release. Not a show stopper though so not much pressure on getting it done yah?
8 afwas Mar 17, 2008 00:39
EdB wrote:
Not a show stopper though so not much pressure on getting it done yah?
You call a fatal Error "not a show stopper"?
9 edb Mar 17, 2008 00:51
Yup. Because *I* am not seeing a fatal error, or an error of any kind in *my* implementation of that code. See the randomyoutubes plugin for the only place I've used that bit so far, and you won't see an error - or at least I don't under any combination of plugin or widget (if enabled) settings.
The only conditions under which a setting needs to be accessed as a param is if the setting is moved to widget-level control. Given that in the randomyoutubes plugin I am not offering the chance for each instance to decide on the value of the link-love setting(s), I've no need to concern myself with grabbing the info via Settings->get or param.
10 afwas Mar 17, 2008 01:29
Fixed now.
I had them under widget params since the widget has no settings. With either code you can now choose where to do the control.
Tx
11 edb Mar 18, 2008 00:38
Good good good. I knew there would be a solution to the widget-settings version, but with 2.4.1 credits_link is toast so now that part of this "idea" is nullified.
Updated