Skip to content

Instantly share code, notes, and snippets.

View kagg-design's full-sized avatar

Igor at KAGG Design kagg-design

View GitHub Profile
<?php
/**
* Error-handler to be used as a mu-plugin.
*
* @package kagg/compatibility
*/
// phpcs:disable Generic.Commenting.DocComment.MissingShort
/** @noinspection PhpIllegalPsrClassPathInspection */
/** @noinspection AutoloadingIssuesInspection */
<?php
class FooClass {
public static function get_instance() {
static $instance;
if ( ! $instance ) {
$variant = 'A';
@kagg-design
kagg-design / rest-download-xls.php
Created February 23, 2023 16:06
Download xls file via REST
<?php
add_action(
'rest_api_init',
static function () {
$namespace = 'myplugin/v1';
$route = '/file';
$params = [
[
'methods' => 'GET',
@kagg-design
kagg-design / level_order_traversal.php
Last active January 22, 2023 09:20
Traverse general tree in level order
<?php
/**
* Level order traversal of a general tree.
*
* @link https://www.geeksforgeeks.org/generic-tree-level-order-traversal/
* @package traverse-general-tree
*/
/**
* Node of an n-ary tree.
@kagg-design
kagg-design / stage.yml
Created November 16, 2022 16:45
GitHub action to deploy the plugin to the staging environment on commit to master
name: Deploy to Stage
on:
push:
branches:
- master
jobs:
release:
name: Deploy to Stage
@kagg-design
kagg-design / Turnstile.php
Created October 10, 2022 08:46
Turnstile integration with Quform
<?php
/**
* Turnstile class file.
*
* @package wtei-core
*/
namespace WTEICore;
use JsonException;
@kagg-design
kagg-design / kagg-shortcuts.php
Last active June 11, 2022 08:32
Open login page by Ctrl+Alt+L. Can be used as a mu-plugin.
<?php
/**
* Add shortcuts.
*
* @return void
*/
function kagg_shortcuts() {
?>
<script>
@kagg-design
kagg-design / Redirect.php
Created February 3, 2022 09:18
WPML redirect from /?lang= to /lang
<?php
/**
* Redirect class file.
*
* @package wtei-core
*/
namespace WTEICore;
/**
@kagg-design
kagg-design / uasort
Created November 12, 2021 18:25
uasort example
<?php
$arr = [
[ 'foo' => 1, 'bar' => 7, 'den' => 9 ],
[ 'foo' => 11, 'bar' => 4, 'den' => 0 ],
[ 'foo' => 1, 'bar' => 12, 'den' => 6 ],
[ 'foo' => 1, 'bar' => 10, 'den' => 6 ],
];
uasort( $arr, 'cmp' );
@kagg-design
kagg-design / class-wpml-element-translation.php
Created April 24, 2021 15:17
Keep cache size within limit
public function shutdown_action() {
$keys = $this->get_data_keys();
$data = [];
foreach ( $keys as $key ) {
$this->data[ $key ] = isset( $this->data[ $key ] ) ? $this->data[ $key ] : [];
$data[ $key ] = array_replace( $this->data[ $key ], $this->{$key} );
}
wp_cache_set( $this->get_cache_key(), $this->maybe_reduce_cache_size( $data ) );