PHP / WordPress — Enable Debugging, Log Writing, etc.

This is my first time messing around with PHP, making a plugin based on other plugins to try to understand how PHP works.

I really needed debugging enabled though. WordPress defaults to a blank white screen of death if any errors are posted.

I went through 10 different ideas for displaying debug messages all the way to php. It turns out all you need enabled are a few options in wp-config.php for wordpress display the errors.

The big problem for googling this answer is that only this post has the KEY that I needed: “WP_DEBUG_DISPLAY”

http://fuelyourcoding.com/simple-debugging-with-wordpress/

WP_DEBUG alone didn’t do it, moving php.ini to my user on dreamhost and enabling errors didn’t do it..

So that’s it:

define(‘WP_DEBUG’, true);

define(‘WP_DEBUG_DISPLAY’, true);

The php.ini settings may be required as well, but the bottom line is WP_DEBUG_DISPLAY.

Nginx / WordPress — Proxy Subdirectory to WordPress Subdomain

Using Nginx to proxy a subdirectory to a wordpress installation on a subdomain.

I’m moving our blog onto our main site, but want to keep them on separate servers from the main site for various reasons.

The blog will be on blog.anuvawines.com, but be accessible from anuvawines.com/blog (for SEO, since google thinks of subdomains as separate sites).

Double Update: Don’t do it!

It’s more trouble than its worth for me — I simply bought a bigger server to handle a separate PHP process and let nginx actually serve it at /blog/.

Update: I ran into issues with permalinks due to the proxy. It looks like WP checks the ‘home’ option against something to pull the post_ID from your permalink format. I tried digging in and replacing option_get(‘home’) where i thought the ID was being generated, but couldn’t solve the issue.

My end solution was to set the home field to the real address where WP is hosted, and to edit the link generator itself to pull data from a new option field I made called proxy_home.

That way, all my issues were solved.

For my peace of mind, I made my subdomain return a 403 forbidden if a certain header was not passed to the subdomain on proxy.  Of course, this could be any other method that generally IDs the proxy server (ip/referrer/whatever). The reason is not for security, so anything goes.

Set up the nginx proxy

Say we want to proxy domain.com/blog/ to blog.domain.com. Note that I say proxy, because we don’t want a redirect. We want a 200 http status message. One that google will crawl as apart of domain.com/

Set up a location in your /etc/nginx/nginx.conf aside your other location directives.

location /blog/ {
 proxy_pass http://static.anuvawines.com/wordpress ;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Restart nginx, and you’re good to go. Visit the mydomain.com/blog and you will be able to navigate to the site, with an HTTP 200 message.

The only problem is that the links are still using the subdomain address, and if you tried admin authentication, it fails.

Set up wordpress links to use proxy address

This is pretty much good to go out of the box, but you will have to change your WordPress installation to rewrite the urls for your proxy domain instead.

Right now, all links are subdomain.mydomain.com/, when they should be accessed by domain.com/blog

add a few lines to your wp-config.php

define('WP_HOME', 'http://mydomain.com/blog');
define('WP-SITEURL', 'http://mydomain.com/blog');

Reload the page and your urls should be set to the new ones.

Fixing admin/authentication for proxy address

Suddenly, we have a problem. We can’t log in via the proxy, OR the actual subdomain address because we set the above 2 lines.

subdomain.mydomain.com/login will redirect to mydomain.com/blog and fail.

I dug around the cookie headers to see that wordpress is looking for a database entry called home and siteurl to set these cookies. The above code fixed our links, but these cookies look directly at the db. I suspect this means the above step is useless.

So, go into your mysql db, alter the wp_options table, option_name “siteurl” and option_name “home”, and set them to the proxy address.

In my case, anuvawines.com/blog

The cookies will now match the domain when you are logging in via the proxy address.

Mimi wo Sumaseba / Whisper of the Heart — Ghibli Studio

I was listening to some old music and came across the soundtrack for this movie, one of my favorites that most people tend to fall asleep watching.

I looked up some reviews and am super happy that lots of people appreciate it as well.

http://www.imdb.com/title/tt0113824/usercomments?start=0

Basically, every Ghibli film i’ve seen is deeply moving. They are the movies I think about 5 years later, not the countless action movies I’ve seen since then.

I suggest you watch them.

Jquery — Click event fires twice.

I had an issue with jquery where the click event fires twice per click.

With the following code, I would get the alert fired twice.

$("div").click( function()  { alert('clicked');} ) 

I narrowed down the problem to having the DOM Ready function inside of my HTML <body></body> tag.

So.. make sure all of your jquery code is inside one document.ready() or $(function() { }); (the jquery shortcut)

I reproduced this error and having two sets of $(function() {}); was no problem inside the <head></head> tags, but as soon as it goes in the <body></body> the problem appeared.

Django — TypeError Str Object Not Callable Urls.py

I got this error recently in my urls.py.

We should naturally be looking for a string in our urls.py (error says str object) and I found that my comment “”” “””” was being the issue.

I’m used to placing a lone string at the beginning of a class or function, but in this case it was in the middle of defining the urlpatterns, so the url parser actually tried to read my string comment.

Just a heads up.

Django — Edit Foreign Keys Directly In Place

I I’m not sure why there are so few results for googling this. Editing foreign keys directly, or at least taking us to the model in question I’ve wanted to do since the first day I used django. I’m finding it very difficult to search for so I’ll add it here. I had to pull out the patch filename to find it again. I wonder why?

The data for a forward relationship (Model A FK –> Model B) should positively identify the target model so I don’t know why a link option hasn’t been built in, because I know tons of people would appreciate that built-in functionality.

This patch will place an edit icon next to the “add” icon for direct foreign links, allowing you to edit an FK in the same manner: a pop up window.

Here’s the ticket that I used to patch my django on my dev server. So far, so good. Has it been merged into 1.1? That would make this useless.

http://code.djangoproject.com/ticket/11397

Go to your directory that CONTAINS django (for example, django-trunk if you used SVN) and download the patch.

http://code.djangoproject.com/attachment/ticket/11397/add_edit_icon.diff

Type:

wget http://code.djangoproject.com/attachment/ticket/11397/add_edit_icon.diff
patch -p1 add_edit_icon.diff

Patch is not my cup of tea, but assuming django hasn’t changed too much, the command should install the patch. Type ‘man patch’ for details on the -pnum argument. I barely know this thing so I can’t say much more.

Google Buzz — How to Turn it Off

One solution: drag the buzz icon to your extra labels area so it’s out of the way.

The second way is to scroll to the bottom, and the option is next to the other Gmail options.

Gmail view: standard | turn on chat | turn off buzz | older versionbasic HTML Learn more

This is going to be deadly as more people start using it. I check it like I check my email. I have my gmail on my right monitor all day. My eye glances towards the inbox indicator once every minute at least.

NOT GOOD. But I can’t turn it off yet. It’s new and exciting.

TinyMCE — Absolute URL Images

Add the option ‘relative_urls’: ‘false’ to disable the auto absolute-to-relative link changing behavior.

This wiki lists all types of URL converting here… but I’m still having issues. I’ve tried all of them.

I’ve heard of issues with IE auto formatting links, but I’m using Chrome. I’m trying to write an img address for a newsletter, which will obviously fail if i use a relative link.

http://wiki.moxiecode.com/index.php/TinyMCE:FAQ#Paths.2FURLs_are_incorrect.2C_I_want_absolute.2Frelative_URLs.3F

WWaaait a minute.. Why doesn’t this link fail? >_>

/blah/ is reaching my server from refreshing gmail.. does it automatically determine the domain from email headers or something??