Viewing 3 reply threads
  • Author
    Posts
    • #1987
      stebcom
      Member

      Hi,
      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 documentation

      https://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!

    • #2008
      Steve
      Keymaster

      @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;
      }
      
    • #2012
      stebcom
      Member

      Thank 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:

      http://stackoverflow.com/questions/21927445/wordpress-admin-when-placing-a-custom-post-type-as-a-submenu-of-a-parent-menu

      I wonder if Piklist includes a scenario like this and how can I develop it.

    • #2013
      Steve
      Keymaster

      @stebcom– You can use the standard WordPress parameter show_in_menu for 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;
      }
      
Viewing 3 reply threads
  • You must be logged in to reply to this topic.