Skip to content

Instantly share code, notes, and snippets.

View ihorvorotnov's full-sized avatar
🇺🇦
Working remotely since 1999

Ihor Vorotnov ihorvorotnov

🇺🇦
Working remotely since 1999
View GitHub Profile
@mishterk
mishterk / Dump.php
Created October 19, 2019 10:42
A simple static class for dumping information to a log file of your choosing. For more info, see https://philkurth.com.au/tips/a-php-class-for-dumping-data-to-a-separate-log-file/
<?php
/**
* Class Dump
* A simple static class for dumping data to a separate log file to aid debugging and development.
*
* @author Phil Kurth <phil@philkurth.com.au>
*/
class Dump {
@mishterk
mishterk / aliased-one-liner-to-update-everything-in-wordpress.sh
Last active July 1, 2020 11:19
Simplify WordPress updates by bundling them by using WP CLI and running them all from the one 'command'. For more info see https://philkurth.com.au/tips/simplify-wordpress-updates-using-these-sequential-wp-cli-commands/
alias wp-update-all="wp plugin update --all && wp language plugin update --all && wp theme update --all && wp language theme update --all && wp core update --force && wp language core update"
<?php
/*
* This is a rather simple and contrived example but it illustrates how this
* function can be used to temporarily change the post context.
*/
$alt_post_content = override_post_context( 1234, function ( $post ) {
ob_start();
// Do whatever you need here. The $post variable, in this scope, is the
<?php
add_action( 'wp_enqueue_scripts', function () {
$uri = get_stylesheet_directory_uri();
$dir = get_stylesheet_directory();
$script_last_updated_at = filemtime( "$dir/scripts/my-script.js" );
$style_last_updated_at = filemtime( "$dir/styles/my-style.css" );
@mishterk
mishterk / 0-readme.md
Last active July 1, 2020 11:21
A basic example for querying data from custom tables created using ACF Custom Database Tables. For more info see https://hookturn.io/2019/09/how-to-use-acf-custom-database-tables-data-with-wp_query-objects/

How to use your custom table data with WP_Object queries

This example illustrates how to query an array of post IDs from a custom DB table then use the array in a WP_Query.

This can be much faster than using meta queries on a WP_Query object, particularly if you are matching multiple fields.

@mishterk
mishterk / custom-wordpress-menu-items-template.php
Last active November 30, 2021 18:29
How to render WordPress menu items without a custom walker
<?php $menu_location = 'some_menu_location'; ?>
<?php if ( has_nav_menu( $menu_location ) ): ?>
<?php $menu_items = wp_get_nav_menu_items( wp_get_nav_menu_name( $menu_location ) ); ?>
<?php foreach ( $menu_items as $menu_item ): ?>
<a href="<?= esc_url( $menu_item->url ) ?>"
target="<?= esc_attr( $menu_item->target ?: '_self' ) ?>"
@binyamin
binyamin / utils.js
Last active February 19, 2020 17:24
Useful Javascript Utility Functions
module.exports = {
generateId: function() {
// Generate a semi-unique id
return '_' + Math.random().toString(36).substr(2, 9);
},
byteToString: function(blob) {
// Turn an arraybuffer into a base64 string
return btoa(new Uint8Array(blob).reduce(function (data, byte) {
return data + String.fromCharCode(byte);
}, ''))
@ralphschindler
ralphschindler / SnapshotCommand.php
Created July 11, 2019 20:26
An example Laravel app command to create and load database snapshots using S3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class SnapshotCommand extends Command
{
@JoeyBurzynski
JoeyBurzynski / 55-bytes-of-css.md
Last active May 6, 2024 10:42
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@hellofromtonya
hellofromtonya / variable-refcount.php
Created March 19, 2019 17:15
Exploring PHP Variables, recount, and copy on write.
<?php
add_action( 'init', function() {
/**
* 1. PHP adds the variable into the symbols table.
* 2. PHP adds the value into the data table, which is called zval.
* 3. PHP points the value location to the variable location, binding them together.
* 4. refcount is incremented to 1.
*/