Category Archives: Coding

All about coding

[SOLVED] WooCommerce conditional fields for gifts options on checkout

Built a web site recently using WooCommerce and decided that a gift wrapping option would be wonderful idea when user checks out.

However, the WooCommerce Checkout Add-Ons plugin whilst its great, is still in its infancy and on the checkout page, it simply populates the page with all the add ons, so makes the checkout page look HUGE!

My idea, was to add a checkbox asking the user if they wanted to gift wrap the order and then when checked, a list of the options would appear.

 

[SOLVED] MAMP – allowing clients to view dev sites on your local machine (with dynamic ip)

As a web developer, I like to work on web sites on my local machine and then give clients a link to the site which is hosted on my local machine so they can view progress. This save me A LOT of time syncing with remote servers as the client can view the dev site in real time on my computer.

The link I give to the client looks something like this: http://dev.theirdomain.com so essentially its not any weird hostname, its a very familiar and easy to remember link as it will contain their domain name.

Below you will find the steps necessary to make this magic happen.

Checklist before you start


There are a few essential pieces of stuff you need before you start setting things up.

  1. You need to know the ip of your local machine on your current local network (usually its something like 192.168.1.x). You should be able to find this in your network settings on your computer (for step 3).
  2. You need to have a dyn.com “DynDNS Pro and Host Services” account, which costs $40 a year (WELL WORTH IT if you have more than one dev site).
  3. You need to have your site configured inside of MAMP like dev.theirdomain.com (see step 2).
  4. You need to have admin access to your router in order to add a NAT rule (for step 4).

Why use dyn.com?
dyn.com offer a great little utility tool for mac and windows so that if your ip changes, then your dynamic dns hostname also gets updated automatically so you don’t need to keep logging into to update your ip.

See: https://dyn.com/updater-mac/ <—get this (very useful)


OKAY! Lets go!

Step 1

Make sure your MAMP ports are configured to port 80.

Step 2

Make sure your MAMP site has a proper dns domain name.

Step 3

Create a DNS alias over at dyn.com and make a note of the new hostname you create as you will need to create a cname record with the alias on the clients domain name.

For the sake of our exercise the host name at dyn.com is: devsites.dyndns.com.

IMPORTANT: make a note of the new dyn.com hostname as you will need it for the CNAME records on your clients domain DNS.

Step 4

Create a sub domain on your client’s dns with the hostname you created at dyn.com.

Step 4 (FINAL STEP)

Update your router so that external requests to the devsites domain are routed to your computer.

This part can be a little daunting for some as you have to dig into the advanced settings of your router.

I have a router given to me by my Spanish ISP, your might differ but for the most part a lot of the navigation will be similar.

Just make sure that you are looking for NAT and make sure you have your local IP to hand.

In Conclusion

As long as you have followed each step carefully, if your clients browses to the dev domain you have created, then they will see the development version of their web site running on your local machine.

Obviously, it goes without saying that you need to have MAMP running in order for them to view the site and your computer is connected to the internet.

[SOLVED] How to remove 2FA from WHMCS Login Page

WHMCS is great, for the most part, but last night I tried to login to my WHMCS admin panel with my google two factor auth only to be met with an error saying my 2fa code was incorrect.

I even tried using the backup code and still met with an error.

I raised a ticket with WHMCS 12 hours ago, no response yet. GRRRRR!

THE SOLUTION
If you have access to the WHMCS database through phpmyadmin or similar then find the table called: tbladmins.

Then find the column called “authmodule”.

Clear whatever is in that field (mine said “totp”).

You will then be able to access WHCMS admin without using 2fa.

[Solved] Get Array of Terms for Custom Post Type Outside of Loop with Post ID

Every stone I overturned looking for the answer to this issue I was met with “use wp_get_post_terms()” but unfortunately it does not work on custom post types.

The solution, after much digging and experimenting is to use get_the_term_list() but with a couple of twists.

Now, I have a custom post type called “faq”.

To get the “terms” or “tags” for the “faq” post type you need to know what the “taxonomy name” is. In this case, the taxonomy name is “faqs-tags”.

