Skip to content

Instantly share code, notes, and snippets.

View nawawi's full-sized avatar

Nawawi Jamili nawawi

View GitHub Profile
@nawawi
nawawi / docketcache_flush_when_save_post.php
Created January 6, 2025 16:44
docketcache_flush_when_save_post.php
<?php
// Place this code in wp-content/mu-plugins/docketcache_flush_when_save_post.php
add_action('docketcache/init', function($docket_cache_instance) {
$docket_cache = $docket_cache_instance;
add_action( 'save_post', function($post_id, $post, $update) use($docket_cache) {
$result = $docket_cache->flush_cache(true);
$docket_cache->co()->lookup_set('occacheflushed', $result);
do_action('docketcache/action/flush/objectcache', $result);
}, 10, 3);
@nawawi
nawawi / docketcache_flush_daily.php
Last active December 26, 2024 11:30
docketcache_flush_daily.php
<?php
// Place this code in wp-content/mu-plugins/docketcache_flush_daily.php
add_action('docketcache/init', function($docket_cache_instance) {
$docket_cache = $docket_cache_instance;
add_action('docketcache_flush_daily', function() use($docket_cache) {
$result = $docket_cache->flush_cache(true);
$docket_cache->co()->lookup_set('occacheflushed', $result);
do_action('docketcache/action/flush/objectcache', $result);
});
@nawawi
nawawi / custom_base64_decode.php
Created December 9, 2024 13:25
custom_base64_decode
<?php
function custom_base64_decode($input) {
$base64_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
$output = '';
// Remove padding characters and replace invalid characters
$input = str_replace(['-', '_'], ['+', '/'], $input);
$input = rtrim($input, '=');
@nawawi
nawawi / 0-docket-cache-deactivate.php
Last active December 8, 2024 02:11
Prevent docket-cache from being activated
<?php
// Disable wp-content/object-cache.php
if (!defined('DOCKET_CACHE_DISABLED')) {
define('DOCKET_CACHE_DISABLED', true);
}
// Deactivate docket-cache
add_action('docketcache/init', function ($docket_cache_instance) {
try {
(new Nawawi\DocketCache\Event($docket_cache_instance))->unregister();
@nawawi
nawawi / 0-wpstg-reset.php
Last active February 17, 2025 10:02
0-wpstg-reset
<?php
add_action('wpstg.clone_first_run', function () {
// Set to false for actual operation
$isDryRun = true;
// Abort if not wp-staging staging site
if (empty($GLOBALS['table_prefix']) || !preg_match('@^wpstg\d+@', $GLOBALS['table_prefix'])) {
return;
}
<?php
add_action('docketcache/init', function($docket_cache_instance) {
$docket_cache = $docket_cache_instance;
// Flush cache
add_action('docket_cache_control_flush_cache', function() use($docket_cache) {
$result = $docket_cache->flush_cache(true);
$docket_cache->co()->lookup_set('occacheflushed', $result);
do_action('docketcache/action/flush/objectcache', $result);
});
@nawawi
nawawi / openssl_private_public_key_example.php
Created June 11, 2024 06:58
php openssl private/public key example
<?php
// Configuration settings for the key
$config = array(
"digest_alg" => "sha512",
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
// Create the private and public key
$res = openssl_pkey_new($config);
@nawawi
nawawi / intuitive-custom-post-order.php
Last active April 16, 2024 19:38
intuitive-custom-post-order.php
<?php
/*
* Plugin Name: Intuitive Custom Post Order
* Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
* Description: Intuitively, Order Items (Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites) using a Drag and Drop Sortable JavaScript.
* Version: 3.1.5
* Author: hijiri
* Author URI: http://hijiriworld.com/web/
* Text Domain: intuitive-custom-post-order
* Domain Path: /languages
<?php
function export_object($value, string $indent = '')
{
switch (true) {
case \is_int($value) || \is_float($value): return var_export($value, true);
case [] === $value: return '[]';
case false === $value: return 'false';
case true === $value: return 'true';
case null === $value: return 'null';
@nawawi
nawawi / remove_orphan_post.sql
Last active September 26, 2022 07:48
MySQL trigger to remove wp orphan post
-- Replace wp_postmeta and wp_posts with your prefix table
CREATE TRIGGER `remove_orphan_post` AFTER DELETE ON `wp_posts`
FOR EACH ROW BEGIN IF ('post' = old.post_type) THEN
DELETE FROM wp_postmeta WHERE wp_postmeta.post_id = old.ID;
END IF; END