Class autoloader in wordpress plugin

前端 未结 2 702
南笙
南笙 2021-01-16 22:52

I want to write a class autoloader to use in a wordpress plugin. This plugin will be installed on multiple sites, and i want to minimize the chance of conflicts with other p

2条回答
  •  北海茫月
    2021-01-16 23:37

    I recommend using namespaces, and PSR-4. You could simply copy this autoloader example from FIG.

    But if you don't want to, you can use an autoloader like this one, that defines an convention for WP classes names, and uses that to find the class file.

    So, for example, if you call a 'Main' class, then this autoloader will try to include the class file from path:

    /class-main.php
    

提交回复
热议问题