Articles of coding standards

PHP Coding Standards, Widgets and Sanitization

I have an issue with custom widgets and WordPress Coding Standards. When you create a custom widget, your class should have a “widget” method that will display the widget. Something like: <?php public function widget( $args, $instance ) { echo $args[‘before_widget’]; ?> <span><?php echo esc_html( ‘Great widget’, ‘text-domain’ ); ?></span> <?php echo $args[‘after_widget’]; } ?> […]

How Flexible are the WordPress Coding Standards for PHPCS?

In my WordPress workflow I use Gulp and have a task that runs my PHP files through PHPCS using the WordPress coding standards tests ( While writing my comments.php file, I have run across the following error: Expected next thing to be an escaping function (see Codex for ‘Data Validation’), not ‘_x’ This is being […]

What is WordPress file encoding?

I noticed that WordPress files use UNIX end-of-line and UTF-8 without BOM. Is this a standard that should be used? Is there anything else to pay attention to? I noticed that Filezilla fails to transfer Macintosh end-of-line files properly to Windows or Linux servers. New line endings are missing. And sometimes they are doubled with […]

how to escape wp_oembed_get for phpcs

I am using phpcs to help with making sure I write nice, valid WP theme code but am coming across the following issue regarding escaping before output. If I try to use echo wp_oembed_get( ‘’ ); it works as expected – I get a nice youtube video on the page. BUT – phpcs throws an […]

What to do when theme and WordPress coding standards conflict?

I am considering different starter themes such as _s and roots. Roots looks very good, especially its sass fork. Anyway, there’s one thing that concerns me. It seems like Roots doesn’t follow the WordPress coding standards of themes and plugins. What standard do I then follow if I want to use Roots as a starter […]

Using global $post v/s $GLOBALS

It’s probably more of a PHP question, but I would like to know if there are any differences in using global $post; echo $post->ID; when compared to echo $GLOBALS[‘post’]->ID; to access the ID of a post in WordPress. This answer on SO suggests that the first method is quicker to process, while the second method […]

How should I document function calls?

Reading the WordPress PHP Documentation Standards, I can’t see anywhere that mentions how to document a function call such as add_action( ‘foo’, ‘bar’ ); Should I be documenting function calls and, if so, how?

Why does WordPress reverse conditional statements?

In WordPress’ core code, you often see this: if (1 == $someVar) as opposed to this: if ($someVar == 1) I don’t know if the first way is a WordPress-centric style of coding, but I’ve only noticed it in WP code (either core or 3rd-party code).

WordPress and event-driven programming – what is it about?

I want to state very clearly that this does not intend to revive the discussion about functional/procedural programming versus object-oriented programming. There is plenty said about that, on WPSE and all over the net. But a while ago I’m reading over some of the discussions about the programming foundations of WordPress and I read something […]

Actions, functions and conditionals

When developing themes and plugins it is sometimes neccesary to add some functionality to some hook using conditional statements. Example: function my_custom_function() { if( is_home()) { <—what should the function do—> } } add_action( ‘some_hook’, ‘my_custom_function’ ); To my understanding, whenever any other condition exists (is_home return false), the content of the function is not […]