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.

Using absint() in WordPress

It convert a value to non-negative integer.

Internally this function used abs( intval( $maybeint ) ).


You can try below examples yourself.

Examples Output var_dump
absint( 0 ) 0 int(0)
absint( '0' ) 0 int(0)
absint( 1 ) 1 int(1)
absint( '8' ) 8 int(8)
absint( -27 ) 27 int(27)
absint( '-8' ) 8 int(8)
absint( 'abc' ) 0 int(0)
echo absint( 0 );
// Output: 0 
// var_dump() int(0)

echo absint( '0' );
// Output: 0 
// var_dump() int(0)

echo absint( 1 );
// Output: 1 
// var_dump() int(1)

echo absint( '8' );
// Output: 8 
// var_dump() int(8)

echo absint( -27 );
// Output: 27 
// var_dump() int(27)

echo absint( '-8' );
// Output: 8 
// var_dump() int(8)

echo absint( 'abc' );
// Output: 0 
// var_dump() int(0)

Finally plugin Sample Data approved!

You can now download the Theme Unit Test for testing your theme or import the WooCommercebbPress plugin sample data with simple ONE click using WordPress plugin Sample Data.

Note: Use Sample Data plugin on your testing/staging environment.

Quick Start:

Follow below simple steps to import the dummy content:

  • Install & Activate plugin.
  • Click on Get Started » from plugin/theme. It read the file and get import content.
  • Click on Start Import and confirm to import the data.
  • For more details check below screenshots or youtube video.

Screenshots:

screenshot-1
Step 1: Install & Activate plugin
screenshot-2
Step 2: Click on `Get Started`
screenshot-3
Step 3: It get the content from file
screenshot-4
Step 4: Click on `Start Import`
screenshot-5
Step 5: Click `Ok` to confirm import
screenshot-6
Step 6: Import Started!
screenshot-7
Step 7: Import Completed!
screenshot-8
Step 8: Imported Contents.

Plugin import the data form the XML file. For now plugin added in-build support for:

  • Theme Unit Test Data
  • WooCommerce
  • bbPress

Do you want another plugin support? Request for support »

Do you know coding? Let’s fork & extend it from Github.

You can download it from wp.orgVisit plugin page Sample Data.

Importing Theme Unit Test Data

Importing Theme Unit Test Data in WordPress with one click.

1) Quick Import:

I have created a simple plugin which imports the Theme Unit Test 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

  1. Clone the theme test data file themeunittestdata.wordpress.xml from the GitHub repository https://github.com/WPTRT/theme-unit-test (last updated 18/Apr/2017) Or Download a copy from https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml
  2. Import test data into your WordPress install by going to Tools => Import => WordPress
  3. Select the XML file from your computer
  4. Click on “Upload file and import”.
  5. Under “Import Attachments,” check the “Download and import file attachments” box and click submit.
    Note: you may have to repeat the Import step until you see “All Done” to obtain the full list of Posts and Media.
  6. Read Becoming a reviewer, and follow the easy steps.

Source Theme Unit Test

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

 

Envato Elements – Template Kits (Beta)

Envato released the plugin Envato Elements – Template Kits (Beta) plugin to import the templates. It supports now for Elementor & Beaver Builder page builder.

Plugin URL: https://wordpress.org/plugins/envato-elements/