Using WordPress meta field values for dynamic Gravity Form emails

Ever use Gravity Forms and want to easily add a form that takes an email value from the post? For example maybe you have store profile posts and each post has a contact form in the sidebar, but you want the email sent to each individual  person/store/whatever. Well there is a really simple way to do that.

function your_custom_notification_signature( $notification, $form) {

   //This example is using a form with the id of 1
    if($form["id"] == 1){
        global $post;

        //the example email is stored in a post meta field called "_cmb_email"
        $store_email = get_post_meta( $post->ID , '_cmb_email', true );
        $notification['to'] = $store_email;

       return $notification;
    }
}

add_filter('gform_notification', 'your_custom_notification_signature', 10, 3);

You can change a lot more than that as well, have a look at:

How to remove error notices using WordPress’s WP_DEBUG

A neat trick I learned today to remove or adjust PHP error reporting when using `WP_DEBUG`. It’s often the case that a theme or plugin author has either not written code with debug on or perhaps supporting an older version of PHP so error notices can hinder the output visually or fill up your log file. A theme I was working on that caused me to find a solution was adding 8k lines of debug output to the log file every couple hours!

In your `wp-content` folder create a new folder called `mu-plugins` and in that folder create a php file with the error level you want, for example:

//Turns off notices
error_reporting(E_ALL ^ E_NOTICE);

If you are using PHP 5.5 +, you will get deprecated noticed for WordPress’s mysql_* functions, you can turn them off using:

error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);

Or for something really robust, which happens to be the case a lot.

error_reporting(E_ALL &  ~( E_DEPRECATED | E_USER_DEPRECATED | E_USER_NOTICE | E_STRICT ));

References:

I you develop themes/plugins please turn on debugging and support at the very least PHP 5.4!

An awesome command line tool for Windows you might have never heard of

gnome-terminalDeveloping on Windows has always been a challenge when it comes to the command line.  I know powershell can do a lot, but I honestly can’t be bothered with it, especially considering I don’t work with .NET, and the regular cmd line is lacking in features to say the least.

In my quest to find a decent alternative that is not full blown cygwin, deep within the bowels of Stack Overflow I found a link to a website called MobaXterm. Pretty crummy name , but I liked the features list, it has a tiny cygwin wrapper (16.5 MB instead of 2GB +) and it was free. Maybe it could do what I’ve been looking for in terms of terminal emulation, specifically features like:

Continue reading

When PHP’s mail function doesn’t work

mail-07[1]A lot of VPS’s do not have mail functionality right out of  the box, so if you install a stack like LAMP or maybe a WordPress install script (like you find on Linode or Digital Ocean) , and then try to send mail via your website, you will most likely get an error.

For example if your using Contact Form 7 in WordPress you will get “Failed to send your message”, not a very meaningful error.  So the first step is to troubleshoot the problem, login via SSH and type:

netstat -tulpn

This should show your servers open ports, there should be a mail program in there with a mail port open to 25 and/or port 465 (or 587) for SSL. If not then you will not be able to send any mail via PHP, unless you have configured a different port or remote service, all of which can be verified.

You can further test PHP’s mail by sending a test email using  PHP’s command line or putting the following into a PHP file.

mail ( 'your@email.com', "Test mail", "Test mail from your server name" );

Continue reading

Enabling Zend OPcache on Ubuntu and Apache

opcodeZend OPcache is the new open source opcode PHP cache that is now bundled with PHP 5.5. I had just upgraded one of my servers running Ubuntu 12.04 to use Apache 2.4.6 and PHP 5.5.4.

So how does one install it? I initially thought I had to just edit the php.ini file since there are a bunch of new settings for the opcache. I set mine similar to the recommended default and did not enable `cli` caching.

opcache.memory_consumption=128
opcache.interned_strings_buffer=6
opcache.max_accelerated_files=2000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

Restarting Apache however and I saw that it was still disabled , even though I had also set

opcache.enable=1

Continue reading