RFC: Plugin Manager Plugin Configuration

To all the plugin developers out there, I would like to get some feedback on what I am currently planning on implementing for the Plugin Manager with regards to plugin configuration options.

So, to start with, here is some sample code that might appear in remote post:

my $blog_id = 1;
my $author_id = 1;

eval "use MT::Plugins::Config;";
if (!defined $@) {
    require MT::Blog;
    require MT::Author;
    MT::Plugins::Config->add_variable ( Blog_ID => {
        plugin          => 'remote post',
        var             => \$blog_id,
        desc            => "Destination blog for all remote post pings",
        allowed_values  => { map { $_->name => $_->id } MT::Blog->load },
        use_hash_values => 1,
    });
    MT::Plugins::Config->add_variable ( Author_ID => {
        plugin          => 'remote post',
        var             => \$author_id,
        desc            => 'Author as whom to post remote post pings',
        allowed_values  => { map { $_->name => $_->id } MT::Author->load },
        use_hash_values => 1,
    });
}

Basically, the idea is that this plugin can operate with or without the Plugin Manager installed. If it is not, the user just changes the values in the initial declaration. Otherwise, the Plugin Manager can handle the validation and storing of the values.

So, let me go into a little more detail about all the hash keys I plan to include:

  • plugin: Plugin name
  • var: Reference to the variable that should hold the configured value (if you don't understand exactly what a Perl reference is, think of it like a pointer).
  • desc: Description of the variable
  • allowed_values: Hash containing possible values for the variable
  • use_hash_values: If set to a true value (i.e. 1), the Plugin Manager will display the hash keys to the user for choosing, but will store/assign the hash value of that key. Otherwise, it will only use the hash keys.
  • regexp: While allowed_values explicitly sets the possible values, regexp gives you a little more flexibility. Just set it to a regular expression that the value of the variable must match (e.g. '\d{1,3}' for a 1-3 digit number).

In the future, I would like to expand this to include dynamic lists of values. To use remote post as an example, I would use it to define a list of remote post id's that a site administrator could use to designate different author-blog-category combinations.

Any thoughts? Concerns?

6 Comments

You might consider adding something that explains a bit more why this is of value to Plugin developers. How this fits into the Plugin manager as a whole and why a developer would want to add this extra code to their plugin.

Seems complicated. Maybe we could just do something like defining specific variables?

$VERSION = "0.10;
$AUTHOR = "Brandon";

Would that work?

Seems complicated. Maybe we could just do something like defining specific variables?

$VERSION = "0.10;
$AUTHOR = "Brandon";

Would that work?

Would this also let me develop and work on a plugin that is not in the plugin database yet?

And actually, more to the point, has this at all been added? I would love to be able to move data away from the config file (which if not configured right, could easily be accessable to the world, so its a bit of a security risk) and this would be an awsome method (with fallback to the file if nothing else works.)

My only issue is here its very limited as to the kind of data that would work. I'd want to be able to have some way of selecting a blog id, and associating data with that. But still with the ability to have multiple blogs setup with thier own set of information (does that actually make any sense?)

Hello.i'am from china!can i make friends with you?

i'am from china!can i make friends with you?

Leave a comment

Recent Entries

  • Plugin Writing 101

    So, I’m planning on writing up some entries about various aspects of plugin development. While I have a couple topics already in mind, I thought...

  • The Olympics Make Me Want To Compete Again

    Every time the Olympics come around (most the summer ones) I always start to delude myself into thinking I could complete once again in the...

  • Minimalist plugins are fun!

    Last night I whipped up one of the smallest plugins I’ve ever written. It is so small in fact that I was able to stuff...

  • Feedburner Widget on MT News

    Movable Type News A WordPress 2.5 Upgrade Guide: And of course there are lots of third-party plugins for the MT dashboard, to integrate statistics and...

  • AD&D Monster Stats for the Presidential Canditates

    Charles Stross (scifi author, D&D nerd, and former perl columnist) posted Politics as she is Played with 3d6: The recent death of Gary Gygax, who...

Close