Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Iulian Stanescu
Iulian Stanescu
4,515 Points

I have some clarification questions while working on my first WP plugin

After finishing the WordPress track, I am working on my first plugin and I have some questions for which I would appreciate if you can give me some clarifications about one or several questions.

Let's say my project is a gallery plugin for WP.

  1. Is it right to make a custom post type for this? So that each gallery is a post that the user creates? And he uses a shortcode to embed it where his theme allows content. Is there a better option or is this the most common approach?From my research, this is the most recommended approach. I have found it in guides as well as in existing plugins.

  2. On a gallery new/edit post page, is using meta boxes for the custom fields the common approach or is there a better option? Some plugins use custom designs on the post page. I preferred to use meta boxes as to keep the UI as close as possible to the WordPress look.

  3. The WP codex recommends that every meta box have it's own nonce. But the post form on the page already has a nonce, why does every meta box need one?

  4. From the Screen Options tab, you can disable meta boxes on the post page. But if my meta boxes have required content, is there a way to prevent them from showing in Screen Options and from being able to turn them off? Like the Publish meta box which does not show there.

  5. When I publish a post, there is a button at the top saying "View Gallery". This just goes to the standard posts page, without the gallery displaying. I presume because the theme does not have a template for my custom post type and it defaults to the posts template. Can I, from the plugin, make a page for my custom post type? Or how can I disable this "View [Custom Post Type]" if it is not possible for me to create a way for the user to view the gallery post type.

  6. What is the difference between a public post type (public: true) and a private one (public: false)? I have tested both and the private one has a slightly different UI at the top. Both have the "Add New" button but with different designs.

  7. Can the text domain of my plugin be slightly different than the plugin file name? My plugin file and class names have 3 words, I have used 2 words for the text domain to make it shorter. Is this acceptable, considering I have used the proper domain name (the 2 words one) in the load_plugin_textdomain function?

1 Answer

Evan Agee
Evan Agee
13,088 Points

Greetings! Let me try and address a couple of your questions:

  1. This sounds like the correct way of creating the plugin. It would be wrong to roll your own solution for something that already exists within Wordpress.

  2. I believe you're also correct here. There's nothing wrong with styling the forms to give your plugin its own feel, but I think it's generally less jarring for users when it feels like the rest of the Wordpress admin.

  3. Yes, you can create custom admin pages and display whatever content you want, including custom post types. https://premium.wpmudev.org/blog/creating-wordpress-admin-pages/?omtr=b&utm_expid=3606929-101._J2UGKNuQ6e7Of8gblmOTA.1&utm_referrer=https%3A%2F%2Fwww.google.com%2F

  4. My understanding is that the text domain can be whatever you want as long as you're consistent. It's somewhat common for the name of a plugin to change and the text domain stay the same over time.