phpcs, phpcbf and loose comparisons
This command fixes “Loose comparisons”: vendor/bin/phpcbf –standard=WordPress,Universal –sniffs=Universal.Operators.StrictComparisons admin.php
This command fixes “Loose comparisons”: vendor/bin/phpcbf –standard=WordPress,Universal –sniffs=Universal.Operators.StrictComparisons admin.php
The issue is that you’re attempting to store output of a method by reference to $starredgroup_products, which is not possible. This should fix it (untested): $starredgroup = $myPage->getGroup( $starredgroup ); $starredgroup_id = $starredgroup[‘groupid’]; $starredgroup_products = $myPage->getStarredProducts( $starredgroup_id );
I’d really like to get rid of the messages about coding style Despite not recommended, you can ignore/whitelist warnings and errors for a line or block of code using special PHPCS/WPCS comments which you can find here: Ignoring Parts of a File Whitelisting code which flags errors Working examples: ( Note: WordPress accepts all these … Read more
You can avoid using (new …)-> by using a static method, which creates the new instance internally. Combining this with the magic __toString method allows you to directly echo the created instance. Here is how to write it: <?php class Post_Share { /** * Using Post_Share::generate() will directly return the new instance, * so (new … Read more
As fuxia says, the most elegant way to adhere to the rule is to just not include that code. If a file is written properly then it’s not required to be safe. Keep in mind that PSR12 is just one set of standards, and WordPress and many plugins do not follow it. They are more … Read more
This is mostly just for readability. The semantics change before and after a parenthesis, and we are used to read spaces as word separators in western languages, so we can read such code faster. Another point is search: If you want to search for all changes on variables beginning with $post it is easier to … Read more
This coding style is known as a Yoda Condition, and it’s nothing specific to WordPress. I’ve used the same style in C++, C#, and even JavaScript code. The main benefit of a Yoda Condition is that it prevents accidental value assignment from a typo. Consider the following (often-seen-in-the-wild) typo: if ( $some_variable = 1 ) … Read more
What happen if the user don’t have capability to eat sandwich? WSOF? If I’d want to follow average default themes templates, I’d go for // eat-sandwich.php (as @Rarst said avoid wp-lunch.php as it’s not part of WP core) get_header( ‘sandwich’ ); if ( current_user_can( ‘eat_sandwich’ ) ) { get_template_part( ‘eat-sandwich’, ‘content’ ); } else { … Read more
Resoning Regarding “white space” (no matter if tabs or spaces): It’s simply a personal preference that stuck with the project. The WP coding standards imo are a mess and can be ignored – as long as you aren’t contributing to core, which is a different story and style guide gets ignored there as well. “[…] … Read more