際際滷

際際滷Share a Scribd company logo
Guida pratica al primo
approccio con Gutenberg per
programmatori PHP
#WCMIL - 17NOV2018
@dottxado #WCMIL 2018
Erika Gili
Ingegnere energetico
Fullstack web developer
Motociclista
Ex bassista
Ex atleta agonista di karate
Nata a Terni, abitato a
Perugia, Genova, Genzano di
Roma, Roma, ora a Bassano
del Grappa
@dottxado #WCMIL 2018
La tua opinione conta!
bit.ly/wcmil-blocchi-erika
bit.ly/wcmil-blocks-erika
@dottxado #WCMIL 2018
Obiettivi
Avvicinarvi allo sviluppo di estensioni Gutenberg
tramite esempio pratico
+Fornire fonti di documentazione
Portarvi suggerimenti che sono frutto dellesperienza
maturata su 3 progetti in produzione
@dottxado #WCMIL 2018
Fonti
Codice: https://github.com/WordPress/gutenberg
Changelog: https://make.wordpress.org/core/tag/gutenberg
Documentazione: https://wordpress.org/gutenberg/handbook
Scaffold di codice
https://developer.wordpress.org/cli/commands/scaffold/block
https://github.com/ahmadawais/create-guten-block
Seguire gli sviluppatori su Twitter o sui
loro blog, studiare i plugin nel repo
ufficiale
@dottxado #WCMIL 2018
Ed oracodice
 WP CLI per lo scaffold
 Plugin
 4 blocchi:
