0

I'm looking to build a plugin that stores settings for a companion app my Wordpress site works with. I've gotten to the point where I have a custom post type mobile_settings that stores labels and colors unique to the companion app.

I've gotten to the point where I have my new post type and it's meta values stored, as well as created a new admin page. Here's what I can't figure out to do:

  1. On the admin page, navigate the user to the "New Item" view if no mobile_settings have been created.
  2. If a single mobile_settings record has been created, navigate the user to it's edit view.

Once I have those, I know how to hide the custom post type from the UI, so the user will think it's a straight "options" page instead of a custom post type.

We are strictly building this from scratch in order to maintain a database structure that works for our needs. It's actually not as hard as I thought it would be =)

Any tips would be appreciated.

Edit: I guess some code would be appreciated too, huh?

add_menu_page(
    'Mobile Settings',
    'Mobile Settings',
    'manage_options',
    'mobile-settings.php',
    function () {
      $mobile_settings = get_posts(array('post_type' => 'mobile_settings', 'posts_per_page' => 1));
      if (count($mobile_settings) > 0) {
        wp_redirect(get_edit_post_link($mobile_settings[0]->ID) . '&noheader=true');
        exit;
      }
    },
    'dashicons-smartphone',
    5
  );
  • Have you considered using the wp_options table and just building an options page, instead of a whole CPT? It seems like that would be easier to tailor to your needs. – WebElaine Mar 26 at 12:37
  • I haven't -- could you point me to a tutorial? Also, would it be extensible enough to store arrays? – EHorodyski Mar 26 at 12:42
0

Thanks to @WebElaine -- I'm converting my custom post type into a Settings page. Can you tell I'm new to this? =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.