Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 60

Naming Classes and Methods

Оглавление

Class and method naming is one area where the core WordPress coding standards don't align with the PHP community. The PHP standard is to write class names in PascalCase where the first character of each word is uppercase and there are no separators between words. The standard for class methods is to write words in camelCase where the difference is that the first character of the first word is lowercase.

The following example shows what a basic class with a single method looks like using this method:

<?php class PDEVSetup { public function setupActions() { } }

The WordPress coding standards follow a different set of rules. Look at the following example to spot the differences:

<?php class PDEV_Setup { public function setup_actions() { } }

As you can see, the WordPress method uses underscores to separate class names and uses snake case for method names. You'll need to decide the best direction for your own plugins. There's no one right answer, and developers have been arguing over naming schemes for as long as programming has existed. The most important thing is to be consistent in your own code.

Professional WordPress Plugin Development

Подняться наверх