Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [coding-standards]

The tag has no usage guidance.

-1
votes
0answers
20 views

Use placeholders and $wpdb->prepare(); found interpolated variable $select

Currently have this fucntion which is throwing out a validation error on Travis: Use placeholders and $wpdb->prepare(); found interpolated variable $select at "SELECT {$select} FROM {$from} WHERE {$...
0
votes
2answers
20 views

Assignments must be the first block of code on a line Validation Error on Travis

Travis is giving me ~ Assignments must be the first block of code on a line for this specific line of code: $validate_string = $pf_param_string = substr( $pf_param_string, 0, - 1 ); It seems fine ...
0
votes
1answer
39 views

WP nonce verification

I'm busy testing out the plugin through Travis and the only issues remaining are: Processing form data without nonce verification It seems to be relating to this action: /** * An action that ...
0
votes
0answers
16 views

Should I check for privileges before hooking into `wp_ajax_$handle` or after?

Should I heck for privileges before even hooking the wp_ajax_hook_name or in the function that I've hooked to it? The first way: if( current_user_can( 'manage_options' ) ) { add_action( '...
0
votes
1answer
99 views

Translate a Constant while appeasing WordPress PHPCS

The following works but isn't up to snuff with PHP Code Sniffer WordPress coding standards <?php esc_html_e( ADDRESS, 'wprig' ); ?> Linter yells at me with: [WordPress.WP.I18n....
0
votes
1answer
20 views

Standard technique for AJAX post endpoint: WP REST or WP API?

I need to create a post endpoint for a contact form that any user (not just logged in users) can use. The post is made via AJAX/REST. Is the industry standard way to do this via a new WP REST ...
1
vote
2answers
174 views

PHPCS: Strings should have translatable content

I am validating plugin to make it compatible with WPCS. a function which contains gettext placeholder returning error when i run phpcs command. Source code and screenshot of error is attached for ...
0
votes
1answer
14 views

How could I better initialize a method from my class?

