Creating Plugins For NP Subscriber Pro - Page 2

Installation Complete Message

  First things first. All Subscriber plugins must have the extension "spi." Obviously, SPI stands for Subscriber PlugIn... Yes, this extension is required. When a user goes to install a plugin, they just type in the filename minus the SPI extension. For this example, we'll just name it "stats.spi" for obvious reasons...

  Now, the first thing we're going to write is the message that is displayed right after the plugin is installed. This will define the variable $message.

  So, right after a user installs the plugin, that is the message that will be displayed.

Admin Button

  The Admin Button is the form button that is displayed in the admin area. Imagine that... How does the script get the form button from the plain text plugin file? Why, it requires it of course! You see, when somebody is "installing" a plugin, all they're really doing it adding text to the "plugins.list" file. For a plugin named "stats.spi," the script just opens up the plugins.list file and prints two simple lines: require "plugins/stats.spi"; and &button;. Then, whenever the main admin interface is loaded, there's a line in subscriber.cgi that requires the plugins.list file. So, it requires a file that is filled with requires. Following me? Good...

  Now, for the button to appear, it has to be a subroutine called button. In the above paragraph I showed that the script requires the plugin file and runs the button subroutine within the HTML of the above interface itself. Hopefully this isn't sounding really complicated because it's really not that hard to understand... But anyway, now we need to create a button that the user sees on the main admin screen. There are a number of variables that you must define in the button. But first, here's the complete code for the button:

  As with everything in NP Subscriber PRO, this is form driven, and each admin button is its own form. You can go ahead and look on the admin screen for yourself... Go on... Now, here's something important for you to remember. Every plugin must have its FORM ACTION as $script?run_plugin and nothing else. You'll see exactly why a little later. But for now, just keep that in the back of your mind because it's important. On the subject of the button again, here's the list of the hidden variables that must be included and what each means:

  • plugin -- This is the filename of the plugin without the .spi extension.
  • list -- This is a variable that is kept in every form in NP Subscriber PRO. It tells the script which list you are logged in under.
  • action -- This tells the run_plugin subroutine in NP Subscriber PRO which subroutine to run in your plugin. Confused? Well, every action a plugin has to do has to be a subroutine. If it was just in the file itself (not in a variable or under a subrountine), the code would be executed on the main admin screen (since it's being required). If you wanted to create a form inside the plugin that does another action in the plugin (like the Form Generator plugin does), you would make the subroutine that contains the form the action in admin button, and make the other subroutine the action in the form itself. Like I said, if you want to see that in action, and possibly get a better understanding of the process, take a look at the Form Generator plugin.
  The Submit button can have a value of whatever you want.

  Got that? Good, continue on the the next page.

Valid XHTML 1.0! Valid CSS!
©1999-2007 Brandon Stewart
"It is not only possible, it is essential!"