Using Alignment Package in Sublime Text 3

It is nice to see the code if it is aligned well. Check out below example of aligning and misaligned code.

Mis Aligned Code

$data = array(
    'one' => 'One',
    'two' => 'two',
    'three' => 'Three',
    'four' => 'Four',
    'five' => 'Five',
);

Aligned Code

$data = array(
    'one'   => 'One',
    'two'   => 'two',
    'three' => 'Three',
    'four'  => 'Four',
    'five'  => 'Five',
);

I’m using the Sublime Text 3 (Unregistered). IMO it is best for the development. It has a lot of awesome features.

In this article, I’m explaining the Alignment package (It is in TOP 25 today).

Alignment Git Repo – https://github.com/wbond/sublime_alignment/

How to Install Alignment Package?

Just follow below simple steps:

  1. Press Command+Shift+P to open Command Palette.
  2. Type Install Package until you see Package Control: Install Package.
  3. When the list of packages appears, type Alignment until you find it.
  4. Press Enter to install Sublime Alignment.

Check out below GIF for reference to know How to Install the alignment package.

Now, Open the preferences file for Sublime Alignment:

Windows: Preferences > Package Settings > Alignment > Settings-User
Linux: Preferences > Package Settings > Alignment > Settings-User
Mac OS X: Sublime Text 2 > Preferences > Package Settings > Alignment > Settings-User

{
    // The mid-line characters to align in a multi-line selection, changing
    // this to an empty array will disable mid-line alignment
    "alignment_chars": [
        "=", ":"
    ]
}

Here, We have added the = and : So, When you select the code which include the = or : then it aligns with these characters.


How to Use Alignment Package?

Select the lines you wish to align. Press Ctrl+Alt+A (Windows & Linux) or Command+Ctrl+A (Mac OS X)

Check out below example to align the code.

BEFORE

$data = array(
    'one' => 'One',
    'two' => 'two',
    'three' => 'Three',
    'four' => 'Four',
    'five' => 'Five',
);

AFTER

$data = array(
    'one'   => 'One',
    'two'   => 'two',
    'three' => 'Three',
    'four'  => 'Four',
    'five'  => 'Five',
);

Check out the below GIF example for reference.

Advertisements

Keyboard shortcut/aliases for the WP CLI, Git, Grunt & PHPCS commands for windows

In development, We spend a lot of time on the command line. We type a lot of commands on regularly.

I have created a shortcut for the most of the commands which I use on a daily basis some of them are below:

WP CLI

Command Keyboard Shortcut/Aliases
wp theme list wpthl
wp plugin list wppll

Check all the available WP CLI commands etc. (all WP CLI commands list)

Example 1. Using shortcut wpthl instead of wp theme list

Example 2. Using shortcut wppll instead of wp plugin list

Some more commands with keyboard shortcuts/aliases are below:

Grunt

Command Keyboard Shortcut/Aliases
grunt release grr
grunt minify grm

PHPCS

Command Keyboard Shortcut/Aliases
phpcs pb
phpcbf pbf

Git

Command Keyboard Shortcut/Aliases
git add . gaa
git commit –message gcm
git checkout gco
git pull origin gpu
git push origin gpp
git status gs

To create keyboard shortcuts using aliases is very simple. We can create any command shortcut/aliases.

Follow below simple steps:

  1. Open the file .bashrc which is found in location  C:\Users\USERNAME\.bashrc and
  2. Add below sample commands of Git & Grunt.

I found the article Terminal/Bash Command-Line Shortcuts with Aliases written by @jonsuh to create keyboard shortcuts for the Terminal/Git Bash.

I have added some more commands of Grunt, WP CLI & PHPCS on my local environment.

Importing bbPress dummy data

Import the bbPress sample data with one click.

1) Quick Import:

I have created a simple plugin which imports the bbPress dummy data on your site within a few minutes. Check below video:

The plugin will approve on wp.org in this week. For now, you can download it from Github repo Sample Data.

Click on the download plugin to download.


2) Manual Download

You can acquire the file from this trac. ticket here. If you want to directly download the file click here.

  1. Go to Tools > Import.
  2. Go all the way down to where it says WordPress and click the link.
  3. If you haven’t installed the WordPress importer plugin already, click Install Now.
  4. If you have the WordPress Importer plugin installed and activated, proceed to the import process.
  5. Click the Choose File button, now select the file you just downloaded before.
  6. Click Upload file and import.
  7. You can now assign the posts to a specific user of your choice and check Import Attachments
  8. Now click Submit
  9. After that, it should import all of the posts in the file and tell you that it is done at the very bottom.

