Home > Software engineering >  can i use PHP standard recomendation(PSR) in wordpress?
can i use PHP standard recomendation(PSR) in wordpress?

Time:12-08

Can i use PSRs in wordpress vs the WordPress Coding Standards?

I am going to create a plugin but I want to use psrs and take advantage of all its features.

  • psr4
  • libs

CodePudding user response:

Absolutely, and it is best to use it for plugin development.
But as you know it is not recommended by the wordpress community one reason is it can be problematic if other plugins or the theme share identical packages installed via composer

But to use PSR4 or somthing similar just start your project with a composer.json and structure it with the correct file path for development for your plugin. Look at the example snippet below declaring autoload in composer.json followed by the PSR and the path

EXAMPLE: composer.json

    {
        "name": "author/myplugin",
        "type": "wordpress-plugin",
        "description": "Description",
        "require": {
           "php": ">=7.4"
        },
        "autoload": {
            "psr-4": {
                "MYPLUGIN\\": "src/Includes/"
            }
        }
    }

  • Related