Changeset 3458865
- Timestamp:
- 02/11/2026 10:29:29 AM (7 weeks ago)
- Location:
- cancer-awareness-ribbon-shortcode/trunk
- Files:
-
- 2 edited
-
cancer-awareness-ribbon.php (modified) (7 diffs)
-
readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cancer-awareness-ribbon-shortcode/trunk/cancer-awareness-ribbon.php
r3458719 r3458865 1 1 <?php 2 2 3 /** 3 4 * Plugin Name: Cancer Awareness Ribbon Shortcode 4 5 * 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.26 * Version: 1.4.0 6 7 * Author: Parallel Media 7 8 * License: GPLv2 or later … … 18 19 plugins_url('assets/css/cancer-awareness-ribbon.css', __FILE__), 19 20 [], 20 '1. 0.2'21 '1.4.0' 21 22 ); 22 23 }, 20); 23 24 24 25 /** 25 * Cancer list: type => [label, month, colors[]] 26 * Cancer list: type => [label, month, colors[], optional category] 27 * Categories: Cancer, Medical, Social, Global 26 28 */ 27 29 function car_get_cancers(): array … … 59 61 'testicular_cancer' => ['label' => 'Testicular Cancer', 'month' => 4, 'colors' => ['#800080']], 60 62 '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'], 61 84 ]; 62 85 } … … 86 109 } 87 110 111 function 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 131 function 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 138 function 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 88 167 function car_render_ribbon_svg(array $colors, int $size, string $label): string 89 168 { … … 137 216 { 138 217 $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 144 225 ], $atts, 'cancer_ribbon'); 145 226 … … 158 239 } 159 240 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 160 296 $type = sanitize_key((string)$atts['type']); 161 297 $selected = null; 162 298 299 // Type override always wins 163 300 if ($type && isset($cancers[$type])) { 164 301 $selected = $cancers[$type]; 165 302 } 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 } 169 311 } 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) { 170 325 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; 172 330 } 173 331 } 332 174 333 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 180 339 $wrap_class = 'car-ribbon-wrap' . ($extra_class ? ' ' . $extra_class : ''); 181 340 182 $svg = car_render_ribbon_svg( $selected['colors'], $size,$selected['label']);341 $svg = car_render_ribbon_svg((array)$selected['colors'], $size, (string)$selected['label']); 183 342 184 343 $html = '<div class="' . esc_attr($wrap_class) . '" style="--car-size:' . esc_attr($size) . 'px;">'; … … 186 345 187 346 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>'; 189 348 } 190 349 -
cancer-awareness-ribbon-shortcode/trunk/readme.txt
r3458719 r3458865 1 1 === Cancer Awareness Ribbon Shortcode === 2 2 Contributors: freelancedirectza 3 Tags: cancer, awareness, ribbon, shortcode, accessibility 3 Tags: cancer, awareness, ribbon, shortcode, accessibility, health, charity, medical, nonprofit 4 4 Requires at least: 5.8 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1. 0.28 Version: 1. 0.27 Stable tag: 1.4.0 8 Version: 1.4.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Display a beautiful, scalable cancer awareness ribbon that automatically changes color based on the current awareness month.12 Display a beautiful, scalable awareness ribbon that automatically changes color based on the current awareness month (supports cancer, medical, social, and global awareness types). 13 13 14 14 == Description == 15 15 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 18 Live Demo: 19 https://www.parallelmedia.co.za/cancer-awareness-ribbon-demo/ 20 21 The ribbon automatically adapts to the current awareness month and supports a wide range of awareness types including Cancer, Medical, Social, and Global causes. 17 22 18 23 The ribbon: 19 24 - Automatically changes color based on the current awareness month 20 25 - Supports single-color and multi-color (gradient) ribbons 21 - Uses a clean SVG with no background22 - Works perfectly with Elementor, Gutenberg, headers, footers, and widgets26 - Uses a clean, scalable SVG with no background 27 - Works seamlessly with Elementor, Gutenberg, headers, footers, and widgets 23 28 - 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 25 31 26 32 This plugin is ideal for: 27 33 - Awareness campaigns 28 - Non-profits 34 - Non-profits and charities 29 35 - 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 40 Version 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 32 45 33 46 == Features == 34 47 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 37 51 * Fully responsive SVG (no images required) 38 52 * Elementor Shortcode widget compatible 39 * Lightweight and fast 53 * Lightweight and fast (no external libraries) 40 54 * Accessible SVG with ARIA labels 41 * Customizable size, label, and typevia shortcode attributes55 * Customizable size, label, type, month, category filtering, and month listing via shortcode attributes 42 56 43 57 == Usage == … … 47 61 [cancer_ribbon] 48 62 49 ### Optional Shortcode Attributes 63 === Optional Shortcode Attributes === 50 64 51 65 [cancer_ribbon size="64"] … … 54 68 [cancer_ribbon month="10"] 55 69 70 New 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"] 56 75 57 76 **Available attributes:** 58 77 59 78 * `size` – Size in pixels (default: 64) 60 * `label` – Show cancerlabel text (1 or 0)61 * `type` – Force a specific cancer ribbon79 * `label` – Show label text (1 or 0) 80 * `type` – Force a specific ribbon type key 62 81 * `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 87 The plugin includes ribbon colors for many cancer awareness months and additional awareness types. 88 89 Examples include: 67 90 68 91 - Breast Cancer (October) – Pink … … 74 97 - Cervical Cancer (January) – Teal & White 75 98 - Thyroid Cancer (September) – Purple, Teal & Pink 76 - And many more 99 100 Additional 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 77 113 78 114 == Installation == 79 115 80 116 1. Upload the plugin folder to `/wp-content/plugins/` 81 2. Activate **Cancer Awareness Ribbon ** via the Plugins menu117 2. Activate **Cancer Awareness Ribbon Shortcode** via the Plugins menu 82 118 3. Add `[cancer_ribbon]` anywhere on your site 83 119 … … 95 131 Yes. Use the `type` attribute in the shortcode. 96 132 133 = Can I filter by category? = 134 Yes. Use `category="Cancer"`, `category="Medical"`, `category="Social"`, or `category="Global"`. 135 136 = Can I list all awareness ribbons for a selected month? = 137 Yes. Use `list="1"` and a month, for example: `[cancer_ribbon list="1" month="11" label="1"]`. 138 97 139 = Will this affect my site performance? = 98 140 No. The plugin is extremely lightweight and outputs minimal markup. … … 103 145 == Screenshots == 104 146 105 1. Cancer awareness ribbon displayed in a site footer147 1. Awareness ribbon displayed in a site footer 106 148 2. Breast cancer awareness ribbon (October) 107 149 3. Multi-color gradient ribbon example 108 150 4. Elementor Shortcode widget usage 151 5. Month listing view (list mode) showing multiple ribbons 109 152 110 153 == 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 111 187 112 188 = 1.0.1 = … … 121 197 == Upgrade Notice == 122 198 123 = 1. 0.1=124 Improved SVG accuracy, styling reliability, and Elementor compatibility.199 = 1.4.0 = 200 Adds category support, category filtering, and list mode to display all ribbons for a selected month. 125 201 126 202 = 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 203 Fixed stylesheet loading, updated contributor metadata, and minor internal cleanup. 130 204 131 205 == License ==
Note: See TracChangeset
for help on using the changeset viewer.