0

A plugin of mine has main PHP file named "init.php", now I want to follow best practice and rename it to "plugin-name.php"

As users are used to upgrade the plugin by overwriting the old folder with update, so there will be

init.php
plugin-name.php

both exist in the plugin folder after upgrade, which results in a PHP fatal error, saying a class not found, whatever, deleting "init.php" and all clear.

Though I can tell users how to fix it when they contact me, but it isn't a good solution to throw the error on users, is there a way to remove or ignore legacy main plugin file in WordPress?

1

Depending on the plugin version delete the file init.php on upgrading from the plugin folder. For this purpose you can use the Filesystem API, especially the delete() method - here exemplary linked to the WP_Filesystem_Direct class.

  • I have figured it out a while ago too, but what I use is php method unlink(__FILE__), tested ok on my host server though, is there any benefits using delete()? – Edward Dec 24 '16 at 17:01
  • @Edward It has an additional security check, but aside from that does use unlink() too. So pretty much no benefits. One point could be consistency with using WordPress API functions, hasn't to do with functionality though. – Nicolai Dec 25 '16 at 11:10

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.