I have the following situation – I’m making a WordPress version of a jQuery plugin and I want the users to be able to have multiple instances of the plugin (with unique content) for their site. On the main page of my plugin settings the user makes and deletes the instances of the plugin and they appear as dynamically generated submenu pages.
Here comes the trouble. In each submenu page there must be a form with settings for that specific instance. I’m doing my best to go with WP standards (so to speak) instead of custom stuff and I really want to try out the Settings API. I barely wrap my head around how to use it in a “normal” or static page, but what about those dynamically generated pages? What do I have to specify as a page when I register the settings section with add_settings_section()?
Also, I’m using the class approach for writing the entire thing, and honestly it’s a mess. I have no idea where should I register those sections and fields. Here is my template for the plugin:
if (!class_exists('PluginName')) {
class PluginName {
function __construct() {
}
function get_admin_options() {
}
function init() {
// Register plugin pages, subpages and stuff
}
function print_admin_page() {
}
}
}
if (class_exists('PluginName')) {
$pluginName = new PluginName();
}
if (isset($pluginName)) {
add_action('admin_init', array($this, 'init'));
}
Any help is much appreciated.
Cheers!
I think the approach you’re attempting is prohibitively complex, and will not scale well at all. I would suggest two possible alternatives to the approach you’re trying to take: