I've created a little WordPress block, starting from the npx @wordpress/create-block template. All is well and good, but I need to fix the packaging process.

The main plugin file includes a couple of php files:

define( '__ROOT__', plugin_dir_path( __FILE__ ) );

require_once( __ROOT__ . 'src/testimonial-pages.php' );
require_once( __ROOT__ . 'src/block.php' );

The problem is, npm run plugin-zip does not include those files in the zip archive.

According to the plugin-zip docs,

In the case where the plugin author wants to customize the files included in the zip file, they can provide the files field in the package.json file as documented in the npm-packlist package

which it does, but isn't the desired behavior. It includes the files specified, but also some additional cruft (e.g., the package.json file), and not all of the original files included by npm run plugin-zip if I don't add a "files" section to package.json.


% npm run plugin-zip
Using Plugin Handbook best practices to discover files:

  Adding `cwr-testimonial-block.php`.
  Adding `readme.txt`.
  Adding `build/block.json`.
  Adding `build/index.asset.php`.
  Adding `build/index.css`.
  Adding `build/index.js`.
  Adding `build/slider.asset.php`.
  Adding `build/slider.css`.
  Adding `build/slider.js`.
  Adding `build/style-index.css`.

then if I add "files": [ "src/*php" ] to package.json:

% npm run plugin-zip
Using the `files` field from `package.json` to detect files:

  Adding `build/index.js`.
  Adding `package.json`.
  Adding `src/block.php`.
  Adding `src/testimonial-pages.php`.
  Adding `readme.txt`.

So, I guess what I want is to extend "Plugin Handbook best practices" to include my required files. (or, alternatively, make whatever changes I need to make such that my plugin conforms to said best practices (which I can't actually find in the Plugin Handbook, but maybe I'm missing something)).

1 Answer 1


Create a folder named includes in the root of your plugin folder; and place your additional php files inside of there. They (andchild folders and files) should then be copied over with plugin-zip.

If you have a php file with the same name as your plugin in your plugin's root folder; that will also copy over as well. (e.g. your plugin is named super-rad-explosion; plugin-zip will also copy oversuper-rad-explosion.php in the root folder of the zip).

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.