Skip to content

Instantly share code, notes, and snippets.

@daddiofaddio
daddiofaddio / human_name_parser.py
Last active May 23, 2024 09:22
Python - Extract & parse raw scraped identification data and reformat to "human name" data values (nameparser/HumanName imports)
from nameparser import HumanName
import pandas as pd
def parse_names_from_file(input_file_path, output_file_path):
# Read the names from a file
with open(input_file_path, 'r') as file:
names = file.read().splitlines()
# Parse the names using the nameparser library
parsed_names = []
@daddiofaddio
daddiofaddio / json_rename.py
Last active May 23, 2024 09:15
Python script - Rename extracted json data files to match sanitized names of urls scraped; regex for batch renaming of suffixes, specific first names, etc.
import os
import re
import json
# Directory containing the JSON files
json_dir = '/path/to/dir'
urls_file_path = '/path/to/urls.txt'
with open(urls_file_path, 'r') as file:
@daddiofaddio
daddiofaddio / gist:1d06dd3359a78e40ab4bba39f14c218d
Created June 13, 2022 23:13
Woocommerce add user role at time of purchase based on product ID
/* ADD USER ROLE BASED ON PRODUCT ID */
function change_role_on_purchase($order_id) {
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($items as $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
@daddiofaddio
daddiofaddio / gist:c0485d2fa846b0f74884203d483256c4
Created June 12, 2022 09:15
Display username, message & avatar shortcode with link to My Account page - conditional based on existing user fields
/* DISPLAY AVATAR & USER SHORTCODE - CONDITIONAL */
function display_current_user_shortcode()
{
global $current_user;
$user = wp_get_current_user();
$avatar = get_avatar($current_user->ID, 32, '', '', $args = array('class' => 'rounded-circle'));
$custom_avatar = get_avatar('https://url-to-custom-avatar.webp');
$first = $user->user_firstname;
$display = $user->display_name;
$email = $user->user_email;
@daddiofaddio
daddiofaddio / gist:2fd2600b2e42d7709750ee6eb20212ed
Created June 12, 2022 09:11
Add avatar & username as menu item to WP menu (functions.php)
/* ADD AVATAR/USER MENU ITEM */
add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items', 10 );
function my_dynamic_menu_items( $menu_items ) {
foreach ( $menu_items as $menu_item ) {
if ( strpos($menu_item->title, '#profile_name#') !== false) {
$menu_item->title = str_replace("#profile_name#", wp_get_current_user()->user_login .' '. get_avatar( wp_get_current_user()->user_email, 50), $menu_item->title);
}
}
return $menu_items;
}
@daddiofaddio
daddiofaddio / install_imagemagic_with_heic.sh
Last active June 12, 2022 06:51 — forked from hurricup/install_imagemagic_with_heic.sh
How to install ImageMagick with HEIC and WEBP support on Ubuntu 20.04
# inspired by https://gist.github.com/rjnienaber/af47fccb8410926ba7ea35f96c3b87fd
# remove bundled ImageMagick
sudo apt remove imagemagick -y
# install base dependencies
sudo apt-get install -y \
libde265-dev \
libdjvulibre-dev \
libfftw3-dev \
@daddiofaddio
daddiofaddio / gist:b5773182ac9d84ddd77b5b48cbba4d7e
Created June 11, 2022 23:44
Replace existing avatar class using str_replace (functions.php)
/* REPLACE EXISTING AVATAR CLASS */
add_filter('get_avatar','change_avatar_css');
function change_avatar_css($class) {
$class = str_replace('class="avatar avatar-96', 'class="avatar-225 rounded-circle', $class);
return $class;
}
@daddiofaddio
daddiofaddio / gist:02c9e131b746e695878c620d53ed6b34
Created June 11, 2022 23:37
Display Woocommerce Memberships shortcode (functions.php)
/* WOO MEMBERSHIPS TABLE SHORTCODE - WITH HEADER */
function ploa_woo_memberships_shortcode() {
if (!function_exists('wc_memberships') || is_admin()) {
return;
}
ob_start();
?>
<div class="woocommerce">
<h2><?php esc_html_e('My Membership', 'textdomain'); ?></h2>
<?php
@daddiofaddio
daddiofaddio / gist:998dbefc0d5bbf194f60549736c91945
Last active June 11, 2022 23:38
Woocommerce change "Return to Shop" message (functions.php)
/* WOO CHANGE RETURN TO SHOP MESSAGE */
add_filter('gettext', 'ploa_translate_woocommerce_strings', 999, 3);
function ploa_translate_woocommerce_strings($translated, $untranslated, $domain) {
if (!is_admin() && 'woocommerce' === $domain) {
switch ($translated) {
case 'Return to shop':
$translated = 'Return to awards area.';
break;
}
}
@daddiofaddio
daddiofaddio / gist:087e81526295b586d1c8de7da1dd9bf0
Created June 11, 2022 23:05
Woocommerce change text from "My Account" to "Login" when user logged out
/* WOOCOMMERCE CHANGE MYACCOUNT TO LOGIN */
add_filter('wp_nav_menu_items', 'dynamic_menu_item_label', 9999, 2);
function dynamic_menu_item_label($items, $args) {
if (!is_user_logged_in()) {
$items = str_replace("My Account", "Login", $items);
}
return $items;
}