Skip to content

Instantly share code, notes, and snippets.

yousufansa / functions.php
Created Apr 20, 2020
MAS WPJMC - Companies Posted Jobs in Single Company
View functions.php
if( ! function_exists( 'mas_wpjmc_single_company_job_listings' ) ) {
function mas_wpjmc_single_company_job_listings() {
global $post;
$company_jobs = mas_wpjmc_get_the_company_job_listing();
if( count( $company_jobs ) ) :
?><div class="mas-company-jobs"><?php
?><h3 class="mas-company-jobs__title"><?php
echo apply_filters( 'mas_wpjmc_company_jobs_title', esc_html__( 'Jobs by This Company', 'mas-wp-job-manager-company' ) );
franzose / ga_reporting.php
Last active Aug 15, 2021
Google Analytics Reporting API usage example
View ga_reporting.php
// composer require google/apiclient
require __DIR__ . '/vendor/autoload.php';
// This is the file obtained from Google during the service account creation process
// see these links:
// 1.
// 2.
JosephHewitt / cloudflare_worker.js
Last active Nov 20, 2021
Cloudflare Worker JS code to cache Wordpress HTML for logged-out users.
View cloudflare_worker.js
/*I make no guarantees this code will work reliably. Use at your own risk. Please thoroughly test before deploying.
Enabling this on a Cloudflare Worker for a Wordpress site should cache all HTML pages (if your origin headers allow that) but bypass the cache when a user is logged in.
This is tested and working on a Wordpress 5.0.2 installation and the free Cloudflare tier (but I make no guarentees it will work for anyone else).
Sets the `x-cfw-cache` header to indicate the Worker cache status (either HIT, MISS, NO, or BYPASS): `NO` = server has set cookies (won't cache) and `BYPASS` = client has cookies (bypassing cache).
addEventListener('fetch', event => {
ko31 / SampleFilterAnalytics.php
Created Dec 19, 2018
Get reports with multiple condition filters for Google Analytics Reporting API v4
View SampleFilterAnalytics.php
// composer require google/apiclient
* @link
* @link
* @link
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 = () => {
justlstn / add-files-to-custom-fields.php
Created Aug 24, 2018
Add multiple files to acf repeater field
View add-files-to-custom-fields.php
$files = $_FILES[ 'attachments' ];
$attachments = [];
foreach ( $files['name'] as $key => $value ) {
if ( $files[ 'name' ][ $key ] ) {
$file = array(
'name' => $files[ 'name' ][ $key ],
'type' => $files[ 'type' ][ $key ],
'tmp_name' => $files[ 'tmp_name' ][ $key ],
'error' => $files[ 'error' ][ $key ],
vdbelt / cloudflare-purge-cache-service-worker.js
Created Aug 21, 2018
A CloudFlare service worker that proxies purge cache requests. Example:
View cloudflare-purge-cache-service-worker.js
addEventListener('fetch', event => {
async function purgeCache(request) {
const url = new URL(request.url)
cp6 / bunnycdn_storage.php
Last active Jan 3, 2021
Bunny CDN Storage API format
View bunnycdn_storage.php
function storage($key, $dir = '')
return json_decode(file_get_contents("" . $dir . "/?AccessKey=" . $key . ""), true);
$items = array('data' => array());
foreach ($array as $value) {
jay7793 /
Last active Oct 18, 2022
Install Laravel 5.6 With PHP7.2 NGINX and PHP7.2-FPM on Ubuntu 16.04
# 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 /
Last active Sep 25, 2022
Clear Nginx Cache

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