Tag Archives: wordpress

WordPress coding standards and Eclipse

If you are writing code for WordPress using Eclipse this post can help you to format your code in wp-style. This post is a simple how-to guide that helps you to integrate PHP Code Sniffer within eclipse.
All information about the WordPress coding standards are available on the codex here.

  • Download and install PHP_CodeSniffer plugin.
  • Download the WordPress Standard definition for Php_CodeSniffer package here.
  • Unpack the file and copy the folder “PHP_CodeSniffer_Standards_WordPress-0.0.1/WordPress” into¬†[YOUR_ECLIPSE_DIRECTORY]/plugins/org.phpsrc.eclipse.pti.library.pear_1.2.2.R20…/php/
    library/PEAR/PHP/CodeSniffer/Standards
  • Create a simple file called ruleset.xml with the following content
    <?xml version="1.0" encoding="UTF-8"?>
    <ruleset name="WordPress">
    <description></description>
    </ruleset>
  • ¬†change the visibility of the var $error to public in [YOUR_ECLIPSE_DIRECTORY]/eclipsePHP/plugins/org.phpsrc.eclipse.pti.library.pear_1.2.2.R20…/php/
    library/PEAR/PHP/CodeSniffer/Standards/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php
  • Configure the plugin on your prj following the instructions on this page.
  • Thats all. You can now validate files manually or automatically: http://www.phpsrc.org/projects/pti-php-codesniffer/wiki/