Tagged: plugin, post_types, submenu
- This topic has 3 replies, 2 voices, and was last updated 7 years, 6 months ago by
Steve.
-
AuthorPosts
-
-
July 14, 2014 at 11:33 am #1987
stebcomMemberHi,
I just discovered Piklist and I’m trying to write a new plugin. I’ve already checked out Piklist Demos, but I can’t figure out how to manage menu and submenu pages. I read the related post in the documentationhttps://piklist.com/user-guide/docs/settings-admin-page-parameters/
but it doesn’t explain how to mix the add_submenu_page() WordPress function with Piklist parameters.
My code is like this:
add_action( ‘admin_menu’, ‘my_plugin_menu’ );
function my_plugin_menu() {
add_menu_page( PAGE_TITLE, MENU_TITLE, CAPABILITY, MENU_SLUG, ‘show_menu’ );
add_submenu_page( MENU_SLUG, ‘Options’, ‘Options’, CAPABILITY, MENU_SLUG, ‘show_options’);function show_menu() {
echo “Hello World!”;
}function show_options() {
add_filter(‘piklist_admin_pages’, ‘custom_options’);
add_filter(‘piklist_post_types’, ‘custom_post’);function custom_options($pages)
{
$pages[] = array(
‘page_title’ => __(‘Custom options’, ‘piklist’)
,’menu_title’ => __(‘Options’, ‘piklist’)
,’capability’ => ‘manage_options’
,’sub_menu’ => ‘edit.php?post_type=custom_options’
,’menu_slug’ => ‘custom-options’
,’setting’ => ‘custom_settings’
,’menu_icon’ => plugins_url(‘piklist/parts/img/piklist-icon.png’)
,’page_icon’ => plugins_url(‘piklist/parts/img/piklist-page-icon-32.png’)
,’default_tab’ => ‘General’
,’single_line’ => true
,’save_text’ => ‘Save these settings’
);return $pages;
}function custom_posts($post_types)
{
$post_types[‘custom_post’] = array(
‘labels’ => piklist(‘post_type_labels’, ‘Custom’)
,’title’ => __(‘Enter a new Custom Post’)
,’menu_icon’ => piklist_admin::responsive_admin() == true ? plugins_url(‘piklist/parts/img/piklist-icon.svg’) : plugins_url(‘piklist/parts/img/piklist-icon.png’)
,’page_icon’ => plugins_url(‘piklist/parts/img/piklist-page-icon-32.png’)
,’supports’ => array(
‘title’
,’revisions’
)
,’public’ => true
,’admin_body_class’ => array (
‘piklist-demonstration’
,’piklist-sample’
)
,’has_archive’ => true
,’rewrite’ => array(
‘slug’ => ‘custom-posts’
)
,’capability_type’ => ‘post’
,’edit_columns’ => array(
‘title’ => __(‘Title’)
,’author’ => __(‘Author’)
)
,’hide_meta_box’ => array(
‘slug’
,’author’
)
,’post_states’ => true
,’status’ => array(
‘draft’ => array(
‘label’ => ‘New’
,’public’ => true
)
,’lock’ => array(
‘label’ => ‘Lock’
,’public’ => true
)
,’publish’ => array(
‘label’ => ‘Published’
,’public’ => true
)
)
);return $post_types;
}}
While for main page I get the “Hello World” text, I get nothing for submenu page. Can you guide me to use this correctly?
Many thanks!
-
July 15, 2014 at 2:26 pm #2008
SteveKeymaster@stebcom– I cleaned it up a bit and removed some parameters you probably won’t need. You had a few typos, like the function in a filter not matching the function you want to call.
The idea here, is to register the post type, and they assign the settings to the post type url, not the settings url.
add_filter('piklist_admin_pages', 'custom_options'); function custom_options($pages) { $pages[] = array( 'page_title' => __('Custom options', 'piklist') ,'menu_title' => __('Options', 'piklist') ,'capability' => 'manage_options' ,'sub_menu' => 'edit.php?post_type=custom_post' ,'menu_slug' => 'custom-options' ,'setting' => 'custom_settings' ,'save_text' => 'Save these settings' ); return $pages; } add_filter('piklist_post_types', 'custom_posts'); function custom_posts($post_types) { $post_types['custom_post'] = array( 'labels' => piklist('post_type_labels', 'Custom') ,'title' => __('Enter a new Custom Post') ,'public' => true ,'has_archive' => true ,'supports' => array( 'title' ,'editor' ) ,'rewrite' => array( 'slug' => 'custom-posts' ) ,'capability_type' => 'post' ); return $post_types; } -
July 16, 2014 at 4:15 am #2012
stebcomMemberThank you Steve, now this is clear to me.
What I’d like to do now is to place a custom post type as a submenu of an existing admin page. I found an interesting thread about this:
I wonder if Piklist includes a scenario like this and how can I develop it.
-
July 16, 2014 at 9:32 am #2013
SteveKeymaster@stebcom– You can use the standard WordPress parameter
show_in_menufor the custom post type. Full code below:add_filter('piklist_admin_pages', 'custom_options'); function custom_options($pages) { $pages[] = array( 'page_title' => __('Custom options', 'piklist') ,'menu_title' => __('Options', 'piklist') ,'capability' => 'manage_options' ,'menu_slug' => 'custom-options' ,'setting' => 'custom_settings' ,'save_text' => 'Save these settings' ); return $pages; } add_filter('piklist_post_types', 'custom_posts'); function custom_posts($post_types) { $post_types['custom_post'] = array( 'labels' => piklist('post_type_labels', 'Custom') ,'title' => __('Enter a new Custom Post') ,'public' => true ,'show_in_menu' => 'custom-options' ,'has_archive' => true ,'supports' => array( 'title' ,'editor' ) ,'rewrite' => array( 'slug' => 'custom-posts' ) ,'capability_type' => 'post' ); return $post_types; }
-
-
AuthorPosts
- You must be logged in to reply to this topic.