1 blocco statico (contenuto 鍖sso)
2 blocchi editabili innestati (contenuto modi鍖cabile)
1 blocco dinamico (fornito dal server)
https://github.com/dottxado/wcmil-2018-example
@dottxado #WCMIL 2018
Scaffold
$ wp scaffold plugin wcmil-2018-example
$ wp scaffold block block-01 -plugin=wcmil-2018-example
$ wp scaffold block block-02 -plugin=wcmil-2018-example
$ wp scaffold block block-03 -plugin=wcmil-2018-example
$ wp scaffold block block-04 -plugin=wcmil-2018-example
Assegno ad ogni blocco un codice numerico
@dottxado #WCMIL 2018
Files
Inserire i necessari require_once nel file
iniziale del plugin
@dottxado #WCMIL 2018
Blocco statico 01 / PHP
add_action( 'init', 'block_01_block_init' );
function block_01_block_init() {
wp_register_script(
'block-01-block-editor',
[...]
);
wp_register_style(
'block-01-block-editor',
[...]
);
wp_register_style(
'block-01-block',
[...]
);
register_block_type(
'wcmil-2018-example/block-01',
array(
'editor_script' => 'block-01-block-editor',
'editor_style' => 'block-01-block-editor',
'style' => 'block-01-block',
)
);
}
Attenzione a dipendenze ed
inclusione nel footer
@dottxado #WCMIL 2018
Blocco statico 01 / JS
var registerBlockType = wp.blocks.registerBlockType;
var el = wp.element.createElement;
registerBlockType('wcmil-2018-example/block-01', {
title: __('Block 01'),
category: 'widgets',
supports: {
html: false,
},
edit: function (props) {},
save: function () {}
});
//wordpress.org/gutenberg/handbook/block-api/
@dottxado #WCMIL 2018
Blocco statico 01 / JS
edit: function (props) {
return el(
'p',
{className: props.className},
__('Hello from the editor!')
);
},
save: function () {
return el(
'p',
{},
__('Hello from the saved content!')
);
}
Durante lo sviluppo, usa console.log
allinizio di ciascun metodo
Eseguito ad OGNI
modifica del
blocco
Eseguito al
caricamento o al
salvataggio
delleditor
@dottxado #WCMIL 2018
Editor
Frontend
Database
@dottxado #WCMIL 2018
Blocco editabile 03 / JS
registerBlockType( 'wcmil-2018-example/block-03', {
[]
attributes: {
id: {
type: 'number',
},
url: {
type: 'url',
},
description: {
source: 'children',
selector: 'p',
}
},
[]
}
//wordpress.org/gutenberg/handbook/block-api/
attributes/
@dottxado #WCMIL 2018
Blocco editabile 03 / JS
edit: function( props ) {
var url = props.attributes.url;
var id = props.attributes.id;
var description = props.attributes.description;
return el(
'div',
{
className: [props.className, 'column'].join(' ')
},
el(
MediaUpload, {[...options...]}
),
el(
RichText, {
tagName: 'p',
value: description,
onChange: function (newValue) {
props.setAttributes({description: newValue});
},
placeholder: __('Inserisci la descrizione'),
keepPlaceholderOnFocus: true,
}
),
);
},
Accedo agli
attributi
Componenti
//github.com/WordPress/gutenberg/tree/master/
packages/editor/src/components
@dottxado #WCMIL 2018
Blocco editabile 03 / JS
save: function(props) {
return el(
'div',
{
className: 'column'
},
el(
'img', {
src: props.attributes.url,
}
),
props.attributes.description.length > 0 && el(
RichText.Content, {
tagName: 'p',
value: props.attributes.description,
}
),
);
}
Sempre controllare la presenza del contenuto
al momento del salvataggio
@dottxado #WCMIL 2018
Blocco editabile 03 / JS
parent: ['wcmil-2018-example/block-02'],
Non 竪 possibile trovarlo nellinserter perch辿 竪 disponibile solo
per il blocco parent block-02, il quale deve essere in grado di
includerlo tramite il componente InnerBlocks
@dottxado #WCMIL 2018
Blocco editabile 02 / JS
registerBlockType('wcmil-2018-example/block-02', {
[]
attributes: {
title: {
source: 'children',
selector: 'h2',
},
hasSeparator: {
type: 'bool',
default: false,
},
numberOfColumns: {
type: 'number',
default: 2,
},
},
[]
}
@dottxado #WCMIL 2018
Blocco editabile 02 / JSedit: function (props) {
return [
el(
InspectorControls, {key: 'inspector'},
el(
PanelBody, {
title: __('Informazioni Aggiuntive'),
initialOpen: true
},
el(
ToggleControl, {
label: __('Aggiungi linea di separazione tra titolo e contenuto'),
checked: props.attributes.hasSeparator,
onChange: function () {
props.setAttributes({hasSeparator: !props.attributes.hasSeparator});
}
}
),
el(
RangeControl, {
label: __('Quante colonne vuoi mostrare?'),
initialPosition: props.attributes.numberOfColumns.default,
value: props.attributes.numberOfColumns,
min: 1,
max: 6,
onChange: function (newValue) {
props.setAttributes({numberOfColumns: newValue});
}
}
),
),
),
Array con due
elementi:
Inspector e
corpo del blocco
@dottxado #WCMIL 2018
Blocco editabile 02 / JS
@dottxado #WCMIL 2018
Blocco editabile 02 / JSel(
'div',
{className: props.className},
el(
RichText, {
tagName: 'h2',
value: props.attributes.title,
onChange: function (newValue) {
props.setAttributes({title: newValue});
},
placeholder: __('Inserisci il titolo'),
keepPlaceholderOnFocus: true,
formattingControls: [],
}
),
props.attributes.hasSeparator && el(
'hr', {}
),
el(
'div', {
className: ['container', 'columns-' + props.attributes.numberOfColumns].join(' '),
},
el(
InnerBlocks,
{
template: getEditTemplate(props.attributes.numberOfColumns),
templateLock: "all",
allowedBlocks: ['wcmil-2018-example/block-03']
}
),
),
)
Inserimento
dellelemento tramite
condizione
@dottxado #WCMIL 2018
Blocco editabile 02 / JS
save: function (props) {
return el(
'div',
{className: props.className},
el(
RichText.Content, {
tagName: 'h2',
value: props.attributes.title,
}
),
props.attributes.hasSeparator && el(
'hr', {}
),
el(
'div', {
className: ['container', 'columns-' + props.attributes.numberOfColumns].join(' '),
},
el(
InnerBlocks.Content,
{}
),
),
);
}
@dottxado #WCMIL 2018
Editor
@dottxado #WCMIL 2018
Frontend
Database
@dottxado #WCMIL 2018
Blocco dinamico 04 / PHP
register_block_type(
'wcmil-2018-example/block-04',
array(
'editor_script' => 'block-04-block-editor',
'editor_style' => 'block-04-block-editor',
'style' => 'block-04-block',
'render_callback' => 'block_04_render',
)
);
function block_04_render( $attrs ) {
if ( ! isset( $attrs['min'] ) ) {
$attrs['min'] = 2;
}
if ( ! isset( $attrs['max'] ) ) {
$attrs['max'] = 100;
}
$html = '<div class="wp-block-wcmil-2018-example-block-04">';
$html .= '<p>Ora ci sono</p>';
$html .= '<p class="bigger">' . wp_rand( $attrs['min'], $attrs['max'] ) . '</p>';
$html .= '<p>utenti attivi</p>';
$html .= '</div>';
return $html;
}
Uso la classe css
standard
@dottxado #WCMIL 2018
Blocco dinamico 04 / JS
registerBlockType( 'wcmil-2018-example/block-04', {
attributes: {
min: {
type: 'number',
default: 2,
},
max: {
type: 'number',
default: 100,
}
},
}
@dottxado #WCMIL 2018
Blocco dinamico 04 / JS
edit: function( props ) {
return [
el(
InspectorControls, {key: 'inspector'},
el(
PanelBody, {
title: __('Informazioni Aggiuntive'),
initialOpen: true
},
el(
RangeControl, {
label: __('Numero minimo di utenti'),
initialPosition: props.attributes.min.default,
value: props.attributes.min,
min: 2,
max: 100,
onChange: function (newValue) {
props.setAttributes({min: newValue});
}
}
),
el(
RangeControl, {
label: __('Numero massimo di utenti'),
[] }
),
),
),
el(
'p',
{ className: props.className },
__( 'Questo blocco mostrer il numero di utenti attivi sul sito.' )
)];
},
Vedi ServerSideRender
@dottxado #WCMIL 2018
Blocco dinamico 04 / JS
@dottxado #WCMIL 2018
Blocco dinamico 04 / JS
save: function() {
return null;
}
Non c竪 HTML da salvare!
@dottxado #WCMIL 2018
Editor
Frontend
Nelleditor evidenzio i blocchi
dinamici con CSS ad hoc
@dottxado #WCMIL 2018
Database
@dottxado #WCMIL 2018
E cosaltro?
Post Meta
State & Components
Modifica dei blocchi core
Transforms
Deprecated
Styles
Rest
Categorie custom
Nuovi hook
Whitelist dei blocchi
Errori di validazione
Template
Blocchi assegnati ai post type
@dottxado #WCMIL 2018
Grazie!
domande?
https://github.com/dottxado/wcmil-2018-example
bit.ly/wcmil-blocchi-erika
bit.ly/wcmil-blocks-erika

More Related Content

Similar to Wcmil2018 (20)

Js intro
Js introJs intro
Js intro
Daniele Cruciani
Closure Visto Da Vicino
Closure Visto Da VicinoClosure Visto Da Vicino
Closure Visto Da Vicino
davide ficano
JavaScript
JavaScriptJavaScript
JavaScript
Manuel Scapolan
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
Alberto Buschettu
E suap - tecnologie client
E suap - tecnologie client E suap - tecnologie client
E suap - tecnologie client
Sabino Labarile
Html5 e css3 nuovi strumenti per un nuovo web
Html5 e css3 nuovi strumenti per un nuovo webHtml5 e css3 nuovi strumenti per un nuovo web
Html5 e css3 nuovi strumenti per un nuovo web
Massimo Bonanni
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftAsp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Stefano Benedetti
HTML e CSS
HTML e CSSHTML e CSS
HTML e CSS
Manuel Scapolan
Session 02 - schema design e architettura
Session 02 - schema design e architetturaSession 02 - schema design e architettura
Session 02 - schema design e architettura
MongoDB
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuery
Sandro Marcon
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the Web
Claudio Gandelli
XPages Tips & Tricks, #dd13
XPages Tips & Tricks, #dd13XPages Tips & Tricks, #dd13
XPages Tips & Tricks, #dd13
Dominopoint - Italian Lotus User Group
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
Alessandro Martin
Presentazione wicket
Presentazione wicketPresentazione wicket
Presentazione wicket
Andrea Del Bene
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript
Stefano Marchisio
Javascript Camp - Listener Per Eventi
Javascript Camp - Listener Per EventiJavascript Camp - Listener Per Eventi
Javascript Camp - Listener Per Eventi
Simone Gentili
jQuery - 1 | WebMaster & WebDesigner
jQuery - 1 | WebMaster & WebDesignerjQuery - 1 | WebMaster & WebDesigner
jQuery - 1 | WebMaster & WebDesigner
Matteo Magni
Sviluppo dei blocchi di Gutenberg per programmatori senza tempo
Sviluppo dei blocchi di Gutenberg per programmatori senza tempoSviluppo dei blocchi di Gutenberg per programmatori senza tempo
Sviluppo dei blocchi di Gutenberg per programmatori senza tempo
Mauricio Gelves
Pycon Jungle
Pycon JunglePycon Jungle
Pycon Jungle
guest6b08a5
Training Signal Webtrends
Training Signal WebtrendsTraining Signal Webtrends
Training Signal Webtrends
Stefano Iaboni
Closure Visto Da Vicino
Closure Visto Da VicinoClosure Visto Da Vicino
Closure Visto Da Vicino
davide ficano
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
Alberto Buschettu
E suap - tecnologie client
E suap - tecnologie client E suap - tecnologie client
E suap - tecnologie client
Sabino Labarile
Html5 e css3 nuovi strumenti per un nuovo web
Html5 e css3 nuovi strumenti per un nuovo webHtml5 e css3 nuovi strumenti per un nuovo web
Html5 e css3 nuovi strumenti per un nuovo web
Massimo Bonanni
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftAsp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Stefano Benedetti
Session 02 - schema design e architettura
Session 02 - schema design e architetturaSession 02 - schema design e architettura
Session 02 - schema design e architettura
MongoDB
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuery
Sandro Marcon
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the Web
Claudio Gandelli
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
Alessandro Martin
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript
Stefano Marchisio
Javascript Camp - Listener Per Eventi
Javascript Camp - Listener Per EventiJavascript Camp - Listener Per Eventi
Javascript Camp - Listener Per Eventi
Simone Gentili
jQuery - 1 | WebMaster & WebDesigner
jQuery - 1 | WebMaster & WebDesignerjQuery - 1 | WebMaster & WebDesigner
jQuery - 1 | WebMaster & WebDesigner
Matteo Magni
Sviluppo dei blocchi di Gutenberg per programmatori senza tempo
Sviluppo dei blocchi di Gutenberg per programmatori senza tempoSviluppo dei blocchi di Gutenberg per programmatori senza tempo
Sviluppo dei blocchi di Gutenberg per programmatori senza tempo
Mauricio Gelves
Training Signal Webtrends
Training Signal WebtrendsTraining Signal Webtrends
Training Signal Webtrends
Stefano Iaboni

Wcmil2018

  • 1. Guida pratica al primo approccio con Gutenberg per programmatori PHP #WCMIL - 17NOV2018
  • 2. @dottxado #WCMIL 2018 Erika Gili Ingegnere energetico Fullstack web developer Motociclista Ex bassista Ex atleta agonista di karate Nata a Terni, abitato a Perugia, Genova, Genzano di Roma, Roma, ora a Bassano del Grappa
  • 3. @dottxado #WCMIL 2018 La tua opinione conta! bit.ly/wcmil-blocchi-erika bit.ly/wcmil-blocks-erika
  • 4. @dottxado #WCMIL 2018 Obiettivi Avvicinarvi allo sviluppo di estensioni Gutenberg tramite esempio pratico +Fornire fonti di documentazione Portarvi suggerimenti che sono frutto dellesperienza maturata su 3 progetti in produzione
  • 5. @dottxado #WCMIL 2018 Fonti Codice: https://github.com/WordPress/gutenberg Changelog: https://make.wordpress.org/core/tag/gutenberg Documentazione: https://wordpress.org/gutenberg/handbook Scaffold di codice https://developer.wordpress.org/cli/commands/scaffold/block https://github.com/ahmadawais/create-guten-block Seguire gli sviluppatori su Twitter o sui loro blog, studiare i plugin nel repo ufficiale
  • 6. @dottxado #WCMIL 2018 Ed oracodice WP CLI per lo scaffold Plugin 4 blocchi: 1 blocco statico (contenuto 鍖sso) 2 blocchi editabili innestati (contenuto modi鍖cabile) 1 blocco dinamico (fornito dal server) https://github.com/dottxado/wcmil-2018-example
  • 7. @dottxado #WCMIL 2018 Scaffold $ wp scaffold plugin wcmil-2018-example $ wp scaffold block block-01 -plugin=wcmil-2018-example $ wp scaffold block block-02 -plugin=wcmil-2018-example $ wp scaffold block block-03 -plugin=wcmil-2018-example $ wp scaffold block block-04 -plugin=wcmil-2018-example Assegno ad ogni blocco un codice numerico
  • 8. @dottxado #WCMIL 2018 Files Inserire i necessari require_once nel file iniziale del plugin
  • 9. @dottxado #WCMIL 2018 Blocco statico 01 / PHP add_action( 'init', 'block_01_block_init' ); function block_01_block_init() { wp_register_script( 'block-01-block-editor', [...] ); wp_register_style( 'block-01-block-editor', [...] ); wp_register_style( 'block-01-block', [...] ); register_block_type( 'wcmil-2018-example/block-01', array( 'editor_script' => 'block-01-block-editor', 'editor_style' => 'block-01-block-editor', 'style' => 'block-01-block', ) ); } Attenzione a dipendenze ed inclusione nel footer
  • 10. @dottxado #WCMIL 2018 Blocco statico 01 / JS var registerBlockType = wp.blocks.registerBlockType; var el = wp.element.createElement; registerBlockType('wcmil-2018-example/block-01', { title: __('Block 01'), category: 'widgets', supports: { html: false, }, edit: function (props) {}, save: function () {} }); //wordpress.org/gutenberg/handbook/block-api/
  • 11. @dottxado #WCMIL 2018 Blocco statico 01 / JS edit: function (props) { return el( 'p', {className: props.className}, __('Hello from the editor!') ); }, save: function () { return el( 'p', {}, __('Hello from the saved content!') ); } Durante lo sviluppo, usa console.log allinizio di ciascun metodo Eseguito ad OGNI modifica del blocco Eseguito al caricamento o al salvataggio delleditor
  • 13. @dottxado #WCMIL 2018 Blocco editabile 03 / JS registerBlockType( 'wcmil-2018-example/block-03', { [] attributes: { id: { type: 'number', }, url: { type: 'url', }, description: { source: 'children', selector: 'p', } }, [] } //wordpress.org/gutenberg/handbook/block-api/ attributes/
  • 14. @dottxado #WCMIL 2018 Blocco editabile 03 / JS edit: function( props ) { var url = props.attributes.url; var id = props.attributes.id; var description = props.attributes.description; return el( 'div', { className: [props.className, 'column'].join(' ') }, el( MediaUpload, {[...options...]} ), el( RichText, { tagName: 'p', value: description, onChange: function (newValue) { props.setAttributes({description: newValue}); }, placeholder: __('Inserisci la descrizione'), keepPlaceholderOnFocus: true, } ), ); }, Accedo agli attributi Componenti //github.com/WordPress/gutenberg/tree/master/ packages/editor/src/components
  • 15. @dottxado #WCMIL 2018 Blocco editabile 03 / JS save: function(props) { return el( 'div', { className: 'column' }, el( 'img', { src: props.attributes.url, } ), props.attributes.description.length > 0 && el( RichText.Content, { tagName: 'p', value: props.attributes.description, } ), ); } Sempre controllare la presenza del contenuto al momento del salvataggio
  • 16. @dottxado #WCMIL 2018 Blocco editabile 03 / JS parent: ['wcmil-2018-example/block-02'], Non 竪 possibile trovarlo nellinserter perch辿 竪 disponibile solo per il blocco parent block-02, il quale deve essere in grado di includerlo tramite il componente InnerBlocks
  • 17. @dottxado #WCMIL 2018 Blocco editabile 02 / JS registerBlockType('wcmil-2018-example/block-02', { [] attributes: { title: { source: 'children', selector: 'h2', }, hasSeparator: { type: 'bool', default: false, }, numberOfColumns: { type: 'number', default: 2, }, }, [] }
  • 18. @dottxado #WCMIL 2018 Blocco editabile 02 / JSedit: function (props) { return [ el( InspectorControls, {key: 'inspector'}, el( PanelBody, { title: __('Informazioni Aggiuntive'), initialOpen: true }, el( ToggleControl, { label: __('Aggiungi linea di separazione tra titolo e contenuto'), checked: props.attributes.hasSeparator, onChange: function () { props.setAttributes({hasSeparator: !props.attributes.hasSeparator}); } } ), el( RangeControl, { label: __('Quante colonne vuoi mostrare?'), initialPosition: props.attributes.numberOfColumns.default, value: props.attributes.numberOfColumns, min: 1, max: 6, onChange: function (newValue) { props.setAttributes({numberOfColumns: newValue}); } } ), ), ), Array con due elementi: Inspector e corpo del blocco
  • 19. @dottxado #WCMIL 2018 Blocco editabile 02 / JS
  • 20. @dottxado #WCMIL 2018 Blocco editabile 02 / JSel( 'div', {className: props.className}, el( RichText, { tagName: 'h2', value: props.attributes.title, onChange: function (newValue) { props.setAttributes({title: newValue}); }, placeholder: __('Inserisci il titolo'), keepPlaceholderOnFocus: true, formattingControls: [], } ), props.attributes.hasSeparator && el( 'hr', {} ), el( 'div', { className: ['container', 'columns-' + props.attributes.numberOfColumns].join(' '), }, el( InnerBlocks, { template: getEditTemplate(props.attributes.numberOfColumns), templateLock: "all", allowedBlocks: ['wcmil-2018-example/block-03'] } ), ), ) Inserimento dellelemento tramite condizione
  • 21. @dottxado #WCMIL 2018 Blocco editabile 02 / JS save: function (props) { return el( 'div', {className: props.className}, el( RichText.Content, { tagName: 'h2', value: props.attributes.title, } ), props.attributes.hasSeparator && el( 'hr', {} ), el( 'div', { className: ['container', 'columns-' + props.attributes.numberOfColumns].join(' '), }, el( InnerBlocks.Content, {} ), ), ); }
  • 24. @dottxado #WCMIL 2018 Blocco dinamico 04 / PHP register_block_type( 'wcmil-2018-example/block-04', array( 'editor_script' => 'block-04-block-editor', 'editor_style' => 'block-04-block-editor', 'style' => 'block-04-block', 'render_callback' => 'block_04_render', ) ); function block_04_render( $attrs ) { if ( ! isset( $attrs['min'] ) ) { $attrs['min'] = 2; } if ( ! isset( $attrs['max'] ) ) { $attrs['max'] = 100; } $html = '<div class="wp-block-wcmil-2018-example-block-04">'; $html .= '<p>Ora ci sono</p>'; $html .= '<p class="bigger">' . wp_rand( $attrs['min'], $attrs['max'] ) . '</p>'; $html .= '<p>utenti attivi</p>'; $html .= '</div>'; return $html; } Uso la classe css standard
  • 25. @dottxado #WCMIL 2018 Blocco dinamico 04 / JS registerBlockType( 'wcmil-2018-example/block-04', { attributes: { min: { type: 'number', default: 2, }, max: { type: 'number', default: 100, } }, }
  • 26. @dottxado #WCMIL 2018 Blocco dinamico 04 / JS edit: function( props ) { return [ el( InspectorControls, {key: 'inspector'}, el( PanelBody, { title: __('Informazioni Aggiuntive'), initialOpen: true }, el( RangeControl, { label: __('Numero minimo di utenti'), initialPosition: props.attributes.min.default, value: props.attributes.min, min: 2, max: 100, onChange: function (newValue) { props.setAttributes({min: newValue}); } } ), el( RangeControl, { label: __('Numero massimo di utenti'), [] } ), ), ), el( 'p', { className: props.className }, __( 'Questo blocco mostrer il numero di utenti attivi sul sito.' ) )]; }, Vedi ServerSideRender
  • 27. @dottxado #WCMIL 2018 Blocco dinamico 04 / JS
  • 28. @dottxado #WCMIL 2018 Blocco dinamico 04 / JS save: function() { return null; } Non c竪 HTML da salvare!
  • 29. @dottxado #WCMIL 2018 Editor Frontend Nelleditor evidenzio i blocchi dinamici con CSS ad hoc
  • 31. @dottxado #WCMIL 2018 E cosaltro? Post Meta State & Components Modifica dei blocchi core Transforms Deprecated Styles Rest Categorie custom Nuovi hook Whitelist dei blocchi Errori di validazione Template Blocchi assegnati ai post type