Categories
WooCommerce WordPress WP-CLI

How to Bulk Delete all WooCommerce Customer Accounts

The following WP-CLI command is a really easy way to delete all existing WooCommerce customer accounts on a WordPress website:

wp user list --field=ID --role=customer | xargs wp user delete --yes

And the best part: all of the information from the customers’ existing orders remained in-tact as well!

Categories
WordPress WP-CLI

Importing 1100 users into WordPress from a CSV file using WP-CLI

The Problem

A spreadsheet of ~1100 people (name, email address, etc) that needs to be imported into a WordPress site as users:

User Import CSV File
The User Import CSV File

I tried several user import plugins, but I had trouble with some users not importing (duplicate email addresses and/or usernames), and the plugins I tried didn’t make it easy to see which accounts were failing to import and why.

The import process via the WordPress dashboard was also encountering timeout problems due to the large amount of data being imported.

The Solution

WP-CLI’s user import command available to the rescue!

I used the following command to import the 1100+ user accounts:

wp user import-csv --skip-update user-import.csv

Note: this command skips user accounts that already exist because I included the --skip-update flag.

The output of this command made it very easy to identify the lines/users that were failing to import due to their email addresses already exist.

Bulk Deleting all Subscriber Accounts

I fixed up the duplicate data in the CSV file, and then used the following command to delete the imported user accounts before attempting the import again:

wp user list --role=subscriber --field=ID | xargs wp user delete --yes

Note: this command deletes ALL existing subscriber user accounts.

Once the imported accounts were deleted, I was able to retry the import using the command above.

Using WP-CLI for this ended up working great, and the import process was much quicker than using a plugin because I didn’t have to worry about server timeouts and other problems.

Are you using WP-CLI?

If you’re not already using WP-CLI, be sure to check out my previous presentation.

Categories
Community Events WordPress

The Inaugural BeachPress Australia – August 2013 – Phillip Island, Victoria

A weekend where WordPress developers and/or businesses owners get together to write code, share ideas, collaborate on projects, and maybe even relax.

Do you like WordPress?

Do you like sharing ideas, stories and (GPL) code with like minded people?

Do you have an idea for a new plugin, and want to team up with someone to get it finished and published?

Do you have a WordPress project that you’ve been wanting to finish, but haven’t been able to find the time?

If you answered yes to any (or all) of those questions, then this weekend is for you!

When?
Arrive Friday 16 August 2013 after 3pm.
Depart Monday 19 August 2013 by 9am.

Where?
A deluxe 5 star holiday house (including ocean views) in Phillip Island, Victoria:


(Photos courtesy of the holiday house’s owner)

What’s included?

  • 3 nights accommodation in Rhyll, Phillip Island, Victoria.
  • 7 meals (Friday dinner, Saturday breakfast, Saturday lunch, Saturday dinner, Sunday breakfast, Sunday lunch, Sunday dinner).
  • your own bed (including linen).
  • the opportunity to collaborate and have fun with some great Australian WordPress people!

How much?
$250 AUD per person (paid in advance).
Note: we are not going to profit from this event – any extra money will be spent on additional food/drinks/snacks for everyone.

What do I need to bring?

  • your laptop and charger
  • mobile phone (with mobile data) – wifi is not available, so we’ll need to use our phones for internet access
  • any alcoholic drinks
  • any specialist snacks/food
  • your wetsuit (if you’re crazy enough to swim during a Melbourne winter!)

Who is organising this?
James Collins and Aaron Rutley.
(Two WordPress developers from Melbourne, and organisers of the WordPress Melbourne User Group).

Can I come?
We are keeping the numbers small – places are limited to 10-12 people.
If you’re willing to sleep on the floor (instead of in a bed), it is more likely we’ll be able to squeeze you in.
So if you’re interested in coming, please contact me.

This event is now sold out. Please keep an eye on the blog if/when we organise another one of these events.

I can’t make it on those dates. Will there be another one?
No promises, but we’re really excited about this concept, and we’re hoping to make them a (semi) regular event in different locations around Australia.

Full disclosure: this event wasn’t my idea – recently in Portland, Justin Sainton organised an event called BeachPress, and he’s been kind enough to give me some advice and let me run a similar event in Australia.

Categories
Community WordPress

Happy 10th Anniversary WordPress!

Today (May 27) is WordPress’ 10th anniversary!

(Technically speaking, today marks 10 years since the first WordPress release).

In that time, there have been 79 WordPress releases (19 of which were major releases that were named in honour of a jazz musician).

To celebrate, there are over 650 WordPress 10th Anniversary parties around the globe. So be sure to get along to one of them and spread the WordPress love.

WordPress' 10th Anniversary Parties

Also, be sure to check out the anniversary posts from WordPress co-founders Mike Little and Matt Mullenweg.

Categories
Community WordPress

How to Get Involved in the WordPress Project

Recently at WordCamp Melbourne, Ryan McCue said the following to all attendees:

If everyone simply contributed just one thing to the WordPress project, then WordPress would be infinitely better.
Ryan McCue

Please pause, and think about that for a second.

