Skip to content

Instantly share code, notes, and snippets.

View khromov's full-sized avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / functions.php
Created April 7, 2020 19:38
WP Recipe Maker
<?php
// Your themes functions.php
add_action( 'init', function() {
add_rewrite_rule(
'recipe/([0-9]+)/?$',
'index.php?pagename=recipe&recipe_id=$matches[1]',
'top' );
});
@khromov
khromov / built-share-[id].js
Created March 24, 2020 20:44
Next.js built chunks
(window.webpackJsonp = window.webpackJsonp || []).push([
[21], {
"+51p": function(t, n, e) {
"use strict";
e.r(n), e.d(n, "__N_SSP", (function() {
return m
}));
var o = e("q1tI"),
r = e.n(o),
c = e("8Kt/"),
@khromov
khromov / deploy.php
Last active March 10, 2020 15:27
Deploying WordPress with Deployer 4
<?php
namespace Deployer;
require 'recipe/common.php';
set('ssh_type', 'native');
set('ssh_multiplexing', true);
// Set configurations
set('repository', 'git@github.com:user/repo.git');
@khromov
khromov / wp-config.php
Last active October 1, 2019 08:58
Convert MySQL connection string to wp-config.php parameters
<?php
//...
// This will usually be received from an env variable, for example $connectionString = getenv('DB_URL');
$connectionString = 'mysql://user:password@foo-bar.rds.amazonaws.com:3306/database';
// The values below will be your default values if $connectionString is empty.
$dbConfig = array_merge(
[
'host' => 'localhost',
@khromov
khromov / file.php
Last active January 29, 2019 21:24
Advanced Custom Fields get_field() sanitization
<?php
/**
* Helper function to get sanitized field
* and also normalize values.
*
* @param $field_key
* @param bool $post_id
* @param bool $format_value
* @param string $sanitization_method esc_html / esc_attr or NULL for none
* @return array|bool|string
@khromov
khromov / functions.php
Created February 14, 2017 21:28
Load WPFacet facets from facets.json file in theme
<?php
//...
add_filter( 'facetwp_facets', function($facets) {
//Load facets.json file located in theme folder
$imported_facets = json_decode(file_get_contents(trailingslashit(dirname(__FILE__)) . 'facets.json'), true);
//Import facets
foreach($imported_facets['facets'] as $single_facet) {
$facets[] = $single_facet;
@khromov
khromov / infogram-oembed.php
Created October 19, 2017 12:25
Infogram oEmbed plugin
<?php
/*
Plugin Name: Infogram oEmbed
Plugin URI:
Description: Adds oEmbed support for infogr.am and infogram.com urls.
Author: khromov
Version: 1.0
Author URI: https://khromov.se
*/
@khromov
khromov / acf-link-picker-shortcode.php
Last active March 27, 2018 04:24
ACF Link Picker Shortcode
@khromov
khromov / fix-broken-instagram.php
Last active March 1, 2018 11:33
Fix broken / overlapping Instagram embed for WordPress
<?php
/**
* Plugin Name: Fix broken Instagram oEmbed
* Description: Fixes an issue with Instagram posts being broken when multiple posts are oEmbedded.
* Version: 1.0
* Author: khromov
*/
/**
* Remove Instagram embed.js script on each embed
@khromov
khromov / acf-nowhere-location-rule.php
Created October 2, 2017 17:36
"Nowhere" location rule for Advanced Custom Fields - never matches
<?php
/*
Plugin Name: Advanced Custom Fields: Nowhere location rules
Description: Adds a "Nowhere" location rule in ACF
*/
add_filter('acf/location/rule_types', function($rules) {
$rules['Extra']['nowhere'] = 'Nowhere';