2014-08-19

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:

2014-05-28

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

2014-03-20

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:

2014-03-19

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.

2014-03-16

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.




2014-03-15

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


2014-02-26

"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

2014-02-16

Visibility of Google Docs (Drive) in SERPs

I've been wondering how would it work if, instead of typing in a blog, I'd share Google Docs. There is a "Publish on the Web" option there. Would I still need a blog, or I can maintain a combination of Google Plus and Google Drive?

I do not have an answer yet, but here is a "discovery" I just made by checking the Google Docs visibility in search results. There is nothing surprising in what I saw, just a little fun :-)

Update:

I received this comment:
... they are not private as you suggest in your article, they are simply shared docs that violate G's TOS
Specifically, they are BH intermediary pages with the intention of passing PR via one of Google's own subdomains. ;(


  • Google publishes links to (probably) all people's docs.
  • All titles and descriptions are the same
This looks almost the same as it would look on your site with the Disallow instruction in the robots.txt file.

Almost - because Google substitutes the title and description with self-promotion.

and finally:
  • When you click on a link, it shows a "scary" message :-)



2014-01-24

Sender address rejected: Domain not found - outgoing mail settings with Postfix

Environment:

A staging server called "tst.myserver.com", with no DNS record pointing to it.
Trying to send email from there to myself (me@my-mail.com)

Problem:

$ echo foo | mail -s bar me@my-mail.com
$ tail /var/log/mail.log
Jan 24 18:30:24 tst postfix/smtp[26306]: 46D8FC2584: to=<me@my-mail>, relay=mail.my-mail[1.2.3.4]:25, delay=0.61, delays=0.02/0.01/0.45/0.13, dsn=5.1.8, status=bounced (host my-mail[1.2.3.4] said: 554 5.1.8 <me@tst.myserver.com>: Sender address rejected: Domain not found (in reply to RCPT TO command))

Explanation:

$ cat /etc/hostname
tst.myserver.com
This is the FQDN (fully qualified domain name), and Postfix appends it to the local user name.

What we want

We'd like Postfix to append only the myserver.com and not the tst.myserver.com

A solution

(figured out by reading http://www.postfix.org/ADDRESS_REWRITING_README.html)
# vi /etc/postfix/main.cf
(add this line:)
masquerade_domains = myserver.com
Restart Postfix
# postfix stop && postfix start

2014-01-04

Could not open input file: /cygdrive/c/PHP/phpunit (PHP under Cygwin)

The problem:

$ /cygdrive/c/PHP/php.exe /cygdrive/c/PHP/phpunit
Could not open input file: /cygdrive/c/PHP/phpunit

Environment:

MS Windows
PHP
Cygwin

Explanation:

While started in Cygwin, php.exe will be run in Windows environment, which does not know how to translate /cygdrive/c to C:\

Solution:

Use a wrapper script https://gist.github.com/tivnet/8256140
(Originally published by aefxx here)