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
@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 ) );
@kagg-design
kagg-design / remote-post-with-files.php
Created April 7, 2021 15:47
Example of how to send files to the remote server.
$boundary = str_repeat( '-', 24 ) . wp_generate_password( 16 );
$headers = array(
'content-type' => 'multipart/form-data; boundary=' . $boundary,
);
if ( ! isset( $files['path'] ) ) {
$error_message = 'Invalid arguments';
return array( $success, $error_message, $word_count, $individual_word_count );
}
@kagg-design
kagg-design / fix-authors-bug-5.7.php
Created March 22, 2021 08:28
MU-Plugin to temporary fix the problem with the list of authors on post edit page with Block Editor.
<?php
/**
* MU-Plugin to temporary fix the problem with the list of authors on post edit page with Block Editor.
* With WP 5.7, user with the Editor role is unable to search across long list of authors in Author combobox.
*
* @package kagg-design
*/
/**
* Fixes bug in WP 5.7 with author selection on post edit in admin.
@kagg-design
kagg-design / cyr2lat-attributes-in-woocommerce.php
Created March 20, 2021 14:01
MU Plugin to block transliteration of WooCommerce attributes and attribute terms.
<?php
/**
* MU Plugin to block transliteration of WooCommerce attributes and attribute terms.
*
* @package cyr-to-lat
*/
/**
* Class Block_WC_Attr_Cyr2lat.
*/
@kagg-design
kagg-design / disable-update-plugins.php
Last active July 19, 2022 15:46
Disable update plugins mu-plugin
<?php
/**
* Plugin Name: Disable updates plugins
* Plugin URI: https://kagg.eu/en/
* Description: Disable update of certain plugins.
* Version: 1.2
* Author: KAGG Design
* Author URI: https://kagg.eu/en/
* License: GPL2
*
@kagg-design
kagg-design / block-login.php
Last active June 23, 2020 14:32
Block any kind of logins to the site
<?php
/**
* Plugin Name: Block Login
*/
function no_login_authenticate_filter( $user, $username, $pass ) {
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
return null;
}
@kagg-design
kagg-design / att.php
Created June 23, 2020 11:58
Mail attachment missing
<?php
add_action( 'init', 'att_page', PHP_INT_MAX );
function att_page() {
if ( is_att_page() ) {
$attachment = null;
$to = '[email protected]';
$subject = 'subj';
$message = 'message';
include_once ABSPATH . 'wp-admin/includes/file.php';
jQuery( document ).ready(
function( $ ) {
var timer;
var logAjax = 0;
var $nonce = $( '#gts_webtranslator_gateway_nonce' ).val();
var $progressBarWrap = $( '#progress-bar-wrap' );
var $progressDot = $( '#progress-dot' );
var $progressCount = $( '#progress-count' );
var $progressBar = $( '#progress-bar' );
var $logElement = $( '#webtranslator-log' );
@kagg-design
kagg-design / functions.php
Created April 25, 2020 08:31
wc1c hooks
<?php
/**
* wc1c_import_product_xml hook
* Prevent processing a product if there is no product in database with same SKU.
* If product with the same SKU found in the db, update _wc1c_guid option to allow product update.
*
* @param array $product
* @param bool $is_full
*
* @return null|array