Tuesday, August 19, 2014

WooCommerce: SQL to fix sorting by date

In one of the projects, I needed to import a product data from a non-WP website to WooCommerce.

After importing, the "Sort by newness" did not work correctly, because the post dates were all the same.

A simple SQL solved my problem:

Wednesday, May 28, 2014

WordPress Tip: Export WooCommerce category list (SQL, CSV, Excel)

Run this SQL in phpMyAdmin, and then click Export link at the bottom to save as CSV for Excel or other format.

Note: tested only on one level of subcategories.

Gist revisions are welcome: https://gist.github.com/tivnet/d9cca4a4f4cfebe143bc

Thursday, March 20, 2014

SourceTree does not show submodules

(SourceTree is a nice Git client by Atlassian)

The Problem:

SourceTree loses track of Git submodules. The entire "submodules" sidebar section is invisible.

A "clue":

Click the "Terminal" toolbar icon and type
$ git submodule

You should see something like:
dbd34bd2657ef70f001c1d135e2e14adef7dcdb9 dbdump (heads/master)
No submodule mapping found in .gitmodules for path 'wp'

The first line is good. The second one is a "clue".
It says: "Git knows about a submodule that you defined earlier. However, it cannot find the path to it in your .gitmodules file!"

Apparently, the path to submodule is wrong, or absent.
Restore it.

...or if you do not need that submodule, issue the following command in the terminal window:
$ git rm --cached {your submodule path} 

Illustration:

Before:

After:

Wednesday, March 19, 2014

Making a WordPress.org plugin: SVN, GitHub, PHPUnit and Travis-CI [Part 1]

This is my first experiment to publish an open-source code. It was quite a "challenge", after years of working exclusively for corporate clients and myself, to write something that can go to "the wild" :-))

WordPress version:
http://wordpress.org/plugins/tivwp-dm-development-manager/
GitHub version:
https://github.com/TIVWP/tivwp-dm

Here is a shortened list of what's involved in making a public plugin and publish it on WordPress.org site:
  • Write a bullet-proof PHP code (mission impossible, but approach as close as you can)
  • Organize the code in a special way: names of the files, folders, special headers, screenshots, readme.txt and so on.
  • Place your plugin somewhere so that WordPress staff can check it out and approve. (Hint: GitHub is a good place for that)
  • Apply here: http://wordpress.org/plugins/add/. Note: the name of your plugin will become it's "slug" in the URL, so choose carefully!
  • Wait for the approval, and if you never used SVN before, take this time to learn the basics.
  • SVN-Commit your code once approved.
  • Wait for reviews and support request.............. :-)
Notes:
  • Folders structure and readme.md on GitHub are not exactly the same as on WordPress.org
  • You can setup Travis-CI calling PHPUnit to test your code automatically. It's not an easy thing to setup - but highly recommended.
To Read:

I'll try to find time and write more details [Part 2,3,...] soon.

Sunday, March 16, 2014

WordPress: How to exclude plugin/theme files from Poedit catalog

► The Problem:

I use some third-party files in my WordPress plugin (or theme). When I run Poedit to built language files, it scans the main plugin folder and puts all text strings found in the .po file, including those from the third-party.

► The Solution?

Vaclav Slavik, the author of Poedit, placed a "wontfix" resolution on that, years ago. See http://www.poedit.net/trac/ticket/359 and http://www.poedit.net/trac/ticket/253.

So, there is no official solution to this.

► So, what to do?

Separate the 3rd party files from yours.

For example, put all your .php files into the "includes" folder, and 3rd party files - into the "vendor" folder. Then, in Poedit -> Catalog -> Properties -> Sources paths tab, instead of the "." (current folder), write "includes".

Poedit will scan only the "includes" and will ignore the "vendor" folder.




Saturday, March 15, 2014

List of Front and Admin WordPress Actions

Below is a list of core WordPress actions as of WP-3.9-beta1.
I obtained this list by printing the $tag parameter in both do_action() and do_action_ref_array() functions while running a front page and an admin page.
This list cannot be considered complete. Please use it for quick reference only.

Link to the spreadsheet on Google Drive:
https://docs.google.com/spreadsheets/d/1-84REYUiT2bBREDV_d_m0skwEstvs-ANAWN3UumePV4/edit?usp=sharing


Wednesday, February 26, 2014

"An error occurred in the upload..." (WordPress Media)

Seeing "An error occurred in the upload..." message when calling WP Media interface on the front?

I believe, that's a core problem, but here is a workaround that I am using quite often in my projects.

Admins won't have this bug, but regular users - will. Because we are on a page, which $post was not created by this regular user, so he does not have the editing capabilities... and Media needs them.

// Preserve the current Post
// (just in case, you may not need it)
$oldPost = $GLOBALS['post'];
// Make it a dummy
$GLOBALS['post'] = 0;

// For example, the editor, with "Media" button:
wp_editor($content, $editor_id, $settings);
// Or "Upload Avatar" code from the WPUA plugin
do_action( 'show_user_profile', $current_user );

// Restore
$GLOBALS['post'] = $oldPost;

// Be happy