Skip to content

Instantly share code, notes, and snippets.

View minimal-analytics-snippet.js
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@cp6
cp6 / bunnycdn_storage.php
Last active Jan 3, 2021
Bunny CDN Storage API format
View bunnycdn_storage.php
<?php
header("Content-type:application/json");
function storage($key, $dir = '')
{
return json_decode(file_get_contents("https://storage.bunnycdn.com/" . $dir . "/?AccessKey=" . $key . ""), true);
}
$array = storage('STORAGE-PASSWORD-HERE', 'STORAGENAME');
$items = array('data' => array());
foreach ($array as $value) {
@jay7793
jay7793 / Instruction.sh
Last active May 5, 2021
Install Laravel 5.6 With PHP7.2 NGINX and PHP7.2-FPM on Ubuntu 16.04
View Instruction.sh
# Install software-properties-common package to give us add-apt-repository package
sudo apt-get install -y software-properties-common
# Install latest nginx version from community maintained ppa
sudo add-apt-repository ppa:nginx/stable
# Update packages after adding ppa
sudo apt-get update
# Install nginx
@AnthumChris
AnthumChris / README.md
Last active Jul 8, 2021
Clear Nginx Cache
View README.md

Clearing Nginx's HTTP Cache

I recently implemented Nginx HTTP content caching on our WordPress web servers to improve page load speeds and eliminate redundant, unneeded server-side page rendering. Caching the pages was relatively straightforward, but clearing the cache required a custom workaround.

Nginx comes in two versions: free and “Nginx Plus” at $2,500/year. The free version of Nginx does not offer the needed cache-clearing features of Nginx Plus, and I wasn’t comfortable paying $20,000 for 8 instances without trying to build my own solution.

Our Nginx servers run as an HTTP proxy for multiple PHP/MySQL-backed WordPress sites. The goal was to cache the dynamic PHP HTML responses in Nginx and serve the HTML pages from Nginx to avoid redundant, CPU-intensive PHP renders.

Site Cache Configuration

The example below shows how PHP response caching is configured for a site (other nginx configuration details are excluded for brevity). A cache named cachedemo-prod is defined to store cached HTML f

@isuke01
isuke01 / custom-wp.ajax
Last active Nov 18, 2019
Custom WP ajax, capable of using SHORTINIT, and much faster than standard WP
View custom-wp.ajax
<?php
/*
If you use short init by passing argument shortinit.
You have base and a bit more wp components loaded, like get_meta, current user .. etc.
*/
if (!isset( $_POST['action']))
die('-1');
if ( isset( $_POST['shortinit']) ){
$type = trim($_POST['shortinit']);
View Custom List Table With Database Example.php
<?php
/*
Plugin Name: Custom List Table With Database Example
Description: A highly documented plugin that demonstrates how to create custom admin list-tables from database using WP_List_Table class.
Version: 1.0
Author: Viramgami Jignesh
Author URI: https://github.com/viramgamijignesh/
License: GPL2
*/
@heiswayi
heiswayi / fm.php
Created Oct 25, 2017
Single PHP File Manager Script - Screenshot: https://i.imgur.com/4OtrKUz.png
View fm.php
<?php
/**
* File Manager Script
*/
// Default language ('en' and other from 'filemanager-l10n.php')
$lang = 'en';
// Auth with login/password (set true/false to enable/disable it)
$use_auth = true;
@hanshsieh
hanshsieh / VerifyIdToken.java
Last active Jun 10, 2020
Google Sign-in Example
View VerifyIdToken.java
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import java.util.Collections;
/**
* Hello world!
View admin.js
$('#update-cat-featured-img, #add-cat-featured-img').click(function(e) {
e.preventDefault();
var custom_uploader = wp.media({
title: 'Featured Image',
button: {
text: 'Insert image'
},
multiple: false // Set this to "add" to allow multiple files to be selected
})
@ahmadawais
ahmadawais / upload-a-file.MD
Created Jun 18, 2017 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API
View upload-a-file.MD

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle: