|
| 1 | +/** |
| 2 | + * BLOCK: page-views-count |
| 3 | + * |
| 4 | + * Registering a basic block with Gutenberg. |
| 5 | + * Simple block, renders and saves the same content without any interactivity. |
| 6 | + */ |
| 7 | + |
| 8 | +// Import CSS. |
| 9 | +//import './style.scss'; |
| 10 | +//import './editor.scss'; |
| 11 | + |
| 12 | +const { __ } = wp.i18n; // Import __() from wp.i18n |
| 13 | +const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks |
| 14 | + |
| 15 | +/** |
| 16 | + * Register: aa Gutenberg Block. |
| 17 | + * |
| 18 | + * Registers a new block provided a unique name and an object defining its |
| 19 | + * behavior. Once registered, the block is made editor as an option to any |
| 20 | + * editor interface where blocks are implemented. |
| 21 | + * |
| 22 | + * @link https://wordpress.org/gutenberg/handbook/block-api/ |
| 23 | + * @param {string} name Block name. |
| 24 | + * @param {Object} settings Block settings. |
| 25 | + * @return {?WPBlock} The block, if it has been successfully |
| 26 | + * registered; otherwise `undefined`. |
| 27 | + */ |
| 28 | +registerBlockType('page-views-count/stats-editor', { |
| 29 | + // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
| 30 | + title: __('Page Views', 'page-views-count'), // Block title. |
| 31 | + |
| 32 | + attributes: { |
| 33 | + align: { |
| 34 | + type: 'string', |
| 35 | + }, |
| 36 | + postID: { |
| 37 | + type: 'string', |
| 38 | + }, |
| 39 | + isDisabled: { |
| 40 | + type: 'boolean', |
| 41 | + default: true, |
| 42 | + }, |
| 43 | + /** |
| 44 | + * For previewing? |
| 45 | + */ |
| 46 | + isPreview: { |
| 47 | + type: 'boolean', |
| 48 | + default: false, |
| 49 | + }, |
| 50 | + }, |
| 51 | + |
| 52 | + /** |
| 53 | + * The edit function describes the structure of your block in the context of the editor. |
| 54 | + * This represents what the editor will render when the block is used. |
| 55 | + * |
| 56 | + * The "edit" property must be a valid function. |
| 57 | + * |
| 58 | + * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ |
| 59 | + */ |
| 60 | + edit: ({ attributes, setAttributes }) => { |
| 61 | + |
| 62 | + // Rendering in PHP |
| 63 | + return null; |
| 64 | + }, |
| 65 | + |
| 66 | + /** |
| 67 | + * The save function defines the way in which the different attributes should be combined |
| 68 | + * into the final markup, which is then serialized by Gutenberg into post_content. |
| 69 | + * |
| 70 | + * The "save" property must be specified and must be a valid function. |
| 71 | + * |
| 72 | + * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ |
| 73 | + */ |
| 74 | + save() { |
| 75 | + // Rendering in PHP |
| 76 | + return null; |
| 77 | + }, |
| 78 | +}); |
0 commit comments