Skip to content
SacredWP
  • Home
  • Products
    • Highlite Pro
  • Documentation
    • Highlite Pro
  • Blog
    • Plugins
      • Highlite
  • My Highlights
  • Login

Highlite Pro

9
  • 🔧 Plugin Overview and Key Features
  • 🛠️ Installation & Activation Instructions
  • ⚙️ Plugin Settings Configuration (Max Words & Post Types)
  • 🖍️ Frontend Highlighting Features and Workflow
  • 📋 Highlight List Shortcode & User Dashboard ([[highlite_list]])
  • 🖨️ Download and Print Highlights – DOCX & HTML Export
  • 🔄 AJAX Functionality and Data Persistence Logic
  • 🎨 Customization, Styling, and Developer Notes
  • ❓ Frequently Asked Questions (FAQ)
View Categories
  • Home
  • Docs
  • Highlite
  • Highlite Pro
  • 🔄 AJAX Functionality and Data Persistence Logic

🔄 AJAX Functionality and Data Persistence Logic

1 min read

At the heart of Highlite Pro is its dynamic interaction model, powered by AJAX. Every highlight, color change, note, and deletion action is performed asynchronously—without refreshing the page—creating a seamless user experience.

This section explains how the plugin handles real-time data saving, editing, and retrieval using AJAX, as well as how it stores user-specific data securely in the WordPress database.


⚙️ Key AJAX Operations #

All AJAX actions are triggered via wp_ajax_{action} hooks and are available only to logged-in users.

✅ 1. save_user_highlight #

  • Purpose: Save the highlight reference and its plain text.
  • Data Stored:
    • user_highlights_{post_id} → Array of encoded highlight keys
    • user_highlight_texts_{post_id} → [key] => text
    • user_highlight_dates_{post_id} → [key] => timestamp

✅ 2. save_user_highlight_color #

  • Purpose: Save or update the background color of a highlight.
  • Data Stored:
    • user_highlight_colors_{post_id} → [key] => hex color code

✅ 3. save_user_highlight_note #

  • Purpose: Save or update the note attached to a highlight.
  • Data Stored:
    • user_highlight_notes_{post_id} → [key] => HTML note content (Quill.js output)

✅ 4. get_user_highlights #

  • Purpose: Retrieve all highlight keys for the current user on a given post.
  • Used During: Page load, to restore previously saved highlights.

✅ 5. get_user_highlight_colors #

  • Purpose: Fetch the highlight colors for the current user on a post.
  • Usage: Ensures that highlight colors are immediately visible after page reload.

✅ 6. get_user_highlight_note #

  • Purpose: Retrieve a saved note for a specific highlight key.
  • Used When: A user clicks the 📝 note icon to edit an existing note.

✅ 7. delete_user_highlight #

  • Purpose: Remove a specific highlight and its associated data.
  • Data Cleared:
    • From all 5 metadata arrays (keys, texts, notes, colors, dates)

💾 Data Storage Model #

Each type of metadata is saved under the usermeta table for the currently logged-in user:

Meta Key FormatValue TypePurpose
user_highlights_{post_id}ArrayList of highlight keys
user_highlight_texts_{post_id}Associative ArrayStores the plain text of the highlight
user_highlight_colors_{post_id}Associative ArrayStores background color
user_highlight_notes_{post_id}Associative ArrayStores HTML-formatted notes
user_highlight_dates_{post_id}Associative ArrayTimestamp of each highlight

🔒 Security Considerations #

  • All AJAX requests:
    • Are limited to authenticated users via wp_ajax_ hooks.
    • Use sanitize_text_field, wp_kses_post, and nonces to prevent tampering or XSS.
  • Notes accept only safe HTML (thanks to wp_kses_post() sanitization).
  • Deletion and modification operations validate that:
    • The key exists
    • The user is authorized

🧪 Example Flow: Creating a Highlight #

  1. User selects a phrase on a post.
  2. Plugin captures DOM path + offset info and generates a unique key.
  3. AJAX save_user_highlight is fired with the key and text.
  4. Simultaneously:
    • save_user_highlight_color stores the chosen background color.
    • save_user_highlight_note stores an optional Quill-formatted note.
  5. Page reloads → get_user_highlights and get_user_highlight_colors fetch all saved items and render them client-side.

Related #


Discover more from SacredWP #

Subscribe to get the latest posts sent to your email.

Updated on May 17, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
🖨️ Download and Print Highlights – DOCX & HTML Export🎨 Customization, Styling, and Developer Notes

Leave a Comment Cancel reply

Table of Contents
  • ⚙️ Key AJAX Operations
    • ✅ 1. save_user_highlight
    • ✅ 2. save_user_highlight_color
    • ✅ 3. save_user_highlight_note
    • ✅ 4. get_user_highlights
    • ✅ 5. get_user_highlight_colors
    • ✅ 6. get_user_highlight_note
    • ✅ 7. delete_user_highlight
  • 💾 Data Storage Model
  • 🔒 Security Considerations
  • 🧪 Example Flow: Creating a Highlight

About | Contact | Terms | Privacy

© 2025 SacredWP • Built with GeneratePress