Changeset 3831810
- Timestamp:
- 11/28/2026 04:29:40 PM (15 hours ago)
- Location:
- contributor-photo-gallery
- Files:
-
- 16 edited
- 1 copied
-
tags/3.2.0 (copied) (copied from contributor-photo-gallery/trunk )
-
tags/3.2.0/blocks/gallery/block.json (modified) (2 diffs)
-
tags/3.2.0/blocks/gallery/index.js (modified) (13 diffs)
-
tags/3.2.0/contributor-photo-gallery.php (modified) (2 diffs)
-
tags/3.2.0/includes/class-cpglry-block.php (modified) (2 diffs)
-
tags/3.2.0/includes/class-cpglry-frontend.php (modified) (1 diff)
-
tags/3.2.0/includes/helpers.php (modified) (1 diff)
-
tags/3.2.0/readme.txt (modified) (5 diffs)
-
tags/3.2.0/templates/grid.php (modified) (2 diffs)
-
trunk/blocks/gallery/block.json (modified) (2 diffs)
-
trunk/blocks/gallery/index.js (modified) (13 diffs)
-
trunk/contributor-photo-gallery.php (modified) (2 diffs)
-
trunk/includes/class-cpglry-block.php (modified) (2 diffs)
-
trunk/includes/class-cpglry-frontend.php (modified) (1 diff)
-
trunk/includes/helpers.php (modified) (1 diff)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/templates/grid.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
contributor-photo-gallery/tags/3.2.0/blocks/gallery/block.json
r3831369 r3831810 7 7 "icon": "format-gallery", 8 8 "description": "Show your WordPress.org/photos contributions in a responsive grid.", 9 "keywords": [ "photos", "wordpress.org", "contributor", "gallery", "grid" ], 9 "keywords": [ 10 "photos", 11 "wordpress.org", 12 "contributor", 13 "gallery", 14 "grid" 15 ], 10 16 "textdomain": "contributor-photo-gallery", 11 17 "attributes": { … … 19 25 "columns": { 20 26 "type": "number" 27 }, 28 "cardStyle": { 29 "type": "string" 30 }, 31 "cardBgColor": { 32 "type": "string" 33 }, 34 "borderStyle": { 35 "type": "string" 36 }, 37 "borderWidth": { 38 "type": "number" 39 }, 40 "borderColor": { 41 "type": "string" 42 }, 43 "shadowStyle": { 44 "type": "string" 45 }, 46 "showCaptions": { 47 "type": "boolean" 48 }, 49 "captionColor": { 50 "type": "string" 51 }, 52 "captionAlignment": { 53 "type": "string" 54 }, 55 "openInNewTab": { 56 "type": "boolean" 57 }, 58 "lazyLoading": { 59 "type": "boolean" 21 60 } 22 61 }, 23 62 "supports": { 24 63 "html": false, 25 "align": [ "wide", "full" ], 64 "align": [ 65 "wide", 66 "full" 67 ], 26 68 "spacing": { 27 69 "margin": true -
contributor-photo-gallery/tags/3.2.0/blocks/gallery/index.js
r3831369 r3831810 5 5 * The block is dynamic: PHP renders it, and the editor shows a live 6 6 * preview through ServerSideRender. 7 * 8 * @param {Object} wp WordPress globals. 9 * @param {Object} settings Plugin defaults from cpglryBlockSettings. 7 10 */ 8 11 ( function ( wp, settings ) { … … 11 14 } 12 15 13 var el = wp.element.createElement; 14 var Fragment = wp.element.Fragment; 15 var __ = wp.i18n.__; 16 var sprintf = wp.i18n.sprintf; 17 var blockEditor = wp.blockEditor; 18 var components = wp.components; 19 var ServerSideRender = wp.serverSideRender; 20 21 var defaults = settings || {}; 22 var defaultUserId = defaults.userId || ''; 23 var defaultPerPage = parseInt( defaults.perPage, 10 ) || 12; 24 var defaultColumns = parseInt( defaults.columns, 10 ) || 4; 16 const el = wp.element.createElement; 17 const Fragment = wp.element.Fragment; 18 const __ = wp.i18n.__; 19 const sprintf = wp.i18n.sprintf; 20 const blockEditor = wp.blockEditor; 21 const components = wp.components; 22 const ServerSideRender = wp.serverSideRender; 23 24 const defaults = settings || {}; 25 const defaultUserId = defaults.userId || ''; 26 const defaultPerPage = parseInt( defaults.perPage, 10 ) || 12; 27 const defaultColumns = parseInt( defaults.columns, 10 ) || 4; 28 const styleDefaults = defaults.styles || {}; 29 30 const CARD_STYLES = { 31 default: __( 'Modern', 'contributor-photo-gallery' ), 32 polaroid: __( 'Polaroid', 'contributor-photo-gallery' ), 33 circle: __( 'Circle', 'contributor-photo-gallery' ), 34 fixed: __( 'Fixed height', 'contributor-photo-gallery' ), 35 }; 36 const BORDER_STYLES = { 37 none: __( 'None', 'contributor-photo-gallery' ), 38 solid: __( 'Solid', 'contributor-photo-gallery' ), 39 dashed: __( 'Dashed', 'contributor-photo-gallery' ), 40 dotted: __( 'Dotted', 'contributor-photo-gallery' ), 41 }; 42 const SHADOWS = { 43 none: __( 'None', 'contributor-photo-gallery' ), 44 subtle: __( 'Light', 'contributor-photo-gallery' ), 45 medium: __( 'Medium', 'contributor-photo-gallery' ), 46 strong: __( 'Strong', 'contributor-photo-gallery' ), 47 }; 48 const ALIGNMENTS = { 49 left: __( 'Left', 'contributor-photo-gallery' ), 50 center: __( 'Center', 'contributor-photo-gallery' ), 51 right: __( 'Right', 'contributor-photo-gallery' ), 52 }; 53 54 /** 55 * Label for "use the plugin setting", naming what that setting is. 56 * 57 * @param {string} current The plugin setting, as shown to the user. 58 * @return {string} Option label. 59 */ 60 function pluginSetting( current ) { 61 return sprintf( 62 /* translators: %s: the value set on the plugin's settings screen. */ 63 __( 'Plugin setting (%s)', 'contributor-photo-gallery' ), 64 current 65 ); 66 } 67 68 /** 69 * A select whose first option keeps the plugin setting (attribute unset). 70 * 71 * @param {Object} args Control arguments. 72 * @param {string} args.label Label. 73 * @param {Object} args.choices Value => label. 74 * @param {string} args.value Current attribute value, or undefined. 75 * @param {string} args.fallback The plugin setting's value. 76 * @param {Function} args.onChange Receives the new value, or undefined. 77 * @return {Object} Element. 78 */ 79 function choiceControl( args ) { 80 const options = [ 81 { 82 value: '', 83 label: pluginSetting( 84 args.choices[ args.fallback ] || args.fallback 85 ), 86 }, 87 ]; 88 Object.keys( args.choices ).forEach( function ( key ) { 89 options.push( { value: key, label: args.choices[ key ] } ); 90 } ); 91 return el( components.SelectControl, { 92 label: args.label, 93 value: args.value === undefined ? '' : String( args.value ), 94 options, 95 onChange( value ) { 96 args.onChange( value === '' ? undefined : value ); 97 }, 98 } ); 99 } 100 101 /** 102 * A show/hide (or on/off) choice that can also keep the plugin setting. 103 * 104 * @param {Object} args Control arguments. 105 * @param {string} args.label Label. 106 * @param {string} args.on Label for true. 107 * @param {string} args.off Label for false. 108 * @param {boolean} args.value Current attribute value, or undefined. 109 * @param {boolean} args.fallback The plugin setting's value. 110 * @param {Function} args.onChange Receives true, false or undefined. 111 * @return {Object} Element. 112 */ 113 function toggleChoice( args ) { 114 return el( components.SelectControl, { 115 label: args.label, 116 value: args.value === undefined ? '' : String( args.value ), 117 options: [ 118 { 119 value: '', 120 label: pluginSetting( args.fallback ? args.on : args.off ), 121 }, 122 { value: 'true', label: args.on }, 123 { value: 'false', label: args.off }, 124 ], 125 onChange( value ) { 126 args.onChange( value === '' ? undefined : value === 'true' ); 127 }, 128 } ); 129 } 130 131 /** 132 * A color picker; clearing it goes back to the plugin setting. 133 * 134 * @param {string} label Label. 135 * @param {string} value Current attribute value, or undefined. 136 * @param {string} fallback The plugin setting's color. 137 * @param {Function} onChange Receives a hex color, or undefined. 138 * @return {Object} Element. 139 */ 140 function colorControl( label, value, fallback, onChange ) { 141 return el( 142 components.BaseControl, 143 { 144 label, 145 help: value ? null : pluginSetting( fallback ), 146 className: 'cpglry-color-control', 147 }, 148 el( components.ColorPalette, { 149 // The theme's palette, plus a custom color picker. 150 colors: 151 ( wp.data && 152 wp.data.select( 'core/block-editor' ).getSettings() 153 .colors ) || 154 [], 155 value, 156 onChange( color ) { 157 onChange( color || undefined ); 158 }, 159 clearable: true, 160 } ) 161 ); 162 } 163 164 /** 165 * Button that clears a panel's attributes, so it uses the plugin settings. 166 * 167 * @param {Array} keys Attribute names. 168 * @param {Object} attributes Block attributes. 169 * @param {Function} setAttributes Setter. 170 * @return {Object|null} Element, or null when nothing is overridden. 171 */ 172 function resetButton( keys, attributes, setAttributes ) { 173 const changed = keys.some( function ( key ) { 174 return attributes[ key ] !== undefined; 175 } ); 176 if ( ! changed ) { 177 return null; 178 } 179 return el( 180 components.Button, 181 { 182 variant: 'secondary', 183 isSecondary: true, 184 isSmall: true, 185 onClick() { 186 const cleared = {}; 187 keys.forEach( function ( key ) { 188 cleared[ key ] = undefined; 189 } ); 190 setAttributes( cleared ); 191 }, 192 }, 193 __( 'Reset to plugin settings', 'contributor-photo-gallery' ) 194 ); 195 } 196 197 /** 198 * Cards, Captions, and Links and loading panels. Each control starts on the plugin 199 * setting and can be changed for this block only. 200 * 201 * @param {Object} attributes Block attributes. 202 * @param {Function} setAttributes Setter. 203 * @return {Array} Panel elements. 204 */ 205 function stylePanels( attributes, setAttributes ) { 206 function set( key ) { 207 return function ( value ) { 208 const next = {}; 209 next[ key ] = value; 210 setAttributes( next ); 211 }; 212 } 213 214 return [ 215 el( 216 components.PanelBody, 217 { 218 key: 'cards', 219 title: __( 'Cards', 'contributor-photo-gallery' ), 220 initialOpen: false, 221 }, 222 choiceControl( { 223 label: __( 'Card style', 'contributor-photo-gallery' ), 224 choices: CARD_STYLES, 225 value: attributes.cardStyle, 226 fallback: styleDefaults.cardStyle, 227 onChange: set( 'cardStyle' ), 228 } ), 229 colorControl( 230 __( 'Card background', 'contributor-photo-gallery' ), 231 attributes.cardBgColor, 232 styleDefaults.cardBgColor, 233 set( 'cardBgColor' ) 234 ), 235 choiceControl( { 236 label: __( 'Border style', 'contributor-photo-gallery' ), 237 choices: BORDER_STYLES, 238 value: attributes.borderStyle, 239 fallback: styleDefaults.borderStyle, 240 onChange: set( 'borderStyle' ), 241 } ), 242 el( components.RangeControl, { 243 label: __( 244 'Border width (px)', 245 'contributor-photo-gallery' 246 ), 247 help: 248 attributes.borderWidth === undefined 249 ? pluginSetting( styleDefaults.borderWidth + 'px' ) 250 : null, 251 value: attributes.borderWidth, 252 initialPosition: styleDefaults.borderWidth, 253 min: 0, 254 max: 10, 255 allowReset: true, 256 resetFallbackValue: undefined, 257 onChange: set( 'borderWidth' ), 258 } ), 259 colorControl( 260 __( 'Border color', 'contributor-photo-gallery' ), 261 attributes.borderColor, 262 styleDefaults.borderColor, 263 set( 'borderColor' ) 264 ), 265 choiceControl( { 266 label: __( 'Shadow', 'contributor-photo-gallery' ), 267 choices: SHADOWS, 268 value: attributes.shadowStyle, 269 fallback: styleDefaults.shadowStyle, 270 onChange: set( 'shadowStyle' ), 271 } ), 272 resetButton( 273 [ 274 'cardStyle', 275 'cardBgColor', 276 'borderStyle', 277 'borderWidth', 278 'borderColor', 279 'shadowStyle', 280 ], 281 attributes, 282 setAttributes 283 ) 284 ), 285 el( 286 components.PanelBody, 287 { 288 key: 'captions', 289 title: __( 'Captions', 'contributor-photo-gallery' ), 290 initialOpen: false, 291 }, 292 toggleChoice( { 293 label: __( 'Captions', 'contributor-photo-gallery' ), 294 on: __( 'Show', 'contributor-photo-gallery' ), 295 off: __( 'Hide', 'contributor-photo-gallery' ), 296 value: attributes.showCaptions, 297 fallback: styleDefaults.showCaptions, 298 onChange: set( 'showCaptions' ), 299 } ), 300 colorControl( 301 __( 'Caption color', 'contributor-photo-gallery' ), 302 attributes.captionColor, 303 styleDefaults.captionColor, 304 set( 'captionColor' ) 305 ), 306 choiceControl( { 307 label: __( 308 'Caption alignment', 309 'contributor-photo-gallery' 310 ), 311 choices: ALIGNMENTS, 312 value: attributes.captionAlignment, 313 fallback: styleDefaults.captionAlignment, 314 onChange: set( 'captionAlignment' ), 315 } ), 316 resetButton( 317 [ 'showCaptions', 'captionColor', 'captionAlignment' ], 318 attributes, 319 setAttributes 320 ) 321 ), 322 el( 323 components.PanelBody, 324 { 325 key: 'links', 326 title: __( 327 'Links and loading', 328 'contributor-photo-gallery' 329 ), 330 initialOpen: false, 331 }, 332 toggleChoice( { 333 label: __( 334 'Open photos in a new tab', 335 'contributor-photo-gallery' 336 ), 337 on: __( 'Yes', 'contributor-photo-gallery' ), 338 off: __( 'No', 'contributor-photo-gallery' ), 339 value: attributes.openInNewTab, 340 fallback: styleDefaults.openInNewTab, 341 onChange: set( 'openInNewTab' ), 342 } ), 343 toggleChoice( { 344 label: __( 345 'Lazy-load images', 346 'contributor-photo-gallery' 347 ), 348 on: __( 'On', 'contributor-photo-gallery' ), 349 off: __( 'Off', 'contributor-photo-gallery' ), 350 value: attributes.lazyLoading, 351 fallback: styleDefaults.lazyLoading, 352 onChange: set( 'lazyLoading' ), 353 } ), 354 resetButton( 355 [ 'openInNewTab', 'lazyLoading' ], 356 attributes, 357 setAttributes 358 ) 359 ), 360 ]; 361 } 25 362 26 363 function Placeholder( props ) { … … 29 366 { 30 367 icon: 'format-gallery', 31 label: __( 'Contributor Photo Gallery', 'contributor-photo-gallery' ), 368 label: __( 369 'Contributor Photo Gallery', 370 'contributor-photo-gallery' 371 ), 32 372 instructions: __( 33 373 'Enter a WordPress.org username or numeric user ID to show their photo contributions.', … … 36 376 }, 37 377 el( components.TextControl, { 38 label: __( 'WordPress.org username or user ID', 'contributor-photo-gallery' ), 378 label: __( 379 'WordPress.org username or user ID', 380 'contributor-photo-gallery' 381 ), 39 382 hideLabelFromVision: true, 40 placeholder: __( 'e.g. makarandmane', 'contributor-photo-gallery' ), 383 placeholder: __( 384 'e.g. makarandmane', 385 'contributor-photo-gallery' 386 ), 41 387 value: props.attributes.userId, 42 onChange : function( value ) {388 onChange( value ) { 43 389 props.setAttributes( { userId: value.trim() } ); 44 390 }, … … 48 394 components.ExternalLink, 49 395 { href: props.settingsUrl }, 50 __( 'Or set a default in plugin settings', 'contributor-photo-gallery' ) 396 __( 397 'Or set a default in plugin settings', 398 'contributor-photo-gallery' 399 ) 51 400 ) 52 401 ); … … 54 403 55 404 function Edit( props ) { 56 varattributes = props.attributes;57 varsetAttributes = props.setAttributes;58 varblockProps = blockEditor.useBlockProps();59 60 vareffectiveUserId = attributes.userId || defaultUserId;61 varperPage = attributes.perPage || defaultPerPage;62 varcolumns = attributes.columns || defaultColumns;63 64 varinspector = el(405 const attributes = props.attributes; 406 const setAttributes = props.setAttributes; 407 const blockProps = blockEditor.useBlockProps(); 408 409 const effectiveUserId = attributes.userId || defaultUserId; 410 const perPage = attributes.perPage || defaultPerPage; 411 const columns = attributes.columns || defaultColumns; 412 413 const inspector = el( 65 414 blockEditor.InspectorControls, 66 415 null, 67 416 el( 68 417 components.PanelBody, 69 { title: __( 'Gallery settings', 'contributor-photo-gallery' ), initialOpen: true }, 418 { 419 title: __( 420 'Gallery settings', 421 'contributor-photo-gallery' 422 ), 423 initialOpen: true, 424 }, 70 425 el( components.TextControl, { 71 label: __( 'WordPress.org username or user ID', 'contributor-photo-gallery' ), 426 label: __( 427 'WordPress.org username or user ID', 428 'contributor-photo-gallery' 429 ), 72 430 help: defaultUserId 73 431 ? sprintf( 74 432 /* translators: %s: default user from plugin settings. */ 75 __( 'Leave empty to use the default from settings (%s).', 'contributor-photo-gallery' ), 433 __( 434 'Leave empty to use the default from settings (%s).', 435 'contributor-photo-gallery' 436 ), 76 437 defaultUserId 77 ) 78 : __( 'No default user is set in plugin settings.', 'contributor-photo-gallery' ), 438 ) 439 : __( 440 'No default user is set in plugin settings.', 441 'contributor-photo-gallery' 442 ), 79 443 value: attributes.userId, 80 onChange : function( value ) {444 onChange( value ) { 81 445 setAttributes( { userId: value.trim() } ); 82 446 }, 83 447 } ), 84 448 el( components.RangeControl, { 85 label: __( 'Number of photos', 'contributor-photo-gallery' ), 449 label: __( 450 'Number of photos', 451 'contributor-photo-gallery' 452 ), 86 453 value: perPage, 87 454 min: 1, 88 455 max: 50, 89 onChange : function( value ) {456 onChange( value ) { 90 457 setAttributes( { perPage: value } ); 91 458 }, … … 96 463 min: 1, 97 464 max: 6, 98 onChange : function( value ) {465 onChange( value ) { 99 466 setAttributes( { columns: value } ); 100 467 }, … … 107 474 components.ExternalLink, 108 475 { href: defaults.settingsUrl }, 109 __( 'Card styles and colors', 'contributor-photo-gallery' ) 476 __( 477 'Card styles and colors', 478 'contributor-photo-gallery' 479 ) 110 480 ) 111 481 ) 112 ) 482 ), 483 stylePanels( attributes, setAttributes ) 113 484 ); 114 485 115 varbody = effectiveUserId486 const body = effectiveUserId 116 487 ? el( 117 488 components.Disabled, … … 119 490 el( ServerSideRender, { 120 491 block: props.name, 121 attributes : attributes,492 attributes, 122 493 skipBlockSupportAttributes: true, 123 494 } ) 124 )495 ) 125 496 : el( Placeholder, { 126 attributes : attributes,127 setAttributes : setAttributes,497 attributes, 498 setAttributes, 128 499 settingsUrl: defaults.settingsUrl, 129 } );500 } ); 130 501 131 502 return el( Fragment, null, inspector, el( 'div', blockProps, body ) ); … … 134 505 wp.blocks.registerBlockType( 'contributor-photo-gallery/gallery', { 135 506 edit: Edit, 136 save : function() {507 save() { 137 508 return null; 138 509 }, … … 145 516 userId: { 146 517 type: 'string', 147 shortcode : function( attrs ) {518 shortcode( attrs ) { 148 519 return attrs.named.user_id || ''; 149 520 }, … … 151 522 perPage: { 152 523 type: 'number', 153 shortcode : function( attrs ) {154 varn = parseInt( attrs.named.per_page, 10 );524 shortcode( attrs ) { 525 const n = parseInt( attrs.named.per_page, 10 ); 155 526 return isNaN( n ) ? undefined : n; 156 527 }, … … 158 529 columns: { 159 530 type: 'number', 160 shortcode : function( attrs ) {161 varn = parseInt( attrs.named.columns, 10 );531 shortcode( attrs ) { 532 const n = parseInt( attrs.named.columns, 10 ); 162 533 return isNaN( n ) ? undefined : n; 163 534 }, -
contributor-photo-gallery/tags/3.2.0/contributor-photo-gallery.php
r3831579 r3831810 4 4 * Plugin URI: https://wordpress.org/plugins/contributor-photo-gallery/ 5 5 * Description: Showcase your contributions to WordPress.org/photos with elegant and responsive photo galleries. 6 * Version: 3. 1.46 * Version: 3.2.0 7 7 * Requires at least: 5.8 8 8 * Requires PHP: 8.0 … … 21 21 } 22 22 23 define( 'CPGLRY_VERSION', '3. 1.4' );23 define( 'CPGLRY_VERSION', '3.2.0' ); 24 24 define( 'CPGLRY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 25 25 define( 'CPGLRY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); -
contributor-photo-gallery/tags/3.2.0/includes/class-cpglry-block.php
r3831417 r3831810 53 53 'perPage' => (int) $options['default_per_page'], 54 54 'columns' => (int) $options['default_columns'], 55 // The plugin settings each style control falls back to. 56 'styles' => array( 57 'cardStyle' => $options['card_style'], 58 'cardBgColor' => $options['card_bg_color'], 59 'borderStyle' => $options['card_border_style'], 60 'borderWidth' => (int) $options['card_border_width'], 61 'borderColor' => $options['card_border_color'], 62 'shadowStyle' => $options['card_shadow_style'], 63 'showCaptions' => (bool) $options['show_captions'], 64 'captionColor' => $options['caption_text_color'], 65 'captionAlignment' => $options['caption_alignment'], 66 'openInNewTab' => (bool) $options['open_in_new_tab'], 67 'lazyLoading' => (bool) $options['enable_lazy_loading'], 68 ), 55 69 'settingsUrl' => current_user_can( 'manage_options' ) ? admin_url( 'admin.php?page=contributor-photo-gallery' ) : '', 56 70 ) … … 104 118 } 105 119 106 $html = CPGLRY_Frontend::render_shortcode( $atts ); 120 // Styling set on this block; anything left empty uses the plugin settings. 121 $overrides = array(); 122 foreach ( cpglry_style_override_keys() as $attribute => $option ) { 123 if ( isset( $attributes[ $attribute ] ) ) { 124 $overrides[ $option ] = $attributes[ $attribute ]; 125 } 126 } 127 128 $html = CPGLRY_Frontend::render_shortcode( $atts, $overrides ); 107 129 108 130 return sprintf( '<div %1$s>%2$s</div>', $this->wrapper_attributes(), $html ); -
contributor-photo-gallery/tags/3.2.0/includes/class-cpglry-frontend.php
r3831417 r3831810 69 69 * Renders the gallery using templates/grid.php which expects $cpglry_photos and $cpglry_options. 70 70 * 71 * @param array $atts Shortcode attributes. 71 * @param array $atts Shortcode attributes. 72 * @param array $overrides Styling options for this gallery only (option key => value), 73 * such as the block's card style; unset keys use the saved settings. 72 74 * @return string 73 75 */ 74 public static function render_shortcode( $atts = array() ) {75 $cpglry_options = cpglry_get_plugin_options();76 public static function render_shortcode( $atts = array(), $overrides = array() ) { 77 $cpglry_options = array_merge( cpglry_get_plugin_options(), cpglry_sanitize_style_overrides( $overrides ) ); 76 78 77 79 // Shortcode attrs override options. -
contributor-photo-gallery/tags/3.2.0/includes/helpers.php
r3831417 r3831810 63 63 } 64 64 } 65 66 67 /** 68 * Block attributes that can override a styling option for one gallery, mapped 69 * to the option they override. 70 * 71 * @return array Block attribute name => option key. 72 */ 73 function cpglry_style_override_keys() { 74 return array( 75 'cardStyle' => 'card_style', 76 'cardBgColor' => 'card_bg_color', 77 'borderStyle' => 'card_border_style', 78 'borderWidth' => 'card_border_width', 79 'borderColor' => 'card_border_color', 80 'shadowStyle' => 'card_shadow_style', 81 'showCaptions' => 'show_captions', 82 'captionColor' => 'caption_text_color', 83 'captionAlignment' => 'caption_alignment', 84 'openInNewTab' => 'open_in_new_tab', 85 'lazyLoading' => 'enable_lazy_loading', 86 ); 87 } 88 89 /** 90 * Sanitizes styling overrides for one gallery. Only keys that are set and 91 * valid are returned, so everything else keeps the saved setting. 92 * 93 * @param array $overrides Option key => raw value. 94 * @return array Option key => sanitized value. 95 */ 96 function cpglry_sanitize_style_overrides( $overrides ) { 97 $choices = array( 98 'card_style' => array( 'default', 'polaroid', 'circle', 'fixed' ), 99 'card_border_style' => array( 'none', 'solid', 'dashed', 'dotted' ), 100 'card_shadow_style' => array( 'none', 'subtle', 'medium', 'strong' ), 101 'caption_alignment' => array( 'left', 'center', 'right' ), 102 ); 103 $colors = array( 'card_bg_color', 'card_border_color', 'caption_text_color' ); 104 $toggles = array( 'show_captions', 'open_in_new_tab', 'enable_lazy_loading' ); 105 $clean = array(); 106 107 foreach ( (array) $overrides as $key => $value ) { 108 if ( null === $value || '' === $value ) { 109 continue; 110 } 111 if ( isset( $choices[ $key ] ) ) { 112 if ( in_array( $value, $choices[ $key ], true ) ) { 113 $clean[ $key ] = $value; 114 } 115 } elseif ( in_array( $key, $colors, true ) ) { 116 $color = sanitize_hex_color( $value ); 117 if ( $color ) { 118 $clean[ $key ] = $color; 119 } 120 } elseif ( in_array( $key, $toggles, true ) ) { 121 $clean[ $key ] = $value ? 1 : 0; 122 } elseif ( 'card_border_width' === $key && is_numeric( $value ) ) { 123 $clean[ $key ] = max( 0, min( 10, absint( $value ) ) ); 124 } 125 } 126 127 return $clean; 128 } -
contributor-photo-gallery/tags/3.2.0/readme.txt
r3831579 r3831810 5 5 Requires at least: 5.8 6 6 Tested up to: 7.1 7 Stable tag: 3. 1.47 Stable tag: 3.2.0 8 8 Requires PHP: 8.0 9 9 License: GPLv3 … … 17 17 18 18 Your photos stay hosted on WordPress.org and link back to it, and the gallery picks up new photos as you publish them. 19 20 ### New in 3.2 21 22 * **Style each block on its own.** The block sidebar now has the same styling as the settings screen: card style, background, border, shadow, captions (show or hide, color, alignment), new-tab links and lazy-loading. Anything you leave alone uses the plugin settings. 19 23 20 24 ### New in 3.1 … … 45 49 ### Add a gallery 46 50 47 **Block:** add **Contributor Photo Gallery** from the Media category. The sidebar sets the WordPress.org user, number of photos (1 to 50) and columns (1 to 6); leave the user empty to use your saved settings. Card styles and colors come from the settings screen, so blocks and shortcodes always match. Existing shortcode blocks can be turned into the block with **Transform to**.51 **Block:** add **Contributor Photo Gallery** from the Media category. The sidebar sets the WordPress.org user, number of photos (1 to 50) and columns (1 to 6); leave the user empty to use your saved settings. The **Cards**, **Captions**, and **Links and loading** panels style this block only; each option starts on the plugin setting, and **Reset to plugin settings** puts a panel back. Existing shortcode blocks can be turned into the block with **Transform to**. 48 52 49 53 **Shortcode:** `[cp_gallery]` uses your saved settings. Attributes change a single gallery: … … 114 118 == Changelog == 115 119 120 = 3.2.0 - 2026-11-28 = 121 122 * New: Card style, background, border, shadow, captions, new-tab links and lazy-loading can be set per block; anything left alone uses the plugin settings. 123 * Fixed: The Lazy-load images setting is now respected; images were always lazy-loaded. 124 116 125 = 3.1.4 - 2026-11-28 = 117 126 … … 182 191 == Upgrade Notice == 183 192 193 = 3.2.0 = 194 Style each gallery block on its own: card style, colors, border, shadow, captions, links and lazy-loading. Existing blocks keep using your plugin settings. 195 184 196 = 3.1.3 = 185 197 3.1 brings a guided setup, a redesigned settings screen with a live preview, caption alignment, and the gallery block from 3.0. Your settings carry over. -
contributor-photo-gallery/tags/3.2.0/templates/grid.php
r3831417 r3831810 137 137 $cpglry_open_in_new = isset( $cpglry_options['open_in_new_tab'] ) ? (bool) $cpglry_options['open_in_new_tab'] : true; 138 138 $cpglry_target = $cpglry_open_in_new ? '_blank' : ''; 139 $cpglry_lazy = isset( $cpglry_options['enable_lazy_loading'] ) ? (bool) $cpglry_options['enable_lazy_loading'] : true; 139 140 // include noreferrer as recommended when opening new tab 140 141 $cpglry_rel = $cpglry_open_in_new ? 'noopener noreferrer' : ''; … … 142 143 echo '<div class="cpg-photo-card cpg-style-' . esc_attr( $cpglry_card_style ) . '">'; 143 144 echo '<a href="' . esc_url( $cpglry_link ) . '"' . ( $cpglry_target ? ' target="' . esc_attr( $cpglry_target ) . '"' : '' ) . ( $cpglry_rel ? ' rel="' . esc_attr( $cpglry_rel ) . '"' : '' ) . '>'; 144 echo '<div class="cpg-photo-image"><img src="' . esc_url( $cpglry_image_url ) . '" alt="' . esc_attr( $cpglry_title ) . '" loading="lazy"></div>';145 echo '<div class="cpg-photo-image"><img src="' . esc_url( $cpglry_image_url ) . '" alt="' . esc_attr( $cpglry_title ) . '"' . ( $cpglry_lazy ? ' loading="lazy"' : '' ) . '></div>'; 145 146 146 147 if ( $cpglry_show_captions && ! empty( $cpglry_title ) ) { -
contributor-photo-gallery/trunk/blocks/gallery/block.json
r3831369 r3831810 7 7 "icon": "format-gallery", 8 8 "description": "Show your WordPress.org/photos contributions in a responsive grid.", 9 "keywords": [ "photos", "wordpress.org", "contributor", "gallery", "grid" ], 9 "keywords": [ 10 "photos", 11 "wordpress.org", 12 "contributor", 13 "gallery", 14 "grid" 15 ], 10 16 "textdomain": "contributor-photo-gallery", 11 17 "attributes": { … … 19 25 "columns": { 20 26 "type": "number" 27 }, 28 "cardStyle": { 29 "type": "string" 30 }, 31 "cardBgColor": { 32 "type": "string" 33 }, 34 "borderStyle": { 35 "type": "string" 36 }, 37 "borderWidth": { 38 "type": "number" 39 }, 40 "borderColor": { 41 "type": "string" 42 }, 43 "shadowStyle": { 44 "type": "string" 45 }, 46 "showCaptions": { 47 "type": "boolean" 48 }, 49 "captionColor": { 50 "type": "string" 51 }, 52 "captionAlignment": { 53 "type": "string" 54 }, 55 "openInNewTab": { 56 "type": "boolean" 57 }, 58 "lazyLoading": { 59 "type": "boolean" 21 60 } 22 61 }, 23 62 "supports": { 24 63 "html": false, 25 "align": [ "wide", "full" ], 64 "align": [ 65 "wide", 66 "full" 67 ], 26 68 "spacing": { 27 69 "margin": true -
contributor-photo-gallery/trunk/blocks/gallery/index.js
r3831369 r3831810 5 5 * The block is dynamic: PHP renders it, and the editor shows a live 6 6 * preview through ServerSideRender. 7 * 8 * @param {Object} wp WordPress globals. 9 * @param {Object} settings Plugin defaults from cpglryBlockSettings. 7 10 */ 8 11 ( function ( wp, settings ) { … … 11 14 } 12 15 13 var el = wp.element.createElement; 14 var Fragment = wp.element.Fragment; 15 var __ = wp.i18n.__; 16 var sprintf = wp.i18n.sprintf; 17 var blockEditor = wp.blockEditor; 18 var components = wp.components; 19 var ServerSideRender = wp.serverSideRender; 20 21 var defaults = settings || {}; 22 var defaultUserId = defaults.userId || ''; 23 var defaultPerPage = parseInt( defaults.perPage, 10 ) || 12; 24 var defaultColumns = parseInt( defaults.columns, 10 ) || 4; 16 const el = wp.element.createElement; 17 const Fragment = wp.element.Fragment; 18 const __ = wp.i18n.__; 19 const sprintf = wp.i18n.sprintf; 20 const blockEditor = wp.blockEditor; 21 const components = wp.components; 22 const ServerSideRender = wp.serverSideRender; 23 24 const defaults = settings || {}; 25 const defaultUserId = defaults.userId || ''; 26 const defaultPerPage = parseInt( defaults.perPage, 10 ) || 12; 27 const defaultColumns = parseInt( defaults.columns, 10 ) || 4; 28 const styleDefaults = defaults.styles || {}; 29 30 const CARD_STYLES = { 31 default: __( 'Modern', 'contributor-photo-gallery' ), 32 polaroid: __( 'Polaroid', 'contributor-photo-gallery' ), 33 circle: __( 'Circle', 'contributor-photo-gallery' ), 34 fixed: __( 'Fixed height', 'contributor-photo-gallery' ), 35 }; 36 const BORDER_STYLES = { 37 none: __( 'None', 'contributor-photo-gallery' ), 38 solid: __( 'Solid', 'contributor-photo-gallery' ), 39 dashed: __( 'Dashed', 'contributor-photo-gallery' ), 40 dotted: __( 'Dotted', 'contributor-photo-gallery' ), 41 }; 42 const SHADOWS = { 43 none: __( 'None', 'contributor-photo-gallery' ), 44 subtle: __( 'Light', 'contributor-photo-gallery' ), 45 medium: __( 'Medium', 'contributor-photo-gallery' ), 46 strong: __( 'Strong', 'contributor-photo-gallery' ), 47 }; 48 const ALIGNMENTS = { 49 left: __( 'Left', 'contributor-photo-gallery' ), 50 center: __( 'Center', 'contributor-photo-gallery' ), 51 right: __( 'Right', 'contributor-photo-gallery' ), 52 }; 53 54 /** 55 * Label for "use the plugin setting", naming what that setting is. 56 * 57 * @param {string} current The plugin setting, as shown to the user. 58 * @return {string} Option label. 59 */ 60 function pluginSetting( current ) { 61 return sprintf( 62 /* translators: %s: the value set on the plugin's settings screen. */ 63 __( 'Plugin setting (%s)', 'contributor-photo-gallery' ), 64 current 65 ); 66 } 67 68 /** 69 * A select whose first option keeps the plugin setting (attribute unset). 70 * 71 * @param {Object} args Control arguments. 72 * @param {string} args.label Label. 73 * @param {Object} args.choices Value => label. 74 * @param {string} args.value Current attribute value, or undefined. 75 * @param {string} args.fallback The plugin setting's value. 76 * @param {Function} args.onChange Receives the new value, or undefined. 77 * @return {Object} Element. 78 */ 79 function choiceControl( args ) { 80 const options = [ 81 { 82 value: '', 83 label: pluginSetting( 84 args.choices[ args.fallback ] || args.fallback 85 ), 86 }, 87 ]; 88 Object.keys( args.choices ).forEach( function ( key ) { 89 options.push( { value: key, label: args.choices[ key ] } ); 90 } ); 91 return el( components.SelectControl, { 92 label: args.label, 93 value: args.value === undefined ? '' : String( args.value ), 94 options, 95 onChange( value ) { 96 args.onChange( value === '' ? undefined : value ); 97 }, 98 } ); 99 } 100 101 /** 102 * A show/hide (or on/off) choice that can also keep the plugin setting. 103 * 104 * @param {Object} args Control arguments. 105 * @param {string} args.label Label. 106 * @param {string} args.on Label for true. 107 * @param {string} args.off Label for false. 108 * @param {boolean} args.value Current attribute value, or undefined. 109 * @param {boolean} args.fallback The plugin setting's value. 110 * @param {Function} args.onChange Receives true, false or undefined. 111 * @return {Object} Element. 112 */ 113 function toggleChoice( args ) { 114 return el( components.SelectControl, { 115 label: args.label, 116 value: args.value === undefined ? '' : String( args.value ), 117 options: [ 118 { 119 value: '', 120 label: pluginSetting( args.fallback ? args.on : args.off ), 121 }, 122 { value: 'true', label: args.on }, 123 { value: 'false', label: args.off }, 124 ], 125 onChange( value ) { 126 args.onChange( value === '' ? undefined : value === 'true' ); 127 }, 128 } ); 129 } 130 131 /** 132 * A color picker; clearing it goes back to the plugin setting. 133 * 134 * @param {string} label Label. 135 * @param {string} value Current attribute value, or undefined. 136 * @param {string} fallback The plugin setting's color. 137 * @param {Function} onChange Receives a hex color, or undefined. 138 * @return {Object} Element. 139 */ 140 function colorControl( label, value, fallback, onChange ) { 141 return el( 142 components.BaseControl, 143 { 144 label, 145 help: value ? null : pluginSetting( fallback ), 146 className: 'cpglry-color-control', 147 }, 148 el( components.ColorPalette, { 149 // The theme's palette, plus a custom color picker. 150 colors: 151 ( wp.data && 152 wp.data.select( 'core/block-editor' ).getSettings() 153 .colors ) || 154 [], 155 value, 156 onChange( color ) { 157 onChange( color || undefined ); 158 }, 159 clearable: true, 160 } ) 161 ); 162 } 163 164 /** 165 * Button that clears a panel's attributes, so it uses the plugin settings. 166 * 167 * @param {Array} keys Attribute names. 168 * @param {Object} attributes Block attributes. 169 * @param {Function} setAttributes Setter. 170 * @return {Object|null} Element, or null when nothing is overridden. 171 */ 172 function resetButton( keys, attributes, setAttributes ) { 173 const changed = keys.some( function ( key ) { 174 return attributes[ key ] !== undefined; 175 } ); 176 if ( ! changed ) { 177 return null; 178 } 179 return el( 180 components.Button, 181 { 182 variant: 'secondary', 183 isSecondary: true, 184 isSmall: true, 185 onClick() { 186 const cleared = {}; 187 keys.forEach( function ( key ) { 188 cleared[ key ] = undefined; 189 } ); 190 setAttributes( cleared ); 191 }, 192 }, 193 __( 'Reset to plugin settings', 'contributor-photo-gallery' ) 194 ); 195 } 196 197 /** 198 * Cards, Captions, and Links and loading panels. Each control starts on the plugin 199 * setting and can be changed for this block only. 200 * 201 * @param {Object} attributes Block attributes. 202 * @param {Function} setAttributes Setter. 203 * @return {Array} Panel elements. 204 */ 205 function stylePanels( attributes, setAttributes ) { 206 function set( key ) { 207 return function ( value ) { 208 const next = {}; 209 next[ key ] = value; 210 setAttributes( next ); 211 }; 212 } 213 214 return [ 215 el( 216 components.PanelBody, 217 { 218 key: 'cards', 219 title: __( 'Cards', 'contributor-photo-gallery' ), 220 initialOpen: false, 221 }, 222 choiceControl( { 223 label: __( 'Card style', 'contributor-photo-gallery' ), 224 choices: CARD_STYLES, 225 value: attributes.cardStyle, 226 fallback: styleDefaults.cardStyle, 227 onChange: set( 'cardStyle' ), 228 } ), 229 colorControl( 230 __( 'Card background', 'contributor-photo-gallery' ), 231 attributes.cardBgColor, 232 styleDefaults.cardBgColor, 233 set( 'cardBgColor' ) 234 ), 235 choiceControl( { 236 label: __( 'Border style', 'contributor-photo-gallery' ), 237 choices: BORDER_STYLES, 238 value: attributes.borderStyle, 239 fallback: styleDefaults.borderStyle, 240 onChange: set( 'borderStyle' ), 241 } ), 242 el( components.RangeControl, { 243 label: __( 244 'Border width (px)', 245 'contributor-photo-gallery' 246 ), 247 help: 248 attributes.borderWidth === undefined 249 ? pluginSetting( styleDefaults.borderWidth + 'px' ) 250 : null, 251 value: attributes.borderWidth, 252 initialPosition: styleDefaults.borderWidth, 253 min: 0, 254 max: 10, 255 allowReset: true, 256 resetFallbackValue: undefined, 257 onChange: set( 'borderWidth' ), 258 } ), 259 colorControl( 260 __( 'Border color', 'contributor-photo-gallery' ), 261 attributes.borderColor, 262 styleDefaults.borderColor, 263 set( 'borderColor' ) 264 ), 265 choiceControl( { 266 label: __( 'Shadow', 'contributor-photo-gallery' ), 267 choices: SHADOWS, 268 value: attributes.shadowStyle, 269 fallback: styleDefaults.shadowStyle, 270 onChange: set( 'shadowStyle' ), 271 } ), 272 resetButton( 273 [ 274 'cardStyle', 275 'cardBgColor', 276 'borderStyle', 277 'borderWidth', 278 'borderColor', 279 'shadowStyle', 280 ], 281 attributes, 282 setAttributes 283 ) 284 ), 285 el( 286 components.PanelBody, 287 { 288 key: 'captions', 289 title: __( 'Captions', 'contributor-photo-gallery' ), 290 initialOpen: false, 291 }, 292 toggleChoice( { 293 label: __( 'Captions', 'contributor-photo-gallery' ), 294 on: __( 'Show', 'contributor-photo-gallery' ), 295 off: __( 'Hide', 'contributor-photo-gallery' ), 296 value: attributes.showCaptions, 297 fallback: styleDefaults.showCaptions, 298 onChange: set( 'showCaptions' ), 299 } ), 300 colorControl( 301 __( 'Caption color', 'contributor-photo-gallery' ), 302 attributes.captionColor, 303 styleDefaults.captionColor, 304 set( 'captionColor' ) 305 ), 306 choiceControl( { 307 label: __( 308 'Caption alignment', 309 'contributor-photo-gallery' 310 ), 311 choices: ALIGNMENTS, 312 value: attributes.captionAlignment, 313 fallback: styleDefaults.captionAlignment, 314 onChange: set( 'captionAlignment' ), 315 } ), 316 resetButton( 317 [ 'showCaptions', 'captionColor', 'captionAlignment' ], 318 attributes, 319 setAttributes 320 ) 321 ), 322 el( 323 components.PanelBody, 324 { 325 key: 'links', 326 title: __( 327 'Links and loading', 328 'contributor-photo-gallery' 329 ), 330 initialOpen: false, 331 }, 332 toggleChoice( { 333 label: __( 334 'Open photos in a new tab', 335 'contributor-photo-gallery' 336 ), 337 on: __( 'Yes', 'contributor-photo-gallery' ), 338 off: __( 'No', 'contributor-photo-gallery' ), 339 value: attributes.openInNewTab, 340 fallback: styleDefaults.openInNewTab, 341 onChange: set( 'openInNewTab' ), 342 } ), 343 toggleChoice( { 344 label: __( 345 'Lazy-load images', 346 'contributor-photo-gallery' 347 ), 348 on: __( 'On', 'contributor-photo-gallery' ), 349 off: __( 'Off', 'contributor-photo-gallery' ), 350 value: attributes.lazyLoading, 351 fallback: styleDefaults.lazyLoading, 352 onChange: set( 'lazyLoading' ), 353 } ), 354 resetButton( 355 [ 'openInNewTab', 'lazyLoading' ], 356 attributes, 357 setAttributes 358 ) 359 ), 360 ]; 361 } 25 362 26 363 function Placeholder( props ) { … … 29 366 { 30 367 icon: 'format-gallery', 31 label: __( 'Contributor Photo Gallery', 'contributor-photo-gallery' ), 368 label: __( 369 'Contributor Photo Gallery', 370 'contributor-photo-gallery' 371 ), 32 372 instructions: __( 33 373 'Enter a WordPress.org username or numeric user ID to show their photo contributions.', … … 36 376 }, 37 377 el( components.TextControl, { 38 label: __( 'WordPress.org username or user ID', 'contributor-photo-gallery' ), 378 label: __( 379 'WordPress.org username or user ID', 380 'contributor-photo-gallery' 381 ), 39 382 hideLabelFromVision: true, 40 placeholder: __( 'e.g. makarandmane', 'contributor-photo-gallery' ), 383 placeholder: __( 384 'e.g. makarandmane', 385 'contributor-photo-gallery' 386 ), 41 387 value: props.attributes.userId, 42 onChange : function( value ) {388 onChange( value ) { 43 389 props.setAttributes( { userId: value.trim() } ); 44 390 }, … … 48 394 components.ExternalLink, 49 395 { href: props.settingsUrl }, 50 __( 'Or set a default in plugin settings', 'contributor-photo-gallery' ) 396 __( 397 'Or set a default in plugin settings', 398 'contributor-photo-gallery' 399 ) 51 400 ) 52 401 ); … … 54 403 55 404 function Edit( props ) { 56 varattributes = props.attributes;57 varsetAttributes = props.setAttributes;58 varblockProps = blockEditor.useBlockProps();59 60 vareffectiveUserId = attributes.userId || defaultUserId;61 varperPage = attributes.perPage || defaultPerPage;62 varcolumns = attributes.columns || defaultColumns;63 64 varinspector = el(405 const attributes = props.attributes; 406 const setAttributes = props.setAttributes; 407 const blockProps = blockEditor.useBlockProps(); 408 409 const effectiveUserId = attributes.userId || defaultUserId; 410 const perPage = attributes.perPage || defaultPerPage; 411 const columns = attributes.columns || defaultColumns; 412 413 const inspector = el( 65 414 blockEditor.InspectorControls, 66 415 null, 67 416 el( 68 417 components.PanelBody, 69 { title: __( 'Gallery settings', 'contributor-photo-gallery' ), initialOpen: true }, 418 { 419 title: __( 420 'Gallery settings', 421 'contributor-photo-gallery' 422 ), 423 initialOpen: true, 424 }, 70 425 el( components.TextControl, { 71 label: __( 'WordPress.org username or user ID', 'contributor-photo-gallery' ), 426 label: __( 427 'WordPress.org username or user ID', 428 'contributor-photo-gallery' 429 ), 72 430 help: defaultUserId 73 431 ? sprintf( 74 432 /* translators: %s: default user from plugin settings. */ 75 __( 'Leave empty to use the default from settings (%s).', 'contributor-photo-gallery' ), 433 __( 434 'Leave empty to use the default from settings (%s).', 435 'contributor-photo-gallery' 436 ), 76 437 defaultUserId 77 ) 78 : __( 'No default user is set in plugin settings.', 'contributor-photo-gallery' ), 438 ) 439 : __( 440 'No default user is set in plugin settings.', 441 'contributor-photo-gallery' 442 ), 79 443 value: attributes.userId, 80 onChange : function( value ) {444 onChange( value ) { 81 445 setAttributes( { userId: value.trim() } ); 82 446 }, 83 447 } ), 84 448 el( components.RangeControl, { 85 label: __( 'Number of photos', 'contributor-photo-gallery' ), 449 label: __( 450 'Number of photos', 451 'contributor-photo-gallery' 452 ), 86 453 value: perPage, 87 454 min: 1, 88 455 max: 50, 89 onChange : function( value ) {456 onChange( value ) { 90 457 setAttributes( { perPage: value } ); 91 458 }, … … 96 463 min: 1, 97 464 max: 6, 98 onChange : function( value ) {465 onChange( value ) { 99 466 setAttributes( { columns: value } ); 100 467 }, … … 107 474 components.ExternalLink, 108 475 { href: defaults.settingsUrl }, 109 __( 'Card styles and colors', 'contributor-photo-gallery' ) 476 __( 477 'Card styles and colors', 478 'contributor-photo-gallery' 479 ) 110 480 ) 111 481 ) 112 ) 482 ), 483 stylePanels( attributes, setAttributes ) 113 484 ); 114 485 115 varbody = effectiveUserId486 const body = effectiveUserId 116 487 ? el( 117 488 components.Disabled, … … 119 490 el( ServerSideRender, { 120 491 block: props.name, 121 attributes : attributes,492 attributes, 122 493 skipBlockSupportAttributes: true, 123 494 } ) 124 )495 ) 125 496 : el( Placeholder, { 126 attributes : attributes,127 setAttributes : setAttributes,497 attributes, 498 setAttributes, 128 499 settingsUrl: defaults.settingsUrl, 129 } );500 } ); 130 501 131 502 return el( Fragment, null, inspector, el( 'div', blockProps, body ) ); … … 134 505 wp.blocks.registerBlockType( 'contributor-photo-gallery/gallery', { 135 506 edit: Edit, 136 save : function() {507 save() { 137 508 return null; 138 509 }, … … 145 516 userId: { 146 517 type: 'string', 147 shortcode : function( attrs ) {518 shortcode( attrs ) { 148 519 return attrs.named.user_id || ''; 149 520 }, … … 151 522 perPage: { 152 523 type: 'number', 153 shortcode : function( attrs ) {154 varn = parseInt( attrs.named.per_page, 10 );524 shortcode( attrs ) { 525 const n = parseInt( attrs.named.per_page, 10 ); 155 526 return isNaN( n ) ? undefined : n; 156 527 }, … … 158 529 columns: { 159 530 type: 'number', 160 shortcode : function( attrs ) {161 varn = parseInt( attrs.named.columns, 10 );531 shortcode( attrs ) { 532 const n = parseInt( attrs.named.columns, 10 ); 162 533 return isNaN( n ) ? undefined : n; 163 534 }, -
contributor-photo-gallery/trunk/contributor-photo-gallery.php
r3831579 r3831810 4 4 * Plugin URI: https://wordpress.org/plugins/contributor-photo-gallery/ 5 5 * Description: Showcase your contributions to WordPress.org/photos with elegant and responsive photo galleries. 6 * Version: 3. 1.46 * Version: 3.2.0 7 7 * Requires at least: 5.8 8 8 * Requires PHP: 8.0 … … 21 21 } 22 22 23 define( 'CPGLRY_VERSION', '3. 1.4' );23 define( 'CPGLRY_VERSION', '3.2.0' ); 24 24 define( 'CPGLRY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 25 25 define( 'CPGLRY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); -
contributor-photo-gallery/trunk/includes/class-cpglry-block.php
r3831417 r3831810 53 53 'perPage' => (int) $options['default_per_page'], 54 54 'columns' => (int) $options['default_columns'], 55 // The plugin settings each style control falls back to. 56 'styles' => array( 57 'cardStyle' => $options['card_style'], 58 'cardBgColor' => $options['card_bg_color'], 59 'borderStyle' => $options['card_border_style'], 60 'borderWidth' => (int) $options['card_border_width'], 61 'borderColor' => $options['card_border_color'], 62 'shadowStyle' => $options['card_shadow_style'], 63 'showCaptions' => (bool) $options['show_captions'], 64 'captionColor' => $options['caption_text_color'], 65 'captionAlignment' => $options['caption_alignment'], 66 'openInNewTab' => (bool) $options['open_in_new_tab'], 67 'lazyLoading' => (bool) $options['enable_lazy_loading'], 68 ), 55 69 'settingsUrl' => current_user_can( 'manage_options' ) ? admin_url( 'admin.php?page=contributor-photo-gallery' ) : '', 56 70 ) … … 104 118 } 105 119 106 $html = CPGLRY_Frontend::render_shortcode( $atts ); 120 // Styling set on this block; anything left empty uses the plugin settings. 121 $overrides = array(); 122 foreach ( cpglry_style_override_keys() as $attribute => $option ) { 123 if ( isset( $attributes[ $attribute ] ) ) { 124 $overrides[ $option ] = $attributes[ $attribute ]; 125 } 126 } 127 128 $html = CPGLRY_Frontend::render_shortcode( $atts, $overrides ); 107 129 108 130 return sprintf( '<div %1$s>%2$s</div>', $this->wrapper_attributes(), $html ); -
contributor-photo-gallery/trunk/includes/class-cpglry-frontend.php
r3831417 r3831810 69 69 * Renders the gallery using templates/grid.php which expects $cpglry_photos and $cpglry_options. 70 70 * 71 * @param array $atts Shortcode attributes. 71 * @param array $atts Shortcode attributes. 72 * @param array $overrides Styling options for this gallery only (option key => value), 73 * such as the block's card style; unset keys use the saved settings. 72 74 * @return string 73 75 */ 74 public static function render_shortcode( $atts = array() ) {75 $cpglry_options = cpglry_get_plugin_options();76 public static function render_shortcode( $atts = array(), $overrides = array() ) { 77 $cpglry_options = array_merge( cpglry_get_plugin_options(), cpglry_sanitize_style_overrides( $overrides ) ); 76 78 77 79 // Shortcode attrs override options. -
contributor-photo-gallery/trunk/includes/helpers.php
r3831417 r3831810 63 63 } 64 64 } 65 66 67 /** 68 * Block attributes that can override a styling option for one gallery, mapped 69 * to the option they override. 70 * 71 * @return array Block attribute name => option key. 72 */ 73 function cpglry_style_override_keys() { 74 return array( 75 'cardStyle' => 'card_style', 76 'cardBgColor' => 'card_bg_color', 77 'borderStyle' => 'card_border_style', 78 'borderWidth' => 'card_border_width', 79 'borderColor' => 'card_border_color', 80 'shadowStyle' => 'card_shadow_style', 81 'showCaptions' => 'show_captions', 82 'captionColor' => 'caption_text_color', 83 'captionAlignment' => 'caption_alignment', 84 'openInNewTab' => 'open_in_new_tab', 85 'lazyLoading' => 'enable_lazy_loading', 86 ); 87 } 88 89 /** 90 * Sanitizes styling overrides for one gallery. Only keys that are set and 91 * valid are returned, so everything else keeps the saved setting. 92 * 93 * @param array $overrides Option key => raw value. 94 * @return array Option key => sanitized value. 95 */ 96 function cpglry_sanitize_style_overrides( $overrides ) { 97 $choices = array( 98 'card_style' => array( 'default', 'polaroid', 'circle', 'fixed' ), 99 'card_border_style' => array( 'none', 'solid', 'dashed', 'dotted' ), 100 'card_shadow_style' => array( 'none', 'subtle', 'medium', 'strong' ), 101 'caption_alignment' => array( 'left', 'center', 'right' ), 102 ); 103 $colors = array( 'card_bg_color', 'card_border_color', 'caption_text_color' ); 104 $toggles = array( 'show_captions', 'open_in_new_tab', 'enable_lazy_loading' ); 105 $clean = array(); 106 107 foreach ( (array) $overrides as $key => $value ) { 108 if ( null === $value || '' === $value ) { 109 continue; 110 } 111 if ( isset( $choices[ $key ] ) ) { 112 if ( in_array( $value, $choices[ $key ], true ) ) { 113 $clean[ $key ] = $value; 114 } 115 } elseif ( in_array( $key, $colors, true ) ) { 116 $color = sanitize_hex_color( $value ); 117 if ( $color ) { 118 $clean[ $key ] = $color; 119 } 120 } elseif ( in_array( $key, $toggles, true ) ) { 121 $clean[ $key ] = $value ? 1 : 0; 122 } elseif ( 'card_border_width' === $key && is_numeric( $value ) ) { 123 $clean[ $key ] = max( 0, min( 10, absint( $value ) ) ); 124 } 125 } 126 127 return $clean; 128 } -
contributor-photo-gallery/trunk/readme.txt
r3831579 r3831810 5 5 Requires at least: 5.8 6 6 Tested up to: 7.1 7 Stable tag: 3. 1.47 Stable tag: 3.2.0 8 8 Requires PHP: 8.0 9 9 License: GPLv3 … … 17 17 18 18 Your photos stay hosted on WordPress.org and link back to it, and the gallery picks up new photos as you publish them. 19 20 ### New in 3.2 21 22 * **Style each block on its own.** The block sidebar now has the same styling as the settings screen: card style, background, border, shadow, captions (show or hide, color, alignment), new-tab links and lazy-loading. Anything you leave alone uses the plugin settings. 19 23 20 24 ### New in 3.1 … … 45 49 ### Add a gallery 46 50 47 **Block:** add **Contributor Photo Gallery** from the Media category. The sidebar sets the WordPress.org user, number of photos (1 to 50) and columns (1 to 6); leave the user empty to use your saved settings. Card styles and colors come from the settings screen, so blocks and shortcodes always match. Existing shortcode blocks can be turned into the block with **Transform to**.51 **Block:** add **Contributor Photo Gallery** from the Media category. The sidebar sets the WordPress.org user, number of photos (1 to 50) and columns (1 to 6); leave the user empty to use your saved settings. The **Cards**, **Captions**, and **Links and loading** panels style this block only; each option starts on the plugin setting, and **Reset to plugin settings** puts a panel back. Existing shortcode blocks can be turned into the block with **Transform to**. 48 52 49 53 **Shortcode:** `[cp_gallery]` uses your saved settings. Attributes change a single gallery: … … 114 118 == Changelog == 115 119 120 = 3.2.0 - 2026-11-28 = 121 122 * New: Card style, background, border, shadow, captions, new-tab links and lazy-loading can be set per block; anything left alone uses the plugin settings. 123 * Fixed: The Lazy-load images setting is now respected; images were always lazy-loaded. 124 116 125 = 3.1.4 - 2026-11-28 = 117 126 … … 182 191 == Upgrade Notice == 183 192 193 = 3.2.0 = 194 Style each gallery block on its own: card style, colors, border, shadow, captions, links and lazy-loading. Existing blocks keep using your plugin settings. 195 184 196 = 3.1.3 = 185 197 3.1 brings a guided setup, a redesigned settings screen with a live preview, caption alignment, and the gallery block from 3.0. Your settings carry over. -
contributor-photo-gallery/trunk/templates/grid.php
r3831417 r3831810 137 137 $cpglry_open_in_new = isset( $cpglry_options['open_in_new_tab'] ) ? (bool) $cpglry_options['open_in_new_tab'] : true; 138 138 $cpglry_target = $cpglry_open_in_new ? '_blank' : ''; 139 $cpglry_lazy = isset( $cpglry_options['enable_lazy_loading'] ) ? (bool) $cpglry_options['enable_lazy_loading'] : true; 139 140 // include noreferrer as recommended when opening new tab 140 141 $cpglry_rel = $cpglry_open_in_new ? 'noopener noreferrer' : ''; … … 142 143 echo '<div class="cpg-photo-card cpg-style-' . esc_attr( $cpglry_card_style ) . '">'; 143 144 echo '<a href="' . esc_url( $cpglry_link ) . '"' . ( $cpglry_target ? ' target="' . esc_attr( $cpglry_target ) . '"' : '' ) . ( $cpglry_rel ? ' rel="' . esc_attr( $cpglry_rel ) . '"' : '' ) . '>'; 144 echo '<div class="cpg-photo-image"><img src="' . esc_url( $cpglry_image_url ) . '" alt="' . esc_attr( $cpglry_title ) . '" loading="lazy"></div>';145 echo '<div class="cpg-photo-image"><img src="' . esc_url( $cpglry_image_url ) . '" alt="' . esc_attr( $cpglry_title ) . '"' . ( $cpglry_lazy ? ' loading="lazy"' : '' ) . '></div>'; 145 146 146 147 if ( $cpglry_show_captions && ! empty( $cpglry_title ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.