Source Creating Test Data

 

How to find broken links of website using command line interface (CLI) (Using wget)

Check the broken links on website using. Try below example command which generate the wget.log it list all the broken links.

  1. Download & Install wget
  2. Add the installation directory to PATH:
    C:\Program Files (x86)\GnuWin32\bin

Syntax:

wget -o wget.log -r -l 10 --spider http://example.com

Usage:

wget -o wget.log -r -l 10 --spider https://maheshwaghmare.wordpress.com --no-check-certificate

Output:

Spider mode enabled. Check if remote file exists.
--2018-06-29 10:11:59-- https://maheshwaghmare.wordpress.com/
Connecting to maheshwaghmare.wordpress.com|192.0.78.12|:443... connected.
WARNING: cannot verify maheshwaghmare.wordpress.com's certificate, issued by `/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2':
Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `maheshwaghmare.wordpress.com/index.html'

0K .......... .......... .......... .......... .......... 318K
50K .......... .......... .......... .......... .......... 80.5K
100K .......... .......... .......... .......... .......... 664K
150K .......... .......... .......... .......... .......... 2.07M
200K ..... 5.80M=0.9s

2018-06-29 10:12:01 (234 KB/s) - `maheshwaghmare.wordpress.com/index.html' saved [210113]

Check which template loading in WordPress site

Below is the simple function which you can use for debugging the site. It  display the template file path of the current page. Like below image:

Add below code snippet into your themes functions.php file.

WordPress Rest API query parameters mappings

This array defines mappings between public API query parameters whose values are accepted as-passed, and their internal WP_Query parameter name equivalents (some are the same). Only values which are also present in registered will be set.

Below is the list of all the endpoints which have query parameters mapping:

  • wp/v2/comments
  • wp/v2/<post-type>
  • wp/v2/<taxonomy>
  • wp/v2/<term>
  • wp/v2/<users>

Check below list of parameters mapping by Rest API endpoints:

wp/v2/comments

$parameter_mappings = array(
    'author'         => 'author__in',
    'author_email'   => 'author_email',
    'author_exclude' => 'author__not_in',
    'exclude'        => 'comment__not_in',
    'include'        => 'comment__in',
    'offset'         => 'offset',
    'order'          => 'order',
    'parent'         => 'parent__in',
    'parent_exclude' => 'parent__not_in',
    'per_page'       => 'number',
    'post'           => 'post__in',
    'search'         => 'search',
    'status'         => 'status',
    'type'           => 'type',
);

wp/v2/<post-type>

$parameter_mappings = array(
    'author'         => 'author__in',
    'author_exclude' => 'author__not_in',
    'exclude'        => 'post__not_in',
    'include'        => 'post__in',
    'menu_order'     => 'menu_order',
    'offset'         => 'offset',
    'order'          => 'order',
    'orderby'        => 'orderby',
    'page'           => 'paged',
    'parent'         => 'post_parent__in',
    'parent_exclude' => 'post_parent__not_in',
    'search'         => 's',
    'slug'           => 'post_name__in',
    'status'         => 'post_status',
);

wp/v2/<taxonomy>

$parameter_mappings = array(
    'exclude'    => 'exclude',
    'include'    => 'include',
    'order'      => 'order',
    'orderby'    => 'orderby',
    'post'       => 'post',
    'hide_empty' => 'hide_empty',
    'per_page'   => 'number',
    'search'     => 'search',
    'slug'       => 'slug',
);

wp/v2/<term>

       
$parameter_mappings = array(
    'exclude'    => 'exclude',
    'include'    => 'include',
    'order'      => 'order',
    'orderby'    => 'orderby',
    'post'       => 'post',
    'hide_empty' => 'hide_empty',
    'per_page'   => 'number',
    'search'     => 'search',
    'slug'       => 'slug',
);

wp/v2/<users>

$parameter_mappings = array(
    'exclude'  => 'exclude',
    'include'  => 'include',
    'order'    => 'order',
    'per_page' => 'number',
    'search'   => 'search',
    'roles'    => 'role__in',
    'slug'     => 'nicename__in',
);

Update PHP Codesniffer (PHPCS), WordPress Coding Standards (WPCS), PHP Compatibility (WIMG)

Update PHP Codesniffer (PHPCS), WordPress Coding Standards (WPCS), PHP Compatibility (WIMG)

Copy below individual or all command(s) to get latest update.

composer global require squizlabs/php_codesniffer
composer global require wp-coding-standards/wpcs
composer global require wimg/php-compatibility
composer global require dealerdirect/phpcodesniffer-composer-installer
phpcbf
phpcs