Skip to content

Instantly share code, notes, and snippets.

View theperfectwill's full-sized avatar
💭
Coding... Working on The WPOnion Framework with Varun

The Perfect Will theperfectwill

💭
Coding... Working on The WPOnion Framework with Varun
View GitHub Profile
@theperfectwill
theperfectwill / using-google-takeout.md
Last active December 5, 2023 23:52 — forked from chabala/using-google-takeout.md
Merge and extract tgz files from Google Takeout

Recently found some clowny gist was the top result for 'google takeout multiple tgz', where it was using two bash scripts to extract all the tgz files and then merge them together. Don't do that. Use brace expansion, cat the TGZs, and extract:

$ cat takeout-20201023T123551Z-{001..011}.tgz | tar xzivf -

You don't even need to use brace expansion. Globbing will order the files numerically:

$ cat takeout-20201023T123551Z-*.tgz | tar xzivf -
@theperfectwill
theperfectwill / jquery.js
Created August 14, 2023 00:40
Latest jQuery in WP - Error in minifying line 9365-9366
/*!
* jQuery JavaScript Library v3.7.0
* https://jquery.com/
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2023-05-11T18:29Z
*/
@theperfectwill
theperfectwill / wp-attachment-url-to-path.php
Created August 7, 2023 03:16 — forked from kamalahmed/wp-attachment-url-to-path.php
You can convert an attachment url to its absolute path in WordPress using this function.
<?php
/**
* Get the attachment absolute path from its url
*
* @param string $url the attachment url to get its absolute path
*
* @return bool|string It returns the absolute path of an attachment
*/
function attachment_url_to_path( $url )
@theperfectwill
theperfectwill / async-defer-module.md
Created August 5, 2023 02:36 — forked from jakub-g/async-defer-module.md
async scripts, defer scripts, module scripts: explainer, comparison, and gotchas

<script> async, defer, async defer, module, nomodule, src, inline - the cheat sheet

With the addition of ES modules, there's now no fewer than 24 ways to load your JS code: (inline|not inline) x (defer|no defer) x (async|no async) x (type=text/javascript | type=module | nomodule) -- and each of them is subtly different.

This document is a comparison of various ways the <script> tags in HTML are processed depending on the attributes set.

If you ever wondered when to use inline <script async type="module"> and when <script nomodule defer src="...">, you're in the good place!

Note that this article is about <script>s inserted in the HTML; the behavior of <script>s inserted at runtime is slightly different - see Deep dive into the murky waters of script loading by Jake Archibald (2013)

@theperfectwill
theperfectwill / pis_array_remove_empty_keys.php
Created June 27, 2023 09:42 — forked from aldolat/pis_array_remove_empty_keys.php
Remove empty keys from an array recursively.
<?php
/**
* Remove empty keys from an array recursively.
*
* @param array $array The array to be checked.
* @param boolean $make_empty If the output is to return as an empty string.
* @since 1.29
* @see http://stackoverflow.com/questions/7696548/php-how-to-remove-empty-entries-of-an-array-recursively
*/
function pis_array_remove_empty_keys( $array, $make_empty = false ) {
@theperfectwill
theperfectwill / dequeue-styles-and-scripts.php
Created June 23, 2023 01:52 — forked from mrkpatchaa/dequeue-styles-and-scripts.php
Dequeue Styles and Scripts In WordPress
<?php
/** From http://www.paulund.co.uk/dequeue-styles-scripts-wordpress */
/**
* Dequeue JavaScript or Stylesheet.
*/
function dequeue_script()
{
// Run the dequeue script with the handle of the JavaScript file
wp_dequeue_script( $handle );
Disable the WordPress Admin Bar for all Users and Visitors
Turn off the toolbar with one simple line.
view plain
/*
* Disable the WordPress Admin Bar for all Users and Visitors
*/
remove_action( 'init', '_wp_admin_bar_init' );
^ top
Enable the WordPress Admin Bar for admins only
// Source: https://blog.templatetoaster.com/update-old-urls-in-database/
// How to Change/Update links with MySQL
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find string’, ‘replace string’);
// For replacing the URL across all database tables, Click on SQL tab and in the panel type the below code:
UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
@theperfectwill
theperfectwill / before_container_after_container.php
Last active February 24, 2023 09:29
before_container_after_container.php
<?php
$this_instance = wponion_builder();
$main_container = $this_instance->container(
'main_container'
);
$container_4 = $this_instance->container(
'container_4'
@theperfectwill
theperfectwill / wpDisableSiteHealth.php
Created January 30, 2023 16:02
WP - Disable Site Health Altogether
<?php
// Plugin Name: wpDisableSiteHealth
// Create our namespace and define whether Wordpress is running or not
namespace wpDisableSiteHealth;
defined('ABSPATH') or exit;
if (!is_blog_installed()) return;