Skip to content

Instantly share code, notes, and snippets.

View jan-koch's full-sized avatar

Jan Koch jan-koch

View GitHub Profile
@jan-koch
jan-koch / Commands for Module 3
Last active September 11, 2019 11:22
Commands to install Jenkins on a Ubuntu 18.04 droplet in Digital Ocean. (Run as root)
// First add the repository key to the system.
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
// Append the Debian repository to your server's sources.list
sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
// Update your package index
apt update
// Run an upgrade
@jan-koch
jan-koch / commands.sh
Created September 12, 2019 05:04
Commands for Module 2. These commands need to be executed in the folder you want to automatically deploy.
// Install PHPloy in your project
composer require "banago/phploy"
// Initialize PHPloy in the project folder
phploy --init
@jan-koch
jan-koch / Jenkinsfile
Last active September 12, 2019 05:08
Jenkinsfile for automated deployment with Github and PHPloy
pipeline {
agent any
// Pull the repo first.
stages {
stage( 'Checkout Repo' ) {
steps {
checkout scm
}
}
stage( 'Deploy' ) {
@jan-koch
jan-koch / phploy.ini
Created September 12, 2019 05:11
Module 2. Example of a phploy.ini file you can customize for your own needs. This file goes into the root of the folder you want to automatically deploy.
; This is a sample phploy.ini file. You can specify as many
; servers as you need and use normal or quickmode configuration.
;
; NOTE: If a value in the .ini file contains any non-alphanumeric
; characters it needs to be enclosed in double-quotes (").
; The server names in the brackets need to match the server names
; you reference in your Jenkinsfile.
[production]
@jan-koch
jan-koch / Jenkinsfile
Created October 9, 2019 05:39
An example Jenkinsfile that stops deployment if your method complexity is above 20, based on the static code analysis of PHPloc.
pipeline {
agent any
tools {
ant 'ant'
}
// Pull the repo first.
stages {
stage( 'Checkout Repo' ) {
@jan-koch
jan-koch / export_database_with_replace.sh
Created June 8, 2019 07:20
Bash script to export a database from a WordPress container and perform a search/replace using the UNIX command "sed". Script is based on https://hub.docker.com/r/jankoch/wordpress.
#! /bin/bash
CONTAINER=$1
SEARCH=$2
REPLACE=$3
# Dump the file
DUMP=$(docker exec $CONTAINER wp db export --add-drop-table --porcelain)
@jan-koch
jan-koch / remove-woo-scripts.php
Created February 28, 2020 09:14
Remove WooCommerce related resources except on WooCommerce-based pages (products, cart, checkout, etc). Use on a testing environment before pasting this into your live website!
/**
* This code snippet removes JavaScript and CSS files loaded from WooCommerce if they are not necessary.
*
* Please test this on a staging copy of your website before putting this into the functions.php of your live website.
*/
add_action( 'wp_enqueue_scripts', 'my_remove_woo_assets', 99 );
function my_remove_woo_assets() {
if ( function_exists( 'is_woocommerce' ) ) { // Check if Woo is installed.
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { // Only run on non-Woo pages.
// Remove unnecessary stylesheets.
@jan-koch
jan-koch / piccia.css
Created August 15, 2020 16:53
CSS for Piccia's progress bar
.gf_progressbar {
margin-left: -40px;
}
.gf_progressbar .gf_progressbar_percentage > span {
position: absolute;
left: -40px;
top: -2px;
}
@jan-koch
jan-koch / woo-text-input.php
Created November 15, 2018 10:35
Example for adding a text input field to the WooCommerce "General" tab.
<?php
function prefix_add_text_input() {
$args = array(
'label' => '', // Text in the label in the editor.
'placeholder' => '', // Give examples or suggestions as placeholder
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post_meta
'id' => '', // required, will be used as meta_key
@jan-koch
jan-koch / woo-textarea.php
Created November 15, 2018 12:05
Example of adding a custom textarea to the "General" tab of a WooCommerce product.
<?php
function prefix_add_textarea() {
$args = array(
'label' => '', // Text in the label in the editor view
'placeholder' => '', // Give advice or examples as placeholder
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, will be loaded as meta_value for the meta_key with the given id