arraypress/wp-anonymize-utils

A simple WordPress utility for anonymizing personal data (names, phones, addresses)

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

pkg:composer/arraypress/wp-anonymize-utils

dev-main 2025-11-16 12:52 UTC

This package is auto-updated.

Last update: 2025-11-16 12:52:39 UTC


README

A simple WordPress utility for anonymizing personal data including names, phone numbers, addresses, and generic text masking. Perfect for GDPR compliance and e-commerce privacy requirements.

Features

  • ðŸŽŊ Focused API - Just 6 essential methods for personal data anonymization
  • 🔒 Privacy Compliance - Built for GDPR and privacy regulations
  • ðŸ“Ķ E-commerce Ready - Perfect for WooCommerce and custom shop plugins
  • ðŸŠķ Lightweight - Single class, ~150 lines of code
  • 🔧 Global Functions - Optional helper functions for convenience

Requirements

  • PHP 7.4 or later
  • WordPress 5.0 or later

Installation

composer require arraypress/wp-utils-anonymize

Usage

Using the Class

use ArrayPress\AnonymizeUtils\Anonymize;

// Anonymize names - preserves first and last letter
$name = Anonymize::name( 'John Smith' );
// Returns: "J**n S***h"

// Anonymize phone numbers - keeps last 4 digits
$phone = Anonymize::phone( '555-123-4567' );
// Returns: "*******4567"

// Anonymize addresses - preserves structure
$address = Anonymize::address( '123 Main Street' );
// Returns: "*** **** ******"

// Anonymize zip codes - keeps last 2 characters
$zip = Anonymize::zipcode( '90210' );
// Returns: "***10"

// Generic text masking
$text = Anonymize::text( 'sensitive', 2, 1 );
// Returns: "se******e"

// Bulk anonymize fields
$data = Anonymize::fields( [
    'billing_name' => 'John Doe',
    'billing_phone' => '555-1234',
    'billing_address' => '123 Main St'
] );
// Returns anonymized array with auto-detection

Using Global Functions

// Simple global functions for common operations
echo anonymize_name( 'Jane Doe' );        // "J**e D*e"
echo anonymize_phone( '555-1234' );       // "****1234"  
echo anonymize_address( '456 Oak Ave' );  // "*** *** ***"

E-commerce Example

use ArrayPress\Utils\Anonymize;

// GDPR compliance - anonymize customer data
class Order_Privacy {
    
    public function anonymize_order( $order_id ) {
        $order = wc_get_order( $order_id );
        
        // Anonymize billing information
        $order->set_billing_first_name( Anonymize::name( $order->get_billing_first_name() ) );
        $order->set_billing_last_name( Anonymize::name( $order->get_billing_last_name() ) );
        $order->set_billing_phone( Anonymize::phone( $order->get_billing_phone() ) );
        $order->set_billing_address_1( Anonymize::address( $order->get_billing_address_1() ) );
        $order->set_billing_postcode( Anonymize::zipcode( $order->get_billing_postcode() ) );
        
        $order->save();
    }
}

Check if Data is Anonymized

$name = 'J**n S***h';
if ( Anonymize::is_anonymized( $name ) ) {
    // Data has already been anonymized
}

Methods

name( string $name ): string

Anonymizes names while preserving the first and last letter of each word.

phone( string $phone, int $keep_last = 4 ): string

Anonymizes phone numbers, keeping only the specified number of last digits.

address( string $address ): string

Anonymizes addresses while preserving structure (spaces, punctuation, line breaks).

zipcode( string $zip, int $keep_last = 2 ): string

Anonymizes postal codes, keeping only the specified number of last characters.

text( string $text, int $show_first = 1, int $show_last = 1 ): string

Generic text masking that shows only specified characters at start and end.

fields( array $data ): array

Bulk anonymize multiple fields with automatic type detection based on field names.

is_anonymized( string $text ): bool

Check if text appears to be already anonymized (contains 3+ asterisks).

Why This Library?

  • Focused - Just personal data anonymization, nothing else
  • E-commerce Ready - Built with WooCommerce/SugarCart needs in mind
  • GDPR Compliant - Helps meet "right to be forgotten" requirements
  • Simple API - Easy to remember methods that do one thing well
  • No Dependencies - Just PHP and WordPress

Note on Email and IP Anonymization

This library focuses on personal data (names, phones, addresses). For email and IP anonymization, use the dedicated utilities:

License

GPL-2.0-or-later

Support