1

I have created a custom plugin. How do I define its slug?

To clarify, if I attach a custom PHP function to the manage_plugins_custom_column hook, and in that function print the value of the $plugin_data array for each plugin in my WordPress installation, that array will contain information about each plugin. Here is such a function:

function opn_render_date( $column_name, $plugin_file, $plugin_data ) {
  error_log( print_r( $plugin_data, true ) );
}
add_action( 'manage_plugins_custom_column', 'opn_render_date', 10, 3 );

And here is example output for one popular plugin in the WordPress repo (Classic Editor). In that output, the array element $plugin_data['slug'] => classic-editor can be seen. I have created a plugin, installed it, and activated it. The plugin functions as expected. But when I print out the same $plugin_data[] for my plugin, $plugin_data['slug'] does not exist. Why is that? How do I define the slug for my plugin?

If the issue is related to the header in my main plugin PHP file, that header can be seen here.

Maybe a slug is assigned by WordPress, only after a plugin is accepted to the WordPress plugin repo? I have not yet submitted it there.

edit: To clarify, I've written a plugin that is installed/activated via Dashboard-->Plugins.

2 Answers 2

1

I eventually submitted this plugin to the WordPress repo. As soon as it was accepted, my plugin was assigned a slug. So it looks like the WordPress plugin admins assign your plugin a slug during the initial review process.

0

By default, it should be the folder of your plugin.

If you use wp cli, you can use

wp plugin list

to show all the plugin slugs.

7
  • Here is the name of my plugin's folder (i.imgur.com/wkFBeWx.jpg). If I'm not using wp-cli, how can I show all the plugin slugs? I may have an issue in which the header in my main plugin file isn't formatted properly.
    – cag8f
    Commented Sep 19, 2019 at 13:37
  • Your slug should be 'outdated-plugin-notifier'. You can put var_dump(get_site_transient('update_plugins')); on a test page to look at plugin info that would include the [folder]/[filename] of each plugin. Note that it relies on transients, which could be stale (shift-reload page, revisit page later). The name of the folder a plugin resides in is the same as the plugin's slug. To define your slug, name your folder what you want the slug to be.
    – C0c0b33f
    Commented Sep 19, 2019 at 14:29
  • Right O. I understand that my slug should be outdated-plugin-notifiier. My issue is that WordPress doesn't seem to recognize that I have a plugin with that slug (or that WordPress doesn't seem to recognize that I have a plugin at all). I added a function to print get_site_transient('update_plugins'), attached it to the wp_head hook, and loaded my home page. This is the output: pastebin.com/UCd5W8q8 . It doesn't contain anything about my new plugin. Here is a screenshot of my plugin admin screen: i.imgur.com/RbiaMmI.jpg. Thoughts?
    – cag8f
    Commented Sep 20, 2019 at 3:01
  • So using get_site_transient('update_plugins'), it seems like WP doesn't recognizes that there is any plugin at all. In the other test I ran (using the manage_plugins_custom_column hook), WP recognized a plugin with the name 'Outdated Plugin Notifier,' but didn't seem to recognize any slug at all for it. To be clear, I'm not saying a blank string was defined as the slug. I'm saying that the slug is contained in the array element $plugin_data['slug'], and the index slug is not defined at all in that particular array. Not sure how to troubleshoot further.
    – cag8f
    Commented Sep 20, 2019 at 3:03
  • Sorry, I have an update. Per your suggestions, on my home page I carried out a hard refresh, then printed get_site_transient('update_plugins') again. There is slightly different output (see here: pastebin.com/FsBYnSNV). The output indicates that my plugin is recognized by the checked array, but not by the no_update array. Why might that be? Should I expect that array to contain info on the Outdated Plugin Notifier plugin?
    – cag8f
    Commented Sep 20, 2019 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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