_install, activate, _uninstall etc
#1
Hi All,

So with the plugin I am currently writing, there aren't really any settings as such however it does create templates and database tables.

My assumption would be to

plugin_install() {
install tables
install tempate
}

plugin_uninstall() {
remove templates
remove tables
}


So now what would I end up doing with activate and deactivate in these circumstances as these actions are more used when removing the plugin, or is it better to have these in activate and deactivate?

[/code]
Reply
#2
usually activate and deactivate will apply template changes, like insert the template variable of the new template you are adding. say you create a new template "myplugin_postbit_extra" that has images and links in it which is handled by install/uninstall .

then you want to insert a similarly named variable {$myplugin_postbit_extra} into the postbit template and that part is in activate/deactivate.
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#3
plugin_install() {
  insert tables
}
plugin_activate() {
  insert tempate changes
}
plugin_deactivate() {
  remove tempate changes
}
plugin_uninstall() {
  remove tables
}
This way user may deactivate plugin (temporarly remove template changes)
to hide it (or update forum) then activate it back while preserving plugin settings
(tables, which was not removed while deactivating).
Reply
#4
i disagree, but it depends on what template changes you need to make

if you have no new templates to add, then the above is fine since you are only inserting the template change.

however, if you have new templates to add then I recommend
plugin_install() {
   insert tables
  insert templates
 }
 plugin_activate() {
   insert template changes
 }
 plugin_deactivate() {
   remove template changes
 }
 plugin_uninstall() {
   remove tables
   remove templates
 }
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#5
I guess that for me, I may make a whole lot of changes to the templates and however I want to disable the plugin for sometime, say during the off season.

So when that happens if I put the changes into activate, that means the template changes will be stripped.

I think I may just put in a setting instead and essentially have activate and de-activate update that setting and check it from the front-end that way I can just throw a 404 or 302 from the page if the active flag is off. I can then keep all template changes and removals to the install and uninstall.

To me activate/deactivate should really be more of a "turned on"/"Turned off"
Reply
#6
it is good to have a simple setting that is on/off or enable/disable that controls the entire plugin. its also a tiny performance gain if you wrap the add_hooks in an if($mybb->settings['myplugin_enabled']) type statement so if the plugin is enabled only then will hooks be added.

and when you say "make a whole lot of changes to the templates", what does that mean? inserting changes to existing templates (like adding a new variable) or adding new templates to the database?
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#7
Hi sorry to clarify. I imagine that with one of the two plugins I am wroting people will want to edit the defauly set I provide. Even I will overtime. I dont want activating and deactivating to effect that
Reply
#8
that is when you use my method where you insert new templates on install and then to make them visible, insert the new template variables in the activate function.

here is a snippet of what I have done in the past

function wordfilter_install()
{
    //do stuff

    $template_insert = array(
        'name'=>'wordfilter_usercp,
        'template => 'some template properly escaped'
        'sid' => -1
        );
    $db->insert_query('templates', $template_insert);
}

function wordfilter_activate()
{
    //do stuff
 
       find_replace_templatesets('usercp_options', '#'.preg_quote('<legend><strong>{$lang->other_options}</strong></legend>
<table cellspacing="0" cellpadding="2">').'#si', "<legend><strong>{\$lang->other_options}</strong></legend>
<table cellspacing=\"0\" cellpadding=\"2\">
{\$wordfilter_usercp}");
}

function wordfilter_deactivate()
{
    //do stuff

    find_replace_templatesets("usercp_options", "#".preg_quote('{$wordfilter_usercp}')."#i", '', 0);

}

function wordfilter_uninstall()
{
    //do stuff

    $db->delete_query("templates", "title='wordfilter_usercp'"); 
}

function wordfilter_called_from_hook()
{
    global $wordfilter_usercp;

    //do stuff

    eval("\$wordfilter_usercp = \"".$templates->get("wordfilter_usercp")."\";");
}


it is by no mean complete but you should be able to get the idea. Once installed you can edit wordfilter_usercp template all you want and activate and deactivate any number of times but it wont go away until you uninstall.

the activate/deactivate only inserts/removes the template variable {$wordfilter_usercp} for the base template that I want it in. How the wrodfilter_usercp template looks is independent of that process.
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#9
Cheers mate
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)