Development Blog

Setting up localhost Apache/PHP on iCloud Drive

Prerequisite: you have a normal localhost LAMP setup, and your localhost/~username/ host serves the contents of ~/Sites/. If you don’t here’s the best step-by-step to get it running.

Alright, lets go:

iCloud drive is a neat place to save your localhost server contents as it backs up remotely and syncs across all devices. So work and home computer can have the same localhost files. As well iOS apps have access to it. A pretty cool way to do things.

Here’s how I got it running.

We’re going to point Apache to run off a folder in our iCloud drive, we’ll keep it named Sites (but it’s not the same as ~/Sites/), create it in iCloud Drive, add a sub folder named _temp and a index.php file with whatever phpinfo() or something therein to let you know when you’ve got things working.

Into Apache’s configuration:

sudo vi /etc/apache2/httpd.conf

Look for DocumentRoot and change to the following lines:

While in the file, we’ll also change the permissions of Apache to our current user

Then we need to change the owners of Apache to us:

And we’ll repeat for username.conf

sudo vi /etc/apache2/users/username.conf

And now let’s hide our temp folder from Finder

My understanding of the security involved with this is making sure PHP can’t touch anything outside of your Localhost directory in iCloud drive. The risks of a localhost being compromised is low but apparently possible using malicious scrips that fire off of localhost links. To prevent this, you can run localhost off of a random port instead of 80, and always ensure you have a good htaccess firewall preventing malicious queries.

WordPress Syntax Highlighter – Advance Usage and Customizing of GISTs

I’ve used many syntax highlighters over the years for pasting and sharing code snippets. In that time I’ve never had any luck with WordPress ones that save the snippets save in post_content. In my experience with it, there seems to be this constant battle for the characters being escaped or not, especially when switching between the Visual/Text tabs frequently.

Until someone builds a module experience in the inline editor (like how the “Image Gallery” displays as a block in TinyMCE, and a lightbox for edit), external posting and embedding of snippets is the way to go.

I’ve done that on this site, using the king, Gist. I used this plugin and a few edits in CSS, WordPress, and to the DOM to get things working how I want.

Anyways, here’s how I do it:

So to get the above, all I did was:

So, just like Youtube videos, a single line URL of a secret gist, and it’ll auto-embed. The post_content action replaces it with what’s required of the gist-embed plugin, you can configure the attributes there to fit your needs. I set a max-height and add a SHOW MORE trigger with basic jQuery and CSS.

You can show a single file of a multi-file gist by manually appending the sensitized filename to the url as an anchor, e.g. #your-file-name.html

Add All Super Admins To All Sites On WordPress

One of the most annoying features of WordPress Multisites (besides domain mapping) is adding a Super Admin a few years after your network is established and grown. Sure, being a Super Admin allows said user to access any site on the network, but the user is technically not added to the site – so the Super Admins users My Sites tab will only have sites that s/he has been manually added to. The user is then forced to jump between sites with a headache of manually typing.

The follow script solves the problem, it runs through all super admins and adds them to all sites in the network they’re not yet added to.

The function needs to be run once to get everyone up to date. For the future it can be wrapped in a $_GET conditional to fire manually, a cronjob to run in background, or like I did, a transient, so that you can run it as often as you need. Mind you this isn’t a network plugin or intended to run on all sites, it just needs to run once on a single site. All the multisite data and blog_switching annoyance happens within the functions themselves.

Quickly And Easily Send To Slack via PHP Function

Quickly And Easily Send To Slack via PHP Function

Building a PHP app that communicates with Slack a lot, I found it was much cleaner to tuck everything away in a function and call it in a single function that resembles the attributes of mail(). This makes for changing your apps icon andor color easy, as well as staying consistent with the Title and PreText.

Slack Incoming Hook required.

One Password Form For All Password Protected WordPress Posts

When using a custom post type for portfolio items, I needed several of them to be password protected, showing a lock icon instead of the portfolio item. The posts are shown via a normal loop, but they’re just thumbnails with lightbox links. To password protect them all, and have them all unlock with a single method, I came up with the following:

For the above to work, all posts passwords need to be the same password. The above uses featherlight, or whatever lightbox you prefer to hide/reveal the password form. Remove the display:none from #passwordInput to bypass lightbox.