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.NonSingularStringLiteralText] The $text arg must be a single string literal, not "ADDRESS". The following, for aforementioned error, also don't work: <?php esc_html_e( (string)ADDRESS, 'wprig' ); ?> <?php esc_html_e( strval(ADDRESS), 'wprig' ); ?> <?php esc_attr_e( ADDRESS, 'wprig' ); ?> I know constants can be exploited so it is needed. Any way to make this work …
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 when i'm verifying a nonce while saving metabox data: $nonce = isset( $_POST['revv_meta_box_nonce'] ) ? $_POST['revv_meta_box_nonce'] : ''; The error i'm getting here is 'Processing data without nonce verification'. Which is pretty silly since i'm just storing the nonce in …
I'm working on implementing WordPress coding standards on a theme which has several custom post-types, each of which have underscores in their handles. The theme uses the custom post-type handle in the file-names, eg: archive-my_posttype.php for the my_posttype post-type... But WordPress coding standards require that filenames use hyphens and not underscores, ( see WordPress.Files.FileName.NotHyphenatedLowercase for more info ) I've changed the file-name of the archive-template to archive-my-posttype.php but I'm apprehensive because I remember this behavior didn't exist previously. example: register_post_type( …
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 handles the call from PayFast to tell Give the order was Completed */ function payfast_ipn() { $give_options = give_get_settings(); if ( isset( $_REQUEST['m_payment_id'] ) ) { if ( give_is_test_mode() ) { $pf_host = 'https://sandbox.payfast.co.za/eng/query/validate'; give_insert_payment_note( $_REQUEST['m_payment_id'], 'ITN callback has been triggered.' ); } else { $pf_host = …
Trying to set up PHP_CodeSniffer with the WordPress Codings Standards. I'm running PHP v8.0.3 and phpcs v3.5.8. (in March 2021). WPCS is installed via git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs The installation worked, but running phpcs leads to this error: phpcs: Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, string given in file.php This is apparently an issue with WPCS and fixed in this commit. The commit seems to be not merged into master yet, so I …
Background I'm building a project that according to the specifications need to follow the WordPress Coding Standards. I am using phpcs to scan my code. If I try to pass $_POST-data into a function without sanitizing it, I will get an error. What I do before my code: Verify that this is actually a POST request by checking that $_POST is set. Verify that we have a value by checking if $_POST['faq_highlighted'] is set. Verify the nonce field using wp_verify_nonce …
I found the following code and tested it on my site. Works fine. But im not sure if the code is up to date because the last few years so much has changed on wordpress. Thx for your feedback and optmization suggestions. // Show only default posts related to current user - https://wordpress.stackexchange.com/a/34788/132453 add_action('pre_get_posts', 'query_set_only_author' ); function query_set_only_author( $wp_query ) { global $current_user; if( is_admin() && !current_user_can('edit_others_posts') ) { $wp_query->set( 'author', $current_user->ID ); add_filter('views_edit-post', 'fix_post_counts'); } } // Fix post …
I have a few plugins that start something like this: namespace MyPlugin; // If this file is called directly, abort. if (! defined('WPINC')) { die; } /** * Define Constants * */ define(__NAMESPACE__ . '\NS', __NAMESPACE__ . '\\'); Now that I'm finally getting around to using PHP_Codesniffer to implement some PSR12 standards, I'm getting a warning: A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, …
After changing the theme to Twenty Twenty-One, I have a bug with custom containers from various block plugins. In particular, custom blocks should have a class ending with inner-container (which I will call as a class family) at the direct parent div of the content. I understand this is a recommended standard from WordPress, and the plugins' authors should follow. However, the fact that those plugins don't have this class family at the first place and still working with other …
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) Returning an Error Object (extension of WP_Error) Just return null/false Some situations that I'm considering Trying to get/set an option stored in the Registry that doesn't exist Passing an invalid value to a method (which should be rare) Calling a method that the class' overloader cannot resolve to …
I'm developing a rather extensive plugin which has a lot of hooks that are prefixed with the plugin namespace. I have created a wrapper class like the one below but because this plugin is geared towards developers I want it to adhere to WordPress standards (coding and documentation) as best as possible. Are the below examples recommended? If not, is there a more "WordPress" way of doing this or should I just stick to hardcoding the prefix in every hook? …
How do you escape these two examples? wc_price() wraps the already escaped $product_price in p and span tags with currency symbol. $product_price = $product->get_price(); <p><?php echo wc_price( esc_html( $product_price ) ); ?></p> The next one outputs the complete image with all attributes: src, srcset, alt, etc. $product_img = $product->get_image(); <?php echo $product_img; ?>
As a plugin developer, I strive for coding plugins that take as less server resources as possible. That's why I thought of avoiding to repeat queries to the database that are run on the same request (non-persitent). Let's say my plugin has a function/class that needs to retrieve a setting from the options table (using the get_option WP core function). And that I know that same value will be needed by another function/class that will be run sometime after (within …
I am working on a large WordPress Plugin. It has already more than 10'000 lines of code (PHP + Javascript) and must be changed to yoda conditions, for matching the coding standards of WordPress. Is there a program or an online tool that converts the code (Javascript + PHP) automatically to yoda conditions?
The Wordpress coding standards states to put spaces both inside and outside opening and closing parenthesis. What is the rationale behind spaces on the inside of parenthesis? I've hardly ever seen that in any other code except PHP.
I'm rewording this because, as it's correctly been pointed out, the original post was "woefully inadequate." I made a plugin which has tabbed views for the various settings. It's based on this Wordpress Plugin Template. The template uses the WP Settings API to construct the settings page and display the tabs. The form uses the default _wpnonce for the submit/save settings button. The tabs are link elements that alter the page URL query string, e.g., from /wp-admin/options-general.php?page=my_plugin_settings&amp;tab=tab_1 to /wp-admin/options-general.php?page=my_plugin_settings&amp;tab=tab_2. The …
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. I'm thinking of using PHP namespaces, but I'm worried that there might be a reason why I shouldn't. Are namespaces compatible with WordPress and Envato's coding standards? Can I use namespaces in the PHP versions that I should be supporting? Are there any professional …
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 not true. I am using a custom function wp_my_own_link_pages() which is a replacement for wp_link_pages(). It generates pagination with a compatible HTML structure for the theme. Did I miss something required? How can I make this work?
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 to me or am I doing the assignments wrong?