I’m working on a plugin that allows the user to create “page/post types”, customize the type style, then tag a page/post with that type. All of this works. My problem is this plugin also needs to allow them to attach widgets to said type.
I have no way of knowing how many “types” there are at any time.
The plugin works like this:
- User creates types (cat, dog, mouse)
- User specifies things like background colors, link colors, etc. for a type
- User specifies widgets for that type
When the page/post is viewed the page detects if it has a type. If it does it pulls in all the relavent data to that type.
Everything works PERFECT.
I know I have to register a sidebar but I can’t registe for each type since I have no idea how many there are and the user can create and delete at their whim.
My plan:
- Register a sidebar called “custom sidebar”
- Create a page that mimics the “Widgets” page
- Allow the user to add widgets there on the “custom sidebar”
- The plugin stores data for the sidebar based on the “type”‘s id
I can’t really use another plugin since the sidebar function has to meld right into my plugin. I’m not even sure this will work or even where to start. Any push in the right direction would be great!
$type . '_sidebar'
$type . '_sidebar'
(e.gdog_sidebar
)wp-admin/widgets.php?sidebar_type=dog_sidebar
)Filter out every sidebar that should not be displayed. You can use this function:
For example in Twenty Twelve there are three registered sidebars (the sidebar IDs): sidebar-1, sidebar-2 and sidebar-3.
If you now go to
your-blogdoma.in/wp-admin/widgets.php?sidebar_type=sidebar-3
, there is only the third sidebar left (with IDsidebar-3
).If you have registered a sidebar
dog_sidebar
and visityour-blogdoma.in/wp-admin/widgets.php?sidebar_type=dog_sidebar
, the only visible sidebar is the ‘Dog Sidebar’ (with IDdog_sidebar
).There is no need to do this. Every sidebar stores it’s own data. But maybe I misunderstood what you attempting with “stores data for the sidebar“.
I ended up just creating a sidebar and any item that was placed there, a dropdown box was added to assign it a special location.