Skip to content

Instantly share code, notes, and snippets.

View lightningspirit's full-sized avatar
🏠
Working from home

Vitor Carvalho lightningspirit

🏠
Working from home
View GitHub Profile
@lightningspirit
lightningspirit / wp-disable-plugin-update-notifications.php
Last active September 12, 2023 16:34
Disable WordPress plugin updates and notifications
<?php
namespace WP_Disable_Plugin_Update_Notifications;
$plugins = [
'elementor/elementor.php',
'elementor-pro/elementor-pro.php',
];
add_filter( 'site_transient_update_plugins', function ( $value ) use ( $plugins ) {
@lightningspirit
lightningspirit / custom-plugin.php
Last active May 24, 2023 10:48
WordPress Custom Plugin - Can be used to add any code using the online editor
<?php
/**
* Plugin Name: Custom
* Plugin URI: https://gist.github.com/lightningspirit/4619cb99fcb662b390d9596df1479d41
* Description: Custom code for everybody
* Author: Move Your Digital
* Author URI: https://moveyourdigital.com
* Version: 1.0.0
*
@lightningspirit
lightningspirit / buildQueryString.ts
Created October 29, 2022 09:31
A function that takes an object and outputs a query string. Booleans are mapped into 1 and 0. Supports arrays of values.
type ValueType =
| string
| number
| boolean
| null
| undefined
| (string | number | boolean | null | undefined)[]
function mapBooleans(key: string, value: ValueType) {
switch (value) {
@lightningspirit
lightningspirit / README.md
Last active September 26, 2022 15:50
WPGraphQL add field format plain text

WPGraphQL add field format plain text

This small plugin adds a new format to retrieve excerpt or title in text plain format instead of rendered.

Usage

  1. Install WPGraphQL
  2. Download or copy the wpgraphql-field-format-text-plain.php file
  3. Place it under wp-content/mu-plugins
  4. Done
@lightningspirit
lightningspirit / README.md
Created September 20, 2022 00:37
Add excerpt to page

WordPress Page Excerpt

Add excerpt field to page

Usage

  1. Download this ZIP
  2. Upload to plugins
  3. Activate it
@lightningspirit
lightningspirit / README.md
Created September 20, 2022 00:28
Includes a `readingTime` field in seconds for every `Post` object response.

WPGraphQL Post Reading Time

Includes a readingTime field in seconds for every Post object response.

Usage

  1. Download this ZIP
  2. Upload to plugins
  3. Activate it
@lightningspirit
lightningspirit / useFSM.tsx
Created September 6, 2022 13:39
Preact Hook Finite State Machine
import { useCallback, useEffect, useMemo, useState } from "preact/hooks"
class StateTransitionError extends Error {}
function useFSM<T extends string>(
transitions: Record<T, T[]>,
options: {
throwOnTransitionError?: boolean
} = { throwOnTransitionError: true },
) {
@lightningspirit
lightningspirit / README.md
Created August 22, 2022 00:30
Includes a WPGraphQL JWT token in every posts preview link

WPGraphQL JWT in Preview Link

Includes a WPGraphQL JWT token in every posts preview link. That can be used for an external application (e.g. Next.js) to include in the authorization header when contacting back the WordPress instance using the WPGraphQL.

Usage

  1. Install both WPGraphQL and WPGraphQL JWT Authentication
  2. Download this ZIP
  3. Upload to plugins
  4. Activate it
@lightningspirit
lightningspirit / README.md
Last active August 22, 2022 00:07
Fix WordPress REST base to use real URL

WordPress REST base on Site URL

If you change the site URL option to use a different one from your installed directory, the /wp-json/ is base changes too. This plugin fixes that.

Usage

  1. Download a ZIP of this plugin
  2. Upload to WordPress
@lightningspirit
lightningspirit / README.md
Last active July 7, 2022 11:17
WordPress Autoload Composer Vendor MU-Plugin

WordPress composer autoload

Do you use WordPress along with composer? This is the right plugin for you. Just add it to mu-plugins and the root autoloader is activated.

Usage

  1. Download or copy the autoload.php file
  2. Place it under wp-content/mu-plugins
  3. Done