ClassicPress Development with GitHub: Sign up for GitHub

GitHubWhen I started developing plugins for ClassicPress I decided that I needed to be using source control. As ClassicPress is intending to use GitHub for their plugin directory, it made sense for me to use it as well. This post is part of a series on ClassicPress Development with GitHub.

The first step to using GitHub for developing with ClasssicPress, is to create a GitHub account; navigate to the landing page, enter a Username, Email and Password and click the large green Sign up for Github button:

Sign up for GitHub

Continue reading “ClassicPress Development with GitHub: Sign up for GitHub”

ClassicPress Development with GitHub: Series Index

GitHubI have been using ClassicPress to run this blog, and several other sites, since early last year. I have also created new versions of all of my plugins for ClassicPress.

When I was working with plugins for WordPress, I used their Plugin Repository for source control which was based off SVN. This wasn’t really the ideal way of doing things, as I should have had my own source control for development purposes.

At the start of 2019, GitHub announced new unlimited repositories (amongst some other changes) which made GitHub a viable source control tool for me.

The added bonus of using GitHub is that ClassicPress mean to use it for their Plugin Directory which is scheduled for inclusion in version 2. Development of this is in the early stages now, but using GitHub for my own development means I am at least part way to being compatible with the directory when it is launched.

I have over a hundred repositories now on GitHub (although you’ll see a much smaller number as quite a few are private). I took some screenshots when I started and meant to blog about it and then got sidetracked. In this series of posts I am going back to my intended posts, in which I am going to cover the basics of using GitHub for development of ClassicPress plugins.

This is a weekend series of posts with new posts going live over the next few weeks. If you’re reading this on azurecurve|Ramblings of a Dynamics GP Consultant the index will update automatically.

Separately compress all sub folders

7-ZipI started using WordPress for this blog when it launched in June 2011 until last year when, with Gutenberg on the horizon, I migrated to ClassicPress. This migration was easy as ClassicPress is a hard-fork of WordPress 4.9. As part od the migration I opted to rewrite all of my plugins to improve them and make them more secure.

I have 32 publically available plugins for ClassicPress. I’ve recently made changes to all of the plugins which means I need to make a release of them.

This partly done by committing the changes to Git Hub and making a tag, but you also need to add a zip file. There are commands to do this automatically on GitHub, but I am quote new so am opting to create the zips myself and upload them.

To do this I wanted to automatically compress all of the plugin folders, but exclude any hidden folders (such as the .git folder). I did some exploring and found the required command on Stack Overflow using 7-zip:

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a -xr!.git\ -xr!*~ "%%X.zip" "%%X\"

The question which had previously been asked was this one and the two answers I used were this and this.

Calculate distance using longitude and latitude on MariaDB

MariaDBI’ve recently been doing some more work on my coppr|Distilleries to Visit website and have added Nearest Distilleries and Nearest Attractions sections where I show the nearest 20 distilleries or attractions to the one beign viewed.

To do this I loaded GPS co-ordinates to each page and then needed to work out how to calculate the distance between them.

Initially I found the ST_Distance MySQL function which seemed like it would do the job. A little more reading though suggested that it would calculate distance between two points on a flat surface, but ot on a (almost) sphere like the Earth.

ST_Distance_Sphere then seemed a good option. I wrote some code and uploaded the page to test and received an error that the function didn’t exist.

After doing some investigation, I spoke to my web host and discovered that they were not using MySQL, but rather used MariaDB which does not have that function.

After some more investigation on options, I came across an old post on using the Haversine formula to calculate distance. The post had sample code in PHP and MySQL with the latter being what I wanted.

The only real difference between the code on the blog and the below, is MySQL no longer allows the use of alias in a WHERE clause so I’ve changed it to a HAVING clause:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
$sql = "SELECT T2.* ,ROUND((((acos(sin((T1.latitude * pi()/180)) * sin((T2.latitude * pi()/180)) + cos((T1.latitude * pi()/180)) * cos((T2.latitude * pi()/180)) * cos(((T1.longitude- T2.longitude) * pi()/180)))) * 180/pi()) * 60 * 1.1515),2) AS DISTANCE FROM {table1} AS T1 INNER JOIN {table2} AS T2 ON T2.ID = T1.ID HAVING DISTANCE <= 100";

azurecurve ClassicPress Plugins updated