Going back a few years, there seemed to be a heavy focus on core code being the primary way to contribute to the WordPress open source project.

However in recent times, I’ve noticed a lot of effort has been put into helping the community contribute to the project in other ways (such as documentation, events, or support).

The WordPress Foundation has recently posted a great summary on how you can get involved in the WordPress project.

Regardless of whether you’re using WordPress for business or personal reasons, I strongly suggest you have a read of the article, which lists these teams/areas that you can get involved in:

  • Accessibility
  • Community
  • Core (testing, bug reporting, code wrangling)
  • Documentation
  • Events (WordCamps, meetups, etc)
  • Meta (wordpress.org)
  • Mobile ((iOS, Android, Windows Phone, and BlackBerry apps)
  • Polygots (translations)
  • Plugins
  • Support
  • Themes
  • UI (user interface design & development)
  • Updates (news / blog posts)

In my case, so far I have helped out with WordPress core (bug reporting & fixing), documentation, events, plugins, suport and updates.

However I haven’t been contributing as much as I would like to. I’ve only used six of the thirteen ways that I could be contributing, so there’s definitely still room for improvement!

How are you planning on contributing to the WordPress project?

Categories
Development PHP Plugins Themes WordPress

New in WordPress 3.6: the attachment_url_to_postid() Function

If you’re writing a WordPress plugin, you may have a scenario where you have an attachment (file) URL, and you’d like to obtain the associated post (attachment) ID.

Luckily, this is very easy to do in WordPress 3.6 because of the new attachment_url_to_postid() function.

The function’s syntax is simple – you pass it a string (the file URL), and it returns an integer (the associated post id), or zero on failure.

Here’s a simple example:

As mentioned above, this function is available in WordPress 3.6 – it will cause a fatal error if you try to use it in any earlier versions such as WordPress 3.5.x.

Thanks to Zack Tollman for the heads up about this handy new function.

Categories
Development PHP Plugins Themes WordPress

Better Mobile Detection with WordPress’ wp_is_mobile() Function

Although WordPress themes typically use Responsive Web Design to tailor website for mobile devices, there is sometimes a need to use PHP (backend code) to detect whether the visitor’s web browser is running on a mobile device.

For example, there may be scenarios where you may want to output certain HTML markup (such as a mobile navigation menu) on mobile devices.

Alternatively, you may only want to output a slider containing large images on desktop and not mobile devices. Doing this via PHP (instead of CSS) means that the visitor’s mobile browser won’t have to download all of the slider images even though the slider is never displayed.

WordPress’ wp_is_mobile() function to the rescue!

wp_is_mobile() is a litte-known function built into WordPress that detects whether the visitor is using a mobile devices such as iPhone, iPad, Android, Silk, Kindle, BlackBerry, Opera Mini, and Opera Mobi.

The function was introduced in WordPress 3.4, and it can be used in a WordPress plugin or theme.

It’s a simple function that accepts no parameters, and returns a simple boolean (true/false) value.

Here’s a simple example:

Interestingly, WordPress core currently uses this function in a few different places:

  • To completely disable the Visual Editor for Opera Mini.
  • To enable jQuery UI Touch Punch in the WordPress dashboard for mobile devices.
  • To detect whether the current device can upload files.
  • To disable the “shake” effect on the WordPress login page when an incorrect username or password is entered using a mobile device.

Are you currently using the wp_is_mobile() function in your plugin or theme? If so, I’d love to hear what your use-case is.

Categories
Meetups WordPress

WordPress User Groups in Australia – Some Statistics

Below are some statistics that demonstrate how popular the WordPress user groups are in Australia:

Location Population Number of
Group Members
% of Population
in Meetup Group
Hobart 216,276 93 0.0430%
Bendigo 89,666 23 0.0257%
Brisbane 2,146,577 342 0.0159%
Sydney 4,605,992 661 0.0144%
Melbourne 4,169,103 516 0.0124%
Canberra 367,752 42 0.0114%
Adelaide 1,262,940 81 0.0064%
Perth 1,832,114 66 0.0036%
Wollongong 288,101 9 0.0031%

As you can see, Hobart has the highest percentage of their population being a member of their user group. Well done Japh!

Here in Melbourne, it looks like we have some work to do.

Population Figures are sourced from Wikipedia as of 10 October 2012.

Number of Group Members Figures were sourced from each meetup.com group page as of 10 October 2012.

Categories
Plugins WordPress

Embed a Github Gist in WordPress Posts/Pages

Looking for a simple way to embed a Github Gist in your WordPress website?

I spent some time reviewing the available plugins in the WordPress plugin repository, so I thought I’d share my findings.

Categories
Plugins WordPress

Should I escape translated strings in a WordPress plugin or theme?

When writing a WordPress plugin recently, I wasn’t sure whether a translatable text/string is considered safe, or if it needs to escaped before being output.

Here’s a simple example:

The Problem

At first glance, that code looks like it should be safe, however what would happen if the string was translated to contained an angled bracket (< or >)?

That would result in invalid HTML code. Or even worse, what if the translation file contained a malicious <script> tag?

The Solution