Skip to content

Instantly share code, notes, and snippets.

Avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
View redirects.php
<?php
add_action( 'muplugins_loaded', function() {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
if ( empty( $_SERVER['HTTP_HOST'] ) ) {
return;
}
View http.conf
# In the main {} context
map $http_user_agent $imgproxy {
"~imgproxy" 1;
default 0;
}
map $http_accept $webp_suffix {
"~image/webp" "@webp";
default "";
View server.conf
# 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 "";
View remote-http-cache.php
<?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 Nov 5, 2021
Pre-deploy hook for Sail CLI
View pre-deploy
#!/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
View deploy.yml
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
View safe-apt-get.sh
#!/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 "$@"
View edit-my-plugin-options.php
<?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 Nov 19, 2015
Get subscribers count via the MailChimp API.
View subscribers-count.php
<?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 Nov 17, 2015
Some array callables for WordPress
View array-callables.php
<?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 ) {