<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Prateek Saxena</title>
    <description>The latest articles on DEV Community by Prateek Saxena (@prtksxna).</description>
    <link>https://dev.to/prtksxna</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F394058%2F8d266a83-b385-4193-96a6-67afbd4c85de.jpeg</url>
      <title>DEV Community: Prateek Saxena</title>
      <link>https://dev.to/prtksxna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prtksxna"/>
    <language>en</language>
    <item>
      <title>How to find date and time in text?</title>
      <dc:creator>Prateek Saxena</dc:creator>
      <pubDate>Mon, 04 Jan 2021 12:54:52 +0000</pubDate>
      <link>https://dev.to/winkjs/how-to-find-date-and-time-in-text-2dmi</link>
      <guid>https://dev.to/winkjs/how-to-find-date-and-time-in-text-2dmi</guid>
      <description>&lt;p&gt;Date and time, and other named entities can be extracted from a document using winkNLP. To do this, we’ll load a document and ask for its entities. We’ll then filter down to just the ones we need. If we want to get the Unix time from the text we can look at the &lt;a href="https://winkjs.org/wink-nlp/its-as-helper.html"&gt;shape&lt;/a&gt; and check if the text can directly be sent to the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;Date&lt;/a&gt; object to be parsed. Here is how we would find the date and time entities in a text using winkNLP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Load wink-nlp package &amp;amp; helpers.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;winkNLP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wink-nlp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;its&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wink-nlp/src/its.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wink-eng-lite-model&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nlp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;winkNLP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`The release happened on 21 August 2020 at 4:32 pm`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nlp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;its&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DATE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// -&amp;gt; 21 August 2020&lt;/span&gt;
    &lt;span class="c1"&gt;// -&amp;gt; Fri Aug 21 2020 00:00:00 GMT+0530 (India Standard Time)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;its&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TIME&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Time:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// -&amp;gt; Time:&lt;/span&gt;
    &lt;span class="c1"&gt;// -&amp;gt; 4:32pm&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would give you all the strings that contain dates or times, and the Unix time corresponding to it if the format allows it. You can now use the usual JavaScript functions like &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort"&gt;sort&lt;/a&gt; on this data structure to get the insights you need. For example our &lt;a href="https://winkjs.org/showcase-timeline/"&gt;Wikipedia Timeline&lt;/a&gt; showcase uses it to create visualizations of articles.&lt;/p&gt;

&lt;p&gt;Raw texts may contain many &lt;a href="https://winkjs.org/wink-nlp/entities.html"&gt;named entities&lt;/a&gt; like time, money, and hashtags. The &lt;a href="https://github.com/winkjs/wink-eng-lite-model"&gt;English language lite model&lt;/a&gt; for winkNLP finds entities spanning multiple tokens by employing pre-trained finite state machine.&lt;/p&gt;

&lt;p&gt;Todo applications that automatically add due dates based on the text that was entered, or email clients that add events to your calendar based on time and location do this by using this form of named entity extraction. It can also be used to create a timeline of events based on raw text.&lt;/p&gt;

</description>
      <category>nlp</category>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Using gitattributes to make releasing WordPress themes easier</title>
      <dc:creator>Prateek Saxena</dc:creator>
      <pubDate>Fri, 24 Jul 2020 12:01:10 +0000</pubDate>
      <link>https://dev.to/prtksxna/using-gitattributes-to-make-releasing-wordpress-themes-easier-30c9</link>
      <guid>https://dev.to/prtksxna/using-gitattributes-to-make-releasing-wordpress-themes-easier-30c9</guid>
      <description>&lt;p&gt;Zuari releases have been &lt;a href="https://wordpress.org/themes/zuari/#theme-download-stats-zuari"&gt;few and far apart&lt;/a&gt; in the last year. While I work on Zuari often, I cut a release only when I know I’ll have time to fix things in case they break for someone. This has meant that I haven’t paid much thought to the release process. Till now, I would create a copy of the directory, go through my list of files to delete, delete them and create an archive to upload to &lt;a href="http://wordpress.org/"&gt;WordPress.org&lt;/a&gt;. As you can see this process is manual and error prone.&lt;/p&gt;

