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.

PowerShell script to download all files from FTP folder then delete files

PowerShellA few weeks ago, I did an article on making folder backups on an FTP site and compressed MySQL backups using Cron.

With the backups made, they need to be downloaded and this is not something I want to do manually. My initial thought was VBA until common sense kicked in and I opted for PowerShell. I found a post on Stack overflow which had the required script to connect to an FTP site and download files which got me half of what I needed.

I did some reading up and was able to work out the function to delete files on an FTP site and have included that in the PowerShell below so that this script both downloads files and deletes them.

There are several parameters which need to be set and these are placed at the top and highlighted to make them easy to identify; make sure all of the highlighted parts are replaced including the curly brackets.

#FTP Server Information - SET VARIABLES
$ftp = "{ftp site}"
$user = "{user}"
$pass = "{password}"
$folder = "{source folder}"
$target = "{destination folder}"

#Register get FTP Directory function
function Get-FtpDir ($url, $credentials) {
	$request = [Net.WebRequest]::Create($url)
	$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory

	if ($credentials) { $request.Credentials = $credentials }
	
	$response = $request.GetResponse()
	$reader = New-Object IO.StreamReader $response.GetResponseStream() 
	
	while(-not $reader.EndOfStream) {
		$reader.ReadLine()
	}
	
	$reader.Close()
	$response.Close()
}

#Register Delete function
function Del-FtpFile($source, $credentials) {
    $source2 = [system.URI] $source
	
    $ftp = [System.Net.FtpWebRequest]::create($source2)
    $ftp.Credentials = $credentials

    $ftp.Method = [System.Net.WebRequestMethods+Ftp]::DeleteFile
	
    $ftp.GetResponse()
}

#Set Crednetials
$credentials = new-object System.Net.NetworkCredential($user, $pass)

#set folder path
$folderPath= $ftp + "/" + $folder + "/"

$files = Get-FTPDir -url $folderPath -credentials $credentials

$webclient = New-Object System.Net.WebClient 
$webclient.Credentials = $credentials 
$counter = 0
foreach ($file in ($files | where {$_ -like "*.gz"})){
	$source = $folderPath + $file  
	$destination = $target + $file 
	$webclient.DownloadFile($source, $destination)
	
	#PRINT FILE NAME AND COUNTER
	$counter++
	$source
	
	# DELETE FILE
	Del-FtpFile -source $source -credentials $credentials
}

azurecurve ClassicPress Plugins: Translating Plugins

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins which introduces the plugins I have available for ClassicPress.

All of the plugins I have created for ClassicPress have been created to support translations. I only speak English so the plugins currently only ship with English vailable; pot files are included in the plugins /languages folder which can be used to translate the plugin using software such as PO Edit.

In addition, I have a translation website which can be used to translate plugins without needing to install any software. To request a language be added for translation, visit my community site and ask for the language to be added.

azurecurve ClassicPress Plugins: Support for Plugins

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins which introduces the plugins I have available for ClassicPress.

Over the course of this series, I have announced all of the plugins I have created for ClassicPress. I have created a Community site where I will provide support.

Whether you have a bug report, feature request, question or want to translate the plugin, this site is the place to go.

azurecurve ClassicPress Plugins: Loop Injection

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins series which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is a brand new one written specially for ClassicPress; Loop Injection.

Functionality

Allows content to be injected before, within and after the loop. All content is configurable via an admin settings page; perfect for adverts.

Each of the three content locations can be activated individually; location within the loop is configurable.

Shortcodes are supported in Loop Injection; allows Snippets to be used.

Demo

The advert five posts down on the homepage and archives has been inserted using this plugin.

Download

The plugin can be downloaded via my Development site.

azurecurve ClassicPress Plugins: Add Twitter Cards

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins series which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is a brand new one written specially for ClassicPress; Add Twitter Cards.

Functionality

Use Add Twitter Cards to attach rich photos to Tweets, helping to drive traffic to your website.

Options allow:

  • Card Types of Summary or Summary With Images.
  • Excerpt or first 200 characters of post added to card.
  • Thumbnail or first post image will be added to card.
  • Integrate with [Floating Featured Images](https:/development.azurecurve.co.uk/classicpress-plugins/floating-featured-image/) for card image.

Demo

You can see this plugin in action by Tweeting this, or any other post, using the available sharing buttons.

Download

The plugin can be downloaded via my Development site.

azurecurve ClassicPress Plugins: URL Shortener

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is a fork of someone elses plugin which I initially created a long time ago, but am now releasing it for others to use; URL Shortener.

Functionality

This plugin allows a fucntion call to be placed on a post or page to display a short URL.

The structure of the short URL is configurable via the plugins Settings page.

Demo

Both this site and azurecurve|GP Table Reference make extensive use of this plugin.

Short URLs are automatically generated for every post, page and custom post type on post creation. Custom short URLs can be assigned to all posts.

Download

The plugin can be downloaded via my Development site.

azurecurve ClassicPress Plugins: Toggle Show/Hide

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is an existing one which has been brought up to coding standards; Toggle Show/Hide.

Functionality

The Toggle Show/Hide shortcode allows content to be hidden until the user clicks the link. Default settings for the toggles can be set via the plugins Settings page, although these can be overridden on any toggle by setting parameters.

Demo

The Toggle Show/Hide plugin is used in numerous places on this site; the Buy My Books section on the sidebar is probably the easiest place to see this in action.

Download

The plugin can be downloaded via my Development site.

azurecurve ClassicPress Plugins: Timelines

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is an existing one which has been brought up to coding standards; Timelines.

Functionality

The Timelines plugin allows a timeline of events to be created using a custom post type and displayed using a timeline shortcode.

Demo

You can see the timeline in action on my Experience page.

Download

The plugin can be downloaded via my Development site.

azurecurve ClassicPress Plugins: Theme Switcher

ClassicPress PluginsThis is part of the azurecurve ClassicPress Plugins which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is an existing one which has been brought up to coding standards; Theme Switcher.

Functionality

Theme Switcher allows users to switch between different themes using the supplied widget; example uses would be to allow them to change mode between light and dark themes.

Demo

This site uses Theme Switcher to allow users to Change Mode between light and dark; you can try this using the Change Mode widget in the sidebar.

Download

The plugin can be downloaded via my Development site.