From 1432cd194fffb481fc744ec882f999296b3c38fc Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 9 Nov 2026 16:01:09 +0100 Subject: [PATCH 1/5] Open the tag suggestion before publishing and mention hashtags --- .github/changelog/add-pre-publish-tags-hint | 4 + build/pre-publish-panel/plugin.asset.php | 4 +- build/pre-publish-panel/plugin.js | 8 +- includes/class-blocks.php | 1 + package-lock.json | 1 + package.json | 1 + .../__tests__/plugin.test.js | 205 ++++++++++++++++++ src/pre-publish-panel/plugin.js | 117 +++++++++- 8 files changed, 333 insertions(+), 8 deletions(-) create mode 100644 .github/changelog/add-pre-publish-tags-hint diff --git a/.github/changelog/add-pre-publish-tags-hint b/.github/changelog/add-pre-publish-tags-hint new file mode 100644 index 0000000000..819fb8179b --- /dev/null +++ b/.github/changelog/add-pre-publish-tags-hint @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Before publishing a post without tags, the tag suggestion now opens by itself and explains that tags are shared as hashtags, which help people on the Fediverse find your post. diff --git a/build/pre-publish-panel/plugin.asset.php b/build/pre-publish-panel/plugin.asset.php index 92fe809fdd..467c9cd419 100644 --- a/build/pre-publish-panel/plugin.asset.php +++ b/build/pre-publish-panel/plugin.asset.php @@ -3,12 +3,14 @@ 'react-jsx-runtime', 'wp-block-editor', 'wp-components', + 'wp-core-data', 'wp-data', 'wp-dom', 'wp-editor', 'wp-element', + 'wp-hooks', 'wp-i18n', 'wp-plugins' ), - 'version' => '8bf8219b700555911ae5' + 'version' => 'afb244db83f09a5dcb3c' ); diff --git a/build/pre-publish-panel/plugin.js b/build/pre-publish-panel/plugin.js index 23ea2053ed..578d23d213 100644 --- a/build/pre-publish-panel/plugin.js +++ b/build/pre-publish-panel/plugin.js @@ -1,3 +1,5 @@ -(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.plugins,i=window.wp.components,n=window.wp.data,a=window.wp.element,s=window.wp.i18n,r=window.wp.dom,u=window._activityPubOptions?.noteLength||500,l=["youtube","vimeo","dailymotion","tiktok","videopress"],d=["spotify","soundcloud","mixcloud"],c=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],p=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],g={gallery:(0,s.__)("Gallery","activitypub"),video:(0,s.__)("Video","activitypub"),audio:(0,s.__)("Audio","activitypub"),image:(0,s.__)("Image","activitypub"),status:(0,s.__)("Status","activitypub")},m=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",h=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:n}=o;if("core/image"===t)e.imageCount++;else if(p.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();l.includes(t)?e.videoCount++:d.includes(t)&&e.audioCount++}if(c.includes(t)){const o=(0,r.__unstableStripHTML)(m(t,i));e.textLength+=o.length,e.textBlockCount++}if(n&&n.length){const t=h(n);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},v=window.ReactJSXRuntime;(0,o.registerPlugin)("activitypub-pre-publish",{render:()=>{const{blocks:o,postFormat:r}=(0,n.useSelect)(o=>({blocks:o(e.store).getBlocks(),postFormat:o(t.store).getEditedPostAttribute("format")}),[]),{editPost:l}=(0,n.useDispatch)(t.store),d=(0,a.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=h(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength0&&o.textLength0&&o.textLength0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,s.__)("This is a short post with no media. Changing the format to Status won't change your post content, but will share it as a Note on the Fediverse, which is the standard format on platforms like Mastodon.","activitypub")}:null})(o,r),[o,r]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!d){if(r&&"standard"!==r&&g[r]){const e=g[r]||r;return(0,v.jsx)(t.PluginPrePublishPanel,{title:(0,s.__)("Fediverse ⁂","activitypub"),initialOpen:!0,children:(0,v.jsx)("p",{children:(0,s.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ -(0,s.__)("This post will be shared in %s format on the Fediverse.","activitypub"),e)})})}return null}return(0,v.jsxs)(t.PluginPrePublishPanel,{title:(0,s.__)("Fediverse ⁂","activitypub"),initialOpen:!0,children:[(0,v.jsx)("p",{children:d.message}),(0,v.jsx)(i.Button,{variant:"secondary",onClick:()=>l({format:d.format}),children:(0,s.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ -(0,s.__)("Set format to %s","activitypub"),g[d.format]||d.format)})]})}})})(); \ No newline at end of file +(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.coreData,i=window.wp.plugins,n=window.wp.components,a=window.wp.data,s=window.wp.element,r=window.wp.hooks,l=window.wp.i18n,u=window.wp.dom,d=window._activityPubOptions?.noteLength||500,c=["youtube","vimeo","dailymotion","tiktok","videopress"],p=["spotify","soundcloud","mixcloud"],g=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],h=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],m={gallery:(0,l.__)("Gallery","activitypub"),video:(0,l.__)("Video","activitypub"),audio:(0,l.__)("Audio","activitypub"),image:(0,l.__)("Image","activitypub"),status:(0,l.__)("Status","activitypub")},w=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",f=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:n}=o;if("core/image"===t)e.imageCount++;else if(h.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();c.includes(t)?e.videoCount++:p.includes(t)&&e.audioCount++}if(g.includes(t)){const o=(0,u.__unstableStripHTML)(w(t,i));e.textLength+=o.length,e.textBlockCount++}if(n&&n.length){const t=f(n);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},b=window.ReactJSXRuntime,y=(0,b.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:(0,b.jsx)("text",{x:"12",y:"18",fontSize:"18",textAnchor:"middle",fill:"currentColor",children:"⁂"})}),v=()=>{const{blocks:o,postFormat:i}=(0,a.useSelect)(o=>({blocks:o(e.store).getBlocks(),postFormat:o(t.store).getEditedPostAttribute("format")}),[]),{editPost:r}=(0,a.useDispatch)(t.store),u=(0,s.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=f(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength0&&o.textLength0&&o.textLength0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,l.__)("This is a short post with no media. Changing the format to Status won't change your post content, but will share it as a Note on the Fediverse, which is the standard format on platforms like Mastodon.","activitypub")}:null})(o,i),[o,i]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!u){if(i&&"standard"!==i&&m[i]){const e=m[i]||i;return(0,b.jsx)(t.PluginPrePublishPanel,{title:(0,l.__)("Post format","activitypub"),initialOpen:!0,children:(0,b.jsx)("p",{children:(0,l.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ +(0,l.__)("This post will be shared in %s format on the Fediverse.","activitypub"),e)})})}return null}return(0,b.jsxs)(t.PluginPrePublishPanel,{title:[(0,l.__)("Suggestion:","activitypub"),(0,b.jsx)("span",{className:"editor-post-publish-panel__link",children:(0,l.__)("Change format","activitypub")},"label")],initialOpen:!0,children:[(0,b.jsx)("p",{children:u.message}),(0,b.jsx)(n.Button,{variant:"secondary",onClick:()=>r({format:u.format}),children:(0,l.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ +(0,l.__)("Set format to %s","activitypub"),m[u.format]||u.format)})]})},_=()=>{const{isOpened:e,addLabel:i,hasSiteTags:n}=(0,a.useSelect)(e=>{const i=e(o.store).getTaxonomy("post_tag");return{isOpened:e(t.store).isPublishSidebarOpened(),addLabel:i?.labels?.add_new_item,hasSiteTags:!(!i||!e(o.store).getEntityRecords("taxonomy","post_tag",{per_page:1})?.length)}},[]);return(0,s.useEffect)(()=>{e&&i&&n&&window.requestAnimationFrame(()=>{const t=Array.from(document.querySelectorAll(".editor-post-publish-panel__prepublish .editor-post-publish-panel__link")).find(t=>t.textContent===i),e=t?.closest("button");"false"===e?.getAttribute("aria-expanded")&&e.click()})},[e,i,n]),null};(0,r.addFilter)("i18n.gettext_default","activitypub/tags-suggestion",(t,e)=>{if("%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post."!==e)return t;let o=(0,l.__)(/* translators: Appended to the editor's tag suggestion, after "Tags help users and search engines navigate your site […]". */ +"Tags are also shared as hashtags, which help people on the Fediverse find your post.","activitypub");return window._activityPubOptions?.useHashtags&&(o+=" "+/* translators: Appended after the previous sentence. "#hashtags" stands for words written with a leading # in the post content. */ /* translators: Appended after the previous sentence. "#hashtags" stands for words written with a leading # in the post content. */ +(0,l.__)("You can also write #hashtags in your post.","activitypub")),t+" "+o.replace(/%/g,"%%")}),(0,i.registerPlugin)("activitypub-pre-publish",{icon:y,render:()=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(v,{}),(0,b.jsx)(_,{})]})})})(); \ No newline at end of file diff --git a/includes/class-blocks.php b/includes/class-blocks.php index 7f7864d9ab..d18430e7e0 100644 --- a/includes/class-blocks.php +++ b/includes/class-blocks.php @@ -115,6 +115,7 @@ public static function enqueue_editor_assets() { 'noteLength' => ACTIVITYPUB_NOTE_LENGTH, 'statsImageUrlEndpoint' => Stats_Image::is_available() ? \get_rest_url( null, ACTIVITYPUB_REST_NAMESPACE . '/stats/image-url/{user_id}/{year}' ) : '', 'reactionTypes' => self::get_reaction_types(), + 'useHashtags' => '1' === \get_option( 'activitypub_use_hashtags', '0' ), ); \wp_localize_script( 'wp-editor', '_activityPubOptions', $data ); diff --git a/package-lock.json b/package-lock.json index 596b7e8da6..c9817b0250 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "@wordpress/editor": "^16.0.0", "@wordpress/element": "^10.0.0", "@wordpress/env": "^12.0.0", + "@wordpress/hooks": "^5.1.0", "@wordpress/html-entities": "^5.0.0", "@wordpress/i18n": "^7.0.0", "@wordpress/icons": "^19.0.0", diff --git a/package.json b/package.json index e11694bd32..16f1fbdd94 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@wordpress/editor": "^16.0.0", "@wordpress/element": "^10.0.0", "@wordpress/env": "^12.0.0", + "@wordpress/hooks": "^5.1.0", "@wordpress/html-entities": "^5.0.0", "@wordpress/i18n": "^7.0.0", "@wordpress/icons": "^19.0.0", diff --git a/src/pre-publish-panel/__tests__/plugin.test.js b/src/pre-publish-panel/__tests__/plugin.test.js index 13802a874a..4a5176c035 100644 --- a/src/pre-publish-panel/__tests__/plugin.test.js +++ b/src/pre-publish-panel/__tests__/plugin.test.js @@ -5,7 +5,58 @@ // Set up the global options before importing utils, so NOTE_LENGTH picks up the value. window._activityPubOptions = { noteLength: 500 }; +import { render, screen } from '@testing-library/react'; +import { registerPlugin } from '@wordpress/plugins'; +import { applyFilters } from '@wordpress/hooks'; +import { __, sprintf } from '@wordpress/i18n'; import { analyzeBlocks, getSuggestedPostFormat } from '../utils'; +import '../plugin'; + +// The editor state the panels read, changed per test. +let mockEditorState; + +jest.mock( '@wordpress/plugins', () => ( { registerPlugin: jest.fn() } ) ); + +jest.mock( '@wordpress/editor', () => ( { + PluginPrePublishPanel: ( { title, children } ) => ( +
+

