Skip to content

Instantly share code, notes, and snippets.

View chrisjangl's full-sized avatar

Chris Jangl chrisjangl

  • Wine Enthusiast, Digitally Cultured
  • NY
  • 20:11 (UTC -04:00)
View GitHub Profile
@chrisjangl
chrisjangl / reset_admin_password.sh
Last active November 24, 2021 12:28
Working from a list of WordPress sites on a shared hosting environment (sites.txt), reset the password for a given user account on each of them. It also creates a report of the admin users on each site
i=1
touch users.txt
COUNT=$(wc -l sites.txt)
for SITE in $(cat sites.txt)
do
cd $SITE
echo "Working on $SITE ($i of $COUNT)..."
echo "## $SITE" >> ../users.txt
wp user list --role=administrator --fields=user_login,user_email >> ../users.txt
echo "----------------" >> ../users.txt
@chrisjangl
chrisjangl / mail-test.php
Created June 14, 2021 12:24
Test whether PHP mail is working on a server
<!DOCTYPE html>
<html>
<head>
<title>Test mail services</title>
</head>
<body>
<h1>Test out the mail functionality on a server</h1>
<?php
$timestamp = "today";
// $timestamp = new DateTime('Y-m-d H:i:s');
@chrisjangl
chrisjangl / remove_custom_post_type_slug.php
Last active July 10, 2020 20:00
removes the slug from a custom post type
/**
* credit to: https://wordpress.stackexchange.com/q/291735
*
*/
/**
* remove the slug from published gallery permalinks.
*
* Makes sure to only touch our CPT
*
@chrisjangl
chrisjangl / secondary-wp_query.php
Last active June 22, 2020 15:17
Create a custom WP_Query, and loop through the results, making sure to reset the query afterward
<?php
/**
* create a custom query, using specific arguments, making sure to reset
* the query afterward.
*/
function create_secondary_query() {
// for list of possible arguments, @see https://developer.wordpress.org/reference/classes/wp_query/#parameters
$args = array(
@chrisjangl
chrisjangl / .htaccess
Last active June 21, 2020 16:00
.htaccess to host WordPress in a subdirectory. Some shared hosting won't let your primary domain be assigned to a subdirectory - this will help to get around that.
# replace <domainname> with your domain name
# replace <directoryname> with the name of the directory where WordPress is located
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?<domainname>.com$
RewriteCond %{REQUEST_URI} !^/<directoryname>/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<directoryname>/$1
@chrisjangl
chrisjangl / Ninja Forms email notification template
Last active April 21, 2021 18:01
Template for Ninja Forms email notification, with HTML formatting.
<h2>Contact Info</h2>
<div style="margin-bottom: 10px;"><br>
<p>
Name: <b>{field:name}</b><br>
Email: <b><a href="mailto:{field:email}">{field:email}</a></b><br>
Phone: <b><a href="tel:{field:phone}">{field:phone}</a></b><br>
</p>
</div>
<hr>
@chrisjangl
chrisjangl / .bash_aliases
Last active December 15, 2019 15:16
Listing of bash aliases. Place in home directory, and make sure that the file is being loaded in .bash_rc.
## binary shortcuts
alias node='nodejs'
alias wp='~/wp-cli.phar'
## environment specific frecents
alias clients='cd ~/public_html/clients/'
alias staging='cd ~/public_html/staging/'
## directory traversal
alias ..='cd ../'
@chrisjangl
chrisjangl / .htaccess
Last active January 1, 2020 17:56
Load images requested on a local/dev (or any)WordPress site from the production (or any other) site. Make sure to add this snipped ABOVE the WordPress rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(wp-content/uploads/\d{4}/\d\d/.*\.jpg)$ https://<your-production-url>.com/$1 [QSA,L]
RewriteRule ^(wp-content/uploads/\d{4}/\d\d/.*\.png)$ https://<your-production-url>.com/$1 [QSA,L]
</IfModule>
@chrisjangl
chrisjangl / find_page_template.sql
Created May 17, 2019 15:03
WordPress: SQL query to find all pages that use a certain page template. Can use WP CLI to run this query without have to log into cPanel/phpMyAdmin. Need to replace <wp_prefix_> & <page-template.php> to match your setup.
SELECT * FROM `<wp_prefix_>postmeta` WHERE `meta_key` LIKE '_wp_page_template' AND `meta_value` LIKE '<page-tempate.php>'
@chrisjangl
chrisjangl / updateWordPressPlugins.sh
Last active July 13, 2022 12:13
WP CLI script to update active plugins, and commit each update individually. 99% percent stolen from https://markjaquith.wordpress.com/2018/02/12/updating-plugins-using-git-and-wp-cli/, (ever so slightly) adapted to my own personal workflow
for plugin in $(wp plugin list --update=available --status=active --field=name);
do
TITLE=$(wp plugin get $plugin --field=title)
wp plugin update $plugin &&
VERSION=$(wp plugin get $plugin --field=version)
git add -A wp-content/plugins/$plugin &&
git commit -m "$(printf "update plugin: $TITLE to $VERSION")"
echo "$TITLE -> $VERSION" >> updated.txt
done;