To find out the taxonomy name for the custom post type, check the screenshot below. Easy!

[SOLVED] Get ENOM balance into WHMCS

I have been running WHMCS for a while now and have had to keep logging into ENOM to get my balance which is a hassle as I have two factor auth and security questions setup so takes me a minute to get through all of that.

Here is some php script you can put in a WHMCS widget to display your enom balance in your admin dashboard saving you some time.

We are using simplexml to parse the results.

Result will be something like this.

get-enom-balance-into-whmcs

[Solved] CSF/LFD Stop Emails containing “Suspicious process running under use X”

CSF really is an excellent IP Tables wrapper but these alerts can become a burden and you can essentially receive hundreds of them per day. Okay, for sure, the goal should be to fix the issues first but if you are a busy server admin, then this can take time so if you need to disable the emails, then just follow the steps below.

1. Edit the CSF config file

2. Search for the following settings PT_USERMEM and PT_USERTIME and set them both to 0.

3. Restart CSf and LFD

The warning emails should stop coming now.

[SOLVED] – WHM Cpanel on Amazon EC2 Servers + FTP TLS Dreamweaver Issue

One of my customers has an Amazon EC2 instance with WHM installed. A decision was made recently to close off port 21 and force FTP over TLS for better security during ftp sessions.

However, one of the team was saying they could not get Dreamweaver to connect  and was getting an error when trying to connect with TLS. All his settings seemed fine and in fact I also was able to replicate his issue on my local copy of Dreamweaver CC 2016 so I turned my attention to the web server on Amazon.

After ALOT of searching about, I found that, if we want to force FTP over TLS on an Amazon EC2 instance, I  had to make a change to the /etc/pure-ftpd.conf file by adding the main server ip to the ForcePassiveIP setting. The reason for this is that EC2 instances use NAT routing and dynamic IP’s and you need to provide a fixed IP so that the passive mode can send the return response back down the correct route, otherwise it does not know where to go.

Here is the changes I had to make.

Side Note: If you are forcing TLS, then make sure that you have already configured your PassivePortRange inside the /etc/pure-ftpd.conf file and also allowed the ports to be open on your firewall. Here is another post giving some details on how to do that.

STEP 1: Open up the FTP config file.

STEP 2: Add your server IP to the ForcePassiveIP setting. This will be the main Public IP of your server.

STEP 3: Restart FTP server

After that, TLS on Dreamweaver was working perfectly.

 

Using CURL with PHP to send POST field data using http header Authentication

Okay, so until now I had been using api keys passed through the post fields but on a more recent project I was asked to send the api key through the headers when making the request, so I have made myself a little function to use curl and pass the api key through CURLOPT_HTTPHEADER.

This will be the call to your curl function and you can print out the results of the call.

 

[SOLVED] Allow WordPress to accept plus (+) sign in usernames

It was revealed to me recently that a wordpress system which programatically creates user accounts via an external api, where we only allow email addresses as the username, anyone submitting a + sign in the username, the plus sign (+) was being stripped out.

For Example:
joe.bloggs+1@gmail.com was becoming joe.bloggs1@gmail.com (wordpress was stripping out the + sign).

So after a bit of sifting around the interwebs, I came across a plugin which allows foreign characters like Arabic and Cyrillic. So not exactly what I was looking for but I figured I could use some of the code.

Drop the following into your functions.php so that it overrides the filtering of the usernames when sanitize_user is called from WordPress core and edit the $allowed_symbols to permit the characters you would like in the new username when its created.

[SOLVED] Add a Custom Column in Custom Post Types Admin Screen Displaying Relational Data From Another Custom Post Type

I had a situation recently with WordPress where I had to display the Company Name against the Attendee profile when viewing a list of Attendees inside the WordPress admin.

Basically there was two custom post types (CPT’s), one was called “attendee” and the other “companies”. When editing an Attendee record we would assign it to a company so that we knew which Company the Attendee was assigned to.

After some ideas from the Advanced WordPress forum on Facebook, this is what I ended up with and code is included below.

custom-column-in-custom-post-type-admin-screen

Here is the code which I inserted into the themes functions.php to display the company name against the attendee record.