Skip to content

Instantly share code, notes, and snippets.

View villesiltala's full-sized avatar

villesiltala villesiltala

View GitHub Profile
@villesiltala
villesiltala / obfuscate-wp-users.php
Last active November 13, 2023 03:40
Obfuscate WordPress user data
<?php
/**
* This script obfuscates WordPress user data for defined user roles.
*/
global $wpdb;
// This example obfuscates all user data for WooCommerce customers.
$roles = [
'customer',
@villesiltala
villesiltala / get_post_by_slug.php
Last active December 8, 2021 00:07
WordPress - Get a post by its post name (slug) and cache results.
<?php
/**
* Get a post object by its post name (slug).
*
* @param string $slug The post name value.
* @param string $post_type The post type to fetch from. Default: 'post'.
*
* @return \WP_Post|bool The post object if found, false if not.
*/
@villesiltala
villesiltala / strip_tags_and_content.php
Last active August 16, 2018 14:20
PHP - Strip HTML tags and content from a string
<?php
/**
* A script for removing a set of HTML tags and their content.
* This example strips all style tags and CSS inside them.
* $content is assumed to contain some HTML.
* To extend this, change or add tags to the $unwanted array.
*/
$unwanted = [
'style',
@villesiltala
villesiltala / keybase.md
Last active May 29, 2018 09:56
My Keybase proof

Keybase proof

I hereby claim:

  • I am villesiltala on github.
  • I am villesiltala (https://keybase.io/villesiltala) on keybase.
  • I have a public key ASCBWhG9oDy7ifcbDr_eB15JEL7DJ8xmRqmIrNNsAFpoOwo

To claim this, I am signing this object:

@villesiltala
villesiltala / group-caching-demo.php
Last active June 12, 2017 08:35
WP Redis Group Cache usage example - see the comment section for description
---- page.php ---
<?php
/**
* This is a demo for using the WP Redis Group Cache.
*/
/**
* A demo DustPress model class.
*/
class Page extends \DustPress\Model {
@villesiltala
villesiltala / i18n.html
Last active April 4, 2016 06:59
A client-side i18n example with some simple jQuery DOM manipulation.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Client-side i18n</title>
</head>
<body>
<div class="container">
<header>
<ul id="i18n-menu">