How to debug WordPress errors

First of all, WordPress provides debugging as an option. It is not activated by default. In order to make it work:

// Enable WP_DEBUG mode
define(‘WP_DEBUG’, true);

There are also ways of storing it into a file or not display it. Please have a look at the detailed options here: https://codex.wordpress.org/Debugging_in_WordPress

If you would like to have a more powerful tool, that also shows the queries and other information, I recommend to use the plugin:

Debug Bar: http://wordpress.org/plugins/debug-bar/

and Debug Bar Console: http://wordpress.org/plugins/debug-bar-console/

Happy debugging!!

Advertisements

How to make a language switcher menu in PHP

this snippet will work if you have a structure like this

(English pages)

/contact

/about

/blog

(Spanish pages)

/es/contact

/es/about

es/blog

This is the code you can put in a menu as a list item. It would work nicely in a wordpress website.

<li>
<? if (substr($_SERVER[“REQUEST_URI”],1,2) == “es”) { ?>
<li><a href=”/<? echo substr($_SERVER[“REQUEST_URI”],4); ?>”>In English</a></li>
<? } else { ?>
<li><a href=”/es<? echo $_SERVER[“REQUEST_URI”]; ?>”>En español</a></li>
<? } ?>
</li>

MAMP: how to use MYSQL from console

I could not access the mysql database from console, getting this error

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ 

So I googled and found this:

http://fischerlaender.de/apple-mac/mac-os-x-trouble-with-mamp-mysql

and I sorted it out using:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

This will allow you to access through the console and do things such as

mysql -u root …

But now, there is an additional challenge. When I try to use the database through php (launching the console php -a), using sentences to connect such as mysql_connect(DB_HOST, DB_USUARIO, DB_PASSWORD) it will return the error

Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in php shell code on line 1

So, again searching in google, this is the solution: http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi

sudo mkdir mysql

cd mysql/

sudo ln -s /tmp/mysql.sock mysql.sock