{ title }

+ { children } +
+ ), + PostTaxonomiesFlatTermSelector: ( { slug } ) =>
, + store: 'core/editor', +} ) ); + +jest.mock( '@wordpress/components', () => ( { + Button: ( { children, onClick } ) => , +} ) ); + +jest.mock( '@wordpress/core-data', () => ( { store: 'core' } ) ); +jest.mock( '@wordpress/block-editor', () => ( { store: 'core/block-editor' } ) ); + +jest.mock( '@wordpress/data', () => ( { + useDispatch: () => ( { editPost: jest.fn() } ), + useSelect: ( callback ) => + callback( ( store ) => { + if ( 'core' === store ) { + return { + getTaxonomy: () => mockEditorState.taxonomy, + getEntityRecords: () => mockEditorState.siteTags, + }; + } + + if ( 'core/block-editor' === store ) { + return { getBlocks: () => mockEditorState.blocks ?? [] }; + } + + return { + isPublishSidebarOpened: () => mockEditorState.isOpened, + getCurrentPostType: () => mockEditorState.postType, + getEditedPostAttribute: ( attribute ) => mockEditorState.attributes[ attribute ], + }; + } ), +} ) ); describe( 'analyzeBlocks', () => { test( 'returns all zeros for empty blocks', () => { @@ -397,3 +448,157 @@ describe( 'getSuggestedPostFormat', () => { expect( result.format ).toBe( 'gallery' ); } ); } ); + +describe( 'Tags suggestion', () => { + const Panels = () => { + const { render: Render } = registerPlugin.mock.calls[ 0 ][ 1 ]; + return ; + }; + + const coreText = + '%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'; + + /** + * Renders core's tags suggestion as core does, a panel titled by the taxonomy label. + * + * @param {string} expanded The panel's aria-expanded value. + * + * @return {jest.Mock} A click spy on the panel toggle. + */ + const renderCorePanel = ( expanded = 'false' ) => { + document.body.innerHTML = `
`; + const click = jest.fn(); + document.querySelector( 'button' ).addEventListener( 'click', click ); + return click; + }; + + beforeEach( () => { + window._activityPubOptions = { noteLength: 500 }; + mockEditorState = { + isOpened: true, + taxonomy: { types: [ 'post' ], rest_base: 'tags', labels: { add_new_item: 'Add Tag' } }, + siteTags: [ { id: 3 } ], + postType: 'post', + attributes: {}, + }; + jest.spyOn( window, 'requestAnimationFrame' ).mockImplementation( ( callback ) => callback() ); + } ); + + afterEach( () => { + window.requestAnimationFrame.mockRestore(); + document.body.innerHTML = ''; + } ); + + test( 'opens core suggestion when the sidebar opens', () => { + const click = renderCorePanel(); + render( ); + + expect( click ).toHaveBeenCalledTimes( 1 ); + } ); + + test( 'leaves core suggestion alone when it is open already', () => { + const click = renderCorePanel( 'true' ); + render( ); + + expect( click ).not.toHaveBeenCalled(); + } ); + + test( 'leaves other suggestions alone', () => { + mockEditorState.taxonomy.labels.add_new_item = 'Add Category'; + const click = renderCorePanel(); + render( ); + + expect( click ).not.toHaveBeenCalled(); + } ); + + test( 'waits for the sidebar to open', () => { + mockEditorState.isOpened = false; + const click = renderCorePanel(); + render( ); + + expect( click ).not.toHaveBeenCalled(); + } ); + + test( 'opens core suggestion once the site tags have loaded', () => { + mockEditorState.siteTags = undefined; + const click = renderCorePanel(); + const { rerender } = render( ); + + expect( click ).not.toHaveBeenCalled(); + + mockEditorState.siteTags = [ { id: 3 } ]; + rerender( ); + + expect( click ).toHaveBeenCalledTimes( 1 ); + } ); + + test( 'marks the panels with the asterism icon', () => { + const { container } = render( registerPlugin.mock.calls[ 0 ][ 1 ].icon ); + + expect( container.querySelector( 'svg text' ) ).toHaveTextContent( '⁂' ); + } ); + + test( 'renders no panel of its own', () => { + render( ); + + expect( screen.queryByTestId( 'pre-publish-panel' ) ).toBeNull(); + } ); + + test( 'adds a note on hashtags to core suggestion text', () => { + // Core's call, through the default i18n instance. + expect( + sprintf( + /* translators: %s: The taxonomy name. */ + __( + '%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.' + ), + 'Tags' + ) + ).toBe( + 'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post. Tags are also shared as hashtags, which help people on the Fediverse find your post.' + ); + } ); + + test( 'mentions hashtags in the content when they are enabled', () => { + window._activityPubOptions.useHashtags = true; + + expect( sprintf( applyFilters( 'i18n.gettext_default', coreText, coreText, undefined ), 'Tags' ) ).toMatch( + /You can also write #hashtags in your post\.$/ + ); + } ); + + test( 'leaves other core strings alone', () => { + expect( __( 'Add a few keywords to describe your post.' ) ).toBe( 'Add a few keywords to describe your post.' ); + } ); +} ); + +describe( 'Post format panel', () => { + const Panels = () => { + const { render: Render } = registerPlugin.mock.calls[ 0 ][ 1 ]; + return ; + }; + + beforeEach( () => { + window._activityPubOptions = { noteLength: 500, objectType: 'wordpress-post-format' }; + // A post type without tags, so only the post format panel renders. + mockEditorState = { + taxonomy: { types: [], rest_base: 'tags' }, + postType: 'post', + attributes: { format: 'standard' }, + blocks: [ { name: 'core/image', attributes: {}, innerBlocks: [] } ], + }; + } ); + + test( 'titles a format suggestion as a suggestion', () => { + render( ); + + expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Suggestion:Change format' ); + } ); + + test( 'titles the confirmation of a set format as the post format', () => { + mockEditorState.attributes.format = 'image'; + render( ); + + expect( screen.getByRole( 'heading' ) ).toHaveTextContent( /^Post format$/ ); + } ); +} ); diff --git a/src/pre-publish-panel/plugin.js b/src/pre-publish-panel/plugin.js index e99d6a6b72..4bd4495bca 100644 --- a/src/pre-publish-panel/plugin.js +++ b/src/pre-publish-panel/plugin.js @@ -1,12 +1,27 @@ import { PluginPrePublishPanel, store as editorStore } from '@wordpress/editor'; import { store as blockEditorStore } from '@wordpress/block-editor'; +import { store as coreStore } from '@wordpress/core-data'; import { registerPlugin } from '@wordpress/plugins'; import { Button } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; -import { useMemo } from '@wordpress/element'; +import { useEffect, useMemo } from '@wordpress/element'; +import { addFilter } from '@wordpress/hooks'; import { __, sprintf } from '@wordpress/i18n'; import { getSuggestedPostFormat, FORMAT_LABELS } from './utils'; +/** + * The asterism, the icon that marks the plugin's panels. + * + * @type {React.JSX.Element} + */ +const asterism = ( + +); + /** * Pre-publish panel that suggests a post format for better federation. * @@ -37,7 +52,7 @@ const PrePublishPanel = () => { if ( postFormat && postFormat !== 'standard' && FORMAT_LABELS[ postFormat ] ) { const formatLabel = FORMAT_LABELS[ postFormat ] || postFormat; return ( - +

{ sprintf( /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ @@ -53,7 +68,15 @@ const PrePublishPanel = () => { } return ( - + + { __( 'Change format', 'activitypub' ) } + , + ] } + initialOpen + >

{ suggestion.message }

, } ) ); -jest.mock( '@wordpress/core-data', () => ( { store: 'core' } ) ); jest.mock( '@wordpress/block-editor', () => ( { store: 'core/block-editor' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { editPost: jest.fn() } ), useSelect: ( callback ) => callback( ( store ) => { - if ( 'core' === store ) { - return { - getTaxonomy: () => mockEditorState.taxonomy, - getEntityRecords: () => mockEditorState.siteTags, - }; - } - if ( 'core/block-editor' === store ) { return { getBlocks: () => mockEditorState.blocks ?? [] }; } return { - isPublishSidebarOpened: () => mockEditorState.isOpened, - getCurrentPostType: () => mockEditorState.postType, getEditedPostAttribute: ( attribute ) => mockEditorState.attributes[ attribute ], }; } ), @@ -458,78 +448,9 @@ describe( 'Tags suggestion', () => { const coreText = '%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'; - /** - * Renders core's tags suggestion as core does, a panel titled by the taxonomy label. - * - * @param {string} expanded The panel's aria-expanded value. - * - * @return {jest.Mock} A click spy on the panel toggle. - */ - const renderCorePanel = ( expanded = 'false' ) => { - document.body.innerHTML = `
`; - const click = jest.fn(); - document.querySelector( 'button' ).addEventListener( 'click', click ); - return click; - }; - beforeEach( () => { window._activityPubOptions = { noteLength: 500 }; - mockEditorState = { - isOpened: true, - taxonomy: { types: [ 'post' ], rest_base: 'tags', labels: { add_new_item: 'Add Tag' } }, - siteTags: [ { id: 3 } ], - postType: 'post', - attributes: {}, - }; - jest.spyOn( window, 'requestAnimationFrame' ).mockImplementation( ( callback ) => callback() ); - } ); - - afterEach( () => { - window.requestAnimationFrame.mockRestore(); - document.body.innerHTML = ''; - } ); - - test( 'opens core suggestion when the sidebar opens', () => { - const click = renderCorePanel(); - render( ); - - expect( click ).toHaveBeenCalledTimes( 1 ); - } ); - - test( 'leaves core suggestion alone when it is open already', () => { - const click = renderCorePanel( 'true' ); - render( ); - - expect( click ).not.toHaveBeenCalled(); - } ); - - test( 'leaves other suggestions alone', () => { - mockEditorState.taxonomy.labels.add_new_item = 'Add Category'; - const click = renderCorePanel(); - render( ); - - expect( click ).not.toHaveBeenCalled(); - } ); - - test( 'waits for the sidebar to open', () => { - mockEditorState.isOpened = false; - const click = renderCorePanel(); - render( ); - - expect( click ).not.toHaveBeenCalled(); - } ); - - test( 'opens core suggestion once the site tags have loaded', () => { - mockEditorState.siteTags = undefined; - const click = renderCorePanel(); - const { rerender } = render( ); - - expect( click ).not.toHaveBeenCalled(); - - mockEditorState.siteTags = [ { id: 3 } ]; - rerender( ); - - expect( click ).toHaveBeenCalledTimes( 1 ); + mockEditorState = { attributes: {} }; } ); test( 'marks the panels with the asterism icon', () => { @@ -563,7 +484,7 @@ describe( 'Tags suggestion', () => { window._activityPubOptions.useHashtags = true; expect( sprintf( applyFilters( 'i18n.gettext_default', coreText, coreText, undefined ), 'Tags' ) ).toMatch( - /You can also write #hashtags in your post\.$/ + /Any #hashtag you write in your post is added as a tag too\.$/ ); } ); @@ -580,10 +501,7 @@ describe( 'Post format panel', () => { beforeEach( () => { window._activityPubOptions = { noteLength: 500, objectType: 'wordpress-post-format' }; - // A post type without tags, so only the post format panel renders. mockEditorState = { - taxonomy: { types: [], rest_base: 'tags' }, - postType: 'post', attributes: { format: 'standard' }, blocks: [ { name: 'core/image', attributes: {}, innerBlocks: [] } ], }; diff --git a/src/pre-publish-panel/plugin.js b/src/pre-publish-panel/plugin.js index 4bd4495bca..a69e3d54dd 100644 --- a/src/pre-publish-panel/plugin.js +++ b/src/pre-publish-panel/plugin.js @@ -1,10 +1,9 @@ import { PluginPrePublishPanel, store as editorStore } from '@wordpress/editor'; import { store as blockEditorStore } from '@wordpress/block-editor'; -import { store as coreStore } from '@wordpress/core-data'; import { registerPlugin } from '@wordpress/plugins'; import { Button } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; -import { useEffect, useMemo } from '@wordpress/element'; +import { useMemo } from '@wordpress/element'; import { addFilter } from '@wordpress/hooks'; import { __, sprintf } from '@wordpress/i18n'; import { getSuggestedPostFormat, FORMAT_LABELS } from './utils'; @@ -89,54 +88,6 @@ const PrePublishPanel = () => { ); }; -/** - * Opens core's tags suggestion, which starts closed. - * - * Core shows it when the site has tags and the post has none. Core has no API - * to open it, so the panel is found by its title, the taxonomy's "add new item" - * label, when the pre-publish sidebar opens. If core's markup changes, it just - * stays closed. - * - * @return {null} Renders nothing. - */ -const TagsSuggestion = () => { - const { isOpened, addLabel, hasSiteTags } = useSelect( ( selectFn ) => { - const taxonomy = selectFn( coreStore ).getTaxonomy( 'post_tag' ); - - return { - isOpened: selectFn( editorStore ).isPublishSidebarOpened(), - addLabel: taxonomy?.labels?.add_new_item, - /* - * Core's own query for its suggestion. Asking for it here loads it with the editor, - * and the panel renders once it has an answer, so it is checked again then. - */ - hasSiteTags: !! ( - taxonomy && selectFn( coreStore ).getEntityRecords( 'taxonomy', 'post_tag', { per_page: 1 } )?.length - ), - }; - }, [] ); - - useEffect( () => { - if ( ! isOpened || ! addLabel || ! hasSiteTags ) { - return; - } - - // Wait for core's panel, which renders with the sidebar. - window.requestAnimationFrame( () => { - const label = Array.from( - document.querySelectorAll( '.editor-post-publish-panel__prepublish .editor-post-publish-panel__link' ) - ).find( ( element ) => element.textContent === addLabel ); - const toggle = label?.closest( 'button' ); - - if ( 'false' === toggle?.getAttribute( 'aria-expanded' ) ) { - toggle.click(); - } - } ); - }, [ isOpened, addLabel, hasSiteTags ] ); - - return null; -}; - /** * The text of core's tags suggestion, which gets a note on hashtags. * @@ -159,8 +110,8 @@ addFilter( 'i18n.gettext_default', 'activitypub/tags-suggestion', ( translation, if ( window._activityPubOptions?.useHashtags ) { note += ' ' + - /* translators: Appended after the previous sentence. "#hashtags" stands for words written with a leading # in the post content. */ - __( 'You can also write #hashtags in your post.', 'activitypub' ); + /* translators: Appended after the previous sentence. "#hashtag" stands for a word written with a leading # in the post content. */ + __( 'Any #hashtag you write in your post is added as a tag too.', 'activitypub' ); } // Core fills in the taxonomy name with sprintf(), so a percent sign in the note must stay literal. @@ -169,10 +120,5 @@ addFilter( 'i18n.gettext_default', 'activitypub/tags-suggestion', ( translation, registerPlugin( 'activitypub-pre-publish', { icon: asterism, - render: () => ( - <> - - - - ), + render: PrePublishPanel, } ); From 8d3a8efdbcc8c41440526bcfafbee521e564de2e Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 12 Nov 2026 08:30:36 +0100 Subject: [PATCH 3/5] leave the format suggestion to core when it shows one, match its wording --- build/pre-publish-panel/plugin.asset.php | 3 +- build/pre-publish-panel/plugin.js | 8 ++-- .../__tests__/plugin.test.js | 24 ++++++++++- src/pre-publish-panel/plugin.js | 41 ++++++++++++++----- src/pre-publish-panel/utils.js | 10 ++--- 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/build/pre-publish-panel/plugin.asset.php b/build/pre-publish-panel/plugin.asset.php index 3c50048e73..c84d7d250b 100644 --- a/build/pre-publish-panel/plugin.asset.php +++ b/build/pre-publish-panel/plugin.asset.php @@ -3,6 +3,7 @@ 'react-jsx-runtime', 'wp-block-editor', 'wp-components', + 'wp-core-data', 'wp-data', 'wp-dom', 'wp-editor', @@ -11,5 +12,5 @@ 'wp-i18n', 'wp-plugins' ), - 'version' => '930e1a3e44ffb34af7f4' + 'version' => '29a3d0e4d8cce0d79d67' ); diff --git a/build/pre-publish-panel/plugin.js b/build/pre-publish-panel/plugin.js index 01968c91d5..a81956b83d 100644 --- a/build/pre-publish-panel/plugin.js +++ b/build/pre-publish-panel/plugin.js @@ -1,5 +1,5 @@ -(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.plugins,i=window.wp.components,n=window.wp.data,a=window.wp.element,s=window.wp.hooks,r=window.wp.i18n,u=window.wp.dom,l=window._activityPubOptions?.noteLength||500,d=["youtube","vimeo","dailymotion","tiktok","videopress"],c=["spotify","soundcloud","mixcloud"],p=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],g=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],h={gallery:(0,r.__)("Gallery","activitypub"),video:(0,r.__)("Video","activitypub"),audio:(0,r.__)("Audio","activitypub"),image:(0,r.__)("Image","activitypub"),status:(0,r.__)("Status","activitypub")},m=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",w=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:n}=o;if("core/image"===t)e.imageCount++;else if(g.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();d.includes(t)?e.videoCount++:c.includes(t)&&e.audioCount++}if(p.includes(t)){const o=(0,u.__unstableStripHTML)(m(t,i));e.textLength+=o.length,e.textBlockCount++}if(n&&n.length){const t=w(n);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},f=window.ReactJSXRuntime,v=(0,f.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:(0,f.jsx)("text",{x:"12",y:"18",fontSize:"18",textAnchor:"middle",fill:"currentColor",children:"⁂"})});(0,s.addFilter)("i18n.gettext_default","activitypub/tags-suggestion",(t,e)=>{if("%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post."!==e)return t;let o=(0,r.__)(/* translators: Appended to the editor's tag suggestion, after "Tags help users and search engines navigate your site […]". */ +(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.coreData,i=window.wp.plugins,s=window.wp.components,a=window.wp.data,n=window.wp.element,r=window.wp.hooks,u=window.wp.i18n,l=window.wp.dom,d=window._activityPubOptions?.noteLength||500,p=["youtube","vimeo","dailymotion","tiktok","videopress"],c=["spotify","soundcloud","mixcloud"],h=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],g=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],m={gallery:(0,u.__)("Gallery","activitypub"),video:(0,u.__)("Video","activitypub"),audio:(0,u.__)("Audio","activitypub"),image:(0,u.__)("Image","activitypub"),status:(0,u.__)("Status","activitypub")},w=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",f=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:s}=o;if("core/image"===t)e.imageCount++;else if(g.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();p.includes(t)?e.videoCount++:c.includes(t)&&e.audioCount++}if(h.includes(t)){const o=(0,l.__unstableStripHTML)(w(t,i));e.textLength+=o.length,e.textBlockCount++}if(s&&s.length){const t=f(s);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},y=window.ReactJSXRuntime,v=(0,y.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:(0,y.jsx)("text",{x:"12",y:"18",fontSize:"18",textAnchor:"middle",fill:"currentColor",children:"⁂"})});(0,r.addFilter)("i18n.gettext_default","activitypub/tags-suggestion",(t,e)=>{if("%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post."!==e)return t;let o=(0,u.__)(/* translators: Appended to the editor's tag suggestion, after "Tags help users and search engines navigate your site […]". */ "Tags are also shared as hashtags, which help people on the Fediverse find your post.","activitypub");return window._activityPubOptions?.useHashtags&&(o+=" "+/* translators: Appended after the previous sentence. "#hashtag" stands for a word written with a leading # in the post content. */ /* translators: Appended after the previous sentence. "#hashtag" stands for a word written with a leading # in the post content. */ -(0,r.__)("Any #hashtag you write in your post is added as a tag too.","activitypub")),t+" "+o.replace(/%/g,"%%")}),(0,o.registerPlugin)("activitypub-pre-publish",{icon:v,render:()=>{const{blocks:o,postFormat:s}=(0,n.useSelect)(o=>({blocks:o(e.store).getBlocks(),postFormat:o(t.store).getEditedPostAttribute("format")}),[]),{editPost:u}=(0,n.useDispatch)(t.store),d=(0,a.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=w(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength0&&o.textLength0&&o.textLength0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,r.__)("This is a short post with no media. Changing the format to Status won't change your post content, but will share it as a Note on the Fediverse, which is the standard format on platforms like Mastodon.","activitypub")}:null})(o,s),[o,s]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!d){if(s&&"standard"!==s&&h[s]){const e=h[s]||s;return(0,f.jsx)(t.PluginPrePublishPanel,{title:(0,r.__)("Post format","activitypub"),initialOpen:!0,children:(0,f.jsx)("p",{children:(0,r.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ -(0,r.__)("This post will be shared in %s format on the Fediverse.","activitypub"),e)})})}return null}return(0,f.jsxs)(t.PluginPrePublishPanel,{title:[(0,r.__)("Suggestion:","activitypub"),(0,f.jsx)("span",{className:"editor-post-publish-panel__link",children:(0,r.__)("Change format","activitypub")},"label")],initialOpen:!0,children:[(0,f.jsx)("p",{children:d.message}),(0,f.jsx)(i.Button,{variant:"secondary",onClick:()=>u({format:d.format}),children:(0,r.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ -(0,r.__)("Set format to %s","activitypub"),h[d.format]||d.format)})]})}})})(); \ No newline at end of file +(0,u.__)("Any #hashtag you write in your post is added as a tag too.","activitypub")),t+" "+o.replace(/%/g,"%%")}),(0,i.registerPlugin)("activitypub-pre-publish",{icon:v,render:()=>{const{blocks:i,postFormat:r,coreSuggestsFormat:l}=(0,a.useSelect)(i=>{const s=i(t.store).getEditedPostAttribute("format"),a=i(t.store).getSuggestedPostFormat(),n=i(o.store).getThemeSupports()?.formats??[];return{blocks:i(e.store).getBlocks(),postFormat:s,coreSuggestsFormat:!!a&&n.includes(a)&&a!==s}},[]),{editPost:p}=(0,a.useDispatch)(t.store),c=(0,n.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=f(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength0&&o.textLength0&&o.textLength0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,u.__)("This is a short post without media. With the Status format, it is shared as a short post on the Fediverse, the way posts look on platforms like Mastodon. Your post content stays the same.","activitypub")}:null})(i,r),[i,r]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!c){if(r&&"standard"!==r&&m[r]){const e=m[r]||r;return(0,y.jsx)(t.PluginPrePublishPanel,{title:(0,u.__)("Post format","activitypub"),initialOpen:!0,children:(0,y.jsx)("p",{children:(0,u.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ +(0,u.__)("This post will be shared in %s format on the Fediverse.","activitypub"),e)})})}return null}return l?null:(0,y.jsxs)(t.PluginPrePublishPanel,{title:[(0,u.__)("Suggestion:","activitypub"),(0,y.jsx)("span",{className:"editor-post-publish-panel__link",children:(0,u.__)("Use a post format","activitypub")},"label")],initialOpen:!1,children:[(0,y.jsx)("p",{children:c.message}),(0,y.jsx)("p",{children:(0,y.jsx)(s.Button,{__next40pxDefaultSize:!0,variant:"link",onClick:()=>p({format:c.format}),children:(0,u.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ +(0,u.__)('Apply the "%s" format.',"activitypub"),m[c.format]||c.format)})})]})}})})(); \ No newline at end of file diff --git a/src/pre-publish-panel/__tests__/plugin.test.js b/src/pre-publish-panel/__tests__/plugin.test.js index f54bf40fcf..cfad69c6c4 100644 --- a/src/pre-publish-panel/__tests__/plugin.test.js +++ b/src/pre-publish-panel/__tests__/plugin.test.js @@ -34,6 +34,8 @@ jest.mock( '@wordpress/components', () => ( { jest.mock( '@wordpress/block-editor', () => ( { store: 'core/block-editor' } ) ); +jest.mock( '@wordpress/core-data', () => ( { store: 'core' } ) ); + jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { editPost: jest.fn() } ), useSelect: ( callback ) => @@ -42,8 +44,13 @@ jest.mock( '@wordpress/data', () => ( { return { getBlocks: () => mockEditorState.blocks ?? [] }; } + if ( 'core' === store ) { + return { getThemeSupports: () => ( { formats: mockEditorState.themeFormats ?? [] } ) }; + } + return { getEditedPostAttribute: ( attribute ) => mockEditorState.attributes[ attribute ], + getSuggestedPostFormat: () => mockEditorState.coreSuggestion ?? null, }; } ), } ) ); @@ -510,7 +517,7 @@ describe( 'Post format panel', () => { test( 'titles a format suggestion as a suggestion', () => { render( ); - expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Suggestion:Change format' ); + expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Suggestion:Use a post format' ); } ); test( 'titles the confirmation of a set format as the post format', () => { @@ -519,4 +526,19 @@ describe( 'Post format panel', () => { expect( screen.getByRole( 'heading' ) ).toHaveTextContent( /^Post format$/ ); } ); + + test( 'leaves the suggestion to core when core suggests a format', () => { + mockEditorState.coreSuggestion = 'image'; + mockEditorState.themeFormats = [ 'image' ]; + render( ); + + expect( screen.queryByTestId( 'pre-publish-panel' ) ).toBeNull(); + } ); + + test( "suggests a format when the theme does not support core's suggestion", () => { + mockEditorState.coreSuggestion = 'image'; + render( ); + + expect( screen.getByRole( 'heading' ) ).toHaveTextContent( 'Suggestion:Use a post format' ); + } ); } ); diff --git a/src/pre-publish-panel/plugin.js b/src/pre-publish-panel/plugin.js index a69e3d54dd..26bd288b4b 100644 --- a/src/pre-publish-panel/plugin.js +++ b/src/pre-publish-panel/plugin.js @@ -1,5 +1,6 @@ import { PluginPrePublishPanel, store as editorStore } from '@wordpress/editor'; import { store as blockEditorStore } from '@wordpress/block-editor'; +import { store as coreStore } from '@wordpress/core-data'; import { registerPlugin } from '@wordpress/plugins'; import { Button } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -26,14 +27,21 @@ const asterism = ( * * Only renders when the object type setting is 'wordpress-post-format' and * the post content suggests a better format than the default Article. + * A suggestion is left out while core's own post format suggestion shows. * * @return {React.JSX.Element|null} The pre-publish panel or null. */ const PrePublishPanel = () => { - const { blocks, postFormat } = useSelect( ( selectFn ) => { + const { blocks, postFormat, coreSuggestsFormat } = useSelect( ( selectFn ) => { + const format = selectFn( editorStore ).getEditedPostAttribute( 'format' ); + const coreFormat = selectFn( editorStore ).getSuggestedPostFormat(); + const themeFormats = selectFn( coreStore ).getThemeSupports()?.formats ?? []; + return { blocks: selectFn( blockEditorStore ).getBlocks(), - postFormat: selectFn( editorStore ).getEditedPostAttribute( 'format' ), + postFormat: format, + // Same check as core's own "Use a post format" suggestion. + coreSuggestsFormat: !! coreFormat && themeFormats.includes( coreFormat ) && coreFormat !== format, }; }, [] ); @@ -66,24 +74,35 @@ const PrePublishPanel = () => { return null; } + // Core already suggests a post format, a second suggestion would repeat it. + if ( coreSuggestsFormat ) { + return null; + } + return ( - { __( 'Change format', 'activitypub' ) } + { __( 'Use a post format', 'activitypub' ) } , ] } - initialOpen + initialOpen={ false } >

{ suggestion.message }

- +

+ +

); }; diff --git a/src/pre-publish-panel/utils.js b/src/pre-publish-panel/utils.js index 422d5c68b0..621848c79f 100644 --- a/src/pre-publish-panel/utils.js +++ b/src/pre-publish-panel/utils.js @@ -164,7 +164,7 @@ export const getSuggestedPostFormat = ( blocks, currentFormat ) => { return { format: 'gallery', message: __( - "This post contains multiple images. Changing the format to Gallery won't change your post content, but will share it as a media post on the Fediverse, making it visible on platforms like Pixelfed.", + 'This post contains multiple images. With the Gallery format, it is shared as a media post on the Fediverse and shows up on platforms like Pixelfed. Your post content stays the same.', 'activitypub' ), }; @@ -175,7 +175,7 @@ export const getSuggestedPostFormat = ( blocks, currentFormat ) => { return { format: 'video', message: __( - "This post contains a video. Changing the format to Video won't change your post content, but will share it as a media post on the Fediverse, improving compatibility with video-focused platforms.", + 'This post contains a video. With the Video format, it is shared as a media post on the Fediverse and works better on video platforms. Your post content stays the same.', 'activitypub' ), }; @@ -186,7 +186,7 @@ export const getSuggestedPostFormat = ( blocks, currentFormat ) => { return { format: 'audio', message: __( - "This post contains audio content. Changing the format to Audio won't change your post content, but will share it as a media post on the Fediverse, improving compatibility with audio-focused platforms.", + 'This post contains audio. With the Audio format, it is shared as a media post on the Fediverse and works better on audio platforms. Your post content stays the same.', 'activitypub' ), }; @@ -202,7 +202,7 @@ export const getSuggestedPostFormat = ( blocks, currentFormat ) => { return { format: 'image', message: __( - "This post contains an image. Changing the format to Image won't change your post content, but will share it as a media post on the Fediverse, making it visible on platforms like Pixelfed.", + 'This post contains an image. With the Image format, it is shared as a media post on the Fediverse and shows up on platforms like Pixelfed. Your post content stays the same.', 'activitypub' ), }; @@ -213,7 +213,7 @@ export const getSuggestedPostFormat = ( blocks, currentFormat ) => { return { format: 'status', message: __( - "This is a short post with no media. Changing the format to Status won't change your post content, but will share it as a Note on the Fediverse, which is the standard format on platforms like Mastodon.", + 'This is a short post without media. With the Status format, it is shared as a short post on the Fediverse, the way posts look on platforms like Mastodon. Your post content stays the same.', 'activitypub' ), }; From dcff6ea1d2fce34f7cb85d09a54742d22e2d8c6a Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 12 Nov 2026 17:06:45 +0100 Subject: [PATCH 4/5] say in core's format suggestion that the format changes the Fediverse post --- build/pre-publish-panel/plugin.asset.php | 2 +- build/pre-publish-panel/plugin.js | 7 +++--- .../__tests__/plugin.test.js | 22 +++++++++++++++++++ src/pre-publish-panel/plugin.js | 21 ++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/build/pre-publish-panel/plugin.asset.php b/build/pre-publish-panel/plugin.asset.php index c84d7d250b..f74e7e5a18 100644 --- a/build/pre-publish-panel/plugin.asset.php +++ b/build/pre-publish-panel/plugin.asset.php @@ -12,5 +12,5 @@ 'wp-i18n', 'wp-plugins' ), - 'version' => '29a3d0e4d8cce0d79d67' + 'version' => 'a6df243d59adf493fc82' ); diff --git a/build/pre-publish-panel/plugin.js b/build/pre-publish-panel/plugin.js index a81956b83d..74039584b0 100644 --- a/build/pre-publish-panel/plugin.js +++ b/build/pre-publish-panel/plugin.js @@ -1,5 +1,6 @@ -(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.coreData,i=window.wp.plugins,s=window.wp.components,a=window.wp.data,n=window.wp.element,r=window.wp.hooks,u=window.wp.i18n,l=window.wp.dom,d=window._activityPubOptions?.noteLength||500,p=["youtube","vimeo","dailymotion","tiktok","videopress"],c=["spotify","soundcloud","mixcloud"],h=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],g=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],m={gallery:(0,u.__)("Gallery","activitypub"),video:(0,u.__)("Video","activitypub"),audio:(0,u.__)("Audio","activitypub"),image:(0,u.__)("Image","activitypub"),status:(0,u.__)("Status","activitypub")},w=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",f=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:s}=o;if("core/image"===t)e.imageCount++;else if(g.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();p.includes(t)?e.videoCount++:c.includes(t)&&e.audioCount++}if(h.includes(t)){const o=(0,l.__unstableStripHTML)(w(t,i));e.textLength+=o.length,e.textBlockCount++}if(s&&s.length){const t=f(s);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},y=window.ReactJSXRuntime,v=(0,y.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:(0,y.jsx)("text",{x:"12",y:"18",fontSize:"18",textAnchor:"middle",fill:"currentColor",children:"⁂"})});(0,r.addFilter)("i18n.gettext_default","activitypub/tags-suggestion",(t,e)=>{if("%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post."!==e)return t;let o=(0,u.__)(/* translators: Appended to the editor's tag suggestion, after "Tags help users and search engines navigate your site […]". */ +(()=>{"use strict";const t=window.wp.editor,e=window.wp.blockEditor,o=window.wp.coreData,i=window.wp.plugins,s=window.wp.components,a=window.wp.data,n=window.wp.element,r=window.wp.hooks,u=window.wp.i18n,l=window.wp.dom,d=window._activityPubOptions?.noteLength||500,p=["youtube","vimeo","dailymotion","tiktok","videopress"],c=["spotify","soundcloud","mixcloud"],h=["core/paragraph","core/heading","core/list-item","core/preformatted","core/verse","core/pullquote"],m=["core/gallery","jetpack/tiled-gallery","jetpack/slideshow"],g={gallery:(0,u.__)("Gallery","activitypub"),video:(0,u.__)("Video","activitypub"),audio:(0,u.__)("Audio","activitypub"),image:(0,u.__)("Image","activitypub"),status:(0,u.__)("Status","activitypub")},f=(t,e)=>"core/pullquote"===t?e?.value||"":e?.content||"",w=t=>{const e={imageCount:0,galleryCount:0,videoCount:0,audioCount:0,textLength:0,textBlockCount:0};if(!t||!t.length)return e;for(const o of t){const{name:t,attributes:i,innerBlocks:s}=o;if("core/image"===t)e.imageCount++;else if(m.includes(t))e.galleryCount++;else if("core/video"===t)e.videoCount++;else if("core/audio"===t)e.audioCount++;else if("core/embed"===t){const t=(i?.providerNameSlug||"").toLowerCase();p.includes(t)?e.videoCount++:c.includes(t)&&e.audioCount++}if(h.includes(t)){const o=(0,l.__unstableStripHTML)(f(t,i));e.textLength+=o.length,e.textBlockCount++}if(s&&s.length){const t=w(s);e.imageCount+=t.imageCount,e.galleryCount+=t.galleryCount,e.videoCount+=t.videoCount,e.audioCount+=t.audioCount,e.textLength+=t.textLength,e.textBlockCount+=t.textBlockCount}}return e},y=window.ReactJSXRuntime,v=(0,y.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:(0,y.jsx)("text",{x:"12",y:"18",fontSize:"18",textAnchor:"middle",fill:"currentColor",children:"⁂"})});(0,r.addFilter)("i18n.gettext_default","activitypub/tags-suggestion",(t,e)=>{if("Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling."===e&&"wordpress-post-format"===window._activityPubOptions?.objectType)return t+" "+(0,u.__)(/* translators: Appended to the editor's post format suggestion, after "Your theme uses post formats […]". */ +"The format also changes how your post is shared on the Fediverse.","activitypub");if("%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post."!==e)return t;let o=(0,u.__)(/* translators: Appended to the editor's tag suggestion, after "Tags help users and search engines navigate your site […]". */ "Tags are also shared as hashtags, which help people on the Fediverse find your post.","activitypub");return window._activityPubOptions?.useHashtags&&(o+=" "+/* translators: Appended after the previous sentence. "#hashtag" stands for a word written with a leading # in the post content. */ /* translators: Appended after the previous sentence. "#hashtag" stands for a word written with a leading # in the post content. */ -(0,u.__)("Any #hashtag you write in your post is added as a tag too.","activitypub")),t+" "+o.replace(/%/g,"%%")}),(0,i.registerPlugin)("activitypub-pre-publish",{icon:v,render:()=>{const{blocks:i,postFormat:r,coreSuggestsFormat:l}=(0,a.useSelect)(i=>{const s=i(t.store).getEditedPostAttribute("format"),a=i(t.store).getSuggestedPostFormat(),n=i(o.store).getThemeSupports()?.formats??[];return{blocks:i(e.store).getBlocks(),postFormat:s,coreSuggestsFormat:!!a&&n.includes(a)&&a!==s}},[]),{editPost:p}=(0,a.useDispatch)(t.store),c=(0,n.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=f(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength0&&o.textLength0&&o.textLength0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,u.__)("This is a short post without media. With the Status format, it is shared as a short post on the Fediverse, the way posts look on platforms like Mastodon. Your post content stays the same.","activitypub")}:null})(i,r),[i,r]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!c){if(r&&"standard"!==r&&m[r]){const e=m[r]||r;return(0,y.jsx)(t.PluginPrePublishPanel,{title:(0,u.__)("Post format","activitypub"),initialOpen:!0,children:(0,y.jsx)("p",{children:(0,u.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ +(0,u.__)("Any #hashtag you write in your post is added as a tag too.","activitypub")),t+" "+o.replace(/%/g,"%%")}),(0,i.registerPlugin)("activitypub-pre-publish",{icon:v,render:()=>{const{blocks:i,postFormat:r,coreSuggestsFormat:l}=(0,a.useSelect)(i=>{const s=i(t.store).getEditedPostAttribute("format"),a=i(t.store).getSuggestedPostFormat(),n=i(o.store).getThemeSupports()?.formats??[];return{blocks:i(e.store).getBlocks(),postFormat:s,coreSuggestsFormat:!!a&&n.includes(a)&&a!==s}},[]),{editPost:p}=(0,a.useDispatch)(t.store),c=(0,n.useMemo)(()=>((t,e)=>{if(e&&"standard"!==e)return null;const o=w(t),i=o.imageCount>0||o.galleryCount>0||o.videoCount>0||o.audioCount>0;return(o.galleryCount>0||o.imageCount>1)&&o.textLength0&&o.textLength0&&o.textLength0&&o.textLength<280&&o.textBlockCount<=3?{format:"status",message:(0,u.__)("This is a short post without media. With the Status format, it is shared as a short post on the Fediverse, the way posts look on platforms like Mastodon. Your post content stays the same.","activitypub")}:null})(i,r),[i,r]);if("wordpress-post-format"!==window._activityPubOptions?.objectType)return null;if(!c){if(r&&"standard"!==r&&g[r]){const e=g[r]||r;return(0,y.jsx)(t.PluginPrePublishPanel,{title:(0,u.__)("Post format","activitypub"),initialOpen:!0,children:(0,y.jsx)("p",{children:(0,u.sprintf)(/* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The current post format name (e.g., "Image", "Gallery", "Video"). */ (0,u.__)("This post will be shared in %s format on the Fediverse.","activitypub"),e)})})}return null}return l?null:(0,y.jsxs)(t.PluginPrePublishPanel,{title:[(0,u.__)("Suggestion:","activitypub"),(0,y.jsx)("span",{className:"editor-post-publish-panel__link",children:(0,u.__)("Use a post format","activitypub")},"label")],initialOpen:!1,children:[(0,y.jsx)("p",{children:c.message}),(0,y.jsx)("p",{children:(0,y.jsx)(s.Button,{__next40pxDefaultSize:!0,variant:"link",onClick:()=>p({format:c.format}),children:(0,u.sprintf)(/* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ /* translators: %s: The suggested post format name (e.g., "Image", "Gallery", "Video"). */ -(0,u.__)('Apply the "%s" format.',"activitypub"),m[c.format]||c.format)})})]})}})})(); \ No newline at end of file +(0,u.__)('Apply the "%s" format.',"activitypub"),g[c.format]||c.format)})})]})}})})(); \ No newline at end of file diff --git a/src/pre-publish-panel/__tests__/plugin.test.js b/src/pre-publish-panel/__tests__/plugin.test.js index cfad69c6c4..e13f0e2286 100644 --- a/src/pre-publish-panel/__tests__/plugin.test.js +++ b/src/pre-publish-panel/__tests__/plugin.test.js @@ -500,6 +500,28 @@ describe( 'Tags suggestion', () => { } ); } ); +describe( 'Post format suggestion text', () => { + const coreText = + 'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.'; + + test( 'adds a note on the Fediverse when the format sets the object type', () => { + window._activityPubOptions = { objectType: 'wordpress-post-format' }; + + // Core's call, through the default i18n instance. + expect( + __( + 'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.' + ) + ).toBe( `${ coreText } The format also changes how your post is shared on the Fediverse.` ); + } ); + + test( 'leaves the text alone when the format does not set the object type', () => { + window._activityPubOptions = { objectType: 'note' }; + + expect( applyFilters( 'i18n.gettext_default', coreText, coreText, undefined ) ).toBe( coreText ); + } ); +} ); + describe( 'Post format panel', () => { const Panels = () => { const { render: Render } = registerPlugin.mock.calls[ 0 ][ 1 ]; diff --git a/src/pre-publish-panel/plugin.js b/src/pre-publish-panel/plugin.js index 26bd288b4b..1cd769a196 100644 --- a/src/pre-publish-panel/plugin.js +++ b/src/pre-publish-panel/plugin.js @@ -115,7 +115,28 @@ const PrePublishPanel = () => { const CORE_TAGS_TEXT = '%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'; +/** + * The text of core's post format suggestion, which gets a note on the Fediverse. + * + * @type {string} + */ +const CORE_FORMAT_TEXT = + 'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.'; + addFilter( 'i18n.gettext_default', 'activitypub/tags-suggestion', ( translation, text ) => { + // Core's format suggestion replaces the plugin's own, so it says what the format does on the Fediverse. + if ( CORE_FORMAT_TEXT === text && window._activityPubOptions?.objectType === 'wordpress-post-format' ) { + return ( + translation + + ' ' + + __( + /* translators: Appended to the editor's post format suggestion, after "Your theme uses post formats […]". */ + 'The format also changes how your post is shared on the Fediverse.', + 'activitypub' + ) + ); + } + if ( CORE_TAGS_TEXT !== text ) { return translation; } From 695e7b088650f7d43e44ad34973b79b0a25bc676 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 16 Nov 2026 09:21:02 +0100 Subject: [PATCH 5/5] match core's tag suggestion before 6.9, cover formats in the changelog --- .github/changelog/add-pre-publish-tags-hint | 2 +- src/pre-publish-panel/__tests__/plugin.test.js | 10 ++++++++++ src/pre-publish-panel/plugin.js | 14 +++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/changelog/add-pre-publish-tags-hint b/.github/changelog/add-pre-publish-tags-hint index a0db7fa435..5bcda89ac2 100644 --- a/.github/changelog/add-pre-publish-tags-hint +++ b/.github/changelog/add-pre-publish-tags-hint @@ -1,4 +1,4 @@ Significance: minor Type: added -Before publishing a post without tags, the tag suggestion now explains that tags are shared as hashtags, which help people on the Fediverse find your post. +Before publishing, the tag and post format suggestions now explain what tags and formats do on the Fediverse. diff --git a/src/pre-publish-panel/__tests__/plugin.test.js b/src/pre-publish-panel/__tests__/plugin.test.js index e13f0e2286..6a747acc12 100644 --- a/src/pre-publish-panel/__tests__/plugin.test.js +++ b/src/pre-publish-panel/__tests__/plugin.test.js @@ -487,6 +487,16 @@ describe( 'Tags suggestion', () => { ); } ); + test( 'adds a note on hashtags to the suggestion text before WordPress 6.9', () => { + expect( + __( + 'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post.' + ) + ).toBe( + 'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post. Tags are also shared as hashtags, which help people on the Fediverse find your post.' + ); + } ); + test( 'mentions hashtags in the content when they are enabled', () => { window._activityPubOptions.useHashtags = true; diff --git a/src/pre-publish-panel/plugin.js b/src/pre-publish-panel/plugin.js index 1cd769a196..0be3cb97df 100644 --- a/src/pre-publish-panel/plugin.js +++ b/src/pre-publish-panel/plugin.js @@ -115,6 +115,14 @@ const PrePublishPanel = () => { const CORE_TAGS_TEXT = '%s help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'; +/** + * The text of core's tags suggestion before WordPress 6.9, which names the taxonomy itself. + * + * @type {string} + */ +const CORE_TAGS_TEXT_BEFORE_6_9 = + 'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post.'; + /** * The text of core's post format suggestion, which gets a note on the Fediverse. * @@ -137,7 +145,7 @@ addFilter( 'i18n.gettext_default', 'activitypub/tags-suggestion', ( translation, ); } - if ( CORE_TAGS_TEXT !== text ) { + if ( CORE_TAGS_TEXT !== text && CORE_TAGS_TEXT_BEFORE_6_9 !== text ) { return translation; } @@ -154,8 +162,8 @@ addFilter( 'i18n.gettext_default', 'activitypub/tags-suggestion', ( translation, __( 'Any #hashtag you write in your post is added as a tag too.', 'activitypub' ); } - // Core fills in the taxonomy name with sprintf(), so a percent sign in the note must stay literal. - return translation + ' ' + note.replace( /%/g, '%%' ); + // Since 6.9 core fills in the taxonomy name with sprintf(), so a percent sign in the note must stay literal. + return translation + ' ' + ( CORE_TAGS_TEXT === text ? note.replace( /%/g, '%%' ) : note ); } ); registerPlugin( 'activitypub-pre-publish', {