Skip to content

Stepfox/regulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Regulator - Content Corrector

A powerful WordPress plugin for conditional content swapping based on multiple criteria.

Features

Multiple Condition Support

Create rules with multiple conditions using AND/OR logic:

  • AND Logic: All conditions must be met
  • OR Logic: At least one condition must be met

Condition Types

Device Type

  • Device is mobile phone
  • Device is desktop
  • Device is tablet

Operating System

  • Windows
  • Mac
  • Linux
  • Android
  • iOS

Location

  • Country detection (requires CloudFlare or geo-location service)

User Conditions

  • User is logged in
  • User is logged out
  • User has specific role

Date & Time

  • Date is after
  • Date is before
  • Day of week is
  • Time is after
  • Time is before

Advanced

  • URL parameter exists
  • URL parameter equals specific value
  • Referrer contains specific text
  • Cookie exists
  • Cookie equals specific value

How to Use

Creating a Rule

  1. Go to WordPress Admin > Regulator
  2. Click Add New Rule
  3. Select a Source Page (the page where the rule will be applied)
    • Regular pages
    • 🏠 Front Page (for block themes)
    • 📰 Blog Page (for block themes)
  4. Add one or more Conditions:
    • Click "Add Condition" to add multiple conditions
    • Select condition type from categorized dropdowns
    • Enter values for conditions that require them
    • Choose AND/OR logic for multiple conditions
  5. Select a Target Page (the content that will replace the source page)
    • Both published and draft pages are available
    • Draft pages are marked with (Draft) for easy identification
    • Perfect for testing before publishing!
  6. Set Priority if you have multiple rules on the same page
  7. Enable/disable the rule with the Active checkbox
  8. Click Save Rule

Example Use Cases

Example 1: Mobile Users from Specific Country

Source Page: Homepage
Conditions:
  - Device is mobile phone (AND)
  - Country is United States
Logic: AND (match all)
Target Page: Mobile US Homepage

Example 2: Desktop or Tablet Users

Source Page: Product Page
Conditions:
  - Device is desktop (OR)
  - Device is tablet
Logic: OR (match any)
Target Page: Desktop Product Page

Example 3: Complex Rule

Source Page: Landing Page
Conditions:
  - Operating System: Windows (AND)
  - Device is desktop (AND)
  - Country is Canada
Logic: AND (match all)
Target Page: Canada Windows Landing Page

Country Detection

Country detection requires a geo-location service. The plugin supports:

  1. CloudFlare - Automatically detected via HTTP_CF_IPCOUNTRY header
  2. Custom Headers - Supports common headers like:
    • HTTP_X_COUNTRY_CODE
    • HTTP_GEOIP_COUNTRY_CODE
    • HTTP_X_GEOIP_COUNTRY_CODE

CloudFlare Setup

If you're using CloudFlare, country detection works automatically. No additional setup needed.

Custom Geo-Location

Add a filter to integrate your geo-location service:

add_filter('regulator_check_country', function($result, $country_code) {
    // Your custom geo-location logic here
    $user_country = your_geo_service_get_country();
    return strtoupper($user_country) === strtoupper($country_code);
}, 10, 2);

Operating System Detection

Operating systems are detected via User Agent strings:

  • Windows: Detects all Windows versions
  • Mac: Detects macOS/Mac OS X
  • Linux: Detects Linux (excluding Android)
  • Android: Detects Android OS
  • iOS: Detects iPhone, iPad, and iPod

Device Detection

Device types are detected using:

  • Mobile: WordPress's wp_is_mobile() function
  • Desktop: Inverse of mobile detection
  • Tablet: Enhanced detection including iPad, Android tablets, etc.

Priority System

When multiple rules exist for the same page:

  1. Rules are evaluated in order of priority (highest first)
  2. The first rule whose conditions are met will be applied
  3. No other rules are evaluated after a match

Database Structure

The plugin creates a wp_regulator_rules table with the following fields:

  • id: Unique rule identifier
  • source_page_id: The page where conditions are checked
  • target_page_id: The page content to display
  • conditions: JSON array of conditions
  • condition_logic: AND or OR
  • is_active: Enable/disable the rule
  • priority: Evaluation order

Extending the Plugin

Adding Custom Conditions

// Add your condition check
add_filter('regulator_check_condition', function($result, $condition_type, $condition_value) {
    if ($condition_type === 'custom_condition') {
        // Your custom logic here
        return true; // or false
    }
    return $result;
}, 10, 3);

Adding Custom Condition Types

Modify the get_condition_types() method in the main plugin class to add new condition types.

Changelog

Version 1.0.0

  • Initial release
  • Multiple conditions support
  • AND/OR logic
  • Device type detection
  • Operating system detection
  • Country detection
  • User conditions
  • Date & time conditions
  • Advanced URL and cookie conditions

Troubleshooting

Rule Won't Save

If you're having trouble saving rules:

  1. Clear your browser cache - Press Ctrl+F5 (Windows) or Cmd+Shift+R (Mac) to hard refresh
  2. Check browser console - Open Developer Tools (F12) and check the Console tab for errors
  3. Ensure all fields are filled:
    • Source Page must be selected
    • At least one condition must be added
    • Target Page must be selected
  4. Check permissions - Ensure you have admin/manage_options capability

Database Update

If you upgraded from a previous version:

  1. Deactivate the plugin
  2. Reactivate the plugin (this will update the database schema)

Browser Compatibility

The plugin requires a modern browser that supports:

  • FormData API
  • ES6 JavaScript features
  • Recommended: Chrome, Firefox, Safari, or Edge (latest versions)

License

GPL v2 or later

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published