I have this class that generates some share links: <?php class Post_Share { /** * Class to add post-sharing capabilities to each post. It has to be initialized within a post page. */ ...
1
vote
0answers
25 views

Add comments for template variables

I am writing a small plugin that uses a custom template to render content. The plugin uses extract() to add variables that can be used inside the template. I was wondering if there is a standard for ...
0
votes
1answer
257 views

Class or function wrapper for plugin code

When developing plugins, to avoid using a prefix for all functions and variables, it is common to use a wrapper for the plugin code. I have seen in many places the practice of using a class and I want ...
1
vote
1answer
164 views

Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?

I am a real fan of the Allman (BSD) coding indent style. However, when i review the top rated plugins on WordPress, i am finding them using the K&R coding indent style. Is there a requirement ...
1
vote
2answers
628 views

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 ...
4
votes
1answer
261 views

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( 'https://www....
1
vote
0answers
39 views

What's the best practice way of handling custom fields in different post formats?

I am developing a theme that is compatible multiple post formats (video, audio, gallery, status, quote, etc.) From the perspective of a theme developer, what is the best practice way of handling ...
2
votes
2answers
437 views

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 (https://github.com/WordPress-Coding-Standards/WordPress-Coding-...
8
votes
1answer
758 views

When to use Exceptions vs Error Objects vs just plain false/null

I'm in the process of writing a plugin and I'm trying to gauge when to use different approaches of handling errors. There are three methods I'm considering: Throwing an Exception (custom class) ...
0
votes
1answer
233 views

PHP Code Sniffer - WordPress VIP Coding Standards

I'm trying to fix up my code to meet the WordPress VIP Coding Standards. I'm getting a couple of issues that I'd like to see go away, but i'm not sure what the best strategy is. The first issue is ...
0
votes
2answers
108 views

Can I use namespaces in my plugin?

I am building a plugin that I hope to eventually put on Envato CodeCanyon. Currently I am creating functions of the form mypluginname_action. This is quickly becoming silly as I have to do that a lot....
0
votes
1answer
30 views

Do define() statements need phpDocumentor-style docblocks?

There's no word on this in the WordPress Documentation Standards, but do define() statements need phpDocumentor-style docblocks? /** * Should this docblock be here? * * @since 1.0.0 */ define( '...
1
vote
1answer
756 views

Avoiding “Usage of a direct database call is discouraged”

WordPress-Coding-Standards reports that "Usage of a direct database call is discouraged." It's complaining about my usage of $wpdb->insert() in a plugin. Is this not recommended? What is the ...
0
votes
1answer
199 views

Sanitization html output itself

I've just started code according to VIP WordPress Coding Standards and I stuck with sanitization. I know that all outputs need sanitization without any exception. But how can I do sanitization of a ...
0
votes
1answer
72 views

Why the WP Core team does not allow filter_* functions? [closed]

This question is somehow related to this other question. Provided that is seems we have a solution for the magic quotes issues, why the WP Core team does not allow them? This is unclear to me and I ...
5
votes
2answers
328 views

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, ...
22
votes
2answers
2k views

Why is Wordpress code so “space-happy”?

The WP core, many WP plugins, and the WP coding standards themselves use a very "generous application" of the Space character (not for indentation, but "inside" of parens and brackets). This seems to ...
8
votes
4answers
1k views

How to name files of namespaced classes?

WP Core Handbook > PHP Coding Standards > Naming Conventions suggests the following for naming files with classes: Class file names should be based on the class name with class- prepended and the ...
1
vote
0answers
83 views

What make possible unit test plugins?

This is more a theory related question. I'm not looking at the practical ways to do this, as I can find plenty of example (official and not), which however does not explain how it is possible to ...
3
votes
2answers
200 views

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 ...
7
votes
5answers
639 views

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()) { ...
8
votes
3answers
752 views

Sandwich Coding Standards

I recently spotted the code for a wp-lunch.php file intended for a WordPress template, what would this look like if following the proper WordPress coding standards? <?php if ( current_user_can('...
7
votes
4answers
1k views

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 ...
0
votes
2answers
435 views

Wordpress Theme Validator?

I'm looking for a Wordpress theme Validator. Not necessarily something that validates the HTML but more along the lines of adhering to the Wordpress Coding Standards for Theme Development.
2
votes
2answers
2k views

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 ...
0
votes
1answer
47 views

Is there a common structure for a wordpress formular?

I am working on a plugin for wordpress and was wondering if there is any common standard for the html and css structure and naming which I should use if I create a html form? so is there a definition ...
0
votes
1answer
734 views

spaces inside parenthesis

The Wordpress coding standards states to put parenthesis both inside and outside opening and closing parenthesis. What is the rationale behind spaces on the inside of parenthesis? I've hardly ever ...
1
vote
2answers
1k views

REQUIRED: Could not find wp_link_pages. See: wp_link_pages by Theme Checker

I have run my theme through WordPress theme checker to see if it can be submitted to WordPress.org. I encountered this error: REQUIRED: Could not find wp_link_pages. See: wp_link_pages But this is ...
6
votes
1answer
529 views

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 ...
4
votes
1answer
2k views

Using global $post v/s $GLOBALS['post']

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 ...
12
votes
1answer
423 views

Why isn't WordPress part of Framework Interop Group?

Are there any technical reasons that prevent WP to be part of Framework Interop Group?
1
vote
1answer
82 views

Is it better to create a function or a variable for current_theme_supports?

Well I just asking myself this, there are two ways I could implement this. What would be a better fit to coding standards? Or is this just a a matter of personal like? And what about php and memory, ...
1
vote
1answer
488 views

WordPress mode for emacs?

Is anyone using emacs for editing WordPress and have a mode that follow the code style guidelines that they would care to share? If so I would appreciate it. Thanks.