Add Files in WordPress Without FTP

I’m working on a client site running WordPress but without any access to FTP. It’s an interesting dilemma because WordPress will allow you to add new themes and plugins via its interface. It does so by allowing you to upload zipped files of the themes and plugins. Obviously, you don’t want to keep doing this especially you want to add just one file to the theme.

I needed to create a new page template on the Genesis platform. My client is using the Enterprise Pro child theme. There’s a command in PHP called ‘touch’ which allows you to create a new file. You can insert this command on the top of your theme’s header file in WordPress. Since I’m using Genesis, the child theme doesn’t have a header, therefore I had to do insert the command in the parent theme.

In the WordPress Dashboard under Appearance, choose the Editor. On the top right-hand side of the page, select the Genesis parent theme from the dropdown menu to edit. Click on the ‘Theme Header’ to edit, and add this line of code on top of the header.php file.

touch('wp-content/themes/enterprise-pro/template.php');

The command has to run once, so you’ll need to access the website at least once. Remove the line of code afterwards. The PHP ‘touch’ function will create a new empty file called template.php inside the Enterprise Pro theme. You can check it by navigating the editor once again, and selecting this time the ‘Enterprise Pro’ theme. Look for the new file called ‘template.php.’

In my case, I decided to change the page template to another filename, so I ended running it for the second time by inserting the rename function on the header.php file once again. Here’s the command to rename template.php to newtemplate.php.

rename('wp-content/themes/enterprise-pro/template.php', 'wp-content/themes/enterprise-pro/newtemplate.php');

Anyway, it works, but use this with extreme caution. If you’re not familiar with PHP and WordPress, you can render the entire website useless if you somehow inserted the wrong PHP code. There’s no FTP to back out the files. The WordPress Dashboard may no longer work. So, work on your own peril.

Update PHP Stable Release on Mac

PHP is installed by default on all Macs since OS X version 10.0.0. You can install and use MAMP, but if you prefer to use the pre-loaded version of PHP, then you may need to update it to the latest stable release. Fortunately, there’s a binary package out there that will simplify your life.

If you like to install PHP 5.6 stable release, all you need to do is run the following from the command line:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

If you feel adventurous, you can try PHP 7 stable release.

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

The installer packager will ask you for your password. PHP will be installed in /usr/local/php5.

Edit your .profile and include the PATH of the new PHP version.

nano ~/.profile

Insert the following:

export PATH=/usr/local/php5/bin:$PATH

To be sure your using the new version, check the PHP version:

php -v

You should see something similar to this:

PHP 5.6.19 (cli) (built: Mar  4 2016 22:35:42) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

You now have the latest PHP 5.6 stable release.

Editing a Blob in PHPMyAdmin

One of my projects this week requires editing a blob. A blob is a binary large object used primarily for storing images, audio and other media types in the database. Unfortunately, the application didn’t allow me to edit a blob. So off to the PHPMyAdmin I went. PHPMyAdmin is a MySQL administration tool.

By default, the blob entries in PHPMyAdmin can’t be edited. Simple texts in blobs are sometimes scrambled. In order to make changes to the blob entries, we need to reconfigure PHPMyAdmin by editing the configuration file.

Edit the /etc/phpmyadmin/config.inc.php file.

$ sudo nano /etc/phpmyadmin/config.inc.php

Add the following entries at the end of the file.

$cfg['ProtectBinary'] = FALSE;
$cfg['DisplayBinaryAsHex'] = FALSE;
$cfg['ShowBlob'] = TRUE;

There is no need to restart any services. Changes are automatically reflected in PHPMyAdmin.