ClassicPress PluginsI migrated to ClassicPress last year and created ClassicPress versions of all of my plugins. This wasn;t just a case of creating an alternate versions, but extensively rewriting them in order to both add new functionality and to improve their security.

I’ve recently made changes to them all again to further improve them. If you use any of my plugins list on my Development site, you should download and install the latest version.

ClassicPress v2 is to include a Plugin Directory which is meant to be available in the second-half of 2020 which will mean automatic updates will then be available.

Making compressed MySQL backups of multiple databases using Cron

Cron JobsI’ve posted a couple of articles now on making MySQL backups using Cron, time-based scheduler, on Linux based hosting.

This is, currently, the last post on this subject. The examples so far have been on backing up single databases, but it is possible to backup multiple databases using one command.

The below example shows the syntax to make a compressed backup of all mySQL databases, with the sections to change highlighted:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
/usr/bin/mysqldump -u {username} -p'{password}' --all-databases | gzip -c > /home/{username}/backups/backup_{databasename}_$(date +\%Y\%m\%d\%H\%M\%S).sql.gz

The below example shows the syntax to make a compressed backup of multiple named mySQL databases, with the sections to change highlighted (any additional database names can be specified):

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
/usr/bin/mysqldump -u {username} -p'{password}' --databases {databasename} {databasename} | gzip -c > /home/{username}/backups/backup_{databasename}_$(date +\%Y\%m\%d\%H\%M\%S).sql.gz

Making compressed MySQL backups using Cron

Cron JobsEarlier this month I posted an article on making MySQL backups using Cron, time-based scheduler, on Linux based hosting.

Since then I’ve realised that I have two databases which are well over 1GB in size and have now looked into making compressed backups.

The below example shows the syntax to make a compressed backup of a mySQL database, with the sections to change highlighted:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
/usr/bin/mysqldump -u {username}-p'{password}' {databasename} | gzip -c > /home/{username}/backups/backup_{databasename}_$(date +\%Y\%m\%d\%H\%M\%S).sql.gz

This is only a little different to the uncompressed backup syntax, but results in a file of much smaller size.

Making folder backups using Cron

Cron JobsAs I mentioned in yesterdays post on making backups of mySQL databases, earlier this year I migrated from a Microsoft Windows based web hosting package to a Linux based one. This meant I had to learn a few new ways of doing things, such as backing up databases or files, on a regular repeating basis.

This is accomplished on Linux web hosts using the Cron time-based scheduler. I needed to create two types of cron jobs; one to backup databases and one to backup files. Yesterdays post was on the databases and todays is on backing up files.

The syntax for backing up a files using Cron jobs will largely be the same on all web hosts.

The below example shows the syntax to backup a files, with the sections to change highlighted:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
/bin/tar -czvf /home/{username}/backups/backup_{sitename}_$(date +\%Y\%m\%d\%H\%M\%S).tar.gz /home/{username}/{foldername}

Making mySQL backups using Cron

Cron JobsEarlier this year I migrated from a Microsoft Windows based web hosting package to a Linux based one. This meant I had to learn a few new ways of doing things, such as backing up databases or files, on a regular repeating basis.

This is accomplished on Linux web hosts using the Cron time-based scheduler. I needed to create two types of cron jobs; one to backup databases and one to backup files.

The syntax for backing up a MySQL database using Cron jobs will largely be the same on all web hosts.

The below example shows the syntax to backup a mySQL database, with the sections to change highlighted:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
/usr/bin/mysqldump -u {username} -p'{password}' {databasename} > /home/{username}/backups/backup_{databasename}_$(date +\%Y\%m\%d\%H\%M\%S).sql

WordPress/ClassicPress Plugin Development: Checking If Function Exists In Namespace

WordPress PluginI’ve been developing my own plugins for WordPress and, more reently, ClassicPress. At times it’s been necessary to check if a function exists.

It’s fairly straightforward to do this check:

if (!function_exists('azrcrv_get_breadrumbs')){
	// code here
}

I also use a few plugins developed by other people. One of the ones I’ve been reviewing recently is Estimated Read Time by CodePotent.

John uses namespaces in his plugins which means the check also needs to include the namespace. You can check for this using the following syntax (the highlighted section is the namespace defined in the plugin):

if (function_exists('CodePotent\EstimatedReadTime\process_shortcode')){
	// code here
}

I’m posting this as a reminder to myself as it took me a few minutes of searching before I found the right answer.