Closed rowellr closed 3 years ago
It should build all your menu items, pages and fields for you.
Essentially, you include the file in your functions.php file with include_once
. Build your array of pages, sections and fields and pass it to the RationalOptionPages
class.
At it's most basic, you should be able to copy/paste this into your functions.php file.
require_once('RationalOptionPages.php');
$pages = array(
'sample-page' => array(
'page_title' => __( 'Sample Page', 'sample-domain' ),
'sections' => array(
'section-one' => array(
'title' => __( 'Section One', 'sample-domain' ),
'fields' => array(
'default' => array(
'title' => __( 'Default', 'sample-domain' ),
),
),
),
),
),
);
$option_page = new RationalOptionPages( $pages );
I am going to double check that nothing is missed. Thank you.
You're welcome. Let me know if you don't have any luck. I'll be happy to help.
On Mon, Oct 31, 2016 at 11:45 AM rowellr notifications@github.com wrote:
I am going to double check that nothing is missed. Thank you.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/jeremyHixon/RationalOptionPages/issues/6#issuecomment-257330337, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXsoWne04B4PFs95N-avXoemeWz6HDeks5q5g0EgaJpZM4KlI0M .
what controls the menu name, and what designates it as a sub menu item? ( i am building an add-on to a current plugin but want to add another menu item to its top level menu. )
Hey Jeremy, Thank you for making this. Its saved me a ton of time. Its simpler too for any of my future alterations to my interface. thank you again. I managed to get it working. Still trying to figure out how to make it a sub menu item, but for the time being it will be great as a top level menu item too. -Ryan
Subpages are added in at the root level with the other pages or under a "subpages" array in the parent itself. You can put all your page parameters as normal in the "subpages" array or pass a parent_slug
parameter to one placed in the root of the $pages
array. You can use the key of the parent page you created or any of WordPress' pre-defined pages as well.
If you created a parent page under the key "my-option-page" then you'd add your subpages one of the two ways below:
require_once('RationalOptionPages.php');
$pages = array(
'my-option-page' => array(
'page_title' => __( 'My Option Page', 'my-domain' ),
// via the subpages key
'subpages' => array(
'sub-page-one' => array(
'page_title' => __( 'Sub Page One', 'my-domain' ),
),
),
),
// via the pages array itself
'sub-page-two' => array(
'parent_slug' => 'my-option-page',
'page_title' => __( 'Sub Page Two', 'my-domain' ),
),
);
$option_page = new RationalOptionPages( $pages );
And you're most welcome. Glad if I can help.
Last question I have, if I wanted to display a simple message at the top of the page showing that settings have been changed and saved how would i do that?
If you leave me long enough, I will figure it out ;)
Thank you again for your help..
I figured out how to use the section callback functions.
Good. I'm glad it's becoming clearer. Are you good now?
On Mon, Oct 31, 2016 at 2:19 PM rowellr notifications@github.com wrote:
If you leave me long enough, I will figure it out ;)
Thank you again for your help..
I figured out how to use the section callback functions.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/jeremyHixon/RationalOptionPages/issues/6#issuecomment-257376111, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXsobR9NKDz8TZL_yLZvpIIgW_fOpcOks5q5jFFgaJpZM4KlI0M .
about the only thing I think I need to know now is how to drop the options from the database on uninstall of the plugin.
On Mon, Oct 31, 2016 at 2:23 PM, Jeremy notifications@github.com wrote:
Good. I'm glad it's becoming clearer. Are you good now?
On Mon, Oct 31, 2016 at 2:19 PM rowellr notifications@github.com wrote:
If you leave me long enough, I will figure it out ;)
Thank you again for your help..
I figured out how to use the section callback functions.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/jeremyHixon/RationalOptionPages/issues/6# issuecomment-257376111, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXsobR9NKDz8TZL_ yLZvpIIgW_fOpcOks5q5jFFgaJpZM4KlI0M
.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jeremyHixon/RationalOptionPages/issues/6#issuecomment-257377155, or mute the thread https://github.com/notifications/unsubscribe-auth/AEoRdq0BTu0i-hZdfOcC8rrZ9mtfY6SSks5q5jIPgaJpZM4KlI0M .
That would be a combination of hooking into your plugin's uninstall process with register_uninstall_hook
and removing each of your keys with delete_post_meta
.
I love and prefer the layout of this code, I want to use the samples you have provided but I have no idea how to call it.
I have created a menu item, and I have created a page but I have no idea how to use your RationalOptionsPages.php to output my array that I have made to show my options in the admin.