messages
listlengths
3
3
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display shopper-facing notifications generated by WooCommerce or extensions. that allows users to configure: align" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/store-notices/block.json\n{\n\t\"name\": \"woocommerce/store-notices\",\n\t\"title\": \"Store Notices\",\n\t\"description\": \"Display shopper-facing notifications generated by WooCommerce or extensions.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"multiple\": false,\n\t\t\"align\": [ \"wide\", \"full\" ]\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/store-notices/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport NoticeBanner from '@woocommerce/base-components/notice-banner';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-store-notices',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<NoticeBanner status=\"info\" isDismissible={ false }>\n\t\t\t\t{ __(\n\t\t\t\t\t'Notices added by WooCommerce or extensions will show up here.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</NoticeBanner>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a grow block with customizable text, style, align, and 2 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/cookie-consent/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/cookie-consent\",\n\t\"title\": \"Cookie Consent\",\n\t\"description\": \"Display a customizable cookie consent banner. To display this block on all pages of your site, please add it inside a Template Part that is present on all your templates, like a Header or a Footer.\",\n\t\"keywords\": [ \"cookie\", \"consent\", \"privacy\", \"GDPR\", \"EU\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m20.27,11.03c-.02-.31-.05-.62-.11-.92h-3.88v-2.91h-2.87v-3.79c-.32-.06-.64-.1-.97-.12-.15,0-.29,0-.44,0C7.42,3.28,3.71,7,3.71,11.57s3.71,8.3,8.29,8.3,8.29-3.72,8.29-8.3c0-.18,0-.36-.02-.54Zm-8.23,7.79c-4,0-7.24-3.25-7.24-7.25s3.24-7.24,7.24-7.24c.14,0,.27,0,.4.02v3.81h2.9v2.87h3.91c.02.18.03.36.03.54,0,4-3.24,7.25-7.24,7.25Z'/><path d='M 8, 8 a 1,1 0 1,1 2,0 a 1,1 0 1,1 -2,0'/><path d='M 12, 11.5 a 1,1 0 1,1 2,0 a 1,1 0 1,1 -2,0'/><path d='M 13, 16 a 1,1 0 1,1 2,0 a 1,1 0 1,1 -2,0'/><path d='M 8, 14 a 1,1 0 1,1 2,0 a 1,1 0 1,1 -2,0'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"right\", \"wide\", \"full\" ],\n\t\t\"alignWide\": true,\n\t\t\"anchor\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"lock\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"text\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \"p\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"color\": {\n\t\t\t\t\t\"text\": \"var(--wp--preset--color--contrast)\",\n\t\t\t\t\t\"background\": \"var(--wp--preset--color--tertiary)\",\n\t\t\t\t\t\"link\": \"var(--wp--preset--color--contrast)\"\n\t\t\t\t},\n\t\t\t\t\"spacing\": {\n\t\t\t\t\t\"padding\": {\n\t\t\t\t\t\t\"top\": \"1em\",\n\t\t\t\t\t\t\"right\": \"1em\",\n\t\t\t\t\t\t\"bottom\": \"1em\",\n\t\t\t\t\t\t\"left\": \"1em\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"consentExpiryDays\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 365\n\t\t},\n\t\t\"showOverlay\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"viewScript\": \"file:./view.js\"\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/cookie-consent/edit.js\nimport { InspectorControls, useBlockProps, InnerBlocks, RichText } from '@wordpress/block-editor';\nimport { PanelBody, TextControl, SelectControl } from '@wordpress/components';\nimport { __, isRTL } from '@wordpress/i18n';\nimport './editor.scss';\nimport { DEFAULT_TEXT } from './constants';\nimport { useSaveCookieConsentSettings } from './use-save-cookie-consent-settings';\n\n/**\n * Cookie Consent Edit Component.\n *\n * @param {object} props - Component props.\n * @param {string} props.clientId - Block id\n * @param {object} props.attributes - {object} Block attributes.\n * @param {Function} props.setAttributes - Set block attributes.\n * @return {object} Element to render.\n */\nfunction CookieConsentBlockEdit( { clientId, attributes, setAttributes } ) {\n\tconst { consentExpiryDays, align, text = DEFAULT_TEXT } = attributes;\n\n\tuseSaveCookieConsentSettings( clientId );\n\t/**\n\t * Update the alignment of the block. This takes care setting names alignments (left, right, etc..) or eg width=500.\n\t *\n\t * @param {string} nextAlign - The new alignment.\n\t */\n\tfunction updateAlignment( nextAlign ) {\n\t\tconst extraUpdatedAttributes = [ 'wide', 'full' ].includes( nextAlign )\n\t\t\t? { width: undefined, height: undefined }\n\t\t\t: {};\n\t\tsetAttributes( {\n\t\t\t...extraUpdatedAttributes,\n\t\t\talign: nextAlign,\n\t\t} );\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: `wp-block-jetpack-cookie-consent align${ align }`,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Block Settings', 'jetpack' ) }>\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Alignment', 'jetpack' ) }\n\t\t\t\t\t\tvalue={ align }\n\t\t\t\t\t\toptions={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: isRTL() ? __( 'Right', 'jetpack' ) : __( 'Left', 'jetpack' ),\n\t\t\t\t\t\t\t\tvalue: 'left',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Full', 'jetpack' ),\n\t\t\t\t\t\t\t\tvalue: 'full',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Wide', 'jetpack' ),\n\t\t\t\t\t\t\t\tvalue: 'wide',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: isRTL() ? __( 'Left', 'jetpack' ) : __( 'Right', 'jetpack' ),\n\t\t\t\t\t\t\t\tvalue: 'right',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t] }\n\t\t\t\t\t\tonChange={ alignValue => updateAlignment( alignValue ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\tlabel={ __( 'Consent Expiry Time (in days)', 'jetpack' ) }\n\t\t\t\t\t\tvalue={ consentExpiryDays }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\tmax=\"365\"\n\t\t\t\t\t\tonChange={ value => setAttributes( { consentExpiryDays: parseInt( value ) } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Note: The block position in the editor is not indicative of the position on the front end. The block will always be positioned at the bottom of the page.',\n\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps } style={ blockProps.style }>\n\t\t\t\t<RichText\n\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\tvalue={ text }\n\t\t\t\t\tonChange={ textValue => setAttributes( { text: textValue } ) }\n\t\t\t\t/>\n\t\t\t\t<InnerBlocks\n\t\t\t\t\tallowedBlocks={ [ 'core/button' ] }\n\t\t\t\t\ttemplate={ [\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'core/button',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttext: __( 'Accept', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t] }\n\t\t\t\t\ttemplateLock=\"all\"\n\t\t\t\t></InnerBlocks>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default CookieConsentBlockEdit;\n\n\n// File: projects/plugins/jetpack/extensions/blocks/cookie-consent/save.js\n/**\n * React hook that is used to mark the block wrapper element.\n * It provides all the necessary props like the class name.\n *\n * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops\n */\nimport { InnerBlocks, useBlockProps, RichText } from '@wordpress/block-editor';\nimport { DEFAULT_TEXT } from './constants';\n\n/**\n * The save function defines the way in which the different attributes should\n * be combined into the final markup, which is then serialized by the block\n * editor into `post_content`.\n *\n * @param {object} props - Save props.\n * @param {object} props.attributes - Block attributes.\n * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save\n * @return {object} Element to render.\n */\nexport default function save( { attributes } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst { text = DEFAULT_TEXT, consentExpiryDays } = attributes;\n\n\treturn (\n\t\t<div { ...blockProps } style={ blockProps.style } role=\"dialog\" aria-modal=\"true\">\n\t\t\t<RichText.Content tagName=\"p\" value={ text } />\n\t\t\t<InnerBlocks.Content />\n\t\t\t<span>{ consentExpiryDays }</span>\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a block feature that provides flexible login/logout link rendering, supporting custom form display and seamless redirection to the active page context." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/loginout/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/loginout\",\n\t\"title\": \"Login/out\",\n\t\"category\": \"theme\",\n\t\"description\": \"Show login & logout links.\",\n\t\"keywords\": [ \"login\", \"logout\", \"form\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"displayLoginAsForm\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"redirectToCurrent\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"className\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": false,\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-loginout\"\n}\n\n\n// File: packages/block-library/src/loginout/index.js\n/**\n * WordPress dependencies\n */\nimport { login as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable show button styles, button height, button border radius, lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/block.json\n{\n\t\"name\": \"woocommerce/cart-express-payment-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Express Checkout\",\n\t\"description\": \"Allow customers to breeze through with quick payment options.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"showButtonStyles\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"buttonHeight\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"48\"\n\t\t},\n\t\t\"buttonBorderRadius\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"4\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { useExpressPaymentMethods } from '@woocommerce/base-context/hooks';\nimport clsx from 'clsx';\nimport { ExpressPaymentControls } from '@woocommerce/blocks/cart-checkout-shared';\nimport type { BlockAttributes } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport type { ExpressCartAttributes } from '../../../cart-checkout-shared/types';\nimport { ExpressPaymentContext } from '../../../cart-checkout-shared/payment-methods/express-payment/express-payment-context';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: ExpressCartAttributes;\n\tsetAttributes: ( attrs: BlockAttributes ) => void;\n} ): JSX.Element | null => {\n\tconst { paymentMethods, isInitialized } = useExpressPaymentMethods();\n\tconst hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods':\n\t\t\t\thasExpressPaymentMethods,\n\t\t} ),\n\t} );\n\n\tconst { className, showButtonStyles, buttonHeight, buttonBorderRadius } =\n\t\tattributes;\n\n\tif ( ! isInitialized || ! hasExpressPaymentMethods ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<ExpressPaymentControls\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t/>\n\t\t\t<ExpressPaymentContext.Provider\n\t\t\t\tvalue={ { showButtonStyles, buttonHeight, buttonBorderRadius } }\n\t\t\t>\n\t\t\t\t<Block className={ className } />\n\t\t\t</ExpressPaymentContext.Provider>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Design a customizable WooCommerce block with integrated lock mechanisms that allow flexible restriction and permission settings." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-methods-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-shipping-methods-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Shipping Options\",\n\t\"description\": \"Display shipping options and rates for your store.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-methods-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { PanelBody, ExternalLink } from '@wordpress/components';\nimport { shipping } from '@wordpress/icons';\nimport { ADMIN_URL, getSetting } from '@woocommerce/settings';\nimport ExternalLinkCard from '@woocommerce/editor-components/external-link-card';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { useCheckoutAddress } from '@woocommerce/base-context/hooks';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\n\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport ConfigurePlaceholder from '../../configure-placeholder';\nimport Block from './block';\nimport './editor.scss';\n\ntype shippingAdminLink = {\n\tid: number;\n\ttitle: string;\n\tdescription: string;\n};\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\ttitle: string;\n\t\tdescription: string;\n\t\tshowStepNumber: boolean;\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element | null => {\n\tconst globalShippingMethods = getSetting(\n\t\t'globalShippingMethods'\n\t) as shippingAdminLink[];\n\tconst activeShippingZones = getSetting(\n\t\t'activeShippingZones'\n\t) as shippingAdminLink[];\n\n\tconst { showShippingMethods } = useCheckoutAddress();\n\n\tif ( ! showShippingMethods ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tattributes={ attributes }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__shipping-option',\n\t\t\t\tattributes?.className\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ __( 'Shipping Calculations', 'woocommerce' ) }\n\t\t\t\t>\n\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Options that control shipping can be managed in your store settings.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=options` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Manage shipping options', 'woocommerce' ) }\n\t\t\t\t\t</ExternalLink>{ ' ' }\n\t\t\t\t</PanelBody>\n\t\t\t\t{ globalShippingMethods.length > 0 && (\n\t\t\t\t\t<PanelBody title={ __( 'Methods', 'woocommerce' ) }>\n\t\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'The following shipping integrations are active on your store.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{ globalShippingMethods.map( ( method ) => {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\t\t\t\tkey={ method.id }\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=${ method.id }` }\n\t\t\t\t\t\t\t\t\ttitle={ method.title }\n\t\t\t\t\t\t\t\t\tdescription={ method.description }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Manage shipping methods', 'woocommerce' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t\t{ activeShippingZones.length && (\n\t\t\t\t\t<PanelBody title={ __( 'Shipping Zones', 'woocommerce' ) }>\n\t\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Shipping Zones can be made managed in your store settings.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t{ activeShippingZones.map( ( zone ) => {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\t\t\t\tkey={ zone.id }\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&zone_id=${ zone.id }` }\n\t\t\t\t\t\t\t\t\ttitle={ zone.title }\n\t\t\t\t\t\t\t\t\tdescription={ zone.description }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block\n\t\t\t\t\tnoShippingPlaceholder={\n\t\t\t\t\t\t<ConfigurePlaceholder\n\t\t\t\t\t\t\ticon={ shipping }\n\t\t\t\t\t\t\tlabel={ __( 'Shipping options', 'woocommerce' ) }\n\t\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t\t'Your store does not have any Shipping Options configured. Once you have added your Shipping Options they will appear here.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tbuttonLabel={ __(\n\t\t\t\t\t\t\t\t'Configure Shipping Options',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tbuttonHref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Noninteractive>\n\t\t\t<AdditionalFields block={ innerBlockAreas.SHIPPING_METHODS } />\n\t\t</FormStepBlock>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<AdditionalFieldsContent />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block that supports custom text input, enables citation fields, and provides text positioning controls for enhanced content presentation." }, { "role": "assistant", "content": "// File: packages/block-library/src/pullquote/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/pullquote\",\n\t\"title\": \"Pullquote (deprecated)\",\n\t\"category\": \"text\",\n\t\"description\": \"This block is deprecated. Please use the Quote block instead.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"value\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"p\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"citation\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"cite\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": [ \"left\", \"right\", \"wide\", \"full\" ],\n\t\t\"background\": {\n\t\t\t\"backgroundImage\": true,\n\t\t\t\"backgroundSize\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"backgroundImage\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"background\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"dimensions\": {\n\t\t\t\"minHeight\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"minHeight\": false\n\t\t\t}\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalStyle\": {\n\t\t\t\"typography\": {\n\t\t\t\t\"fontSize\": \"1.5em\",\n\t\t\t\t\"lineHeight\": \"1.6\"\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-pullquote-editor\",\n\t\"style\": \"wp-block-pullquote\"\n}\n\n\n// File: packages/block-library/src/pullquote/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { pullquote as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tvalue:\n\t\t\t\t// translators: Quote serving as example for the Pullquote block. Attributed to Matt Mullenweg.\n\t\t\t\t__(\n\t\t\t\t\t'One of the hardest things to do in technology is disrupt yourself.'\n\t\t\t\t),\n\t\t\tcitation: __( 'Matt Mullenweg' ),\n\t\t},\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'value',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'citation',\n\t\t\tlabel: __( 'Citation' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'value' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/pullquote/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { textAlign, citation, value } = attributes;\n\tconst shouldShowCitation = ! RichText.isEmpty( citation );\n\n\treturn (\n\t\t<figure\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tclassName: clsx( {\n\t\t\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t\t\t} ),\n\t\t\t} ) }\n\t\t>\n\t\t\t<blockquote>\n\t\t\t\t<RichText.Content tagName=\"p\" value={ value } />\n\t\t\t\t{ shouldShowCitation && (\n\t\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\n\t\t</figure>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Displays the name of this site. Update the block, and the changes apply everywhere it’s used. This will also appear in the browser title bar and in search results. with these attributes: level, level options, text align, and 2 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/site-title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/site-title\",\n\t\"title\": \"Site Title\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the name of this site. Update the block, and the changes apply everywhere it’s used. This will also appear in the browser title bar and in search results.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 1\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": [ 0, 1, 2, 3, 4, 5, 6 ]\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"viewportWidth\": 500\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-site-title-editor\",\n\t\"style\": \"wp-block-site-title\"\n}\n\n\n// File: packages/block-library/src/site-title/index.js\n/**\n * WordPress dependencies\n */\nimport { mapMarker as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport deprecated from './deprecated';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tviewportWidth: 350,\n\t\tattributes: {\n\t\t\ttextAlign: 'center',\n\t\t},\n\t},\n\tedit,\n\ttransforms,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Prompt visitors to take action with a button-style link. with these attributes: tag name, type, text align, and 10 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/button/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/button\",\n\t\"title\": \"Button\",\n\t\"category\": \"design\",\n\t\"parent\": [ \"core/buttons\" ],\n\t\"description\": \"Prompt visitors to take action with a button-style link.\",\n\t\"keywords\": [ \"link\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"a\", \"button\" ],\n\t\t\t\"default\": \"a\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"button\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a\",\n\t\t\t\"attribute\": \"href\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a,button\",\n\t\t\t\"attribute\": \"title\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"text\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"a,button\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a\",\n\t\t\t\"attribute\": \"target\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"a\",\n\t\t\t\"attribute\": \"rel\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"backgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"textColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"gradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"number\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"splitting\": true,\n\t\t\"align\": false,\n\t\t\"alignWide\": false,\n\t\t\"color\": {\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"__experimentalSkipSerialization\": [\n\t\t\t\t\"fontSize\",\n\t\t\t\t\"lineHeight\",\n\t\t\t\t\"fontFamily\",\n\t\t\t\t\"fontWeight\",\n\t\t\t\t\"fontStyle\",\n\t\t\t\t\"textTransform\",\n\t\t\t\t\"textDecoration\",\n\t\t\t\t\"letterSpacing\"\n\t\t\t],\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"reusable\": false,\n\t\t\"shadow\": {\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"padding\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{ \"name\": \"fill\", \"label\": \"Fill\", \"isDefault\": true },\n\t\t{ \"name\": \"outline\", \"label\": \"Outline\" }\n\t],\n\t\"editorStyle\": \"wp-block-button-editor\",\n\t\"style\": \"wp-block-button\",\n\t\"selectors\": {\n\t\t\"root\": \".wp-block-button .wp-block-button__link\",\n\t\t\"typography\": {\n\t\t\t\"writingMode\": \".wp-block-button\"\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/button/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { button as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tclassName: 'is-style-fill',\n\t\t\ttext: __( 'Call to action' ),\n\t\t},\n\t},\n\tedit,\n\tsave,\n\tdeprecated,\n\tmerge: ( a, { text = '' } ) => ( {\n\t\t...a,\n\t\ttext: ( a.text || '' ) + text,\n\t} ),\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'text',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'link',\n\t\t\tlabel: __( 'Link' ),\n\t\t\ttype: 'link',\n\t\t\tmapping: {\n\t\t\t\turl: 'url',\n\t\t\t\trel: 'rel',\n\t\t\t\tlinkTarget: 'linkTarget',\n\t\t\t},\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'text' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/button/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,\n\t__experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n\t__experimentalGetElementClassName,\n\tgetTypographyClassesAndStyles,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes, className } ) {\n\tconst {\n\t\ttagName,\n\t\ttype,\n\t\ttextAlign,\n\t\tfontSize,\n\t\tlinkTarget,\n\t\trel,\n\t\tstyle,\n\t\ttext,\n\t\ttitle,\n\t\turl,\n\t\twidth,\n\t} = attributes;\n\n\tconst TagName = tagName || 'a';\n\tconst isButtonTag = 'button' === TagName;\n\tconst buttonType = type || 'button';\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst colorProps = getColorClassesAndStyles( attributes );\n\tconst spacingProps = getSpacingClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\tconst typographyProps = getTypographyClassesAndStyles( attributes );\n\tconst buttonClasses = clsx(\n\t\t'wp-block-button__link',\n\t\tcolorProps.className,\n\t\tborderProps.className,\n\t\ttypographyProps.className,\n\t\t{\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t\t// For backwards compatibility add style that isn't provided via\n\t\t\t// block support.\n\t\t\t'no-border-radius': style?.border?.radius === 0,\n\t\t\t[ `has-custom-font-size` ]: fontSize || style?.typography?.fontSize,\n\t\t},\n\t\t__experimentalGetElementClassName( 'button' )\n\t);\n\tconst buttonStyle = {\n\t\t...borderProps.style,\n\t\t...colorProps.style,\n\t\t...spacingProps.style,\n\t\t...shadowProps.style,\n\t\t...typographyProps.style,\n\t\twritingMode: undefined,\n\t};\n\n\t// The use of a `title` attribute here is soft-deprecated, but still applied\n\t// if it had already been assigned, for the sake of backward-compatibility.\n\t// A title will no longer be assigned for new or updated button block links.\n\n\tconst wrapperClasses = clsx( className, {\n\t\t[ `has-custom-width wp-block-button__width-${ width }` ]: width,\n\t} );\n\n\treturn (\n\t\t<div { ...useBlockProps.save( { className: wrapperClasses } ) }>\n\t\t\t<RichText.Content\n\t\t\t\ttagName={ TagName }\n\t\t\t\ttype={ isButtonTag ? buttonType : null }\n\t\t\t\tclassName={ buttonClasses }\n\t\t\t\thref={ isButtonTag ? null : url }\n\t\t\t\ttitle={ title }\n\t\t\t\tstyle={ buttonStyle }\n\t\t\t\tvalue={ text }\n\t\t\t\ttarget={ isButtonTag ? null : linkTarget }\n\t\t\t\trel={ isButtonTag ? null : rel }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Display a product's description, attributes, and reviews with these attributes: align, hide tab title" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-details/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-details\",\n\t\"title\": \"Product Details\",\n\t\"description\": \"Display a product's description, attributes, and reviews\",\n\t\"category\": \"woocommerce\",\n\t\"textdomain\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ]\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"hideTabTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\", \"postType\" ]\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-details/edit.tsx\n/**\n * External dependencies\n */\nimport { productsStore } from '@woocommerce/data';\nimport { useEffect, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { Disabled, PanelBody, ToggleControl } from '@wordpress/components';\n\nimport {\n\tstore as blockEditorStore,\n\tuseBlockProps,\n\t// @ts-expect-error - useInnerBlocksProps is not exported from @wordpress/block-editor\n\tuseInnerBlocksProps,\n\tWarning,\n\tInspectorControls,\n} from '@wordpress/block-editor';\n\n/**\n * External dependencies\n */\nimport { getInnerBlockByName } from '@woocommerce/utils';\n\n/**\n * Internal dependencies\n */\nimport { ProductDetailsEditProps } from './types';\nimport { getTemplate, isAdditionalProductDataEmpty } from './utils';\nimport { LegacyProductDetailsPreview } from './legacy-preview';\nimport './editor.scss';\n\n/**\n * Check if block is inside a Query Loop with non-product post type\n *\n * @param {string} clientId The block's client ID\n * @param {string} postType The current post type\n * @return {boolean} Whether the block is in an invalid Query Loop context\n */\nconst useIsInvalidQueryLoopContext = ( clientId: string, postType: string ) => {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst blockParents = select(\n\t\t\t\tblockEditorStore\n\t\t\t).getBlockParentsByBlockName( clientId, 'core/post-template' );\n\t\t\treturn blockParents.length > 0 && postType !== 'product';\n\t\t},\n\t\t[ clientId, postType ]\n\t);\n};\n\nconst Edit = ( {\n\tclientId,\n\tcontext,\n\tattributes,\n\tsetAttributes,\n}: ProductDetailsEditProps ) => {\n\tconst blockProps = useBlockProps();\n\tconst { hideTabTitle } = attributes;\n\n\tconst product = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! context.postId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst { getProduct } = select( productsStore );\n\t\t\treturn getProduct( Number( context.postId ) );\n\t\t},\n\t\t[ context.postId ]\n\t);\n\n\tconst {\n\t\tisInnerBlockOfSingleProductBlock,\n\t\thasInnerBlocks,\n\t\twasBlockJustInserted,\n\t\taccordionItemClientId,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst blockEditorSelect = select( blockEditorStore );\n\n\t\t\t// Check if block is inner block of single product block\n\t\t\tconst singleProductParentBlocks = blockEditorSelect\n\t\t\t\t// @ts-expect-error - getBlockParentsByBlockName is not typed\n\t\t\t\t.getBlockParentsByBlockName(\n\t\t\t\t\tclientId,\n\t\t\t\t\t'woocommerce/single-product'\n\t\t\t\t);\n\t\t\tconst isInnerBlock = singleProductParentBlocks.length > 0;\n\n\t\t\t// Get inner blocks and insertion status\n\t\t\t// @ts-expect-error - getBlocks is not typed\n\t\t\tconst blocks = blockEditorSelect.getBlocks( clientId );\n\t\t\tconst innerBlocks = blocks.length > 0;\n\t\t\tconst blockJustInserted =\n\t\t\t\t// @ts-expect-error - wasBlockJustInserted is not typed\n\t\t\t\tblockEditorSelect.wasBlockJustInserted( clientId );\n\n\t\t\tconst productDetailsBlock = select(\n\t\t\t\tblockEditorStore\n\t\t\t\t// @ts-expect-error - getBlocksByName is not typed\n\t\t\t).getBlock( clientId );\n\n\t\t\tconst productSpecificationClientId = getInnerBlockByName(\n\t\t\t\tproductDetailsBlock,\n\t\t\t\t'woocommerce/product-specifications'\n\t\t\t)?.clientId;\n\n\t\t\tconst accordionClientId = select(\n\t\t\t\tblockEditorStore\n\t\t\t\t// @ts-expect-error - getBlockParentsByBlockName is not typed\n\t\t\t).getBlockParentsByBlockName(\n\t\t\t\tproductSpecificationClientId ?? '',\n\t\t\t\t'woocommerce/accordion-item'\n\t\t\t)[ 0 ];\n\n\t\t\treturn {\n\t\t\t\tisInnerBlockOfSingleProductBlock: isInnerBlock,\n\t\t\t\thasInnerBlocks: innerBlocks,\n\t\t\t\twasBlockJustInserted: blockJustInserted,\n\t\t\t\taccordionItemClientId: accordionClientId,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst template = useMemo( () => {\n\t\treturn getTemplate( product, {\n\t\t\tisInnerBlockOfSingleProductBlock,\n\t\t} );\n\t}, [ product, isInnerBlockOfSingleProductBlock ] );\n\n\tconst { removeBlock } = useDispatch( blockEditorStore );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: wasBlockJustInserted ? template : undefined,\n\t} );\n\n\t/**\n\t * In some cases, the template variable is calculated before all the props are set.\n\t * This is why we need to do this additional check.\n\t * Check the PR for more details: https://github.com/woocommerce/woocommerce/pull/59686\n\t */\n\tuseEffect( () => {\n\t\tif (\n\t\t\twasBlockJustInserted &&\n\t\t\tproduct &&\n\t\t\tisAdditionalProductDataEmpty( product ) &&\n\t\t\taccordionItemClientId\n\t\t) {\n\t\t\tremoveBlock( accordionItemClientId );\n\t\t}\n\t}, [ wasBlockJustInserted, accordionItemClientId, product, removeBlock ] );\n\n\tconst isInvalidQueryLoopContext = useIsInvalidQueryLoopContext(\n\t\tclientId,\n\t\tcontext.postType\n\t);\n\tif ( isInvalidQueryLoopContext ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'The Product Details block requires a product context. When used in a Query Loop, the Query Loop must be configured to display products.',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( hasInnerBlocks || wasBlockJustInserted ) {\n\t\treturn <div { ...innerBlocksProps } />;\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls key=\"inspector\">\n\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Show tab title in content',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ ! hideTabTitle }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\thideTabTitle: ! hideTabTitle,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<Disabled>\n\t\t\t\t<LegacyProductDetailsPreview hideTabTitle={ hideTabTitle } />\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-details/save.tsx\n/**\n * External dependencies\n */\nimport {\n\t// @ts-expect-error Missing types for this package.\n\tuseInnerBlocksProps,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\nexport default function Save() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable align, class name" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/downloads/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-downloads\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Downloads\",\n\t\"description\": \"Display links to purchased downloads.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"multiple\": false,\n\t\t\"align\": [\n\t\t\t\"wide\",\n\t\t\t\"full\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalSelector\": \".wp-block-woocommerce-order-confirmation-totals table\"\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/downloads/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { Disabled } from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-downloads',\n\t} );\n\n\tconst {\n\t\tborderBottomColor,\n\t\tborderLeftColor,\n\t\tborderRightColor,\n\t\tborderTopColor,\n\t\tborderWidth,\n\t} = blockProps.style;\n\n\tconst borderStyles = {\n\t\tborderBottomColor,\n\t\tborderLeftColor,\n\t\tborderRightColor,\n\t\tborderTopColor,\n\t\tborderWidth,\n\t} as React.CSSProperties;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Disabled>\n\t\t\t\t<table\n\t\t\t\t\tstyle={ borderStyles }\n\t\t\t\t\tcellSpacing=\"0\"\n\t\t\t\t\tclassName=\"wc-block-order-confirmation-downloads__table\"\n\t\t\t\t>\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th className=\"download-product\">\n\t\t\t\t\t\t\t\t<span className=\"nobr\">\n\t\t\t\t\t\t\t\t\t{ __( 'Product', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<th className=\"download-remaining\">\n\t\t\t\t\t\t\t\t<span className=\"nobr\">\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Downloads remaining',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<th className=\"download-expires\">\n\t\t\t\t\t\t\t\t<span className=\"nobr\">\n\t\t\t\t\t\t\t\t\t{ __( 'Expires', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t<th className=\"download-file\">\n\t\t\t\t\t\t\t\t<span className=\"nobr\">\n\t\t\t\t\t\t\t\t\t{ __( 'Download', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\tclassName=\"download-product\"\n\t\t\t\t\t\t\t\tdata-title=\"Product\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<a href=\"https://example.com\">\n\t\t\t\t\t\t\t\t\t{ _x(\n\t\t\t\t\t\t\t\t\t\t'Test Product',\n\t\t\t\t\t\t\t\t\t\t'sample product name',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\tclassName=\"download-remaining\"\n\t\t\t\t\t\t\t\tdata-title=\"Downloads remaining\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ _x(\n\t\t\t\t\t\t\t\t\t'∞',\n\t\t\t\t\t\t\t\t\t'infinite downloads remaining',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\tclassName=\"download-expires\"\n\t\t\t\t\t\t\t\tdata-title=\"Expires\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ _x(\n\t\t\t\t\t\t\t\t\t'Never',\n\t\t\t\t\t\t\t\t\t'download expires',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td className=\"download-file\" data-title=\"Download\">\n\t\t\t\t\t\t\t\t<a\n\t\t\t\t\t\t\t\t\thref=\"https://example.com\"\n\t\t\t\t\t\t\t\t\tclassName=\"woocommerce-MyAccount-downloads-file button alt\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ _x(\n\t\t\t\t\t\t\t\t\t\t'Test Download',\n\t\t\t\t\t\t\t\t\t\t'sample download name',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</Disabled>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Displays the name of the author of the review. with these attributes: is link, link target, text align" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-author-name/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-review-author-name\",\n\t\"title\": \"Review Author Name\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews\" ],\n\t\"description\": \"Displays the name of the author of the review.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"commentId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-author-name/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { __, _x } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\nimport {\n\t// @ts-expect-error AlignmentControl is not exported from @wordpress/block-editor\n\tAlignmentControl,\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\ntype Comment = {\n\tauthor_name?: string;\n\tauthor: number;\n};\n\ntype User = {\n\tname?: string;\n};\n\nexport default function Edit( {\n\tattributes: { isLink, linkTarget, textAlign },\n\tcontext: { commentId },\n\tsetAttributes,\n}: BlockEditProps< {\n\tisLink: boolean;\n\tlinkTarget: string;\n\ttextAlign: string;\n} > & {\n\tcontext: { commentId: string };\n} ) {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\tlet displayName = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\n\t\t\tconst comment = getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'comment',\n\t\t\t\tcommentId\n\t\t\t) as Comment | null;\n\t\t\tconst authorName = comment?.author_name;\n\n\t\t\tif ( comment && ! authorName ) {\n\t\t\t\tconst user = getEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'user',\n\t\t\t\t\tcomment.author\n\t\t\t\t) as User | null;\n\t\t\t\treturn user?.name ?? __( 'Anonymous', 'woocommerce' );\n\t\t\t}\n\t\t\treturn authorName ?? '';\n\t\t},\n\t\t[ commentId ]\n\t);\n\n\tif ( ! commentId || ! displayName ) {\n\t\tdisplayName = _x( 'Review Author', 'block title', 'woocommerce' );\n\t}\n\n\tconst displayAuthor = isLink ? (\n\t\t<a\n\t\t\thref=\"#review-author-pseudo-link\"\n\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t>\n\t\t\t{ displayName }\n\t\t</a>\n\t) : (\n\t\tdisplayName\n\t);\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Link to authors URL', 'woocommerce' ) }\n\t\t\t\t\t\tonChange={ () => setAttributes( { isLink: ! isLink } ) }\n\t\t\t\t\t\tchecked={ isLink }\n\t\t\t\t\t/>\n\t\t\t\t\t{ isLink && (\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Open in new tab', 'woocommerce' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tlinkTarget: value ? '_blank' : '_self',\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tchecked={ linkTarget === '_blank' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( newAlign: string | undefined ) => {\n\t\t\t\t\t\tif ( typeof newAlign === 'string' ) {\n\t\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>{ displayAuthor }</div>\n\t\t</>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for A group of headers and associated expandable content. that allows users to configure: icon position, autoclose, allowed blocks" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/accordion-group/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/accordion-group\",\n\t\"title\": \"Accordion Group\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"A group of headers and associated expandable content.\",\n\t\"example\": {},\n\t\"__experimental\": true,\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"background\": {\n\t\t\t\"backgroundImage\": true,\n\t\t\t\"backgroundSize\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"backgroundImage\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradient\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"blockGap\": true\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": true,\n\t\t\"interactivity\": true\n\t},\n\t\"attributes\": {\n\t\t\"iconPosition\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"right\"\n\t\t},\n\t\t\"autoclose\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"allowedBlocks\": {\n\t\t\t\"type\": \"array\"\n\t\t}\n\t},\n\t\"allowedBlocks\": [ \"woocommerce/accordion-item\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"viewScriptModule\": \"woocommerce/accordion-group\",\n\t\"style\": \"file:../woocommerce/accordion-group-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/accordion-group/index.js\n/**\n * External dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\nimport { registerBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\n\nconst icon = (\n\t<SVG\n\t\twidth=\"24\"\n\t\theight=\"24\"\n\t\tviewBox=\"0 0 24 24\"\n\t\tfill=\"none\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<Path\n\t\t\tfillRule=\"evenodd\"\n\t\t\tclipRule=\"evenodd\"\n\t\t\td=\"M19.5 9.25L9.5 9.25L9.5 7.75L19.5 7.75L19.5 9.25Z\"\n\t\t\tfill=\"currentColor\"\n\t\t/>\n\t\t<Path d=\"M4.5 6L8.5 8.5L4.5 11L4.5 6Z\" fill=\"currentColor\" />\n\t\t<Path\n\t\t\tfillRule=\"evenodd\"\n\t\t\tclipRule=\"evenodd\"\n\t\t\td=\"M19.5 16.25L9.5 16.25L9.5 14.75L19.5 14.75L19.5 16.25Z\"\n\t\t\tfill=\"currentColor\"\n\t\t/>\n\t\t<Path d=\"M4.5 13L8.5 15.5L4.5 18L4.5 13Z\" fill=\"currentColor\" />\n\t</SVG>\n);\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\tapiVersion: 3,\n\ticon,\n\texample: {},\n\tedit,\n\tsave,\n};\n\nregisterBlockType( metadata, settings );\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/accordion/accordion-group/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { iconPosition } = attributes;\n\tconst blockProps = useBlockProps.save();\n\tconst className = clsx(\n\t\t{\n\t\t\t'icon-position-left': iconPosition === 'left',\n\t\t},\n\t\tblockProps.className\n\t);\n\n\treturn (\n\t\t<div { ...useInnerBlocksProps.save( { ...blockProps, className } ) } />\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a text block with customizable answers link, answers link text, gravatars, and 8 more options" }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/blogging-prompt/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/blogging-prompt\",\n\t\"title\": \"Writing Prompt\",\n\t\"description\": \"Answer a new and inspiring writing prompt each day.\",\n\t\"keywords\": [ \"writing\", \"blogging\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"text\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M14.3438 19.3438H9.65625C9.57031 19.3438 9.5 19.4141 9.5 19.5V20.125C9.5 20.4707 9.7793 20.75 10.125 20.75H13.875C14.2207 20.75 14.5 20.4707 14.5 20.125V19.5C14.5 19.4141 14.4297 19.3438 14.3438 19.3438ZM12 3.25C8.46289 3.25 5.59375 6.11914 5.59375 9.65625C5.59375 12.0273 6.88281 14.0977 8.79688 15.2051V17.4688C8.79688 17.8145 9.07617 18.0938 9.42188 18.0938H14.5781C14.9238 18.0938 15.2031 17.8145 15.2031 17.4688V15.2051C17.1172 14.0977 18.4062 12.0273 18.4062 9.65625C18.4062 6.11914 15.5371 3.25 12 3.25ZM14.498 13.9883L13.7969 14.3945V16.6875H10.2031V14.3945L9.50195 13.9883C7.96484 13.0996 7 11.4629 7 9.65625C7 6.89453 9.23828 4.65625 12 4.65625C14.7617 4.65625 17 6.89453 17 9.65625C17 11.4629 16.0352 13.0996 14.498 13.9883Z' stroke-width='0.1'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"alignWide\": false,\n\t\t\"anchor\": false,\n\t\t\"className\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"customClassName\": true,\n\t\t\"html\": false,\n\t\t\"inserter\": true,\n\t\t\"multiple\": false,\n\t\t\"reusable\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"padding\": true,\n\t\t\t\"blockGap\": false\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"answersLink\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"attribute\": \"href\",\n\t\t\t\"selector\": \".jetpack-blogging-prompt__answers-link\"\n\t\t},\n\t\t\"answersLinkText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \".jetpack-blogging-prompt__answers-link\"\n\t\t},\n\t\t\"gravatars\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"source\": \"query\",\n\t\t\t\"selector\": \".jetpack-blogging-prompt__answers-gravatar\",\n\t\t\t\"query\": {\n\t\t\t\t\"url\": {\n\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\"source\": \"attribute\",\n\t\t\t\t\t\"attribute\": \"src\"\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"default\": []\n\t\t},\n\t\t\"promptLabel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \".jetpack-blogging-prompt__label\"\n\t\t},\n\t\t\"promptText\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"html\",\n\t\t\t\"selector\": \".jetpack-blogging-prompt__text\"\n\t\t},\n\t\t\"promptFetched\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"promptId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"showResponses\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"tagsAdded\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isBloganuary\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{ \"name\": \"block\", \"label\": \"Block\", \"isDefault\": true },\n\t\t{ \"name\": \"quote\", \"label\": \"Quote\" }\n\t]\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogging-prompt/edit.js\nimport apiFetch from '@wordpress/api-fetch';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { Button, PanelBody, Spinner, ToggleControl, withNotices } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { addQueryArgs } from '@wordpress/url';\nimport clsx from 'clsx';\nimport './editor.scss';\nimport { languageToLocale } from '../../shared/locale';\nimport { usePromptTags } from './use-prompt-tags';\n\nfunction BloggingPromptEdit( { attributes, noticeOperations, noticeUI, setAttributes } ) {\n\t// Use the ref to keep track of starting to fetch the prompt, so we don't make duplicate requests.\n\tconst fetchingPromptRef = useRef( false );\n\tconst {\n\t\tanswersLink,\n\t\tanswersLinkText,\n\t\tgravatars,\n\t\t// Use the attribute the track when we've finished fetching the prompt.\n\t\tpromptFetched,\n\t\tpromptId,\n\t\tpromptLabel,\n\t\tpromptText,\n\t\tshowLabel,\n\t\tshowResponses,\n\t\ttagsAdded,\n\t\tisBloganuary,\n\t} = attributes;\n\tconst blockProps = useBlockProps( { className: 'jetpack-blogging-prompt' } );\n\n\tconst setTagsAdded = state => setAttributes( { tagsAdded: state } );\n\n\t// Add the prompt tags to the post, if they haven't already been added.\n\tusePromptTags( promptId, tagsAdded, setTagsAdded );\n\n\tconst siteLanguage = useSelect( select => {\n\t\tconst { getEntityRecord, hasFinishedResolution } = select( 'core' );\n\t\tconst language = getEntityRecord( 'root', 'site' )?.language || 'en_US';\n\t\tconst hasFinishedResolving = hasFinishedResolution( 'getEntityRecord', [ 'root', 'site' ] );\n\t\treturn hasFinishedResolving ? language : null;\n\t}, [] );\n\n\t// Fetch the prompt by id, if present, otherwise the get the prompt for today.\n\tuseEffect( () => {\n\t\t// Only fetch the prompt one time when the block is inserted, after we know the site language.\n\t\tif ( ! siteLanguage || fetchingPromptRef.current || promptFetched ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst retryPrompt = () => {\n\t\t\tsetAttributes( { promptFetched: false, promptId: null, tagsAdded: false } );\n\t\t\tfetchingPromptRef.current = false;\n\t\t\tnoticeOperations.removeAllNotices();\n\t\t};\n\n\t\tconst errorMessage = message => (\n\t\t\t<>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t/* translators: %s is the error message. */\n\t\t\t\t\t__( 'Error while fetching prompt: %s', 'jetpack' ),\n\t\t\t\t\tmessage\n\t\t\t\t) }{ ' ' }\n\t\t\t\t<Button variant=\"link\" onClick={ retryPrompt }>\n\t\t\t\t\t{ __( 'Retry', 'jetpack' ) }\n\t\t\t\t</Button>\n\t\t\t</>\n\t\t);\n\n\t\tconst notFoundMessage = pId => (\n\t\t\t<>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t/* translators: %d is the prompt id. */\n\t\t\t\t\t__( 'Prompt with id %d not found.', 'jetpack' ),\n\t\t\t\t\tpId\n\t\t\t\t) }{ ' ' }\n\t\t\t\t<Button variant=\"link\" onClick={ retryPrompt }>\n\t\t\t\t\t{ __( 'Reset prompt', 'jetpack' ) }\n\t\t\t\t</Button>\n\t\t\t</>\n\t\t);\n\n\t\tlet path = '/wpcom/v3/blogging-prompts';\n\n\t\tif ( promptId ) {\n\t\t\tpath += '/' + encodeURIComponent( promptId );\n\t\t} else {\n\t\t\tconst date = new Date();\n\n\t\t\t// Current month and day with leading zeros.\n\t\t\tconst month = ( date.getMonth() + 1 ).toString().padStart( 2, '0' );\n\t\t\tconst day = date.getDate().toString().padStart( 2, '0' );\n\n\t\t\tpath += `?after=--${ month }-${ day }&order=desc`;\n\t\t}\n\n\t\tpath = addQueryArgs( path, {\n\t\t\t_locale: siteLanguage,\n\t\t\tforce_year: new Date()?.getFullYear(),\n\t\t} );\n\t\tfetchingPromptRef.current = true;\n\t\tapiFetch( { path } )\n\t\t\t.then( prompts => {\n\t\t\t\tconst promptData = promptId ? prompts : prompts[ 0 ];\n\t\t\t\tconst locale = languageToLocale( siteLanguage );\n\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tanswersLink: promptData.answered_link + `?locale=${ locale }`,\n\t\t\t\t\tanswersLinkText: promptData.answered_link_text,\n\t\t\t\t\tgravatars: promptData.answered_users_sample.map( ( { avatar } ) => ( { url: avatar } ) ),\n\t\t\t\t\tpromptFetched: true,\n\t\t\t\t\tpromptLabel: promptData.label,\n\t\t\t\t\tpromptText: promptData.text,\n\t\t\t\t\tpromptId: promptData.id,\n\t\t\t\t\tisBloganuary: !! promptData.bloganuary_id,\n\t\t\t\t} );\n\t\t\t} )\n\t\t\t.catch( error => {\n\t\t\t\tsetAttributes( { promptFetched: true } );\n\t\t\t\tconst message =\n\t\t\t\t\terror.code === 'rest_post_invalid_id' && promptId\n\t\t\t\t\t\t? notFoundMessage( promptId )\n\t\t\t\t\t\t: errorMessage( error.message );\n\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\tnoticeOperations.createErrorNotice( message );\n\t\t\t} );\n\t}, [\n\t\tfetchingPromptRef,\n\t\tnoticeOperations,\n\t\tpromptFetched,\n\t\tpromptId,\n\t\tsetAttributes,\n\t\tsiteLanguage,\n\t] );\n\n\tconst onShowLabelChange = newValue => {\n\t\tsetAttributes( { showLabel: newValue } );\n\t};\n\n\tconst onShowResponsesChange = newValue => {\n\t\tsetAttributes( { showResponses: newValue } );\n\t};\n\n\tconst renderControls = () => (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ _x( 'Settings', 'title of block settings sidebar section', 'jetpack' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show prompt label', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ showLabel }\n\t\t\t\t\t\tonChange={ onShowLabelChange }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show other responses', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ showResponses }\n\t\t\t\t\t\tonChange={ onShowResponsesChange }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n\tconst labelClassnames = clsx( [ 'jetpack-blogging-prompt__label' ], {\n\t\t'is-bloganuary-icon': isBloganuary,\n\t} );\n\n\tconst renderPrompt = () => (\n\t\t<>\n\t\t\t{ showLabel && <div className={ labelClassnames }>{ promptLabel }</div> }\n\n\t\t\t<div className=\"jetpack-blogging-prompt__text\">{ promptText }</div>\n\n\t\t\t{ showResponses && promptId && (\n\t\t\t\t<div className=\"jetpack-blogging-prompt__answers\">\n\t\t\t\t\t{ gravatars &&\n\t\t\t\t\t\tgravatars.slice( 0, 3 ).map( ( { url } ) => {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\turl && (\n\t\t\t\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/alt-text\n\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\tclassName=\"jetpack-blogging-prompt__answers-gravatar\"\n\t\t\t\t\t\t\t\t\t\t// Gravatar are decorative, here.\n\t\t\t\t\t\t\t\t\t\tsrc={ url }\n\t\t\t\t\t\t\t\t\t\tkey={ url }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\n\t\t\t\t\t<a\n\t\t\t\t\t\tclassName=\"jetpack-blogging-prompt__answers-link\"\n\t\t\t\t\t\thref={ answersLink }\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"external noreferrer noopener\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ answersLinkText }\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ noticeUI }\n\t\t\t{ renderControls() }\n\n\t\t\t{ ! promptFetched ? (\n\t\t\t\t<div className=\"jetpack-blogging-prompt__spinner\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) : (\n\t\t\t\trenderPrompt()\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default withNotices( BloggingPromptEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/blogging-prompt/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nfunction BloggingPromptSave( { attributes } ) {\n\tconst {\n\t\tanswersLink,\n\t\tanswersLinkText,\n\t\tgravatars,\n\t\tpromptId,\n\t\tpromptLabel,\n\t\tpromptText,\n\t\tshowLabel,\n\t\tshowResponses,\n\t\tisBloganuary,\n\t} = attributes;\n\n\tconst blockProps = useBlockProps.save( { className: 'jetpack-blogging-prompt' } );\n\n\tconst labelClassnames = clsx( [ 'jetpack-blogging-prompt__label' ], {\n\t\t'is-bloganuary-icon': isBloganuary,\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ showLabel && <div className={ labelClassnames }>{ promptLabel }</div> }\n\t\t\t<div className=\"jetpack-blogging-prompt__text\">{ promptText }</div>\n\t\t\t{ showResponses && promptId && (\n\t\t\t\t<div className=\"jetpack-blogging-prompt__answers\">\n\t\t\t\t\t{ gravatars.map( ( { url } ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\turl && (\n\t\t\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/alt-text\n\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\tclassName=\"jetpack-blogging-prompt__answers-gravatar\"\n\t\t\t\t\t\t\t\t\t// Gravatar are decorative, here.\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t\tsrc={ url }\n\t\t\t\t\t\t\t\t\tkey={ url }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t\t<a\n\t\t\t\t\t\tclassName=\"jetpack-blogging-prompt__answers-link\"\n\t\t\t\t\t\thref={ answersLink }\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"external noreferrer noopener\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ answersLinkText }\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default BloggingPromptSave;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-footer-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Footer\",\n\t\"description\": \"Block that displays the footer of the Mini-Cart block.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false,\n\t\t\"interactivity\": true\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/filled-mini-cart-contents-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { TotalsItem } from '@woocommerce/blocks-components';\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { getCurrencyFromPriceResponse } from '@woocommerce/price-format';\nimport {\n\tusePaymentMethods,\n\tuseStoreCart,\n} from '@woocommerce/base-context/hooks';\nimport PaymentMethodIcons from '@woocommerce/base-components/cart-checkout/payment-method-icons';\nimport { getIconsFromPaymentMethods } from '@woocommerce/base-utils';\nimport { getSetting } from '@woocommerce/settings';\nimport { PaymentEventsProvider } from '@woocommerce/base-context';\n\n/**\n * Internal dependencies\n */\nimport { getTotalsItemDescription } from '../utils';\nimport './editor.scss';\n\nconst PaymentMethodIconsElement = (): JSX.Element => {\n\tconst { paymentMethods } = usePaymentMethods();\n\treturn (\n\t\t<PaymentMethodIcons\n\t\t\ticons={ getIconsFromPaymentMethods( paymentMethods ) }\n\t\t/>\n\t);\n};\n\nexport const Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\tconst { cartTotals } = useStoreCart();\n\tconst subTotal = getSetting( 'displayCartPricesIncludingTax', false )\n\t\t? parseInt( cartTotals.total_items, 10 ) +\n\t\t parseInt( cartTotals.total_items_tax, 10 )\n\t\t: parseInt( cartTotals.total_items, 10 );\n\n\tconst TEMPLATE = [\n\t\t[ 'woocommerce/mini-cart-cart-button-block', {} ],\n\t\t[ 'woocommerce/mini-cart-checkout-button-block', {} ],\n\t];\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<div className=\"wc-block-mini-cart__footer\">\n\t\t\t\t<TotalsItem\n\t\t\t\t\tclassName=\"wc-block-mini-cart__footer-subtotal\"\n\t\t\t\t\tcurrency={ getCurrencyFromPriceResponse( cartTotals ) }\n\t\t\t\t\tlabel={ __( 'Subtotal', 'woocommerce' ) }\n\t\t\t\t\tvalue={ subTotal }\n\t\t\t\t\tdescription={ getTotalsItemDescription() }\n\t\t\t\t/>\n\t\t\t\t<div className=\"wc-block-mini-cart__footer-actions\">\n\t\t\t\t\t<InnerBlocks template={ TEMPLATE } />\n\t\t\t\t</div>\n\t\t\t\t<PaymentEventsProvider>\n\t\t\t\t\t<PaymentMethodIconsElement />\n\t\t\t\t</PaymentEventsProvider>\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<InnerBlocks.Content />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a configurable media component that allows users to personalize display settings and upload various media assets." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/story/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/story\",\n\t\"title\": \"Story\",\n\t\"description\": \"Add an interactive story.\",\n\t\"keywords\": [ \"story\", \"image\", \"video\", \"gallery\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"media\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><g><path d='M17 5a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2h9z' /><path d='M13 4H5a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2z' /><path d='M7 16h8a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z' /></g></svg>\",\n\t\"supports\": {\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"settings\": {\n\t\t\t\"type\": \"object\"\n\t\t},\n\t\t\"mediaFiles\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"mediaFiles\": [\n\t\t\t\t{\n\t\t\t\t\t\"alt\": \"\",\n\t\t\t\t\t\"caption\": \"\",\n\t\t\t\t\t\"mime\": \"image/jpg\",\n\t\t\t\t\t\"type\": \"image\",\n\t\t\t\t\t\"id\": 22,\n\t\t\t\t\t\"url\": \"./storyExample1.png\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/story/edit.js\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport { isBlobURL } from '@wordpress/blob';\nimport { MediaPlaceholder, useBlockProps } from '@wordpress/block-editor';\nimport { withNotices } from '@wordpress/components';\nimport { useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport metadata from './block.json';\nimport Controls from './controls';\nimport StoryPlayer from './player';\n\nimport './editor.scss';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image', 'video' ];\nconst ALLOWED_MEDIA_PROPS = [\n\t'alt',\n\t'title',\n\t'id',\n\t'link',\n\t'type',\n\t'mime',\n\t'caption',\n\t'width',\n\t'height',\n];\nconst icon = getBlockIconComponent( metadata );\n\nexport const pickRelevantMediaFiles = media => {\n\tconst mediaProps = Object.fromEntries(\n\t\tObject.entries( media ).filter( ( [ k ] ) => ALLOWED_MEDIA_PROPS.includes( k ) )\n\t);\n\tmediaProps.url =\n\t\tmedia?.media_details?.original?.url ||\n\t\tmedia?.media_details?.videopress?.original ||\n\t\tmedia?.media_details?.sizes?.large?.source_url ||\n\t\tmedia?.sizes?.large?.url ||\n\t\tmedia.url;\n\tmediaProps.type = media.media_type || media.type;\n\tmediaProps.mime = media.mime_type || media.mime;\n\tmediaProps.title = mediaProps.title?.rendered || mediaProps.title;\n\tmediaProps.width = mediaProps.width || media.media_details?.width;\n\tmediaProps.height = mediaProps.height || media.media_details?.height;\n\treturn mediaProps;\n};\n\nexport default withNotices( function StoryEdit( {\n\tattributes,\n\tisSelected,\n\tnoticeOperations,\n\tnoticeUI,\n\tsetAttributes,\n} ) {\n\tconst { mediaFiles } = attributes;\n\tconst { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );\n\tconst blockProps = useBlockProps();\n\tconst lockName = 'storyBlockLock';\n\n\tconst onSelectMedia = newMediaFiles => {\n\t\tconst allMedia = newMediaFiles\n\t\t\t.map( newMedia => {\n\t\t\t\t// MediaPlaceholder passes only the media ids as value to MediaUpload, so we're only getting those back\n\t\t\t\tif ( ! isNaN( newMedia ) ) {\n\t\t\t\t\tconst existingMedia = mediaFiles.find( mediaFile => mediaFile.id === newMedia );\n\t\t\t\t\treturn existingMedia || { id: newMedia };\n\t\t\t\t}\n\t\t\t\treturn newMedia;\n\t\t\t} )\n\t\t\t.map( pickRelevantMediaFiles );\n\t\tconst uploadedMedias = allMedia.filter( media => ! isBlobURL( media.url ) );\n\t\t// prevent saving blob urls in mediaFiles block attribute\n\t\tif ( allMedia.length !== uploadedMedias.length ) {\n\t\t\tlockPostSaving( lockName );\n\t\t} else {\n\t\t\tunlockPostSaving( lockName );\n\t\t}\n\t\tsetAttributes( {\n\t\t\tmediaFiles: allMedia,\n\t\t} );\n\t};\n\n\tconst controls = (\n\t\t<Controls\n\t\t\tallowedMediaTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\tattributes={ attributes }\n\t\t\tonSelectMedia={ onSelectMedia }\n\t\t/>\n\t);\n\n\tconst hasImages = !! mediaFiles.length;\n\n\tconst mediaPlaceholder = (\n\t\t<MediaPlaceholder\n\t\t\taddToGallery={ hasImages }\n\t\t\tisAppender={ hasImages }\n\t\t\tclassName={ blockProps.className }\n\t\t\tdisableMediaButtons={ hasImages && ! isSelected }\n\t\t\ticon={ ! hasImages && icon }\n\t\t\tlabels={ {\n\t\t\t\ttitle: ! hasImages && __( 'Story', 'jetpack' ),\n\t\t\t\tinstructions:\n\t\t\t\t\t! hasImages &&\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Drag images and videos, upload new ones, or select files from your library.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t),\n\t\t\t} }\n\t\t\tonSelect={ onSelectMedia }\n\t\t\taccept={ ALLOWED_MEDIA_TYPES.map( type => type + '/*' ).join( ',' ) }\n\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\tmultiple=\"add\"\n\t\t\tvalue={ mediaFiles }\n\t\t\tnotices={ hasImages ? undefined : noticeUI }\n\t\t\tonError={ noticeOperations.createErrorNotice }\n\t\t/>\n\t);\n\n\tlet content;\n\n\tif ( ! hasImages ) {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t{ controls }\n\t\t\t\t{ mediaPlaceholder }\n\t\t\t</>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t{ controls }\n\t\t\t\t{ noticeUI }\n\t\t\t\t<StoryPlayer\n\t\t\t\t\tslides={ mediaFiles }\n\t\t\t\t\tdisabled={ ! isSelected }\n\t\t\t\t\tshowSlideCount={ isSelected }\n\t\t\t\t\tshadowDOM={ {\n\t\t\t\t\t\tenabled: false,\n\t\t\t\t\t} }\n\t\t\t\t\tplayInFullscreen={ false }\n\t\t\t\t\ttapToPlayPause={ false }\n\t\t\t\t\tplayOnNextSlide={ false }\n\t\t\t\t/>\n\t\t\t\t{ isSelected && mediaPlaceholder }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( 'wp-block-jetpack-story', 'wp-story', blockProps.className ) }\n\t\t>\n\t\t\t{ content }\n\t\t</div>\n\t);\n} );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/story/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default () => {\n\tconst blockProps = useBlockProps.save();\n\n\treturn <div { ...blockProps } className={ clsx( 'wp-story', blockProps.className ) }></div>;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build an adaptable block featuring configurable URL settings to enable seamless monetization strategies within your WordPress site." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/tock/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/tock\",\n\t\"title\": \"Tock\",\n\t\"description\": \"Reserve a table at your restaurant with Tock.\",\n\t\"keywords\": [ \"booking\", \"reservation\", \"restaurant\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"monetize\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M10 15.619C6.84915 15.619 4.28572 13.0542 4.28572 9.90176C4.28572 7.24269 6.10957 5.00183 8.57143 4.36551V0C3.72557 0.693782 0 4.86162 0 9.90176C0 15.4274 4.47715 19.9069 10 19.9069C12.2461 19.9069 14.3193 19.1658 15.9887 17.9148L12.9003 14.825C12.0494 15.3287 11.0581 15.619 10 15.619 M15.7135 9.90176C15.7135 10.9604 15.4233 11.9522 14.9199 12.8035L18.0082 15.8935C19.2585 14.2232 19.9992 12.149 19.9992 9.90176C19.9992 4.86162 16.2736 0.693782 11.4277 0V4.36551C13.8896 5.00183 15.7135 7.24269 15.7135 9.90176'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": false\n\t},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"url\": \"roister\"\n\t\t},\n\t\t\"viewportWidth\": 250\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/tock/edit.js\nimport { useBlockProps, BlockControls } from '@wordpress/block-editor';\nimport {\n\tSandBox,\n\tTextControl,\n\tToolbarGroup,\n\tToolbarButton,\n\tButton,\n\tBaseControl,\n\tDropdown,\n} from '@wordpress/components';\nimport {\n\tcreateInterpolateElement,\n\tuseCallback,\n\tuseEffect,\n\tuseState,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { keyboardReturn } from '@wordpress/icons';\nimport { ENTER, ESCAPE } from '@wordpress/keycodes';\n\nimport './editor.scss';\n\nconst UrlDropdown = ( { tockUrl, setEditedUrl, setUrl, cancel } ) => {\n\tconst firstRender = useRef( true );\n\tconst committedChanges = useRef( false );\n\tconst handleSubmitOrCancel = ( event, onClose ) => {\n\t\tconst { keyCode } = event;\n\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t'' !== tockUrl // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\tcommitChanges( onClose );\n\t\t}\n\n\t\tif ( keyCode === ESCAPE ) {\n\t\t\tevent.preventDefault();\n\t\t\tcancel();\n\t\t\tonClose();\n\t\t}\n\t};\n\n\tconst commitChanges = close => {\n\t\tsetUrl();\n\t\tcommittedChanges.current = true;\n\t\tclose();\n\t};\n\n\treturn (\n\t\t<ToolbarGroup>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tvariant: 'toolbar',\n\t\t\t\t} }\n\t\t\t\tonClose={ () =>\n\t\t\t\t\tcommittedChanges.current ? ( committedChanges.current = false ) : cancel()\n\t\t\t\t}\n\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => {\n\t\t\t\t\tif ( firstRender.current && ! isOpen && ! tockUrl ) {\n\t\t\t\t\t\tfirstRender.current = false;\n\t\t\t\t\t\tonToggle();\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\t\t\t\tlabel={ __( 'Edit Tock business name', 'jetpack' ) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\tisOpen && cancel();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit', 'jetpack' ) }\n\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\tclassName=\"jetpack-tock-url-settings\"\n\t\t\t\t\t\thelp={ createInterpolateElement(\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'The Tock business can be found in the URL of your public Tock page. For example: www.exploretock.com/<b>myname</b>',\n\t\t\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tb: <strong />,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t>\n\t\t\t\t\t\t<div className=\"jetpack-tock-url-input-wrapper\">\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\tplaceholder={ __( 'Add Tock business name', 'jetpack' ) }\n\t\t\t\t\t\t\t\tonChange={ setEditedUrl }\n\t\t\t\t\t\t\t\tvalue={ tockUrl }\n\t\t\t\t\t\t\t\tonKeyDownCapture={ event => handleSubmitOrCancel( event, onClose ) }\n\t\t\t\t\t\t\t\tclassName=\"jetpack-tock-url-input\"\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<div className=\"jetpack-tock-url-input-action\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Submit', 'jetpack' ) }\n\t\t\t\t\t\t\t\t\ticon={ keyboardReturn }\n\t\t\t\t\t\t\t\t\tclassName=\"jetpack-tock-url-input-submit\"\n\t\t\t\t\t\t\t\t\tonClick={ () => commitChanges( onClose ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t) }\n\t\t\t/>\n\t\t</ToolbarGroup>\n\t);\n};\n\nconst TockPreview = ( { url, popoverAnchor } ) => {\n\tconst html = `\n\t\t<div id=\"Tock_widget_container\" data-tock-display-mode=\"Button\" data-tock-color-mode=\"Blue\" data-tock-locale=\"en-us\" data-tock-timezone=\"America/New_York\" style=\"display:inline-block;\"></div>\n\t\t<script src=\"https://www.exploretock.com/tock.js\" async></script>\n\t\t<script>\n\t\t\t!function(t,o){if(!t.tock){var e=t.tock=function(){e.callMethod?\n\t\t\t e.callMethod.apply(e,arguments):e.queue.push(arguments)};t._tock||(t._tock=e),\n\t\t\t e.push=e,e.loaded=!0,e.version='1.0',e.queue=[];}}(window,document);\n\t\t\ttock('init', '${ url }');\n\t\t</script>\n\t`;\n\n\treturn (\n\t\t<div ref={ popoverAnchor }>\n\t\t\t{\n\t\t\t\t// Related to this bug (https://github.com/WordPress/gutenberg/issues/16831), the\n\t\t\t\t// `SandBox` component won't rerun the scripts correctly when the injected `html` prop changes.\n\t\t\t\t// To work around that, we change the key of the component to force a new one render\n\t\t\t }\n\t\t\t<SandBox html={ html } key={ `tock-${ url }` } />\n\t\t\t{ /* Use an overlay to prevent interactivity with the preview, since the preview does not always resize correctly. */ }\n\t\t\t<div className=\"block-library-embed__interactive-overlay\" />\n\t\t</div>\n\t);\n};\n\nexport default function TockBlockEdit( { attributes, setAttributes, isSelected } ) {\n\tconst tockUrl = attributes.url ?? '';\n\tconst [ editedUrl, setEditedUrl ] = useState( tockUrl );\n\n\tconst setUrl = () => {\n\t\tconst newUrl = editedUrl.replace( /.*exploretock.com\\//, '' );\n\t\tsetEditedUrl( newUrl );\n\t\tsetAttributes( { url: newUrl } );\n\t};\n\n\tconst cancel = useCallback( () => {\n\t\tsetEditedUrl( tockUrl );\n\t}, [ tockUrl ] );\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tcancel();\n\t\t}\n\t}, [ isSelected, cancel ] );\n\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<BlockControls>\n\t\t\t\t<UrlDropdown\n\t\t\t\t\ttockUrl={ editedUrl }\n\t\t\t\t\tsetEditedUrl={ setEditedUrl }\n\t\t\t\t\tsetUrl={ setUrl }\n\t\t\t\t\tcancel={ cancel }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<TockPreview url={ tockUrl } />\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Enable customers to filter the product grid by selecting one or more attributes, such as color. with these attributes: class name, attribute id, show counts, and 6 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/attribute-filter/block.json\n{\n\t\"name\": \"woocommerce/attribute-filter\",\n\t\"title\": \"Filter by Attribute Controls\",\n\t\"description\": \"Enable customers to filter the product grid by selecting one or more attributes, such as color.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"lock\": false,\n\t\t\"interactivity\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"attributeId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"showCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"queryType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"or\"\n\t\t},\n\t\t\"headingLevel\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"displayStyle\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"list\"\n\t\t},\n\t\t\"showFilterButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"selectType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"multiple\"\n\t\t},\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/attribute-filter/edit.tsx\n/**\n * External dependencies\n */\nimport { sort } from 'fast-sort';\nimport { __, sprintf, _n, _x } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tInspectorControls,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { Icon, category, external } from '@wordpress/icons';\nimport { SearchListControl } from '@woocommerce/editor-components/search-list-control';\nimport { getAdminLink, getSetting } from '@woocommerce/settings';\nimport BlockTitle from '@woocommerce/editor-components/block-title';\nimport clsx from 'clsx';\nimport { SearchListItem } from '@woocommerce/editor-components/search-list-control/types';\nimport { AttributeSetting } from '@woocommerce/types';\nimport {\n\tPlaceholder,\n\tDisabled,\n\tPanelBody,\n\tToggleControl,\n\tButton,\n\tToolbarGroup,\n\tNotice,\n\twithSpokenMessages,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t// eslint-disable-next-line @wordpress/no-unsafe-wp-apis\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\nimport type { EditProps, GetNotice } from './types';\nimport { UpgradeNotice } from '../filter-wrapper/upgrade';\n\nconst ATTRIBUTES = getSetting< AttributeSetting[] >( 'attributes', [] );\n\nconst noticeContent = {\n\tnoAttributes: __(\n\t\t'Please select an attribute to use this filter!',\n\t\t'woocommerce'\n\t),\n\tnoProducts: __(\n\t\t'There are no products with the selected attributes.',\n\t\t'woocommerce'\n\t),\n};\n\nconst getNotice: GetNotice = ( type ) => {\n\tconst content = noticeContent[ type ];\n\treturn content ? (\n\t\t<Notice status=\"warning\" isDismissible={ false }>\n\t\t\t<p>{ content }</p>\n\t\t</Notice>\n\t) : null;\n};\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tdebouncedSpeak,\n\tclientId,\n}: EditProps ) => {\n\tconst {\n\t\tattributeId,\n\t\tdisplayStyle,\n\t\theading,\n\t\theadingLevel,\n\t\tisPreview,\n\t\tqueryType,\n\t\tshowCounts,\n\t\tshowFilterButton,\n\t\tselectType,\n\t} = attributes;\n\n\tconst [ isEditing, setIsEditing ] = useState(\n\t\t! attributeId && ! isPreview\n\t);\n\n\tconst blockProps = useBlockProps();\n\n\tconst getBlockControls = () => {\n\t\treturn (\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup\n\t\t\t\t\tcontrols={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ticon: 'edit',\n\t\t\t\t\t\t\ttitle: __( 'Edit', 'woocommerce' ),\n\t\t\t\t\t\t\tonClick: () => setIsEditing( ! isEditing ),\n\t\t\t\t\t\t\tisActive: isEditing,\n\t\t\t\t\t\t},\n\t\t\t\t\t] }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t);\n\t};\n\n\tconst onChange = ( selected: SearchListItem[] ) => {\n\t\tif ( ! selected || ! selected.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst selectedId = selected[ 0 ].id;\n\t\tconst productAttribute = ATTRIBUTES.find(\n\t\t\t( attribute ) => attribute.attribute_id === selectedId.toString()\n\t\t);\n\n\t\tif ( ! productAttribute || attributeId === selectedId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tattributeId: selectedId as number,\n\t\t} );\n\t};\n\n\tconst renderAttributeControl = ( {\n\t\tisCompact,\n\t}: {\n\t\tisCompact: boolean;\n\t} ) => {\n\t\tconst messages = {\n\t\t\tclear: __( 'Clear selected attribute', 'woocommerce' ),\n\t\t\tlist: __( 'Product Attributes', 'woocommerce' ),\n\t\t\tnoItems: __(\n\t\t\t\t\"Your store doesn't have any product attributes.\",\n\t\t\t\t'woocommerce'\n\t\t\t),\n\t\t\tsearch: __( 'Search for a product attribute:', 'woocommerce' ),\n\t\t\tselected: ( n: number ) =>\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %d is the number of attributes selected. */\n\t\t\t\t\t_n(\n\t\t\t\t\t\t'%d attribute selected',\n\t\t\t\t\t\t'%d attributes selected',\n\t\t\t\t\t\tn,\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t),\n\t\t\t\t\tn\n\t\t\t\t),\n\t\t\tupdated: __(\n\t\t\t\t'Product attribute search results updated.',\n\t\t\t\t'woocommerce'\n\t\t\t),\n\t\t};\n\n\t\tconst list = sort(\n\t\t\tATTRIBUTES.map( ( item ) => {\n\t\t\t\treturn {\n\t\t\t\t\tid: parseInt( item.attribute_id, 10 ),\n\t\t\t\t\tname: item.attribute_label,\n\t\t\t\t};\n\t\t\t} )\n\t\t).asc( 'name' );\n\n\t\treturn (\n\t\t\t<SearchListControl\n\t\t\t\tclassName=\"woocommerce-product-attributes\"\n\t\t\t\tlist={ list }\n\t\t\t\tselected={ list.filter( ( { id } ) => id === attributeId ) }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tmessages={ messages }\n\t\t\t\tisSingle\n\t\t\t\tisCompact={ isCompact }\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst getInspectorControls = () => {\n\t\treturn (\n\t\t\t<InspectorControls key=\"inspector\">\n\t\t\t\t<PanelBody>\n\t\t\t\t\t<UpgradeNotice clientId={ clientId } />\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Display Settings', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Display product count', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showCounts }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowCounts: ! showCounts,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t'Allow selecting multiple options?',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ selectType || 'multiple' }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tselectType: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__multiple-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"multiple\"\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Multiple',\n\t\t\t\t\t\t\t\t'Number of filters',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"single\"\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Single',\n\t\t\t\t\t\t\t\t'Number of filters',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t{ selectType === 'multiple' && (\n\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\tlabel={ __( 'Filter Conditions', 'woocommerce' ) }\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t\tqueryType === 'and'\n\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t'Choose to return filter results for all of the attributes selected.',\n\t\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t'Choose to return filter results for any of the attributes selected.',\n\t\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvalue={ queryType }\n\t\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tqueryType: value,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__conditions-toggle\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"or\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Any', 'woocommerce' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"and\"\n\t\t\t\t\t\t\t\tlabel={ __( 'All', 'woocommerce' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Display Style', 'woocommerce' ) }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tvalue={ displayStyle }\n\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdisplayStyle: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__display-toggle\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"list\"\n\t\t\t\t\t\t\tlabel={ __( 'List', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tvalue=\"dropdown\"\n\t\t\t\t\t\t\tlabel={ __( 'Dropdown', 'woocommerce' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\"Show 'Apply filters' button\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Products will update when the button is clicked.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ showFilterButton }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowFilterButton: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ __( 'Content Settings', 'woocommerce' ) }\n\t\t\t\t\tinitialOpen={ false }\n\t\t\t\t>\n\t\t\t\t\t{ renderAttributeControl( { isCompact: true } ) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t);\n\t};\n\n\tconst noAttributesPlaceholder = () => (\n\t\t<Placeholder\n\t\t\tclassName=\"wc-block-attribute-filter\"\n\t\t\ticon={ <Icon icon={ category } /> }\n\t\t\tlabel={ __( 'Filter by Attribute', 'woocommerce' ) }\n\t\t\tinstructions={ __(\n\t\t\t\t'Display a list of filters based on the selected attributes.',\n\t\t\t\t'woocommerce'\n\t\t\t) }\n\t\t>\n\t\t\t<p>\n\t\t\t\t{ __(\n\t\t\t\t\t\"Attributes are needed for filtering your products. You haven't created any attributes yet.\",\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t<Button\n\t\t\t\tclassName=\"wc-block-attribute-filter__add-attribute-button\"\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\thref={ getAdminLink(\n\t\t\t\t\t'edit.php?post_type=product&page=product_attributes'\n\t\t\t\t) }\n\t\t\t\ttarget=\"_top\"\n\t\t\t>\n\t\t\t\t{ __( 'Add new attribute', 'woocommerce' ) + ' ' }\n\t\t\t\t<Icon icon={ external } />\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tclassName=\"wc-block-attribute-filter__read_more_button\"\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\thref=\"https://woocommerce.com/document/managing-product-taxonomies/\"\n\t\t\t\ttarget=\"_blank\"\n\t\t\t>\n\t\t\t\t{ __( 'Learn more', 'woocommerce' ) }\n\t\t\t</Button>\n\t\t</Placeholder>\n\t);\n\n\tconst onDone = () => {\n\t\tsetIsEditing( false );\n\t\tdebouncedSpeak(\n\t\t\t__(\n\t\t\t\t'Now displaying a preview of the Filter Products by Attribute block.',\n\t\t\t\t'woocommerce'\n\t\t\t)\n\t\t);\n\t};\n\n\tconst renderEditMode = () => {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\tclassName=\"wc-block-attribute-filter\"\n\t\t\t\ticon={ <Icon icon={ category } /> }\n\t\t\t\tlabel={ __( 'Filter by Attribute', 'woocommerce' ) }\n\t\t\t>\n\t\t\t\t<div className=\"wc-block-attribute-filter__instructions\">\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Display a list of filters based on the selected attributes.',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<div className=\"wc-block-attribute-filter__selection\">\n\t\t\t\t\t{ renderAttributeControl( { isCompact: false } ) }\n\t\t\t\t\t<Button variant=\"primary\" onClick={ onDone }>\n\t\t\t\t\t\t{ __( 'Done', 'woocommerce' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\n\treturn Object.keys( ATTRIBUTES ).length === 0 ? (\n\t\tnoAttributesPlaceholder()\n\t) : (\n\t\t<div { ...blockProps }>\n\t\t\t{ getBlockControls() }\n\t\t\t{ getInspectorControls() }\n\t\t\t{ isEditing ? (\n\t\t\t\trenderEditMode()\n\t\t\t) : (\n\t\t\t\t<div className={ clsx( 'wc-block-attribute-filter' ) }>\n\t\t\t\t\t{ heading && (\n\t\t\t\t\t\t<BlockTitle\n\t\t\t\t\t\t\tclassName=\"wc-block-attribute-filter__title\"\n\t\t\t\t\t\t\theadingLevel={ headingLevel }\n\t\t\t\t\t\t\theading={ heading }\n\t\t\t\t\t\t\tonChange={ ( value: string ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { heading: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<Disabled>\n\t\t\t\t\t\t<Block\n\t\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\t\tisEditor={ true }\n\t\t\t\t\t\t\tgetNotice={ getNotice }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Disabled>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport default withSpokenMessages( Edit );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a WordPress block enabling dynamic login/logout link display with configurable form presentation and current-page redirection options." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/loginout/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/loginout\",\n\t\"title\": \"Login/out\",\n\t\"category\": \"theme\",\n\t\"description\": \"Show login & logout links.\",\n\t\"keywords\": [ \"login\", \"logout\", \"form\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"displayLoginAsForm\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"redirectToCurrent\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"className\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": false,\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-loginout\"\n}\n\n\n// File: packages/block-library/src/loginout/index.js\n/**\n * WordPress dependencies\n */\nimport { login as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Implement a Gutenberg block for Contains the block elements used to render a product." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-template/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-template\",\n\t\"title\": \"Product Template\",\n\t\"category\": \"woocommerce\",\n\t\"description\": \"Contains the block elements used to render a product.\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [\n\t\t\"queryId\",\n\t\t\"query\",\n\t\t\"queryContext\",\n\t\t\"displayLayout\",\n\t\t\"templateSlug\",\n\t\t\"postId\",\n\t\t\"queryContextIncludes\",\n\t\t\"collection\",\n\t\t\"__privateProductCollectionPreviewState\"\n\t],\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"inserter\": false,\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowEditing\": false,\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowSizingOnChildren\": false,\n\t\t\t\"allowVerticalAlignment\": false\n\t\t},\n\t\t\"email\": true\n\t},\n\t\"editorStyle\": \"file:../woocommerce/product-template-editor.css\",\n\t\"style\": \"file:../woocommerce/product-template-style.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-template/edit.tsx\n/* eslint-disable @wordpress/no-unsafe-wp-apis */\n/* eslint-disable @typescript-eslint/naming-convention */\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { memo, useMemo, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockContextProvider,\n\t__experimentalUseBlockPreview as useBlockPreview,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { ProductCollectionAttributes } from '@woocommerce/blocks/product-collection/types';\nimport { getSettingWithCoercion } from '@woocommerce/settings';\nimport { isNumber, ProductResponseItem } from '@woocommerce/types';\nimport { ProductDataContextProvider } from '@woocommerce/shared-context';\nimport { withProduct } from '@woocommerce/block-hocs';\nimport type { BlockEditProps, BlockInstance } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseGetLocation,\n\tuseProductCollectionQueryContext,\n\tparseTemplateSlug,\n} from './utils';\nimport { getDefaultStockStatuses } from '../product-collection/constants';\n\nconst DEFAULT_QUERY_CONTEXT_ATTRIBUTES = [ 'collection' ];\n\nconst ProductTemplateInnerBlocks = () => {\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ className: 'wc-block-product' },\n\t\t{ __unstableDisableLayoutClassNames: true }\n\t);\n\treturn <li { ...innerBlocksProps } />;\n};\n\ntype ProductTemplateBlockPreviewProps = {\n\tblocks: object[];\n\tblockContextId: string;\n\tisHidden: boolean;\n\tsetActiveBlockContextId: ( blockContextId: string ) => void;\n};\n\nconst ProductTemplateBlockPreview = ( {\n\tblocks,\n\tblockContextId,\n\tisHidden,\n\tsetActiveBlockContextId,\n}: ProductTemplateBlockPreviewProps ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t\tprops: {\n\t\t\tclassName: 'wc-block-product',\n\t\t},\n\t} );\n\n\tconst handleOnClick = () => {\n\t\tsetActiveBlockContextId( blockContextId );\n\t};\n\n\tconst style = {\n\t\tdisplay: isHidden ? 'none' : undefined,\n\t};\n\n\treturn (\n\t\t<li\n\t\t\t{ ...blockPreviewProps }\n\t\t\ttabIndex={ 0 }\n\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n\t\t\trole=\"button\"\n\t\t\tonClick={ handleOnClick }\n\t\t\tonKeyPress={ handleOnClick }\n\t\t\tstyle={ style }\n\t\t/>\n\t);\n};\n\nconst MemoizedProductTemplateBlockPreview = memo( ProductTemplateBlockPreview );\n\ntype ProductContentProps = {\n\tattributes: { productId: string };\n\tdisplayTemplate: boolean;\n\tblocks: BlockInstance[];\n\tblockContext: {\n\t\tpostType: string;\n\t\tpostId: string;\n\t};\n\tsetActiveBlockContextId: ( id: string ) => void;\n};\n\nconst ProductContent = ( {\n\tdisplayTemplate,\n\tblocks,\n\tblockContext,\n\tsetActiveBlockContextId,\n}: ProductContentProps ) => {\n\treturn (\n\t\t<BlockContextProvider\n\t\t\tkey={ blockContext.postId }\n\t\t\tvalue={ blockContext }\n\t\t>\n\t\t\t{ displayTemplate ? <ProductTemplateInnerBlocks /> : null }\n\t\t\t<MemoizedProductTemplateBlockPreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tblockContextId={ blockContext.postId }\n\t\t\t\tsetActiveBlockContextId={ setActiveBlockContextId }\n\t\t\t\tisHidden={ displayTemplate }\n\t\t\t/>\n\t\t</BlockContextProvider>\n\t);\n};\n\n// This version of the component is used only when Product Collection is within Single Product block.\n// But because it's causing performance issues in editor, it's extracted to a separate component\n// and will be removed once all inner blocks are migrated from withProduct to useProduct HOC.\nconst ProductContentWithProduct = withProduct(\n\t( {\n\t\tisLoading,\n\t\tproduct,\n\t\tdisplayTemplate,\n\t\tblocks,\n\t\tblockContext,\n\t\tsetActiveBlockContextId,\n\t}: ProductContentProps & {\n\t\tisLoading: boolean;\n\t\tproduct: ProductResponseItem;\n\t} ) => {\n\t\treturn (\n\t\t\t<BlockContextProvider\n\t\t\t\tkey={ blockContext.postId }\n\t\t\t\tvalue={ blockContext }\n\t\t\t>\n\t\t\t\t<ProductDataContextProvider\n\t\t\t\t\tproduct={ product }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t>\n\t\t\t\t\t{ displayTemplate ? <ProductTemplateInnerBlocks /> : null }\n\t\t\t\t\t<MemoizedProductTemplateBlockPreview\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tblockContextId={ blockContext.postId }\n\t\t\t\t\t\tsetActiveBlockContextId={ setActiveBlockContextId }\n\t\t\t\t\t\tisHidden={ displayTemplate }\n\t\t\t\t\t/>\n\t\t\t\t</ProductDataContextProvider>\n\t\t\t</BlockContextProvider>\n\t\t);\n\t}\n);\n\nconst getOrderPropertiesForDefaultQuery = ( defaultSetting: string ) => {\n\tswitch ( defaultSetting ) {\n\t\tcase 'title':\n\t\t\treturn {\n\t\t\t\torderby: 'title',\n\t\t\t\torder: 'asc',\n\t\t\t};\n\t\tcase 'price':\n\t\t\treturn {\n\t\t\t\torderby: 'price',\n\t\t\t\torder: 'asc',\n\t\t\t};\n\t\tcase 'price-desc':\n\t\t\treturn {\n\t\t\t\torderby: 'price',\n\t\t\t\torder: 'desc',\n\t\t\t};\n\t\tcase 'popularity':\n\t\t\treturn {\n\t\t\t\torderby: 'popularity',\n\t\t\t\torder: 'desc',\n\t\t\t};\n\t\tcase 'rating':\n\t\t\treturn {\n\t\t\t\torderby: 'rating',\n\t\t\t\torder: 'desc',\n\t\t\t};\n\t\tcase 'date':\n\t\t\treturn {\n\t\t\t\torderby: 'date',\n\t\t\t\torder: 'desc',\n\t\t\t};\n\t}\n\n\treturn {\n\t\torderby: 'menu_order',\n\t\torder: 'asc',\n\t};\n};\n\nconst ProductTemplateEdit = (\n\tprops: BlockEditProps< {\n\t\tclientId: string;\n\t} > & {\n\t\tcontext: ProductCollectionAttributes;\n\t\t__unstableLayoutClassNames: string;\n\t}\n) => {\n\tconst {\n\t\tclientId,\n\t\tcontext: {\n\t\t\tquery: {\n\t\t\t\tperPage,\n\t\t\t\toffset = 0,\n\t\t\t\torder,\n\t\t\t\torderBy,\n\t\t\t\tsearch,\n\t\t\t\texclude,\n\t\t\t\tinherit,\n\t\t\t\ttaxQuery,\n\t\t\t\tpages,\n\t\t\t\t...restQueryArgs\n\t\t\t},\n\t\t\tqueryContext = [ { page: 1 } ],\n\t\t\ttemplateSlug,\n\t\t\tdisplayLayout: { type: layoutType, columns, shrinkColumns } = {\n\t\t\t\ttype: 'flex',\n\t\t\t\tcolumns: 3,\n\t\t\t\tshrinkColumns: false,\n\t\t\t},\n\t\t\tqueryContextIncludes = [],\n\t\t\t__privateProductCollectionPreviewState,\n\t\t},\n\t\t__unstableLayoutClassNames,\n\t} = props;\n\tconst location = useGetLocation( props.context, props.clientId );\n\n\tconst [ { page } ] = queryContext;\n\tconst [ activeBlockContextId, setActiveBlockContextId ] =\n\t\tuseState< string >();\n\tconst postType = 'product';\n\tconst loopShopPerPage = getSettingWithCoercion(\n\t\t'loopShopPerPage',\n\t\t12,\n\t\tisNumber\n\t);\n\n\t// Add default query context attributes to queryContextIncludes\n\tconst queryContextIncludesWithDefaults = [\n\t\t...new Set(\n\t\t\tqueryContextIncludes.concat( DEFAULT_QUERY_CONTEXT_ATTRIBUTES )\n\t\t),\n\t];\n\n\tconst productCollectionQueryContext = useProductCollectionQueryContext( {\n\t\tclientId,\n\t\tqueryContextIncludes: queryContextIncludesWithDefaults,\n\t} );\n\n\tconst { products, isInSingleProductBlock, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords, getEditedEntityRecord, getTaxonomies } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst { getBlocks, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst taxonomies = getTaxonomies( {\n\t\t\t\ttype: postType,\n\t\t\t\tper_page: -1,\n\t\t\t\tcontext: 'view',\n\t\t\t} );\n\t\t\tconst query: Record< string, unknown > = {\n\t\t\t\tpostType,\n\t\t\t\toffset: perPage ? perPage * ( page - 1 ) + offset : 0,\n\t\t\t\torder,\n\t\t\t\torderby: orderBy,\n\t\t\t};\n\t\t\t// There is no need to build the taxQuery if we inherit.\n\t\t\tif ( taxQuery && ! inherit ) {\n\t\t\t\t// We have to build the tax query for the REST API and use as\n\t\t\t\t// keys the taxonomies `rest_base` with the `term ids` as values.\n\t\t\t\tconst builtTaxQuery = Object.entries( taxQuery ).reduce(\n\t\t\t\t\t( accumulator, [ taxonomySlug, terms ] ) => {\n\t\t\t\t\t\tconst taxonomy = taxonomies?.find(\n\t\t\t\t\t\t\t( { slug } ) => slug === taxonomySlug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( taxonomy?.rest_base ) {\n\t\t\t\t\t\t\taccumulator[ taxonomy?.rest_base ] = terms;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t},\n\t\t\t\t\t{}\n\t\t\t\t);\n\t\t\t\tif ( !! Object.keys( builtTaxQuery ).length ) {\n\t\t\t\t\tObject.assign( query, builtTaxQuery );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( perPage ) {\n\t\t\t\tquery.per_page = perPage;\n\t\t\t}\n\t\t\tif ( search ) {\n\t\t\t\tquery.search = search;\n\t\t\t}\n\t\t\tif ( exclude?.length ) {\n\t\t\t\tquery.exclude = exclude;\n\t\t\t}\n\t\t\t// If `inherit` is truthy, adjust conditionally the query to create a better preview.\n\t\t\tif ( inherit ) {\n\t\t\t\tconst { taxonomy, slug } = parseTemplateSlug( templateSlug );\n\n\t\t\t\tif ( taxonomy && slug ) {\n\t\t\t\t\tconst taxonomyRecord = getEntityRecords(\n\t\t\t\t\t\t'taxonomy',\n\t\t\t\t\t\ttaxonomy,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t_fields: [ 'id' ],\n\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( taxonomyRecord ) {\n\t\t\t\t\t\tconst taxonomyId = taxonomyRecord[ 0 ]?.id;\n\t\t\t\t\t\tif ( taxonomy === 'category' ) {\n\t\t\t\t\t\t\tquery.categories = taxonomyId;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// If taxonomy is not `category`, we expect either `product_cat` or `product_tag`\n\t\t\t\t\t\t\tquery[ taxonomy ] = taxonomyId;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tquery.per_page = loopShopPerPage;\n\n\t\t\t\tconst settings = getEditedEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'site',\n\t\t\t\t\tundefined\n\t\t\t\t) as unknown as Record< string, string >;\n\n\t\t\t\tconst orderProperties = getOrderPropertiesForDefaultQuery(\n\t\t\t\t\tsettings.woocommerce_default_catalog_orderby\n\t\t\t\t);\n\t\t\t\tquery.orderby = orderProperties.orderby;\n\t\t\t\tquery.order = orderProperties.order;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tproducts: getEntityRecords( 'postType', postType, {\n\t\t\t\t\t...query,\n\t\t\t\t\t...restQueryArgs,\n\t\t\t\t\tproductCollectionLocation: location,\n\t\t\t\t\tproductCollectionQueryContext,\n\t\t\t\t\tpreviewState: __privateProductCollectionPreviewState,\n\t\t\t\t\t/**\n\t\t\t\t\t * Use value of \"Out of stock visibility\" setting to determine\n\t\t\t\t\t * which stock statuses to include if inherit query\n\t\t\t\t\t * from template is true.\n\t\t\t\t\t */\n\t\t\t\t\t...( inherit && {\n\t\t\t\t\t\twoocommerceStockStatus: getDefaultStockStatuses(),\n\t\t\t\t\t} ),\n\t\t\t\t} ),\n\t\t\t\tisInSingleProductBlock:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, [\n\t\t\t\t\t\t'woocommerce/single-product',\n\t\t\t\t\t] ).length > 0,\n\t\t\t\tblocks: getBlocks( clientId ),\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tperPage,\n\t\t\tpage,\n\t\t\toffset,\n\t\t\torder,\n\t\t\torderBy,\n\t\t\tclientId,\n\t\t\tsearch,\n\t\t\tpostType,\n\t\t\texclude,\n\t\t\tinherit,\n\t\t\ttemplateSlug,\n\t\t\ttaxQuery,\n\t\t\trestQueryArgs,\n\t\t\tlocation,\n\t\t\tproductCollectionQueryContext,\n\t\t\tloopShopPerPage,\n\t\t\t__privateProductCollectionPreviewState,\n\t\t]\n\t);\n\tconst blockContexts = useMemo(\n\t\t() =>\n\t\t\tproducts?.map( ( product ) => ( {\n\t\t\t\tpostType: product.type,\n\t\t\t\tpostId: product.id,\n\t\t\t} ) ),\n\t\t[ products ]\n\t);\n\n\tconst hasLayoutFlex = layoutType === 'flex' && columns > 1;\n\tlet customClassName = '';\n\n\t// We don't want to apply layout styles if there's no products.\n\tif ( products && products.length && hasLayoutFlex ) {\n\t\tconst dynamicGrid = `wc-block-product-template__responsive columns-${ columns }`;\n\t\tconst staticGrid = `is-flex-container columns-${ columns }`;\n\n\t\tcustomClassName = shrinkColumns ? dynamicGrid : staticGrid;\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx(\n\t\t\t__unstableLayoutClassNames,\n\t\t\t'wc-block-product-template',\n\t\t\tcustomClassName,\n\t\t\t{ [ `is-product-collection-layout-${ layoutType }` ]: layoutType }\n\t\t),\n\t} );\n\n\tif ( ! products ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t<Spinner className=\"wc-block-product-template__spinner\" />\n\t\t\t</p>\n\t\t);\n\t}\n\n\tif ( ! products.length ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t{ ' ' }\n\t\t\t\t{ __(\n\t\t\t\t\t'No products to display. Try adjusting the filters in the block settings panel.',\n\t\t\t\t\t'woocommerce'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t);\n\t}\n\n\tconst ProductContentComponent = isInSingleProductBlock\n\t\t? ProductContentWithProduct\n\t\t: ProductContent;\n\n\t// To avoid flicker when switching active block contexts, a preview is rendered\n\t// for each block context, but the preview for the active block context is hidden.\n\t// This ensures that when it is displayed again, the cached rendering of the\n\t// block preview is used, instead of having to re-render the preview from scratch.\n\treturn (\n\t\t<ul { ...blockProps }>\n\t\t\t{ blockContexts &&\n\t\t\t\tblockContexts.map( ( blockContext ) => {\n\t\t\t\t\tconst displayTemplate =\n\t\t\t\t\t\tblockContext.postId ===\n\t\t\t\t\t\t( activeBlockContextId || blockContexts[ 0 ]?.postId );\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t\t\t\t// @ts-ignore isLoading and product props are missing as they're coming from untyped withProduct HOC.\n\t\t\t\t\t\t<ProductContentComponent\n\t\t\t\t\t\t\tkey={ blockContext.postId }\n\t\t\t\t\t\t\tattributes={ {\n\t\t\t\t\t\t\t\tproductId: blockContext.postId,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\t\tdisplayTemplate={ displayTemplate }\n\t\t\t\t\t\t\tblockContext={ blockContext }\n\t\t\t\t\t\t\tsetActiveBlockContextId={ setActiveBlockContextId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t</ul>\n\t);\n};\n\nexport default ProductTemplateEdit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-template/save.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function Save() {\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a custom Gutenberg block enabling video embedding directly from WordPress media or new uploads, incorporating autoplay, caption, controls, and additional configurable settings." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/video/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/video\",\n\t\"title\": \"Video\",\n\t\"category\": \"media\",\n\t\"description\": \"Embed a video from your media library or upload a new one.\",\n\t\"keywords\": [ \"movie\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"autoplay\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"autoplay\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"figcaption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"controls\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"controls\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"loop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"loop\"\n\t\t},\n\t\t\"muted\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"muted\"\n\t\t},\n\t\t\"poster\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"poster\"\n\t\t},\n\t\t\"preload\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"preload\",\n\t\t\t\"default\": \"metadata\"\n\t\t},\n\t\t\"blob\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"local\"\n\t\t},\n\t\t\"src\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"src\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"playsInline\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"video\",\n\t\t\t\"attribute\": \"playsinline\"\n\t\t},\n\t\t\"tracks\": {\n\t\t\t\"role\": \"content\",\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\"\n\t\t\t},\n\t\t\t\"default\": []\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-video-editor\",\n\t\"style\": \"wp-block-video\"\n}\n\n\n// File: packages/block-library/src/video/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { video as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tsrc: 'https://upload.wikimedia.org/wikipedia/commons/c/ca/Wood_thrush_in_Central_Park_switch_sides_%2816510%29.webm',\n\t\t\t// translators: Caption accompanying a video of the wood thrush singing, which serves as an example for the Video block.\n\t\t\tcaption: __( 'Wood thrush singing in Central Park, NYC.' ),\n\t\t},\n\t},\n\ttransforms,\n\tdeprecated,\n\tedit,\n\tsave,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'video',\n\t\t\tlabel: __( 'Video' ),\n\t\t\ttype: 'media',\n\t\t\tmapping: {\n\t\t\t\tid: 'id',\n\t\t\t\turl: 'src',\n\t\t\t\tcaption: 'caption',\n\t\t\t\tposter: 'poster',\n\t\t\t},\n\t\t\targs: {\n\t\t\t\tallowedTypes: [ 'video' ],\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'caption',\n\t\t\tlabel: __( 'Caption' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'video' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/video/save.js\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Tracks from './tracks';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\tautoplay,\n\t\tcaption,\n\t\tcontrols,\n\t\tloop,\n\t\tmuted,\n\t\tposter,\n\t\tpreload,\n\t\tsrc,\n\t\tplaysInline,\n\t\ttracks,\n\t} = attributes;\n\treturn (\n\t\t<figure { ...useBlockProps.save() }>\n\t\t\t{ src && (\n\t\t\t\t<video\n\t\t\t\t\tautoPlay={ autoplay }\n\t\t\t\t\tcontrols={ controls }\n\t\t\t\t\tloop={ loop }\n\t\t\t\t\tmuted={ muted }\n\t\t\t\t\tposter={ poster }\n\t\t\t\t\tpreload={ preload !== 'metadata' ? preload : undefined }\n\t\t\t\t\tsrc={ src }\n\t\t\t\t\tplaysInline={ playsInline }\n\t\t\t\t>\n\t\t\t\t\t<Tracks tracks={ tracks } />\n\t\t\t\t</video>\n\t\t\t) }\n\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</figure>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a Gutenberg block representing the cart subtotal, featuring configurable class name and lock settings to enhance block functionality." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-subtotal-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Subtotal\",\n\t\"description\": \"Shows the cart subtotal row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Block that displays the shopping button when the Mini-Cart is empty. with these attributes: lock, start shopping button label" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-shopping-button-block/block.json\n{\n\t\"name\": \"woocommerce/mini-cart-shopping-button-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Mini-Cart Shopping Button\",\n\t\"description\": \"Block that displays the shopping button when the Mini-Cart is empty.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": true,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": false,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t},\n\t\t\"startShoppingButtonLabel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"fill\",\n\t\t\t\"label\": \"Fill\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"outline\",\n\t\t\t\"label\": \"Outline\"\n\t\t}\n\t],\n\t\"parent\": [ \"woocommerce/empty-mini-cart-contents-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-shopping-button-block/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n} from '@wordpress/block-editor';\nimport EditableButton from '@woocommerce/editor-components/editable-button';\n\n/**\n * Internal dependencies\n */\nimport { defaultStartShoppingButtonLabel } from './constants';\nimport { getVariant } from '../utils';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\tstartShoppingButtonLabel: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-button aligncenter',\n\t} );\n\tconst colorProps = useColorProps( attributes );\n\tconst { startShoppingButtonLabel } = attributes;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<EditableButton\n\t\t\t\tclassName={ `wc-block-mini-cart__shopping-button ${\n\t\t\t\t\tcolorProps.className || ''\n\t\t\t\t}` }\n\t\t\t\tvalue={ startShoppingButtonLabel }\n\t\t\t\tplaceholder={ defaultStartShoppingButtonLabel }\n\t\t\t\tonChange={ ( content ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tstartShoppingButtonLabel: content,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tvariant={ getVariant( blockProps.className, 'contained' ) }\n\t\t\t\tstyle={ colorProps.style }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a dynamic WordPress block empowering users to filter and showcase taxonomy terms using configurable search criteria and visual customization options for term and tag selection." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/terms-query/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/terms-query\",\n\t\"title\": \"Terms Query\",\n\t\"category\": \"theme\",\n\t\"description\": \"An advanced block that allows displaying taxonomy terms based on different query parameters and visual configurations.\",\n\t\"keywords\": [ \"terms\", \"taxonomy\", \"categories\", \"tags\", \"list\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"termQuery\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"perPage\": 10,\n\t\t\t\t\"taxonomy\": \"category\",\n\t\t\t\t\"order\": \"asc\",\n\t\t\t\t\"orderBy\": \"name\",\n\t\t\t\t\"include\": [],\n\t\t\t\t\"hideEmpty\": true,\n\t\t\t\t\"showNested\": false,\n\t\t\t\t\"inherit\": false\n\t\t\t}\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"templateSlug\" ],\n\t\"providesContext\": {\n\t\t\"termQuery\": \"termQuery\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"layout\": true,\n\t\t\"interactivity\": true\n\t}\n}\n\n\n// File: packages/block-library/src/terms-query/index.js\n/**\n * WordPress dependencies\n */\nimport { loop as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport variations from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\texample: {},\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/terms-query/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes: { tagName: Tag = 'div' } } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <Tag { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display a list of your most recent posts. that allows users to configure: categories, selected author, posts to show, and 15 more options" }, { "role": "assistant", "content": "// File: packages/block-library/src/latest-posts/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/latest-posts\",\n\t\"title\": \"Latest Posts\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Display a list of your most recent posts.\",\n\t\"keywords\": [ \"recent posts\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"categories\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\"\n\t\t\t}\n\t\t},\n\t\t\"selectedAuthor\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"postsToShow\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"displayPostContent\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayPostContentRadio\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"excerpt\"\n\t\t},\n\t\t\"excerptLength\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 55\n\t\t},\n\t\t\"displayAuthor\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayPostDate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"postLayout\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"list\"\n\t\t},\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"order\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"desc\"\n\t\t},\n\t\t\"orderBy\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"date\"\n\t\t},\n\t\t\"displayFeaturedImage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"featuredImageAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"left\", \"center\", \"right\" ]\n\t\t},\n\t\t\"featuredImageSizeSlug\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"thumbnail\"\n\t\t},\n\t\t\"featuredImageSizeWidth\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": null\n\t\t},\n\t\t\"featuredImageSizeHeight\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": null\n\t\t},\n\t\t\"addLinkToFeaturedImage\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-latest-posts-editor\",\n\t\"style\": \"wp-block-latest-posts\"\n}\n\n\n// File: packages/block-library/src/latest-posts/index.js\n/**\n * WordPress dependencies\n */\nimport { postList as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block enabling vertical spacing between content sections, with customizable height and width parameters for flexible layout control." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/spacer/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/spacer\",\n\t\"title\": \"Spacer\",\n\t\"category\": \"design\",\n\t\"description\": \"Add white space between blocks and customize its height.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"height\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"100px\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"orientation\" ],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-spacer-editor\",\n\t\"style\": \"wp-block-spacer\"\n}\n\n\n// File: packages/block-library/src/spacer/index.js\n/**\n * WordPress dependencies\n */\nimport { resizeCornerNE as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport transforms from './transforms';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/spacer/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, getSpacingPresetCssVar } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { height, width, style } = attributes;\n\tconst { layout: { selfStretch } = {} } = style || {};\n\t// If selfStretch is set to 'fill' or 'fit', don't set default height.\n\tconst finalHeight =\n\t\tselfStretch === 'fill' || selfStretch === 'fit' ? undefined : height;\n\treturn (\n\t\t<div\n\t\t\t{ ...useBlockProps.save( {\n\t\t\t\tstyle: {\n\t\t\t\t\theight: getSpacingPresetCssVar( finalHeight ),\n\t\t\t\t\twidth: getSpacingPresetCssVar( width ),\n\t\t\t\t},\n\t\t\t\t'aria-hidden': true,\n\t\t\t} ) }\n\t\t/>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that A collection of blocks that allow visitors to get around your site. with these attributes: ref, text color, custom text color, and 16 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/navigation/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/navigation\",\n\t\"title\": \"Navigation\",\n\t\"category\": \"theme\",\n\t\"allowedBlocks\": [\n\t\t\"core/navigation-link\",\n\t\t\"core/search\",\n\t\t\"core/social-links\",\n\t\t\"core/page-list\",\n\t\t\"core/spacer\",\n\t\t\"core/home-link\",\n\t\t\"core/site-title\",\n\t\t\"core/site-logo\",\n\t\t\"core/navigation-submenu\",\n\t\t\"core/loginout\",\n\t\t\"core/buttons\"\n\t],\n\t\"description\": \"A collection of blocks that allow visitors to get around your site.\",\n\t\"keywords\": [ \"menu\", \"navigation\", \"links\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"ref\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"textColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customTextColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"rgbTextColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"backgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"rgbBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showSubmenuIcon\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"openSubmenusOnClick\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"overlayMenu\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"mobile\"\n\t\t},\n\t\t\"icon\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"handle\"\n\t\t},\n\t\t\"hasIcon\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"__unstableLocation\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"overlayBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customOverlayBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"overlayTextColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customOverlayTextColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"maxNestingLevel\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"templateLock\": {\n\t\t\t\"type\": [ \"string\", \"boolean\" ],\n\t\t\t\"enum\": [ \"all\", \"insert\", \"contentOnly\", false ]\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"textColor\": \"textColor\",\n\t\t\"customTextColor\": \"customTextColor\",\n\t\t\"backgroundColor\": \"backgroundColor\",\n\t\t\"customBackgroundColor\": \"customBackgroundColor\",\n\t\t\"overlayTextColor\": \"overlayTextColor\",\n\t\t\"customOverlayTextColor\": \"customOverlayTextColor\",\n\t\t\"overlayBackgroundColor\": \"overlayBackgroundColor\",\n\t\t\"customOverlayBackgroundColor\": \"customOverlayBackgroundColor\",\n\t\t\"fontSize\": \"fontSize\",\n\t\t\"customFontSize\": \"customFontSize\",\n\t\t\"showSubmenuIcon\": \"showSubmenuIcon\",\n\t\t\"openSubmenusOnClick\": \"openSubmenusOnClick\",\n\t\t\"style\": \"style\",\n\t\t\"maxNestingLevel\": \"maxNestingLevel\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"ariaLabel\": true,\n\t\t\"contentRole\": true,\n\t\t\"html\": false,\n\t\t\"inserter\": true,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalSkipSerialization\": [ \"textDecoration\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true,\n\t\t\t\"units\": [ \"px\", \"em\", \"rem\", \"vh\", \"vw\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowVerticalAlignment\": false,\n\t\t\t\"allowSizingOnChildren\": true,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": true,\n\t\t\"renaming\": false\n\t},\n\t\"editorStyle\": \"wp-block-navigation-editor\",\n\t\"style\": \"wp-block-navigation\"\n}\n\n\n// File: packages/block-library/src/navigation/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { navigation as icon } from '@wordpress/icons';\nimport { select } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\toverlayMenu: 'never',\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/navigation-link',\n\t\t\t\tattributes: {\n\t\t\t\t\t// translators: 'Home' as in a website's home page.\n\t\t\t\t\tlabel: __( 'Home' ),\n\t\t\t\t\turl: 'https://make.wordpress.org/',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/navigation-link',\n\t\t\t\tattributes: {\n\t\t\t\t\t// translators: 'About' as in a website's about page.\n\t\t\t\t\tlabel: __( 'About' ),\n\t\t\t\t\turl: 'https://make.wordpress.org/',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/navigation-link',\n\t\t\t\tattributes: {\n\t\t\t\t\t// translators: 'Contact' as in a website's contact page.\n\t\t\t\t\tlabel: __( 'Contact' ),\n\t\t\t\t\turl: 'https://make.wordpress.org/',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\tedit,\n\tsave,\n\t__experimentalLabel: ( { ref } ) => {\n\t\tif ( ! ref ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst navigation = select( coreStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_navigation',\n\t\t\tref\n\t\t);\n\n\t\tif ( ! navigation?.title ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn decodeEntities( navigation.title );\n\t},\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/navigation/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tif ( attributes.ref ) {\n\t\t// Avoid rendering inner blocks when a ref is defined.\n\t\t// When this id is defined the inner blocks are loaded from the\n\t\t// `wp_navigation` entity rather than the hard-coded block html.\n\t\treturn;\n\t}\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce-product-elements block with customizable product id, is descendent of query loop, text align, and 2 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.json\n{\n\t\"name\": \"woocommerce/product-rating-counter\",\n\t\"title\": \"Product Rating Counter\",\n\t\"description\": \"Display the review count of a product\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"productId\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t},\n\t\t\"isDescendentOfQueryLoop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"isDescendentOfSingleProductBlock\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isDescendentOfSingleProductTemplate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"inserter\": false,\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": false,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wc-block-components-product-rating-counter\"\n\t},\n\t\"usesContext\": [ \"query\", \"queryId\", \"postId\" ],\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"ancestor\": [ \"woocommerce/single-product\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport { useEffect } from '@wordpress/element';\nimport { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport { BlockAttributes } from './types';\nimport { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';\nimport { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';\n\nconst Edit = (\n\tprops: BlockEditProps< BlockAttributes > & { context: Context }\n): JSX.Element => {\n\tconst { attributes, setAttributes, context } = props;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-woocommerce-product-rating-counter',\n\t} );\n\tconst blockAttrs = {\n\t\t...attributes,\n\t\t...context,\n\t\tshouldDisplayMockedReviewsWhenProductHasNoReviews: true,\n\t};\n\tconst isDescendentOfQueryLoop = Number.isFinite( context.queryId );\n\tconst { isDescendentOfSingleProductBlock } =\n\t\tuseIsDescendentOfSingleProductBlock( {\n\t\t\tblockClientId: blockProps?.id,\n\t\t} );\n\tlet { isDescendentOfSingleProductTemplate } =\n\t\tuseIsDescendentOfSingleProductTemplate();\n\n\tif ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {\n\t\tisDescendentOfSingleProductTemplate = false;\n\t}\n\n\tuseEffect( () => {\n\t\tsetAttributes( {\n\t\t\tisDescendentOfQueryLoop,\n\t\t\tisDescendentOfSingleProductBlock,\n\t\t\tisDescendentOfSingleProductTemplate,\n\t\t} );\n\t}, [\n\t\tsetAttributes,\n\t\tisDescendentOfQueryLoop,\n\t\tisDescendentOfSingleProductBlock,\n\t\tisDescendentOfSingleProductTemplate,\n\t] );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ attributes.textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign || '' } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Block { ...blockAttrs } />\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a widgets block with customizable columns, block layout, feed u r l, and 7 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/rss/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/rss\",\n\t\"title\": \"RSS\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Display entries from any RSS or Atom feed.\",\n\t\"keywords\": [ \"atom\", \"feed\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"blockLayout\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"list\"\n\t\t},\n\t\t\"feedURL\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"itemsToShow\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"displayExcerpt\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayAuthor\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"displayDate\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"excerptLength\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 55\n\t\t},\n\t\t\"openInNewTab\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": false,\n\t\t\t\t\"margin\": false\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-rss-editor\",\n\t\"style\": \"wp-block-rss\"\n}\n\n\n// File: packages/block-library/src/rss/index.js\n/**\n * WordPress dependencies\n */\nimport { rss as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tfeedURL: 'https://wordpress.org',\n\t\t},\n\t},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Add a user’s avatar. that allows users to configure: user id, size, is link, link target" }, { "role": "assistant", "content": "// File: packages/block-library/src/avatar/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/avatar\",\n\t\"title\": \"Avatar\",\n\t\"category\": \"theme\",\n\t\"description\": \"Add a user’s avatar.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"userId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"size\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 96\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postType\", \"postId\", \"commentId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"align\": true,\n\t\t\"alignWide\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"color\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"border\": \".wp-block-avatar img\",\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-avatar img\"\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-avatar-editor\",\n\t\"style\": \"wp-block-avatar\"\n}\n\n\n// File: packages/block-library/src/avatar/index.js\n/**\n * WordPress dependencies\n */\nimport { commentAuthorAvatar as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a flexible Gutenberg block designed to embed images with comprehensive configuration options, including blob, url, alt, and 14 supplementary attribute settings for refined visual presentation." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/image/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/image\",\n\t\"title\": \"Image\",\n\t\"category\": \"media\",\n\t\"usesContext\": [\n\t\t\"allowResize\",\n\t\t\"imageCrop\",\n\t\t\"fixedHeight\",\n\t\t\"postId\",\n\t\t\"postType\",\n\t\t\"queryId\"\n\t],\n\t\"description\": \"Insert an image to make a visual statement.\",\n\t\"keywords\": [ \"img\", \"photo\", \"picture\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"blob\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"local\"\n\t\t},\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"img\",\n\t\t\t\"attribute\": \"src\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"alt\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"img\",\n\t\t\t\"attribute\": \"alt\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"figcaption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"lightbox\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"enabled\": {\n\t\t\t\t\"type\": \"boolean\"\n\t\t\t}\n\t\t},\n\t\t\"title\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"img\",\n\t\t\t\"attribute\": \"title\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"href\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"href\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"rel\"\n\t\t},\n\t\t\"linkClass\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"class\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"width\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"height\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"aspectRatio\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"scale\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"sizeSlug\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"linkDestination\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"figure > a\",\n\t\t\t\"attribute\": \"target\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"align\": [ \"left\", \"center\", \"right\", \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalSkipSerialization\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": {\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"border\": \".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder\",\n\t\t\"shadow\": \".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder\",\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-image img, .wp-block-image .components-placeholder\"\n\t\t}\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"default\",\n\t\t\t\"label\": \"Default\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{ \"name\": \"rounded\", \"label\": \"Rounded\" }\n\t],\n\t\"editorStyle\": \"wp-block-image-editor\",\n\t\"style\": \"wp-block-image\"\n}\n\n\n// File: packages/block-library/src/image/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { image as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tsizeSlug: 'large',\n\t\t\turl: 'https://s.w.org/images/core/5.3/MtBlanc1.jpg',\n\t\t\t// translators: Caption accompanying an image of the Mont Blanc, which serves as an example for the Image block.\n\t\t\tcaption: __( 'Mont Blanc appears—still, snowy, and serene.' ),\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\tif ( context === 'list-view' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\tconst { caption, alt, url } = attributes;\n\n\t\t\tif ( ! url ) {\n\t\t\t\treturn __( 'Empty' );\n\t\t\t}\n\n\t\t\tif ( ! alt ) {\n\t\t\t\treturn caption || '';\n\t\t\t}\n\n\t\t\t// This is intended to be read by a screen reader.\n\t\t\t// A period simply means a pause, no need to translate it.\n\t\t\treturn alt + ( caption ? '. ' + caption : '' );\n\t\t}\n\t},\n\tgetEditWrapperProps( attributes ) {\n\t\treturn {\n\t\t\t'data-align': attributes.align,\n\t\t};\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'image',\n\t\t\tlabel: __( 'Image' ),\n\t\t\ttype: 'media',\n\t\t\tmapping: {\n\t\t\t\tid: 'id',\n\t\t\t\turl: 'url',\n\t\t\t\tcaption: 'caption',\n\t\t\t\talt: 'alt',\n\t\t\t},\n\t\t\targs: {\n\t\t\t\tallowedTypes: [ 'image' ],\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'link',\n\t\t\tlabel: __( 'Link' ),\n\t\t\ttype: 'link',\n\t\t\tmapping: {\n\t\t\t\turl: 'href',\n\t\t\t\trel: 'rel',\n\t\t\t\tlinkTarget: 'linkTarget',\n\t\t\t\tdestination: 'linkDestination',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'caption',\n\t\t\tlabel: __( 'Caption' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t\t{\n\t\t\tid: 'alt',\n\t\t\tlabel: __( 'Alt text' ),\n\t\t\ttype: 'text',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'image' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/image/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\turl,\n\t\talt,\n\t\tcaption,\n\t\talign,\n\t\thref,\n\t\trel,\n\t\tlinkClass,\n\t\twidth,\n\t\theight,\n\t\taspectRatio,\n\t\tscale,\n\t\tid,\n\t\tlinkTarget,\n\t\tsizeSlug,\n\t\ttitle,\n\t\tmetadata: { bindings = {} } = {},\n\t} = attributes;\n\n\tconst newRel = ! rel ? undefined : rel;\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst classes = clsx( {\n\t\t// All other align classes are handled by block supports.\n\t\t// `{ align: 'none' }` is unique to transforms for the image block.\n\t\talignnone: 'none' === align,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'is-resized': width || height,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst imageClasses = clsx( borderProps.className, {\n\t\t[ `wp-image-${ id }` ]: !! id,\n\t} );\n\n\tconst image = (\n\t\t<img\n\t\t\tsrc={ url }\n\t\t\talt={ alt }\n\t\t\tclassName={ imageClasses || undefined }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\t...shadowProps.style,\n\t\t\t\taspectRatio,\n\t\t\t\tobjectFit: scale,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t} }\n\t\t\ttitle={ title }\n\t\t/>\n\t);\n\n\tconst displayCaption =\n\t\t! RichText.isEmpty( caption ) ||\n\t\tbindings.caption ||\n\t\tbindings?.__default?.source === 'core/pattern-overrides';\n\n\tconst figure = (\n\t\t<>\n\t\t\t{ href ? (\n\t\t\t\t<a\n\t\t\t\t\tclassName={ linkClass }\n\t\t\t\t\thref={ href }\n\t\t\t\t\ttarget={ linkTarget }\n\t\t\t\t\trel={ newRel }\n\t\t\t\t>\n\t\t\t\t\t{ image }\n\t\t\t\t</a>\n\t\t\t) : (\n\t\t\t\timage\n\t\t\t) }\n\t\t\t{ displayCaption && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<figure { ...useBlockProps.save( { className: classes } ) }>\n\t\t\t{ figure }\n\t\t</figure>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a customizable podcast block enabling users to choose and play episodes, with comprehensive configuration settings for podcast URL, episode selection, display quantity, and additional parameters." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/podcast-player/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/podcast-player\",\n\t\"title\": \"Podcast Player\",\n\t\"description\": \"Select and play episodes from a single podcast.\",\n\t\"keywords\": [ \"audio\", \"embed\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m22,6h-5v8.18c-.31-.11-.65-.18-1-.18-1.66,0-3,1.34-3,3s1.34,3,3,3,3-1.34,3-3v-9h3v-2h0Zm-7,0H3v2h12v-2h0Zm0,4H3v2h12v-2h0Zm-4,4H3v2h8v-2h0Zm4,3c0-.55.45-1,1-1s1,.45,1,1-.45,1-1,1-1-.45-1-1Z' /></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"anchor\": false,\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true\n\t},\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"selectedEpisodes\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"itemsToShow\": {\n\t\t\t\"type\": \"integer\",\n\t\t\t\"default\": 5\n\t\t},\n\t\t\"showCoverArt\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showEpisodeTitle\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showEpisodeDescription\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"primaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customPrimaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hexPrimaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"secondaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customSecondaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hexSecondaryColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"backgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"hexBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"exampleFeedData\": {\n\t\t\t\"type\": \"object\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"customPrimaryColor\": \"GREEN\",\n\t\t\t\"hexPrimaryColor\": \"GREEN\",\n\t\t\t\"exampleFeedData\": {\n\t\t\t\t\"title\": \"Jetpack Example Podcast\",\n\t\t\t\t\"link\": \"https://jetpack.com\",\n\t\t\t\t\"cover\": \"https://jetpackme.files.wordpress.com/2020/05/jetpack-example-podcast-cover.png?w=160\",\n\t\t\t\t\"tracks\": [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": \"3\",\n\t\t\t\t\t\t\"title\": \"3. Our third episode\",\n\t\t\t\t\t\t\"duration\": \"14:58\"\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": \"2\",\n\t\t\t\t\t\t\"title\": \"2. Interview with a special guest\",\n\t\t\t\t\t\t\"duration\": \"19:17\"\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": \"1\",\n\t\t\t\t\t\t\"title\": \"1. Welcome to Example Podcast\",\n\t\t\t\t\t\t\"duration\": \"11:25\"\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/podcast-player/edit.js\nimport { isWpcomPlatformSite } from '@automattic/jetpack-script-data';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\twithColors,\n\tPanelColorSettings,\n\tContrastChecker,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\tButton,\n\tExternalLink,\n\tPanelBody,\n\tPlaceholder,\n\tRangeControl,\n\tTextControl,\n\tToolbarButton,\n\tToolbarGroup,\n\twithNotices,\n\tToggleControl,\n\tSpinner,\n\tComboboxControl,\n} from '@wordpress/components';\nimport { compose, withInstanceId } from '@wordpress/compose';\nimport { withDispatch } from '@wordpress/data';\nimport { useCallback, useEffect, useState, useRef, useReducer, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport debugFactory from 'debug';\nimport { debounce } from 'lodash';\nimport { applyFallbackStyles } from '../../shared/apply-fallback-styles';\nimport { maybeCopyElementsToSiteEditorContext } from '../../shared/block-editor-asset-loader';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport { fetchPodcastFeed, fetchTrackQuantity } from './api';\nimport metadata from './block.json';\nimport PodcastPlayer from './components/podcast-player';\nimport { PODCAST_FEED, EMBED_BLOCK } from './constants';\nimport { queueMusic } from './icons/';\nimport { podcastPlayerReducer, actions } from './state';\nimport { makeCancellable } from './utils';\n\nimport './editor.scss';\n\nconst DEFAULT_MIN_ITEMS = 1;\nconst debug = debugFactory( 'jetpack:podcast-player:edit' );\nconst noop = () => {};\n\n// Support page link.\nconst supportUrl = isWpcomPlatformSite()\n\t? 'http://en.support.wordpress.com/wordpress-editor/blocks/podcast-player-block/'\n\t: 'https://jetpack.com/support/jetpack-blocks/podcast-player-block/';\n\nconst PodcastPlayerEdit = ( {\n\tinstanceId,\n\tattributes,\n\tsetAttributes,\n\tnoticeOperations: { createErrorNotice, removeAllNotices },\n\tnoticeUI,\n\tprimaryColor: primaryColorProp,\n\tsetPrimaryColor,\n\tsecondaryColor: secondaryColorProp,\n\tsetSecondaryColor,\n\tfallbackTextColor,\n\tbackgroundColor: backgroundColorProp,\n\tsetBackgroundColor,\n\tfallbackBackgroundColor,\n\tisSelected,\n\treplaceWithEmbedBlock,\n} ) => {\n\t// Validated attributes.\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\tconst {\n\t\turl,\n\t\tselectedEpisodes,\n\t\titemsToShow,\n\t\tshowCoverArt,\n\t\tshowEpisodeTitle,\n\t\tshowEpisodeDescription,\n\t\texampleFeedData,\n\t} = validatedAttributes;\n\n\tconst playerId = `jetpack-podcast-player-block-${ instanceId }`;\n\n\tconst blockProps = useBlockProps();\n\tconst [ hasMigratedStyles, setHasMigratedStyles ] = useState( false );\n\tconst [ defaultMaxItems, setDefaultMaxItems ] = useState( 10 );\n\n\t// State.\n\tconst cancellableFetch = useRef( undefined );\n\tconst [ { selectedGuid, checkUrl, ...state }, dispatch ] = useReducer( podcastPlayerReducer, {\n\t\teditedUrl: url || '',\n\t\tisEditing: ! url && ! exampleFeedData,\n\t\tisLoading: false,\n\t\tfeedData: exampleFeedData || {},\n\t\tisInteractive: false,\n\t\tselectedGuid: selectedEpisodes?.[ 0 ]?.guid,\n\t\tcheckUrl: url || '',\n\t} );\n\n\tconst fetchFeed = useMemo(\n\t\t() =>\n\t\t\tdebounce( requestParams => {\n\t\t\t\tdispatch( { type: actions.START_FETCH } );\n\t\t\t\tcancellableFetch.current?.cancel();\n\t\t\t\tcancellableFetch.current = makeCancellable(\n\t\t\t\t\tfetchPodcastFeed( { ...requestParams, fetchEpisodeOptions: true } )\n\t\t\t\t);\n\n\t\t\t\tcancellableFetch.current.promise.then(\n\t\t\t\t\tresponse => {\n\t\t\t\t\t\tremoveAllNotices();\n\t\t\t\t\t\tif ( response?.isCanceled ) {\n\t\t\t\t\t\t\tdebug( 'Block was unmounted during fetch', response );\n\t\t\t\t\t\t\treturn; // bail if canceled to avoid setting state\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check what type of response we got and act accordingly.\n\t\t\t\t\t\tswitch ( response?.type ) {\n\t\t\t\t\t\t\tcase PODCAST_FEED:\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\turl: requestParams.url,\n\t\t\t\t\t\t\t\t\tselectedEpisodes: requestParams.guids.map( guid => ( { guid } ) ),\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\treturn dispatch( { type: actions.FEED_RECEIVED, payload: response.data } );\n\t\t\t\t\t\t\tcase EMBED_BLOCK:\n\t\t\t\t\t\t\t\treturn replaceWithEmbedBlock();\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\terror => {\n\t\t\t\t\t\tif ( error?.isCanceled ) {\n\t\t\t\t\t\t\tdebug( 'Block was unmounted during fetch', error );\n\t\t\t\t\t\t\treturn; // bail if canceled to avoid setting state\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Show error and allow to edit URL.\n\t\t\t\t\t\tdebug( 'feed error', error );\n\t\t\t\t\t\tremoveAllNotices();\n\t\t\t\t\t\tcreateErrorNotice(\n\t\t\t\t\t\t\t// Error messages already come localized.\n\t\t\t\t\t\t\terror.message ||\n\t\t\t\t\t\t\t\t// Fallback to a generic message.\n\t\t\t\t\t\t\t\t__( \"Your podcast couldn't be embedded. Please double check your URL.\", 'jetpack' )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdispatch( { type: actions.START_EDITING } );\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}, 300 ),\n\t\t[ replaceWithEmbedBlock, setAttributes, createErrorNotice, removeAllNotices ]\n\t);\n\n\t// Call once on mount or unmount (the return callback).\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tcancellableFetch?.current?.cancel?.();\n\t\t};\n\t}, [] );\n\n\t// The Podcast player audio element requires wpmedialement styles.\n\t// These aren't available in the Site Editor context, so we have to copy them in.\n\tconst podCastPlayerRef = useCallback(\n\t\tnode => {\n\t\t\tif ( node !== null && ! hasMigratedStyles ) {\n\t\t\t\tmaybeCopyElementsToSiteEditorContext(\n\t\t\t\t\t[ 'link#mediaelement-css', 'link#wp-mediaelement-css' ],\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tsetHasMigratedStyles( true );\n\t\t\t}\n\t\t},\n\t\t[ hasMigratedStyles ]\n\t);\n\n\t// Load RSS feed initially and when the feed or selected episode changes.\n\tuseEffect( () => {\n\t\t// Don't do anything if no url is set.\n\t\tif ( '' === checkUrl ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfetchFeed( {\n\t\t\turl: checkUrl,\n\t\t\tguids: selectedGuid ? [ selectedGuid ] : [],\n\t\t} );\n\n\t\treturn () => cancellableFetch?.current?.cancel?.();\n\t}, [ fetchFeed, checkUrl, selectedGuid ] );\n\n\t// Retrieve tracks quantity to fetch; the jetpack_podcast_helper_tracks_quantity filter value.\n\tuseEffect( () => {\n\t\tfetchTrackQuantity().then( response => {\n\t\t\tsetDefaultMaxItems( response );\n\t\t} );\n\t}, [] );\n\n\t// Make sure itemsToShow is 1 when we have a selected episode\n\tuseEffect( () => {\n\t\tif ( selectedGuid && 1 !== itemsToShow ) {\n\t\t\tsetAttributes( { itemsToShow: 1 } );\n\t\t}\n\t}, [ selectedGuid, itemsToShow, setAttributes ] );\n\n\t// Bring back the overlay after block gets deselected.\n\tuseEffect( () => {\n\t\tif ( ! isSelected && state.isInteractive ) {\n\t\t\tdispatch( { type: actions.PREVENT_INTERACTIONS } );\n\t\t}\n\t}, [ isSelected, state.isInteractive ] );\n\n\t/**\n\t * Check if the current URL of the Podcast RSS feed is valid. If so, set the\n\t * block attribute and changes the edition mode. This function is bound to the\n\t * onSubmit event for the form.\n\t *\n\t * @param {object} event - Form on submit event object.\n\t */\n\tconst checkPodcastLink = event => {\n\t\tevent.preventDefault();\n\n\t\tif ( '' === state.editedUrl ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Ensure URL has `http` appended to it (if it doesn't already) before we\n\t\t * accept it as the entered URL.\n\t\t */\n\t\tconst prependedURL = prependHTTP( state.editedUrl );\n\n\t\tif ( ! isURL( prependedURL ) ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\t__( \"Your podcast couldn't be embedded. Please double check your URL.\", 'jetpack' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Short-circuit feed fetching if we tried before, use useEffect otherwise.\n\t\t * @see {@link https://github.com/Automattic/jetpack/pull/15213}\n\t\t */\n\t\tif ( prependedURL === checkUrl ) {\n\t\t\t// Reset the feedData, so that we display the spinner.\n\t\t\tdispatch( { type: actions.CLEAR_FEED } );\n\t\t\tfetchFeed( {\n\t\t\t\turl: checkUrl,\n\t\t\t\tguids: selectedEpisodes[ 0 ]?.guid ? [ selectedEpisodes[ 0 ].guid ] : [],\n\t\t\t} );\n\t\t} else {\n\t\t\tdispatch( { type: actions.CHECK_URL, payload: prependedURL } );\n\t\t}\n\n\t\t/*\n\t\t * Also update the temporary `input` value in order that clicking `Replace`\n\t\t * in the UI will show the \"corrected\" version of the URL (ie: with `http`\n\t\t * prepended if it wasn't originally present).\n\t\t */\n\t\tdispatch( { type: actions.FINISH_EDITING, payload: prependedURL } );\n\t};\n\n\tlet content;\n\n\tif ( state.isEditing ) {\n\t\tcontent = (\n\t\t\t<Placeholder\n\t\t\t\ticon={ queueMusic }\n\t\t\t\tlabel={ __( 'Podcast Player', 'jetpack' ) }\n\t\t\t\tinstructions={ __( 'Enter your podcast RSS feed URL.', 'jetpack' ) }\n\t\t\t\tclassName={ 'jetpack-podcast-player__placeholder' }\n\t\t\t>\n\t\t\t\t<form onSubmit={ checkPodcastLink }>\n\t\t\t\t\t{ noticeUI }\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\tinputMode=\"url\"\n\t\t\t\t\t\tplaceholder={ __( 'Enter URL here…', 'jetpack' ) }\n\t\t\t\t\t\tvalue={ state.editedUrl }\n\t\t\t\t\t\tclassName={ 'components-placeholder__input' }\n\t\t\t\t\t\tonChange={ editedUrl => dispatch( { type: actions.EDIT_URL, payload: editedUrl } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t{ __( 'Embed', 'jetpack' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</form>\n\t\t\t\t<div className=\"components-placeholder__learn-more\">\n\t\t\t\t\t<ExternalLink href={ supportUrl }>\n\t\t\t\t\t\t{ __( 'Learn more about embeds', 'jetpack' ) }\n\t\t\t\t\t</ExternalLink>\n\t\t\t\t</div>\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\t// With no tracks data, this is either the first load or the URL has changed\n\t// and we need the data to refresh before displaying the other controls.\n\telse if ( ! state.feedData.tracks?.length ) {\n\t\tcontent = (\n\t\t\t<Placeholder\n\t\t\t\ticon={ queueMusic }\n\t\t\t\tlabel={ __( 'Podcast Player', 'jetpack' ) }\n\t\t\t\tinstructions={ __( 'Loading podcast feed…', 'jetpack' ) }\n\t\t\t>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t} else {\n\t\tconst createColorChangeHandler = ( colorAttr, handler ) => color => {\n\t\t\tsetAttributes( { [ colorAttr ]: color } );\n\t\t\thandler( color );\n\t\t};\n\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\taria-label={ __( 'Edit Podcast Feed URL', 'jetpack' ) }\n\t\t\t\t\t\t\tonClick={ () => dispatch( { type: actions.START_EDITING } ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Replace', 'jetpack' ) }\n\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t</BlockControls>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Podcast settings', 'jetpack' ) }>\n\t\t\t\t\t\t{ ( ComboboxControl || 0 === selectedEpisodes.length ) && (\n\t\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Number of items', 'jetpack' ) }\n\t\t\t\t\t\t\t\tvalue={ itemsToShow }\n\t\t\t\t\t\t\t\tonChange={ value => setAttributes( { itemsToShow: selectedGuid ? 1 : value } ) }\n\t\t\t\t\t\t\t\tmin={ DEFAULT_MIN_ITEMS }\n\t\t\t\t\t\t\t\tmax={ defaultMaxItems }\n\t\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t\t\tdisabled={ !! selectedGuid }\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ComboboxControl && (\n\t\t\t\t\t\t\t<ComboboxControl\n\t\t\t\t\t\t\t\tclassName=\"jetpack-podcast-player__episode-selector\"\n\t\t\t\t\t\t\t\tvalue={ selectedGuid }\n\t\t\t\t\t\t\t\tonChange={ guid => dispatch( { type: actions.SELECT_EPISODE, payload: guid } ) }\n\t\t\t\t\t\t\t\toptions={ state.feedData.options || [] }\n\t\t\t\t\t\t\t\tlabel={ __( 'Episode', 'jetpack' ) }\n\t\t\t\t\t\t\t\tonFilterValueChange={ noop }\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show Cover Art', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showCoverArt }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { showCoverArt: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show Episode Title', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showEpisodeTitle }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { showEpisodeTitle: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show Episode Description', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showEpisodeDescription }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { showEpisodeDescription: value } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t\t<PanelColorSettings\n\t\t\t\t\t\ttitle={ __( 'Color Settings', 'jetpack' ) }\n\t\t\t\t\t\tcolorSettings={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: primaryColorProp.color,\n\t\t\t\t\t\t\t\tonChange: createColorChangeHandler( 'hexPrimaryColor', setPrimaryColor ),\n\t\t\t\t\t\t\t\tlabel: __( 'Primary Color', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: secondaryColorProp.color,\n\t\t\t\t\t\t\t\tonChange: createColorChangeHandler( 'hexSecondaryColor', setSecondaryColor ),\n\t\t\t\t\t\t\t\tlabel: __( 'Secondary Color', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: backgroundColorProp.color,\n\t\t\t\t\t\t\t\tonChange: createColorChangeHandler( 'hexBackgroundColor', setBackgroundColor ),\n\t\t\t\t\t\t\t\tlabel: __( 'Background Color', 'jetpack' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t] }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ContrastChecker\n\t\t\t\t\t\t\tisLargeText={ false }\n\t\t\t\t\t\t\ttextColor={ secondaryColorProp.color }\n\t\t\t\t\t\t\tbackgroundColor={ backgroundColorProp.color }\n\t\t\t\t\t\t\tfallbackBackgroundColor={ fallbackBackgroundColor }\n\t\t\t\t\t\t\tfallbackTextColor={ fallbackTextColor }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelColorSettings>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t<div id={ playerId } ref={ podCastPlayerRef }>\n\t\t\t\t\t<PodcastPlayer\n\t\t\t\t\t\tplayerId={ playerId }\n\t\t\t\t\t\tattributes={ validatedAttributes }\n\t\t\t\t\t\ttracks={ state.feedData.tracks }\n\t\t\t\t\t\tcover={ state.feedData.cover }\n\t\t\t\t\t\ttitle={ state.feedData.title }\n\t\t\t\t\t\tlink={ state.feedData.link }\n\t\t\t\t\t/>\n\t\t\t\t\t{ /*\n\t\t\t\t\t * Disabled because the overlay div doesn't actually have a role or\n\t\t\t\t\t * functionality as far as the user is concerned. We're just catching\n\t\t\t\t\t * the first click so that the block can be selected without\n\t\t\t\t\t * interacting with the embed preview that the overlay covers.\n\t\t\t\t\t */ }\n\t\t\t\t\t{ /* eslint-disable jsx-a11y/no-static-element-interactions */ }\n\t\t\t\t\t{ ! state.isInteractive && ! state.isLoading && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"jetpack-podcast-player__interactive-overlay\"\n\t\t\t\t\t\t\tonMouseUp={ () => dispatch( { type: actions.MAKE_INTERACTIVE } ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ /* eslint-enable jsx-a11y/no-static-element-interactions */ }\n\t\t\t\t\t{ state.isLoading && (\n\t\t\t\t\t\t<div className=\"jetpack-podcast-player__loading-overlay\">\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default compose( [\n\twithDispatch( ( dispatch, { clientId, attributes } ) => {\n\t\treturn {\n\t\t\treplaceWithEmbedBlock() {\n\t\t\t\tdispatch( 'core/block-editor' ).replaceBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tcreateBlock( 'core/embed', {\n\t\t\t\t\t\turl: attributes.url,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t} ),\n\twithColors( 'backgroundColor', { primaryColor: 'color' }, { secondaryColor: 'color' } ),\n\twithNotices,\n\twithInstanceId,\n\tapplyFallbackStyles,\n] )( PodcastPlayerEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/podcast-player/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst { url } = attributes;\n\tif ( ! url || url === '' ) {\n\t\treturn;\n\t}\n\n\tconst blockProps = useBlockProps.save();\n\treturn (\n\t\t<a\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx( blockProps.className, 'jetpack-podcast-player__direct-link' ) }\n\t\t\thref={ url }\n\t\t>\n\t\t\t{ url }\n\t\t</a>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display post author details such as name, avatar, and bio. that allows users to configure: text align, avatar size, show avatar, and 4 more options" }, { "role": "assistant", "content": "// File: packages/block-library/src/post-author/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-author\",\n\t\"title\": \"Author\",\n\t\"category\": \"theme\",\n\t\"description\": \"Display post author details such as name, avatar, and bio.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"avatarSize\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 48\n\t\t},\n\t\t\"showAvatar\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showBio\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"byline\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postType\", \"postId\", \"queryId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"filter\": {\n\t\t\t\"duotone\": true\n\t\t}\n\t},\n\t\"selectors\": {\n\t\t\"filter\": {\n\t\t\t\"duotone\": \".wp-block-post-author .wp-block-post-author__avatar img\"\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-post-author-editor\",\n\t\"style\": \"wp-block-post-author\"\n}\n\n\n// File: packages/block-library/src/post-author/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { postAuthor as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tviewportWidth: 350,\n\t\tattributes: {\n\t\t\tshowBio: true,\n\t\t\tbyline: __( 'Posted by' ),\n\t\t},\n\t},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a plugin that Adds infinite scrolling support to the front-end blog post view for themes, pulling the next set of posts automatically into view when the reader approaches the bottom of the page. with the following capabilities: settings api, enqueue scripts" }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/modules/infinite-scroll/infinity.php\n<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName\n\n// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.\n\nuse Automattic\\Jetpack\\Assets;\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/*\nPlugin Name: The Neverending Home Page.\nPlugin URI: https://automattic.com/\nDescription: Adds infinite scrolling support to the front-end blog post view for themes, pulling the next set of posts automatically into view when the reader approaches the bottom of the page.\nVersion: 1.1\nAuthor: Automattic\nAuthor URI: https://automattic.com/\nLicense: GNU General Public License v2 or later\nLicense URI: https://www.gnu.org/licenses/gpl-2.0.html\nText Domain: jetpack\n*/\n\n/**\n * Class: The_Neverending_Home_Page relies on add_theme_support, expects specific\n * styling from each theme; including fixed footer.\n *\n * @phan-constructor-used-for-side-effects\n */\nclass The_Neverending_Home_Page {\n\t/**\n\t* Maximum allowed number of posts per page in $_REQUEST.\n\t*/\n\tconst MAX_ALLOWED_POSTS_PER_PAGE_ΙΝ_REQUEST = 5000;\n\n\t/**\n\t * Register actions and filters, plus parse IS settings\n\t *\n\t * @uses add_action, add_filter, self::get_settings\n\t */\n\tpublic function __construct() {\n\t\tadd_action( 'pre_get_posts', array( $this, 'posts_per_page_query' ) );\n\t\tadd_action( 'admin_init', array( $this, 'settings_api_init' ) );\n\t\tadd_action( 'template_redirect', array( $this, 'action_template_redirect' ) );\n\t\tadd_action( 'customize_preview_init', array( $this, 'init_customizer_assets' ) );\n\t\tadd_action( 'template_redirect', array( $this, 'ajax_response' ) );\n\t\tadd_action( 'custom_ajax_infinite_scroll', array( $this, 'query' ) );\n\t\tadd_filter( 'infinite_scroll_query_args', array( $this, 'inject_query_args' ) );\n\t\tadd_filter( 'infinite_scroll_allowed_vars', array( $this, 'allowed_query_vars' ) );\n\t\tadd_action( 'the_post', array( $this, 'preserve_more_tag' ) );\n\t\tadd_action( 'wp_footer', array( $this, 'footer' ) );\n\t\tadd_filter( 'infinite_scroll_additional_scripts', array( $this, 'add_mejs_config' ) );\n\n\t\t// Plugin compatibility\n\t\tadd_filter( 'grunion_contact_form_redirect_url', array( $this, 'filter_grunion_redirect_url' ) );\n\n\t\t// AMP compatibility\n\t\t// needs to happen after parse_query so that Jetpack_AMP_Support::is_amp_request() is ready.\n\t\tadd_action( 'wp', array( $this, 'amp_load_hooks' ) );\n\n\t\t// Parse IS settings from theme\n\t\tself::get_settings();\n\t}\n\n\t/**\n\t * Initialize our static variables\n\t */\n\n\t/**\n\t * The time.\n\t *\n\t * @var null - I don't think this is used?\n\t */\n\tpublic static $the_time = null;\n\n\t/**\n\t * Settings.\n\t *\n\t * Don't access directly, instead use self::get_settings().\n\t *\n\t * @var array\n\t */\n\tpublic static $settings = null;\n\n\t/**\n\t * The enabled option name.\n\t *\n\t * @var string\n\t */\n\tpublic static $option_name_enabled = 'infinite_scroll';\n\n\t/**\n\t * Parse IS settings provided by theme\n\t *\n\t * @uses get_theme_support, infinite_scroll_has_footer_widgets, sanitize_title, add_action, get_option, wp_parse_args, is_active_sidebar\n\t * @return object\n\t */\n\tpublic static function get_settings() {\n\t\t$defaults = array(\n\t\t\t'type' => 'scroll', // scroll | click\n\t\t\t'requested_type' => 'scroll', // store the original type for use when logic overrides it\n\t\t\t'footer_widgets' => false, // true | false | sidebar_id | array of sidebar_ids -- last two are checked with is_active_sidebar\n\t\t\t'container' => 'content', // container html id\n\t\t\t'wrapper' => true, // true | false | html class -- the html class.\n\t\t\t'render' => false, // optional function, otherwise the `content` template part will be used\n\t\t\t'footer' => true, // boolean to enable or disable the infinite footer | string to provide an html id to derive footer width from\n\t\t\t'footer_callback' => false, // function to be called to render the IS footer, in place of the default\n\t\t\t'posts_per_page' => false, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page -- int | false to set based on IS type\n\t\t\t'click_handle' => true, // boolean to enable or disable rendering the click handler div. If type is click and this is false, page must include its own trigger with the HTML ID `infinite-handle`.\n\t\t);\n\n\t\tif ( self::$settings === null ) {\n\t\t\t$css_pattern = '#[^A-Z\\d\\-_]#i';\n\n\t\t\t$settings = $defaults;\n\t\t\t// Validate settings passed through add_theme_support()\n\t\t\t$_settings = get_theme_support( 'infinite-scroll' );\n\n\t\t\tif ( is_array( $_settings ) ) {\n\t\t\t\t// Preferred implementation, where theme provides an array of options\n\t\t\t\tif ( isset( $_settings[0] ) && is_array( $_settings[0] ) ) {\n\t\t\t\t\tforeach ( $_settings[0] as $key => $value ) {\n\t\t\t\t\t\tswitch ( $key ) {\n\t\t\t\t\t\t\tcase 'type':\n\t\t\t\t\t\t\t\tif ( in_array( $value, array( 'scroll', 'click' ), true ) ) {\n\t\t\t\t\t\t\t\t\t$settings['requested_type'] = $value;\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $settings['requested_type'];\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'footer_widgets':\n\t\t\t\t\t\t\t\tif ( is_string( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = sanitize_title( $value );\n\t\t\t\t\t\t\t\t} elseif ( is_array( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = array_map( 'sanitize_title', $value );\n\t\t\t\t\t\t\t\t} elseif ( is_bool( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'container':\n\t\t\t\t\t\t\tcase 'wrapper':\n\t\t\t\t\t\t\t\tif ( 'wrapper' === $key && is_bool( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t$value = preg_replace( $css_pattern, '', $value );\n\n\t\t\t\t\t\t\t\t\tif ( ! empty( $value ) ) {\n\t\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'render':\n\t\t\t\t\t\t\t\tif ( false !== $value && is_callable( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'footer':\n\t\t\t\t\t\t\t\tif ( is_bool( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t} elseif ( is_string( $value ) ) {\n\t\t\t\t\t\t\t\t\t$value = preg_replace( $css_pattern, '', $value );\n\n\t\t\t\t\t\t\t\t\tif ( ! empty( $value ) ) {\n\t\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'footer_callback':\n\t\t\t\t\t\t\t\tif ( is_callable( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = false;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'posts_per_page':\n\t\t\t\t\t\t\t\tif ( is_numeric( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = (int) $value;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tcase 'click_handle':\n\t\t\t\t\t\t\t\tif ( is_bool( $value ) ) {\n\t\t\t\t\t\t\t\t\t$settings[ $key ] = $value;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} elseif ( is_string( $_settings[0] ) ) {\n\t\t\t\t\t// Checks below are for backwards compatibility\n\n\t\t\t\t\t// Container to append new posts to\n\t\t\t\t\t$settings['container'] = preg_replace( $css_pattern, '', $_settings[0] );\n\n\t\t\t\t\t// Wrap IS elements?\n\t\t\t\t\tif ( isset( $_settings[1] ) ) {\n\t\t\t\t\t\t$settings['wrapper'] = (bool) $_settings[1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Always ensure all values are present in the final array\n\t\t\t$settings = wp_parse_args( $settings, $defaults );\n\n\t\t\t// Check if a legacy `infinite_scroll_has_footer_widgets()` function is defined and override the footer_widgets parameter's value.\n\t\t\t// Otherwise, if a widget area ID or array of IDs was provided in the footer_widgets parameter, check if any contains any widgets.\n\t\t\t// It is safe to use `is_active_sidebar()` before the sidebar is registered as this function doesn't check for a sidebar's existence when determining if it contains any widgets.\n\t\t\tif ( function_exists( 'infinite_scroll_has_footer_widgets' ) ) {\n\t\t\t\t// @phan-suppress-next-line PhanUndeclaredFunction -- Checked above. See also https://github.com/phan/phan/issues/1204.\n\t\t\t\t$settings['footer_widgets'] = (bool) infinite_scroll_has_footer_widgets();\n\t\t\t} elseif ( is_array( $settings['footer_widgets'] ) ) {\n\t\t\t\t$sidebar_ids = $settings['footer_widgets'];\n\t\t\t\t$settings['footer_widgets'] = false;\n\n\t\t\t\tforeach ( $sidebar_ids as $sidebar_id ) {\n\t\t\t\t\tif ( is_active_sidebar( $sidebar_id ) ) {\n\t\t\t\t\t\t$settings['footer_widgets'] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tunset( $sidebar_ids );\n\t\t\t\tunset( $sidebar_id );\n\t\t\t} elseif ( is_string( $settings['footer_widgets'] ) ) {\n\t\t\t\t$settings['footer_widgets'] = (bool) is_active_sidebar( $settings['footer_widgets'] );\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Filter Infinite Scroll's `footer_widgets` parameter.\n\t\t\t *\n\t\t\t * @module infinite-scroll\n\t\t\t *\n\t\t\t * @since 2.0.0\n\t\t\t *\n\t\t\t * @param bool $settings['footer_widgets'] Does the current theme have Footer Widgets.\n\t\t\t */\n\t\t\t$settings['footer_widgets'] = apply_filters( 'infinite_scroll_has_footer_widgets', $settings['footer_widgets'] );\n\n\t\t\t// Finally, after all of the sidebar checks and filtering, ensure that a boolean value is present, otherwise set to default of `false`.\n\t\t\tif ( ! is_bool( $settings['footer_widgets'] ) ) {\n\t\t\t\t$settings['footer_widgets'] = false;\n\t\t\t}\n\n\t\t\t// Ensure that IS is enabled and no footer widgets exist if the IS type isn't already \"click\".\n\t\t\tif ( 'click' !== $settings['type'] ) {\n\t\t\t\t// Check the setting status\n\t\t\t\t$disabled = '' === get_option( self::$option_name_enabled ) ? true : false;\n\n\t\t\t\t// Footer content or Reading option check\n\t\t\t\tif ( $settings['footer_widgets'] || $disabled ) {\n\t\t\t\t\t$settings['type'] = 'click';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Force display of the click handler and attendant bits when the type isn't `click`\n\t\t\tif ( 'click' !== $settings['type'] ) {\n\t\t\t\t$settings['click_handle'] = true;\n\t\t\t}\n\n\t\t\t// Store final settings in a class static to avoid reparsing\n\t\t\tself::$settings = $settings;\n\t\t}\n\n\t\t/**\n\t\t * Filter the array of Infinite Scroll settings.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t *\n\t\t * @param array $settings Array of Infinite Scroll settings.\n\t\t */\n\t\t$filtered_settings = apply_filters( 'infinite_scroll_settings', self::$settings );\n\n\t\t// Ensure all properties are still set.\n\t\treturn (object) wp_parse_args( $filtered_settings, $defaults );\n\t}\n\n\t/**\n\t * Number of posts per page.\n\t *\n\t * @uses self::wp_query, self::get_settings, apply_filters\n\t * @return int\n\t */\n\tpublic static function posts_per_page() {\n\t\t$settings = self::get_settings();\n\t\t$posts_per_page = $settings->posts_per_page ? $settings->posts_per_page : self::wp_query()->get( 'posts_per_page' );\n\t\t$posts_per_page_core_option = get_option( 'posts_per_page' );\n\n\t\t// If Infinite Scroll is set to click, and if the site owner changed posts_per_page, let's use that.\n\t\tif (\n\t\t\t'click' === $settings->type\n\t\t\t\t&& ( '10' !== $posts_per_page_core_option )\n\t\t) {\n\t\t\t$posts_per_page = $posts_per_page_core_option;\n\t\t}\n\n\t\t// Take JS query into consideration here.\n\t\t$posts_per_page_in_request = isset( $_REQUEST['query_args']['posts_per_page'] ) ? (int) $_REQUEST['query_args']['posts_per_page'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended\n\t\tif ( $posts_per_page_in_request > 0 &&\n\t\t\tself::MAX_ALLOWED_POSTS_PER_PAGE_ΙΝ_REQUEST >= $posts_per_page_in_request\n\t\t) {\n\t\t\t$posts_per_page = $posts_per_page_in_request;\n\t\t}\n\n\t\t/**\n\t\t * Filter the number of posts per page.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 6.0.0\n\t\t *\n\t\t * @param int $posts_per_page The number of posts to display per page.\n\t\t */\n\t\treturn (int) apply_filters( 'infinite_scroll_posts_per_page', $posts_per_page );\n\t}\n\n\t/**\n\t * Retrieve the query used with Infinite Scroll\n\t *\n\t * @global $wp_the_query\n\t * @uses apply_filters\n\t * @return object\n\t */\n\tpublic static function wp_query() {\n\t\tglobal $wp_the_query;\n\t\t/**\n\t\t * Filter the Infinite Scroll query object.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.2.1\n\t\t *\n\t\t * @param WP_Query $wp_the_query WP Query.\n\t\t */\n\t\treturn apply_filters( 'infinite_scroll_query_object', $wp_the_query );\n\t}\n\n\t/**\n\t * Has infinite scroll been triggered?\n\t */\n\tpublic static function got_infinity() {\n\t\t/**\n\t\t * Filter the parameter used to check if Infinite Scroll has been triggered.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 3.9.0\n\t\t *\n\t\t * @param bool isset( $_GET[ 'infinity' ] ) Return true if the \"infinity\" parameter is set.\n\t\t */\n\t\treturn apply_filters( 'infinite_scroll_got_infinity', isset( $_GET['infinity'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.\n\t}\n\n\t/**\n\t * Is this guaranteed to be the last batch of posts?\n\t */\n\tpublic static function is_last_batch() {\n\t\t/**\n\t\t * Override whether or not this is the last batch for a request\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 4.8.0\n\t\t *\n\t\t * @param bool|null null Bool if value should be overridden, null to determine from query\n\t\t * @param object self::wp_query() WP_Query object for current request\n\t\t * @param object self::get_settings() Infinite Scroll settings\n\t\t */\n\t\t$override = apply_filters( 'infinite_scroll_is_last_batch', null, self::wp_query(), self::get_settings() ); // phpcs:ignore WordPress.WP.ClassNameCase.Incorrect -- False positive.\n\t\tif ( is_bool( $override ) ) {\n\t\t\treturn $override;\n\t\t}\n\n\t\t$entries = (int) self::wp_query()->found_posts;\n\t\t$posts_per_page = self::posts_per_page();\n\n\t\t// This is to cope with an issue in certain themes or setups where posts are returned but found_posts is 0.\n\t\tif ( 0 === $entries ) {\n\t\t\treturn ( ! is_countable( self::wp_query()->posts ) || ( count( self::wp_query()->posts ) < $posts_per_page ) );\n\t\t}\n\t\t$paged = max( 1, (int) self::wp_query()->get( 'paged' ) );\n\n\t\t// Are there enough posts for more than the first page?\n\t\tif ( $entries <= $posts_per_page ) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Calculate entries left after a certain number of pages\n\t\tif ( $paged && $paged > 1 ) {\n\t\t\t$entries -= $posts_per_page * $paged;\n\t\t}\n\n\t\t// Are there some entries left to display?\n\t\treturn $entries <= 0;\n\t}\n\n\t/**\n\t * The more tag will be ignored by default if the blog page isn't our homepage.\n\t * Let's force the $more global to false.\n\t *\n\t * @param array $array - the_post array.\n\t * @return array\n\t */\n\tpublic function preserve_more_tag( $array ) {\n\t\tglobal $more;\n\n\t\tif ( self::got_infinity() ) {\n\t\t\t$more = 0; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- 0 = show content up to the more tag. Add more link.\n\t\t}\n\n\t\treturn $array;\n\t}\n\n\t/**\n\t * Add a checkbox field to Settings > Reading\n\t * for enabling infinite scroll.\n\t *\n\t * Only show if the current theme supports infinity.\n\t *\n\t * @uses current_theme_supports, add_settings_field, __, register_setting\n\t * @action admin_init\n\t * @return null\n\t */\n\tpublic function settings_api_init() {\n\t\tif ( ! current_theme_supports( 'infinite-scroll' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Add the setting field [infinite_scroll] and place it in Settings > Reading\n\t\tadd_settings_field( self::$option_name_enabled, '<span id=\"infinite-scroll-options\">' . esc_html__( 'Infinite Scroll Behavior', 'jetpack' ) . '</span>', array( $this, 'infinite_setting_html' ), 'reading' );\n\t\tregister_setting( 'reading', self::$option_name_enabled, 'esc_attr' );\n\t}\n\n\t/**\n\t * HTML code to display a checkbox true/false option\n\t * for the infinite_scroll setting.\n\t */\n\tpublic function infinite_setting_html() {\n\t\t$settings = self::get_settings();\n\n\t\t// If the blog has footer widgets, show a notice instead of the checkbox\n\t\tif ( $settings->footer_widgets || 'click' === $settings->requested_type ) {\n\t\t\techo '<label><em>' . esc_html__( 'We&rsquo;ve changed this option to a click-to-scroll version for you since you have footer widgets in Appearance &rarr; Widgets, or your theme uses click-to-scroll as the default behavior.', 'jetpack' ) . '</em></label>';\n\t\t} else {\n\t\t\techo '<label><input name=\"infinite_scroll\" type=\"checkbox\" value=\"1\" ' . checked( 1, '' !== get_option( self::$option_name_enabled ), false ) . ' /> ' . esc_html__( 'Check to load posts as you scroll. Uncheck to show clickable button to load posts', 'jetpack' ) . '</label>';\n\t\t\t// translators: the number of posts to show on each page load.\n\t\t\techo '<p class=\"description\">' . esc_html( sprintf( _n( 'Shows %s post on each load.', 'Shows %s posts on each load.', self::posts_per_page(), 'jetpack' ), number_format_i18n( self::posts_per_page() ) ) ) . '</p>';\n\t\t}\n\t}\n\n\t/**\n\t * Does the legwork to determine whether the feature is enabled.\n\t *\n\t * @uses current_theme_supports, self::archive_supports_infinity, self::get_settings, add_filter, wp_enqueue_script, plugins_url, wp_enqueue_style, add_action\n\t * @action template_redirect\n\t * @return null\n\t */\n\tpublic function action_template_redirect() {\n\t\t// Check that we support infinite scroll, and are on the home page.\n\t\tif ( ! current_theme_supports( 'infinite-scroll' ) || ! self::archive_supports_infinity() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$id = self::get_settings()->container;\n\n\t\t// Check that we have an id.\n\t\tif ( empty( $id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// AMP infinite scroll functionality will start on amp_load_hooks().\n\t\tif ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Add our scripts.\n\t\twp_register_script(\n\t\t\t'the-neverending-homepage',\n\t\t\tAssets::get_file_url_for_environment(\n\t\t\t\t'_inc/build/infinite-scroll/infinity.min.js',\n\t\t\t\t'modules/infinite-scroll/infinity.js'\n\t\t\t),\n\t\t\tarray(),\n\t\t\tJETPACK__VERSION . '-is5.0.1', // Added for ability to cachebust on WP.com.\n\t\t\ttrue\n\t\t);\n\n\t\t// Add our default styles.\n\t\twp_register_style( 'the-neverending-homepage', plugins_url( 'infinity.css', __FILE__ ), array(), '20140422' );\n\n\t\t// Make sure there are enough posts for IS\n\t\tif ( self::is_last_batch() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Add our scripts.\n\t\twp_enqueue_script( 'the-neverending-homepage' );\n\n\t\t// Add our default styles.\n\t\twp_enqueue_style( 'the-neverending-homepage' );\n\n\t\tadd_action( 'wp_footer', array( $this, 'action_wp_footer_settings' ), 2 );\n\n\t\tadd_action( 'wp_footer', array( $this, 'action_wp_footer' ), 21 ); // Core prints footer scripts at priority 20, so we just need to be one later than that\n\n\t\tadd_filter( 'infinite_scroll_results', array( $this, 'filter_infinite_scroll_results' ), 10, 3 );\n\t}\n\n\t/**\n\t * Initialize the Customizer logic separately from the main JS.\n\t *\n\t * @since 8.4.0\n\t */\n\tpublic function init_customizer_assets() {\n\t\t// Add our scripts.\n\t\twp_register_script(\n\t\t\t'the-neverending-homepage-customizer',\n\t\t\tAssets::get_file_url_for_environment(\n\t\t\t\t'_inc/build/infinite-scroll/infinity-customizer.min.js',\n\t\t\t\t'modules/infinite-scroll/infinity-customizer.js'\n\t\t\t),\n\t\t\tarray( 'jquery', 'customize-base' ),\n\t\t\tJETPACK__VERSION . '-is5.0.0', // Added for ability to cachebust on WP.com.\n\t\t\ttrue\n\t\t);\n\n\t\twp_enqueue_script( 'the-neverending-homepage-customizer' );\n\t}\n\n\t/**\n\t * Returns classes to be added to <body>. If it's enabled, 'infinite-scroll'. If set to continuous scroll, adds 'neverending' too.\n\t *\n\t * @since 4.7.0 No longer added as a 'body_class' filter but passed to JS environment and added using JS.\n\t *\n\t * @return string\n\t */\n\tpublic function body_class() {\n\t\t$settings = self::get_settings();\n\t\t$classes = '';\n\t\t// Do not add infinity-scroll class if disabled through the Reading page\n\t\t$disabled = '' === get_option( self::$option_name_enabled ) ? true : false;\n\t\tif ( ! $disabled || 'click' === $settings->type ) {\n\t\t\t$classes = 'infinite-scroll';\n\n\t\t\tif ( 'scroll' === $settings->type ) {\n\t\t\t\t$classes .= ' neverending';\n\t\t\t}\n\t\t}\n\n\t\treturn $classes;\n\t}\n\n\t/**\n\t * In case IS is activated on search page, we have to exclude initially loaded posts which match the keyword by title, not the content as they are displayed before content-matching ones\n\t *\n\t * @uses self::wp_query\n\t * @uses self::get_last_post_date\n\t * @uses self::has_only_title_matching_posts\n\t * @return array\n\t */\n\tpublic function get_excluded_posts() {\n\n\t\t$excluded_posts = array();\n\t\t// loop through posts returned by wp_query call\n\t\tforeach ( self::wp_query()->get_posts() as $post ) {\n\t\t\tif ( ! $post instanceof \\WP_Post ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t$orderby = isset( self::wp_query()->query_vars['orderby'] ) ? self::wp_query()->query_vars['orderby'] : '';\n\t\t\t$post_date = ( ! empty( $post->post_date ) ? $post->post_date : false );\n\t\t\tif ( 'modified' === $orderby || false === $post_date ) {\n\t\t\t\t$post_date = $post->post_modified;\n\t\t\t}\n\n\t\t\t// in case all posts initially displayed match the keyword by title we add em all to excluded posts array\n\t\t\t// else, we add only posts which are older than last_post_date param as newer are natually excluded by last_post_date condition in the SQL query\n\t\t\tif ( self::has_only_title_matching_posts() || $post_date <= self::get_last_post_date() ) {\n\t\t\t\tarray_push( $excluded_posts, $post->ID );\n\t\t\t}\n\t\t}\n\t\treturn $excluded_posts;\n\t}\n\n\t/**\n\t * In case IS is active on search, we have to exclude posts matched by title rather than by post_content in order to prevent dupes on next pages\n\t *\n\t * @uses self::wp_query\n\t * @uses self::get_excluded_posts\n\t * @return array\n\t */\n\tpublic function get_query_vars() {\n\n\t\t$query_vars = self::wp_query()->query_vars;\n\t\t// applies to search page only\n\t\tif ( true === self::wp_query()->is_search() ) {\n\t\t\t// set post__not_in array in query_vars in case it does not exists\n\t\t\tif ( false === isset( $query_vars['post__not_in'] ) ) {\n\t\t\t\t$query_vars['post__not_in'] = array();\n\t\t\t}\n\t\t\t// get excluded posts\n\t\t\t$excluded = self::get_excluded_posts();\n\t\t\t// merge them with other post__not_in posts (eg.: sticky posts)\n\t\t\t$query_vars['post__not_in'] = array_merge( $query_vars['post__not_in'], $excluded );\n\t\t}\n\t\treturn $query_vars;\n\t}\n\n\t/**\n\t * This function checks whether all posts returned by initial wp_query match the keyword by title\n\t * The code used in this function is borrowed from WP_Query class where it is used to construct like conditions for keywords\n\t *\n\t * @uses self::wp_query\n\t * @return bool\n\t */\n\tpublic function has_only_title_matching_posts() {\n\n\t\t// apply following logic for search page results only\n\t\tif ( false === self::wp_query()->is_search() ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// grab the last posts in the stack as if the last one is title-matching the rest is title-matching as well\n\t\t$post = end( self::wp_query()->posts );\n\n\t\t// code inspired by WP_Query class\n\t\tif ( preg_match_all( '/\".*?(\"|$)|((?<=[\\t \",+])|^)[^\\t \",+]+/', self::wp_query()->get( 's' ), $matches ) ) {\n\t\t\t$search_terms = self::wp_query()->query_vars['search_terms'] ?? null;\n\t\t\t// if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence\n\t\t\tif ( empty( $search_terms ) || ! is_countable( $search_terms ) || count( $search_terms ) > 9 ) {\n\t\t\t\t$search_terms = array( self::wp_query()->get( 's' ) );\n\t\t\t}\n\t\t} else {\n\t\t\t$search_terms = array( self::wp_query()->get( 's' ) );\n\t\t}\n\n\t\t// actual testing. As search query combines multiple keywords with AND, it's enough to check if any of the keywords is present in the title\n\t\t$term = current( $search_terms );\n\t\tif ( ! empty( $term ) && str_contains( $post->post_title, $term ) ) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Grab the timestamp for the initial query's last post.\n\t *\n\t * This takes into account the query's 'orderby' parameter and returns\n\t * false if the posts are not ordered by date.\n\t *\n\t * @uses self::got_infinity\n\t * @uses self::has_only_title_matching_posts\n\t * @uses self::wp_query\n\t * @return string 'Y-m-d H:i:s' or false\n\t */\n\tpublic function get_last_post_date() {\n\t\tif ( self::got_infinity() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! self::wp_query()->have_posts() ) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// In case there are only title-matching posts in the initial WP_Query result, we don't want to use the last_post_date param yet\n\t\tif ( true === self::has_only_title_matching_posts() ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t$post = end( self::wp_query()->posts );\n\t\t$orderby = isset( self::wp_query()->query_vars['orderby'] ) ?\n\t\t\tself::wp_query()->query_vars['orderby'] : '';\n\t\t$post_date = ( ! empty( $post->post_date ) ? $post->post_date : false );\n\t\tswitch ( $orderby ) {\n\t\t\tcase 'modified':\n\t\t\t\treturn $post->post_modified;\n\t\t\tcase 'date':\n\t\t\tcase '':\n\t\t\t\treturn $post_date;\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the appropriate `wp_posts` table field for a given query's\n\t * 'orderby' parameter, if applicable.\n\t *\n\t * @param object $query - an optional query object.\n\t * @uses self::wp_query\n\t * @return string or false\n\t */\n\tpublic function get_query_sort_field( $query = null ) {\n\t\tif ( empty( $query ) ) {\n\t\t\t$query = self::wp_query();\n\t\t}\n\n\t\t$orderby = isset( $query->query_vars['orderby'] ) ? $query->query_vars['orderby'] : '';\n\n\t\tswitch ( $orderby ) {\n\t\t\tcase 'modified':\n\t\t\t\treturn 'post_modified';\n\t\t\tcase 'date':\n\t\t\tcase '':\n\t\t\t\treturn 'post_date';\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Create a where clause that will make sure post queries return posts\n\t * in the correct order, without duplicates, if a new post is added\n\t * and we're sorting by post date.\n\t *\n\t * @global $wpdb\n\t * @param string $where - the where clause.\n\t * @param object $query - the query.\n\t * @uses apply_filters\n\t * @filter posts_where\n\t * @return string\n\t */\n\tpublic function query_time_filter( $where, $query ) {\n\t\tif ( self::got_infinity() ) {\n\t\t\tglobal $wpdb;\n\n\t\t\t$sort_field = self::get_query_sort_field( $query );\n\n\t\t\tif ( 'post_date' !== $sort_field ||\n\t\t\t! isset( $_REQUEST['query_args']['order'] ) || 'DESC' !== $_REQUEST['query_args']['order'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.\n\t\t\t\treturn $where;\n\t\t\t}\n\n\t\t\t$query_before = isset( $_REQUEST['query_before'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['query_before'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.\n\n\t\t\tif ( empty( $query_before ) ) {\n\t\t\t\treturn $where;\n\t\t\t}\n\n\t\t\t// Construct the date query using our timestamp\n\t\t\t$clause = $wpdb->prepare( \" AND {$wpdb->posts}.post_date <= %s\", $query_before );\n\n\t\t\t/**\n\t\t\t * Filter Infinite Scroll's SQL date query making sure post queries\n\t\t\t * will always return results prior to (descending sort)\n\t\t\t * or before (ascending sort) the last post date.\n\t\t\t *\n\t\t\t * @deprecated 14.0\n\t\t\t *\n\t\t\t * @module infinite-scroll\n\t\t\t *\n\t\t\t * @param string $clause SQL Date query.\n\t\t\t * @param object $query Query.\n\t\t\t * @param string $operator @deprecated Query operator.\n\t\t\t * @param string $last_post_date @deprecated Last Post Date timestamp.\n\t\t\t */\n\t\t\t$operator = '<';\n\t\t\t$last_post_date = isset( $_REQUEST['last_post_date'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['last_post_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes to the site\n\t\t\t$where .= apply_filters_deprecated( 'infinite_scroll_posts_where', array( $clause, $query, $operator, $last_post_date ), '14.0', '' );\n\t\t}\n\n\t\treturn $where;\n\t}\n\n\t/**\n\t * Let's overwrite the default post_per_page setting to always display a fixed amount.\n\t *\n\t * @param object $query - the query.\n\t * @uses is_admin, self::archive_supports_infinity, self::get_settings\n\t */\n\tpublic function posts_per_page_query( $query ) {\n\t\tif ( ! is_admin() && self::archive_supports_infinity() && $query->is_main_query() ) {\n\t\t\t$query->set( 'posts_per_page', self::posts_per_page() );\n\t\t}\n\t}\n\n\t/**\n\t * Check if the IS output should be wrapped in a div.\n\t * Setting value can be a boolean or a string specifying the class applied to the div.\n\t *\n\t * @uses self::get_settings\n\t * @return bool\n\t */\n\tpublic function has_wrapper() {\n\t\treturn (bool) self::get_settings()->wrapper;\n\t}\n\n\t/**\n\t * Returns the Ajax url\n\t *\n\t * @global $wp\n\t * @uses home_url, add_query_arg, apply_filters\n\t * @return string\n\t */\n\tpublic function ajax_url() {\n\t\t$base_url = set_url_scheme( home_url( '/' ) );\n\n\t\t$ajaxurl = add_query_arg( array( 'infinity' => 'scrolling' ), $base_url );\n\n\t\t/**\n\t\t * Filter the Infinite Scroll Ajax URL.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t *\n\t\t * @param string $ajaxurl Infinite Scroll Ajax URL.\n\t\t */\n\t\treturn apply_filters( 'infinite_scroll_ajax_url', $ajaxurl );\n\t}\n\n\t/**\n\t * Our own Ajax response, avoiding calling admin-ajax\n\t */\n\tpublic function ajax_response() {\n\t\t// Only proceed if the url query has a key of \"Infinity\"\n\t\tif ( ! self::got_infinity() ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// This should already be defined below, but make sure.\n\t\tif ( ! defined( 'DOING_AJAX' ) ) {\n\t\t\tdefine( 'DOING_AJAX', true );\n\t\t}\n\n\t\t@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged\n\t\tsend_nosniff_header();\n\n\t\t/**\n\t\t * Fires at the end of the Infinite Scroll Ajax response.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t */\n\t\tdo_action( 'custom_ajax_infinite_scroll' );\n\t\tdie( '0' );\n\t}\n\n\t/**\n\t * Alias for renamed class method.\n\t *\n\t * Previously, JS settings object was unnecessarily output in the document head.\n\t * When the hook was changed, the method name no longer made sense.\n\t */\n\tpublic function action_wp_head() {\n\t\t$this->action_wp_footer_settings();\n\t}\n\n\t/**\n\t * Prints the relevant infinite scroll settings in JS.\n\t *\n\t * @global $wp_rewrite\n\t * @uses self::get_settings, esc_js, esc_url_raw, self::has_wrapper, __, apply_filters, do_action, self::get_query_vars\n\t * @action wp_footer\n\t */\n\tpublic function action_wp_footer_settings() {\n\t\tglobal $wp_rewrite;\n\t\tglobal $currentday;\n\n\t\t$settings = self::get_settings();\n\n\t\t// Default click handle text\n\t\t$click_handle_text = __( 'Older posts', 'jetpack' );\n\n\t\t// If a single CPT is displayed, use its plural name instead of \"posts\"\n\t\t// Could be empty (posts) or an array of multiple post types.\n\t\t// In the latter two cases cases, the default text is used, leaving the `infinite_scroll_js_settings` filter for further customization.\n\t\t$post_type = self::wp_query()->get( 'post_type' );\n\n\t\t// If it's a taxonomy, try to change the button text.\n\t\tif ( is_tax() ) {\n\t\t\t// Get current taxonomy slug.\n\t\t\t$taxonomy_slug = self::wp_query()->get( 'taxonomy' );\n\n\t\t\t// Get taxonomy settings.\n\t\t\t$taxonomy = get_taxonomy( $taxonomy_slug );\n\n\t\t\t// Check if the taxonomy is attached to one post type only and use its plural name.\n\t\t\t// If not, use \"Posts\" without confusing the users.\n\t\t\tif (\n\t\t\t\tis_a( $taxonomy, 'WP_Taxonomy' )\n\t\t\t\t&& is_countable( $taxonomy->object_type )\n\t\t\t\t&& ! empty( $taxonomy->object_type )\n\t\t\t\t&& count( $taxonomy->object_type ) < 2\n\t\t\t) {\n\t\t\t\t$post_type = $taxonomy->object_type[0];\n\t\t\t}\n\t\t}\n\n\t\tif ( is_string( $post_type ) && ! empty( $post_type ) ) {\n\t\t\t$post_type = get_post_type_object( $post_type );\n\n\t\t\tif ( is_object( $post_type ) && ! is_wp_error( $post_type ) ) {\n\t\t\t\tif ( isset( $post_type->labels->name ) ) {\n\t\t\t\t\t$cpt_text = $post_type->labels->name;\n\t\t\t\t} elseif ( isset( $post_type->label ) ) {\n\t\t\t\t\t$cpt_text = $post_type->label;\n\t\t\t\t}\n\n\t\t\t\tif ( isset( $cpt_text ) ) {\n\t\t\t\t\t/* translators: %s is the name of a custom post type */\n\t\t\t\t\t$click_handle_text = sprintf( __( 'More %s', 'jetpack' ), $cpt_text );\n\t\t\t\t\tunset( $cpt_text );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tunset( $post_type );\n\n\t\t// Base JS settings\n\t\t$js_settings = array(\n\t\t\t'id' => $settings->container,\n\t\t\t'ajaxurl' => esc_url_raw( self::ajax_url() ),\n\t\t\t'type' => esc_js( $settings->type ),\n\t\t\t'wrapper' => self::has_wrapper(),\n\t\t\t'wrapper_class' => is_string( $settings->wrapper ) ? esc_js( $settings->wrapper ) : 'infinite-wrap',\n\t\t\t'footer' => is_string( $settings->footer ) ? esc_js( $settings->footer ) : $settings->footer,\n\t\t\t'click_handle' => esc_js( $settings->click_handle ),\n\t\t\t'text' => esc_js( $click_handle_text ),\n\t\t\t'totop' => __( 'Scroll back to top', 'jetpack' ),\n\t\t\t'currentday' => $currentday,\n\t\t\t'order' => 'DESC',\n\t\t\t'scripts' => array(),\n\t\t\t'styles' => array(),\n\t\t\t'google_analytics' => false,\n\t\t\t'offset' => max( 1, self::wp_query()->get( 'paged' ) ), // Pass through the current page so we can use that to offset the first load.\n\t\t\t'history' => array(\n\t\t\t\t'host' => preg_replace( '#^http(s)?://#i', '', untrailingslashit( esc_url( get_home_url() ) ) ),\n\t\t\t\t'path' => self::get_request_path(),\n\t\t\t\t'use_trailing_slashes' => $wp_rewrite->use_trailing_slashes,\n\t\t\t\t'parameters' => self::get_request_parameters(),\n\t\t\t),\n\t\t\t'query_args' => self::get_query_vars(),\n\t\t\t'query_before' => current_time( 'mysql' ),\n\t\t\t'last_post_date' => self::get_last_post_date(),\n\t\t\t'body_class' => self::body_class(),\n\t\t\t'loading_text' => __( 'Loading new page', 'jetpack' ),\n\t\t);\n\n\t\t// Optional order param\n\t\tif ( isset( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.\n\t\t\t$order = strtoupper( sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.\n\n\t\t\tif ( in_array( $order, array( 'ASC', 'DESC' ), true ) ) {\n\t\t\t\t$js_settings['order'] = $order;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Filter the Infinite Scroll JS settings outputted in the head.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t *\n\t\t * @param array $js_settings Infinite Scroll JS settings.\n\t\t */\n\t\t$js_settings = apply_filters( 'infinite_scroll_js_settings', $js_settings );\n\n\t\t/**\n\t\t * Fires before Infinite Scroll outputs inline JavaScript in the head.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t */\n\t\tdo_action( 'infinite_scroll_wp_head' );\n\n\t\t?>\n\t\t<script type=\"text/javascript\">\n\t\tvar infiniteScroll = <?php echo wp_json_encode( array( 'settings' => $js_settings ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;\n\t\t</script>\n\t\t<?php\n\t}\n\n\t// phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited\n\n\t/**\n\t * Build path data for current request.\n\t * Used for Google Analytics and pushState history tracking.\n\t *\n\t * @global $wp_rewrite\n\t * @global $wp\n\t * @uses user_trailingslashit, sanitize_text_field, add_query_arg\n\t * @return string|bool\n\t */\n\tprivate function get_request_path() {\n\t\tglobal $wp_rewrite;\n\n\t\tif ( $wp_rewrite->using_permalinks() ) {\n\t\t\tglobal $wp;\n\n\t\t\t// If called too early, bail\n\t\t\tif ( ! isset( $wp->request ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Determine path for paginated version of current request\n\t\t\tif ( preg_match( '#' . preg_quote( $wp_rewrite->pagination_base, '#' ) . '/\\d+/?$#i', $wp->request ) ) {\n\t\t\t\t$path = preg_replace( '#' . preg_quote( $wp_rewrite->pagination_base, '#' ) . '/\\d+$#i', $wp_rewrite->pagination_base . '/%d', $wp->request );\n\t\t\t} else {\n\t\t\t\t$path = $wp->request . '/' . $wp_rewrite->pagination_base . '/%d';\n\t\t\t}\n\n\t\t\t// Slashes everywhere we need them\n\t\t\tif ( ! str_starts_with( $path, '/' ) ) {\n\t\t\t\t$path = '/' . $path;\n\t\t\t}\n\n\t\t\t$path = user_trailingslashit( $path );\n\t\t} else {\n\t\t\t// Clean up raw $_REQUEST input\n\t\t\t$path = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- seems this is used for Google Analytics and browser history tracking.\n\t\t\t$path = array_filter( $path );\n\n\t\t\t$path['paged'] = '%d';\n\n\t\t\t$path = add_query_arg( $path, '/' );\n\t\t}\n\n\t\treturn empty( $path ) ? false : $path;\n\t}\n\n\t/**\n\t * Return query string for current request, prefixed with '?'.\n\t *\n\t * @return string\n\t */\n\tprivate function get_request_parameters() {\n\t\t$uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';\n\t\t$uri = preg_replace( '/^[^?]*(\\?.*$)/', '$1', $uri, 1, $count );\n\t\tif ( $count !== 1 ) {\n\t\t\treturn '';\n\t\t}\n\t\treturn $uri;\n\t}\n\n\t/**\n\t * Provide IS with a list of the scripts and stylesheets already present on the page.\n\t * Since posts may contain require additional assets that haven't been loaded, this data will be used to track the additional assets.\n\t *\n\t * @global $wp_scripts, $wp_styles\n\t * @action wp_footer\n\t */\n\tpublic function action_wp_footer() {\n\t\tglobal $wp_scripts, $wp_styles;\n\n\t\t$scripts = is_a( $wp_scripts, 'WP_Scripts' ) ? $wp_scripts->done : array();\n\t\t/**\n\t\t * Filter the list of scripts already present on the page.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.1.2\n\t\t *\n\t\t * @param array $scripts Array of scripts present on the page.\n\t\t */\n\t\t$scripts = apply_filters( 'infinite_scroll_existing_scripts', $scripts );\n\n\t\t$styles = is_a( $wp_styles, 'WP_Styles' ) ? $wp_styles->done : array();\n\t\t/**\n\t\t * Filter the list of styles already present on the page.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.1.2\n\t\t *\n\t\t * @param array $styles Array of styles present on the page.\n\t\t */\n\t\t$styles = apply_filters( 'infinite_scroll_existing_stylesheets', $styles );\n\n\t\t?>\n\t\t<script type=\"text/javascript\">\n\t\t\t(function() {\n\t\t\t\tvar extend = function(out) {\n\t\t\t\t\tout = out || {};\n\n\t\t\t\t\tfor (var i = 1; i < arguments.length; i++) {\n\t\t\t\t\t\tif (!arguments[i])\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\t\tfor (var key in arguments[i]) {\n\t\t\t\t\t\tif (arguments[i].hasOwnProperty(key))\n\t\t\t\t\t\t\tout[key] = arguments[i][key];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn out;\n\t\t\t\t};\n\t\t\t\textend( window.infiniteScroll.settings.scripts, <?php echo wp_json_encode( $scripts, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );\n\t\t\t\textend( window.infiniteScroll.settings.styles, <?php echo wp_json_encode( $styles, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );\n\t\t\t})();\n\t\t</script>\n\t\t<?php\n\t\t$aria_live = 'assertive';\n\t\tif ( 'scroll' === self::get_settings()->type ) {\n\t\t\t$aria_live = 'polite';\n\t\t}\n\t\t?>\n\t\t<span id=\"infinite-aria\" aria-live=\"<?php echo esc_attr( $aria_live ); ?>\"></span>\n\t\t<?php\n\t}\n\n\t/**\n\t * Identify additional scripts required by the latest set of IS posts and provide the necessary data to the IS response handler.\n\t *\n\t * @param array $results - the results.\n\t * @param array $query_args - Array of Query arguments.\n\t * @param array $wp_query - the WP query.\n\t * @global $wp_scripts\n\t * @uses sanitize_text_field, add_query_arg\n\t * @filter infinite_scroll_results\n\t * @return array\n\t */\n\tpublic function filter_infinite_scroll_results( $results, $query_args, $wp_query ) {\n\t\t// Don't bother unless there are posts to display\n\t\tif ( 'success' !== $results['type'] ) {\n\t\t\treturn $results;\n\t\t}\n\n\t\t// Parse and sanitize the script handles already output\n\t\t$initial_scripts = isset( $_REQUEST['scripts'] ) && is_array( $_REQUEST['scripts'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['scripts'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes made.\n\n\t\tif ( is_array( $initial_scripts ) ) {\n\t\t\tglobal $wp_scripts;\n\n\t\t\t// Identify new scripts needed by the latest set of IS posts\n\t\t\t$new_scripts = array_filter(\n\t\t\t\t$wp_scripts->done,\n\t\t\t\tfunction ( $script_name ) use ( $initial_scripts ) {\n\t\t\t\t\t// Jetpack block scripts should always be sent, even if they've been\n\t\t\t\t\t// sent before. These scripts only run once on when loaded, they don't\n\t\t\t\t\t// watch for new blocks being added.\n\t\t\t\t\tif ( str_starts_with( $script_name, 'jetpack-block-' ) ) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ! in_array( $script_name, $initial_scripts, true );\n\t\t\t\t}\n\t\t\t);\n\n\t\t\t// If new scripts are needed, extract relevant data from $wp_scripts\n\t\t\tif ( ! empty( $new_scripts ) ) {\n\t\t\t\t$results['scripts'] = array();\n\n\t\t\t\tforeach ( $new_scripts as $handle ) {\n\t\t\t\t\t// Abort if somehow the handle doesn't correspond to a registered script\n\t\t\t\t\t// or if the script doesn't have `src` set.\n\t\t\t\t\t$script_not_registered = ! isset( $wp_scripts->registered[ $handle ] );\n\t\t\t\t\t$empty_src = empty( $wp_scripts->registered[ $handle ]->src );\n\t\t\t\t\tif ( $script_not_registered || $empty_src ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t$before_handle = $wp_scripts->get_inline_script_data( $handle, 'before' );\n\t\t\t\t\t$after_handle = $wp_scripts->get_inline_script_data( $handle, 'after' );\n\n\t\t\t\t\t// Provide basic script data\n\t\t\t\t\t$script_data = array(\n\t\t\t\t\t\t'handle' => $handle,\n\t\t\t\t\t\t'footer' => ( is_array( $wp_scripts->in_footer ) && in_array( $handle, $wp_scripts->in_footer, true ) ),\n\t\t\t\t\t\t'extra_data' => $wp_scripts->print_extra_script( $handle, false ),\n\t\t\t\t\t\t'before_handle' => $before_handle,\n\t\t\t\t\t\t'after_handle' => $after_handle,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Base source\n\t\t\t\t\t$src = $wp_scripts->registered[ $handle ]->src;\n\n\t\t\t\t\t// Take base_url into account\n\t\t\t\t\tif ( strpos( $src, 'http' ) !== 0 ) {\n\t\t\t\t\t\t$src = $wp_scripts->base_url . $src;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Version and additional arguments\n\t\t\t\t\tif ( null === $wp_scripts->registered[ $handle ]->ver ) {\n\t\t\t\t\t\t$ver = '';\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$ver = $wp_scripts->registered[ $handle ]->ver ? $wp_scripts->registered[ $handle ]->ver : $wp_scripts->default_version;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( isset( $wp_scripts->args[ $handle ] ) ) {\n\t\t\t\t\t\t$ver = $ver ? $ver . '&amp;' . $wp_scripts->args[ $handle ] : $wp_scripts->args[ $handle ];\n\t\t\t\t\t}\n\n\t\t\t\t\t// Full script source with version info\n\t\t\t\t\t$script_data['src'] = add_query_arg( 'ver', $ver, $src );\n\n\t\t\t\t\t// Add script to data that will be returned to IS JS\n\t\t\t\t\tarray_push( $results['scripts'], $script_data );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Expose additional script data to filters, but only include in final `$results` array if needed.\n\t\tif ( ! isset( $results['scripts'] ) ) {\n\t\t\t$results['scripts'] = array();\n\t\t}\n\n\t\t/**\n\t\t * Filter the additional scripts required by the latest set of IS posts.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.1.2\n\t\t *\n\t\t * @param array $results['scripts'] Additional scripts required by the latest set of IS posts.\n\t\t * @param array|bool $initial_scripts Set of scripts loaded on each page.\n\t\t * @param array $results Array of Infinite Scroll results.\n\t\t * @param array $query_args Array of Query arguments.\n\t\t * @param WP_Query $wp_query WP Query.\n\t\t */\n\t\t$results['scripts'] = apply_filters(\n\t\t\t'infinite_scroll_additional_scripts',\n\t\t\t$results['scripts'],\n\t\t\t$initial_scripts,\n\t\t\t$results,\n\t\t\t$query_args,\n\t\t\t$wp_query\n\t\t);\n\n\t\tif ( empty( $results['scripts'] ) ) {\n\t\t\tunset( $results['scripts'] );\n\t\t}\n\n\t\t// Parse and sanitize the style handles already output\n\t\t$initial_styles = isset( $_REQUEST['styles'] ) && is_array( $_REQUEST['styles'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['styles'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended\n\n\t\tif ( is_array( $initial_styles ) ) {\n\t\t\tglobal $wp_styles;\n\n\t\t\t// Identify new styles needed by the latest set of IS posts\n\t\t\t$new_styles = array_diff( $wp_styles->done, $initial_styles );\n\n\t\t\t// If new styles are needed, extract relevant data from $wp_styles\n\t\t\tif ( ! empty( $new_styles ) ) {\n\t\t\t\t$results['styles'] = array();\n\n\t\t\t\tforeach ( $new_styles as $handle ) {\n\t\t\t\t\t// Abort if somehow the handle doesn't correspond to a registered stylesheet\n\t\t\t\t\tif ( ! isset( $wp_styles->registered[ $handle ] ) ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Provide basic style data\n\t\t\t\t\t$style_data = array(\n\t\t\t\t\t\t'handle' => $handle,\n\t\t\t\t\t\t'media' => 'all',\n\t\t\t\t\t);\n\n\t\t\t\t\t// Base source\n\t\t\t\t\t$src = $wp_styles->registered[ $handle ]->src;\n\n\t\t\t\t\t// Take base_url into account\n\t\t\t\t\tif ( strpos( $src, 'http' ) !== 0 ) {\n\t\t\t\t\t\t$src = $wp_styles->base_url . $src;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Version and additional arguments\n\t\t\t\t\tif ( null === $wp_styles->registered[ $handle ]->ver ) {\n\t\t\t\t\t\t$ver = '';\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$ver = $wp_styles->registered[ $handle ]->ver ? $wp_styles->registered[ $handle ]->ver : $wp_styles->default_version;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( isset( $wp_styles->args[ $handle ] ) ) {\n\t\t\t\t\t\t$ver = $ver ? $ver . '&amp;' . $wp_styles->args[ $handle ] : $wp_styles->args[ $handle ];\n\t\t\t\t\t}\n\n\t\t\t\t\t// Full stylesheet source with version info\n\t\t\t\t\t$style_data['src'] = add_query_arg( 'ver', $ver, $src );\n\n\t\t\t\t\t// Parse stylesheet's conditional comments if present, converting to logic executable in JS\n\t\t\t\t\tif ( isset( $wp_styles->registered[ $handle ]->extra['conditional'] ) && $wp_styles->registered[ $handle ]->extra['conditional'] ) {\n\t\t\t\t\t\t// First, convert conditional comment operators to standard logical operators. %ver is replaced in JS with the IE version\n\t\t\t\t\t\t$style_data['conditional'] = str_replace(\n\t\t\t\t\t\t\tarray(\n\t\t\t\t\t\t\t\t'lte',\n\t\t\t\t\t\t\t\t'lt',\n\t\t\t\t\t\t\t\t'gte',\n\t\t\t\t\t\t\t\t'gt',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tarray(\n\t\t\t\t\t\t\t\t'%ver <=',\n\t\t\t\t\t\t\t\t'%ver <',\n\t\t\t\t\t\t\t\t'%ver >=',\n\t\t\t\t\t\t\t\t'%ver >',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t$wp_styles->registered[ $handle ]->extra['conditional']\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Next, replace any !IE checks. These shouldn't be present since WP's conditional stylesheet implementation doesn't support them, but someone could be _doing_it_wrong().\n\t\t\t\t\t\t$style_data['conditional'] = preg_replace( '#!\\s*IE(\\s*\\d+){0}#i', '1==2', $style_data['conditional'] );\n\n\t\t\t\t\t\t// Lastly, remove the IE strings\n\t\t\t\t\t\t$style_data['conditional'] = str_replace( 'IE', '', $style_data['conditional'] );\n\t\t\t\t\t}\n\n\t\t\t\t\t// Parse requested media context for stylesheet\n\t\t\t\t\tif ( isset( $wp_styles->registered[ $handle ]->args ) ) {\n\t\t\t\t\t\t$style_data['media'] = esc_attr( $wp_styles->registered[ $handle ]->args );\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add stylesheet to data that will be returned to IS JS\n\t\t\t\t\tarray_push( $results['styles'], $style_data );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Expose additional stylesheet data to filters, but only include in final `$results` array if needed.\n\t\tif ( ! isset( $results['styles'] ) ) {\n\t\t\t$results['styles'] = array();\n\t\t}\n\n\t\t/**\n\t\t * Filter the additional styles required by the latest set of IS posts.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.1.2\n\t\t *\n\t\t * @param array $results['styles'] Additional styles required by the latest set of IS posts.\n\t\t * @param array|bool $initial_styles Set of styles loaded on each page.\n\t\t * @param array $results Array of Infinite Scroll results.\n\t\t * @param array $query_args Array of Query arguments.\n\t\t * @param WP_Query $wp_query WP Query.\n\t\t */\n\t\t$results['styles'] = apply_filters(\n\t\t\t'infinite_scroll_additional_stylesheets',\n\t\t\t$results['styles'],\n\t\t\t$initial_styles,\n\t\t\t$results,\n\t\t\t$query_args,\n\t\t\t$wp_query\n\t\t);\n\n\t\tif ( empty( $results['styles'] ) ) {\n\t\t\tunset( $results['styles'] );\n\t\t}\n\n\t\t// Lastly, return the IS results array\n\t\treturn $results;\n\t}\n\n\t/**\n\t * Runs the query and returns the results via JSON.\n\t * Triggered by an AJAX request.\n\t *\n\t * @global $wp_query\n\t * @global $wp_the_query\n\t * @uses current_theme_supports, get_option, self::wp_query, current_user_can, apply_filters, self::get_settings, add_filter, WP_Query, remove_filter, have_posts, wp_head, do_action, add_action, this::render, this::has_wrapper, esc_attr, wp_footer, sharing_register_post_for_share_counts, get_the_id\n\t */\n\tpublic function query() {\n\t\tif ( ! isset( $_REQUEST['page'] ) || ! current_theme_supports( 'infinite-scroll' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes to the site.\n\t\t\tdie( 0 );\n\t\t}\n\n\t\t// @todo see if we should validate this nonce since we use it to form a query.\n\t\t$page = (int) $_REQUEST['page']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- we're casting this to an int and not making changes to the site.\n\n\t\t// Sanitize and set $previousday. Expected format: dd.mm.yy\n\t\tif ( isset( $_REQUEST['currentday'] ) && is_string( $_REQUEST['currentday'] ) && preg_match( '/^\\d{2}\\.\\d{2}\\.\\d{2}$/', $_REQUEST['currentday'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification.Recommended -- manually validating, no changes to site\n\t\t\tglobal $previousday;\n\t\t\t$previousday = $_REQUEST['currentday']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput\n\t\t}\n\n\t\t$post_status = array( 'publish' );\n\t\tif ( current_user_can( 'read_private_posts' ) ) {\n\t\t\tarray_push( $post_status, 'private' );\n\t\t}\n\n\t\t$order = isset( $_REQUEST['order'] ) && in_array( $_REQUEST['order'], array( 'ASC', 'DESC' ), true ) ? sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) : 'DESC'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.\n\n\t\t$query_args = array_merge(\n\t\t\tself::wp_query()->query_vars,\n\t\t\tarray(\n\t\t\t\t'paged' => $page,\n\t\t\t\t'post_status' => $post_status,\n\t\t\t\t'posts_per_page' => self::posts_per_page(), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page\n\t\t\t\t'order' => $order,\n\t\t\t)\n\t\t);\n\n\t\t// 4.0 ?s= compatibility, see https://core.trac.wordpress.org/ticket/11330#comment:50\n\t\tif ( empty( $query_args['s'] ) && ! isset( self::wp_query()->query['s'] ) ) {\n\t\t\tunset( $query_args['s'] );\n\t\t}\n\n\t\t// By default, don't query for a specific page of a paged post object.\n\t\t// This argument can come from merging self::wp_query() into $query_args above.\n\t\t// Since IS is only used on archives, we should always display the first page of any paged content.\n\t\tunset( $query_args['page'] );\n\n\t\t/**\n\t\t * Filter the array of main query arguments.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.1\n\t\t *\n\t\t * @param array $query_args Array of Query arguments.\n\t\t */\n\t\t$query_args = apply_filters( 'infinite_scroll_query_args', $query_args );\n\n\t\tadd_filter( 'posts_where', array( $this, 'query_time_filter' ), 10, 2 );\n\n\t\t$infinite_scroll_query = new WP_Query();\n\t\t$GLOBALS['wp_the_query'] = $infinite_scroll_query;\n\t\t$GLOBALS['wp_query'] = $infinite_scroll_query;\n\n\t\t$infinite_scroll_query->query( $query_args );\n\n\t\tremove_filter( 'posts_where', array( $this, 'query_time_filter' ), 10 );\n\n\t\t$results = array();\n\n\t\tif ( have_posts() ) {\n\t\t\t// Fire wp_head to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer.\n\t\t\tob_start();\n\t\t\twp_head();\n\t\t\twhile ( ob_get_length() ) {\n\t\t\t\tob_end_clean();\n\t\t\t}\n\n\t\t\t$results['type'] = 'success';\n\n\t\t\t/**\n\t\t\t * Fires when rendering Infinite Scroll posts.\n\t\t\t *\n\t\t\t * @module infinite-scroll\n\t\t\t *\n\t\t\t * @since 2.0.0\n\t\t\t */\n\t\t\tdo_action( 'infinite_scroll_render' );\n\t\t\t$results['html'] = ob_get_clean();\n\t\t\tif ( empty( $results['html'] ) ) {\n\t\t\t\t/**\n\t\t\t\t * Gather renderer callbacks. These will be called in order and allow multiple callbacks to be queued. Once content is found, no futher callbacks will run.\n\t\t\t\t *\n\t\t\t\t * @module infinite-scroll\n\t\t\t\t *\n\t\t\t\t * @since 6.0.0\n\t\t\t\t */\n\t\t\t\t$callbacks = apply_filters(\n\t\t\t\t\t'infinite_scroll_render_callbacks',\n\t\t\t\t\tarray( self::get_settings()->render ) // This is the setting callback e.g. from add theme support.\n\t\t\t\t);\n\n\t\t\t\t// Append fallback callback. That rhymes.\n\t\t\t\t$callbacks[] = array( $this, 'render' );\n\n\t\t\t\tforeach ( $callbacks as $callback ) {\n\t\t\t\t\tif ( false !== $callback && is_callable( $callback ) ) {\n\t\t\t\t\t\trewind_posts();\n\t\t\t\t\t\tob_start();\n\n\t\t\t\t\t\tadd_action( 'infinite_scroll_render', $callback );\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * This action is already documented above.\n\t\t\t\t\t\t * See https://github.com/Automattic/jetpack/pull/16317/\n\t\t\t\t\t\t * for more details as to why it was introduced.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tdo_action( 'infinite_scroll_render' );\n\n\t\t\t\t\t\t// Fire wp_head to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer.\n\t\t\t\t\t\twp_head();\n\n\t\t\t\t\t\t$results['html'] = ob_get_clean();\n\t\t\t\t\t\tremove_action( 'infinite_scroll_render', $callback );\n\t\t\t\t\t}\n\t\t\t\t\tif ( ! empty( $results['html'] ) ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If primary and fallback rendering methods fail, prevent further IS rendering attempts. Otherwise, wrap the output if requested.\n\t\t\tif ( empty( $results['html'] ) ) {\n\t\t\t\tunset( $results['html'] );\n\t\t\t\t/**\n\t\t\t\t * Fires when Infinite Scoll doesn't render any posts.\n\t\t\t\t *\n\t\t\t\t * @module infinite-scroll\n\t\t\t\t *\n\t\t\t\t * @since 2.0.0\n\t\t\t\t */\n\t\t\t\tdo_action( 'infinite_scroll_empty' );\n\t\t\t\t$results['type'] = 'empty';\n\t\t\t} elseif ( $this->has_wrapper() ) {\n\t\t\t\t$wrapper_classes = is_string( self::get_settings()->wrapper ) ? self::get_settings()->wrapper : 'infinite-wrap';\n\t\t\t\t$wrapper_classes .= ' infinite-view-' . $page;\n\t\t\t\t$wrapper_classes = trim( $wrapper_classes );\n\t\t\t\t$aria_label = sprintf(\n\t\t\t\t\t/* translators: %1$s is the page count */\n\t\t\t\t\t__( 'Page: %1$d.', 'jetpack' ),\n\t\t\t\t\t$page\n\t\t\t\t);\n\n\t\t\t\t$results['html'] = '<div class=\"' . esc_attr( $wrapper_classes ) . '\" id=\"infinite-view-' . $page . '\" data-page-num=\"' . $page . '\" role=\"region\" aria-label=\"' . esc_attr( $aria_label ) . '\">' . $results['html'] . '</div>';\n\t\t\t}\n\n\t\t\t// Fire wp_footer to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer.\n\t\t\tob_start();\n\t\t\twp_footer();\n\t\t\twhile ( ob_get_length() ) {\n\t\t\t\tob_end_clean();\n\t\t\t}\n\n\t\t\tif ( 'success' === $results['type'] ) {\n\t\t\t\tglobal $currentday;\n\t\t\t\t$results['lastbatch'] = self::is_last_batch();\n\t\t\t\t$results['currentday'] = $currentday;\n\t\t\t}\n\n\t\t\t// Loop through posts to capture sharing data for new posts loaded via Infinite Scroll\n\t\t\tif ( 'success' === $results['type'] && function_exists( 'sharing_register_post_for_share_counts' ) ) {\n\t\t\t\tglobal $jetpack_sharing_counts;\n\n\t\t\t\twhile ( have_posts() ) {\n\t\t\t\t\tthe_post();\n\n\t\t\t\t\tsharing_register_post_for_share_counts( get_the_ID() );\n\t\t\t\t}\n\n\t\t\t\t// If sharing counts are not initialized for any reason, we initialize them here.\n\t\t\t\tif ( ! is_array( $jetpack_sharing_counts ) ) {\n\t\t\t\t\t$jetpack_sharing_counts = array();\n\t\t\t\t} else {\n\t\t\t\t\t// Filter out non-string and non-integer values to avoid warnings with array_flip.\n\t\t\t\t\t$flippable_jetpack_sharing_counts = array_filter(\n\t\t\t\t\t\t$jetpack_sharing_counts,\n\t\t\t\t\t\tfunction ( $value ) {\n\t\t\t\t\t\t\treturn is_string( $value ) || is_int( $value );\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t$results['postflair'] = array_flip( $flippable_jetpack_sharing_counts ?? array() );\n\t\t\t}\n\t\t} else {\n\t\t\t/** This action is already documented in modules/infinite-scroll/infinity.php */\n\t\t\tdo_action( 'infinite_scroll_empty' );\n\t\t\t$results['type'] = 'empty';\n\t\t}\n\n\t\twp_send_json(\n\t\t\t/**\n\t\t\t * Filter the Infinite Scroll results.\n\t\t\t *\n\t\t\t * @module infinite-scroll\n\t\t\t *\n\t\t\t * @since 2.0.0\n\t\t\t *\n\t\t\t * @param array $results Array of Infinite Scroll results.\n\t\t\t * @param array $query_args Array of main query arguments.\n\t\t\t * @param WP_Query $wp_query WP Query.\n\t\t\t */\n\t\t\tapply_filters( 'infinite_scroll_results', $results, $query_args, self::wp_query() ),\n\t\t\tnull, // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.\n\t\t\tJSON_UNESCAPED_SLASHES\n\t\t);\n\t}\n\n\t/**\n\t * Update the $allowed_vars array with the standard WP public and private\n\t * query vars, as well as taxonomy vars\n\t *\n\t * @global $wp\n\t * @param array $allowed_vars - the allowed variables array.\n\t * @filter infinite_scroll_allowed_vars\n\t * @return array\n\t */\n\tpublic function allowed_query_vars( $allowed_vars ) {\n\t\tglobal $wp;\n\n\t\t$allowed_vars += $wp->public_query_vars;\n\t\t$allowed_vars += $wp->private_query_vars;\n\t\t$allowed_vars += $this->get_taxonomy_vars();\n\n\t\tforeach ( array_keys( $allowed_vars, 'paged', true ) as $key ) {\n\t\t\tunset( $allowed_vars[ $key ] );\n\t\t}\n\n\t\treturn array_unique( $allowed_vars );\n\t}\n\n\t/**\n\t * Returns an array of stock and custom taxonomy query vars\n\t *\n\t * @global $wp_taxonomies\n\t * @return array\n\t */\n\tpublic function get_taxonomy_vars() {\n\t\tglobal $wp_taxonomies;\n\n\t\t$taxonomy_vars = array();\n\t\tforeach ( $wp_taxonomies as $t ) {\n\t\t\tif ( $t->query_var ) {\n\t\t\t\t$taxonomy_vars[] = $t->query_var;\n\t\t\t}\n\t\t}\n\n\t\t// still needed?\n\t\t$taxonomy_vars[] = 'tag_id';\n\n\t\treturn $taxonomy_vars;\n\t}\n\n\t/**\n\t * Update the $query_args array with the parameters provided via AJAX/GET.\n\t *\n\t * @param array $query_args - the query args.\n\t * @filter infinite_scroll_query_args\n\t * @return array\n\t */\n\tpublic function inject_query_args( $query_args ) {\n\t\t/**\n\t\t * Filter the array of allowed Infinite Scroll query arguments.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.6.0\n\t\t *\n\t\t * @param array $args Array of allowed Infinite Scroll query arguments.\n\t\t * @param array $query_args Array of query arguments.\n\t\t */\n\t\t$allowed_vars = apply_filters( 'infinite_scroll_allowed_vars', array(), $query_args );\n\n\t\t$query_args = array_merge(\n\t\t\t$query_args,\n\t\t\tarray(\n\t\t\t\t'suppress_filters' => false,\n\t\t\t)\n\t\t);\n\n\t\tif ( isset( $_REQUEST['query_args'] ) && is_array( $_REQUEST['query_args'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes.\n\t\t\tforeach ( wp_unslash( $_REQUEST['query_args'] ) as $var => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- no site changes, sanitized below.\n\t\t\t\tif ( in_array( $var, $allowed_vars, true ) && ! empty( $value ) ) {\n\t\t\t\t\t$query_args[ $var ] = filter_var( $value );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn $query_args;\n\t}\n\n\t/**\n\t * Rendering fallback used when themes don't specify their own handler.\n\t *\n\t * @uses have_posts, the_post, get_template_part, get_post_format\n\t * @action infinite_scroll_render\n\t */\n\tpublic function render() {\n\t\twhile ( have_posts() ) {\n\t\t\tthe_post();\n\n\t\t\tget_template_part( 'content', get_post_format() );\n\t\t}\n\t}\n\n\t/**\n\t * Allow plugins to filter what archives Infinite Scroll supports\n\t *\n\t * @uses current_theme_supports, is_home, is_archive, apply_filters, self::get_settings\n\t * @return bool\n\t */\n\tpublic static function archive_supports_infinity() {\n\t\t$supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() || is_archive() || is_search() );\n\n\t\t// Disable when previewing a non-active theme in the customizer\n\t\tif ( is_customize_preview() && ! $GLOBALS['wp_customize']->is_theme_active() ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t/**\n\t\t * Allow plugins to filter what archives Infinite Scroll supports.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t *\n\t\t * @param bool $supported Does the Archive page support Infinite Scroll.\n\t\t * @param object self::get_settings() IS settings provided by theme.\n\t\t */\n\t\treturn (bool) apply_filters( 'infinite_scroll_archive_supported', $supported, self::get_settings() );\n\t}\n\n\t/**\n\t * The Infinite Blog Footer\n\t *\n\t * @uses self::get_settings, self::archive_supports_infinity, self::default_footer\n\t * @return string or null\n\t */\n\tpublic function footer() {\n\t\tif ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$settings = self::get_settings();\n\n\t\t// Bail if theme requested footer not show\n\t\tif ( false === $settings->footer ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We only need the new footer for the 'scroll' type\n\t\tif ( 'scroll' !== $settings->type || ! self::archive_supports_infinity() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( self::is_last_batch() ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Display a footer, either user-specified or a default\n\t\tif ( false !== $settings->footer_callback && is_callable( $settings->footer_callback ) ) {\n\t\t\tcall_user_func( $settings->footer_callback, $settings );\n\t\t} else {\n\t\t\tself::default_footer();\n\t\t}\n\t}\n\n\t/**\n\t * Render default IS footer\n\t *\n\t * @uses __, wp_get_theme, apply_filters, home_url, esc_attr, get_bloginfo, bloginfo\n\t */\n\tprivate function default_footer() {\n\t\tif ( '' !== get_privacy_policy_url() ) {\n\t\t\t$credits = get_the_privacy_policy_link() . '<span role=\"separator\" aria-hidden=\"true\"> / </span>';\n\t\t} else {\n\t\t\t$credits = '';\n\t\t}\n\t\t$credits .= sprintf(\n\t\t\t'<a href=\"https://wordpress.org/\" rel=\"noopener noreferrer\" target=\"_blank\" rel=\"generator\">%1$s</a> ',\n\t\t\t__( 'Proudly powered by WordPress', 'jetpack' )\n\t\t);\n\t\t$credits .= sprintf(\n\t\t\t/* translators: %1$s is the name of a theme */\n\t\t\t__( 'Theme: %1$s.', 'jetpack' ),\n\t\t\twp_get_theme()->Name\n\t\t);\n\t\t/**\n\t\t * Filter Infinite Scroll's credit text.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 2.0.0\n\t\t *\n\t\t * @param string $credits Infinite Scroll credits.\n\t\t */\n\t\t$credits = apply_filters( 'infinite_scroll_credit', $credits );\n\n\t\t?>\n\t\t<div id=\"infinite-footer\">\n\t\t\t<div class=\"container\">\n\t\t\t\t<div class=\"blog-info\">\n\t\t\t\t\t<a id=\"infinity-blog-title\" href=\"<?php echo esc_url( home_url( '/' ) ); ?>\" rel=\"home\">\n\t\t\t\t\t\t<?php bloginfo( 'name' ); ?>\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"blog-credits\">\n\t\t\t\t\t<?php echo $credits; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div><!-- #infinite-footer -->\n\t\t<?php\n\t}\n\n\t/**\n\t * Ensure that IS doesn't interfere with Grunion by stripping IS query arguments from the Grunion redirect URL.\n\t * When arguments are present, Grunion redirects to the IS AJAX endpoint.\n\t *\n\t * @param string $url - the Grunion redirect URL.\n\t * @uses remove_query_arg\n\t * @filter grunion_contact_form_redirect_url\n\t * @return string\n\t */\n\tpublic function filter_grunion_redirect_url( $url ) {\n\t\t// Remove IS query args, if present\n\t\tif ( str_contains( $url, 'infinity=scrolling' ) ) {\n\t\t\t$url = remove_query_arg(\n\t\t\t\tarray(\n\t\t\t\t\t'infinity',\n\t\t\t\t\t'action',\n\t\t\t\t\t'page',\n\t\t\t\t\t'order',\n\t\t\t\t\t'scripts',\n\t\t\t\t\t'styles',\n\t\t\t\t),\n\t\t\t\t$url\n\t\t\t);\n\t\t}\n\n\t\treturn $url;\n\t}\n\n\t/**\n\t * When the MediaElement is loaded in dynamically, we need to enforce that\n\t * its settings are added to the page as well.\n\t *\n\t * @param array $scripts_data New scripts exposed to the infinite scroll.\n\t *\n\t * @since 8.4.0\n\t */\n\tpublic function add_mejs_config( $scripts_data ) {\n\t\tforeach ( $scripts_data as $key => $data ) {\n\t\t\tif ( 'mediaelement-core' === $data['handle'] ) {\n\t\t\t\t$mejs_settings = array(\n\t\t\t\t\t'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),\n\t\t\t\t\t'classPrefix' => 'mejs-',\n\t\t\t\t\t'stretching' => 'responsive',\n\t\t\t\t);\n\n\t\t\t\t$scripts_data[ $key ]['extra_data'] = sprintf(\n\t\t\t\t\t'window.%s = %s',\n\t\t\t\t\t'_wpmejsSettings',\n\t\t\t\t\twp_json_encode( apply_filters( 'mejs_settings', $mejs_settings ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP )\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn $scripts_data;\n\t}\n\n\t/**\n\t * Determines whether the legacy AMP Reader post templates are being used.\n\t *\n\t * @return bool\n\t */\n\tprivate function is_exempted_amp_page() {\n\t\tif ( is_singular( 'web-story' ) ) {\n\t\t\t// Ensure that <amp-next-page> is not injected after <amp-story> as generated by the Web Stories plugin.\n\t\t\treturn true;\n\t\t}\n\t\tif ( function_exists( 'amp_is_legacy' ) ) {\n\t\t\t// Available since AMP v2.0, this will return false if a theme like Twenty Twenty is selected as the Reader theme.\n\t\t\treturn amp_is_legacy();\n\t\t}\n\t\tif ( method_exists( 'AMP_Options_Manager', 'get_option' ) ) {\n\t\t\t// In versions prior to v2.0, checking the template mode as being 'reader' is sufficient.\n\t\t\treturn 'reader' === AMP_Options_Manager::get_option( 'theme_support' );\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Load AMP specific hooks.\n\t *\n\t * @return void\n\t */\n\tpublic function amp_load_hooks() {\n\t\tif ( $this->is_exempted_amp_page() ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {\n\t\t\t$template = self::get_settings()->render;\n\n\t\t\tadd_filter( 'jetpack_infinite_scroll_load_scripts_and_styles', '__return_false' );\n\n\t\t\tadd_action( 'template_redirect', array( $this, 'amp_start_output_buffering' ), 0 );\n\t\t\tadd_action( 'shutdown', array( $this, 'amp_output_buffer' ), 1 );\n\n\t\t\tif ( is_string( $template ) && strpos( $template, '::' ) === false && is_callable( \"amp_{$template}_hooks\" ) ) {\n\t\t\t\tcall_user_func( \"amp_{$template}_hooks\" );\n\t\t\t}\n\n\t\t\t// Warms up the amp next page markup.\n\t\t\t// This should be done outside the output buffering callback started in the template_redirect.\n\t\t\t$this->amp_get_footer_template();\n\t\t}\n\t}\n\n\t/**\n\t * Start the AMP output buffering.\n\t *\n\t * @return void\n\t */\n\tpublic function amp_start_output_buffering() {\n\t\tob_start( array( $this, 'amp_finish_output_buffering' ) );\n\t}\n\n\t/**\n\t * Flush the AMP output buffer.\n\t *\n\t * @return void\n\t */\n\tpublic function amp_output_buffer() {\n\t\tif ( ob_get_contents() ) {\n\t\t\tob_end_flush();\n\t\t}\n\t}\n\n\t/**\n\t * Filter the AMP output buffer contents.\n\t *\n\t * @param string $buffer Contents of the output buffer.\n\t *\n\t * @return string|false\n\t */\n\tpublic function amp_finish_output_buffering( $buffer ) {\n\t\t// Hide WordPress admin bar on next page load.\n\t\t$buffer = preg_replace(\n\t\t\t'/id=\"wpadminbar\"/',\n\t\t\t'$0 next-page-hide',\n\t\t\t$buffer\n\t\t);\n\n\t\t/**\n\t\t * Get the theme footers.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 9.0.0\n\t\t *\n\t\t * @param array array() An array to store multiple markup entries to be added to the footer.\n\t\t * @param string $buffer The contents of the output buffer.\n\t\t */\n\t\t$footers = apply_filters( 'jetpack_amp_infinite_footers', array(), $buffer );\n\n\t\t/**\n\t\t * Filter the output buffer.\n\t\t * Themes can leverage this hook to add custom markup on next page load.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 9.0.0\n\t\t *\n\t\t * @param string $buffer The contents of the output buffer.\n\t\t */\n\t\t$buffer = apply_filters( 'jetpack_amp_infinite_output', $buffer );\n\n\t\t// Add the amp next page markup.\n\t\t$buffer = preg_replace(\n\t\t\t'~</body>~',\n\t\t\t$this->amp_get_footer_template( $footers ) . '$0',\n\t\t\t$buffer\n\t\t);\n\n\t\treturn $buffer;\n\t}\n\n\t/**\n\t * Get AMP next page markup with the custom footers.\n\t *\n\t * @param string[] $footers The theme footers.\n\t *\n\t * @return string\n\t */\n\tprotected function amp_get_footer_template( $footers = array() ) {\n\t\tstatic $template = null;\n\n\t\tif ( null === $template ) {\n\t\t\t$template = $this->amp_footer_template();\n\t\t}\n\n\t\tif ( empty( $footers ) ) {\n\t\t\treturn $template;\n\t\t}\n\n\t\treturn preg_replace(\n\t\t\t'/%%footer%%/',\n\t\t\timplode( '', $footers ),\n\t\t\t$template\n\t\t);\n\t}\n\n\t/**\n\t * AMP Next Page markup.\n\t *\n\t * @return string\n\t */\n\tprotected function amp_footer_template() {\n\t\tob_start();\n\t\t?>\n<amp-next-page max-pages=\"<?php echo esc_attr( static::amp_get_max_pages() ); ?>\">\n\t<script type=\"application/json\">\n\t\t[\n\t\t\t<?php echo wp_json_encode( $this->amp_next_page(), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>\n\t\t]\n\t</script>\n\t<div separator>\n\t\t<?php\n\t\techo wp_kses_post(\n\t\t\t/**\n\t\t\t * AMP infinite scroll separator.\n\t\t\t *\n\t\t\t * @module infinite-scroll\n\t\t\t *\n\t\t\t * @since 9.0.0\n\t\t\t *\n\t\t\t * @param string '' The markup for the next page separator.\n\t\t\t */\n\t\t\tapply_filters( 'jetpack_amp_infinite_separator', '' )\n\t\t);\n\t\t?>\n\t</div>\n\t<div recommendation-box class=\"recommendation-box\">\n\t\t<template type=\"amp-mustache\">\n\t\t\t{{#pages}}\n\t\t\t<?php\n\t\t\techo wp_kses_post(\n\t\t\t\t/**\n\t\t\t\t * AMP infinite scroll older posts markup.\n\t\t\t\t *\n\t\t\t\t * @module infinite-scroll\n\t\t\t\t *\n\t\t\t\t * @since 9.0.0\n\t\t\t\t *\n\t\t\t\t * @param string '' The markup for the older posts/next page.\n\t\t\t\t */\n\t\t\t\tapply_filters( 'jetpack_amp_infinite_older_posts', '' )\n\t\t\t);\n\t\t\t?>\n\t\t\t{{/pages}}\n\t\t</template>\n\t</div>\n\t<div footer>\n\t\t%%footer%%\n\t</div>\n</amp-next-page>\n\t\t<?php\n\t\treturn ob_get_clean();\n\t}\n\n\t/**\n\t * Get the AMP next page information.\n\t *\n\t * @return array\n\t */\n\tprotected function amp_next_page() {\n\t\t$title = '';\n\t\t$url = '';\n\t\t$image = '';\n\n\t\tif ( ! static::amp_is_last_page() ) {\n\t\t\t$title = sprintf(\n\t\t\t\t'%s - %s %d - %s',\n\t\t\t\twp_title( '', false ),\n\t\t\t\t__( 'Page', 'jetpack' ),\n\t\t\t\tmax( get_query_var( 'paged', 1 ), 1 ) + 1,\n\t\t\t\tget_bloginfo( 'name' )\n\t\t\t);\n\t\t\t$url = get_next_posts_page_link();\n\t\t}\n\n\t\t$next_page = array(\n\t\t\t'title' => $title,\n\t\t\t'url' => $url,\n\t\t\t'image' => $image,\n\t\t);\n\n\t\t/**\n\t\t * The next page settings.\n\t\t * An array containing:\n\t\t * - title => The title to be featured on the browser tab.\n\t\t * - url => The URL of next page.\n\t\t * - image => The image URL. A required AMP setting, not in use currently. Themes are welcome to leverage.\n\t\t *\n\t\t * @module infinite-scroll\n\t\t *\n\t\t * @since 9.0.0\n\t\t *\n\t\t * @param array $next_page The contents of the output buffer.\n\t\t */\n\t\treturn apply_filters( 'jetpack_amp_infinite_next_page_data', $next_page );\n\t}\n\n\t/**\n\t * Get the number of pages left.\n\t *\n\t * @return int\n\t */\n\tprotected static function amp_get_max_pages() {\n\t\tglobal $wp_query;\n\n\t\treturn (int) $wp_query->max_num_pages - (int) $wp_query->query_vars['paged'];\n\t}\n\n\t/**\n\t * Is the last page.\n\t *\n\t * @return bool\n\t */\n\tprotected static function amp_is_last_page() {\n\t\treturn 0 === static::amp_get_max_pages();\n\t}\n}\n\n/**\n * Initialize The_Neverending_Home_Page\n */\nfunction the_neverending_home_page_init() {\n\tif ( ! current_theme_supports( 'infinite-scroll' ) ) {\n\t\treturn;\n\t}\n\n\tnew The_Neverending_Home_Page();\n}\nadd_action( 'init', 'the_neverending_home_page_init', 20 );\n\n/**\n * Check whether the current theme is infinite-scroll aware.\n * If so, include the files which add theme support.\n */\nfunction the_neverending_home_page_theme_support() {\n\tif (\n\t\t\tdefined( 'IS_WPCOM' ) && IS_WPCOM &&\n\t\t\tdefined( 'REST_API_REQUEST' ) && REST_API_REQUEST &&\n\t\t\t! doing_action( 'restapi_theme_after_setup_theme' )\n\t) {\n\t\t// Don't source theme compat files until we're in the site's context\n\t\treturn;\n\t}\n\t$theme_name = get_stylesheet();\n\n\t/**\n\t * Filter the path to the Infinite Scroll compatibility file.\n\t *\n\t * @module infinite-scroll\n\t *\n\t * @since 2.0.0\n\t *\n\t * @param string $str IS compatibility file path.\n\t * @param string $theme_name Theme name.\n\t */\n\t$customization_file = apply_filters( 'infinite_scroll_customization_file', __DIR__ . \"/themes/{$theme_name}.php\", $theme_name );\n\n\tif ( is_readable( $customization_file ) ) {\n\t\trequire_once $customization_file;\n\t}\n}\nadd_action( 'after_setup_theme', 'the_neverending_home_page_theme_support', 5 );\n\n/**\n * Early accommodation of the Infinite Scroll AJAX request\n */\nif ( The_Neverending_Home_Page::got_infinity() ) {\n\t/**\n\t * If we're sure this is an AJAX request (i.e. the HTTP_X_REQUESTED_WITH header says so),\n\t * indicate it as early as possible for actions like init\n\t */\n\tif ( ! defined( 'DOING_AJAX' ) &&\n\t\tisset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) &&\n\t\tstrtoupper( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ) ) === 'XMLHTTPREQUEST'\n\t) {\n\t\tdefine( 'DOING_AJAX', true );\n\t}\n\n\t// Don't load the admin bar when doing the AJAX response.\n\tshow_admin_bar( false );\n}\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentyfifteen.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for Twenty Fifteen.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinite scroll\n */\nfunction jetpack_twentyfifteen_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'main',\n\t\t\t'footer' => 'page',\n\t\t)\n\t);\n}\nadd_action( 'after_setup_theme', 'jetpack_twentyfifteen_infinite_scroll_init' );\n\n/**\n * Enqueue CSS stylesheet with theme styles for Infinite Scroll.\n */\nfunction jetpack_twentyfifteen_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\twp_enqueue_style( 'infinity-twentyfifteen', plugins_url( 'twentyfifteen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20141022' );\n\t\twp_style_add_data( 'infinity-twentyfifteen', 'rtl', 'replace' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentyfifteen_infinite_scroll_enqueue_styles', 25 );\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentysixteen.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for Twenty Sixteen.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinite scroll\n */\nfunction jetpack_twentysixteen_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'main',\n\t\t\t'render' => 'jetpack_twentysixteen_infinite_scroll_render',\n\t\t\t'footer' => 'content',\n\t\t)\n\t);\n}\nadd_action( 'after_setup_theme', 'jetpack_twentysixteen_infinite_scroll_init' );\n\n/**\n * Custom render function for Infinite Scroll.\n */\nfunction jetpack_twentysixteen_infinite_scroll_render() {\n\twhile ( have_posts() ) {\n\t\tthe_post();\n\t\tif ( is_search() ) {\n\t\t\tget_template_part( 'template-parts/content', 'search' );\n\t\t} else {\n\t\t\tget_template_part( 'template-parts/content', get_post_format() );\n\t\t}\n\t}\n}\n\n/**\n * Enqueue CSS stylesheet with theme styles for Infinite Scroll.\n */\nfunction jetpack_twentysixteen_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\twp_enqueue_style( 'infinity-twentysixteen', plugins_url( 'twentysixteen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20151102' );\n\t\twp_style_add_data( 'infinity-twentysixteen', 'rtl', 'replace' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentysixteen_infinite_scroll_enqueue_styles', 25 );\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentyeleven.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for @Twenty Eleven and enqueue relevant styles.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinity scroll\n */\nfunction jetpack_twentyeleven_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'content',\n\t\t\t'footer' => 'page',\n\t\t\t'footer_widgets' => jetpack_twentyeleven_has_footer_widgets(),\n\t\t)\n\t);\n}\nadd_action( 'init', 'jetpack_twentyeleven_infinite_scroll_init' );\n\n/**\n * Enqueue CSS stylesheet with theme styles for infinity.\n */\nfunction jetpack_twentyeleven_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\t// Add theme specific styles.\n\t\twp_enqueue_style( 'infinity-twentyeleven', plugins_url( 'twentyeleven.css', __FILE__ ), array( 'the-neverending-homepage' ), '20121002' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentyeleven_infinite_scroll_enqueue_styles', 25 );\n\n/**\n * Do we have footer widgets?\n */\nfunction jetpack_twentyeleven_has_footer_widgets() {\n\t// Are any of the \"Footer Area\" sidebars active?\n\tif ( is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) || is_active_sidebar( 'sidebar-5' ) ) {\n\t\treturn true;\n\t}\n\n\t// If we're on mobile and the Main Sidebar has widgets, it falls below the content, so we have footer widgets.\n\tif ( function_exists( 'jetpack_is_mobile' ) && jetpack_is_mobile() && is_active_sidebar( 'sidebar-1' ) ) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentyten.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for @Twenty Ten and enqueue relevant styles.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinity scroll\n */\nfunction jetpack_twentyten_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'content',\n\t\t\t'render' => 'jetpack_twentyten_infinite_scroll_render',\n\t\t\t'footer' => 'wrapper',\n\t\t\t'footer_widgets' => jetpack_twentyten_has_footer_widgets(),\n\t\t)\n\t);\n}\nadd_action( 'init', 'jetpack_twentyten_infinite_scroll_init' );\n\n/**\n * Set the code to be rendered on for calling posts,\n * hooked to template parts when possible.\n *\n * Note: must define a loop.\n */\nfunction jetpack_twentyten_infinite_scroll_render() {\n\tget_template_part( 'loop' );\n}\n\n/**\n * Enqueue CSS stylesheet with theme styles for infinity.\n */\nfunction jetpack_twentyten_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\t// Add theme specific styles.\n\t\twp_enqueue_style( 'infinity-twentyten', plugins_url( 'twentyten.css', __FILE__ ), array( 'the-neverending-homepage' ), '20121002' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentyten_infinite_scroll_enqueue_styles', 25 );\n\n/**\n * Do we have footer widgets?\n */\nfunction jetpack_twentyten_has_footer_widgets() {\n\tif ( is_active_sidebar( 'first-footer-widget-area' ) ||\n\t\tis_active_sidebar( 'second-footer-widget-area' ) ||\n\t\tis_active_sidebar( 'third-footer-widget-area' ) ||\n\t\tis_active_sidebar( 'fourth-footer-widget-area' ) ) {\n\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for Twenty Thirteen.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinite scroll\n */\nfunction jetpack_twentythirteen_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'content',\n\t\t\t'footer' => 'page',\n\t\t\t'footer_widgets' => array( 'sidebar-1' ),\n\t\t)\n\t);\n}\nadd_action( 'after_setup_theme', 'jetpack_twentythirteen_infinite_scroll_init' );\n\n/**\n * Enqueue CSS stylesheet with theme styles for Infinite Scroll.\n */\nfunction jetpack_twentythirteen_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\twp_enqueue_style( 'infinity-twentythirteen', plugins_url( 'twentythirteen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20130409' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentythirteen_infinite_scroll_enqueue_styles', 25 );\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for Twenty Seventeen.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinite scroll\n */\nfunction jetpack_twentyseventeen_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'main',\n\t\t\t'render' => 'jetpack_twentyseventeen_infinite_scroll_render',\n\t\t\t'footer' => 'content',\n\t\t\t'footer_widgets' => jetpack_twentyseventeen_has_footer_widgets(),\n\t\t)\n\t);\n}\nadd_action( 'init', 'jetpack_twentyseventeen_infinite_scroll_init' );\n\n/**\n * Custom render function for Infinite Scroll.\n */\nfunction jetpack_twentyseventeen_infinite_scroll_render() {\n\twhile ( have_posts() ) {\n\t\tthe_post();\n\t\tif ( is_search() ) {\n\t\t\tget_template_part( 'template-parts/post/content', 'search' );\n\t\t} else {\n\t\t\tget_template_part( 'template-parts/post/content', get_post_format() );\n\t\t}\n\t}\n}\n\n/**\n * Custom function to check for the presence of footer widgets or the social links menu\n */\nfunction jetpack_twentyseventeen_has_footer_widgets() {\n\tif ( is_active_sidebar( 'sidebar-2' ) ||\n\t\tis_active_sidebar( 'sidebar-3' ) ||\n\t\thas_nav_menu( 'social' ) ) {\n\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n/**\n * Enqueue CSS stylesheet with theme styles for Infinite Scroll.\n */\nfunction jetpack_twentyseventeen_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\twp_enqueue_style( 'infinity-twentyseventeen', plugins_url( 'twentyseventeen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20161219' );\n\t\twp_style_add_data( 'infinity-twentyseventeen', 'rtl', 'replace' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentyseventeen_infinite_scroll_enqueue_styles', 25 );\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentytwelve.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for Twenty Twelve and enqueue relevant styles.\n *\n * @package jetpack\n */\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinite scroll\n */\nfunction jetpack_twentytwelve_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'content',\n\t\t\t'footer' => 'page',\n\t\t\t'footer_widgets' => jetpack_twentytwelve_has_footer_widgets(),\n\t\t)\n\t);\n}\nadd_action( 'after_setup_theme', 'jetpack_twentytwelve_infinite_scroll_init' );\n\n/**\n * Enqueue CSS stylesheet with theme styles for infinity.\n */\nfunction jetpack_twentytwelve_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\t// Add theme specific styles.\n\t\twp_enqueue_style( 'infinity-twentytwelve', plugins_url( 'twentytwelve.css', __FILE__ ), array( 'the-neverending-homepage' ), '20120817' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentytwelve_infinite_scroll_enqueue_styles', 25 );\n\n/**\n * Do we have footer widgets?\n */\nfunction jetpack_twentytwelve_has_footer_widgets() {\n\tif ( function_exists( 'jetpack_is_mobile' ) && jetpack_is_mobile() ) {\n\t\tif ( is_front_page() && ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) ) ) {\n\t\t\treturn true;\n\t\t} elseif ( is_active_sidebar( 'sidebar-1' ) ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n\n// File: projects/plugins/jetpack/modules/infinite-scroll/themes/twentyfourteen.php\n<?php\n/**\n * Infinite Scroll Theme Assets\n *\n * Register support for Twenty Fourteen.\n *\n * @package jetpack\n */\n\nuse Automattic\\Jetpack\\Device_Detection\\User_Agent_Info;\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit( 0 );\n}\n\n/**\n * Add theme support for infinite scroll\n */\nfunction jetpack_twentyfourteen_infinite_scroll_init() {\n\tadd_theme_support(\n\t\t'infinite-scroll',\n\t\tarray(\n\t\t\t'container' => 'content',\n\t\t\t'footer' => 'page',\n\t\t\t'footer_widgets' => jetpack_twentyfourteen_has_footer_widgets(),\n\t\t)\n\t);\n}\nadd_action( 'after_setup_theme', 'jetpack_twentyfourteen_infinite_scroll_init' );\n\n/**\n * Switch to the \"click to load\" type IS with the following cases\n * 1. Viewed from iPad and the primary sidebar is active.\n * 2. Viewed from mobile and either the primary or the content sidebar is active.\n * 3. The footer widget is active.\n *\n * @return bool\n */\nfunction jetpack_twentyfourteen_has_footer_widgets() {\n\tif ( function_exists( 'jetpack_is_mobile' ) ) {\n\t\tif ( ( User_Agent_Info::is_ipad() && is_active_sidebar( 'sidebar-1' ) )\n\t\t\t|| ( jetpack_is_mobile( '', true ) && ( is_active_sidebar( 'sidebar-1' ) || is_active_sidebar( 'sidebar-2' ) ) )\n\t\t\t|| is_active_sidebar( 'sidebar-3' ) ) {\n\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Enqueue CSS stylesheet with theme styles for Infinite Scroll.\n */\nfunction jetpack_twentyfourteen_infinite_scroll_enqueue_styles() {\n\tif ( wp_script_is( 'the-neverending-homepage' ) ) {\n\t\twp_enqueue_style( 'infinity-twentyfourteen', plugins_url( 'twentyfourteen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20131118' );\n\t}\n}\nadd_action( 'wp_enqueue_scripts', 'jetpack_twentyfourteen_infinite_scroll_enqueue_styles', 25 );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Construct a Gutenberg block mechanism specifically for presenting alternative content when database queries return empty or zero matching results." }, { "role": "assistant", "content": "// File: packages/block-library/src/query-no-results/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-no-results\",\n\t\"title\": \"No Results\",\n\t\"category\": \"theme\",\n\t\"description\": \"Contains the block elements used to render content when no query results are found.\",\n\t\"ancestor\": [ \"core/query\" ],\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"queryId\", \"query\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/query-no-results/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { loop as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __( 'No posts were found.' ),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/query-no-results/save.js\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function save() {\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a WordPress block for displaying cart items with customizable options including class name, product description visibility, and locking mechanisms." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-cart-items/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-summary-cart-items-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Cart Items\",\n\t\"description\": \"Shows cart items.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"disableProductDescriptions\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [ \"woocommerce/checkout-order-summary-block\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-cart-items/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\nimport { isExperimentalBlocksEnabled } from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport type BlockAttributes = {\n\tclassName?: string;\n\tdisableProductDescriptions?: boolean;\n};\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: BlockAttributes;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className = '', disableProductDescriptions = false } = attributes;\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ /* For now this setting can only be enabled if you have experimental features enabled. */ }\n\t\t\t{ isExperimentalBlocksEnabled() && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings', 'woocommerce' ) }>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Disable product descriptions',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Disable display of product descriptions.',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ disableProductDescriptions }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tdisableProductDescriptions:\n\t\t\t\t\t\t\t\t\t\t! disableProductDescriptions,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t<Block\n\t\t\t\tdisableProductDescriptions={ disableProductDescriptions }\n\t\t\t\tclassName={ className }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block utilizing Gutenberg's framework that allows for selecting shipping or local pickup methods, with integrated attribute locking functionality." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-shipping-method-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Delivery\",\n\t\"description\": \"Select between shipping or local pickup.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/edit.tsx\n/* eslint-disable @wordpress/no-unsafe-wp-apis */\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\nimport { Icon, store, shipping } from '@wordpress/icons';\nimport { ADMIN_URL, getSetting } from '@woocommerce/settings';\nimport { LOCAL_PICKUP_ENABLED } from '@woocommerce/block-settings';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tRichText,\n} from '@wordpress/block-editor';\nimport { Button } from '@ariakit/react';\nimport { useShippingData } from '@woocommerce/base-context/hooks';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { checkoutStore as checkoutStoreDescriptor } from '@woocommerce/block-data';\nimport ExternalLinkCard from '@woocommerce/editor-components/external-link-card';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport { RatePrice, getLocalPickupPrices, getShippingPrices } from './shared';\nimport type { minMaxPrices } from './shared';\nimport './style.scss';\nimport { defaultShippingText, defaultLocalPickupText } from './constants';\n\nconst LocalPickupSelector = ( {\n\tchecked,\n\trate,\n\tshowPrice,\n\tshowIcon,\n\ttoggleText,\n\tsetAttributes,\n\tonClick,\n}: {\n\tchecked: string;\n\trate: minMaxPrices;\n\tshowPrice: boolean;\n\tshowIcon: boolean;\n\ttoggleText: string;\n\tonClick: () => void;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ) => {\n\treturn (\n\t\t<Button\n\t\t\trender={ <div /> }\n\t\t\tclassName={ clsx( 'wc-block-checkout__shipping-method-option', {\n\t\t\t\t'wc-block-checkout__shipping-method-option--selected':\n\t\t\t\t\tchecked === 'pickup',\n\t\t\t} ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ showIcon === true && (\n\t\t\t\t<Icon\n\t\t\t\t\ticon={ store }\n\t\t\t\t\tsize={ 28 }\n\t\t\t\t\tclassName=\"wc-block-checkout__shipping-method-option-icon\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichText\n\t\t\t\tvalue={ toggleText }\n\t\t\t\tplaceholder={ defaultLocalPickupText }\n\t\t\t\ttagName=\"span\"\n\t\t\t\tclassName=\"wc-block-checkout__shipping-method-option-title\"\n\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\tsetAttributes( { localPickupText: value } )\n\t\t\t\t}\n\t\t\t\t__unstableDisableFormats\n\t\t\t\tpreserveWhiteSpace\n\t\t\t/>\n\t\t\t{ showPrice === true && (\n\t\t\t\t<RatePrice minRate={ rate.min } maxRate={ rate.max } />\n\t\t\t) }\n\t\t</Button>\n\t);\n};\n\nconst ShippingSelector = ( {\n\tchecked,\n\trate,\n\tshowPrice,\n\tshowIcon,\n\ttoggleText,\n\tsetAttributes,\n\tonClick,\n}: {\n\tchecked: string;\n\trate: minMaxPrices;\n\tshowPrice: boolean;\n\tshowIcon: boolean;\n\ttoggleText: string;\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n\tonClick: () => void;\n} ) => {\n\tconst Price =\n\t\trate.min === undefined ? (\n\t\t\t<span className=\"wc-block-checkout__shipping-method-option-price\">\n\t\t\t\t{ __( 'calculated with an address', 'woocommerce' ) }\n\t\t\t</span>\n\t\t) : (\n\t\t\t<RatePrice minRate={ rate.min } maxRate={ rate.max } />\n\t\t);\n\n\treturn (\n\t\t<Button\n\t\t\trender={ <div /> }\n\t\t\tclassName={ clsx( 'wc-block-checkout__shipping-method-option', {\n\t\t\t\t'wc-block-checkout__shipping-method-option--selected':\n\t\t\t\t\tchecked === 'shipping',\n\t\t\t} ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ showIcon === true && (\n\t\t\t\t<Icon\n\t\t\t\t\ticon={ shipping }\n\t\t\t\t\tsize={ 28 }\n\t\t\t\t\tclassName=\"wc-block-checkout__shipping-method-option-icon\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichText\n\t\t\t\tvalue={ toggleText }\n\t\t\t\tplaceholder={ defaultShippingText }\n\t\t\t\ttagName=\"span\"\n\t\t\t\tclassName=\"wc-block-checkout__shipping-method-option-title\"\n\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\tsetAttributes( { shippingText: value } )\n\t\t\t\t}\n\t\t\t\t__unstableDisableFormats\n\t\t\t\tpreserveWhiteSpace\n\t\t\t/>\n\t\t\t{ showPrice === true && Price }\n\t\t</Button>\n\t);\n};\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\ttitle: string;\n\t\tdescription: string;\n\t\tshowStepNumber: boolean;\n\t\tallowCreateAccount: boolean;\n\t\tlocalPickupText: string;\n\t\tshippingText: string;\n\t\tshowPrice: boolean;\n\t\tshowIcon: boolean;\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element | null => {\n\tuseEffect( () => {\n\t\tconst localPickupTitle = getSetting< string >(\n\t\t\t'localPickupText',\n\t\t\tattributes.localPickupText\n\t\t);\n\t\tsetAttributes( { localPickupText: localPickupTitle } );\n\t\t// Disable the exhaustive deps rule because we only want to run this on first mount to set the attribute, not\n\t\t// each time the attribute changes.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ setAttributes ] );\n\tconst { setPrefersCollection } = useDispatch( checkoutStoreDescriptor );\n\tconst { prefersCollection } = useSelect( ( select ) => {\n\t\tconst checkoutStore = select( checkoutStoreDescriptor );\n\t\treturn {\n\t\t\tprefersCollection: checkoutStore.prefersCollection(),\n\t\t};\n\t} );\n\tconst { showPrice, showIcon, className, localPickupText, shippingText } =\n\t\tattributes;\n\tconst {\n\t\tshippingRates,\n\t\tneedsShipping,\n\t\thasCalculatedShipping,\n\t\tisCollectable,\n\t} = useShippingData();\n\n\tif (\n\t\t! needsShipping ||\n\t\t! hasCalculatedShipping ||\n\t\t! shippingRates ||\n\t\t! isCollectable ||\n\t\t! LOCAL_PICKUP_ENABLED\n\t) {\n\t\treturn null;\n\t}\n\n\tconst changeView = ( method: string ) => {\n\t\tif ( method === 'pickup' ) {\n\t\t\tsetPrefersCollection( true );\n\t\t} else {\n\t\t\tsetPrefersCollection( false );\n\t\t}\n\t};\n\n\treturn (\n\t\t<FormStepBlock\n\t\t\tattributes={ attributes }\n\t\t\tsetAttributes={ setAttributes }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wc-block-checkout__shipping-method',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Appearance', 'woocommerce' ) }>\n\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Choose how this block is displayed to your customers.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Show icon', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showIcon }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowIcon: ! showIcon,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Show costs', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showPrice }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowPrice: ! showPrice,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t\t<PanelBody title={ __( 'Shipping Methods', 'woocommerce' ) }>\n\t\t\t\t\t<p className=\"wc-block-checkout__controls-text\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Methods can be made managed in your store settings.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\tkey={ 'shipping_methods' }\n\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }\n\t\t\t\t\t\ttitle={ __( 'Shipping', 'woocommerce' ) }\n\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t'Manage your shipping zones, methods, and rates.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<ExternalLinkCard\n\t\t\t\t\t\tkey={ 'pickup_location' }\n\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=pickup_location` }\n\t\t\t\t\t\ttitle={ __( 'Pickup', 'woocommerce' ) }\n\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t'Allow customers to choose a local pickup location during checkout.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div\n\t\t\t\tid=\"shipping-method\"\n\t\t\t\tclassName=\"wc-block-checkout__shipping-method-container\"\n\t\t\t\trole=\"radiogroup\"\n\t\t\t>\n\t\t\t\t<ShippingSelector\n\t\t\t\t\tchecked={ prefersCollection ? 'pickup' : 'shipping' }\n\t\t\t\t\trate={ getShippingPrices(\n\t\t\t\t\t\tshippingRates[ 0 ]?.shipping_rates\n\t\t\t\t\t) }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tchangeView( 'shipping' );\n\t\t\t\t\t} }\n\t\t\t\t\tshowPrice={ showPrice }\n\t\t\t\t\tshowIcon={ showIcon }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\ttoggleText={ shippingText }\n\t\t\t\t/>\n\t\t\t\t<LocalPickupSelector\n\t\t\t\t\tchecked={ prefersCollection ? 'pickup' : 'shipping' }\n\t\t\t\t\trate={ getLocalPickupPrices(\n\t\t\t\t\t\tshippingRates[ 0 ]?.shipping_rates\n\t\t\t\t\t) }\n\t\t\t\t\tshowPrice={ showPrice }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tchangeView( 'pickup' );\n\t\t\t\t\t} }\n\t\t\t\t\tshowIcon={ showIcon }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\ttoggleText={ localPickupText }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<AdditionalFields block={ innerBlockAreas.SHIPPING_METHOD } />\n\t\t</FormStepBlock>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<AdditionalFieldsContent />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Allow customers to add a note to their order. that allows users to configure: class name, lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-note-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-order-note-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Order Note\",\n\t\"description\": \"Allow customers to add a note to their order.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": false,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-note-block/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport Noninteractive from '@woocommerce/base-components/noninteractive';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\nimport './editor.scss';\n\nexport const Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Noninteractive>\n\t\t\t\t<Block />\n\t\t\t</Noninteractive>\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress theme block featuring adjustable link destination and text alignment settings for enhanced customization." }, { "role": "assistant", "content": "// File: packages/block-library/src/comment-edit-link/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comment-edit-link\",\n\t\"title\": \"Comment Edit Link\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/comment-template\" ],\n\t\"description\": \"Displays a link to edit the comment in the WordPress Dashboard. This link is only visible to users with the edit comment capability.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"commentId\" ],\n\t\"attributes\": {\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t},\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-comment-edit-link\"\n}\n\n\n// File: packages/block-library/src/comment-edit-link/index.js\n/**\n * WordPress dependencies\n */\nimport { commentEditLink as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce-product-elements block with customizable text align" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/average-rating/block.json\n{\n\t\"name\": \"woocommerce/product-average-rating\",\n\t\"title\": \"Product Average Rating (Beta)\",\n\t\"description\": \"Display the average rating of a product\",\n\t\"apiVersion\": 3,\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"ancestor\": [ \"woocommerce/single-product\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wc-block-components-product-average-rating\"\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/average-rating/edit.tsx\n/**\n * External dependencies\n */\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport type { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport interface BlockAttributes {\n\ttextAlign: string;\n}\n\nconst Edit = ( props: BlockEditProps< BlockAttributes > ): JSX.Element => {\n\tconst { attributes, setAttributes } = props;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-woocommerce-product-average-rating',\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ attributes.textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign || '' } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Block { ...attributes } />\n\t\t\t</div>\n\t\t</>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable class name, lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/block.json\n{\n\t\"name\": \"woocommerce/cart-order-summary-discount-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Discount\",\n\t\"description\": \"Shows the cart discount row.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/cart-order-summary-totals-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport Block from './block';\n\nexport const Edit = ( {\n\tattributes,\n}: {\n\tattributes: {\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element => {\n\tconst { className } = attributes;\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Block className={ className } />\n\t\t</div>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Book a reservation with OpenTable. that allows users to configure: rid, style, iframe, and 4 more options" }, { "role": "assistant", "content": "// File: projects/plugins/jetpack/extensions/blocks/opentable/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/opentable\",\n\t\"title\": \"OpenTable\",\n\t\"description\": \"Book a reservation with OpenTable.\",\n\t\"keywords\": [ \"booking\", \"reservation\", \"restaurant\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"monetize\",\n\t\"icon\": \"<svg viewBox='0 0 22 16' width='22' height='16' xmlns='http://www.w3.org/2000/svg'><path d='m1.997 5.982c-.39457-.00039-.7804.11622-1.108699.33511-.328295.21888-.584312.5302-.735674.89459-.15136174.36439-.1912714.76548-.1146819 1.15254.0765899.38707.2662379.74274.5449639 1.02202.278726.27929.634011.46965 1.020921.54702.38692.07732.78809.03826 1.15278-.11238.36469-.15063.67652-.40602.89606-.73387.21954-.32786.33693-.71345.33733-1.10803v-.002c.001-1.1-.89-1.994-1.992-1.995zm12.006 3.988c-.3946.0004-.7805-.11625-1.1088-.33517-.3283-.21893-.5843-.53031-.7357-.89476-.1513-.36444-.1912-.76558-.1145-1.15268s.2664-.74276.5453-1.022c.2788-.27925.6342-.46953 1.0211-.54679.387-.07725.7882-.038 1.1529.11278.3647.15079.6764.40634.8959.73432.2194.32799.3366.71369.3368 1.1083v.003c.0003.52814-.2092 1.03477-.5824 1.4085s-.8795.58397-1.4076.5845zm0-9.96999843c-1.5777-.0009886-3.1203.46588743-4.43262 1.34158843-1.31236.8757-2.33558 2.1209-2.94025 3.57813-.60467 1.45722-.76365 3.06103-.45683 4.60861.30683 1.54757 1.06567 2.96947 2.18058 4.08577 1.1149 1.1163 2.53582 1.8769 4.08302 2.1856 1.5472.3088 3.1512.1518 4.6091-.451 1.458-.6028 2.7045-1.6245 3.5819-2.9358.8773-1.3112 1.3461-2.8532 1.3471-4.4309v-.005c.0008-2.11466-.8384-4.14304-2.3331-5.63899-1.4946-1.495952-3.5222-2.3369478-5.6369-2.33800843z' /></svg>\",\n\t\"supports\": { \"align\": true, \"html\": false },\n\t\"attributes\": {\n\t\t\"rid\": {\n\t\t\t\"default\": [],\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"default\": \"standard\",\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"button\", \"standard\", \"wide\", \"tall\" ]\n\t\t},\n\t\t\"iframe\": {\n\t\t\t\"default\": true,\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"domain\": {\n\t\t\t\"default\": \"com\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"lang\": {\n\t\t\t\"default\": \"en-US\",\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"en-US\", \"fr-CA\", \"de-DE\", \"es-MX\", \"ja-JP\", \"nl-NL\", \"it-IT\" ]\n\t\t},\n\t\t\"newtab\": {\n\t\t\t\"default\": false,\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"negativeMargin\": {\n\t\t\t\"default\": false,\n\t\t\t\"type\": \"boolean\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"rid\": [ \"1\" ],\n\t\t\t\"style\": \"standard\",\n\t\t\t\"iframe\": true,\n\t\t\t\"domain\": \"com\",\n\t\t\t\"lang\": \"en-US\",\n\t\t\t\"newtab\": false,\n\t\t\t\"negativeMargin\": false\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/opentable/edit.js\nimport { isWpcomPlatformSite } from '@automattic/jetpack-script-data';\nimport { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';\nimport {\n\tInspectorControls,\n\tInspectorAdvancedControls,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport {\n\tgetBlockDefaultClassName,\n\tregisterBlockStyle,\n\tunregisterBlockStyle,\n} from '@wordpress/blocks';\nimport {\n\tExternalLink,\n\tPanelBody,\n\tPlaceholder,\n\tSelectControl,\n\tToggleControl,\n\twithNotices,\n} from '@wordpress/components';\nimport { useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { isEmpty, isEqual } from 'lodash';\nimport { getActiveStyleName } from '../../shared/block-styles';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport metadata from './block.json';\nimport { languageOptions, languageValues } from './i18n';\nimport RestaurantPicker from './restaurant-picker';\nimport { buttonStyle, getStyleOptions, getStyleValues } from './styles';\nimport usePrevious from './use-previous';\nimport { getAttributesFromEmbedCode } from './utils';\n\nimport './editor.scss';\n\nconst icon = getBlockIconComponent( metadata );\n\nfunction OpenTableEdit( {\n\tattributes,\n\tclientId,\n\tisSelected,\n\tname,\n\tnoticeOperations,\n\tnoticeUI,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst defaultClassName = getBlockDefaultClassName( name );\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\n\tif ( ! isEqual( validatedAttributes, attributes ) ) {\n\t\tsetAttributes( validatedAttributes );\n\t}\n\n\tconst { align, rid, iframe, domain, lang, newtab, negativeMargin } = attributes;\n\tconst isPlaceholder = isEmpty( rid );\n\tconst selectedStyle = getActiveStyleName( getStyleOptions(), attributes.className );\n\tconst style = getActiveStyleName( getStyleOptions( rid ), attributes.className );\n\tconst prevStyle = usePrevious( style );\n\tconst __isBlockPreview = isEqual( rid, [ '1' ] );\n\n\tuseEffect( () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tif (\n\t\t\t! isPlaceholder &&\n\t\t\t! __isBlockPreview &&\n\t\t\t'wide' === style &&\n\t\t\t'wide' !== align &&\n\t\t\t'full' !== align\n\t\t) {\n\t\t\tconst content = (\n\t\t\t\t<>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'With the OpenTable block you may encounter display issues if you use its \"wide\" style with anything other than \"wide\" or \"full\" alignment. The wide display style may also not work well on smaller screens.',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t);\n\t\t\tnoticeOperations.createNotice( { status: 'warning', content } );\n\t\t}\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ __isBlockPreview, align, isPlaceholder, rid, style ] );\n\n\t// Don't allow button style with multiple restaurant IDs.\n\tuseEffect( () => {\n\t\tif ( 'button' === selectedStyle && Array.isArray( rid ) && rid?.length > 1 ) {\n\t\t\tsetAttributes( { className: '', style: '' } );\n\t\t}\n\t}, [ rid, selectedStyle, setAttributes ] );\n\n\t// Temporarily remove button block style if multiple restaurants are present.\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( Array.isArray( rid ) && rid?.length > 1 ) {\n\t\t\tunregisterBlockStyle( 'jetpack/opentable', [ 'button' ] );\n\t\t} else {\n\t\t\tregisterBlockStyle( 'jetpack/opentable', buttonStyle );\n\t\t}\n\t}, [ isSelected, rid ] );\n\n\tuseEffect( () => {\n\t\t// Reset wide alignment if switching from wide style.\n\t\tif ( 'wide' === prevStyle && 'wide' === align ) {\n\t\t\tsetAttributes( { align: '' } );\n\t\t}\n\n\t\t// If switching to wide style set wide alignment as well as it works better.\n\t\tif ( 'wide' === style && prevStyle && style !== prevStyle ) {\n\t\t\tsetAttributes( { align: 'wide' } );\n\t\t}\n\n\t\t// Need to force attribute to be updated after switch to using block styles\n\t\t// so it still meets frontend rendering expectations.\n\t\tsetAttributes( { style } );\n\t}, [ align, style, prevStyle, setAttributes ] );\n\n\tconst parseEmbedCode = embedCode => {\n\t\tconst newAttributes = getAttributesFromEmbedCode( embedCode );\n\t\tif ( ! newAttributes ) {\n\t\t\tnoticeOperations.removeAllNotices();\n\t\t\tnoticeOperations.createErrorNotice(\n\t\t\t\t<>\n\t\t\t\t\t<strong>{ __( 'We ran into an issue', 'jetpack' ) }</strong>\n\t\t\t\t\t<br />\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Please ensure this embed matches the one from your OpenTable account',\n\t\t\t\t\t\t'jetpack'\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t);\n\t\t}\n\n\t\tconst validatedNewAttributes = getValidatedAttributes( metadata.attributes, newAttributes );\n\t\tsetAttributes( validatedNewAttributes );\n\t\tnoticeOperations.removeAllNotices();\n\t};\n\n\tconst styleValues = getStyleValues( rid );\n\tconst getTypeAndTheme = fromStyle =>\n\t\trid?.length > 1\n\t\t\t? [ 'multi', 'button' !== fromStyle ? fromStyle : 'standard' ]\n\t\t\t: [\n\t\t\t\t\t'button' === fromStyle ? 'button' : 'standard',\n\t\t\t\t\t'button' === fromStyle ? 'standard' : fromStyle,\n\t\t\t ];\n\n\tconst blockPreview = styleOverride => {\n\t\tconst [ type, theme ] = getTypeAndTheme( styleOverride ? styleOverride : style );\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div className={ `${ defaultClassName }-overlay` }></div>\n\t\t\t\t<iframe\n\t\t\t\t\ttitle={ sprintf(\n\t\t\t\t\t\t/* translators: %s: a unique ID. */\n\t\t\t\t\t\t__( 'Open Table Preview %s', 'jetpack' ),\n\t\t\t\t\t\tclientId\n\t\t\t\t\t) }\n\t\t\t\t\tscrolling=\"no\"\n\t\t\t\t\tsrc={ `https://www.opentable.com/widget/reservation/canvas?rid=${\n\t\t\t\t\t\tArray.isArray( rid ) ? rid.join( '%2C' ) : ''\n\t\t\t\t\t}&type=${ type }&theme=${ theme }&overlay=false&domain=${ domain }&lang=${\n\t\t\t\t\t\tlang && languageValues.includes( lang ) ? lang : 'en-US'\n\t\t\t\t\t}&newtab=${ newtab }&disablega=true` }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t};\n\n\tconst onPickerSubmit = input => {\n\t\tif ( Array.isArray( input ) ) {\n\t\t\tsetAttributes( {\n\t\t\t\trid: input,\n\t\t\t\tstyle: input.length > 1 && 'button' === style ? 'standard' : style,\n\t\t\t} );\n\t\t} else {\n\t\t\tparseEmbedCode( input );\n\t\t}\n\t};\n\n\tconst inspectorControls = (\n\t\t<>\n\t\t\t<InspectorAdvancedControls>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Load the widget in an iFrame (Recommended)', 'jetpack' ) }\n\t\t\t\t\tchecked={ iframe }\n\t\t\t\t\tonChange={ () => setAttributes( { iframe: ! iframe } ) }\n\t\t\t\t\tclassName=\"is-opentable\"\n\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t/>\n\t\t\t\t{ 'button' === style && (\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Remove button margin', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ negativeMargin }\n\t\t\t\t\t\tonChange={ () => setAttributes( { negativeMargin: ! negativeMargin } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</InspectorAdvancedControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t<RestaurantPicker rids={ rid } onChange={ onPickerSubmit } />\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Language', 'jetpack' ) }\n\t\t\t\t\t\tvalue={ lang }\n\t\t\t\t\t\tonChange={ newLang => setAttributes( { lang: newLang } ) }\n\t\t\t\t\t\toptions={ languageOptions }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Open in a new window', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ newtab }\n\t\t\t\t\t\tonChange={ () => setAttributes( { newtab: ! newtab } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n\n\tconst supportLink = isWpcomPlatformSite()\n\t\t? 'https://en.support.wordpress.com/wordpress-editor/blocks/opentable-block/'\n\t\t: 'https://jetpack.com/support/jetpack-blocks/opentable-block/';\n\n\tconst blockPlaceholder = (\n\t\t<Placeholder\n\t\t\tlabel={ __( 'OpenTable Reservation', 'jetpack' ) }\n\t\t\ticon={ icon }\n\t\t\tinstructions={ __(\n\t\t\t\t'Enter your restaurants IDs, separated by comma, or paste an OpenTable Reservation Widget embed code.',\n\t\t\t\t'jetpack'\n\t\t\t) }\n\t\t\tnotices={ noticeUI }\n\t\t>\n\t\t\t<RestaurantPicker rids={ rid } onSubmit={ onPickerSubmit } />\n\t\t\t<div className={ `${ defaultClassName }-placeholder-links` }>\n\t\t\t\t<ExternalLink href=\"https://restaurant.opentable.com/get-started/\">\n\t\t\t\t\t{ __( 'Sign up for OpenTable', 'jetpack' ) }\n\t\t\t\t</ExternalLink>\n\t\t\t\t<ExternalLink href={ supportLink }>{ __( 'Learn more', 'jetpack' ) }</ExternalLink>\n\t\t\t</div>\n\t\t</Placeholder>\n\t);\n\n\tconst editClasses = clsx( {\n\t\t[ `is-style-${ style }` ]: ! isPlaceholder && styleValues.includes( style ),\n\t\t'is-placeholder': isPlaceholder,\n\t\t'is-multi': 'multi' === getTypeAndTheme( style )[ 0 ],\n\t\t[ `align${ align }` ]: align,\n\t\t'has-no-margin': negativeMargin,\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ noticeUI }\n\t\t\t<div className={ editClasses }>\n\t\t\t\t{ ! isPlaceholder && inspectorControls }\n\t\t\t\t{ ! isPlaceholder ? blockPreview() : blockPlaceholder }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default withNotices( OpenTableEdit );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block for seamlessly displaying Eventbrite event specifics and purchase options, utilizing input fields for event link, unique identifier, and design preferences." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/eventbrite/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/eventbrite\",\n\t\"title\": \"Eventbrite Checkout\",\n\t\"description\": \"Embed Eventbrite event details and ticket checkout.\",\n\t\"keywords\": [ \"events\", \"tickets\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"embed\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M18.041,3.931L5.959,3C4.325,3,3,4.325,3,5.959v12.083C3,19.675,4.325,21,5.959,21l12.083-0.931C19.699,19.983,21,18.744,21,17.11V6.89C21,5.256,19.741,4.027,18.041,3.931zM16.933,8.17c-0.082,0.215-0.192,0.432-0.378,0.551c-0.188,0.122-0.489,0.132-0.799,0.132c-1.521,0-3.062-0.048-4.607-0.048c-0.152,0.708-0.304,1.416-0.451,2.128c0.932-0.004,1.873,0.005,2.81,0.005c0.726,0,1.462-0.069,1.586,0.525c0.04,0.189-0.001,0.426-0.052,0.615c-0.105,0.38-0.258,0.676-0.625,0.783c-0.185,0.054-0.408,0.058-0.646,0.058c-1.145,0-2.345,0.017-3.493,0.02c-0.169,0.772-0.328,1.553-0.489,2.333c1.57-0.005,3.067-0.041,4.633-0.058c0.627-0.007,1.085,0.194,1.009,0.85c-0.031,0.262-0.098,0.497-0.211,0.725c-0.102,0.208-0.248,0.376-0.488,0.452c-0.237,0.075-0.541,0.064-0.862,0.078c-0.304,0.014-0.614,0.008-0.924,0.016c-0.309,0.009-0.619,0.022-0.919,0.022c-1.253,0-2.429,0.08-3.683,0.073c-0.603-0.004-1.014-0.249-1.124-0.757c-0.059-0.273-0.018-0.58,0.036-0.841c0.541-2.592,1.083-5.176,1.629-7.763c0.056-0.265,0.114-0.511,0.225-0.714C9.279,7.051,9.534,6.834,9.9,6.735c0.368-0.099,0.883-0.047,1.344-0.047c0.305,0,0.612,0.008,0.914,0.016c0.925,0.026,1.817,0.03,2.747,0.053c0.304,0.007,0.615,0.016,0.915,0.016c0.621,0,1.17,0.073,1.245,0.614C17.104,7.675,17.014,7.954,16.933,8.17z'/></svg>\",\n\t\"supports\": { \"html\": false, \"align\": true },\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"eventId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"style\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"inline\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"url\": \"https://www.eventbrite.com/e/test-event-tickets-123456789\",\n\t\t\t\"eventId\": 123456789,\n\t\t\t\"style\": \"modal\"\n\t\t},\n\t\t\"innerBlocks\": [\n\t\t\t{\n\t\t\t\t\"name\": \"jetpack/button\",\n\t\t\t\t\"attributes\": {\n\t\t\t\t\t\"element\": \"a\",\n\t\t\t\t\t\"text\": \"Register\",\n\t\t\t\t\t\"uniqueId\": \"eventbrite-widget-id\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/eventbrite/edit.js\nimport { BlockControls, InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { Button, withNotices } from '@wordpress/components';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport testEmbedUrl from '../../shared/test-embed-url';\nimport metadata from './block.json';\nimport { EVENTBRITE_EXAMPLE_URL, URL_REGEX } from './constants';\nimport { ToolbarControls, InspectorControls } from './controls';\nimport EmbedForm from './form';\nimport Loader from './loader';\nimport InlinePreview from './preview';\nimport { convertToLink, eventIdFromUrl, normalizeUrlInput } from './utils';\n\nimport './editor.scss';\n\nconst innerButtonBlock = {\n\tname: 'jetpack/button',\n\tattributes: {\n\t\telement: 'a',\n\t\ttext: _x( 'Register', 'verb: e.g. register for an event.', 'jetpack' ),\n\t\tuniqueId: 'eventbrite-widget-id',\n\t},\n};\n\nexport const EventbriteEdit = props => {\n\tconst { attributes, noticeOperations, onReplace, setAttributes } = props;\n\tconst { url, style } = attributes;\n\n\tconst blockProps = useBlockProps();\n\tconst [ editingUrl, setEditingUrl ] = useState( false );\n\tconst [ editedUrl, setEditedUrl ] = useState( attributes.url || '' );\n\tconst [ isResolvingUrl, setIsResolvingUrl ] = useState( false );\n\n\tconst cannotEmbed = ! isResolvingUrl && url && ! URL_REGEX.test( url );\n\n\tconst setErrorNotice = useCallback( () => {\n\t\tnoticeOperations.removeAllNotices();\n\t\tnoticeOperations.createErrorNotice(\n\t\t\t<>\n\t\t\t\t{ __( 'Sorry, this content could not be embedded.', 'jetpack' ) }{ ' ' }\n\t\t\t\t<Button variant=\"link\" onClick={ () => convertToLink( editedUrl, onReplace ) }>\n\t\t\t\t\t{ _x( 'Convert block to link', 'button label', 'jetpack' ) }\n\t\t\t\t</Button>\n\t\t\t</>\n\t\t);\n\t}, [ noticeOperations, onReplace, editedUrl ] );\n\n\tconst setUrl = useCallback(\n\t\tstr => {\n\t\t\tif ( ! str || EVENTBRITE_EXAMPLE_URL === str || 'modal' === style ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst eventId = eventIdFromUrl( str );\n\n\t\t\tif ( ! eventId ) {\n\t\t\t\tsetErrorNotice();\n\t\t\t} else {\n\t\t\t\tconst newAttributes = {\n\t\t\t\t\teventId,\n\t\t\t\t\turl: str,\n\t\t\t\t};\n\n\t\t\t\ttestEmbedUrl( newAttributes.url, setIsResolvingUrl )\n\t\t\t\t\t.then( resolvedUrl => {\n\t\t\t\t\t\tconst newValidatedAttributes = getValidatedAttributes( metadata.attributes, {\n\t\t\t\t\t\t\t...newAttributes,\n\t\t\t\t\t\t\turl: resolvedUrl,\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tsetAttributes( newValidatedAttributes );\n\t\t\t\t\t\tsetEditedUrl( resolvedUrl );\n\t\t\t\t\t\tnoticeOperations.removeAllNotices();\n\t\t\t\t\t} )\n\t\t\t\t\t.catch( () => {\n\t\t\t\t\t\tsetAttributes( { eventId: undefined, url: undefined } );\n\t\t\t\t\t\tsetErrorNotice();\n\t\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ style, noticeOperations, setErrorNotice, setAttributes, setEditedUrl, setIsResolvingUrl ]\n\t);\n\n\tuseEffect( () => {\n\t\tsetUrl( url );\n\t}, [ url, setUrl ] );\n\n\tlet content;\n\n\tif ( isResolvingUrl ) {\n\t\tcontent = <Loader />;\n\t} else if ( editingUrl || ! url || cannotEmbed ) {\n\t\tcontent = (\n\t\t\t<EmbedForm\n\t\t\t\t{ ...props }\n\t\t\t\teditedUrl={ editedUrl }\n\t\t\t\tonChange={ e => setEditedUrl( e.target.value ) }\n\t\t\t\tonSubmit={ e => {\n\t\t\t\t\tif ( e ) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t}\n\n\t\t\t\t\tsetUrl( normalizeUrlInput( editedUrl ) );\n\t\t\t\t\tsetEditingUrl( false );\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t} else {\n\t\tcontent = (\n\t\t\t<>\n\t\t\t\t<InspectorControls { ...props } />\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<ToolbarControls setEditingUrl={ setEditingUrl } />\n\t\t\t\t</BlockControls>\n\t\t\t\t{ style === 'modal' ? (\n\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\ttemplate={ [ [ innerButtonBlock.name, innerButtonBlock.attributes ] ] }\n\t\t\t\t\t\ttemplateLock=\"all\"\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<InlinePreview { ...props } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn <div { ...blockProps }>{ content }</div>;\n};\n\nexport default withNotices( EventbriteEdit );\n\n\n// File: projects/plugins/jetpack/extensions/blocks/eventbrite/save.js\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { eventId, style, url } = attributes;\n\n\tif ( ! eventId ) {\n\t\treturn;\n\t}\n\n\tlet content;\n\n\tif ( style === 'modal' ) {\n\t\tcontent = <InnerBlocks.Content />;\n\t} else if ( url ) {\n\t\tcontent = (\n\t\t\t<a className=\"eventbrite__direct-link\" href={ url }>\n\t\t\t\t{ url }\n\t\t\t</a>\n\t\t);\n\t}\n\n\tconst blockProps = useBlockProps.save();\n\treturn <div { ...blockProps }>{ content }</div>;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a modular block that empowers users to dynamically render product grids by selecting specific attributes, defining display operators, and adjusting column configurations with multiple advanced options." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/block.json\n{\n\t\"name\": \"woocommerce/products-by-attribute\",\n\t\"title\": \"Products by Attribute\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"description\": \"Display a grid of products with selected attributes.\",\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"inserter\": false\n\t},\n\t\"attributes\": {\n\t\t\"attributes\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t},\n\t\t\"attrOperator\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [ \"all\", \"any\" ],\n\t\t\t\"default\": \"any\"\n\t\t},\n\t\t\"columns\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"contentVisibility\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"image\": true,\n\t\t\t\t\"title\": true,\n\t\t\t\t\"price\": true,\n\t\t\t\t\"rating\": true,\n\t\t\t\t\"button\": true\n\t\t\t},\n\t\t\t\"properties\": {\n\t\t\t\t\"image\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"title\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"price\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"rating\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t},\n\t\t\t\t\"button\": {\n\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\"default\": true\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"orderby\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [\n\t\t\t\t\"date\",\n\t\t\t\t\"popularity\",\n\t\t\t\t\"price_asc\",\n\t\t\t\t\"price_desc\",\n\t\t\t\t\"rating\",\n\t\t\t\t\"title\",\n\t\t\t\t\"menu_order\"\n\t\t\t],\n\t\t\t\"default\": \"date\"\n\t\t},\n\t\t\"rows\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t},\n\t\t\"alignButtons\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"stockStatus\": {\n\t\t\t\"type\": \"array\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/edit.tsx\n/**\n * External dependencies\n */\nimport { BlockControls, useBlockProps } from '@wordpress/block-editor';\nimport {\n\tDisabled,\n\tToolbarGroup,\n\twithSpokenMessages,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { Props } from './types';\nimport { ProductsByAttributeInspectorControls } from './inspector-controls';\nimport { ProductsByAttributeEditMode } from './edit-mode';\nimport { ProductsByAttributeBlock } from './block';\n\nexport const EditBlock = ( props: Props ): JSX.Element => {\n\tconst blockProps = useBlockProps();\n\n\tconst {\n\t\tattributes: { attributes },\n\t} = props;\n\n\tconst [ isEditing, setIsEditing ] = useState( ! attributes.length );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup\n\t\t\t\t\tcontrols={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ticon: 'edit',\n\t\t\t\t\t\t\ttitle: __(\n\t\t\t\t\t\t\t\t'Edit selected attribute',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tonClick: () => setIsEditing( ! isEditing ),\n\t\t\t\t\t\t\tisActive: isEditing,\n\t\t\t\t\t\t},\n\t\t\t\t\t] }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<ProductsByAttributeInspectorControls { ...props } />\n\t\t\t{ isEditing ? (\n\t\t\t\t<ProductsByAttributeEditMode\n\t\t\t\t\tisEditing={ isEditing }\n\t\t\t\t\tsetIsEditing={ setIsEditing }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<Disabled>\n\t\t\t\t\t<ProductsByAttributeBlock { ...props } />\n\t\t\t\t</Disabled>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\nexport const Edit = withSpokenMessages( EditBlock );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a WordPress block to Display the number of products on the archive page or search result page." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-results-count/block.json\n{\n\t\"name\": \"woocommerce/product-results-count\",\n\t\"title\": \"Product Results Count\",\n\t\"description\": \"Display the number of products on the archive page or search result page.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t}\n\t},\n\t\"usesContext\": [ \"queryId\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-results-count/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\nexport interface Attributes {\n\tclassName?: string;\n}\n\nconst Edit = () => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'woocommerce wc-block-product-results-count',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<p className=\"woocommerce-result-count\">\n\t\t\t\t{ __( 'Showing 1-X of X results', 'woocommerce' ) }\n\t\t\t</p>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Collect your customer's shipping address. with these attributes: lock" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-shipping-address-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Shipping Address\",\n\t\"description\": \"Collect your customer's shipping address.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": false,\n\t\t\"lock\": false\n\t},\n\t\"attributes\": {\n\t\t\"lock\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"remove\": true,\n\t\t\t\t\"move\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { useCheckoutAddress } from '@woocommerce/base-context/hooks';\nimport { innerBlockAreas } from '@woocommerce/blocks-checkout';\n\n/**\n * Internal dependencies\n */\nimport {\n\tFormStepBlock,\n\tAdditionalFields,\n\tAdditionalFieldsContent,\n} from '../../form-step';\nimport Block from './block';\nimport { AddressFieldControls } from '../../address-field-controls';\n\nexport const Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: {\n\t\ttitle: string;\n\t\tdescription: string;\n\t\tshowStepNumber: boolean;\n\t\tclassName: string;\n\t};\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ): JSX.Element | null => {\n\tconst { showShippingFields } = useCheckoutAddress();\n\n\tif ( ! showShippingFields ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<AddressFieldControls />\n\t\t\t<FormStepBlock\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tattributes={ attributes }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wc-block-checkout__shipping-fields',\n\t\t\t\t\tattributes?.className\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t<Block />\n\t\t\t\t<AdditionalFields block={ innerBlockAreas.SHIPPING_ADDRESS } />\n\t\t\t</FormStepBlock>\n\t\t</>\n\t);\n};\n\nexport const Save = (): JSX.Element => {\n\treturn (\n\t\t<div { ...useBlockProps.save() }>\n\t\t\t<AdditionalFieldsContent />\n\t\t</div>\n\t);\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a dynamic content block in WordPress that dynamically manages page visibility through configurable view count parameters and user engagement thresholds." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/repeat-visitor/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/repeat-visitor\",\n\t\"title\": \"Repeat Visitor\",\n\t\"description\": \"Control block visibility based on how often a visitor has viewed the page.\",\n\t\"keywords\": [ \"return\", \"visitors\", \"visibility\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"widgets\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false\n\t},\n\t\"attributes\": {\n\t\t\"criteria\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"after-visits\"\n\t\t},\n\t\t\"threshold\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 3\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"criteria\": \"after-visits\",\n\t\t\t\"threshold\": 3\n\t\t},\n\t\t\"innerBlocks\": [\n\t\t\t{\n\t\t\t\t\"name\": \"core/paragraph\",\n\t\t\t\t\"attributes\": \"This block will only appear to a visitor who visited the page three or more times.\"\n\t\t\t}\n\t\t]\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/repeat-visitor/constants.js\nexport const CRITERIA_AFTER = 'after-visits';\nexport const CRITERIA_BEFORE = 'before-visits';\nexport const DEFAULT_THRESHOLD = 3;\nexport const COOKIE_NAME = 'jp-visit-counter';\nexport const MAX_COOKIE_AGE = 6 * 30 * 24 * 60 * 60; // 6 months\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a design block with customizable label" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/tab/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"__experimental\": true,\n\t\"apiVersion\": 3,\n\t\"name\": \"core/tab\",\n\t\"title\": \"Tab\",\n\t\"description\": \"Content for a tab in a tabbed interface.\",\n\t\"version\": \"1.0.0\",\n\t\"category\": \"design\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"parent\": [ \"core/tabs\" ],\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"html\": false,\n\t\t\"reusable\": false,\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": true,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowVerticalAlignment\": true,\n\t\t\t\"allowJustification\": true,\n\t\t\t\"allowOrientation\": true,\n\t\t\t\"allowSizingOnChildren\": true\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"__experimentalFontFamily\": true\n\t\t\t},\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"core/tab-label\": \"label\"\n\t},\n\t\"editorScript\": \"file:./index.js\",\n\t\"style\": \"file:./style-index.css\"\n}\n\n\n// File: packages/block-library/src/tab/index.js\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\nimport icon from './icon';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/tab/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function Save( { attributes } ) {\n\tconst { anchor } = attributes;\n\n\tconst tabPanelId = anchor;\n\n\t// eslint-disable-next-line react-compiler/react-compiler\n\tconst blockProps = useBlockProps.save();\n\t// eslint-disable-next-line react-compiler/react-compiler\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn <section { ...innerBlocksProps } id={ tabPanelId } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a design block with customizable open by default" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/accordion-item/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/accordion-item\",\n\t\"title\": \"Accordion Item\",\n\t\"category\": \"design\",\n\t\"description\": \"Wraps the heading and panel in one unit.\",\n\t\"parent\": [ \"core/accordion\" ],\n\t\"allowedBlocks\": [ \"core/accordion-heading\", \"core/accordion-panel\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true\n\t\t},\n\t\t\"interactivity\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"blockGap\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"layout\": {\n\t\t\t\"allowEditing\": false\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"contentRole\": true\n\t},\n\t\"attributes\": {\n\t\t\"openByDefault\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"textdomain\": \"default\",\n\t\"style\": \"wp-block-accordion-item\"\n}\n\n\n// File: packages/block-library/src/accordion-item/index.js\n/**\n * Internal dependencies\n */\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\nimport initBlock from '../utils/init-block';\nimport icon from './icon';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/accordion-item/save.js\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\nexport default function save( { attributes } ) {\n\tconst { openByDefault } = attributes;\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( {\n\t\t\t'is-open': openByDefault,\n\t\t} ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display the total number of results in a query. that allows users to configure: display type" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/query-total/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query-total\",\n\t\"title\": \"Query Total\",\n\t\"category\": \"theme\",\n\t\"ancestor\": [ \"core/query\" ],\n\t\"description\": \"Display the total number of results in a query.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"displayType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"total-results\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"queryId\", \"query\" ],\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-query-total\"\n}\n\n\n// File: packages/block-library/src/query-total/index.js\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\nimport initBlock from '../utils/init-block';\nimport { queryTotal } from './icons';\n\n/* Block settings */\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon: queryTotal,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a flexible date archive block that empowers users to personalize their archive view through configurable display settings like dropdown style, label, post count, and type." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/archives/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/archives\",\n\t\"title\": \"Archives\",\n\t\"category\": \"widgets\",\n\t\"description\": \"Display a date archive of your posts.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"displayAsDropdown\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showLabel\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showPostCounts\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"monthly\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-archives-editor\"\n}\n\n\n// File: packages/block-library/src/archives/index.js\n/**\n * WordPress dependencies\n */\nimport { archive as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block that renders hyperlinks for various content types, enabling precise control over link presentation and destination settings." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/read-more/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/read-more\",\n\t\"title\": \"Read More\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the link of a post, page, or any other content-type.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"content\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\" ],\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true,\n\t\t\t\t\"textDecoration\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"padding\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"style\": \"wp-block-read-more\"\n}\n\n\n// File: packages/block-library/src/read-more/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { link as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Read more' ),\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a theme block with customizable text align, is link, link target" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-author-name/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-author-name\",\n\t\"title\": \"Author Name\",\n\t\"category\": \"theme\",\n\t\"description\": \"The author name.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postType\", \"postId\" ],\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": \"wp-block-post-author-name\"\n}\n\n\n// File: packages/block-library/src/post-author-name/index.js\n/**\n * WordPress dependencies\n */\nimport { postAuthor as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\ttransforms,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Use blocks to create an \"Add to cart\" area that's customized for different product types, such as variable and grouped. with these attributes: is descendant of add to cart with options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options\",\n\t\"title\": \"Add to Cart + Options (Beta)\",\n\t\"description\": \"Use blocks to create an \\\"Add to cart\\\" area that's customized for different product types, such as variable and grouped. \",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"attributes\": {\n\t\t\"isDescendantOfAddToCartWithOptions\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\" ],\n\t\"providesContext\": {\n\t\t\"woocommerce/isDescendantOfAddToCartWithOptions\": \"isDescendantOfAddToCartWithOptions\"\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"interactivity\": true\n\t},\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"viewScriptModule\": \"woocommerce/add-to-cart-with-options\",\n\t\"style\": \"file:../woocommerce/add-to-cart-with-options-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/add-to-cart-with-options-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/index.tsx\n/**\n * External dependencies\n */\nimport { button } from '@wordpress/icons';\nimport { getPlugin, registerPlugin } from '@wordpress/plugins';\nimport { registerProductBlockType } from '@woocommerce/atomic-utils';\nimport type { BlockConfiguration } from '@wordpress/blocks';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport ProductTypeSelectorPlugin from './plugins';\nimport metadata from './block.json';\nimport AddToCartOptionsEdit from './edit';\nimport '../../base/components/quantity-selector/style.scss';\nimport type { Attributes } from './types';\n\n// Register a plugin that adds a product type selector to the template sidebar.\nconst PLUGIN_NAME = 'document-settings-template-selector-pane';\nif ( ! getPlugin( PLUGIN_NAME ) ) {\n\tregisterPlugin( PLUGIN_NAME, {\n\t\trender: ProductTypeSelectorPlugin,\n\t} );\n}\n\n// Register the block\nregisterProductBlockType< Attributes >(\n\t{\n\t\t...( metadata as BlockConfiguration< Attributes > ),\n\t\ticon: {\n\t\t\tsrc: ( { size }: { size?: number } ) => (\n\t\t\t\t<span\n\t\t\t\t\tclassName=\"wp-block-woocommerce-add-to-cart-with-options__block-icon\"\n\t\t\t\t\tstyle={ { height: size, width: size } }\n\t\t\t\t>\n\t\t\t\t\t{ button }\n\t\t\t\t</span>\n\t\t\t),\n\t\t},\n\t\tedit: AddToCartOptionsEdit,\n\t\tsave: () => null,\n\t\tancestor: [ 'woocommerce/single-product' ],\n\t},\n\t{\n\t\tisAvailableOnPostEditor: true,\n\t}\n);\n\n// Remove the Add to Cart + Options template part from the block inserter.\naddFilter(\n\t'blocks.registerBlockType',\n\t'woocommerce/area_add-to-cart-with-options',\n\tfunction ( blockSettings, blockName ) {\n\t\tif ( blockName === 'core/template-part' ) {\n\t\t\treturn {\n\t\t\t\t...blockSettings,\n\t\t\t\tvariations: blockSettings.variations.map(\n\t\t\t\t\t( variation: { name: string } ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tvariation.name === 'area_add-to-cart-with-options'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...variation,\n\t\t\t\t\t\t\t\tscope: [],\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn variation;\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t\treturn blockSettings;\n\t}\n);\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Displays the current category description. that allows users to configure: text align" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/category-description/block.json\n{\n\t\"name\": \"woocommerce/category-description\",\n\t\"title\": \"Product Category Description\",\n\t\"description\": \"Displays the current category description.\",\n\t\"category\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true\n\t\t},\n\t\t\"html\": false,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": true\n\t},\n\t\"usesContext\": [ \"termId\", \"termTaxonomy\" ]\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/category-description/edit.tsx\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore, useEntityProp } from '@wordpress/core-data';\nimport {\n\t// @ts-expect-error AlignmentControl is not exported from @wordpress/block-editor\n\tAlignmentControl,\n\tBlockControls,\n\tuseBlockProps,\n\tPlainText,\n} from '@wordpress/block-editor';\ninterface Props {\n\tattributes: {\n\t\ttextAlign?: string;\n\t};\n\tsetAttributes: ( attrs: Partial< Props[ 'attributes' ] > ) => void;\n\tcontext: {\n\t\ttermId?: number;\n\t\ttermTaxonomy?: string;\n\t};\n}\n\nexport default function Edit( { attributes, setAttributes, context }: Props ) {\n\tconst { textAlign } = attributes;\n\tconst { termId, termTaxonomy } = context;\n\n\tconst userCanEdit = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! termId ) return false;\n\t\t\t// @ts-expect-error canUser is not typed correctly\n\t\t\t// This use actually reflects the use seen in `core/post-title` block.\n\t\t\treturn select( coreStore ).canUser( 'update', {\n\t\t\t\tkind: 'taxonomy',\n\t\t\t\tname: termTaxonomy || 'product_cat',\n\t\t\t\tid: termId,\n\t\t\t} );\n\t\t},\n\t\t[ termId, termTaxonomy ]\n\t);\n\n\tconst [ rawDescription = '', setDescription, fullDescription ] =\n\t\tuseEntityProp(\n\t\t\t'taxonomy',\n\t\t\ttermTaxonomy || 'product_cat',\n\t\t\t'description',\n\t\t\tString( termId )\n\t\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( { [ `has-text-align-${ textAlign }` ]: textAlign } ),\n\t} );\n\n\tlet descriptionElement = (\n\t\t<p { ...blockProps }>{ __( 'Category description', 'woocommerce' ) }</p>\n\t);\n\n\tif ( termId ) {\n\t\tdescriptionElement = userCanEdit ? (\n\t\t\t<PlainText\n\t\t\t\t// @ts-expect-error PlainText component types are not up-to-date\n\t\t\t\ttagName=\"p\"\n\t\t\t\tplaceholder={ __( 'No description', 'woocommerce' ) as string }\n\t\t\t\tvalue={ rawDescription }\n\t\t\t\tonChange={ ( v: string ) =>\n\t\t\t\t\t( setDescription as ( v: string ) => void )( v )\n\t\t\t\t}\n\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t{ ...blockProps }\n\t\t\t/>\n\t\t) : (\n\t\t\t<p\n\t\t\t\t{ ...blockProps }\n\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t__html: fullDescription?.rendered,\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ /* @ts-expect-error BlockControls typing */ }\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign: string ) =>\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign || '' } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t{ descriptionElement }\n\t\t</>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "To craft a custom WordPress block specifically designed for rendering WooCommerce page content, enabling flexible configuration options for users." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/page-content-wrapper/block.json\n{\n\t\"name\": \"woocommerce/page-content-wrapper\",\n\t\"title\": \"WooCommerce Page\",\n\t\"description\": \"Displays WooCommerce page content.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"inserter\": false\n\t},\n\t\"attributes\": {\n\t\t\"page\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"postId\": \"postId\",\n\t\t\"postType\": \"postType\"\n\t},\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/page-content-wrapper/index.tsx\n/**\n * External dependencies\n */\nimport {\n\tregisterBlockType,\n\tInnerBlockTemplate,\n\tBlockAttributes,\n} from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { page } from '@wordpress/icons';\nimport { CHECKOUT_PAGE_ID, CART_PAGE_ID } from '@woocommerce/block-settings';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport './editor.scss';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: BlockAttributes;\n\tsetAttributes: ( attrs: BlockAttributes ) => void;\n} ) => {\n\tconst TEMPLATE: InnerBlockTemplate[] = [\n\t\t[ 'core/post-title', { align: 'wide', level: 1 } ],\n\t\t[ 'core/post-content', { align: 'wide' } ],\n\t];\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-woocommerce-page-content-wrapper',\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( ! attributes.postId && attributes.page ) {\n\t\t\tlet postId = 0;\n\n\t\t\tif ( attributes.page === 'checkout' ) {\n\t\t\t\tpostId = CHECKOUT_PAGE_ID;\n\t\t\t}\n\n\t\t\tif ( attributes.page === 'cart' ) {\n\t\t\t\tpostId = CART_PAGE_ID;\n\t\t\t}\n\n\t\t\tif ( postId ) {\n\t\t\t\tsetAttributes( { postId, postType: 'page' } );\n\t\t\t}\n\t\t}\n\t}, [ attributes, setAttributes ] );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks template={ TEMPLATE } />\n\t\t</div>\n\t);\n};\n\nregisterBlockType( metadata, {\n\ticon: {\n\t\tsrc: page,\n\t},\n\tedit: Edit,\n\tsave: () => <InnerBlocks.Content />,\n\tvariations: [\n\t\t{\n\t\t\tname: 'checkout-page',\n\t\t\ttitle: __( 'Checkout Page', 'woocommerce' ),\n\t\t\tattributes: {\n\t\t\t\tpage: 'checkout',\n\t\t\t},\n\t\t\tisActive: ( blockAttributes, variationAttributes ) =>\n\t\t\t\tblockAttributes.page === variationAttributes.page,\n\t\t},\n\t\t{\n\t\t\tname: 'cart-page',\n\t\t\ttitle: __( 'Cart Page', 'woocommerce' ),\n\t\t\tattributes: {\n\t\t\t\tpage: 'cart',\n\t\t\t},\n\t\t\tisActive: ( blockAttributes, variationAttributes ) =>\n\t\t\t\tblockAttributes.page === variationAttributes.page,\n\t\t},\n\t],\n} );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Craft a custom WordPress block that enables users to view and select from available product variations, facilitating direct addition to cart." }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/block.json\n{\n\t\"name\": \"woocommerce/add-to-cart-with-options-variation-selector\",\n\t\"title\": \"Variation Selector (Beta)\",\n\t\"description\": \"Display any product variations available to select from and add to cart.\",\n\t\"category\": \"woocommerce-product-elements\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"postId\" ],\n\t\"ancestor\": [ \"woocommerce/add-to-cart-with-options\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"supports\": {\n\t\t\"interactivity\": true\n\t},\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"viewScriptModule\": \"woocommerce/add-to-cart-with-options-variation-selector\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { BlockEditProps } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { ATTRIBUTE_ITEM_TEMPLATE } from './attribute/constants';\n\ninterface Attributes {\n\tclassName?: string;\n}\n\nexport default function AddToCartWithOptionsVariationSelectorEdit(\n\tprops: BlockEditProps< Attributes >\n) {\n\tconst { className } = props.attributes;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName,\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: ATTRIBUTE_ITEM_TEMPLATE,\n\t\ttemplateLock: 'all',\n\t} );\n\n\treturn <div { ...innerBlocksProps } />;\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/variation-selector/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function AddToCartWithOptionsVariationSelectorSave() {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( {\n\t\t...blockProps,\n\t\trole: 'list',\n\t} );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Show links for subscribers to login, logout, or manage their subscription. that allows users to configure: redirect to current, log in label, log out label, and 2 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/subscriber-login/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/subscriber-login\",\n\t\"title\": \"Subscriber Login\",\n\t\"description\": \"Show links for subscribers to login, logout, or manage their subscription.\",\n\t\"keywords\": [ \"login\", \"logout\", \"subscription\", \"member\", \"account\", \"user\" ],\n\t\"version\": \"0.0.1\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg width='24' height='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z' fill-rule='evenodd' clip-rule='evenodd'></path></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"anchor\": false,\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": true,\n\t\t\"reusable\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"text\": false,\n\t\t\t\"link\": true,\n\t\t\t\"gradients\": true\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"redirectToCurrent\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"logInLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"logOutLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showManageSubscriptionsLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"manageSubscriptionsLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/subscriber-login/edit.js\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl, BaseControl, TextControl } from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport metadata from './block.json';\n\nfunction SubscriberLoginEdit( { attributes, setAttributes } ) {\n\tconst logInInputId = useInstanceId( TextControl, 'inspector-text-control' );\n\tconst logOutInputId = useInstanceId( TextControl, 'inspector-text-control' );\n\tconst manageSubscriptionsInputId = useInstanceId( TextControl, 'inspector-text-control' );\n\tconst blockProps = useBlockProps();\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\tconst {\n\t\tredirectToCurrent,\n\t\tlogInLabel,\n\t\tlogOutLabel,\n\t\tshowManageSubscriptionsLink,\n\t\tmanageSubscriptionsLabel,\n\t} = validatedAttributes;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Redirect to current URL', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ redirectToCurrent }\n\t\t\t\t\t\tonChange={ () => setAttributes( { redirectToCurrent: ! redirectToCurrent } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\tlabel={ __( 'Log in label', 'jetpack' ) }\n\t\t\t\t\t\tid={ logInInputId }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tplaceholder={ __( 'Log in', 'jetpack' ) }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { logInLabel: value } ) }\n\t\t\t\t\t\t\tvalue={ logInLabel }\n\t\t\t\t\t\t\tid={ logInInputId }\n\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t\t<BaseControl\n\t\t\t\t\t\tlabel={ __( 'Log out label', 'jetpack' ) }\n\t\t\t\t\t\tid={ logOutInputId }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tplaceholder={ __( 'Log out', 'jetpack' ) }\n\t\t\t\t\t\t\tonChange={ value => setAttributes( { logOutLabel: value } ) }\n\t\t\t\t\t\t\tvalue={ logOutLabel }\n\t\t\t\t\t\t\tid={ logOutInputId }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show \"Manage subscription\" link', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ showManageSubscriptionsLink }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( { showManageSubscriptionsLink: ! showManageSubscriptionsLink } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t\t{ showManageSubscriptionsLink && (\n\t\t\t\t\t\t<BaseControl\n\t\t\t\t\t\t\tlabel={ __( 'Manage subscription label', 'jetpack' ) }\n\t\t\t\t\t\t\tid={ manageSubscriptionsInputId }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\tplaceholder={ __( 'Manage subscription', 'jetpack' ) }\n\t\t\t\t\t\t\t\tonChange={ value => setAttributes( { manageSubscriptionsLabel: value } ) }\n\t\t\t\t\t\t\t\tvalue={ manageSubscriptionsLabel }\n\t\t\t\t\t\t\t\tid={ manageSubscriptionsInputId }\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</BaseControl>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<a href=\"#logout-pseudo-link\">{ logOutLabel || __( 'Log out', 'jetpack' ) }</a>\n\t\t</div>\n\t);\n}\n\nexport default SubscriberLoginEdit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a text block with customizable text align, content, level, and 2 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/heading/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/heading\",\n\t\"title\": \"Heading\",\n\t\"category\": \"text\",\n\t\"description\": \"Introduce new sections and organize content to help visitors (and search engines) understand the structure of your content.\",\n\t\"keywords\": [ \"title\", \"subtitle\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"content\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"h1,h2,h3,h4,h5,h6\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"anchor\": true,\n\t\t\"className\": true,\n\t\t\"splitting\": true,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true\n\t\t},\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalWritingMode\": true,\n\t\t\t\"fitText\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__unstablePasteTextInline\": true,\n\t\t\"__experimentalSlashInserter\": true,\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-heading-editor\",\n\t\"style\": \"wp-block-heading\"\n}\n\n\n// File: packages/block-library/src/heading/index.js\n/**\n * WordPress dependencies\n */\nimport { heading as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Code is Poetry' ),\n\t\t\tlevel: 2,\n\t\t\ttextAlign: 'center',\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content, level } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasContent = content?.trim().length > 0;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasContent ) ) {\n\t\t\treturn customName || content;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! hasContent\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: heading level. */\n\t\t\t\t\t\t__( 'Level %s. Empty.' ),\n\t\t\t\t\t\tlevel\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. 1: heading level. 2: heading content. */\n\t\t\t\t\t\t__( 'Level %1$s. %2$s' ),\n\t\t\t\t\t\tlevel,\n\t\t\t\t\t\tcontent\n\t\t\t\t );\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n\tvariations,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'content',\n\t\t\tlabel: __( 'Content' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'content' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/heading/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { textAlign, content, level } = attributes;\n\tconst TagName = 'h' + level;\n\n\tconst className = clsx( {\n\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t} );\n\n\treturn (\n\t\t<TagName { ...useBlockProps.save( { className } ) }>\n\t\t\t<RichText.Content value={ content } />\n\t\t</TagName>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WooCommerce block that allows dynamic HTML tag selection for flexible rendering." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews\",\n\t\"icon\": \"admin-comments\",\n\t\"title\": \"Product Reviews\",\n\t\"description\": \"Display a product's reviews\",\n\t\"category\": \"woocommerce\",\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"postType\" ],\n\t\"viewScriptModule\": \"woocommerce/product-reviews\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/edit.tsx\n/**\n * External dependencies\n */\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useQueryLoopProductContextValidation } from '@woocommerce/base-hooks';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\t// @ts-expect-error missing types.\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport TEMPLATE from './template';\nimport { ProductReviewsEditProps } from './types';\nimport { htmlElementMessages } from '../../utils/messages';\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n\tcontext,\n}: ProductReviewsEditProps ) => {\n\tconst { tagName: TagName = 'div' } = attributes;\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\n\tconst { hasInvalidContext, warningElement } =\n\t\tuseQueryLoopProductContextValidation( {\n\t\t\tclientId,\n\t\t\tpostType: context.postType,\n\t\t\tblockName: __( 'Product Reviews', 'woocommerce' ),\n\t\t} );\n\n\tif ( hasInvalidContext ) {\n\t\treturn warningElement;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ /* @ts-expect-error missing types */ }\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<SelectControl\n\t\t\t\t\t// @ts-expect-error missing types.\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'HTML element', 'woocommerce' ) }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Default (<div>)', 'woocommerce' ),\n\t\t\t\t\t\t\tvalue: 'div',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ label: '<section>', value: 'section' },\n\t\t\t\t\t\t{ label: '<aside>', value: 'aside' },\n\t\t\t\t\t] }\n\t\t\t\t\tvalue={ TagName }\n\t\t\t\t\tonChange={ ( value: 'div' | 'section' | 'aside' ) =>\n\t\t\t\t\t\tsetAttributes( { tagName: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={ htmlElementMessages[ TagName ] }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<TagName { ...innerBlocksProps } />\n\t\t</>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/save.tsx\n/**\n * External dependencies\n */\nimport {\n\t// @ts-expect-error Missing types for this package.\n\tuseInnerBlocksProps,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\nexport default function Save( {\n\tattributes: { tagName: Tag = 'div' },\n}: {\n\tattributes: { tagName: string };\n} ) {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <Tag { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block that renders a numbered navigation component for facilitating product review pagination across pages." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination-numbers/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-reviews-pagination-numbers\",\n\t\"title\": \"Reviews Page Numbers\",\n\t\"category\": \"woocommerce\",\n\t\"ancestor\": [ \"woocommerce/product-reviews-pagination\" ],\n\t\"description\": \"Displays a list of page numbers for product reviews pagination.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination-numbers/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport type { ElementType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\n\nconst PaginationItem = ( {\n\tcontent,\n\ttag: Tag = 'a',\n\textraClass = '',\n}: {\n\tcontent: string;\n\ttag?: ElementType;\n\textraClass?: string;\n} ) =>\n\tTag === 'a' ? (\n\t\t<Tag\n\t\t\tclassName={ `page-numbers ${ extraClass }` }\n\t\t\thref=\"#comments-pagination-numbers-pseudo-link\"\n\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t>\n\t\t\t{ content }\n\t\t</Tag>\n\t) : (\n\t\t<Tag className={ `page-numbers ${ extraClass }` }>{ content }</Tag>\n\t);\n\nexport default function Edit() {\n\treturn (\n\t\t<div { ...useBlockProps() }>\n\t\t\t<PaginationItem content=\"1\" />\n\t\t\t<PaginationItem content=\"2\" />\n\t\t\t<PaginationItem content=\"3\" tag=\"span\" extraClass=\"current\" />\n\t\t\t<PaginationItem content=\"4\" />\n\t\t\t<PaginationItem content=\"5\" />\n\t\t\t<PaginationItem content=\"...\" tag=\"span\" extraClass=\"dots\" />\n\t\t\t<PaginationItem content=\"8\" />\n\t\t</div>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Display icons for available payment methods. that allows users to configure: number of icons" }, { "role": "assistant", "content": "// File: plugins/woocommerce/client/blocks/assets/js/blocks/payment-method-icons/block.json\n{\n\t\"name\": \"woocommerce/payment-method-icons\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Payment Method Icons\",\n\t\"description\": \"Display icons for available payment methods.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"woocommerce\", \"payments\", \"payment methods\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"attributes\": {\n\t\t\"numberOfIcons\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 0\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t}\n\t},\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/payment-method-icons/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { PanelBody, RangeControl } from '@wordpress/components';\n\ntype BlockAttributes = {\n\tnumberOfIcons: number;\n};\n\ntype PaymentMethod = {\n\ticon: string;\n};\n\ntype PaymentMethods = Record< string, PaymentMethod >;\n\nconst CardPreview = ( {\n\ttype,\n\ticon,\n}: {\n\ttype: string | undefined;\n\ticon: string | undefined;\n} ) => {\n\tlet CardIcon = null;\n\n\tif ( type && icon ) {\n\t\tCardIcon = (\n\t\t\t<div className=\"wc-block-payment-method-icons__item\">\n\t\t\t\t<span\n\t\t\t\t\tclassName=\"wc-block-payment-method-icons__icon\"\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tbackgroundImage: `url(${ icon })`,\n\t\t\t\t\t} }\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={ type }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn CardIcon;\n};\n\nconst Edit = ( {\n\tattributes,\n\tsetAttributes,\n}: {\n\tattributes: BlockAttributes;\n\tsetAttributes: ( attributes: Partial< BlockAttributes > ) => void;\n} ) => {\n\tconst blockProps = useBlockProps();\n\tconst paymentMethods =\n\t\t( window.wcSettings?.availablePaymentMethods as PaymentMethods ) || {};\n\tconst { numberOfIcons } = attributes;\n\n\tif ( paymentMethods && Object.keys( paymentMethods ).length > 0 ) {\n\t\tconst icons = Object.keys( paymentMethods ).reduce( ( acc, type ) => {\n\t\t\tif ( ! paymentMethods[ type ] || ! paymentMethods[ type ].icon ) {\n\t\t\t\treturn acc;\n\t\t\t}\n\t\t\tacc.push( {\n\t\t\t\ttype,\n\t\t\t\ticon: paymentMethods[ type ].icon,\n\t\t\t} );\n\t\t\treturn acc;\n\t\t}, [] as Array< { type: string; icon: string } > );\n\n\t\tconst iconsToShow =\n\t\t\tnumberOfIcons === 0\n\t\t\t\t? icons.length\n\t\t\t\t: Math.min( numberOfIcons, icons.length );\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody\n\t\t\t\t\t\ttitle={ __(\n\t\t\t\t\t\t\t'Payment Method Icon Settings',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\tlabel={ __( 'Number of icons', 'woocommerce' ) }\n\t\t\t\t\t\t\tvalue={ numberOfIcons }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { numberOfIcons: value || 0 } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\t\tmax={ icons.length }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Choose how many icons to display. To show all icons, use 0 (zero).',\n\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t\t<div className=\"wc-block-payment-method-icons\">\n\t\t\t\t\t{ icons.slice( 0, iconsToShow ).map( ( icon ) => (\n\t\t\t\t\t\t<CardPreview\n\t\t\t\t\t\t\tkey={ icon?.type }\n\t\t\t\t\t\t\ttype={ icon?.type }\n\t\t\t\t\t\t\ticon={ icon?.icon }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ __( 'No active payment methods found.', 'woocommerce' ) }\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a WordPress block that retrieves and displays third-party content, featuring a flexible configuration with attributes including URL, caption, content type, and four supplementary customization options." }, { "role": "assistant", "content": "// File: packages/block-library/src/embed/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/embed\",\n\t\"title\": \"Embed\",\n\t\"category\": \"embed\",\n\t\"description\": \"Add a block that displays content pulled from other sites, like Twitter or YouTube.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"url\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"figcaption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"type\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"providerNameSlug\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"allowResponsive\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"responsive\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"previewable\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true,\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-embed-editor\",\n\t\"style\": \"wp-block-embed\"\n}\n\n\n// File: packages/block-library/src/embed/index.js\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport save from './save';\nimport metadata from './block.json';\nimport transforms from './transforms';\nimport variations from './variations';\nimport deprecated from './deprecated';\nimport { embedContentIcon } from './icons';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon: embedContentIcon,\n\tedit,\n\tsave,\n\ttransforms,\n\tvariations,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/embed/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { url, caption, type, providerNameSlug } = attributes;\n\n\tif ( ! url ) {\n\t\treturn null;\n\t}\n\n\tconst className = clsx( 'wp-block-embed', {\n\t\t[ `is-type-${ type }` ]: type,\n\t\t[ `is-provider-${ providerNameSlug }` ]: providerNameSlug,\n\t\t[ `wp-block-embed-${ providerNameSlug }` ]: providerNameSlug,\n\t} );\n\n\treturn (\n\t\t<figure { ...useBlockProps.save( { className } ) }>\n\t\t\t<div className=\"wp-block-embed__wrapper\">\n\t\t\t\t{ `\\n${ url }\\n` /* URL needs to be on its own line. */ }\n\t\t\t</div>\n\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</figure>\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Embed a simple audio player. that allows users to configure: blob, src, caption, and 4 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/audio/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/audio\",\n\t\"title\": \"Audio\",\n\t\"category\": \"media\",\n\t\"description\": \"Embed a simple audio player.\",\n\t\"keywords\": [ \"music\", \"sound\", \"podcast\", \"recording\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"blob\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"role\": \"local\"\n\t\t},\n\t\t\"src\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"audio\",\n\t\t\t\"attribute\": \"src\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"caption\": {\n\t\t\t\"type\": \"rich-text\",\n\t\t\t\"source\": \"rich-text\",\n\t\t\t\"selector\": \"figcaption\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"id\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"autoplay\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"audio\",\n\t\t\t\"attribute\": \"autoplay\"\n\t\t},\n\t\t\"loop\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"audio\",\n\t\t\t\"attribute\": \"loop\"\n\t\t},\n\t\t\"preload\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"source\": \"attribute\",\n\t\t\t\"selector\": \"audio\",\n\t\t\t\"attribute\": \"preload\"\n\t\t}\n\t},\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t},\n\t\"editorStyle\": \"wp-block-audio-editor\",\n\t\"style\": \"wp-block-audio\"\n}\n\n\n// File: packages/block-library/src/audio/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { audio as icon } from '@wordpress/icons';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tsrc: 'https://upload.wikimedia.org/wikipedia/commons/d/dd/Armstrong_Small_Step.ogg',\n\t\t},\n\t\tviewportWidth: 350,\n\t},\n\ttransforms,\n\tdeprecated,\n\tedit,\n\tsave,\n};\n\nif ( window.__experimentalContentOnlyInspectorFields ) {\n\tsettings[ fieldsKey ] = [\n\t\t{\n\t\t\tid: 'audio',\n\t\t\tlabel: __( 'Audio' ),\n\t\t\ttype: 'media',\n\t\t\tmapping: {\n\t\t\t\tid: 'id',\n\t\t\t\turl: 'src',\n\t\t\t},\n\t\t\targs: {\n\t\t\t\tallowedTypes: [ 'audio' ],\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: 'caption',\n\t\t\tlabel: __( 'Caption' ),\n\t\t\ttype: 'richtext',\n\t\t},\n\t];\n\tsettings[ formKey ] = {\n\t\tfields: [ 'audio' ],\n\t};\n}\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/audio/save.js\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst { autoplay, caption, loop, preload, src } = attributes;\n\n\treturn (\n\t\tsrc && (\n\t\t\t<figure { ...useBlockProps.save() }>\n\t\t\t\t<audio\n\t\t\t\t\tcontrols=\"controls\"\n\t\t\t\t\tsrc={ src }\n\t\t\t\t\tautoPlay={ autoplay }\n\t\t\t\t\tloop={ loop }\n\t\t\t\t\tpreload={ preload }\n\t\t\t\t/>\n\t\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t\t<RichText.Content\n\t\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\t\tvalue={ caption }\n\t\t\t\t\t\tclassName={ __experimentalGetElementClassName(\n\t\t\t\t\t\t\t'caption'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</figure>\n\t\t)\n\t);\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Displays the previous comment's page link. with these attributes: label" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/comments-pagination-previous/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/comments-pagination-previous\",\n\t\"title\": \"Comments Previous Page\",\n\t\"category\": \"theme\",\n\t\"parent\": [ \"core/comments-pagination\" ],\n\t\"description\": \"Displays the previous comment's page link.\",\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"label\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"usesContext\": [ \"postId\", \"comments/paginationArrow\" ],\n\t\"supports\": {\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t}\n\t}\n}\n\n\n// File: packages/block-library/src/comments-pagination-previous/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { queryPaginationPrevious as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {\n\t\tattributes: {\n\t\t\tlabel: __( 'Older Comments' ),\n\t\t},\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Implement a flexible text block allowing users to personalize the action button label, input field placeholder, copy display preference, plus two extra adaptable options." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/ai-chat/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/ai-chat\",\n\t\"title\": \"Jetpack AI Search\",\n\t\"description\": \"Provide a summarized answer to questions, trained on the sites content. Powered by AI.\",\n\t\"keywords\": [ \"AI\", \"GPT\", \"Chat\", \"Search\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"text\",\n\t\"icon\": \"<svg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M6.96774 8C6.96774 9.1402 6.04343 10.0645 4.90323 10.0645C3.76303 10.0645 2.83871 9.1402 2.83871 8C2.83871 6.8598 3.76303 5.93548 4.90323 5.93548C6.04343 5.93548 6.96774 6.8598 6.96774 8ZM5.41935 8C5.41935 8.28505 5.18828 8.51613 4.90323 8.51613C4.61818 8.51613 4.3871 8.28505 4.3871 8C4.3871 7.71495 4.61818 7.48387 4.90323 7.48387C5.18828 7.48387 5.41935 7.71495 5.41935 8Z'/><path fill-rule='evenodd' clip-rule='evenodd' d='M11.0968 10.0645C12.237 10.0645 13.1613 9.1402 13.1613 8C13.1613 6.8598 12.237 5.93548 11.0968 5.93548C9.95657 5.93548 9.03226 6.8598 9.03226 8C9.03226 9.1402 9.95657 10.0645 11.0968 10.0645ZM11.0968 8.51613C11.3818 8.51613 11.6129 8.28505 11.6129 8C11.6129 7.71495 11.3818 7.48387 11.0968 7.48387C10.8117 7.48387 10.5806 7.71495 10.5806 8C10.5806 8.28505 10.8117 8.51613 11.0968 8.51613Z'/><path d='M5.93548 11.3548C5.50791 11.3548 5.16129 11.7015 5.16129 12.129C5.16129 12.5566 5.50791 12.9032 5.93548 12.9032H10.0645C10.4921 12.9032 10.8387 12.5566 10.8387 12.129C10.8387 11.7015 10.4921 11.3548 10.0645 11.3548H5.93548Z'/><path fill-rule='evenodd' clip-rule='evenodd' d='M8.77419 0.774194C8.77419 0.346618 8.42758 0 8 0C7.57242 0 7.22581 0.346618 7.22581 0.774194V3.09677H4.90323C2.19525 3.09677 0 5.29202 0 8V11.0968C0 13.8048 2.19525 16 4.90323 16H11.0968C13.8048 16 16 13.8048 16 11.0968V8C16 5.29202 13.8048 3.09677 11.0968 3.09677H8.77419V0.774194ZM1.54839 8C1.54839 6.14717 3.0504 4.64516 4.90323 4.64516H11.0968C12.9496 4.64516 14.4516 6.14717 14.4516 8V11.0968C14.4516 12.9496 12.9496 14.4516 11.0968 14.4516H4.90323C3.0504 14.4516 1.54839 12.9496 1.54839 11.0968V8Z'/></svg>\",\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"alignWide\": true,\n\t\t\"customClassName\": true,\n\t\t\"className\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"askButtonLabel\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"placeholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showCopy\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showFeedback\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t},\n\t\t\"showSources\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/ai-chat/edit.js\n/**\n * External dependencies\n */\nimport { GuidelineMessage } from '@automattic/jetpack-ai-client';\n/**\n * WordPress dependencies\n */\nimport { InspectorControls, useBlockProps, RichText } from '@wordpress/block-editor';\nimport { TextControl } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport ConnectBanner from '../../shared/components/connect-banner';\nimport useIsUserConnected from '../../shared/use-is-user-connected';\nimport EnableJetpackSearchPrompt from './components/nudge-enable-search';\nimport { DEFAULT_ASK_BUTTON_LABEL, DEFAULT_PLACEHOLDER } from './constants';\nimport { AiChatControls } from './controls';\n\nexport default function Edit( { attributes, setAttributes, clientId } ) {\n\tconst {\n\t\taskButtonLabel = DEFAULT_ASK_BUTTON_LABEL,\n\t\tplaceholder = DEFAULT_PLACEHOLDER,\n\t\tshowCopy,\n\t\tshowFeedback,\n\t\tshowSources,\n\t} = attributes;\n\tconst blockProps = useBlockProps();\n\tconst isBlockSelected = useSelect(\n\t\tselect => {\n\t\t\treturn select( 'core/block-editor' ).isBlockSelected( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\tconst isUserConnected = useIsUserConnected();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ ! isUserConnected && <ConnectBanner block=\"Jetpack AI Search\" /> }\n\t\t\t<EnableJetpackSearchPrompt />\n\t\t\t<div className=\"jetpack-ai-chat-question-wrapper\">\n\t\t\t\t<TextControl\n\t\t\t\t\tclassName=\"jetpack-ai-chat-question-input\"\n\t\t\t\t\tplaceholder={ placeholder }\n\t\t\t\t\tdisabled={ true }\n\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t__next40pxDefaultSize={ true }\n\t\t\t\t/>\n\t\t\t\t<RichText\n\t\t\t\t\tclassName=\"wp-block-button__link jetpack-ai-chat-question-button\"\n\t\t\t\t\tonChange={ value => setAttributes( { askButtonLabel: value } ) }\n\t\t\t\t\tvalue={ askButtonLabel }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tallowedFormats={ [ 'core/bold', 'core/italic', 'core/strikethrough' ] }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t{ isBlockSelected && <GuidelineMessage /> }\n\t\t\t<InspectorControls>\n\t\t\t\t<AiChatControls\n\t\t\t\t\taskButtonLabel={ askButtonLabel }\n\t\t\t\t\tplaceholder={ placeholder }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tshowCopy={ showCopy }\n\t\t\t\t\tshowFeedback={ showFeedback }\n\t\t\t\t\tshowSources={ showSources }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t</div>\n\t);\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/ai-chat/save.js\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { DEFAULT_ASK_BUTTON_LABEL } from './constants';\n\nexport default function ( { attributes } ) {\n\tconst blockProps = useBlockProps.save( {\n\t\t'data-ask-button-label': attributes.askButtonLabel || DEFAULT_ASK_BUTTON_LABEL,\n\t} );\n\treturn <div { ...blockProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a Gutenberg block that Give your readers the ability to show appreciation for your posts. with these attributes: show reblog button, show avatars" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/like/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/like\",\n\t\"title\": \"Like\",\n\t\"description\": \"Give your readers the ability to show appreciation for your posts.\",\n\t\"keywords\": [ \"like\", \"likes\", \"thumbs up\", \"button\", \"heart\" ],\n\t\"version\": \"1.0.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' d='M9.706 8.646a.25.25 0 01-.188.137l-4.626.672a.25.25 0 00-.139.427l3.348 3.262a.25.25 0 01.072.222l-.79 4.607a.25.25 0 00.362.264l4.138-2.176a.25.25 0 01.233 0l4.137 2.175a.25.25 0 00.363-.263l-.79-4.607a.25.25 0 01.072-.222l3.347-3.262a.25.25 0 00-.139-.427l-4.626-.672a.25.25 0 01-.188-.137l-2.069-4.192a.25.25 0 00-.448 0L9.706 8.646zM12 7.39l-.948 1.921a1.75 1.75 0 01-1.317.957l-2.12.308 1.534 1.495c.412.402.6.982.503 1.55l-.362 2.11 1.896-.997a1.75 1.75 0 011.629 0l1.895.997-.362-2.11a1.75 1.75 0 01.504-1.55l1.533-1.495-2.12-.308a1.75 1.75 0 01-1.317-.957L12 7.39z' clip-rule='evenodd'></path></svg>\",\n\t\"usesContext\": [ \"postId\" ],\n\t\"attributes\": {\n\t\t\"showReblogButton\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showAvatars\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/like/edit.js\nimport { isWpcomPlatformSite, isSimpleSite } from '@automattic/jetpack-script-data';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport { ExternalLink, ToggleControl, PanelBody } from '@wordpress/components';\nimport { createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport avatar1 from '../blogging-prompt/example-avatars/avatar1.jpg';\nimport avatar2 from '../blogging-prompt/example-avatars/avatar2.jpg';\nimport avatar3 from '../blogging-prompt/example-avatars/avatar3.jpg';\nimport metadata from './block.json';\nimport './editor.scss';\n\nfunction LikeEdit( { attributes, setAttributes } ) {\n\tconst blockProps = useBlockProps();\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\tconst { showReblogButton, showAvatars } = validatedAttributes;\n\tconst isJetpackSite = ! isWpcomPlatformSite();\n\tconst avatars = [ avatar1, avatar2, avatar3 ];\n\tconst preventDefault = event => event.preventDefault();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls key=\"like-inspector\">\n\t\t\t\t{ isJetpackSite && (\n\t\t\t\t\t<div className=\"wp-block-jetpack-like__learn-more\">\n\t\t\t\t\t\t<ExternalLink href={ 'https://jetpack.com/support/likes/' }>\n\t\t\t\t\t\t\t{ __( 'Learn more', 'jetpack' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<PanelBody title={ __( 'Settings', 'jetpack' ) }>\n\t\t\t\t\t{ isSimpleSite() && (\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show reblog button', 'jetpack' ) }\n\t\t\t\t\t\t\tchecked={ showReblogButton }\n\t\t\t\t\t\t\tonChange={ () => setAttributes( { showReblogButton: ! showReblogButton } ) }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show avatars', 'jetpack' ) }\n\t\t\t\t\t\tchecked={ showAvatars }\n\t\t\t\t\t\tonChange={ () => setAttributes( { showAvatars: ! showAvatars } ) }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div className=\"wpl-likebox\">\n\t\t\t\t{ isSimpleSite() && showReblogButton && (\n\t\t\t\t\t<div className=\"wpl-button reblog\">\n\t\t\t\t\t\t<a\n\t\t\t\t\t\t\thref=\"#\"\n\t\t\t\t\t\t\ttitle={ __( 'Reblog this post on your main site.', 'jetpack' ) }\n\t\t\t\t\t\t\tclassName=\"reblog sd-button\"\n\t\t\t\t\t\t\trel=\"nofollow\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span>{ __( 'Reblog', 'jetpack' ) }</span>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<div className=\"wpl-button like\">\n\t\t\t\t\t<a href=\"#\" className=\"sd-button like\" rel=\"nofollow\" onClick={ preventDefault }>\n\t\t\t\t\t\t<span>{ __( 'Like', 'jetpack' ) }</span>\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t\t{ showAvatars && (\n\t\t\t\t\t<ul className=\"wpl-avatars\">\n\t\t\t\t\t\t{ avatars.map( ( avatar, i ) => (\n\t\t\t\t\t\t\t<li key={ `liker-${ i }` } className=\"wp-liker-me\">\n\t\t\t\t\t\t\t\t<a className=\"wpl-liker\" href=\"#\" rel=\"nofollow\" onClick={ preventDefault }>\n\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\tsrc={ avatar }\n\t\t\t\t\t\t\t\t\t\tclassName=\"avatar avatar-30\"\n\t\t\t\t\t\t\t\t\t\twidth={ 30 }\n\t\t\t\t\t\t\t\t\t\theight={ 30 }\n\t\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</ul>\n\t\t\t\t) }\n\t\t\t\t<div className=\"wpl-count\">\n\t\t\t\t\t<span className=\"wpl-count-text\">\n\t\t\t\t\t\t<a href=\"#\" onClick={ preventDefault }>\n\t\t\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t\t// translators: %1$d: Number of likes\n\t\t\t\t\t\t\t\t\t__( '<span>%1$d</span> likes', 'jetpack' ),\n\t\t\t\t\t\t\t\t\tavatars.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tspan: <span className=\"wpl-count-number\"></span>,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default LikeEdit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a Gutenberg block designed to facilitate legal consent by creating an interactive checkbox component that enables website visitors to explicitly agree to Terms & Conditions and Privacy Policy, with flexible styling and text customization." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/block.json\n{\n\t\"name\": \"woocommerce/checkout-terms-block\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Terms and Conditions\",\n\t\"description\": \"Ensure that customers agree to your Terms & Conditions and Privacy Policy.\",\n\t\"category\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"align\": false,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false\n\t},\n\t\"attributes\": {\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t},\n\t\t\"checkbox\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"text\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"required\": false\n\t\t},\n\t\t\"showSeparator\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": true\n\t\t}\n\t},\n\t\"parent\": [\n\t\t\"woocommerce/checkout-fields-block\"\n\t],\n\t\"textdomain\": \"woocommerce\",\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/edit.tsx\n/**\n * External dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseBlockProps,\n\tRichText,\n\tInspectorControls,\n} from '@wordpress/block-editor';\nimport { CheckboxControl } from '@woocommerce/blocks-components';\nimport {\n\tPanelBody,\n\tToggleControl,\n\tNotice,\n\tExternalLink,\n} from '@wordpress/components';\nimport { PRIVACY_URL, TERMS_URL } from '@woocommerce/block-settings';\nimport { ADMIN_URL } from '@woocommerce/settings';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { termsConsentDefaultText, termsCheckboxDefaultText } from './constants';\n\nconst noop = () => undefined;\n\nexport const Edit = ( {\n\tattributes: { checkbox, text, showSeparator },\n\tsetAttributes,\n}: {\n\tattributes: { text: string; checkbox: boolean; showSeparator: boolean };\n\tsetAttributes: ( attributes: Record< string, unknown > ) => void;\n} ) => {\n\tconst blockProps = useBlockProps();\n\n\tconst defaultText = checkbox\n\t\t? termsCheckboxDefaultText\n\t\t: termsConsentDefaultText;\n\n\tconst currentText = text || defaultText;\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InspectorControls>\n\t\t\t\t{ /* Show this notice if a terms page or a privacy page is not setup. */ }\n\t\t\t\t{ ( ! TERMS_URL || ! PRIVACY_URL ) && (\n\t\t\t\t\t<Notice\n\t\t\t\t\t\tclassName=\"wc-block-checkout__terms_notice\"\n\t\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\"Link to your store's Terms and Conditions and Privacy Policy pages by creating pages for them.\",\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<br />\n\t\t\t\t\t\t{ ! TERMS_URL && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<br />\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=advanced` }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Setup a Terms and Conditions page',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! PRIVACY_URL && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<br />\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ `${ ADMIN_URL }options-privacy.php` }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Setup a Privacy Policy page',\n\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Notice>\n\t\t\t\t) }\n\t\t\t\t{ /* Show this notice if we have both a terms and privacy pages, but they're not present in the text. */ }\n\t\t\t\t{ TERMS_URL &&\n\t\t\t\t\tPRIVACY_URL &&\n\t\t\t\t\t! (\n\t\t\t\t\t\tcurrentText.includes( TERMS_URL ) &&\n\t\t\t\t\t\tcurrentText.includes( PRIVACY_URL )\n\t\t\t\t\t) && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"wc-block-checkout__terms_notice\"\n\t\t\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t\tactions={\n\t\t\t\t\t\t\t\ttermsConsentDefaultText !== text\n\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'Restore default text',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\tonClick: () =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttext: '',\n\t\t\t\t\t\t\t\t\t\t\t\t\t} ),\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t\t: []\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t'Ensure you add links to your policy pages in this section.',\n\t\t\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t<PanelBody title={ __( 'Display options', 'woocommerce' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Require checkbox', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ checkbox }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tcheckbox: ! checkbox,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Show separator', 'woocommerce' ) }\n\t\t\t\t\t\tchecked={ showSeparator }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowSeparator: ! showSeparator,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'wc-block-checkout__terms', {\n\t\t\t\t\t'wc-block-checkout__terms--with-separator': showSeparator,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ checkbox ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<div className=\"wc-block-checkout__terms-checkbox-wrapper\">\n\t\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\t\tid=\"terms-condition\"\n\t\t\t\t\t\t\t\tchecked={ false }\n\t\t\t\t\t\t\t\tonChange={ noop }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\tvalue={ currentText }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { text: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tvalue={ currentText }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { text: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport const Save = () => {\n\treturn <div { ...useBlockProps.save() } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Design a Gutenberg block featuring a configurable array of clickable link buttons to encourage user interaction and navigation." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/buttons/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/buttons\",\n\t\"title\": \"Buttons\",\n\t\"category\": \"design\",\n\t\"allowedBlocks\": [ \"core/button\" ],\n\t\"description\": \"Prompt visitors to take action with a group of button-style links.\",\n\t\"keywords\": [ \"link\" ],\n\t\"textdomain\": \"default\",\n\t\"supports\": {\n\t\t\"anchor\": true,\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"__experimentalExposeControlsToChildren\": true,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": [ \"top\", \"bottom\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"style\": true,\n\t\t\t\"width\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"color\": true,\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"style\": true,\n\t\t\t\t\"width\": true\n\t\t\t}\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"contentRole\": true\n\t},\n\t\"editorStyle\": \"wp-block-buttons-editor\",\n\t\"style\": \"wp-block-buttons\"\n}\n\n\n// File: packages/block-library/src/buttons/index.js\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { buttons as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport transforms from './transforms';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\tjustifyContent: 'center',\n\t\t\t},\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/button',\n\t\t\t\tattributes: { text: __( 'Find out more' ) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/button',\n\t\t\t\tattributes: { text: __( 'Contact us' ) },\n\t\t\t},\n\t\t],\n\t},\n\tdeprecated,\n\ttransforms,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/buttons/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes, className } ) {\n\tconst { fontSize, style } = attributes;\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( className, {\n\t\t\t'has-custom-font-size': fontSize || style?.typography?.fontSize,\n\t\t} ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a WordPress block to Display next and previous buttons." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/next-previous-buttons/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-gallery-large-image-next-previous\",\n\t\"title\": \"Next/Previous Buttons\",\n\t\"description\": \"Display next and previous buttons.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"usesContext\": [ \"iapi/provider\" ],\n\t\"textdomain\": \"woocommerce\",\n\t\"supports\": {\n\t\t\"interactivity\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"align\": true,\n\t\t\"layout\": {\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\",\n\t\t\t\t\"flexWrap\": \"nowrap\",\n\t\t\t\t\"verticalAlignment\": \"center\"\n\t\t\t},\n\t\t\t\"allowVerticalAlignment\": true,\n\t\t\t\"allowOrientation\": false,\n\t\t\t\"allowJustification\": false\n\t\t},\n\t\t\"shadow\": true,\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"__experimentalSkipSerialization\": true\n\t\t},\n\t\t\"__experimentalSelector\": \".wc-block-next-previous-buttons__button\"\n\t},\n\t\"ancestor\": [\n\t\t\"woocommerce/product-gallery-large-image\",\n\t\t\"woocommerce/product-collection\"\n\t],\n\t\"style\": \"file:../woocommerce/product-gallery-large-image-next-previous-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/product-gallery-large-image-next-previous-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/next-previous-buttons/edit.tsx\n/**\n * External dependencies\n */\nimport type { BlockAttributes } from '@wordpress/blocks';\nimport { isRTL } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport {\n\tuseBlockProps,\n\t/* eslint-disable */\n\t/* @ts-ignore module is exported as experimental */\n\t__experimentalUseBorderProps as useBorderProps,\n\t/* @ts-ignore module is exported as experimental */\n\t__experimentalUseColorProps as useColorProps,\n\t/* @ts-ignore module is exported as experimental */\n\t__experimentalGetSpacingClassesAndStyles as useSpacingProps,\n\t/* @ts-ignore module is exported as experimental */\n\t__experimentalGetShadowClassesAndStyles as useShadowProps,\n\t/* eslint-enable */\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { PrevIcon, NextIcon } from './icons';\n\nconst getVerticalAlignmentClass = ( attributes: BlockAttributes ) => {\n\tconst verticalAlignment = attributes?.layout?.verticalAlignment;\n\n\tif ( verticalAlignment === 'top' ) {\n\t\treturn 'aligntop';\n\t}\n\tif ( verticalAlignment === 'bottom' ) {\n\t\treturn 'alignbottom';\n\t}\n\t// Default to center.\n\treturn '';\n};\n\nexport const Edit = ( { attributes }: { attributes: BlockAttributes } ) => {\n\tconst verticalAlignmentClass = getVerticalAlignmentClass( attributes );\n\tconst { style, ...blockProps } = useBlockProps( {\n\t\tclassName: clsx(\n\t\t\t'wc-block-next-previous-buttons',\n\t\t\tverticalAlignmentClass\n\t\t),\n\t} );\n\n\tconst borderProps = useBorderProps( attributes );\n\tconst colorProps = useColorProps( attributes );\n\tconst spacingProps = useSpacingProps( attributes );\n\tconst shadowProps = useShadowProps( attributes );\n\n\tconst buttonClassName = clsx(\n\t\t'wc-block-next-previous-buttons__button',\n\t\tborderProps.className,\n\t\tcolorProps.className,\n\t\tspacingProps.className,\n\t\tshadowProps.className\n\t);\n\n\tconst buttonStyles = {\n\t\t...style,\n\t\t...borderProps.style,\n\t\t...colorProps.style,\n\t\t...spacingProps.style,\n\t\t...shadowProps.style,\n\t};\n\n\tconst rtl = isRTL();\n\tconst LeftComponent = rtl ? NextIcon : PrevIcon;\n\tconst RightComponent = rtl ? PrevIcon : NextIcon;\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<button\n\t\t\t\tclassName={ buttonClassName }\n\t\t\t\tstyle={ buttonStyles }\n\t\t\t\tdisabled\n\t\t\t>\n\t\t\t\t<LeftComponent className=\"wc-block-next-previous-buttons__icon wc-block-next-previous-buttons__icon--left\" />\n\t\t\t</button>\n\t\t\t<button className={ buttonClassName } style={ buttonStyles }>\n\t\t\t\t<RightComponent className=\"wc-block-next-previous-buttons__icon wc-block-next-previous-buttons__icon--right\" />\n\t\t\t</button>\n\t\t</div>\n\t);\n};\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/next-previous-buttons/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\nexport const Save = () => {\n\treturn <div { ...useBlockProps.save() }></div>;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a block for Displays the title of a post, page, or any other content-type. that allows users to configure: text align, level, level options, and 3 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/post-title/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/post-title\",\n\t\"title\": \"Title\",\n\t\"category\": \"theme\",\n\t\"description\": \"Displays the title of a post, page, or any other content-type.\",\n\t\"textdomain\": \"default\",\n\t\"usesContext\": [ \"postId\", \"postType\", \"queryId\" ],\n\t\"attributes\": {\n\t\t\"textAlign\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"level\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"default\": 2\n\t\t},\n\t\t\"levelOptions\": {\n\t\t\t\"type\": \"array\"\n\t\t},\n\t\t\"isLink\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false,\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"rel\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"attribute\": \"rel\",\n\t\t\t\"default\": \"\",\n\t\t\t\"role\": \"content\"\n\t\t},\n\t\t\"linkTarget\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"_self\",\n\t\t\t\"role\": \"content\"\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"viewportWidth\": 350\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true,\n\t\t\t\t\"link\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t}\n\t},\n\t\"style\": \"wp-block-post-title\"\n}\n\n\n// File: packages/block-library/src/post-title/index.js\n/**\n * WordPress dependencies\n */\nimport { title as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Develop a custom WordPress block that renders a specific message or layout in situations where product search results return empty." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/inner-blocks/no-results/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-collection-no-results\",\n\t\"title\": \"No results\",\n\t\"category\": \"woocommerce\",\n\t\"description\": \"The contents of this block will display when there are no products found.\",\n\t\"textdomain\": \"woocommerce\",\n\t\"keywords\": [ \"Product Collection\" ],\n\t\"usesContext\": [ \"queryId\", \"query\" ],\n\t\"ancestor\": [ \"woocommerce/product-collection\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"align\": true,\n\t\t\"reusable\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"gradients\": true,\n\t\t\t\"link\": true\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"email\": true\n\t}\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/inner-blocks/no-results/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, InnerBlocks } from '@wordpress/block-editor';\nimport { Template } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\nconst TEMPLATE: Template[] = [\n\t[\n\t\t'core/group',\n\t\t{\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\torientation: 'vertical',\n\t\t\t\tjustifyContent: 'center',\n\t\t\t\tflexWrap: 'wrap',\n\t\t\t},\n\t\t},\n\t\t[\n\t\t\t[\n\t\t\t\t'core/paragraph',\n\t\t\t\t{\n\t\t\t\t\ttextAlign: 'center',\n\t\t\t\t\tfontSize: 'medium',\n\t\t\t\t\tcontent: `<strong>${ __(\n\t\t\t\t\t\t'No results found',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }</strong>`,\n\t\t\t\t},\n\t\t\t],\n\t\t\t[\n\t\t\t\t'core/paragraph',\n\t\t\t\t{\n\t\t\t\t\tcontent: `${ __(\n\t\t\t\t\t\t'You can try',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) } <a href=\"#\" class=\"wc-link-clear-any-filters\">${ __(\n\t\t\t\t\t\t'clearing any filters',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }</a> ${ __(\n\t\t\t\t\t\t'or head to our',\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) } <a href=\"#\" class=\"wc-link-stores-home\">${ __(\n\t\t\t\t\t\t\"store's home\",\n\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t) }</a>`,\n\t\t\t\t},\n\t\t\t],\n\t\t],\n\t],\n];\n\nconst Edit = () => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-product-collection-no-results',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<InnerBlocks template={ TEMPLATE } />\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-collection/inner-blocks/no-results/save.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks } from '@wordpress/block-editor';\n\nexport default function NoResultsSave() {\n\t// @ts-expect-error: `InnerBlocks.Content` is a component that is typed in WordPress core\n\treturn <InnerBlocks.Content />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable shortcode, align" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/classic-shortcode/block.json\n{\n\t\"name\": \"woocommerce/classic-shortcode\",\n\t\"title\": \"Classic Shortcode\",\n\t\"description\": \"Renders classic WooCommerce shortcodes.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": false\n\t\t},\n\t\t\"align\": true,\n\t\t\"html\": false,\n\t\t\"multiple\": false,\n\t\t\"reusable\": false,\n\t\t\"inserter\": true\n\t},\n\t\"attributes\": {\n\t\t\"shortcode\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"cart\",\n\t\t\t\"enum\": [ \"cart\", \"checkout\" ]\n\t\t},\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/classic-shortcode/index.tsx\n/**\n * External dependencies\n */\nimport {\n\tBlockInstance,\n\tcreateBlock,\n\tregisterBlockType,\n} from '@wordpress/blocks';\nimport type { BlockEditProps } from '@wordpress/blocks';\nimport {\n\tuseBlockProps,\n\tBlockPreview,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tButton,\n\tPlaceholder,\n\tPopover,\n\tExternalLink,\n\tTabbableContainer,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { shortcode, Icon } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState, createInterpolateElement } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { findBlock } from '@woocommerce/utils';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport './style.scss';\nimport { CartPlaceholder, CheckoutPlaceholder } from './placeholder';\nimport { TEMPLATES, TYPES } from './constants';\nimport { getTemplateDetailsBySlug } from './utils';\nimport * as blockifiedCheckout from './checkout';\nimport * as blockifiedCart from './cart';\nimport metadata from './block.json';\nimport type { BlockifiedTemplateConfig } from './types';\n\ntype Attributes = {\n\tshortcode: string;\n\talign: string;\n};\n\nconst blockifiedFallbackConfig = {\n\tgetBlockifiedTemplate: () => [],\n\tgetDescription: () => '',\n\tonClickCallback: () => void 0,\n};\n\nconst conversionConfig: { [ key: string ]: BlockifiedTemplateConfig } = {\n\t[ TYPES.cart ]: blockifiedCart,\n\t[ TYPES.checkout ]: blockifiedCheckout,\n\tfallback: blockifiedFallbackConfig,\n};\n\nconst ConvertTemplate = ( { blockifyConfig, clientId, attributes } ) => {\n\tconst { getButtonLabel, onClickCallback, getBlockifiedTemplate } =\n\t\tblockifyConfig;\n\n\tconst [ isPopoverOpen, setIsPopoverOpen ] = useState( false );\n\n\tconst { replaceBlock, selectBlock } = useDispatch( blockEditorStore );\n\tconst { createInfoNotice } = useDispatch( noticesStore );\n\n\tconst { getBlocks } = useSelect( ( sel ) => {\n\t\treturn {\n\t\t\tgetBlocks: sel( blockEditorStore ).getBlocks,\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<TabbableContainer className=\"wp-block-woocommerce-classic-shortcode__placeholder-migration-button-container\">\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tonClickCallback( {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tgetBlocks,\n\t\t\t\t\t\tattributes,\n\t\t\t\t\t\treplaceBlock,\n\t\t\t\t\t\tselectBlock,\n\t\t\t\t\t} );\n\t\t\t\t\tcreateInfoNotice(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Classic shortcode transformed to blocks.',\n\t\t\t\t\t\t\t'woocommerce'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlabel: __( 'Undo', 'woocommerce' ),\n\t\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\t\tconst targetBlocks = [\n\t\t\t\t\t\t\t\t\t\t\t'woocommerce/cart',\n\t\t\t\t\t\t\t\t\t\t\t'woocommerce/checkout',\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\tconst cartCheckoutBlock = findBlock( {\n\t\t\t\t\t\t\t\t\t\t\tblocks: getBlocks(),\n\t\t\t\t\t\t\t\t\t\t\tfindCondition: (\n\t\t\t\t\t\t\t\t\t\t\t\tfoundBlock: BlockInstance\n\t\t\t\t\t\t\t\t\t\t\t) =>\n\t\t\t\t\t\t\t\t\t\t\t\ttargetBlocks.includes(\n\t\t\t\t\t\t\t\t\t\t\t\t\tfoundBlock.name\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\tif ( ! cartCheckoutBlock ) {\n\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treplaceBlock(\n\t\t\t\t\t\t\t\t\t\t\tcartCheckoutBlock.clientId,\n\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t'woocommerce/classic-shortcode',\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tshortcode:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tattributes.shortcode,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t\tonMouseEnter={ () => setIsPopoverOpen( true ) }\n\t\t\t\tonMouseLeave={ () => setIsPopoverOpen( false ) }\n\t\t\t\ttext={ getButtonLabel ? getButtonLabel() : '' }\n\t\t\t\ttabIndex={ 0 }\n\t\t\t>\n\t\t\t\t{ isPopoverOpen && (\n\t\t\t\t\t<Popover resize={ false } placement=\"right-end\">\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\tminWidth: '250px',\n\t\t\t\t\t\t\t\twidth: '250px',\n\t\t\t\t\t\t\t\tmaxWidth: '250px',\n\t\t\t\t\t\t\t\tminHeight: '300px',\n\t\t\t\t\t\t\t\theight: '300px',\n\t\t\t\t\t\t\t\tmaxHeight: '300px',\n\t\t\t\t\t\t\t\tcursor: 'pointer',\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<BlockPreview\n\t\t\t\t\t\t\t\tblocks={ getBlockifiedTemplate( {\n\t\t\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\t\t\tisPreview: true,\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t\tviewportWidth={ 1200 }\n\t\t\t\t\t\t\t\tadditionalStyles={ [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcss: 'body { padding: 20px !important; height: fit-content !important; overflow:hidden}',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Popover>\n\t\t\t\t) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\thref=\"https://woocommerce.com/document/woocommerce-store-editing/customizing-cart-and-checkout/\"\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\ttabIndex={ 0 }\n\t\t\t>\n\t\t\t\t{ __( 'Learn more', 'woocommerce' ) }\n\t\t\t</Button>\n\t\t</TabbableContainer>\n\t);\n};\nconst Edit = ( { clientId, attributes }: BlockEditProps< Attributes > ) => {\n\tconst blockProps = useBlockProps();\n\n\tconst templateDetails = getTemplateDetailsBySlug(\n\t\tattributes.shortcode,\n\t\tTEMPLATES\n\t);\n\tconst templateTitle = attributes.shortcode;\n\tconst templatePlaceholder = templateDetails?.placeholder ?? 'cart';\n\tconst templateType = templateDetails?.type ?? 'fallback';\n\n\tconst { getDescription, getTitle, blockifyConfig } =\n\t\tconversionConfig[ templateType ];\n\n\tconst canConvert = !! templateDetails?.type;\n\tconst placeholderTitle = getTitle\n\t\t? getTitle()\n\t\t: __( 'Classic Shortcode Placeholder', 'woocommerce' );\n\tconst placeholderDescription = getDescription( templateTitle );\n\n\tconst learnMoreContent = createInterpolateElement(\n\t\t__(\n\t\t\t'You can learn more about the benefits of switching to blocks, compatibility with extensions, and how to switch back to shortcodes <a>in our documentation</a>.',\n\t\t\t'woocommerce'\n\t\t),\n\t\t{\n\t\t\ta: (\n\t\t\t\t// Suppress the warning as this <a> will be interpolated into the string with content.\n\t\t\t\t// eslint-disable-next-line jsx-a11y/anchor-has-content\n\t\t\t\t<ExternalLink href=\"https://woocommerce.com/document/woocommerce-store-editing/customizing-cart-and-checkout/\" />\n\t\t\t),\n\t\t}\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Placeholder className=\"wp-block-woocommerce-classic-shortcode__placeholder\">\n\t\t\t\t<div className=\"wp-block-woocommerce-classic-shortcode__placeholder-wireframe\">\n\t\t\t\t\t{ templatePlaceholder === 'cart' ? (\n\t\t\t\t\t\t<CartPlaceholder />\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<CheckoutPlaceholder />\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<div className=\"wp-block-woocommerce-classic-shortcode__placeholder-copy\">\n\t\t\t\t\t<div className=\"wp-block-woocommerce-classic-shortcode__placeholder-copy__icon-container\">\n\t\t\t\t\t\t<h1>{ __( 'WooCommerce', 'woocommerce' ) }</h1>\n\t\t\t\t\t\t<span>{ placeholderTitle }</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ canConvert && <p>{ placeholderDescription }</p> }\n\t\t\t\t\t<p>{ learnMoreContent }</p>\n\t\t\t\t\t{ canConvert && blockifyConfig && (\n\t\t\t\t\t\t<ConvertTemplate\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tblockifyConfig={ blockifyConfig }\n\t\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</Placeholder>\n\t\t</div>\n\t);\n};\n\nconst settings = {\n\ticon: (\n\t\t<Icon\n\t\t\ticon={ shortcode }\n\t\t\tclassName=\"wc-block-editor-components-block-icon\"\n\t\t/>\n\t),\n\tedit: ( {\n\t\tattributes,\n\t\tclientId,\n\t\tsetAttributes,\n\t}: BlockEditProps< Attributes > ) => {\n\t\treturn (\n\t\t\t<Edit\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tclientId={ clientId }\n\t\t\t/>\n\t\t);\n\t},\n\tsave: () => null,\n\tvariations: [\n\t\t{\n\t\t\tname: 'checkout',\n\t\t\ttitle: __( 'Classic Checkout', 'woocommerce' ),\n\t\t\tattributes: {\n\t\t\t\tshortcode: 'checkout',\n\t\t\t},\n\t\t\tisActive: ( blockAttributes, variationAttributes ) =>\n\t\t\t\tblockAttributes.shortcode === variationAttributes.shortcode,\n\t\t\tscope: [ 'inserter' ],\n\t\t},\n\t\t{\n\t\t\tname: 'cart',\n\t\t\ttitle: __( 'Classic Cart', 'woocommerce' ),\n\t\t\tattributes: {\n\t\t\t\tshortcode: 'cart',\n\t\t\t},\n\t\t\tisActive: ( blockAttributes, variationAttributes ) =>\n\t\t\t\tblockAttributes.shortcode === variationAttributes.shortcode,\n\t\t\tscope: [ 'inserter' ],\n\t\t\tisDefault: true,\n\t\t},\n\t],\n\tapiVersion: 3,\n};\n\nregisterBlockType( metadata, settings );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Build a WordPress block for widgets that allows granular icon color customization through 9 distinct styling and color control options." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/social-links/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/social-links\",\n\t\"title\": \"Social Icons\",\n\t\"category\": \"widgets\",\n\t\"allowedBlocks\": [ \"core/social-link\" ],\n\t\"description\": \"Display icons linking to your social profiles or sites.\",\n\t\"keywords\": [ \"links\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"iconColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customIconColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customIconBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"iconBackgroundColorValue\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"openInNewTab\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"showLabels\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"size\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t},\n\t\"providesContext\": {\n\t\t\"openInNewTab\": \"openInNewTab\",\n\t\t\"showLabels\": \"showLabels\",\n\t\t\"iconColor\": \"iconColor\",\n\t\t\"iconColorValue\": \"iconColorValue\",\n\t\t\"iconBackgroundColor\": \"iconBackgroundColor\",\n\t\t\"iconBackgroundColorValue\": \"iconBackgroundColorValue\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"left\", \"center\", \"right\" ],\n\t\t\"anchor\": true,\n\t\t\"html\": false,\n\t\t\"__experimentalExposeControlsToChildren\": true,\n\t\t\"layout\": {\n\t\t\t\"allowSwitching\": false,\n\t\t\t\"allowInheriting\": false,\n\t\t\t\"allowVerticalAlignment\": false,\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\"\n\t\t\t}\n\t\t},\n\t\t\"color\": {\n\t\t\t\"enableContrastChecker\": false,\n\t\t\t\"background\": true,\n\t\t\t\"gradients\": true,\n\t\t\t\"text\": false,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": false\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": [ \"horizontal\", \"vertical\" ],\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true,\n\t\t\t\"units\": [ \"px\", \"em\", \"rem\", \"vh\", \"vw\" ],\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"blockGap\": true,\n\t\t\t\t\"margin\": true,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t},\n\t\t\"interactivity\": {\n\t\t\t\"clientNavigation\": true\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"radius\": true,\n\t\t\t\"color\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"radius\": true,\n\t\t\t\t\"color\": true,\n\t\t\t\t\"width\": true,\n\t\t\t\t\"style\": true\n\t\t\t}\n\t\t},\n\t\t\"contentRole\": true\n\t},\n\t\"styles\": [\n\t\t{ \"name\": \"default\", \"label\": \"Default\", \"isDefault\": true },\n\t\t{ \"name\": \"logos-only\", \"label\": \"Logos Only\" },\n\t\t{ \"name\": \"pill-shape\", \"label\": \"Pill Shape\" }\n\t],\n\t\"editorStyle\": \"wp-block-social-links-editor\",\n\t\"style\": \"wp-block-social-links\"\n}\n\n\n// File: packages/block-library/src/social-links/index.js\n/**\n * WordPress dependencies\n */\nimport { share as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\texample: {\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/social-link',\n\t\t\t\tattributes: {\n\t\t\t\t\tservice: 'wordpress',\n\t\t\t\t\turl: 'https://wordpress.org',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/social-link',\n\t\t\t\tattributes: {\n\t\t\t\t\tservice: 'facebook',\n\t\t\t\t\turl: 'https://www.facebook.com/WordPress/',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'core/social-link',\n\t\t\t\tattributes: {\n\t\t\t\t\tservice: 'twitter',\n\t\t\t\t\turl: 'https://twitter.com/WordPress',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ticon,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/social-links/save.js\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( props ) {\n\tconst {\n\t\tattributes: {\n\t\t\ticonBackgroundColorValue,\n\t\t\ticonColorValue,\n\t\t\tshowLabels,\n\t\t\tsize,\n\t\t},\n\t} = props;\n\n\tconst className = clsx( size, {\n\t\t'has-visible-labels': showLabels,\n\t\t'has-icon-color': iconColorValue,\n\t\t'has-icon-background-color': iconBackgroundColorValue,\n\t} );\n\tconst blockProps = useBlockProps.save( { className } );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn <ul { ...innerBlocksProps } />;\n}\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable align" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/billing-address/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-billing-address\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Billing Address\",\n\t\"description\": \"Display the order confirmation billing address.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"multiple\": false,\n\t\t\"align\": [\n\t\t\t\"wide\",\n\t\t\t\"full\"\n\t\t],\n\t\t\"inserter\": false,\n\t\t\"html\": false,\n\t\t\"color\": {\n\t\t\t\"text\": true,\n\t\t\t\"background\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"background\": true,\n\t\t\t\t\"text\": true\n\t\t\t}\n\t\t},\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true,\n\t\t\t\"lineHeight\": true,\n\t\t\t\"__experimentalFontFamily\": true,\n\t\t\t\"__experimentalFontWeight\": true,\n\t\t\t\"__experimentalFontStyle\": true,\n\t\t\t\"__experimentalTextTransform\": true,\n\t\t\t\"__experimentalTextDecoration\": true,\n\t\t\t\"__experimentalLetterSpacing\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"fontSize\": true\n\t\t\t}\n\t\t},\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"width\": true,\n\t\t\t\t\"color\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/billing-address/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { AdditionalFieldsPlaceholder } from '@woocommerce/base-components/cart-checkout';\nimport { ADDRESS_FORM_FIELDS } from '@woocommerce/block-settings';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-billing-address',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<address>\n\t\t\t\tTest address 1<br />\n\t\t\t\tTest address 2<br />\n\t\t\t\tSan Francisco, CA 94110\n\t\t\t\t<br />\n\t\t\t\tUnited States\n\t\t\t\t<AdditionalFieldsPlaceholder\n\t\t\t\t\tadditionalFields={ ADDRESS_FORM_FIELDS }\n\t\t\t\t/>\n\t\t\t</address>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a woocommerce block with customizable align, class name" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/additional-fields/block.json\n{\n\t\"name\": \"woocommerce/order-confirmation-additional-fields\",\n\t\"version\": \"1.0.0\",\n\t\"title\": \"Additional Field List\",\n\t\"description\": \"Display the list of additional field values from the current order.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [\n\t\t\"WooCommerce\"\n\t],\n\t\"supports\": {\n\t\t\"multiple\": false,\n\t\t\"align\": [\n\t\t\t\"wide\",\n\t\t\t\"full\"\n\t\t],\n\t\t\"html\": false,\n\t\t\"__experimentalBorder\": {\n\t\t\t\"color\": true,\n\t\t\t\"radius\": true,\n\t\t\t\"width\": true,\n\t\t\t\"style\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"width\": true,\n\t\t\t\t\"color\": true\n\t\t\t}\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"padding\": true,\n\t\t\t\"margin\": true,\n\t\t\t\"__experimentalDefaultControls\": {\n\t\t\t\t\"margin\": false,\n\t\t\t\t\"padding\": false\n\t\t\t}\n\t\t}\n\t},\n\t\"attributes\": {\n\t\t\"align\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"wide\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"\"\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"apiVersion\": 3,\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\"\n}\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/order-confirmation/additional-fields/edit.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport {\n\tORDER_FORM_FIELDS,\n\tCONTACT_FORM_FIELDS,\n} from '@woocommerce/block-settings';\nimport { AdditionalFieldsPlaceholder } from '@woocommerce/base-components/cart-checkout';\n\n/**\n * Internal dependencies\n */\nimport './style.scss';\n\nconst Edit = (): JSX.Element => {\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wc-block-order-confirmation-additional-fields',\n\t} );\n\n\tconst additionalFields = {\n\t\t...ORDER_FORM_FIELDS,\n\t\t...CONTACT_FORM_FIELDS,\n\t};\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<AdditionalFieldsPlaceholder\n\t\t\t\tadditionalFields={ additionalFields }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport default Edit;\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Design a Gutenberg block enabling readers to subscribe to blog posts via newsletter, with extensive customization including placeholder settings, total subscriber visibility, social follower connections, and 26 supplementary configuration parameters." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: projects/plugins/jetpack/extensions/blocks/subscriptions/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"jetpack/subscriptions\",\n\t\"title\": \"Subscribe\",\n\t\"description\": \"Subscribe to this blog's posts as a newsletter.\",\n\t\"keywords\": [ \"newsletter\", \"email\", \"follow\" ],\n\t\"version\": \"12.5.0\",\n\t\"textdomain\": \"jetpack\",\n\t\"category\": \"grow\",\n\t\"icon\": \"<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m19.02,5H4.98c-1.09,0-1.98.89-1.98,1.98v10.04c0,1.09.89,1.98,1.98,1.98h14.04c1.09,0,1.98-.89,1.98-1.98V6.98c0-1.09-.89-1.98-1.98-1.98Zm.48,11.92c0,.32-.26.58-.58.58H5.08c-.32,0-.58-.26-.58-.58V7.08c0-.32.26-.58.58-.58h13.84c.32,0,.58.26.58.58v9.84Z'/><path d='m4.38,17.69l5.71-4.79s.96,1,1.91.99,1.91-.99,1.91-.99l5.59,4.79v-2.03l-4.41-3.73,4.41-3.72v-1.91l-7.14,5.76c-.24.19-.59.19-.83,0l-7.14-5.88v1.98l4.3,3.67-4.3,3.78v2.08Z'/></svg>\",\n\t\"supports\": {\n\t\t\"spacing\": {\n\t\t\t\"margin\": true,\n\t\t\t\"padding\": true\n\t\t},\n\t\t\"align\": [ \"wide\", \"full\" ]\n\t},\n\t\"styles\": [\n\t\t{\n\t\t\t\"name\": \"split\",\n\t\t\t\"label\": \"Split\",\n\t\t\t\"isDefault\": true\n\t\t},\n\t\t{\n\t\t\t\"name\": \"compact\",\n\t\t\t\"label\": \"Compact\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"button\",\n\t\t\t\"label\": \"Button only\"\n\t\t}\n\t],\n\t\"attributes\": {\n\t\t\"subscribePlaceholder\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"showSubscribersTotal\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"includeSocialFollowers\": {\n\t\t\t\"type\": \"boolean\"\n\t\t},\n\t\t\"buttonOnNewLine\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"buttonWidth\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"submitButtonText\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"emailFieldBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customEmailFieldBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"emailFieldGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customEmailFieldGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"buttonBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customButtonBackgroundColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"buttonGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customButtonGradient\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"textColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customTextColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"fontSize\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customFontSize\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"borderRadius\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"borderWeight\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"borderColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"customBorderColor\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"padding\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"successMessage\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm' to start subscribing.\"\n\t\t},\n\t\t\"appSource\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"className\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"preselectNewsletterCategories\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t},\n\t\t\"selectedNewsletterCategoryIds\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"default\": []\n\t\t}\n\t},\n\t\"example\": {}\n}\n\n\n// File: projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js\nimport { ThemeProvider } from '@automattic/jetpack-components';\nimport { formatNumberCompact } from '@automattic/number-formatters';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\twithColors,\n\twithFontSizes,\n\tuseBlockProps,\n\t__experimentalUseGradient as useGradient, // eslint-disable-line @wordpress/no-unsafe-wp-apis\n} from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\twithFallbackStyles,\n\tToolbarGroup,\n\tToolbarButton,\n} from '@wordpress/components';\nimport { compose, usePrevious } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport { _n, sprintf, _x, __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { isEqual } from 'lodash';\nimport { getActiveStyleName } from '../../shared/block-styles';\nimport { getValidatedAttributes } from '../../shared/get-validated-attributes';\nimport { getPaidPlanLink } from '../../shared/memberships/utils';\nimport './view.scss';\nimport './editor.scss';\nimport { store as membershipProductsStore } from '../../store/membership-products';\nimport metadata from './block.json';\nimport {\n\tDEFAULT_BORDER_RADIUS_VALUE,\n\tDEFAULT_BORDER_WEIGHT_VALUE,\n\tDEFAULT_PADDING_VALUE,\n\tDEFAULT_SPACING_VALUE,\n\tDEFAULT_FONTSIZE_VALUE,\n\tDEFAULT_SUBSCRIBE_PLACEHOLDER,\n\tDEFAULT_SUBMIT_BUTTON_LABEL,\n\tDEFAULT_SUCCESS_MESSAGE,\n} from './constants';\nimport SubscriptionControls from './controls';\n\nconst { getComputedStyle } = window;\nconst isGradientAvailable = !! useGradient;\nconst useGradientIfAvailable = isGradientAvailable ? useGradient : () => ( {} );\n\nconst applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {\n\tconst { buttonBackgroundColor, textColor } = ownProps;\n\tconst buttonBackgroundColorValue = buttonBackgroundColor && buttonBackgroundColor.color;\n\tconst textColorValue = textColor && textColor.color;\n\n\tconst buttonNode = node.querySelector( '.wp-block-jetpack-subscriptions__button' );\n\n\treturn {\n\t\tfallbackButtonBackgroundColor:\n\t\t\tbuttonBackgroundColorValue || ! node\n\t\t\t\t? undefined\n\t\t\t\t: buttonNode && getComputedStyle( buttonNode ).backgroundColor,\n\t\tfallbackTextColor:\n\t\t\ttextColorValue || ! node ? undefined : buttonNode && getComputedStyle( buttonNode ).color,\n\t};\n} );\n\nexport function SubscriptionEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\temailFieldBackgroundColor,\n\t\tbuttonBackgroundColor,\n\t\tsetButtonBackgroundColor,\n\t\tfallbackButtonBackgroundColor,\n\t\ttextColor,\n\t\tfallbackTextColor,\n\t\tsetTextColor,\n\t\tborderColor,\n\t\tsetBorderColor,\n\t\tfontSize,\n\t} = props;\n\tconst hasTierPlans = useSelect(\n\t\tselect => !! select( 'jetpack/membership-products' )?.getNewsletterTierProducts()?.length,\n\t\t[]\n\t);\n\tconst blockProps = useBlockProps();\n\tconst validatedAttributes = getValidatedAttributes( metadata.attributes, attributes );\n\tif ( ! isEqual( validatedAttributes, attributes ) ) {\n\t\tsetAttributes( validatedAttributes );\n\t}\n\n\tconst {\n\t\tborderRadius,\n\t\tborderWeight,\n\t\tbuttonWidth,\n\t\tclassName,\n\t\tincludeSocialFollowers,\n\t\tpadding,\n\t\tpreselectNewsletterCategories,\n\t\tselectedNewsletterCategoryIds,\n\t\tspacing,\n\t\tsubmitButtonText = DEFAULT_SUBMIT_BUTTON_LABEL,\n\t\tsubscribePlaceholder = DEFAULT_SUBSCRIBE_PLACEHOLDER,\n\t\tshowSubscribersTotal,\n\t\tbuttonOnNewLine,\n\t\tsuccessMessage = DEFAULT_SUCCESS_MESSAGE,\n\t} = validatedAttributes;\n\n\tconst activeStyleName = getActiveStyleName( metadata.styles, className );\n\n\tconst { subscriberCount, subscriberCountString } = useSelect( select => {\n\t\tconst { totalSubscribers, socialFollowers } =\n\t\t\tselect( membershipProductsStore ).getSubscriberCounts();\n\t\tlet count = totalSubscribers;\n\t\tif ( includeSocialFollowers ) {\n\t\t\tcount += socialFollowers;\n\t\t}\n\n\t\treturn {\n\t\t\tsubscriberCount: count,\n\t\t\tsubscriberCountString: sprintf(\n\t\t\t\t/* translators: %s: the number of subscribers. */\n\t\t\t\t_n( 'Join %s other subscriber', 'Join %s other subscribers', count, 'jetpack' ),\n\t\t\t\tformatNumberCompact( count, { numberFormatOptions: { maximumFractionDigits: 1 } } )\n\t\t\t),\n\t\t};\n\t} );\n\n\tconst { availableNewsletterCategories, areNewsletterCategoriesEnabled } = useSelect( select => {\n\t\tconst store = select( membershipProductsStore );\n\n\t\treturn {\n\t\t\tavailableNewsletterCategories: store.getNewsletterCategories(),\n\t\t\tareNewsletterCategoriesEnabled: store.getNewsletterCategoriesEnabled(),\n\t\t};\n\t} );\n\n\tconst emailFieldGradient = useGradientIfAvailable( {\n\t\tgradientAttribute: 'emailFieldGradient',\n\t\tcustomGradientAttribute: 'customEmailFieldGradient',\n\t} );\n\tconst buttonGradient = useGradientIfAvailable( {\n\t\tgradientAttribute: 'buttonGradient',\n\t\tcustomGradientAttribute: 'customButtonGradient',\n\t} );\n\n\tconst sharedClasses = {\n\t\t'no-border-radius': borderRadius === 0,\n\t\t[ fontSize.class ]: fontSize.class,\n\t\t'has-text-color': textColor.color,\n\t\t[ textColor.class ]: textColor.class,\n\t};\n\n\tconst emailFieldClasses = {\n\t\t...sharedClasses,\n\t\t'has-background': emailFieldBackgroundColor.color || emailFieldGradient.gradientValue,\n\t\t[ emailFieldBackgroundColor.class ]:\n\t\t\t! emailFieldGradient.gradientValue && emailFieldBackgroundColor.class,\n\t\t[ emailFieldGradient.gradientClass ]: emailFieldGradient.gradientClass,\n\t};\n\n\tconst buttonClasses = {\n\t\t...sharedClasses,\n\t\t'has-background': buttonBackgroundColor.color || buttonGradient.gradientValue,\n\t\t[ buttonBackgroundColor.class ]: ! buttonGradient.gradientValue && buttonBackgroundColor.class,\n\t\t[ buttonGradient.gradientClass ]: buttonGradient.gradientClass,\n\t};\n\n\tconst getPaddingStyleValue = paddingValue => {\n\t\tconst value = paddingValue ? paddingValue : DEFAULT_PADDING_VALUE;\n\n\t\treturn (\n\t\t\tvalue +\n\t\t\t'px ' +\n\t\t\tMath.round( value * 1.5 ) +\n\t\t\t'px ' +\n\t\t\tvalue +\n\t\t\t'px ' +\n\t\t\tMath.round( value * 1.5 ) +\n\t\t\t'px'\n\t\t);\n\t};\n\n\tconst getSpacingStyleValue = spacingValue => {\n\t\treturn spacingValue ? spacingValue : DEFAULT_SPACING_VALUE;\n\t};\n\n\tconst sharedStyles = {\n\t\tcolor: textColor.color,\n\t\tborderColor: borderColor.color,\n\t\tborderRadius: borderRadius ? borderRadius + 'px' : DEFAULT_BORDER_RADIUS_VALUE + 'px',\n\t\tborderWidth: borderWeight ? borderWeight + 'px' : DEFAULT_BORDER_WEIGHT_VALUE + 'px',\n\t\tfontSize: fontSize.size ? fontSize.size : DEFAULT_FONTSIZE_VALUE,\n\t\tpadding: getPaddingStyleValue( padding ),\n\t};\n\n\tconst cssVars = {\n\t\t'--subscribe-block-border-radius': borderRadius\n\t\t\t? borderRadius + 'px'\n\t\t\t: DEFAULT_BORDER_RADIUS_VALUE + 'px',\n\t};\n\n\tconst emailFieldStyles = {\n\t\t...sharedStyles,\n\t\t...( ! emailFieldBackgroundColor.color && emailFieldGradient.gradientValue\n\t\t\t? { background: emailFieldGradient.gradientValue }\n\t\t\t: { backgroundColor: emailFieldBackgroundColor.color } ),\n\t};\n\n\tconst buttonStyles = {\n\t\t...sharedStyles,\n\t\t...( ! buttonBackgroundColor.color && buttonGradient.gradientValue\n\t\t\t? { background: buttonGradient.gradientValue }\n\t\t\t: { backgroundColor: buttonBackgroundColor.color } ),\n\t\twidth: buttonWidth?.length ? buttonWidth : 'auto',\n\t};\n\n\tif ( activeStyleName !== 'button' ) {\n\t\tif ( buttonOnNewLine ) {\n\t\t\tbuttonStyles.marginTop = getSpacingStyleValue( spacing ) + 'px';\n\t\t} else {\n\t\t\tbuttonStyles.marginLeft = getSpacingStyleValue( spacing ) + 'px';\n\t\t}\n\t}\n\n\tconst previousButtonBackgroundColor = usePrevious( buttonBackgroundColor );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tpreviousButtonBackgroundColor?.color !== borderColor?.color ||\n\t\t\tborderColor?.color === buttonBackgroundColor?.color\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetBorderColor( buttonBackgroundColor.color );\n\t}, [ buttonBackgroundColor, previousButtonBackgroundColor, borderColor, setBorderColor ] );\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockProps }\n\t\t\tclassName={ clsx(\n\t\t\t\tblockProps.className,\n\t\t\t\t'wp-block-jetpack-subscriptions__container',\n\t\t\t\t'wp-block-jetpack-subscriptions__supports-newline',\n\t\t\t\tbuttonOnNewLine ? 'wp-block-jetpack-subscriptions__use-newline' : undefined,\n\t\t\t\tshowSubscribersTotal ? 'wp-block-jetpack-subscriptions__show-subs' : undefined\n\t\t\t) }\n\t\t>\n\t\t\t<InspectorControls>\n\t\t\t\t<SubscriptionControls\n\t\t\t\t\tareNewsletterCategoriesEnabled={ areNewsletterCategoriesEnabled }\n\t\t\t\t\tavailableNewsletterCategories={ availableNewsletterCategories }\n\t\t\t\t\tbuttonBackgroundColor={ buttonBackgroundColor }\n\t\t\t\t\tborderColor={ borderColor }\n\t\t\t\t\tbuttonGradient={ buttonGradient }\n\t\t\t\t\tborderRadius={ borderRadius }\n\t\t\t\t\tborderWeight={ borderWeight }\n\t\t\t\t\tbuttonOnNewLine={ buttonOnNewLine }\n\t\t\t\t\temailFieldBackgroundColor={ emailFieldBackgroundColor }\n\t\t\t\t\tfallbackButtonBackgroundColor={ fallbackButtonBackgroundColor }\n\t\t\t\t\tfallbackTextColor={ fallbackTextColor }\n\t\t\t\t\tfontSize={ fontSize }\n\t\t\t\t\tincludeSocialFollowers={ includeSocialFollowers }\n\t\t\t\t\tisGradientAvailable={ isGradientAvailable }\n\t\t\t\t\tpadding={ padding }\n\t\t\t\t\tpreselectNewsletterCategories={ preselectNewsletterCategories }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tsetBorderColor={ setBorderColor }\n\t\t\t\t\tsetButtonBackgroundColor={ setButtonBackgroundColor }\n\t\t\t\t\tsetTextColor={ setTextColor }\n\t\t\t\t\tshowSubscribersTotal={ showSubscribersTotal }\n\t\t\t\t\tspacing={ spacing }\n\t\t\t\t\tsubscriberCount={ subscriberCount }\n\t\t\t\t\ttextColor={ textColor }\n\t\t\t\t\tbuttonWidth={ buttonWidth }\n\t\t\t\t\tselectedNewsletterCategoryIds={ selectedNewsletterCategoryIds }\n\t\t\t\t\tsubscribePlaceholder={ subscribePlaceholder }\n\t\t\t\t\tsubmitButtonText={ submitButtonText }\n\t\t\t\t\tsuccessMessage={ successMessage }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton href={ getPaidPlanLink( hasTierPlans ) } target=\"_blank\">\n\t\t\t\t\t\t{ hasTierPlans\n\t\t\t\t\t\t\t? _x( 'Manage plans', 'unused context to distinguish translations', 'jetpack' )\n\t\t\t\t\t\t\t: __( 'Set up a paid plan', 'jetpack' ) }\n\t\t\t\t\t</ToolbarButton>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<div style={ cssVars }>\n\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__container is-not-subscriber\">\n\t\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__form\" role=\"form\">\n\t\t\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__form-elements\">\n\t\t\t\t\t\t\t{ activeStyleName !== 'button' && (\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tplaceholder={ subscribePlaceholder }\n\t\t\t\t\t\t\t\t\tdisabled={ true }\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\temailFieldClasses,\n\t\t\t\t\t\t\t\t\t\t'wp-block-jetpack-subscriptions__textfield'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tstyle={ emailFieldStyles }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\tbuttonClasses,\n\t\t\t\t\t\t\t\t\t'wp-block-jetpack-subscriptions__button',\n\t\t\t\t\t\t\t\t\t'wp-block-button__link'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonChange={ value => setAttributes( { submitButtonText: value } ) }\n\t\t\t\t\t\t\t\tstyle={ buttonStyles }\n\t\t\t\t\t\t\t\tvalue={ submitButtonText }\n\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\tallowedFormats={ [ 'core/bold', 'core/italic', 'core/strikethrough' ] }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t{ showSubscribersTotal && (\n\t\t\t\t\t<div className=\"wp-block-jetpack-subscriptions__subscount\">{ subscriberCountString }</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nconst withThemeProvider = WrappedComponent => props => (\n\t<ThemeProvider>\n\t\t<WrappedComponent { ...props } />\n\t</ThemeProvider>\n);\n\nexport default compose( [\n\twithColors(\n\t\t{ emailFieldBackgroundColor: 'backgroundColor' },\n\t\t{ buttonBackgroundColor: 'backgroundColor' },\n\t\t{ textColor: 'color' },\n\t\t'borderColor'\n\t),\n\twithFontSizes( 'fontSize' ),\n\tapplyFallbackStyles,\n\twithThemeProvider,\n] )( SubscriptionEdit );\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a WordPress block that empowers users to dynamically refine product displays through an intuitive interface with preview configuration options." }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"woocommerce/product-filters\",\n\t\"title\": \"Product Filters\",\n\t\"description\": \"Let shoppers filter products displayed on the page.\",\n\t\"category\": \"woocommerce\",\n\t\"keywords\": [ \"WooCommerce\" ],\n\t\"supports\": {\n\t\t\"align\": true,\n\t\t\"color\": {\n\t\t\t\"background\": true,\n\t\t\t\"text\": true,\n\t\t\t\"heading\": true,\n\t\t\t\"enableContrastChecker\": false,\n\t\t\t\"button\": true\n\t\t},\n\t\t\"multiple\": true,\n\t\t\"inserter\": true,\n\t\t\"interactivity\": true,\n\t\t\"typography\": {\n\t\t\t\"fontSize\": true\n\t\t},\n\t\t\"layout\": {\n\t\t\t\"default\": {\n\t\t\t\t\"type\": \"flex\",\n\t\t\t\t\"orientation\": \"vertical\",\n\t\t\t\t\"flexWrap\": \"nowrap\",\n\t\t\t\t\"justifyContent\": \"stretch\"\n\t\t\t},\n\t\t\t\"allowEditing\": false\n\t\t},\n\t\t\"spacing\": {\n\t\t\t\"blockGap\": true\n\t\t}\n\t},\n\t\"textdomain\": \"woocommerce\",\n\t\"usesContext\": [ \"postId\", \"query\", \"queryId\" ],\n\t\"attributes\": {\n\t\t\"isPreview\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"example\": {\n\t\t\"attributes\": {\n\t\t\t\"isPreview\": true\n\t\t}\n\t},\n\t\"viewScriptModule\": \"woocommerce/product-filters\",\n\t\"style\": \"file:../woocommerce/product-filters-style.css\",\n\t\"editorStyle\": \"file:../woocommerce/product-filters-editor.css\"\n}\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/edit.tsx\n/**\n * External dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\nimport { BlockEditProps, InnerBlockTemplate } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, close } from '@wordpress/icons';\nimport { useState } from '@wordpress/element';\nimport { filterThreeLines } from '@woocommerce/icons';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { type BlockAttributes } from './types';\nimport { getProductFiltersCss } from './utils/get-product-filters-css';\n\nconst TEMPLATE: InnerBlockTemplate[] = [\n\t[\n\t\t'core/heading',\n\t\t{\n\t\t\tlevel: 2,\n\t\t\tcontent: __( 'Filters', 'woocommerce' ),\n\t\t\tstyle: {\n\t\t\t\tmargin: { top: '0', bottom: '0' },\n\t\t\t\tspacing: { margin: { top: '0', bottom: '0' } },\n\t\t\t},\n\t\t},\n\t],\n\t[ 'woocommerce/product-filter-active' ],\n\t[ 'woocommerce/product-filter-price' ],\n\t[ 'woocommerce/product-filter-rating' ],\n\t[ 'woocommerce/product-filter-attribute' ],\n\t[ 'woocommerce/product-filter-taxonomy' ],\n\t[ 'woocommerce/product-filter-status' ],\n];\n\nexport const Edit = ( props: BlockEditProps< BlockAttributes > ) => {\n\tconst { attributes } = props;\n\tconst { isPreview } = attributes;\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( 'wc-block-product-filters', {\n\t\t\t'is-overlay-opened': isOpen,\n\t\t} ),\n\t\tstyle: getProductFiltersCss( attributes ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ isPreview ? (\n\t\t\t\t<div className=\"wc-block-product-filters__overlay-content\">\n\t\t\t\t\t<InnerBlocks templateLock={ false } template={ TEMPLATE } />\n\t\t\t\t</div>\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t<button\n\t\t\t\t\t\tclassName=\"wc-block-product-filters__open-overlay\"\n\t\t\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ filterThreeLines } />\n\t\t\t\t\t\t<span>{ __( 'Filter products', 'woocommerce' ) }</span>\n\t\t\t\t\t</button>\n\n\t\t\t\t\t<div className=\"wc-block-product-filters__overlay\">\n\t\t\t\t\t\t<div className=\"wc-block-product-filters__overlay-wrapper\">\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filters__overlay-dialog\"\n\t\t\t\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<header className=\"wc-block-product-filters__overlay-header\">\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filters__close-overlay\"\n\t\t\t\t\t\t\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Close', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t<Icon icon={ close } />\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t<div className=\"wc-block-product-filters__overlay-content\">\n\t\t\t\t\t\t\t\t\t<InnerBlocks\n\t\t\t\t\t\t\t\t\t\ttemplateLock={ false }\n\t\t\t\t\t\t\t\t\t\ttemplate={ TEMPLATE }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<footer className=\"wc-block-product-filters__overlay-footer\">\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName=\"wc-block-product-filters__apply wp-block-button__link wp-element-button\"\n\t\t\t\t\t\t\t\t\t\tonClick={ () => setIsOpen( ! isOpen ) }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Apply', 'woocommerce' ) }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</footer>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\n\n// File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/save.tsx\n/**\n * External dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\nimport './editor.scss';\nimport { type BlockAttributes } from './types';\nimport { getProductFiltersCss } from './utils/get-product-filters-css';\n\nexport const Save = ( {\n\tattributes,\n}: {\n\tattributes: BlockAttributes;\n\tstyle: Record< string, string >;\n} ): JSX.Element => {\n\tconst blockProps = useBlockProps.save( {\n\t\tclassName: clsx( 'wc-block-product-filters' ),\n\t\tstyle: getProductFiltersCss( attributes ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <div { ...innerBlocksProps } />;\n};\n" } ]
[ { "role": "system", "content": "You are an expert WordPress developer specializing in creating high-quality plugins and Gutenberg blocks.\nYou write clean, well-documented code following WordPress coding standards and best practices.\nYour code is secure, performant, and maintainable.\n" }, { "role": "user", "content": "Create a theme block with customizable query id, query, tag name, and 2 more options" }, { "role": "assistant", "content": "<|thinking|>\nTo create this {type}, I need to:\n- Create the block.json configuration file\n- Register the block type\n- Define block attributes and their types\n- Implement the Edit component for the editor\n- Implement the Save component for frontend rendering\n- Add necessary controls in the inspector panel\n- Style the block for both editor and frontend\n<|im_end|>\n\n\n// File: packages/block-library/src/query/block.json\n{\n\t\"$schema\": \"https://schemas.wp.org/trunk/block.json\",\n\t\"apiVersion\": 3,\n\t\"name\": \"core/query\",\n\t\"title\": \"Query Loop\",\n\t\"category\": \"theme\",\n\t\"description\": \"An advanced block that allows displaying post types based on different query parameters and visual configurations.\",\n\t\"keywords\": [ \"posts\", \"list\", \"blog\", \"blogs\", \"custom post types\" ],\n\t\"textdomain\": \"default\",\n\t\"attributes\": {\n\t\t\"queryId\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"query\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"default\": {\n\t\t\t\t\"perPage\": null,\n\t\t\t\t\"pages\": 0,\n\t\t\t\t\"offset\": 0,\n\t\t\t\t\"postType\": \"post\",\n\t\t\t\t\"order\": \"desc\",\n\t\t\t\t\"orderBy\": \"date\",\n\t\t\t\t\"author\": \"\",\n\t\t\t\t\"search\": \"\",\n\t\t\t\t\"exclude\": [],\n\t\t\t\t\"sticky\": \"\",\n\t\t\t\t\"inherit\": true,\n\t\t\t\t\"taxQuery\": null,\n\t\t\t\t\"parents\": [],\n\t\t\t\t\"format\": []\n\t\t\t}\n\t\t},\n\t\t\"tagName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"default\": \"div\"\n\t\t},\n\t\t\"namespace\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"enhancedPagination\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"default\": false\n\t\t}\n\t},\n\t\"usesContext\": [ \"templateSlug\" ],\n\t\"providesContext\": {\n\t\t\"queryId\": \"queryId\",\n\t\t\"query\": \"query\",\n\t\t\"displayLayout\": \"displayLayout\",\n\t\t\"enhancedPagination\": \"enhancedPagination\"\n\t},\n\t\"supports\": {\n\t\t\"align\": [ \"wide\", \"full\" ],\n\t\t\"html\": false,\n\t\t\"layout\": true,\n\t\t\"interactivity\": true,\n\t\t\"contentRole\": true\n\t},\n\t\"editorStyle\": \"wp-block-query-editor\"\n}\n\n\n// File: packages/block-library/src/query/index.js\n/**\n * WordPress dependencies\n */\nimport { loop as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport variations from './variations';\nimport deprecated from './deprecated';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\texample: {\n\t\tviewportWidth: 650,\n\t\tattributes: {\n\t\t\tnamespace: 'core/posts-list',\n\t\t\tquery: {\n\t\t\t\tperPage: 4,\n\t\t\t\tpages: 1,\n\t\t\t\toffset: 0,\n\t\t\t\tpostType: 'post',\n\t\t\t\torder: 'desc',\n\t\t\t\torderBy: 'date',\n\t\t\t\tauthor: '',\n\t\t\t\tsearch: '',\n\t\t\t\tsticky: 'exclude',\n\t\t\t\tinherit: false,\n\t\t\t},\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/post-template',\n\t\t\t\tattributes: {\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'grid',\n\t\t\t\t\t\tcolumnCount: 2,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tinnerBlocks: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/post-title',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/post-date',\n\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\tbindings: {\n\t\t\t\t\t\t\t\t\tdatetime: {\n\t\t\t\t\t\t\t\t\t\tsource: 'core/post-data',\n\t\t\t\t\t\t\t\t\t\targs: { field: 'date' },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/post-excerpt',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t},\n\tsave,\n\tvariations,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n\n\n// File: packages/block-library/src/query/save.js\n/**\n * WordPress dependencies\n */\nimport { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';\n\nexport default function save( { attributes: { tagName: Tag = 'div' } } ) {\n\tconst blockProps = useBlockProps.save();\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\treturn <Tag { ...innerBlocksProps } />;\n}\n" } ]