Changeset 3413649
- Timestamp:
- 12/07/2025 05:56:39 PM (7 days ago)
- Location:
- lightweight-accordion
- Files:
-
- 30 added
- 9 edited
-
tags/1.5.20 (added)
-
tags/1.5.20/block.json (added)
-
tags/1.5.20/build (added)
-
tags/1.5.20/build/index.asset.php (added)
-
tags/1.5.20/build/index.js (added)
-
tags/1.5.20/css (added)
-
tags/1.5.20/css/editor-styles.css (added)
-
tags/1.5.20/css/lightweight-accordion.css (added)
-
tags/1.5.20/css/min (added)
-
tags/1.5.20/css/min/editor-styles.min.css (added)
-
tags/1.5.20/css/min/lightweight-accordion.min.css (added)
-
tags/1.5.20/index.php (added)
-
tags/1.5.20/lightweight-accordion.php (added)
-
tags/1.5.20/readme.txt (added)
-
tags/1.5.20/wpml-config.xml (added)
-
tags/1.6.0 (added)
-
tags/1.6.0/block.json (added)
-
tags/1.6.0/build (added)
-
tags/1.6.0/build/index.asset.php (added)
-
tags/1.6.0/build/index.js (added)
-
tags/1.6.0/css (added)
-
tags/1.6.0/css/editor-styles.css (added)
-
tags/1.6.0/css/lightweight-accordion.css (added)
-
tags/1.6.0/css/min (added)
-
tags/1.6.0/css/min/editor-styles.min.css (added)
-
tags/1.6.0/css/min/lightweight-accordion.min.css (added)
-
tags/1.6.0/index.php (added)
-
tags/1.6.0/lightweight-accordion.php (added)
-
tags/1.6.0/readme.txt (added)
-
tags/1.6.0/wpml-config.xml (added)
-
trunk/block.json (modified) (1 diff)
-
trunk/build/index.asset.php (modified) (1 diff)
-
trunk/build/index.js (modified) (1 diff)
-
trunk/css/editor-styles.css (modified) (2 diffs)
-
trunk/css/lightweight-accordion.css (modified) (1 diff)
-
trunk/css/min/editor-styles.min.css (modified) (1 diff)
-
trunk/css/min/lightweight-accordion.min.css (modified) (1 diff)
-
trunk/lightweight-accordion.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lightweight-accordion/trunk/block.json
r3056966 r3413649 11 11 "style": "file:./css/min/lightweight-accordion.min.css" 12 12 } 13 -
lightweight-accordion/trunk/build/index.asset.php
r3056945 r3413649 1 <?php return array('dependencies' => array('react ', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n'), 'version' => '7fc8717a6775aa1efa08');1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => '437c1cc681508d588916'); -
lightweight-accordion/trunk/build/index.js
r3056945 r3413649 1 (()=>{"use strict";const e=window. React,t=window.wp.i18n,l=window.wp.blocks,o=window.wp.blockEditor,a=window.wp.components;(0,l.registerBlockType)("lightweight-accordion/lightweight-accordion",{title:(0,t.__)("Lightweight Accordion"),category:"widgets",icon:"editor-ul",keywords:[(0,t.__)("accordion"),(0,t.__)("list"),(0,t.__)("collapse"),(0,t.__)("collapsable")],supports:{anchor:!0},attributes:{content:{type:"array",source:"children"},anchor:{type:"string",default:null},title:{type:"string",default:null},title_tag:{type:"string",default:"span"},title_text_color:{type:"string",default:""},title_background_color:{type:"string",default:""},accordion_open:{type:"boolean",default:!1},bordered:{type:"boolean",default:!1},schema:{type:"string",default:!1}},example:{attributes:{title:(0,t.__)("Accordion Title"),bordered:!0}},edit:function({attributes:l,setAttributes:n,className:r}){const{title:c,title_tag:i,title_text_color:d,title_background_color:s,accordion_open:u,bordered:_,schema:g}=l;return(0,e.createElement)("div",{className:"lightweight-accordion "+(_?"bordered":""),id:l.anchor},(0,e.createElement)("summary",{className:`lightweight-accordion-title ${r}`,style:{color:d,background:s}},(0,e.createElement)(o.RichText,{tagName:i,value:c,onChange:e=>n({title:e}),placeholder:(0,t.__)("Accordion title..."),allowedFormats:["core/bold","core/italic"]})),(0,e.createElement)("div",{className:`lightweight-accordion-body ${r}`,style:{borderColor:s}},(0,e.createElement)(o.InnerBlocks,null)),(0,e.createElement)(o.InspectorControls,null,(0,e.createElement)(a.PanelBody,null,(0,e.createElement)(a.ToggleControl,{label:(0,t.__)("Open by default?"),checked:u,onChange:e=>n({accordion_open:e})}),(0,e.createElement)(a.ToggleControl,{label:(0,t.__)("Border?"),checked:_,onChange:e=>n({bordered:e})}),(0,e.createElement)(a.SelectControl,{label:(0,t.__)("HTML tag for accordion title"),value:i,onChange:e=>n({title_tag:e}),options:[{value:"span",label:"span"},{value:"div",label:"div"},{value:"p",label:"p"},{value:"h1",label:"H1"},{value:"h2",label:"H2"},{value:"h3",label:"H3"},{value:"h4",label:"H4"}]}),(0,e.createElement)(a.SelectControl,{label:(0,t.__)("Schema Markup?"),value:g,onChange:e=>n({schema:e}),options:[{value:!1,label:"None"},{value:"faq",label:"FAQ"}]})),(0,e.createElement)(o.PanelColorSettings,{title:(0,t.__)("Color Settings"),colorSettings:[{value:d||void 0,onChange:e=>n({title_text_color:e}),label:(0,t.__)("Title Text Color")},{value:s||void 0,onChange:e=>n({title_background_color:e}),label:(0,t.__)("Title Background Color")}]})))},save:function({attributes:t}){return(0,e.createElement)(o.InnerBlocks.Content,null)}})})();1 (()=>{"use strict";const e=window.wp.i18n,o=window.wp.blocks,t=window.wp.blockEditor,l=window.wp.components,r=window.wp.data,n=window.ReactJSXRuntime;(0,o.registerBlockType)("lightweight-accordion/accordion-group",{title:(0,e.__)("Accordion Group"),category:"widgets",icon:"list-view",description:(0,e.__)("Group multiple accordions together so only one can be open at a time."),supports:{anchor:!0,html:!1,inserter:!1},attributes:{groupName:{type:"string",default:""}},providesContext:{"lightweight-accordion/groupName":"groupName"},edit:function({attributes:c,setAttributes:i,clientId:a}){const{groupName:s}=c,{insertBlock:d}=(0,r.useDispatch)("core/block-editor"),{innerBlockCount:g}=(0,r.useSelect)(e=>({innerBlockCount:e("core/block-editor").getBlockCount(a)}),[a]),u=(0,t.useBlockProps)({className:"lightweight-accordion-group"}),h=(0,t.useInnerBlocksProps)({},{allowedBlocks:["lightweight-accordion/lightweight-accordion"],renderAppender:!1});return(0,n.jsxs)("div",{...u,children:[(0,n.jsx)(t.BlockControls,{children:(0,n.jsx)(l.ToolbarGroup,{children:(0,n.jsx)(l.ToolbarButton,{onClick:()=>{const e=(0,o.createBlock)("lightweight-accordion/lightweight-accordion",{});d(e,g,a)},children:(0,e.__)("Add Item")})})}),(0,n.jsx)(t.InspectorControls,{children:(0,n.jsx)(l.PanelBody,{title:(0,e.__)("Group Settings"),children:(0,n.jsx)(l.TextControl,{label:(0,e.__)("Group Name"),value:s,onChange:e=>i({groupName:e}),help:(0,e.__)("All accordions in this group will auto-close when another opens. To disable auto-closing, remove the group name.")})})}),(0,n.jsx)("div",{...h})]})},save:function(){return(0,n.jsx)(t.InnerBlocks.Content,{})}}),(0,o.registerBlockType)("lightweight-accordion/lightweight-accordion",{title:(0,e.__)("Lightweight Accordion"),category:"widgets",icon:"editor-ul",keywords:[(0,e.__)("accordion"),(0,e.__)("list"),(0,e.__)("collapse"),(0,e.__)("collapsable"),(0,e.__)("faq"),(0,e.__)("toggle")],supports:{anchor:!0},attributes:{content:{type:"array",source:"children"},anchor:{type:"string",default:null},title:{type:"string",default:null},title_tag:{type:"string",default:"span"},title_text_color:{type:"string",default:""},title_background_color:{type:"string",default:""},accordion_open:{type:"boolean",default:!1},bordered:{type:"boolean",default:!1},schema:{type:"string",default:""},group:{type:"string",default:""}},usesContext:["lightweight-accordion/groupName"],example:{attributes:{title:(0,e.__)("Accordion Title"),bordered:!0}},edit:function({attributes:c,setAttributes:i,className:a,context:s,clientId:d}){const{title:g,title_tag:u,title_text_color:h,title_background_color:p,accordion_open:_,bordered:b,schema:w,group:k}=c,x=!!s["lightweight-accordion/groupName"],{replaceBlocks:m,insertBlock:v}=(0,r.useDispatch)("core/block-editor"),{parentBlock:B,blockIndex:C,currentBlock:j}=(0,r.useSelect)(e=>{const{getBlock:o,getBlockRootClientId:t,getBlockIndex:l}=e("core/block-editor"),r=t(d);return{parentBlock:r?o(r):null,blockIndex:l(d),currentBlock:o(d)}},[d]),y="lightweight-accordion/accordion-group"===B?.name,f=(0,t.useBlockProps)({className:"lightweight-accordion "+(b?"bordered":""),id:c.anchor||void 0});return(0,n.jsxs)("div",{...f,children:[(0,n.jsx)(t.BlockControls,{children:(0,n.jsx)(l.ToolbarGroup,{children:(0,n.jsx)(l.ToolbarButton,{onClick:()=>{const e=(0,o.createBlock)("lightweight-accordion/lightweight-accordion",{});if(y&&B)v(e,C+1,B.clientId);else{const t=(0,o.createBlock)("lightweight-accordion/accordion-group",{groupName:"accordion-group-"+Math.random().toString(36).substring(2,11)},[(0,o.createBlock)("lightweight-accordion/lightweight-accordion",{...j.attributes},j.innerBlocks),e]);m(d,t)}},children:(0,e.__)("Add Item")})})}),(0,n.jsx)("summary",{className:`lightweight-accordion-title ${a||""}`,style:{color:h||void 0,background:p||void 0},children:(0,n.jsx)(t.RichText,{tagName:u,value:g,onChange:e=>i({title:e}),placeholder:(0,e.__)("Accordion title..."),allowedFormats:["core/bold","core/italic"]})}),(0,n.jsx)("div",{className:`lightweight-accordion-body ${a||""}`,style:{borderColor:p||void 0},children:(0,n.jsx)(t.InnerBlocks,{})}),(0,n.jsxs)(t.InspectorControls,{children:[(0,n.jsxs)(l.PanelBody,{children:[(0,n.jsx)(l.ToggleControl,{label:(0,e.__)("Open by default?"),checked:_,onChange:e=>i({accordion_open:e})}),(0,n.jsx)(l.ToggleControl,{label:(0,e.__)("Border?"),checked:b,onChange:e=>i({bordered:e})}),(0,n.jsx)(l.SelectControl,{label:(0,e.__)("HTML tag for accordion title"),value:u,onChange:e=>i({title_tag:e}),options:[{value:"span",label:"span"},{value:"div",label:"div"},{value:"p",label:"p"},{value:"h1",label:"H1"},{value:"h2",label:"H2"},{value:"h3",label:"H3"},{value:"h4",label:"H4"},{value:"h5",label:"H5"},{value:"h6",label:"H6"}]}),(0,n.jsx)(l.SelectControl,{label:(0,e.__)("Schema Markup?"),value:w,onChange:e=>i({schema:e}),options:[{value:"",label:"None"},{value:"faq",label:"FAQ"}]}),!x&&(0,n.jsx)(l.TextControl,{label:(0,e.__)("Accordion Group"),value:k,onChange:e=>i({group:e}),help:(0,e.__)('Accordions with the same group name will auto-close when another opens. Or use the "Add Item" button to create grouped accordions.')}),x&&(0,n.jsx)("p",{className:"components-base-control__help",children:(0,e.__)("This accordion is part of a group. Only one accordion in the group can be open at a time.")})]}),(0,n.jsx)(t.PanelColorSettings,{title:(0,e.__)("Color Settings"),colorSettings:[{value:h||void 0,onChange:e=>i({title_text_color:e}),label:(0,e.__)("Title Text Color")},{value:p||void 0,onChange:e=>i({title_background_color:e}),label:(0,e.__)("Title Background Color")}]})]})]})},save:function(){return(0,n.jsx)(t.InnerBlocks.Content,{})}})})(); -
lightweight-accordion/trunk/css/editor-styles.css
r3056945 r3413649 1 .wp-admin .lightweight-accordion .lightweight-accordion-body {2 padding: 0;3 }4 1 .wp-admin .lightweight-accordion .lightweight-accordion-title { 5 2 display: block; … … 23 20 display: block; 24 21 } 22 23 /* Accordion Group Block Styles */ 24 .wp-admin .lightweight-accordion-group { 25 border-left: 3px solid #007cba; 26 padding-left: 12px; 27 } -
lightweight-accordion/trunk/css/lightweight-accordion.css
r3056945 r3413649 18 18 animation: lwopen .5s ease-in-out; 19 19 } 20 .lightweight-accordion .lightweight-accordion-title p, .lightweight-accordion .lightweight-accordion-title span, .lightweight-accordion .lightweight-accordion-title h1, .lightweight-accordion .lightweight-accordion-title h2, .lightweight-accordion .lightweight-accordion-title h3 {20 .lightweight-accordion .lightweight-accordion-title p, .lightweight-accordion .lightweight-accordion-title span, .lightweight-accordion .lightweight-accordion-title h1, .lightweight-accordion .lightweight-accordion-title h2, .lightweight-accordion .lightweight-accordion-title h3, .lightweight-accordion .lightweight-accordion-title h4, .lightweight-accordion .lightweight-accordion-title h5, .lightweight-accordion .lightweight-accordion-title h6 { 21 21 display: inline; 22 22 font-size: 18px; -
lightweight-accordion/trunk/css/min/editor-styles.min.css
r3056945 r3413649 1 .wp-admin .lightweight-accordion .lightweight-accordion- body{padding:0}.wp-admin .lightweight-accordion .lightweight-accordion-title{display:block;background:#f1f2f6;padding:10px 12px 10px 18px;margin-bottom:0}.wp-admin .lightweight-accordion .lightweight-accordion-title:before{content:"\25BC ";margin-right:.4em}.wp-admin .lightweight-accordion .lightweight-accordion-body{padding:10px;border:2px dashed #f1f2f6;border-top:0}.wp-admin .lightweight-accordion.bordered .lightweight-accordion-body{border-style:solid}.block-editor-block-list__block.is-selected:not(.has-child-selected)>.lightweight-accordion .block-editor-default-block-appender{display:block}1 .wp-admin .lightweight-accordion .lightweight-accordion-title{display:block;background:#f1f2f6;padding:10px 12px 10px 18px;margin-bottom:0}.wp-admin .lightweight-accordion .lightweight-accordion-title:before{content:"\25BC ";margin-right:.4em}.wp-admin .lightweight-accordion .lightweight-accordion-body{padding:10px;border:2px dashed #f1f2f6;border-top:0}.wp-admin .lightweight-accordion.bordered .lightweight-accordion-body{border-style:solid}.block-editor-block-list__block.is-selected:not(.has-child-selected)>.lightweight-accordion .block-editor-default-block-appender{display:block}.wp-admin .lightweight-accordion-group{border-left:3px solid #007cba;padding-left:12px} -
lightweight-accordion/trunk/css/min/lightweight-accordion.min.css
r3056945 r3413649 1 .lightweight-accordion{margin-bottom:.4em}.lightweight-accordion .lightweight-accordion-title{display:list-item;background:#f1f2f6;padding:10px 12px 10px 18px;cursor:pointer}.lightweight-accordion .lightweight-accordion-body{padding:10px}.lightweight-accordion.bordered .lightweight-accordion-body{border:2px solid #f1f2f6;border-top:0}.lightweight-accordion details[open] summary~*{animation:lwopen .5s ease-in-out}.lightweight-accordion .lightweight-accordion-title h1,.lightweight-accordion .lightweight-accordion-title h2,.lightweight-accordion .lightweight-accordion-title h3,.lightweight-accordion .lightweight-accordion-title p,.lightweight-accordion .lightweight-accordion-title span{display:inline;font-size:18px;font-family:inherit;font-weight:400}@keyframes lwopen{0%{opacity:0}100%{opacity:1}}1 .lightweight-accordion{margin-bottom:.4em}.lightweight-accordion .lightweight-accordion-title{display:list-item;background:#f1f2f6;padding:10px 12px 10px 18px;cursor:pointer}.lightweight-accordion .lightweight-accordion-body{padding:10px}.lightweight-accordion.bordered .lightweight-accordion-body{border:2px solid #f1f2f6;border-top:0}.lightweight-accordion details[open] summary~*{animation:lwopen .5s ease-in-out}.lightweight-accordion .lightweight-accordion-title h1,.lightweight-accordion .lightweight-accordion-title h2,.lightweight-accordion .lightweight-accordion-title h3,.lightweight-accordion .lightweight-accordion-title h4,.lightweight-accordion .lightweight-accordion-title h5,.lightweight-accordion .lightweight-accordion-title h6,.lightweight-accordion .lightweight-accordion-title p,.lightweight-accordion .lightweight-accordion-title span{display:inline;font-size:18px;font-family:inherit;font-weight:400}@keyframes lwopen{0%{opacity:0}100%{opacity:1}} -
lightweight-accordion/trunk/lightweight-accordion.php
r3166105 r3413649 2 2 /** 3 3 * Plugin Name: Lightweight Accordion 4 * Plugin URI: https://smartwp.co /lightweight-accordion4 * Plugin URI: https://smartwp.com/lightweight-accordion 5 5 * Description: Extremely simple accordion for adding collapse elements to pages without affecting page load time. Works for Classic Editor via shortcode and Gutenberg via Block. 6 * Version: 1. 5.206 * Version: 1.6.0 7 7 * Text Domain: lightweight-accordion 8 8 * Author: Andy Feliciotti … … 14 14 } 15 15 16 define( 'LIGHTWEIGHT_ACCORDION_VERSION', '1. 5.20' );17 define( 'LIGHTWEIGHT_ACCORDION_CSS_VERSION', '1. 3.3' );16 define( 'LIGHTWEIGHT_ACCORDION_VERSION', '1.6.0' ); 17 define( 'LIGHTWEIGHT_ACCORDION_CSS_VERSION', '1.6.0' ); 18 18 19 19 // Enqueue CSS when in use … … 28 28 $plugin_url = plugin_dir_url( __FILE__ ); 29 29 30 if( $include_frontend_stylesheet && ( $always_include_frontend_stylesheet || ( isset($post->post_content) && has_shortcode( $post->post_content, 'lightweight-accordion') || has_block('lightweight-accordion/lightweight-accordion') ) ) ){30 if( $include_frontend_stylesheet && ( $always_include_frontend_stylesheet || ( isset($post->post_content) && has_shortcode( $post->post_content, 'lightweight-accordion') || has_block('lightweight-accordion/lightweight-accordion') || has_block('lightweight-accordion/accordion-group') ) ) ){ 31 31 wp_enqueue_style('lightweight-accordion', $plugin_url . 'css/min/lightweight-accordion.min.css', array(), LIGHTWEIGHT_ACCORDION_CSS_VERSION); 32 32 } … … 51 51 'schema' => false, 52 52 'class' => false, 53 'autop' => true 53 'autop' => true, 54 'group' => false 54 55 ), $atts, 'lightweight-accordion' ); 55 56 … … 60 61 61 62 // Block handler for Gutenberg 62 function lightweight_accordion_block_handler( $atts, $content ) { 63 function lightweight_accordion_block_handler( $atts, $content, $block = null ) { 64 // Check if we're inside an accordion group and get the group name from context 65 if ( $block && isset( $block->context['lightweight-accordion/groupName'] ) ) { 66 $atts['group'] = $block->context['lightweight-accordion/groupName']; 67 } 63 68 return render_lightweight_accordion( $atts, $content, true ); 69 } 70 71 // Accordion Group block handler - just renders inner content 72 function lightweight_accordion_group_block_handler( $atts, $content ) { 73 return $content; 64 74 } 65 75 … … 68 78 $output = ''; 69 79 70 $process_shortcodes = apply_filters( 'lightweight_accordion_process_shortcodes', true); 71 72 if($process_shortcodes){ 73 $content = do_shortcode($content); 74 } 75 76 if(!$isBlock && filter_var($options['autop'], FILTER_VALIDATE_BOOLEAN)){ 77 $content = wpautop(preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', force_balance_tags($content))); 80 // Merge with defaults to prevent undefined key warnings 81 $defaults = array( 82 'anchor' => null, 83 'title' => null, 84 'title_tag' => 'span', 85 'accordion_open' => false, 86 'bordered' => false, 87 'title_background_color' => false, 88 'title_text_color' => false, 89 'schema' => false, 90 'class' => false, 91 'className' => false, 92 'autop' => true, 93 'group' => false, 94 ); 95 $options = wp_parse_args( $options, $defaults ); 96 97 $process_shortcodes = apply_filters( 'lightweight_accordion_process_shortcodes', true ); 98 99 if ( $process_shortcodes ) { 100 $content = do_shortcode( $content ); 101 } 102 103 if ( ! $isBlock && filter_var( $options['autop'], FILTER_VALIDATE_BOOLEAN ) ) { 104 $content = wpautop( preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', force_balance_tags( $content ) ) ); 78 105 } 79 106 80 107 $anchor = ''; 81 if (isset($options['anchor']) && $options['anchor']){82 $anchor = ' id="' .esc_attr( $options['anchor'] ).'"';108 if ( $options['anchor'] ) { 109 $anchor = ' id="' . esc_attr( $options['anchor'] ) . '"'; 83 110 } 84 111 85 112 $open = ''; 86 if ($options['accordion_open']){113 if ( $options['accordion_open'] ) { 87 114 $open = ' open'; 88 115 } 89 116 90 $classes = array('lightweight-accordion'); 91 if($options['bordered']){ 117 $group = ''; 118 if ( $options['group'] ) { 119 $group = ' name="' . esc_attr( $options['group'] ) . '"'; 120 } 121 122 $classes = array( 'lightweight-accordion' ); 123 if ( $options['bordered'] ) { 92 124 $classes[] = 'bordered'; 93 125 } 94 if(isset($options['class']) && $options['class']){ 95 $classes[] = $options['class']; 96 } 97 if(isset($options['className']) && $options['className']){ 98 $classes[] = $options['className']; 99 } 100 101 $bodyClasses = array('lightweight-accordion-body'); 126 if ( $options['class'] ) { 127 // Sanitize each custom class name 128 $custom_classes = array_map( 'sanitize_html_class', explode( ' ', $options['class'] ) ); 129 $classes = array_merge( $classes, array_filter( $custom_classes ) ); 130 } 131 if ( $options['className'] ) { 132 // Sanitize each custom class name (Gutenberg className) 133 $custom_classes = array_map( 'sanitize_html_class', explode( ' ', $options['className'] ) ); 134 $classes = array_merge( $classes, array_filter( $custom_classes ) ); 135 } 136 137 $bodyClasses = array( 'lightweight-accordion-body' ); 102 138 103 139 $titleStyles = $bodyStyles = array(); 104 if ($options['title_text_color']){105 $titleStyles[] = 'color:' .esc_attr( $options['title_text_color'] );106 $classes[] = 'has-text-color';107 } 108 if ($options['title_background_color']){109 $titleStyles[] = 'background:' .esc_attr( $options['title_background_color'] );110 $bodyStyles[] = 'border-color:'.esc_attr( $options['title_background_color'] );111 $classes[] = 'has-background';140 if ( $options['title_text_color'] ) { 141 $titleStyles[] = 'color:' . esc_attr( $options['title_text_color'] ); 142 $classes[] = 'has-text-color'; 143 } 144 if ( $options['title_background_color'] ) { 145 $titleStyles[] = 'background:' . esc_attr( $options['title_background_color'] ); 146 $bodyStyles[] = 'border-color:' . esc_attr( $options['title_background_color'] ); 147 $classes[] = 'has-background'; 112 148 } 113 149 if(!empty($titleStyles)){ … … 132 168 ); 133 169 } 170 // Strip HTML for JSON-LD schema (should be plain text) 171 $schema_title = wp_strip_all_tags( $options['title'] ); 172 $schema_content = wp_strip_all_tags( $content ); 173 134 174 $lightweight_accordion_schema['mainEntity'][] = array( 135 175 '@type' => 'Question', 136 'name' => $ options['title'],176 'name' => $schema_title, 137 177 'acceptedAnswer' => array( 138 178 '@type' => 'Answer', 139 'text' => $ content179 'text' => $schema_content 140 180 ) 141 181 ); … … 152 192 153 193 $title = isset( $options['title'] ) ? wp_kses_post( $options['title'] ) : ''; 154 $title_tag = isset( $options['title_tag'] ) ? sanitize_html_class( $options['title_tag'] ) : 'h3'; 194 195 // Whitelist allowed title tags for security 196 $allowed_title_tags = array( 'span', 'div', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ); 197 $title_tag = isset( $options['title_tag'] ) && in_array( $options['title_tag'], $allowed_title_tags, true ) 198 ? $options['title_tag'] 199 : 'span'; 155 200 156 201 if( $title && isset($content) ){ 157 $output .= '<div class="' . esc_attr( implode(' ', $classes) ) . '"' . $anchor . '><details' . $propBox . ''. $open . '><summary class="lightweight-accordion-title"' . $titleStyles . '><' . esc_attr( $title_tag ) . '' . $propTitle . '>' . $title . '</' . esc_attr( $title_tag ) . '></summary><div class="' . esc_attr( implode(' ', $bodyClasses) ) . '"' . $bodyStyles . '>';202 $output .= '<div class="' . esc_attr( implode(' ', $classes) ) . '"' . $anchor . '><details' . $propBox . $group . $open . '><summary class="lightweight-accordion-title"' . $titleStyles . '><' . esc_attr( $title_tag ) . '' . $propTitle . '>' . $title . '</' . esc_attr( $title_tag ) . '></summary><div class="' . esc_attr( implode(' ', $bodyClasses) ) . '"' . $bodyStyles . '>'; 158 203 $output .= $content; 159 204 $output .= '</div></details></div>'; … … 177 222 178 223 // Register Gutenberg block 179 add_action('init', function () { 224 add_action( 'init', 'lightweight_accordion_register_block' ); 225 function lightweight_accordion_register_block() { 180 226 // Skip block registration if Gutenberg is not enabled. 181 if ( !function_exists('register_block_type')) {227 if ( ! function_exists( 'register_block_type' ) ) { 182 228 return; 183 229 } 184 $dir = dirname( __FILE__);230 $dir = dirname( __FILE__ ); 185 231 186 232 $index_js = 'build/index.js'; 187 233 wp_register_script( 188 234 'lightweight-accordion', 189 plugins_url( $index_js, __FILE__),235 plugins_url( $index_js, __FILE__ ), 190 236 array( 191 'wp- editor',237 'wp-block-editor', 192 238 'wp-blocks', 193 239 'wp-i18n', 194 240 'wp-element', 195 'wp-components' 241 'wp-components', 242 'wp-data' 196 243 ), 197 filemtime( "$dir/$index_js")244 filemtime( "$dir/$index_js" ) 198 245 ); 199 246 200 register_block_type('lightweight-accordion/lightweight-accordion', array( 201 'editor_script' => 'lightweight-accordion', 247 // Register the accordion group block 248 register_block_type( 'lightweight-accordion/accordion-group', array( 249 'editor_script' => 'lightweight-accordion', 250 'render_callback' => 'lightweight_accordion_group_block_handler', 251 'provides_context' => array( 252 'lightweight-accordion/groupName' => 'groupName', 253 ), 254 'attributes' => array( 255 'groupName' => array( 256 'type' => 'string', 257 'default' => '', 258 ), 259 ), 260 ) ); 261 262 // Register the accordion block (works standalone or inside groups) 263 register_block_type( 'lightweight-accordion/lightweight-accordion', array( 264 'editor_script' => 'lightweight-accordion', 202 265 'render_callback' => 'lightweight_accordion_block_handler', 203 'attributes' => [ 204 'content' => [ 205 'type' => 'array', 206 'default' => 'Content' 207 ], 208 'title' => [ 209 'type' => 'string', 210 'default' => 'Accordion Title' 211 ], 212 'accordion_open' => [ 213 'type' => 'boolean', 214 'default' => false 215 ], 216 'bordered' => [ 217 'type' => 'boolean', 218 'default' => false 219 ], 220 'title_tag' => [ 221 'type' => 'string', 222 'default' => 'span' 223 ], 224 'title_text_color' => [ 225 'type' => 'string', 226 'default' => false 227 ], 228 'title_background_color' => [ 229 'type' => 'string', 230 'default' => false 231 ], 232 'schema' => [ 233 'type' => 'string', 234 'default' => false 235 ] 236 ] 237 )); 238 }); 266 'uses_context' => array( 'lightweight-accordion/groupName' ), 267 ) ); 268 } -
lightweight-accordion/trunk/readme.txt
r3166105 r3413649 4 4 Tags: accordion, collapsible, performance, block, blocks 5 5 Requires at least: 5.0 6 Tested up to: 6. 76 Tested up to: 6.9 7 7 Requires PHP: 7.0 8 Stable tag: 1. 5.208 Stable tag: 1.6.0 9 9 License: GPLv3 10 10 License URI: http://www.gnu.org/licenses/gpl.html … … 20 20 **Extremely Lightweight (<1kb):** Without using Javascript the plugin uses the native details HTML tag and a few lines of code for almost no impact on front-end. 21 21 22 **Customizable:** Options include customizing the HTML tag used for the accordion title, open by default, orders, and colors.22 **Customizable:** Options include customizing the HTML tag used for the accordion title, open by default, borders, colors, and accordion grouping (auto-close others when one opens). 23 23 24 24 = Shortcode Usage examples = … … 43 43 44 44 `[lightweight-accordion title="Bordered Content" bordered=true]My Content[/lightweight-accordion]` 45 46 If you want accordions to auto-close when another opens (exclusive accordion), use the "group" attribute with the same value on each accordion. 47 48 `[lightweight-accordion title="Question 1" group="faq"]Answer 1[/lightweight-accordion]` 49 `[lightweight-accordion title="Question 2" group="faq"]Answer 2[/lightweight-accordion]` 50 `[lightweight-accordion title="Question 3" group="faq"]Answer 3[/lightweight-accordion]` 45 51 46 52 = Shortcode Options = … … 59 65 * **anchor** (Default: null) Adds the value as an ID to the accordion div as an anchor. 60 66 * **autop** (Default: true) By default the shortcode will wrap text in a 'p' tag. Set this to false if you'd like this disabled for the specific accordion. 67 * **group** (Default: false) Set this to a group name to make accordions with the same group auto-close when another opens. Uses the native HTML details name attribute for zero JavaScript overhead. 61 68 62 69 = Additional Details = … … 99 106 100 107 == Changelog == 108 109 = 1.6.0 = 110 * New feature: Accordion grouping - only one accordion can be open at a time within a group. 111 * Added "Add Item" button in block toolbar to easily create grouped accordions. 112 * Added `group` attribute for shortcodes to enable exclusive accordion behavior. 113 * Added H5 and H6 title tag options. 114 * Fixed deprecated `wp-editor` script dependency. 115 * Security improvements for class and title tag sanitization. 116 * Code improvements and bug fixes. 101 117 102 118 = 1.5.20 =
Note: See TracChangeset
for help on using the changeset viewer.