Giter VIP home page Giter VIP logo

wp-multisite-cookie-manager's Introduction

WordPress Logo

WordPress - Multisite Cookie Manager

Licence

Overview

Manage cookies across a WordPress multisite network with the Multisite Cookie Manager plugin.

This plugin allows network administrators and site admins to manage cookie expiration settings, and identify all cookies being set across the multisite network. It provides a settings page within each site's admin area where you can specify cookie expiration times based on user roles and manage geo-location data as well as user sessions. A unique cookie will be set for each site in the network based on the specified settings.

Features

  • Unique cookie generation per site, named based on the site name and blog ID.
  • Customizable cookie expiration times based on user roles and login status.
  • Geo-location data collection and user session tracking.
  • Logging and error handling for debugging.
  • Export and import of cookie settings via JSON.
  • Site admin settings page for managing cookies.
  • Usage reporting for monitoring cookies across the network.

Installation

  1. Download the plugin files to your computer.
  2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to the /wp-content/plugins/ directory of your WordPress multisite installation.
  3. Navigate to the Plugins page within your WordPress dashboard on the site where you want to manage cookies.
  4. Locate MN - WordPress Multisite Cookie Manager in the list of available plugins and click "Activate".
  5. Once activated, a new menu item "Cookie Settings" will appear in the admin dashboard of the site where you activated the plugin. Now you can manage cookie settings and view cookie usage reports from this menu.

Usage

Setting Cookie Expiration Times

  1. After activating the plugin, navigate to the Network Admin -> Settings page.
  2. Click on Cookie Settings in the menu.
  3. On the Cookie Settings page, you'll find a form to manage cookie expirations:
  4. Under Cookie Expirations, text area, input a JSON object with user roles and corresponding expiration times in seconds.

Example:

{
   "administrator": 86400,
   "editor": 43200,
   "author": 21600,
   "contributor": 10800,
   "subscriber": 5400,
   "logged_out": 1800
}
  1. Click Save Settings to save your changes.
  2. The plugin will automatically set cookies with the specified expiration times for each site in your network.

Exporting and Importing Settings

  • Export: Click on "Export Settings" to download a JSON file containing the current cookie expiration settings.
  • Import: Choose a JSON file by clicking "Choose File" under "Import Settings", then click "Import Settings" to apply the settings from the file.

Viewing Cookie Usage Reports

  • Navigate to the "Cookie Usage Reports" submenu under "Cookie Settings".
  • View the table showing the usage of each cookie across the network.

Clear the Cookies from DB

  • When you visit "Cookie Usage Reports" admin page, you'll see a "Clear Cookies" button above the table. Pressing this button will clear the cookies with the unique cookie name from the database.

Functions

mn_get_unique_cookie_name()

Generates a unique cookie name based on the site name and blog ID.

mn_log_error($message, $error_type = E_USER_NOTICE)

Handles error logging based on the WP_DEBUG settings in the WordPress configuration.

mn_register_cookie_settings_page()

Registers a new menu page in the network admin for managing cookie settings.

mn_cookie_settings_page()

Displays the cookie settings page, handles form submission for updating settings, and exporting/importing settings.

mn_get_cookie_expiration($default_expiration)

Determines the expiration time for a cookie based on the user's role.

mn_set_custom_cookie()

Sets a custom cookie on page load with a name generated by mn_get_unique_cookie_name() and expiration determined by mn_get_cookie_expiration().

mn_create_cookie_usage_table()

Creates a new database table for logging cookie usage on plugin activation.

mn_log_cookie_usage()

Logs cookie usage on page load.

mn_write_cookie_usage_log_entries()

Writes log entries from transient to database hourly.

mn_register_cookie_reporting_page()

Registers a submenu page for cookie usage reports.

mn_cookie_reporting_page()

Displays cookie usage reports.

mn_export_cookie_settings()

Exports cookie settings to a JSON file.

mn_import_cookie_settings($json_settings)

Imports cookie settings from a JSON file.

mn_get_geolocation_data()

Fetches the user's geo-location data using an external API.

mn_clear_cookies()

Function to clear the cookies with the unique cookie name from the database.

mn_handle_clear_cookies_request()

This function is triggered by the admin_init action. This function checks the nonce for security, calls mn_clear_cookies() to clear the cookies from the database, and displays a success message.

mn_custom_plugin_styles()

The function is designed to inject custom CSS styling into the admin pages of your WordPress site without the need for an external stylesheet file. This is achieved by hooking the function into the admin_head action, which triggers the function to output a <style> block within the <head> section of WordPress admin pages.

Error Handling and Debugging

Enable WP_DEBUG in your WordPress configuration to catch errors during development. In your wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Uninstallation

Upon uninstallation, the plugin will remove the multisite_cookie_usage table from the database.

FAQs

How do I set custom cookie expiration times?

Navigate to the Settings->Cookie Settings page on any site within your network. In the provided text area, input a JSON object specifying the expiration times for different user roles and for logged-out users. Click "Save Settings" to save your changes.

How are cookies named?

Cookies are named following this pattern: __site_name_blog_id, where site_name is the name of the site with all spaces removed and converted to lowercase, and blog_id is the ID of the site within the network.

Example: For a site named "My Site" with a blog ID of 2, the cookie would be named __mysite_2.

How can I view all cookies being set across the network?

Navigate to the Settings->Cookie Settings->Cookie Usage Reports on any site within your network to view a list of all unique cookies being set across the network along with the number of sites on which each cookie has been found.

How can I export or import cookie settings?

On the Settings->Cookie Settings page, you'll find options to export your current cookie settings to a JSON file, or import settings from a JSON file. This allows for easy transfer of settings between different sites or for backup purposes.

How can I style the settings and reports pages?

The plugin includes a function mn_custom_plugin_styles() that injects custom CSS into the admin pages. You can modify the CSS rules within this function to change the appearance of the plugin's settings and reports pages according to your preferences.

Changelog

For a detailed list of changes and updates made to this project, please refer to our Changelog.


License

This project is released under the GPL-2.0+ License.

wp-multisite-cookie-manager's People

Contributors

mnestorov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.