Plugin Directory

Changeset 3384366


Ignore:
Timestamp:
10/25/2025 08:46:31 AM (5 months ago)
Author:
pointalize
Message:

Simplified even more by removing the faq-item class dependency.

Location:
pointalize-faq-markup
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • pointalize-faq-markup/trunk/pointalize-faq-markup.php

    r3380535 r3384366  
    44 * Plugin URI: https://pointalize.com/
    55 * Description:       Automatically generates FAQPage JSON-LD from <details class="faq-item">…</details> in post/page content (answers output as plain text).
    6  * Version:           1.0
     6 * Version:           1.1
    77 * Requires at least: 5.0
    88 * Requires PHP:      7.4
     
    1818
    1919/**
    20  * Extract Q&A pairs from <details class="faq-item"> blocks within an HTML string.
     20 * Extract Q&A pairs from <details> blocks within an HTML string.
    2121 *
    2222 * Rules:
    2323 * - Question = text inside <summary>
    24  * - Answer   = text inside <div class="faq-content"> if present, else first <p>
     24 * - Answer   = text inside first <p> after the <summary>, else remaining text in <details>
    2525 * - All HTML in answers is stripped → plain text only for clean schema.
    2626 *
     
    3232    if ( ! $html || stripos( $html, '<details' ) === false ) return $faqs;
    3333
    34     // Match all <details class="faq-item">...</details>
    35     if ( ! preg_match_all('/<details[^>]*class="[^"]*\\bfaq-item\\b[^"]*"[^>]*>(.*?)<\\/details>/is', $html, $items) ) {
     34    // Match all <details>...</details> blocks (any <details>, no class required)
     35    if ( ! preg_match_all('/<details[^>]*>(.*?)<\/details>/is', $html, $items) ) {
    3636        return $faqs;
    3737    }
    3838
    3939    foreach ( $items[1] as $block ) {
    40         // Question from <summary>
    41         if ( ! preg_match('/<summary[^>]*>(.*?)<\\/summary>/is', $block, $qm) ) continue;
     40
     41        // Extract <summary> (question)
     42        if ( ! preg_match('/<summary[^>]*>(.*?)<\/summary>/is', $block, $qm) ) continue;
    4243        $q = trim( wp_strip_all_tags( $qm[1] ) );
    4344        if ( $q === '' ) continue;
    4445
    45         // Answer: prefer .faq-content, else first <p>
     46        // Remove the <summary> portion so we can inspect the remaining HTML for the answer
     47        $after_summary = preg_replace('/<summary[^>]*>.*?<\/summary>/is', '', $block);
     48
     49        // Answer: first <p> after <summary>, else fallback to remaining text
    4650        $answer_html = '';
    47         if ( preg_match('/<div[^>]*class="[^"]*\\bfaq-content\\b[^"]*"[^>]*>(.*?)<\\/div>/is', $block, $am) ) {
    48             $answer_html = trim( $am[1] );
    49         } elseif ( preg_match('/<p[^>]*>(.*?)<\\/p>/is', $block, $pm) ) {
     51        if ( preg_match('/<p[^>]*>(.*?)<\/p>/is', $after_summary, $pm) ) {
    5052            $answer_html = trim( $pm[1] );
     53        } else {
     54            $answer_html = trim( $after_summary );
    5155        }
    5256        if ( $answer_html === '' ) continue;
    5357
    5458        // ---- Strip ALL HTML to plain text ----
    55         // Remove shortcodes (e.g., [shortcode]).
     59        // Remove shortcodes (e.g., [shortcode])
    5660        $answer_plain = strip_shortcodes( $answer_html );
    57         // Strip tags, decode entities (so &amp; -> &), normalize whitespace.
     61        // Strip tags, decode entities (so &amp; -> &), normalize whitespace
    5862        $answer_plain = wp_strip_all_tags( $answer_plain, true );
    5963        $answer_plain = html_entity_decode( $answer_plain, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
    60         // Collapse multiple spaces/newlines to single spaces.
    61         $answer_plain = preg_replace( '/\s+/u', ' ', $answer_plain );
     64        // Collapse multiple spaces/newlines to single spaces
     65        $answer_plain = preg_replace('/\s+/u', ' ', $answer_plain );
    6266        $answer_plain = trim( $answer_plain );
    6367
  • pointalize-faq-markup/trunk/readme.txt

    r3380535 r3384366  
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1515Pointalize FAQ Markup automatically adds valid **FAQPage JSON-LD structured data** to your WordPress posts and pages — helping your content qualify for Google’s rich FAQ results.
    1616
    17 Simply add collapsible FAQ sections using standard HTML `<details class="faq-item">` blocks, and the plugin will detect them automatically, generate the required JSON-LD markup, and inject it into your page’s `<head>` — no Gutenberg blocks, shortcodes, or extra settings required.
     17Simply add collapsible FAQ sections using standard HTML `<details>` blocks, and the plugin will detect them automatically, generate the required JSON-LD markup, and inject it into your page’s `<head>` — no Gutenberg blocks, shortcodes, or extra settings required.
    1818
    1919**Main Features:**
    20 * Detects all `<details class="faq-item">` blocks automatically 
    21 * Extracts questions from `<summary>` and answers from `<p>` tag 
     20* Detects all `<details>` blocks and extracts questions and answers automatically.
    2221* Outputs valid FAQPage JSON-LD schema for Google Rich Results 
    2322* Works on posts, pages, and custom post types 
     
    2928= Features =
    3029
    31 * Detects all `<details class="faq-item">` blocks automatically 
    32 * Extracts questions from `<summary>` and answers from `<div class="faq-content">` or first `<p>` tag 
    33 * Generates valid **FAQPage JSON-LD** markup 
     30* Detects all `<details>` blocks and extracts questions and answers automatically.
     31* Outputs valid FAQPage JSON-LD schema for Google Rich Results 
    3432* Works on posts, pages, and custom post types 
    35 * Outputs plain-text answers (no HTML) 
    36 * Zero dependencies, zero bloat — pure PHP 
     33* Converts answers to plain text for maximum schema compatibility   
     34* No dependencies, no UI, zero bloat — pure PHP simplicity 
    3735
    3836= Example Usage =
     
    4038Add the following to your WordPress post or page:
    4139
    42 <details class="faq-item">
     40<details>
    4341  <summary>How do I enable FAQ markup?</summary>
    4442  <p>Simply install and activate the plugin. It automatically detects your FAQ blocks.</p>
    4543</details>
    4644
    47 <details class="faq-item">
     45<details>
    4846  <summary>Does it work on pages too?</summary>
    4947  <p>Yes, it supports posts, pages, and custom post types out of the box.</p>
     
    5654You can install **Pointalize FAQ Markup** in two simple ways:
    5755
    58 = Option 1 — Upload the ZIP manually: =
     56= Option 1 — Install directly from WordPress: =
     571. Go to **Plugins → Add New**
     582. Search for “Pointalize FAQ Markup”
     593. Click **Install Now**, then **Activate**
     60
     61= Option 2 — Upload the ZIP manually: =
    59621. Download the plugin ZIP file (`pointalize-faq-markup.zip`)
    60632. In your WordPress dashboard, go to **Plugins → Add New → Upload Plugin**
     
    62654. Activate the plugin
    6366
    64 = Option 2 — Install directly from WordPress: =
    65 1. Go to **Plugins → Add New**
    66 2. Search for “Pointalize FAQ Markup”
    67 3. Click **Install Now**, then **Activate**
    68 
    69 After activation, the plugin will automatically detect any `<details class="faq-item">` blocks in your content and output the corresponding FAQ schema.
     67After activation, the plugin will automatically detect any `<details>` blocks in your content and output the corresponding FAQ schema.
    7068
    7169== Frequently Asked Questions ==
    7270
    7371= Do I need to configure anything? =
    74 No. The plugin works automatically on any post or page containing `<details class="faq-item">` elements.
     72No. The plugin works automatically on any post or page containing `<details>` elements.
    7573
    7674= Can I use HTML inside my answers? =
     
    9391= 1.0 =
    9492* Initial release
     93= 1.1 =
     94* Simplified even more by removing the faq-item class dependency.
    9595
    9696== Screenshots ==
Note: See TracChangeset for help on using the changeset viewer.