Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
<?php
add_action( 'muplugins_loaded', function() {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
if ( empty( $_SERVER['HTTP_HOST'] ) ) {
return;
}
# In the main {} context
map $http_user_agent $imgproxy {
"~imgproxy" 1;
default 0;
}
map $http_accept $webp_suffix {
"~image/webp" "@webp";
default "";
# Inside the server {} block
location @imgproxy {
proxy_ssl_server_name on;
proxy_ssl_name imgproxy.ondigitalocean.app;
proxy_set_header Host imgproxy.ondigitalocean.app;
proxy_set_header If-Modified-Since "";
proxy_set_header ETag "";
proxy_set_header Cache-Control "";
<?php
/**
* Pressjitsu Remote HTTP Cache
*
* Many plugins like to perform remote HTTP requests for front-end visits,
* sometimes without even employing transient caching. We think that *all* HTTP
* requests should run in the background, and thus be always served from cache,
* even if the cache is stale.
*
* Configure cachable hosts via the pj_http_cache_hosts filter.
@kovshenin
kovshenin / pre-deploy
Created November 5, 2021 10:38
Pre-deploy hook for Sail CLI
#!/bin/bash
FILES=`sail diff --raw | grep \.php$`
ROOT="$(dirname `dirname $0`)"
EXIST=''
for FILE in $FILES
do
if [ -f "$ROOT/$FILE" ]; then
EXIST="$EXIST $ROOT/$FILE"
fi
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
@kovshenin
kovshenin / safe-apt-get.sh
Last active August 26, 2021 11:25
Safe apt-get
#!/bin/bash
while fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1 ; do
sleep 0.5
done
/usr/bin/apt-get "$@"
<?php
add_filter( 'map_meta_cap', function( $caps, $cap ) {
if ( $cap == 'edit_my_plugin_options' ) {
$c = is_multisite() ? 'manage_site_options' : 'manage_options';
$caps = array( $c );
}
return $caps;
}, 10, 2 );
if ( current_user_can( 'edit_my_plugin_options' ) ) { ... }
@kovshenin
kovshenin / subscribers-count.php
Created November 19, 2015 13:03
Get subscribers count via the MailChimp API.
<?php
/**
* Get subscribers count via the MailChimp API.
*/
function mailchimp_get_subscribers_count() {
$cache_key = 'mailchimp-subscribers';
$api_key = '';
$username = '';
$dc = '';
$list_id = '';
@kovshenin
kovshenin / array-callables.php
Created November 17, 2015 12:53
Some array callables for WordPress
<?php
function __array_append( $item ) {
return function( $array ) use ( $item ) {
$array[] = $item;
return $array;
};
}
function __array_set( $key, $value ) {
return function( $array ) use ( $key, $value ) {