<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>coding standards Archives - Alexandros Georgiou</title>
	<atom:link href="https://www.alexgeorgiou.gr/tag/coding-standards/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.alexgeorgiou.gr/tag/coding-standards/</link>
	<description>Balancing brackets for a living</description>
	<lastBuildDate>Mon, 22 Apr 2024 10:19:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.alexgeorgiou.gr/wp-content/uploads/2021/07/cropped-alexgeorgiou-icon-32x32.png</url>
	<title>coding standards Archives - Alexandros Georgiou</title>
	<link>https://www.alexgeorgiou.gr/tag/coding-standards/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>💩 Please, WordPress theme and plugin developers, learn to write proper HTML already&#8230; smh</title>
		<link>https://www.alexgeorgiou.gr/how-to-html-in-wordpress/</link>
					<comments>https://www.alexgeorgiou.gr/how-to-html-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[alexg]]></dc:creator>
		<pubDate>Fri, 07 Feb 2020 17:28:38 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[ARIA]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[code style]]></category>
		<category><![CDATA[coding standards]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[microformats]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[output buffering]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[schema.org]]></category>
		<category><![CDATA[string interpolation]]></category>
		<category><![CDATA[templating]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://www.alexgeorgiou.gr/?p=303</guid>

					<description><![CDATA[<p>Use PHP output buffering in WordPress to interpolate HTML code and dynamic values in a way that's more readable.</p>
<p>The post <a href="https://www.alexgeorgiou.gr/how-to-html-in-wordpress/">💩 Please, WordPress theme and plugin developers, learn to write proper HTML already&#8230; smh</a> appeared first on <a href="https://www.alexgeorgiou.gr">Alexandros Georgiou</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I know, I know, I&#8217;ve <a href="https://www.alexgeorgiou.gr/wordpress-php-code-quality/">ranted before about code quality</a>, but today I want to focus more on how we, as WordPress theme and plugin developers, write HTML.</p>



<h2 class="wp-block-heading">Don&#8217;t print out too early</h2>



<p>We&#8217;ve all been there: You&#8217;ve happily opened your PHP tag, <code>&lt;?php</code>, at the beginning of the file, at character #1. Your file is going to contain only code, no markup. Perhaps the file is included before any HTML output has even begun.</p>



<p>Being the savvy PHP developer that you are, you know all too well, that if your code were to output even one extra white-space, that would screw up the page&#8217;s markup. You&#8217;re careful not to use any closing <code>?&gt;</code> tag at the end of the file, to avoid any mishaps. Even a stray linefeed character could trigger output buffering early, and then out goes any chance for other code to modify the HTTP response headers, among other things.</p>



<p>So now you&#8217;re happily defining your functions, classes and other code-y stuff, then all of a sudden, you need to build some markup! Perhaps you&#8217;re printing out a UI element, maybe it&#8217;s a widget, maybe it&#8217;s a shortcode, maybe it&#8217;s even an RSS feed or other XML, but in any case, it&#8217;s too small for you to define an entire <a rel="noreferrer noopener" aria-label="template-part (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/get_template_part/" target="_blank">template-part</a>. Your string is going to be some concatenation of hard-coded markup and dynamic data that&#8217;s currently sitting in variables.</p>



<h2 class="wp-block-heading">How To Meet Ladies</h2>



<p>Everyone says they know HTML. But HTML is easy to get started with, and hard to master.</p>



<p>When writing HTML markup for a theme or plugin in WordPress, your professional-grade code must fulfill a number of simultaneous requirements. Your main concerns should be to:</p>



<ul class="wp-block-list"><li>Write correct HTML5 markup that is SEO friendly, using semantic tags where possible (e.g. <code>&lt;nav&gt;</code>, <code>&lt;article&gt;</code>, <code>&lt;aside&gt;</code>, etc).</li><li>Escape any values properly</li><li><a href="https://www.alexgeorgiou.gr/make-pot-wordpress/">Internationalize strings so they can be translated</a></li><li>Give unique IDs to your elements, and name your classes properly, to assist any CSS and JS assets that go with your markup. Remember, naming things is one of the two hard things in computer science!</li><li>Conform to the <a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/html/" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">WordPress HTML Coding Standards</a>. This is a good standard to follow, because it forces you to be consistent about how to open and close your PHP tags, among other things.</li><li>Depending on use case, optionally add semantic metadata, such as <a rel="noreferrer noopener" href="http://microformats.org/" target="_blank">microformats.org</a>, <a rel="noreferrer noopener" href="https://schema.org/" target="_blank">schema.org</a>, <a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://ogp.me/" target="_blank">Open Graph</a>, <a rel="noreferrer noopener" href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA" target="_blank">ARIA</a>, etc</li></ul>



<h2 class="wp-block-heading">A concrete example</h2>



<p>So let&#8217;s say you want to output some HTML form when a shortcode is used. We&#8217;ll give the form a unique ID and we&#8217;ll also embed some default values, coming from the shortcode&#8217;s attributes.</p>



<h3 class="wp-block-heading">Don&#8217;t do this:</h3>



<p>You might be tempted to do the following:</p>



<pre class="wp-block-preformatted"><code>$id = uniqid( 'form' );</code>
<code>$html  = '&lt;form id="' . esc_attr( $id ) . '"&gt;';</code>
<code>$html .= '&lt;input type="text" name="name" placeholder="' . esc_attr( 'Enter your name', 'langdomain' ) . '" value="' . esc_attr( $atts['name'] ) . '" /&gt;';</code>
<code>$html .= '&lt;input type="number" name="age" placeholder="' . esc_attr( 'Enter your age', 'langdomain' ) . '" value="' . absint( $atts['age'] ) . '" /&gt;';</code>
<code>$html .= '&lt;button type="submit"&gt;' . esc_html( 'Submit', 'langdomain' ) . '&lt;/button&gt;';</code>
<code>$html .= '&lt;/form&gt;';</code></pre>



<p>Sadly, a lot of people would say this is fine! I can&#8217;t blame them too much. We&#8217;re all way too used to opening the PHP tag and then never closing it again: we tend to use PHP as if it was Java. And with so many PHP templating libraries out there, it&#8217;s hard to remember that PHP <em>is</em> primarily a templating tool.</p>



<h3 class="wp-block-heading">Do this instead:</h3>



<p>We can combine the awesome templating power of the language with some cleverly nested <a rel="noreferrer noopener" aria-label="output bufferin (opens in a new tab)" href="https://www.php.net/manual/en/book.outcontrol.php" target="_blank">output buffering</a>, and now the above can be re-written as follows:</p>



<pre class="wp-block-preformatted"><code>$id = uniqid( 'form' );</code>

<code>ob_start();</code>
<code>?&gt;</code>
<code>&lt;form id="&lt;?php esc_attr_e( $id ); ?&gt;"&gt;</code>

    <code>&lt;input type="text" name="name" placeholder="&lt;?php esc_attr_e( 'Enter your name', 'langdomain' ); ?&gt;" value="&lt;?php esc_attr_e( $atts['name'] ); ?&gt;" /&gt;</code>
    <code>&lt;input type="number" name="age" placeholder="&lt;?php esc_attr_e( 'Enter your age', 'langdomain' ); ?&gt;" value="&lt;?php esc_attr_e( $atts['age'] ); ?&gt;" /&gt;</code>

    <code>&lt;button type="submit"&gt;&lt;?php esc_html_e( 'Submit', 'langdomain' ); ?&gt;&lt;/button&gt;</code>
<code>&lt;/form&gt;</code>
<code>&lt;?php</code>
<code>return ob_get_clean();</code></pre>



<p>To see a somewhat more complete example, here&#8217;s the above as a gist:</p>



<script src="https://gist.github.com/alex-georgiou/2299b24680e4fe5258ac0285044b8e56.js"></script>



<p>Notice how we start a new output buffer with <code><a rel="noreferrer noopener" aria-label="ob_start() (opens in a new tab)" href="https://www.php.net/manual/en/function.ob-start.php" target="_blank">ob_start()</a></code> and how we then get the resulting string with <code><a rel="noreferrer noopener" aria-label="ob_get_clean() (opens in a new tab)" href="https://www.php.net/manual/en/function.ob-get-clean.php" target="_blank">ob_get_clean()</a></code>. Notice also how we&#8217;ve swapped <code><a rel="noreferrer noopener" aria-label="esc_html() (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/esc_html/" target="_blank">esc_html()</a></code> with <code><a rel="noreferrer noopener" aria-label="esc_html_e() (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/esc_html_e/" target="_blank">esc_html_e()</a></code> and <code><a rel="noreferrer noopener" aria-label="esc_attr() (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/esc_attr/" target="_blank">esc_attr()</a></code> with <code><a rel="noreferrer noopener" aria-label="esc_attr_e() (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/esc_attr_e/" target="_blank">esc_attr_e()</a></code>. Similarly, we would swap <code><a rel="noreferrer noopener" aria-label="sprintf() (opens in a new tab)" href="https://www.php.net/manual/en/function.sprintf.php" target="_blank">sprintf()</a></code> with <code><a rel="noreferrer noopener" aria-label="printf (opens in a new tab)" href="https://www.php.net/manual/en/function.printf.php" target="_blank">printf</a>()</code>, <code><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/checked/" target="_blank">checked( $value, true, false )</a></code> with <code>checked( $value, true )</code>, and so on.</p>



<p><strong>PRO TIP:</strong> If your code throws an exception, you can use <code><a rel="noreferrer noopener" aria-label="ob_end_clean() (opens in a new tab)" href="https://www.php.net/manual/en/function.ob-end-clean.php" target="_blank">ob_end_clean()</a></code> in your <code>catch</code> clause to cancel your buffer.</p>



<h2 class="wp-block-heading">&#8220;Why does it even matter&#8221;, you ask?</h2>



<p>Well, there&#8217;s a few advantages with the second form of our, err&#8230;, form!</p>



<ul class="wp-block-list"><li><strong>Readability.</strong> I find the second piece of code to be much more readable.</li><li><strong>Syntax coloring.</strong> Yes, some editors do perform HTML parsing and show visual queues related to the syntax of HTML inside strings. But not every editor does this, and the ones that do, cannot do this perfectly.</li><li><strong>No quote hell.</strong> No need to count opening and closing <code>'</code> characters, interpolated with <code>"</code> characters while printing HTML attributes. This business can quickly get confusing, and is a common source of errors.</li><li><strong>Show off</strong> your mad PHP output buffering skillz! Your average front-end developer will be astonished at your professional-looking code!</li></ul>



<p>Now, if only we were allowed to use shorthand PHP tags, our code could be even nicer. Sadly, <a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#no-shorthand-php-tags" target="_blank">we can&#8217;t</a>.</p>



<p><code>?&gt;</code></p>
<p>The post <a href="https://www.alexgeorgiou.gr/how-to-html-in-wordpress/">💩 Please, WordPress theme and plugin developers, learn to write proper HTML already&#8230; smh</a> appeared first on <a href="https://www.alexgeorgiou.gr">Alexandros Georgiou</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.alexgeorgiou.gr/how-to-html-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>☑ WordPress checklists to go through before publishing a theme or plugin</title>
		<link>https://www.alexgeorgiou.gr/wordpress-checklists-publish-theme-plugin/</link>
					<comments>https://www.alexgeorgiou.gr/wordpress-checklists-publish-theme-plugin/#respond</comments>
		
		<dc:creator><![CDATA[alexg]]></dc:creator>
		<pubDate>Mon, 07 Nov 2016 11:48:55 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[checklist]]></category>
		<category><![CDATA[codecanyon]]></category>
		<category><![CDATA[coding standards]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[envato]]></category>
		<category><![CDATA[publish]]></category>
		<category><![CDATA[quality assurance]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[themeforest]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress.org]]></category>
		<guid isPermaLink="false">http://www.alexgeorgiou.gr/?p=142</guid>

					<description><![CDATA[<p>In this meta-article I will list eight WordPress checklists and a book that you will want to go through, before you publish a theme or plugin.</p>
<p>The post <a href="https://www.alexgeorgiou.gr/wordpress-checklists-publish-theme-plugin/">☑ WordPress checklists to go through before publishing a theme or plugin</a> appeared first on <a href="https://www.alexgeorgiou.gr">Alexandros Georgiou</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this meta-article I will list <em>eight WordPress checklists</em> and a book that you will want to go through, before you publish a theme or plugin. So before committing to the <em>wordpress.org</em> SVN or uploading to <em>Envato</em>, bookmark this page and start double-checking all the resources listed here!</p>
<h2><a title="Read 'Ten Things Every WordPress Plugin Developer Should Know'" href="https://www.smashingmagazine.com/2011/03/ten-things-every-wordpress-plugin-developer-should-know/" target="_blank" rel="bookmark noopener noreferrer">Ten Things Every WordPress Plugin Developer Should Know</a></h2>
<p>Actually you&#8217;ll probably want to read this before even starting your project; but better late than never! It&#8217;s packed with essential info that you should know. If you&#8217;ve missed any of the info in this article, go back to your code and fix it. There&#8217;s stuff about common practices, coding standards, etc.</p>
<h2 class="handbook-page-title"><a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/" target="_blank" rel="noopener noreferrer">PHP Coding Standards</a></h2>
<p>This is a list of PHP coding standards that WordPress developers follow, both in core and in themes and plugins. It&#8217;s a requirement for submission to <em>wordpress.org</em> but it would be really nice to follow as many of these as possible even if you&#8217;re not planning to submit your code there.</p>
<p>Ideally you&#8217;ll want to use some tools for this. A quick search on <em>GitHub</em> reveals a number of syntax checkers. Here&#8217;s one that I use with <em>Eclipse</em>: <a href="https://github.com/edpittol/wordpress-eclipse-formatter" target="_blank" rel="noopener noreferrer">https://github.com/edpittol/wordpress-eclipse-formatter</a>, and another one for <em>CodeSniffer</em> (which can integrate nicely with a number of IDEs): <a href="https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards" target="_blank" rel="noopener noreferrer">https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards</a>.</p>
<p>Whatever you use, it doesn&#8217;t hurt to double check your code one last time. In <em>Eclipse Formatter</em> for instance, there is no way to check for <a href="https://en.wikipedia.org/wiki/Yoda_conditions" target="_blank" rel="noopener noreferrer">&#8220;Yoda&#8221; conditions</a> as far as I know, so you&#8217;ll want to manually check for those if you&#8217;re using it.</p>
<h2 class="handbook-page-title"><a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/">JavaScript Coding Standards</a></h2>
<p>Have you checked your PHP code for compliance to the coding standards? Good! Get ready to do it again, this time for your JavaScript files; at least the unminified copies of them. Here&#8217;s a project that uses <em>ESLint</em> to help you enforce the standards: <a href="https://www.npmjs.com/package/eslint-plugin-wordpress" target="_blank" rel="noopener noreferrer">https://www.npmjs.com/package/eslint-plugin-wordpress</a>. If you have a lot of JavaScript in your code, it might pay to integrate this into your pre-build checks, but as with PHP, always have one last look using your eyeballs.</p>
<h2><a href="https://wordpress.org/plugins/about/" target="_blank" rel="noopener noreferrer">WordPress plugins</a></h2>
<p>If you&#8217;re writing a plugin, this is a short list of conditions that your project must meet before you publish to <em>WordPress.org</em>. It has more to do with functionality than standards, and essentially it&#8217;s about not being evil with your code.</p>
<h2><a href="https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/" target="_blank" rel="noopener noreferrer">Detailed Plugin Guidelines</a></h2>
<p>This is essentially a longer version of the above. A definite must read if you&#8217;re publishing to <em>WordPress.org</em>. It&#8217;s about licensing, versioning, what you can and can&#8217;t do, etc.</p>
<h2 id="theme-review-process" class="toc-heading" tabindex="-1"><a href="https://make.wordpress.org/themes/handbook/review/#theme-review-process" target="_blank" rel="noopener noreferrer">Theme Review Process</a></h2>
<p>If you&#8217;re writing a theme that you plan to publish to <em>WordPress.org</em>, check that it at least conforms to all the <a href="https://make.wordpress.org/themes/handbook/review/required/" target="_blank" rel="noopener noreferrer">required items</a> and try to conform to as many <a href="https://make.wordpress.org/themes/handbook/review/recommended/" target="_blank" rel="noopener noreferrer">recommended items</a> as possible. The write-up for the recommended guidelines is not complete as of the writing of this article, but there&#8217;s some very useful guidelines in there.</p>
<h2><a href="https://codex.wordpress.org/Theme_Unit_Test" target="_blank" rel="noopener noreferrer">Theme Unit Test</a></h2>
<p>Again, if you&#8217;re writing a theme for <em>WordPress.org</em>, you will also want to check a number of things against the provided <a href="https://codex.wordpress.org/Theme_Unit_Test" target="_blank" rel="noopener noreferrer">Theme Unit Test</a>. It&#8217;s probably a good idea to do this even if you&#8217;re publishing elsewhere.</p>
<h2><a href="https://help.market.envato.com/hc/en-us/articles/202500774-ThemeForest-General-File-Preparation-Guidelines" target="_blank" rel="noopener noreferrer">ThemeForest General File Preparation Guidelines</a></h2>
<p>If you&#8217;re publishing to <em>ThemeForest</em>, you will have to follow these guidelines on how to bundle your files.</p>
<h2><a href="https://help.market.envato.com/hc/en-us/articles/202501494-WordPress-Phase-1-Submission-Requirements-Q-A" target="_blank" rel="noopener noreferrer">WordPress Phase 1 Submission Requirements &#8211; Q&amp;A</a></h2>
<p>This is a list of guidelines to follow before submitting to <em>ThemeForest</em>. There&#8217;s a number of things listed that are not allowed, so make sure to check.</p>
<h2><a href="https://help.market.envato.com/hc/en-us/articles/203269650-A-step-by-step-guide-to-the-upload-process" target="_blank" rel="noopener noreferrer">A step-by-step guide to the upload process</a></h2>
<p>When uploading to <em>ThemeForest</em>, you will also want to follow these guidelines. They are mostly about the upload process but also include some information about how to bundle your files.</p>
<h2>Professional WordPress: Design and Development</h2>
<p><a style="width: 120px; height: 240px; float: right; margin-left: 1em;" href="https://amzn.to/3W4EePm" width="300" height="150"><br />
<img decoding="async" src="https://m.media-amazon.com/images/I/71OD8C2NZNL._SY466_.jpg" /><br />
</a><br />
Finally, this is a book, not an actual checklist, but still I recommend that you at least glance through the table of contents. I&#8217;ve found this book very helpful. It covers all topics related to WordPress development and it&#8217;s very likely that whatever it is you&#8217;re trying to do, there might be a better way of doing it. WordPress is a complex system and it&#8217;s only getting more complex by the day.</p>
<p>My recommendation is that you go through the table of contents and read any chapter that talks about things you do in your theme or plugin. There are things you might have missed.</p>
<div style="clear: right;"></div>
<hr />
<p>Too meta? Perhaps! But no matter what and where you&#8217;re publishing, if you want to be professional about it, don&#8217;t assume you know everything. At least glance through all of these guidelines.</p>
<p>The post <a href="https://www.alexgeorgiou.gr/wordpress-checklists-publish-theme-plugin/">☑ WordPress checklists to go through before publishing a theme or plugin</a> appeared first on <a href="https://www.alexgeorgiou.gr">Alexandros Georgiou</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.alexgeorgiou.gr/wordpress-checklists-publish-theme-plugin/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
