-
-
Save MonteLogic/1cc795c558e9d28c8bfd28e154dfb21a to your computer and use it in GitHub Desktop.
Revisions
-
MonteLogic revised this gist
Sep 16, 2022 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,11 @@ This gist is related to a project. Where it is scaffolded as a dynamic block using the following script: "npx @wordpress/create-block mol-custom-block --variant=dynamic" https://www.twitch.tv/videos/1591609219?t=01h02m40s -
MonteLogic revised this gist
Sep 16, 2022 . 2 changed files with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ This gist is related to a project. Where it is scaffolded as a dynamic block using the following script: "npx @wordpress/create-block mol-custom-block --variant=dynamic" Empty file. -
ryanwelcher revised this gist
Sep 15, 2022 . 6 changed files with 85 additions and 88 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,19 +9,14 @@ "description": "A Gutenberg block to show your pride! This block enables you to type text and style it with the color font Gilbert from Type with Pride.", "attributes": { "message": { "type": "string" }, "time": { "type": "string" }, "hasCreated": { "type": "string", "default":false } }, "supports": { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,53 +30,26 @@ import { Card, CardBody } from '@wordpress/components'; import { useEffect } from '@wordpress/element'; export default function Edit( { attributes: { hasCreated, time}, setAttributes } ) { const blockProps = useBlockProps(); useEffect(() => { if ( !hasCreated ){ const d = new Date(); setAttributes( { hasCreated: 1, time: d.toString()} ) } // setAttributes( { hasCreated: hasCreated =+ 1} ); }, []); return ( <div { ...blockProps }> <Card> <CardBody value={time}><b>New Day:</b> {time} </CardBody> </Card> </div> ); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ /** * Registers a new block provided a unique name and an object defining its behavior. * * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ */ import { registerBlockType } from '@wordpress/blocks'; /** * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. * All files containing `style` keyword are bundled together. The code used * gets applied both to the front of your site and to the editor. * * @see https://www.npmjs.com/package/@wordpress/scripts#using-css */ import './style.scss'; /** * Internal dependencies */ import Edit from './edit'; import metadata from './block.json'; /** * Every block starts by registering a new block type definition. * * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ */ registerBlockType( metadata.name, { /** * @see ./edit.js */ edit: Edit, } ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ function create_block_acf_expert_block_init() { register_block_type( __DIR__ . '/build', array( 'render_callback' => 'create_block_acf_expert_render_callback', ) ); } add_action( 'init', 'create_block_acf_expert_block_init' ); /** * Render callback function. * * @param array $attributes The block attributes. * @param string $content The block content. * @param WP_Block $block Block instance. * * @return string The rendered output. */ function create_block_acf_expert_render_callback( $attributes, $content, $block ) { ob_start(); require plugin_dir_path( __FILE__ ) . 'build/template.php'; return ob_get_clean(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <?php $time = $attributes['time'] ?? '';?> <p <?php echo get_block_wrapper_attributes(); ?>> <?php echo $time; ?> </p> -
MonteLogic revised this gist
Sep 15, 2022 . 1 changed file with 34 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "name": "create-block/mol-custom-blocks", "version": "0.1.0", "title": "Monte Logic's Custom Blocks", "category": "text", "icon": "flag", "description": "A Gutenberg block to show your pride! This block enables you to type text and style it with the color font Gilbert from Type with Pride.", "attributes": { "message": { "type": "string", "source": "text", "selector": "div" }, "time": { "type": "string", "source": "text", "selector": "div" }, "hasCreated": { "type": "string", "source": "text", "selector": "div" } }, "supports": { "html": false }, "textdomain": "mol-custom-blocks", "editorScript": "file:./index.js", "editorStyle": "file:./index.css", "style": "file:./style-index.css" } -
MonteLogic created this gist
Sep 15, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ /** * WordPress components that create the necessary UI elements for the block * * @see https://developer.wordpress.org/block-editor/packages/packages-components/ */ import { TextControl } from '@wordpress/components'; /** * React hook that is used to mark the block wrapper element. * It provides all the necessary props like the class name. * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ import { useBlockProps } from '@wordpress/block-editor'; /** * The edit function describes the structure of your block in the context of the * editor. This represents what the editor will render when the block is used. * * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit * * @param {Object} props Properties passed to the function. * @param {Object} props.attributes Available block attributes. * @param {Function} props.setAttributes Function that updates individual attributes. * * @return {WPElement} Element to render. */ import { Card, CardBody } from '@wordpress/components'; import { useEffect } from '@wordpress/element'; export default function Edit( { attributes, setAttributes } ) { const blockProps = useBlockProps(); const hasCreatedVar = attributes.hasCreated; useEffect(() => { console.log( attributes ); if ( !attributes.hasCreated ){ console.log( attributes ); console.log ( "Not = 1" ); const d = new Date(); console.log(d); console.log("Updated time"); attributes.time = d.toString(); attributes.hasCreated = 1; console.log( attributes ); } attributes.hasCreated =+ 1; console.log( attributes ); console.log('Inserted'); return () => { console.log('Removed'); attributes.hasCreated = 0; console.log ( attributes.hasCreated ); }; }, []); return ( <div { ...blockProps }> <Card> <CardBody value={attributes.time}><b>New Day:</b> {attributes.time} </CardBody> </Card> </div> ); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ /** * React hook that is used to mark the block wrapper element. * It provides all the necessary props like the class name. * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ import { useBlockProps } from '@wordpress/block-editor'; /** * The save function defines the way in which the different attributes should * be combined into the final markup, which is then serialized by the block * editor into `post_content`. * * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save * * @param {Object} props Properties passed to the function. * @param {Object} props.attributes Available block attributes. * @return {WPElement} Element to render. */ /** * * {...blockProps} renders out to: "wp-block-create-block-gutenpride" * */ export default function save( { attributes } ) { const blockProps = useBlockProps.save(); return <div { ...blockProps }>{attributes.time} </div>; }