&lt;p&gt;While looking at &lt;a href="https://david.shanske.com/"&gt;David&lt;/a&gt;’s &lt;a href="https://github.com/dshanske/syndication-links"&gt;syndication-links&lt;/a&gt; repository I saw a &lt;a href="https://git-scm.com/docs/gitattributes"&gt;&lt;code&gt;.gitattributes&lt;/code&gt;&lt;/a&gt; file. I had seen it before but never looked into it. Turns out, that among other things, you can use it to define a list of files to ignore when creating a &lt;a href="https://git-scm.com/docs/git-archive#ATTRIBUTES"&gt;&lt;code&gt;git archive&lt;/code&gt;&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;So, I setup the following &lt;code&gt;.gitattributes&lt;/code&gt; file for my WordPress themes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Git
.gitignore export-ignore
.gitattributes export-ignore

# Styles
.sass-cache export-ignore
*.css.map export-ignore
**/*.scss export-ignore
.stylelintrc.json export-ignore

# Scripts
Gruntfile.js export-ignore
package.json export-ignore
package-lock.json export-ignore
node_modules export-ignore
.storybook export-ignore
.babelrc export-ignore

# Github
README.md export-ignore
.github export-ignore

# Composer
composer.json export-ignore
composer.lock export-ignore
vendor export-ignore
phpcs.xml.dist export-ignore
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now, to create the zip file for uploading on WordPress.org I simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git archive master -o theme-name.zip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;No more manual work, no more slips and mistakes.&lt;/p&gt;

&lt;p&gt;Releasing a theme (or any other package for that matter) requires quite a few steps. And if you don’t release often it’s easy to forget and miss something. For this reason, the most important thing in Zuari’s otherwise inadequate &lt;a href="https://github.com/prtksxna/zuari/#zuari"&gt;README&lt;/a&gt; are the &lt;a href="https://github.com/prtksxna/zuari/#release"&gt;release steps&lt;/a&gt;. Documentation is as important for our future-selves as it is for others.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;Cover photo by &lt;a href="https://unsplash.com/@catvcarvalho?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Catarina Carvalho&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/archive?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/small&gt;&lt;br&gt;
&lt;small&gt;This post was originally published at &lt;a href="https://prtksxna.com/gitattributes-releasing-wordpress-themes-easier/"&gt;prtksxna.com&lt;/a&gt;. &lt;/small&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>git</category>
    </item>
    <item>
      <title>Gutenberg editor color palettes for WordPress themes</title>
      <dc:creator>Prateek Saxena</dc:creator>
      <pubDate>Fri, 26 Jun 2020 09:11:25 +0000</pubDate>
      <link>https://dev.to/prtksxna/gutenberg-editor-color-palettes-for-wordpress-themes-4cjo</link>
      <guid>https://dev.to/prtksxna/gutenberg-editor-color-palettes-for-wordpress-themes-4cjo</guid>
      <description>&lt;p&gt;One of my favorite features of the Gutenberg block editor is the &lt;a href="https://developer.wordpress.org/block-editor/developers/themes/theme-support/#block-color-palettes"&gt;editor color palette&lt;/a&gt;. It allows themes to register a color palette that is shown in the block editor whenever a block needs to choose a color.&lt;/p&gt;

&lt;p&gt;Allowing the theme to have a say in the styling of the content of the post is a powerful idea. It helps guide the user’s design choices while still allowing them freedom to make changes. When working on &lt;a href="https://wordpress.org/themes/zuari/"&gt;Zuari&lt;/a&gt;, it was important for me to get this right since the theme is otherwise just black and gray. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FyEkuAlW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/luvajjcjj81f1j6j9dm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FyEkuAlW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/luvajjcjj81f1j6j9dm9.png" alt="Color palette for Zuari"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we have the colors picked and named (This can be tricky. What is ecru?) we need to let WordPress know that our theme would like to register a palette, and add our colors to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nx"&gt;add_theme_support&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'editor-color-palette'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Brick'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'zuari'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="s1"&gt;'slug'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'brick'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'color'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'#825A58'&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Baby Pink'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'zuari'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="s1"&gt;'slug'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'baby-pink'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'color'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'#E0BAC0'&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Ecru'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'zuari'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="s1"&gt;'slug'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'ecru'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'color'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'#E1D9D3'&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, we’ll need to add two CSS classes for each of these colors so that they can be used on the different blocks as background and foreground colors. The naming convention for these classes is has-{slug}-color and has-{slug}-background-color:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.has-brick-color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#825a58&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.has-baby-pink-color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e0bac0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.has-ecru-color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e1d9d3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.has-brick-background-color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#825a58&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.has-baby-pink-background-color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e0bac0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.has-ecru-background-color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e1d9d3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That’s it! This will add the color palette to the block inspector for any blocks that need color, and show the right colors in the website once they’re selected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dLlDjafD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qj55zktlft5smlz910i4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dLlDjafD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qj55zktlft5smlz910i4.png" alt="Block settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope that WordPress adds these &lt;a href="https://github.com/WordPress/gutenberg/issues/22296"&gt;colors as options&lt;/a&gt; in the &lt;a href="https://wptavern.com/conceptual-ideas-on-how-the-customizer-could-integrate-with-gutenberg"&gt;Customizer panels&lt;/a&gt; as well, allowing for more design guidance coming from the theme. I’ve been thinking about WordPress themes as design patterns and guidelines rather than skeletons for a website. I’ll be writing about this soon.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cover image by &lt;a href="https://unsplash.com/@carissaweiser"&gt;Carisse Weiser&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/oPI3Oxj_cEw"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was originally published on &lt;a href="https://prtksxna.com/gutenberg-color-palettes/"&gt;prtksxna.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>css</category>
      <category>colors</category>
    </item>
    <item>
      <title>Setting up WordPress’s PHP coding standards for your theme</title>
      <dc:creator>Prateek Saxena</dc:creator>
      <pubDate>Fri, 05 Jun 2020 12:28:06 +0000</pubDate>
      <link>https://dev.to/prtksxna/setting-up-wordpress-s-php-coding-standards-for-your-theme-442o</link>
      <guid>https://dev.to/prtksxna/setting-up-wordpress-s-php-coding-standards-for-your-theme-442o</guid>
      <description>&lt;p&gt;Setting up coding standards for your project is always a good idea. While it is ideal to start with one from the beginning, sometimes you have to do it after you’ve already written quite a bit of code (looks at &lt;a href="https://github.com/prtksxna/zuari/"&gt;Zuari&lt;/a&gt; 👀). Here is a quick guide on setting up the &lt;a href="https://github.com/WordPress/WordPress-Coding-Standards"&gt;WordPress PHP Coding Standards&lt;/a&gt; for your theme or plugin:&lt;/p&gt;

&lt;p&gt;For the purpose of this guide you’d need PHP and Composer installed locally, even if you are using &lt;a href="https://prtksxna.com/2018/10/03/docker-compose-for-local-wordpress-development/"&gt;docker for local development&lt;/a&gt;. We start by running &lt;code&gt;composer init&lt;/code&gt;. This sets up the &lt;code&gt;composer.json&lt;/code&gt; file and adds it to &lt;code&gt;.gitignore&lt;/code&gt;. Next to get the &lt;a href="https://github.com/squizlabs/PHP_CodeSniffer"&gt;phpcs&lt;/a&gt; and the &lt;a href="https://github.com/WordPress/WordPress-Coding-Standards"&gt;WordPress coding standards&lt;/a&gt;, we run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require squizlabs/php_codesniffer &lt;span class="nt"&gt;--dev&lt;/span&gt;
composer require wp-coding-standards/wpcs &lt;span class="nt"&gt;--dev&lt;/span&gt;
composer require dealerdirect/phpcodesniffer-composer-installer &lt;span class="nt"&gt;--dev&lt;/span&gt;
composer require phpcompatibility/php-compatibility &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, to make sure that things are set up correctly on a fresh install we’ll create scripts that’ll run automatically post install. You can read more about this in the &lt;a href="https://github.com/DealerDirect/phpcodesniffer-composer-installer#calling-the-plugin-directly"&gt;PHP_CodeSniffer standards composer installer plugin documentation&lt;/a&gt;. We’ll also add a script to actually run &lt;code&gt;phpcs&lt;/code&gt; from inside of &lt;code&gt;./vendor/bin&lt;/code&gt;, this will serve as a shorthand when we need it later. So in &lt;code&gt;composer.json&lt;/code&gt; we’ll add a new key called scripts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"lint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"phpcs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"install-codestandards"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Dealerdirect&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Composer&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Plugin&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Installers&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;PHPCodeSniffer&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Plugin::run"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"post-install-cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"@install-codestandards"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we try to run &lt;code&gt;composer run-script lint&lt;/code&gt; now it will start showing us a ton of linting errors. These might be a bit more than we actually need to resolve though, and that is because we haven’t yet defined which coding standard we’ll be following. To do this we’ll create a &lt;code&gt;phpcs.xml.dist&lt;/code&gt; file and copy over the contents from the &lt;a href="https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample"&gt;sample config file&lt;/a&gt; that the WordPress Coding Standards provides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ruleset&lt;/span&gt; &lt;span class="na"&gt;xmlns:xsi=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Your Project"&lt;/span&gt; &lt;span class="na"&gt;xsi:noNamespaceSchemaLocation=&lt;/span&gt;&lt;span class="s"&gt;"https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;A custom set of rules to check for a WPized WordPress project&lt;span class="nt"&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/docroot/wp-admin/*&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/docroot/wp-includes/*&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/docroot/wp-*.php&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/docroot/index.php&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/docroot/xmlrpc.php&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/docroot/wp-content/plugins/*&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/vendor/*&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;/node_modules/*&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclude-pattern&amp;gt;&lt;/span&gt;*.min.js&lt;span class="nt"&gt;&amp;lt;/exclude-pattern&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"WordPress-Docs"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"Generic.CodeAnalysis.UnusedFunctionParameter"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"Generic.Commenting.Todo"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;config&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"minimum_supported_wp_version"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"4.9"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"WordPress.WP.I18n"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;properties&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;property&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"text_domain"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"array"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;element&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"my-textdomain"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/property&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/properties&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/rule&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"WordPress.NamingConventions.PrefixAllGlobals"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;properties&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;property&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"prefixes"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"array"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;element&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"my_prefix"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/property&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/properties&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/rule&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/ruleset&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we just need to make some adjustments to this file based on our theme and preferences. Look at the &lt;code&gt;exclude-patterns&lt;/code&gt;, is there anything else that we should be excluding? Next, let’s make sure that the &lt;code&gt;minimum_supported_wp_version&lt;/code&gt; is set correctly. Finally, we’ll fix the &lt;code&gt;prefixes&lt;/code&gt; and &lt;code&gt;text_domain&lt;/code&gt; to use your theme name. Make sure you use “&lt;code&gt;-&lt;/code&gt;” for the &lt;code&gt;text_domain&lt;/code&gt; and “&lt;code&gt;_&lt;/code&gt;” for the &lt;code&gt;prefixes&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And that’s it 🎉 You should be ready to go! Running composer lint will show you all the places where you aren’t following WordPress’s coding standards. Take some time to clean up all the errors and warnings and &lt;a href="https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file"&gt;ignore&lt;/a&gt; the ones that you think aren’t appropriate. Marvel at your clean and beautiful code 😍&lt;/p&gt;

&lt;p&gt;The only thing left to do is to make sure that things stay nice and clean over time. Atom has a &lt;a href="https://atom.io/packages/linter-phpcs"&gt;package&lt;/a&gt; to see linting issues in the editor itself, and you can find and set one up for the editor of your choice. I would like to set this up on CI too, making sure something is looking at these errors even when I am not.&lt;/p&gt;

&lt;p&gt;(Photo by &lt;a href="https://unsplash.com/@otenteko"&gt;Anas Alshanti&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/feXpdV001o4"&gt;Unsplash&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>codequality</category>
    </item>
  </channel>
</rss>
