Skip to content

Instantly share code, notes, and snippets.

View colegeissinger's full-sized avatar

Cole Geissinger colegeissinger

View GitHub Profile
@colegeissinger
colegeissinger / .htaccess
Last active December 7, 2022 22:18
How to enable multilevel directory WordPress multisite install. You Multisite should be configured with subdirectories rather than subdomains as the default.
# This should be used over the server.conf if you are running on Apache and need .htaccess rewrites. Ref this documentation for more details https://wordpress.org/support/article/htaccess/#wordpress-3-5-and-up
RewriteRule ^(/[_0-9A-Za-z-]+\/?)+(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^(/[_0-9A-Za-z-]+\/?)+(.*\.php)$ $2 [L]
@colegeissinger
colegeissinger / command.txt
Created November 2, 2022 16:45
Copy WordPress users from one site to another in a multisite installation with WP-CLI
# Ensure you change the yoursite.com to the domain you want to use. When assigning user roles, we set a default of 'subscriber' if no user role is set on a user we want to migrate.
# This command assumes we are copying users from the "root site" of WordPress to a subsite. If you want to copy from a sub-site to another sub-site, update the first domain url to match that.
for I in $(wp user list --url=https://yoursite.com/ --fields=user_login,roles --format=csv | grep -v user_login); do WPUSER=$(echo -n $I | cut -d ',' -f 1); WPROLE=$(echo -n $I | cut -d ',' -f 2); wp user update ${WPUSER} --role=${WPROLE:-subscriber} --url=https://my-site.com/new-sub-site/; done
@colegeissinger
colegeissinger / download-image.sh
Created August 5, 2020 22:26
Loop over a CSV of image URL's and download them while retaining the folder structure.
#!/usr/bin/env bash
filename="$1"
while IFS="," read f1
do
# Remove the carriage return on the URL which makes for invalid URL's on some servers.
URL=$(echo $f1 | tr -d '\r')
# Fetch the file.
wget -x -nH "$URL"
done < "$filename"

Keybase proof

I hereby claim:

  • I am colegeissinger on github.
  • I am cgeissinger (https://keybase.io/cgeissinger) on keybase.
  • I have a public key whose fingerprint is 76B6 369B CF45 0383 4C77 7A4D CB17 FB2D F6F5 2B74

To claim this, I am signing this object:

@colegeissinger
colegeissinger / build-a-dynamic-sub-nav-for-child-pages.php
Created January 5, 2016 07:05
Build A Dynamic Sub-nav for Child Pages EG 05
$id = $post->ID;
@colegeissinger
colegeissinger / build-a-dynamic-sub-nav-for-child-pages.php
Created January 5, 2016 07:04
Build A Dynamic Sub-nav for Child Pages EG 04
$parent_ids = get_post_ancestors($post->ID);
$id = end($parent_id);
@colegeissinger
colegeissinger / build-a-dynamic-sub-nav-for-child-pages.php
Created January 5, 2016 07:04
Build A Dynamic Sub-nav for Child Pages EG 03
if ( $post->post_parent ) {
...
} else {
...
}
@colegeissinger
colegeissinger / build-a-dynamic-sub-nav-for-child-pages.php
Created January 5, 2016 07:02
Build A Dynamic Sub-nav for Child Pages EG 02
global $post;
@colegeissinger
colegeissinger / build-a-dynamic-sub-nav-for-child-pages.php
Last active January 5, 2016 07:01
Build a Dynamic Sub-nav for Child Pages EG 01
<?php
global $post;
if($post->post_parent) {
$parent_id = get_post_ancestors($post->ID);
$id = end($parent_id);
} else {
$id = $post->ID;
}
wp_list_pages('title_li=&child_of=' . $id);
@colegeissinger
colegeissinger / modify-breadcrumbs-in-canvas-from-woothemes.php
Last active January 5, 2016 06:40
Modify Breadcrumbs in Canvas EG 04
$defaults = array(
'separator' =>; '>;',
'before' =>; '<span class="breadcrumb-title">' . esc_html__( 'You are here:', 'woothemes' ) . '</span>',
'after' =>; false,
'front_page' =>; true,
'show_home' =>; esc_html__( 'Home', 'woothemes' ),
'echo' =>; true,
'show_posts_page' =>; true
);