Skip to content

Instantly share code, notes, and snippets.

View chrisjangl's full-sized avatar

Chris Jangl chrisjangl

  • Wine Enthusiast, Digitally Cultured
  • NY
  • 18:00 (UTC -04:00)
View GitHub Profile
@chrisjangl
chrisjangl / admin_email_report.sh
Created November 24, 2021 12:30
Working from a list of WordPress sites on a shared hosting environment (sites.txt), create a report of the admin email for each. Includes a link to the settings page to update the value.
i=1
touch admin-email.txt
COUNT=$(wc -l sites.txt)
for SITE in $(cat sites.txt)
do
cd $SITE
echo "Working on $SITE ($i of $COUNT)..."
echo "## $SITE" >> ../admin-email.txt
url=$(wp option get siteurl)
postURL="/wp-admin/options-general.php"
@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 / DB_report.sh
Created November 24, 2021 12:28
Working from a list of WordPress sites on a shared hosting environment (sites.txt), this script will print the DB name and login URL for each site.
i=1
touch urls.txt
COUNT=$(wc -l sites.txt)
for SITE in $(cat sites.txt)
do
cd $SITE
echo "Working on $SITE ($i of $COUNT)..."
echo "## $SITE" >> ../urls.txt
url=$(wp option get siteurl)
postURL="/wp-login.php"
@chrisjangl
chrisjangl / .gitignore
Last active August 23, 2021 16:42
gitignore to track entire WP site. Excludes VS Code configs (.vscode/), my own local configs (info/), some common filetypes I find in projects I don't need to track, and some common BU/cache locations from popular plugins
.vscode/
.well-known/
info/
*/*/error_log
*.log
*.mmdb
*/*/node_modules
*.sh
*.sql
@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 / 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 / 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 / .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>