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 / disable-update-plugins.php
Last active November 20, 2018 12:56
Disable update of certain plugins.Put this file into /wp-content/mu-plugins/
<?php
/**
* Plugin Name: Disable updates plugins
* Plugin URI: https://kagg.eu/en/
* Description: Disable update of certain plugins.
* Version: 1.0
* Author: KAGG Design
* Author URI: https://kagg.eu/en/
* License: GPL2
*/
@kagg-design
kagg-design / kagg_get_between.php
Last active December 9, 2018 11:32
Finds a substring between two strings.
<?php
/**
* Finds a substring between two strings.
*
* @param string $string The string to be searched
* @param string $start The start of the desired substring
* @param string $end The end of the desired substring
* @param bool $greedy Use last instance of`$end` (default: false)
*
<?php
/**
* Change site url in admin bar
*
* @param WP_Admin_Bar $wp_admin_bar
*/
function admin_bar_menu_filter( WP_Admin_Bar $wp_admin_bar ) {
$new_url = 'site.org';
$site_name_node = $wp_admin_bar->get_nodes()['site-name'];
$site_name_node->href = $new_url;
@kagg-design
kagg-design / is_gutenberg_active.php
Last active January 27, 2019 21:18
Function to check if Gutenberg is active.
<?php
/**
* Check if Block Editor is active.
* Must only be used after plugins_loaded action is fired.
*
* @return bool
*/
function is_active() {
// Gutenberg plugin is installed and activated.
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) );
@kagg-design
kagg-design / clear-grp-cron-jobs.php
Created January 17, 2019 17:40
Clear multiple cron jobs created by Google Reviews Business plugin.
<?php
/**
* Clear multiple cron jobs created by Google Reviews Business plugin.
*/
function clear_cron_jobs() {
$crons = _get_cron_array();
$hook = 'grp_auto_save';
$args_array = array();
$new_cron = array();
foreach ( $crons as $timestamp => $cron ) {
@kagg-design
kagg-design / add_admin
Created April 26, 2019 08:45
Simple mu-plugin to add admin to the site
<?php
/**
* Plugin Name: Add Admin
* Plugin URI: https://kagg.eu/en/
* Description: Add admin to the WordPress site.
* Version: 1.0
* Author: KAGG Design
* Author URI: https://kagg.eu/en/
* License: GPL2
*
@kagg-design
kagg-design / kagg_syntaxhighlighter_precode.php
Last active September 6, 2019 08:21
Due to issue in SyntaxHighlighter Evolved plugin & symbol is output as &amp; what makes code unreadable.
<?php
/**
* Filter to fix issue in SyntaxHighlighter Evolved plugin.
*
* @param string $code Code to format.
* @param array $atts Attributes.
* @param string $tag Tag.
*
* @return string
*/
@kagg-design
kagg-design / sample-rest-output.json
Created November 16, 2019 09:46
Sample rest output
[
{
"id": 217,
"date": "2019-11-14T11:20:23",
"date_gmt": "2019-11-14T08:20:23",
"guid": {
"rendered": "http:\/\/wpml.test\/?page_id=217"
},
"modified": "2019-11-15T12:36:54",
"modified_gmt": "2019-11-15T09:36:54",
<?php
require_once 'C:\laragon\www\test\wp-load.php';
echo 'Filling up array...' . "\n";
$size = 10 * 1000;
$cycles = 1000 * 1000;
$array = [];
@kagg-design
kagg-design / 1.php
Last active January 11, 2020 16:50
Preemptive cache
<?php
$data = [
'element_data' =>
[
7 =>
[
'translation_id' => '18',
'trid' => '12',
'lang' => 'en',