Recent Topics

1 Feb 08, 2009 13:07    

Hi. Me again. Still blundering through a plugin that should have been done. By the way last year I was trying the same thing and settled for the cheapest hack ever made because I couldn't finish on time. So here I am again, trying to make the same old code (that never got used) actually work this time.

This time I had lots of stuff working. Added lots of fields to my tables, cleaned up a bunch of stuff that, while technically feasible, wasn't the best way to do something. Made it all the way to the point where my fields existed on the 'write' tab. Starting going through the AdminBeforeItemEditCreate hook to validate all my plugin inputs. Had a handle on that when I saw something that made me think OMG *that* is how I should have been doing LOTS of stuff I've already hammered in the hard way!

// set the params we'll need later
$this->set_param( 'entry_longitude', $entry_longitude );

So, like a total fool, I took something that was close to useful and totally screwed it up. And then went back and undid everything. Total waste of time eh?

Therefore I finally come to a question: has anyone thought about doing a general "this is how you do it" type of thing for plugins? Some of it I could do, like how to make settings for the Plugins page or the Users profile (and how to switch them). And maybe I could handle a general flow of what hooks to use for what type of stuff, but right now I'm thinking about good old set_param.

Like a plugin often gets a value for something in one hook that it needs in another hook. That's a pretty general statement right? So what's the best way to do it? The AHA moment of mine that turned out to not work was that I should use "set_param( 'a_param_name', 'a_param_value' )" so that later on in a different hook I would be able to access it with "$that_param_was = $this->a_param_name;" for example. Unfortunately that wiped out all functionality so I had to undo it all.

Great idea for the wiki-manual?

2 Feb 08, 2009 15:52

Okay so I got this one bit figured out. Probably already knew it cuz Yabba probably already told me, but now I feel smart cuz I forgot it all and now I know again :) When your plugin has a value it needs to remember so that another hook can use it later just do like this:

set_param( 'my_variable_name', $my_variable_value );


To get that value back when the plugin is on a different hook just do like this:

$my_variable_name = param('my_variable_name');

Faked up example: your plugin makes an extra form field for when you are blogging.

function AdminDisplayItemFormFieldset( & $params ) 
{
	$my_variable_value = '';
	$params['Form']->begin_fieldset( 'Shiny Happy Field' );
	$params['Form']->text_input( $this->get_class_id().'_my_variable_name', $my_variable_value, '32', T_('Label'), T_('this is a comment'), array( 'maxlength' => '255' ) );
	$params['Form']->end_fieldset( 'whateva' );
}

Now you want to ... I dunno maybe store it in your plugin's database table after the post is stored in b2evolution's tables.

function AfterItemInsert( & $params ) 
{
	$my_variable_name = param('my_variable_name');
	// $my_variable_name now holds whatever text you typed into your fancy form field
}

Beats the heck out of the way I'm trying to do it :(

3 Feb 08, 2009 15:56

To remember something use

$this->my_param = '12345';


then to get the value just type

echo 'Saved param = '.$this->my_param;

You don't have to set_param() unless you want to make it global (and available in skin)

4 Feb 08, 2009 17:35

I thought that was supposed to work but I kept getting double-crossed by either it or me. hmmm... :roll:

5 Feb 08, 2009 18:53

2nd hardest part about documenting solutions is knowing what problems people have.

Hardest part is getting them to describe the real problem without 20 posts that contain http://domain.com/ :roll:

It would be cool to (collaboratively ) find the time to sit down and work through all the available functionalities of plugins and how/where/why they can be (best) used/abused though ;)

¥


Form is loading...