Skip to content

Instantly share code, notes, and snippets.

@devwax
devwax / Elementor popup toggle control.js
Created July 16, 2023 22:54
jQuery snippet that toggles an Elementor popup while respecting Esc key and other non-click events like clicking outside the toggle button or menu.
jQuery(function ($) {
// Initialize toggler state
window.mytheme_mobile_menu_toggle_open = false;
var popup_id = 7627;
var delay = 50; // Delay to avoid Elementor events firing before click event handlers (milliseconds)
// Mobile nav button toggle click event
$('li.mobile-menu-toggle').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
@devwax
devwax / inline-styles.mjs
Last active May 17, 2023 01:05 — forked from farolanf/inline-styles.mjs
Astro JS - Inline CSS
import path from 'node:path'
import fs from 'node:fs/promises'
import { globby } from 'globby'
const files = await globby('./dist/**/index.html')
await Promise.all(
files.map(async (htmlPath) => {
const pageStyles = []
const stylesPaths = []
@devwax
devwax / Toggle GoDaddy Firewall
Last active February 1, 2023 18:00
Steps to find and turn off/on GoDaddy Web Application Firewall
# The GoDaddy firewall also prevents the DNS records of the domain it's protecting from being edited.
# So WAF needs to be temporarily disabled in order to update DNS records.
In your GoDaddy account main dashboard page...
# Turn Off Godaddy WAF
https://sec.godaddy.com/
1. Scroll to: "Website Security and Backups" (search page for "security" to jump to it
2. Click "Manage" next to "Website Security and Backups"
3. Click "Details" under "Firewall"
@devwax
devwax / react-context-appstate.md
Last active April 3, 2022 19:36
React Context-Driven AppState Scaffolding Snippets

React Context-Driven AppState Scaffolding

  • /context/

    • AppState.js
    • app-context.js
  • Wrap App _(app.js)

    import AppState from "../context/AppState";
    <AppState>
      ...
@devwax
devwax / sparse-checkout-monorepo
Created March 13, 2022 18:14
Checkout a directory within a monorepo or other large repo
git clone --filter=blob:none --sparse https://github.com/[username]/[whatever].git
cd [whatever]
git sparse-checkout init --cone
git sparse-checkout add examples/nextjs-slack-clone
# Source: https://hasura.io/learn/graphql/hasura-auth-slack/data-modeling/3-apply-migrations/
@devwax
devwax / WP REST API.php
Last active February 25, 2021 04:28
WP REST API snippets / notes
// Register acf fields to Wordpress API (functions.php)
// https://support.advancedcustomfields.com/forums/topic/json-rest-api-and-acf/
function acf_to_rest_api($response, $post, $request) {
if (!function_exists('get_fields')) return $response;
if (isset($post)) {
$acf = get_fields($post->id);
$response->data['acf'] = $acf;
}
@devwax
devwax / custom.css
Last active December 6, 2020 20:46
Prevent admin bar overflow with CSS on frontend
/* This only applies outside of /wp-admin/ i,e, on frontend while viewing public pages, etc. */
body.admin-bar {
#wpadminbar {
overflow: hidden;
}
}
/* WP Bakery padding-top */
body.logged-in {
.vc_row.wpb_row.vc_row-fluid.vc_custom_123456789 {
@devwax
devwax / functions.php
Last active December 4, 2020 20:37
WordPress Admin URL shortcuts
<?php
/*
Usage:
domain.com/plugins > domain.com/wp-admin/plugins.php (WP Admin > Plugins)
domain.com/pg > domain.com/wp-admin/edit.php?post_type=page (WP Admin > Pages)
etc...
*/
add_action('wp', 'redirect_shortcuts');
function redirect_shortcuts(){
if (is_user_logged_in()) {
@devwax
devwax / wordpress_snippets.php
Last active March 30, 2023 18:59
WordPress Snippets
<?php
// Frontend memory limit
define('WP_MEMORY_LIMIT', '64M'); // Default for WooCommerce: https://github.com/WordPress/WordPress/blob/master/wp-includes/default-constants.php#L50
// /wp-admin/ memory limit
define('WP_MAX_MEMORY_LIMIT', '256M'); // Default: https://github.com/WordPress/WordPress/blob/master/wp-includes/default-constants.php#L62
// WordPress memory limits deep dive: https://www.saotn.org/increase-wordpress-memory-limit-wp-config-php/
@devwax
devwax / mysql_snippets.sql
Last active September 17, 2021 05:13
MySQL snippets
### Queries for replacing strings in MySQL database records
- https://www.webhostface.com/kb/knowledgebase/mysql-search-replace/
UPDATE `wp_options` SET option_value = REPLACE(option_value, 'newdev/', '') WHERE `option_value` LIKE '%newdev/%' LIMIT 1;
- Regular expression
SELECT * FROM tablename WHERE meta_key REGEXP '^wp_([0-9]+)_' limit 10;
### MySQL dump specific rows, etc
-- Run in bash terminal, not in mysql> cli