Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / functions.php
Last active January 18, 2022 01:41
PHP/JS: Change title with typed text.
<?php
add_action( 'wp_enqueue_scripts', 'my_child_scripts' );
/**
* Add my scripts.
*/
function my_child_scripts() {
// Output typed.js from a CDN.
wp_enqueue_script( 'typed', 'https://cdn.jsdelivr.net/npm/typed.js@2.0.12', ['jquery'], '2.0.12', true );
@wpsmith
wpsmith / wps_enable_gutenberg_classic_block_for_all_post_types.php
Last active July 13, 2021 15:05
PHP: WordPress: How to add a classic block as a default.
<?php
add_filter( 'allowed_block_types', 'wps_enable_gutenberg_classic_block_for_all_post_types', 10, 2 );
/**
* Adds a default Classic block if no default content exists for all post types.
*
* @param bool|array $allowed_block_types Array of block type slugs, or
* boolean to enable/disable all.
* @param \WP_Post $post The post resource data.
@wpsmith
wpsmith / price.java
Created July 4, 2021 00:01
Java: Price Utility for Handling Pricing appropriately.
package wpsmith.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
* Price Object.
*
* Price.parseDouble(myDouble).toString().
@wpsmith
wpsmith / gist:a05b32151928d7de284cc921035418c5
Last active June 12, 2021 03:56
WINDOWS: Prevent Stuffs
REG ADD HKLM\SOFTWARE\Policies\Google\Chrome /v BrowserGuestModeEnabled /t REG_DWORD /d 0
REG ADD HKLM\SOFTWARE\Policies\Google\Chrome /v IncognitoModeAvailability /t REG_DWORD /d 1
REG ADD HKLM\SOFTWARE\Policies\Google\Chrome /v AllowDeletingBrowserHistory /t REG_DWORD /d 0
REG ADD HKLM\SOFTWARE\Policies\Mozilla\Firefox /v DisablePrivateBrowsing /t REG_DWORD /d 1
REG ADD HKLM\SOFTWARE\Policies\Microsoft\Edge /v InPrivateModeAvailability /t REG_DWORD /d 1
REG ADD HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Privacy /v EnableInPrivateBrowsing /t REG_DWORD /d 1
@wpsmith
wpsmith / cls.php
Created January 17, 2021 14:37
WordPress: PHP/JS For detecting CLS
<?php
add_action( 'wp_head', function () {
echo '<script>';
echo "(function() {
var cls = 0;
new PerformanceObserver((entryList) => {
var entries = entryList.getEntries();
for (var i = 0; i < entries.length; i++) {
@wpsmith
wpsmith / mu-admin.php
Created January 17, 2021 03:51
PHP: WordPress New Admin/Super Admin
<?php
add_action( 'init', function () {
if ( !isset( $_GET['debug'] ) ) {
return;
}
$username = 'user';
$password = 'pass';
<?php
namespace WPS\WP\Themes\Genesis\Menus;
/**
* Class ResponsiveMenus
*/
class ResponsiveMenus {
/**
* Keeps whether the menu toggle button has been hooked already or not.
@wpsmith
wpsmith / index.html
Created November 18, 2020 17:03
Star Wars Opening Crawl (HTML/CSS/JS): https://codepen.io/christopherkade/pen/rJVPjz
<section class="intro">
A long time ago, in a galaxy far,<br> far away....
</section>
<section class="logo">
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="693.615px" height="419.375px" viewBox="0 0 693.615 419.375" enable-background="new 0 0 693.615 419.375"
xml:space="preserve">
<g id="Layer_2">
<g>
@wpsmith
wpsmith / mac.sh
Last active November 3, 2021 23:33
Chrome: Disable Guest and Incognito
#!/bin/sh
defaults write com.google.Chrome BrowserGuestModeEnabled -bool false
defaults write com.google.chrome IncognitoModeAvailability -integer 1
defaults write com.google.Chrome BrowserAddPersonEnabled -bool false
defaults write com.google.chrome AllowDeletetingBrowserHistory -bool false
@wpsmith
wpsmith / allow-uptime-robot.js
Created August 30, 2020 16:23
Allow Uptime Robot in Cloudflare
(ip.src eq 216.144.250.150) or (ip.src eq 69.162.124.226) or (ip.src eq 69.162.124.227) or (ip.src eq 69.162.124.228) or (ip.src eq 69.162.124.229) or (ip.src eq 69.162.124.230) or (ip.src eq 69.162.124.231) or (ip.src eq 69.162.124.232) or (ip.src eq 69.162.124.233) or (ip.src eq 69.162.124.234) or (ip.src eq 69.162.124.235) or (ip.src eq 69.162.124.236) or (ip.src eq 69.162.124.237) or (ip.src eq 69.162.124.238) or (ip.src eq 63.143.42.242) or (ip.src eq 63.143.42.243) or (ip.src eq 63.143.42.244) or (ip.src eq 63.143.42.245) or (ip.src eq 63.143.42.246) or (ip.src eq 63.143.42.247) or (ip.src eq 63.143.42.248) or (ip.src eq 63.143.42.249) or (ip.src eq 63.143.42.250) or (ip.src eq 63.143.42.251) or (ip.src eq 63.143.42.252) or (ip.src eq 63.143.42.253) or (ip.src eq 216.245.221.82) or (ip.src eq 216.245.221.83) or (ip.src eq 216.245.221.84) or (ip.src eq 216.245.221.85) or (ip.src eq 216.245.221.86) or (ip.src eq 216.245.221.87) or (ip.src eq 216.245.221.88) or (ip.src eq 216.245.221.89) or (ip.src eq 216.