Plugin Directory

Changeset 3458865


Ignore:
Timestamp:
02/11/2026 10:29:29 AM (7 weeks ago)
Author:
FreelanceDirectZA
Message:

Release 1.4.0 – Categories, filtering, and list mode added

Location:
cancer-awareness-ribbon-shortcode/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cancer-awareness-ribbon-shortcode/trunk/cancer-awareness-ribbon.php

    r3458719 r3458865  
    11<?php
     2
    23/**
    34 * Plugin Name: Cancer Awareness Ribbon Shortcode
    45 * Description: Adds a shortcode to display a cancer awareness ribbon whose colors change based on the current month (or by type override).
    5  * Version: 1.0.2
     6 * Version: 1.4.0
    67 * Author: Parallel Media
    78 * License: GPLv2 or later
     
    1819        plugins_url('assets/css/cancer-awareness-ribbon.css', __FILE__),
    1920        [],
    20         '1.0.2'
     21        '1.4.0'
    2122    );
    2223}, 20);
    2324
    2425/**
    25  * Cancer list: type => [label, month, colors[]]
     26 * Cancer list: type => [label, month, colors[], optional category]
     27 * Categories: Cancer, Medical, Social, Global
    2628 */
    2729function car_get_cancers(): array
     
    5961        'testicular_cancer' => ['label' => 'Testicular Cancer', 'month' => 4, 'colors' => ['#800080']],
    6062        'thyroid_cancer' => ['label' => 'Thyroid Cancer', 'month' => 9, 'colors' => ['#800080', '#00B3B3', '#FF69B4']],
     63
     64        // v1.1 - additional awareness ribbons (non-cancer)
     65        'hiv_aids_awareness' => ['label' => 'HIV / AIDS Awareness', 'month' => 12, 'colors' => ['#E10600'], 'category' => 'Global'],
     66        'autism_awareness' => ['label' => 'Autism Awareness', 'month' => 4, 'colors' => ['#1877F2'], 'category' => 'Medical'],
     67        'mental_health_awareness' => ['label' => 'Mental Health Awareness', 'month' => 5, 'colors' => ['#2E7D32'], 'category' => 'Medical'],
     68        'diabetes_awareness' => ['label' => 'Diabetes Awareness', 'month' => 11, 'colors' => ['#9E9E9E'], 'category' => 'Medical'],
     69        'heart_disease_awareness' => ['label' => 'Heart Disease Awareness', 'month' => 2, 'colors' => ['#C62828'], 'category' => 'Medical'],
     70
     71        // v1.2 - additional awareness ribbons (non-cancer)
     72        'domestic_violence_awareness' => ['label' => 'Domestic Violence Awareness', 'month' => 10, 'colors' => ['#800080'], 'category' => 'Social'],
     73        'prostate_health_awareness' => ['label' => 'Prostate Health Awareness', 'month' => 9, 'colors' => ['#7EC8E3'], 'category' => 'Medical'],
     74        'ovarian_health_awareness' => ['label' => 'Ovarian Health Awareness', 'month' => 9, 'colors' => ['#00B3B3'], 'category' => 'Medical'],
     75        'lung_health_awareness' => ['label' => 'Lung Health Awareness', 'month' => 11, 'colors' => ['#FFFFFF'], 'category' => 'Medical'],
     76        'alzheimers_awareness' => ['label' => 'Alzheimer’s Awareness', 'month' => 11, 'colors' => ['#5E2D79'], 'category' => 'Medical'],
     77
     78        // v1.3 - additional awareness ribbons (non-cancer)
     79        'pride_awareness' => ['label' => 'Pride Awareness', 'month' => 6, 'colors' => ['#E40303', '#FF8C00', '#FFED00', '#008026', '#004DFF', '#750787'], 'category' => 'Social'],
     80        'veterans_awareness' => ['label' => 'Veterans Awareness', 'month' => 11, 'colors' => ['#B22234', '#FFFFFF', '#3C3B6E'], 'category' => 'Social'],
     81        'child_protection_awareness' => ['label' => 'Child Protection Awareness', 'month' => 4, 'colors' => ['#0057B8'], 'category' => 'Social'],
     82        'anti_bullying_awareness' => ['label' => 'Anti-Bullying Awareness', 'month' => 10, 'colors' => ['#1E90FF'], 'category' => 'Social'],
     83        'organ_donation_awareness' => ['label' => 'Organ Donation Awareness', 'month' => 4, 'colors' => ['#4CAF50'], 'category' => 'Medical'],
    6184    ];
    6285}
     
    86109}
    87110
     111function car_normalize_category($v): string
     112{
     113    $v = trim((string)$v);
     114    if ($v === '') return '';
     115    $v = strtolower($v);
     116
     117    // allow a few friendly aliases
     118    if ($v === 'cancers') $v = 'cancer';
     119    if ($v === 'med') $v = 'medical';
     120
     121    $map = [
     122        'cancer' => 'Cancer',
     123        'medical' => 'Medical',
     124        'social' => 'Social',
     125        'global' => 'Global',
     126    ];
     127
     128    return $map[$v] ?? '';
     129}
     130
     131function car_item_category(array $item): string
     132{
     133    // Default: anything without explicit category is Cancer
     134    $cat = isset($item['category']) ? car_normalize_category($item['category']) : '';
     135    return $cat !== '' ? $cat : 'Cancer';
     136}
     137
     138function car_group_items_by_category(array $items): array
     139{
     140    $order = ['Cancer', 'Medical', 'Social', 'Global'];
     141    $grouped = [
     142        'Cancer' => [],
     143        'Medical' => [],
     144        'Social' => [],
     145        'Global' => [],
     146    ];
     147
     148    foreach ($items as $key => $item) {
     149        $cat = car_item_category($item);
     150        if (!isset($grouped[$cat])) $grouped[$cat] = [];
     151        $grouped[$cat][$key] = $item;
     152    }
     153
     154    // return ordered + any extra categories (future-proof)
     155    $out = [];
     156    foreach ($order as $cat) {
     157        if (!empty($grouped[$cat])) $out[$cat] = $grouped[$cat];
     158        unset($grouped[$cat]);
     159    }
     160    foreach ($grouped as $cat => $bucket) {
     161        if (!empty($bucket)) $out[$cat] = $bucket;
     162    }
     163
     164    return $out;
     165}
     166
    88167function car_render_ribbon_svg(array $colors, int $size, string $label): string
    89168{
     
    137216{
    138217    $atts = shortcode_atts([
    139         'type'  => '',
    140         'month' => '',
    141         'size'  => '64',
    142         'label' => '0',
    143         'class' => '',
     218        'type'     => '',
     219        'month'    => '',
     220        'size'     => '64',
     221        'label'    => '0',
     222        'class'    => '',
     223        'category' => '',   // v1.4: filter by category (Cancer, Medical, Social, Global)
     224        'list'     => '0',  // v1.4: list all ribbons for a selected month
    144225    ], $atts, 'cancer_ribbon');
    145226
     
    158239    }
    159240
     241    $category = car_normalize_category($atts['category']);
     242    $list_mode = ($atts['list'] === '1' || strtolower((string)$atts['list']) === 'true');
     243
     244    $extra_class = sanitize_html_class((string)$atts['class']);
     245
     246    // v1.4: list all awareness ribbons for the selected month (optionally filtered by category)
     247    if ($list_mode) {
     248        $matches = [];
     249
     250        foreach ($cancers as $key => $item) {
     251            if ((int)($item['month'] ?? 0) !== (int)$month) continue;
     252
     253            $item_cat = car_item_category($item);
     254            if ($category !== '' && strcasecmp($item_cat, $category) !== 0) continue;
     255
     256            $matches[$key] = $item;
     257        }
     258
     259        if (!$matches) {
     260            $wrap_class = 'car-ribbon-list-wrap' . ($extra_class ? ' ' . $extra_class : '');
     261            return '<div class="' . esc_attr($wrap_class) . '"><div class="car-ribbon-empty">No awareness ribbons found.</div></div>';
     262        }
     263
     264        // Group by category (Cancer, Medical, Social, Global)
     265        $grouped = car_group_items_by_category($matches);
     266
     267        $wrap_class = 'car-ribbon-list-wrap' . ($extra_class ? ' ' . $extra_class : '');
     268        $html = '<div class="' . esc_attr($wrap_class) . '">';
     269
     270        foreach ($grouped as $cat => $bucket) {
     271            $html .= '<div class="car-ribbon-category">';
     272            $html .= '<div class="car-ribbon-category-title">' . esc_html($cat) . '</div>';
     273            $html .= '<div class="car-ribbon-category-grid" style="display:flex;flex-wrap:wrap;gap:14px;">';
     274
     275            foreach ($bucket as $it) {
     276                $svg = car_render_ribbon_svg((array)$it['colors'], $size, (string)$it['label']);
     277
     278                $html .= '<div class="car-ribbon-wrap" style="--car-size:' . esc_attr($size) . 'px;">';
     279                $html .= $svg;
     280
     281                if ($show_label) {
     282                    $html .= '<div class="car-ribbon-label">' . esc_html((string)$it['label']) . '</div>';
     283                }
     284
     285                $html .= '</div>';
     286            }
     287
     288            $html .= '</div></div>';
     289        }
     290
     291        $html .= '</div>';
     292        return $html;
     293    }
     294
     295    // Single ribbon mode (existing behavior) + optional category filter when type is not forced
    160296    $type = sanitize_key((string)$atts['type']);
    161297    $selected = null;
    162298
     299    // Type override always wins
    163300    if ($type && isset($cancers[$type])) {
    164301        $selected = $cancers[$type];
    165302    } else {
    166         $featured = car_featured_by_month();
    167         if (isset($featured[$month]) && isset($cancers[$featured[$month]])) {
    168             $selected = $cancers[$featured[$month]];
     303        // If a category is provided and it's not Cancer, skip featured_by_month and pick first matching in that category for the month
     304        if ($category !== '' && $category !== 'Cancer') {
     305            foreach ($cancers as $item) {
     306                if ((int)($item['month'] ?? 0) === (int)$month && strcasecmp(car_item_category($item), $category) === 0) {
     307                    $selected = $item;
     308                    break;
     309                }
     310            }
    169311        } else {
     312            // Original featured-by-month logic
     313            $featured = car_featured_by_month();
     314            if (isset($featured[$month]) && isset($cancers[$featured[$month]])) {
     315                $candidate = $cancers[$featured[$month]];
     316                // If category is set (Cancer) ensure it matches
     317                if ($category === '' || strcasecmp(car_item_category($candidate), $category) === 0) {
     318                    $selected = $candidate;
     319                }
     320            }
     321        }
     322
     323        // Fallback: first item matching month (+ optional category)
     324        if (!$selected) {
    170325            foreach ($cancers as $item) {
    171                 if ((int)$item['month'] === (int)$month) { $selected = $item; break; }
     326                if ((int)($item['month'] ?? 0) !== (int)$month) continue;
     327                if ($category !== '' && strcasecmp(car_item_category($item), $category) !== 0) continue;
     328                $selected = $item;
     329                break;
    172330            }
    173331        }
     332
    174333        if (!$selected) {
    175             $selected = ['label' => 'Cancer Awareness', 'month' => $month, 'colors' => ['#999999']];
    176         }
    177     }
    178 
    179     $extra_class = sanitize_html_class((string)$atts['class']);
     334            $fallback_label = ($category !== '') ? ($category . ' Awareness') : 'Cancer Awareness';
     335            $selected = ['label' => $fallback_label, 'month' => $month, 'colors' => ['#999999']];
     336        }
     337    }
     338
    180339    $wrap_class = 'car-ribbon-wrap' . ($extra_class ? ' ' . $extra_class : '');
    181340
    182     $svg = car_render_ribbon_svg($selected['colors'], $size, $selected['label']);
     341    $svg = car_render_ribbon_svg((array)$selected['colors'], $size, (string)$selected['label']);
    183342
    184343    $html  = '<div class="' . esc_attr($wrap_class) . '" style="--car-size:' . esc_attr($size) . 'px;">';
     
    186345
    187346    if ($show_label) {
    188         $html .= '<div class="car-ribbon-label">' . esc_html($selected['label']) . '</div>';
     347        $html .= '<div class="car-ribbon-label">' . esc_html((string)$selected['label']) . '</div>';
    189348    }
    190349
  • cancer-awareness-ribbon-shortcode/trunk/readme.txt

    r3458719 r3458865  
    11=== Cancer Awareness Ribbon Shortcode ===
    22Contributors: freelancedirectza
    3 Tags: cancer, awareness, ribbon, shortcode, accessibility
     3Tags: cancer, awareness, ribbon, shortcode, accessibility, health, charity, medical, nonprofit
    44Requires at least: 5.8
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.2
    8 Version: 1.0.2
     7Stable tag: 1.4.0
     8Version: 1.4.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1111
    12 Display a beautiful, scalable cancer awareness ribbon that automatically changes color based on the current awareness month.
     12Display a beautiful, scalable awareness ribbon that automatically changes color based on the current awareness month (supports cancer, medical, social, and global awareness types).
    1313
    1414== Description ==
    1515
    16 **Cancer Awareness Ribbon Shortcode** is a lightweight WordPress plugin that adds a shortcode for displaying a professionally designed cancer awareness ribbon.
     16**Cancer Awareness Ribbon Shortcode** is a lightweight WordPress plugin that adds a shortcode for displaying a professionally designed awareness ribbon anywhere on your website.
     17
     18Live Demo:
     19https://www.parallelmedia.co.za/cancer-awareness-ribbon-demo/
     20
     21The ribbon automatically adapts to the current awareness month and supports a wide range of awareness types including Cancer, Medical, Social, and Global causes.
    1722
    1823The ribbon:
    1924- Automatically changes color based on the current awareness month
    2025- Supports single-color and multi-color (gradient) ribbons
    21 - Uses a clean SVG with no background
    22 - Works perfectly with Elementor, Gutenberg, headers, footers, and widgets
     26- Uses a clean, scalable SVG with no background
     27- Works seamlessly with Elementor, Gutenberg, headers, footers, and widgets
    2328- Scales crisply at any size
    24 - Does not rely on external assets or libraries
     29- Does not rely on external libraries or image files
     30- Includes accessibility-friendly ARIA labels
    2531
    2632This plugin is ideal for:
    2733- Awareness campaigns
    28 - Non-profits
     34- Non-profits and charities
    2935- Medical practices
    30 - Corporate social responsibility pages
    31 - Footer or site-wide awareness displays
     36- Schools and community organizations
     37- Corporate social responsibility initiatives
     38- Site-wide awareness displays
     39
     40Version 1.4.0 introduces:
     41- Category grouping (Cancer, Medical, Social, Global)
     42- Category filtering via shortcode
     43- List mode to display all awareness ribbons for a selected month
     44- Structured support for expanding awareness types
    3245
    3346== Features ==
    3447
    35 * Automatic ribbon color based on month
    36 * Multi-color gradient support for applicable cancers
     48* Automatic ribbon selection based on the current month
     49* Supports many awareness types (Cancer, Medical, Social, Global)
     50* Multi-color gradient support for applicable ribbons
    3751* Fully responsive SVG (no images required)
    3852* Elementor Shortcode widget compatible
    39 * Lightweight and fast
     53* Lightweight and fast (no external libraries)
    4054* Accessible SVG with ARIA labels
    41 * Customizable size, label, and type via shortcode attributes
     55* Customizable size, label, type, month, category filtering, and month listing via shortcode attributes
    4256
    4357== Usage ==
     
    4761[cancer_ribbon]
    4862
    49 ### Optional Shortcode Attributes
     63=== Optional Shortcode Attributes ===
    5064
    5165[cancer_ribbon size="64"]
     
    5468[cancer_ribbon month="10"]
    5569
     70New in 1.4.0:
     71
     72[cancer_ribbon category="Medical"]
     73[cancer_ribbon list="1" month="11" label="1"]
     74[cancer_ribbon list="1" month="10" category="Social" label="1"]
    5675
    5776**Available attributes:**
    5877
    5978* `size` – Size in pixels (default: 64)
    60 * `label` – Show cancer label text (1 or 0)
    61 * `type` – Force a specific cancer ribbon
     79* `label` – Show label text (1 or 0)
     80* `type` – Force a specific ribbon type key
    6281* `month` – Force a specific month (1–12)
    63 
    64 == Supported Awareness Colors ==
    65 
    66 The plugin includes accurate ribbon colors for major cancer awareness months, including:
     82* `category` – Filter by category: Cancer, Medical, Social, Global (optional)
     83* `list` – If set to 1/true, lists all ribbons for the selected month (optional, works great with `category`)
     84
     85== Supported Awareness Types ==
     86
     87The plugin includes ribbon colors for many cancer awareness months and additional awareness types.
     88
     89Examples include:
    6790
    6891- Breast Cancer (October) – Pink
     
    7497- Cervical Cancer (January) – Teal & White
    7598- Thyroid Cancer (September) – Purple, Teal & Pink
    76 - And many more
     99
     100Additional awareness ribbons added in later versions include (among others):
     101- HIV / AIDS Awareness
     102- Autism Awareness
     103- Mental Health Awareness
     104- Diabetes Awareness
     105- Heart Disease Awareness
     106- Domestic Violence Awareness
     107- Alzheimer’s Awareness
     108- Pride Awareness (multi-color)
     109- Anti-Bullying Awareness
     110- Organ Donation Awareness
     111- Veterans Awareness
     112- Child Protection Awareness
    77113
    78114== Installation ==
    79115
    801161. Upload the plugin folder to `/wp-content/plugins/`
    81 2. Activate **Cancer Awareness Ribbon** via the Plugins menu
     1172. Activate **Cancer Awareness Ribbon Shortcode** via the Plugins menu
    821183. Add `[cancer_ribbon]` anywhere on your site
    83119
     
    95131Yes. Use the `type` attribute in the shortcode.
    96132
     133= Can I filter by category? =
     134Yes. Use `category="Cancer"`, `category="Medical"`, `category="Social"`, or `category="Global"`.
     135
     136= Can I list all awareness ribbons for a selected month? =
     137Yes. Use `list="1"` and a month, for example: `[cancer_ribbon list="1" month="11" label="1"]`.
     138
    97139= Will this affect my site performance? =
    98140No. The plugin is extremely lightweight and outputs minimal markup.
     
    103145== Screenshots ==
    104146
    105 1. Cancer awareness ribbon displayed in a site footer
     1471. Awareness ribbon displayed in a site footer
    1061482. Breast cancer awareness ribbon (October)
    1071493. Multi-color gradient ribbon example
    1081504. Elementor Shortcode widget usage
     1515. Month listing view (list mode) showing multiple ribbons
    109152
    110153== Changelog ==
     154
     155= 1.4.0 =
     156* Added awareness categories: Cancer, Medical, Social, Global
     157* Added `category` shortcode attribute for filtering
     158* Added `list` shortcode attribute to display all ribbons for a selected month
     159* Added grouped output by category when using list mode
     160* Added categories to non-cancer awareness entries while keeping existing data structure intact
     161
     162= 1.3.0 =
     163* Added Pride awareness ribbon (multi-color gradient)
     164* Added Veterans awareness ribbon
     165* Added Child Protection awareness ribbon
     166* Added Anti-Bullying awareness ribbon
     167* Added Organ Donation awareness ribbon
     168
     169= 1.2.0 =
     170* Added Domestic Violence awareness ribbon
     171* Added Prostate Health awareness ribbon
     172* Added Ovarian Health awareness ribbon
     173* Added Lung Health awareness ribbon
     174* Added Alzheimer’s awareness ribbon
     175
     176= 1.1.0 =
     177* Added HIV / AIDS awareness ribbon
     178* Added Autism awareness ribbon
     179* Added Mental Health awareness ribbon
     180* Added Diabetes awareness ribbon
     181* Added Heart Disease awareness ribbon
     182
     183= 1.0.2 =
     184* Fixed stylesheet loading to use proper WordPress enqueue functions
     185* Updated contributor metadata for WordPress.org compliance
     186* Minor internal cleanup and review-related improvements
    111187
    112188= 1.0.1 =
     
    121197== Upgrade Notice ==
    122198
    123 = 1.0.1 =
    124 Improved SVG accuracy, styling reliability, and Elementor compatibility.
     199= 1.4.0 =
     200Adds category support, category filtering, and list mode to display all ribbons for a selected month.
    125201
    126202= 1.0.2 =
    127 * Fixed stylesheet loading to use proper WordPress enqueue functions
    128 * Updated contributor metadata for WordPress.org compliance
    129 * Minor internal cleanup and review-related improvements
     203Fixed stylesheet loading, updated contributor metadata, and minor internal cleanup.
    130204
    131205== License ==
Note: See TracChangeset for help on using the changeset viewer.