Skip to content

Instantly share code, notes, and snippets.

View TeemuSuoranta's full-sized avatar
🐢
I may respond slowly, but I'll respond eventually. Probably.

Teemu Suoranta TeemuSuoranta

🐢
I may respond slowly, but I'll respond eventually. Probably.
View GitHub Profile
@k1sul1
k1sul1 / index.js
Last active June 27, 2023 20:02
Express.js server with a proxy and session management for making authenticated requests to WP without the gray hairs of OAuth
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const session = require('express-session')
const redis = require('redis')
const RedisStore = require('connect-redis')(session)
const axios = require('axios')
const csurf = require('csurf')
const cookieParser = require('cookie-parser')
const listEndpoints = require('express-list-endpoints')
function removeDropCap(settings, name) {
if (name !== 'core/paragraph') {
return settings;
}
let newSettings = Object.assign({}, settings);
if (newSettings.supports &&
newSettings.supports.__experimentalFeatures &&
newSettings.supports.__experimentalFeatures.typography &&
newSettings.supports.__experimentalFeatures.typography.dropCap) {
newSettings.supports.__experimentalFeatures.typography.dropCap = false
@k1sul1
k1sul1 / webpack.config.babel.js
Last active December 15, 2023 18:47
Webpack configuration for building a WordPress plugin with React and Typescript
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const TerserJSPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
@elierotenberg
elierotenberg / BLOG.md
Last active August 16, 2023 12:01
Idiomatic Data Fetching using React Hooks

Idiomatic Data Fetching using React Hooks

This post has been written in collaboration with @klervicn

Virtually all web apps and websites need to pull data from a server, usually through a JSON-returning API. When it comes to integrating data fetching in React component, the "impedence mismatch" between the React components, which are declarative and synchronous, and the HTTP requests, which are imperative and asynchronous, is often problematic.

Many apps use third-party libraries such as Redux or Apollo Client to abstract it away. This requires extra dependencies, and couple your app with a specific library to perform data fetching. In most cases, what we want is a direct way to integrate plain HTTP requests (e.g. using native fetch) for usage in React components.

Here we will discuss how we can use React Hooks to do this in an elegant, scalable manner.

@davewardle
davewardle / functions.php
Last active December 23, 2021 08:22
Updates retention policy for all existing Gravity Forms
<?php
function enforce_gravity_forms_retention_policy() {
// only load for admin panel
if ( is_admin() && class_exists( 'GFForms' ) ) {
// load all forms
$forms = GFAPI::get_forms();
// loop through each form
foreach ( $forms as $form ) {
@onnimonni
onnimonni / remove-accents-uploaded-files-and-database.php
Last active March 1, 2016 14:34
Run this file with wp-cli: $ wp eval-file remove-accents-uploaded-files-and-database.php to remove accents from all of your previous uploads. Also fix OS-X NFD filenames. After running this command install https://gist.github.com/onnimonni/d58bdcff44f8208a15c7 to your mu-plugins to avoid this in future uploads.
<?php
/**
* Sanitize accents from Cyrillic, German, French, Polish, Spanish, Hungarian, Czech, Greek, Swedish
* This replaces all accents from your uploads by renaming files and replacing attachment urls from database.
* This even removes NFD characters from OS-X by using Normalizer::normalize()
* This is one time script which you can use by running it with wp-cli:
* $ wp eval-file remove-accents-uploaded-files-and-database.php
*/
// Get all uploads
@onnimonni
onnimonni / remove-accents-on-upload.php
Last active February 26, 2018 11:02
Wordpress plugin which sanitizes files on upload. This fixes OS-X NFD characters as well if you have Normalizer class and icu library installed.
<?php
/**
* Plugin Name: Remove accents from files on upload
* Plugin URI: https://gist.github.com/onnimonni/d58bdcff44f8208a15c7
* Description: Sanitize accents from Cyrillic, German, French, Polish, Spanish, Hungarian, Czech, Greek, Swedish during upload. Also fix OS-X NFD filenames.
* Version: 1.0
* Author: Onni Hakala
* Author URI: http://github.com/onnimonni
* License: GPLv3
*/
@mayeenulislam
mayeenulislam / Default Taxonomy Term for CPT
Last active April 5, 2023 11:07
Make Default taxonomy term for Custom Post Type - WordPress
/**
* Author: Michael Fields
* Source: http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/
* Thanks a lot for the nice tweak
*/
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
@hakre
hakre / dl-file.php
Created January 2, 2012 21:41
Wordpress login to download uploaded files
<?php
/*
* dl-file.php
*
* Protect uploaded files with login.
*
* @link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* @author hakre <http://hakre.wordpress.com/>
* @license GPL-3.0+