Naming Your Plugin


Bones “artisan” command

When you install your plugin, you may wish to change the plugin name. This is a common practice when you are using bones as a starting point for your plugin development.

Let’s rename the plugin name and the namespace:

php bones rename <your plugin name> <your namespace>

Note: On Windows, the command line treats single quotes differently than double quotes. To ensure compatibility, always use double quotes for arguments containing spaces.

If you leave blank <your plugin name>, a command line prompt will be displayed, and you will be asked to enter a new Plugin name. The Bones command will use this information to make some changes to the code. Also, the bones command will use it as a namespace as well as a slug.

The plugin name is the first argument and you can skip the second argument if you want to use the namespace generated by the plugin name.

For example, if you enter "My WP Plugin", the bones command will create:

My WP Plugin          Name of plugin
MyWPPlugin            Namespace, see [PSR-4 autoloading standard](http://www.php-fig.org/psr/psr-4/)
my_wp_plugin_slug     Plugin slug
my_wp_plugin_vars     Plugin vars used for CPT, taxonomy, etc.
my-wp-plugin          Internal id used for css, js and less files
my-wp-plugin.php      Main plugin file

Starting from v1.5.0, we replaced the previous index.php main plugin file with the name of your plugin. This change was made to avoid rejection from the WordPress plugin repository.

Naming Your Plugin Again

After installing your plugin, you may wish to change the plugin name again.

⚠️

Remember that a plugin name is bound to PHP namespace. This is because WordPress doesn’t support namespaces in the current plugin architecture.

You can do this by using the rename command in the Bones command line:

php bones rename "WP My Awesome Plugin"

In this case, you will get:

WP My Awesome Plugin          Name of plugin
WPMyAwesomePlugin             Namespace (PSR-4)
wp_my_awesome_plugin_slug     Plugin slug
wp_my_awesome_plugin_vars     Plugin vars used for CPT, taxonomy, etc.
wp-my-awesome_plugin          Internal id used for css, js and less files
wp-my-awesome-plugin.php      Main plugin file

Options

You may also reset the plugin name and the namespace to the original version.

php bones rename --reset

In addition to that, you may also update the namespace after a composer update.

php bones rename --update

Probably, you won’t need to do that as the update flow is already in the composer file

...
  "scripts": {
    "post-autoload-dump": [
      "php -r \"copy('vendor/wpbones/wpbones/src/Console/bin/bones', 'bones');\"",
      "php bones rename --update"
    ]
  }
  ...