Skip to content

Instantly share code, notes, and snippets.

View craigiswayne's full-sized avatar

Craig Wayne craigiswayne

View GitHub Profile
@craigiswayne
craigiswayne / install-wp-cli-composer-imagick.sh
Last active January 29, 2019 08:25
Install WP-CLI, Composer and Imagick on Digital Ocean WordPress Droplet (Ubuntu 16)
echo "Installing WP-CLI...";
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
echo "Installing Composer...";
sudo apt-get update;
sudo apt-get install curl php-cli php-mbstring git unzip -y;
cd ~;
@craigiswayne
craigiswayne / create-dummy-posts.sh
Created January 26, 2019 11:03
Batch Create WordPress Posts via wp-cli
###
# Creates 30 dummy posts with featured images via placeimg.com
###
POST_TYPE_SLUG=post;
POST_TYPE_SINGULAR_NAME=Post;
for i in {1..31}
do
echo "Creating $POST_TYPE_SINGULAR_NAME i = [$i]";
post_id=$(wp post create --post_name="Entrant $i" --post_title="Entry $i" --post_type="$POST_TYPE_SLUG" --post_status=publish --post_author=1 --post_date="1987-10-$i 00:00:00" --porcelain --allow-root);
echo "post_id = [$post_id]";
@craigiswayne
craigiswayne / reset_admin_user.sh
Last active October 31, 2018 10:17
Reset WP Admin User
function wp_reset_admin_user () {
echo "#################################";
echo "Resetting the Admin User...";
email="admin@localhost.com"
username=admin;
name=$username;
admin_pass=$username;
echo "Attempting to create User with username: $username";
@craigiswayne
craigiswayne / script.sh
Last active October 28, 2018 21:51
Create WordPress Posts with Featured Images from WP-CLI
for i in {1..20}
do
post_type="post";
post_type_singular="Entrant";
post_title="$post_type_singular $i";
post_id=$(wp post create --post_author=admin --post_type=$post_type --post_status=publish --post_content="$post_title Content" --post_title="$post_title" --post_excerpt="$post_title Excerpt" --porcelain);
wp media import "https://picsum.photos/480/640/?random&$i.jpeg" --post_id=$post_id --title="Random Image for $post_title" --caption="$post_title Caption" --alt="$post_title Alternative Text" --desc="$post_title Desciption" --featured_image;
done
@craigiswayne
craigiswayne / composer.json
Last active October 8, 2018 21:06
Requiring non composer package in composer
"repositories": [
{
"type": "package",
"package": {
"name": "vendor-name/package-name",
"version": "dev-master",
"type": "library",
"source": {
"url": "https://gitlab.com/vendor-name/package-name.git",
"type": "git",
@craigiswayne
craigiswayne / functions.php
Created September 20, 2018 10:27
How to Render YouTube Video in WordPress (given the URL)
<?php
$ytURL = https://www.youtube.com/watch?v=dQw4w9WgXcQ;
echo wp_oembed_get( $ytURL );
@craigiswayne
craigiswayne / extensibility.sh
Last active July 12, 2018 23:17
How Extensible is a WordPress Plugin
# Find all do_action's and add_action's
grep -En "(add|do)_action\(" . -R --context=2 --include="*.php"
# Find all apply_filter's and add_filter's
grep -En "(apply|add)_filters?\(" . -R --context=2 --include="*.php"
@craigiswayne
craigiswayne / window.open.debug.js
Last active June 25, 2018 10:26
Debugging the window.open function
/**
* Debugging window.open function
* Overwrites the origin window.open function so that you can see the call stack
* And debug variables
* @see https://www.w3schools.com/Jsref/met_win_open.asp
*/
window.open = function( URL, name, specs, replace ){
console.group("Debugging the window.open function");
console.log("URL : " + URL);
console.log("name : " + name);
@craigiswayne
craigiswayne / README.md
Created June 8, 2018 12:44
How i tried to test my Travis Build Locally (for PHP)

How i tried to test my Travis Build Locally (for PHP)

TLDR; didn't work

docker run --name travis-debug -dit travisci/ci-garnet:packer-1512502276-986baf0 /sbin/init
docker exec -it travis-debug bash -l

From inside the docker container

@craigiswayne
craigiswayne / follow_url.sh
Created May 29, 2018 07:40
Follow Redirects on URL
URL=www.google.com
curl -sILk $URL;