Because programming sucks.
Download master.zip, then install it via the "Add Plugin" button on WordPress's "Plugins" page.
Just use the shortcode in any WordPress text area. Easy peasy. A few examples:
[left-pad foo 5]
// => " foo"
[left-pad foobar 6]
// => "foobar"
[left-pad 1 2 0]
// => "01"
[left-pad 17 5 0]
// => "00017"
Note: The third argument should be a single character. Obviously.
- 1.0
- First proper release
- CHANGE: Fix handling of multi-byte pad characters
- 0.1
- Work in progress
Distributed under the WTFPL. Because who cares. See LICENSE
for more information.
I originally had the idea to do this after someone on Reddit joked about WordPress plugins being like node modules. I responded with a low-effort left-pad joke, but soon thought "hey, that might actually be funny to do!". It was a fun little exercise to spend a little time on.
Wrong. str_pad()
doesn't handle multi-byte characters correctly, and while I tried to replicate the functionality of left-pad as closely as possible, multi-byte characters needed to work correctly. Otherwise, I couldn't use non-breaking spaces (which are encoded as c2 a0
in UTF-8); I needed to use non-breaking spaces as WordPress automatically consolidates consecutive normal spaces into one space.