diff --git a/.github/changelog/fix-visibility-meta-sync b/.github/changelog/fix-visibility-meta-sync new file mode 100644 index 0000000000..2499166e36 --- /dev/null +++ b/.github/changelog/fix-visibility-meta-sync @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed visibility setting not being saved correctly in block editor and classic editor. diff --git a/build/editor-plugin/plugin.asset.php b/build/editor-plugin/plugin.asset.php index 2bc42a8252..f251f461c4 100644 --- a/build/editor-plugin/plugin.asset.php +++ b/build/editor-plugin/plugin.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '4371fba4c154ea1d6303'); + array('react-jsx-runtime', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'c5a3060dcb4bb10e94ee'); diff --git a/build/editor-plugin/plugin.js b/build/editor-plugin/plugin.js index b6ce964b64..0dbbccacdf 100644 --- a/build/editor-plugin/plugin.js +++ b/build/editor-plugin/plugin.js @@ -1 +1 @@ -(()=>{"use strict";const t=window.wp.editor,e=window.wp.editPost,i=window.wp.plugins,n=window.wp.components,a=window.wp.element;var o=(0,a.forwardRef)(({icon:t,size:e=24,...i},n)=>(0,a.cloneElement)(t,{width:e,height:e,...i,ref:n}));const l=window.wp.primitives,c=window.ReactJSXRuntime;var s=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{d:"M12 4c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm6.5 8c0 .6 0 1.2-.2 1.8h-2.7c0-.6.2-1.1.2-1.8s0-1.2-.2-1.8h2.7c.2.6.2 1.1.2 1.8Zm-.9-3.2h-2.4c-.3-.9-.7-1.8-1.1-2.4-.1-.2-.2-.4-.3-.5 1.6.5 3 1.6 3.8 3ZM12.8 17c-.3.5-.6 1-.8 1.3-.2-.3-.5-.8-.8-1.3-.3-.5-.6-1.1-.8-1.7h3.3c-.2.6-.5 1.2-.8 1.7Zm-2.9-3.2c-.1-.6-.2-1.1-.2-1.8s0-1.2.2-1.8H14c.1.6.2 1.1.2 1.8s0 1.2-.2 1.8H9.9ZM11.2 7c.3-.5.6-1 .8-1.3.2.3.5.8.8 1.3.3.5.6 1.1.8 1.7h-3.3c.2-.6.5-1.2.8-1.7Zm-1-1.2c-.1.2-.2.3-.3.5-.4.7-.8 1.5-1.1 2.4H6.4c.8-1.4 2.2-2.5 3.8-3Zm-1.8 8H5.7c-.2-.6-.2-1.1-.2-1.8s0-1.2.2-1.8h2.7c0 .6-.2 1.1-.2 1.8s0 1.2.2 1.8Zm-2 1.4h2.4c.3.9.7 1.8 1.1 2.4.1.2.2.4.3.5-1.6-.5-3-1.6-3.8-3Zm7.4 3c.1-.2.2-.3.3-.5.4-.7.8-1.5 1.1-2.4h2.4c-.8 1.4-2.2 2.5-3.8 3Z"})}),u=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),r=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{d:"M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"})});const p=window.wp.data,v=window.wp.coreData,w=window.wp.url,_=window.wp.i18n,h=(t,e)=>t?.activitypub_content_visibility?t.activitypub_content_visibility:"federated"===t?.activitypub_status?"public":e&&new Date(e).getTime(){const i=(0,p.useSelect)(e=>e(t.store).getCurrentPostType(),[]),[a,r]=(0,v.useEntityProp)("postType",i,"meta"),w=(0,p.useSelect)(e=>e(t.store).getCurrentPost().date,[]);if("wp_block"===i)return null;const b=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 18.5A6.5 6.5 0 0 1 6.93 7.931l9.139 9.138A6.473 6.473 0 0 1 12 18.5Zm5.123-2.498a6.5 6.5 0 0 0-9.124-9.124l9.124 9.124ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Z"})}),d={verticalAlign:"middle",gap:"4px",justifyContent:"start",display:"inline-flex",alignItems:"center"},m=(t,e,i)=>(0,c.jsx)(n.Tooltip,{text:i,children:(0,c.jsxs)(n.__experimentalText,{style:d,children:[(0,c.jsx)(o,{icon:t}),e]})}),y=t.PluginDocumentSettingPanel||e.PluginDocumentSettingPanel;return(0,c.jsxs)(y,{name:"activitypub",className:"block-editor-block-inspector",title:(0,_.__)("Fediverse ⁂","activitypub"),children:[(0,c.jsx)(n.TextControl,{label:(0,_.__)("Content Warning","activitypub"),value:a?.activitypub_content_warning,onChange:t=>{r({...a,activitypub_content_warning:t})},placeholder:(0,_.__)("Optional content warning","activitypub"),help:(0,_.__)("Content warnings do not change the content on your site, only in the fediverse.","activitypub"),__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),(0,c.jsx)(n.RangeControl,{label:(0,_.__)("Maximum Image Attachments","activitypub"),value:a?.activitypub_max_image_attachments,onChange:t=>{r({...a,activitypub_max_image_attachments:t})},min:0,max:10,help:(0,_.__)("Maximum number of image attachments to include when sharing to the fediverse.","activitypub"),__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),(0,c.jsx)(n.RadioControl,{label:(0,_.__)("Visibility","activitypub"),help:(0,_.__)("This adjusts the visibility of a post in the fediverse, but note that it won't affect how the post appears on the blog.","activitypub"),selected:h(a,w),options:[{label:m(s,(0,_.__)("Public","activitypub"),(0,_.__)("Post will be visible to everyone and appear in public timelines.","activitypub")),value:"public"},{label:m(u,(0,_.__)("Quiet public","activitypub"),(0,_.__)("Post will be visible to everyone but will not appear in public timelines.","activitypub")),value:"quiet_public"},{label:m(b,(0,_.__)("Do not federate","activitypub"),(0,_.__)("Post will not be shared to the Fediverse.","activitypub")),value:"local"}],onChange:t=>{r({...a,activitypub_content_visibility:t})},className:"activitypub-visibility"}),(0,c.jsx)(n.SelectControl,{label:(0,_.__)("Who can quote this post?","activitypub"),help:(0,_.__)("Quoting allows others to cite your post while adding their own commentary.","activitypub"),value:a?.activitypub_interaction_policy_quote,options:[{label:(0,_.__)("Anyone","activitypub"),value:"anyone"},{label:(0,_.__)("Followers only","activitypub"),value:"followers"},{label:(0,_.__)("Just me","activitypub"),value:"me"}],onChange:t=>{r({...a,activitypub_interaction_policy_quote:t})},__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})]})}}),(0,i.registerPlugin)("activitypub-editor-preview",{render:()=>{const e=(0,p.useSelect)(e=>e(t.store).getCurrentPost().status,[]);return(0,c.jsx)(c.Fragment,{children:t.PluginPreviewMenuItem?(0,c.jsx)(t.PluginPreviewMenuItem,{onClick:()=>{const e=(0,p.select)(t.store).getEditedPostPreviewLink(),i=(0,w.addQueryArgs)(e,{activitypub:"true"});window.open(i,"_blank")},icon:r,disabled:"auto-draft"===e,children:(0,_.__)("Fediverse preview ⁂","activitypub")}):null})}})})(); \ No newline at end of file +(()=>{"use strict";const t=window.wp.editor,e=window.wp.editPost,i=window.wp.plugins,n=window.wp.components,a=window.wp.element;var o=(0,a.forwardRef)(({icon:t,size:e=24,...i},n)=>(0,a.cloneElement)(t,{width:e,height:e,...i,ref:n}));const l=window.wp.primitives,c=window.ReactJSXRuntime;var s=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{d:"M12 4c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm6.5 8c0 .6 0 1.2-.2 1.8h-2.7c0-.6.2-1.1.2-1.8s0-1.2-.2-1.8h2.7c.2.6.2 1.1.2 1.8Zm-.9-3.2h-2.4c-.3-.9-.7-1.8-1.1-2.4-.1-.2-.2-.4-.3-.5 1.6.5 3 1.6 3.8 3ZM12.8 17c-.3.5-.6 1-.8 1.3-.2-.3-.5-.8-.8-1.3-.3-.5-.6-1.1-.8-1.7h3.3c-.2.6-.5 1.2-.8 1.7Zm-2.9-3.2c-.1-.6-.2-1.1-.2-1.8s0-1.2.2-1.8H14c.1.6.2 1.1.2 1.8s0 1.2-.2 1.8H9.9ZM11.2 7c.3-.5.6-1 .8-1.3.2.3.5.8.8 1.3.3.5.6 1.1.8 1.7h-3.3c.2-.6.5-1.2.8-1.7Zm-1-1.2c-.1.2-.2.3-.3.5-.4.7-.8 1.5-1.1 2.4H6.4c.8-1.4 2.2-2.5 3.8-3Zm-1.8 8H5.7c-.2-.6-.2-1.1-.2-1.8s0-1.2.2-1.8h2.7c0 .6-.2 1.1-.2 1.8s0 1.2.2 1.8Zm-2 1.4h2.4c.3.9.7 1.8 1.1 2.4.1.2.2.4.3.5-1.6-.5-3-1.6-3.8-3Zm7.4 3c.1-.2.2-.3.3-.5.4-.7.8-1.5 1.1-2.4h2.4c-.8 1.4-2.2 2.5-3.8 3Z"})}),u=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),r=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{d:"M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"})});const p=window.wp.data,v=window.wp.coreData,_=window.wp.url,w=window.wp.i18n;(0,i.registerPlugin)("activitypub-editor-plugin",{render:()=>{const i=(0,p.useSelect)(e=>e(t.store).getCurrentPostType(),[]),[r,_]=(0,v.useEntityProp)("postType",i,"meta"),b=(0,p.useSelect)(e=>e(t.store).getCurrentPost().date,[]),h=((t,e)=>t?.activitypub_content_visibility?t.activitypub_content_visibility:"federated"===t?.activitypub_status?"public":e&&new Date(e).getTime(){const t=r?.activitypub_content_visibility;t||"public"===h||_({...r,activitypub_content_visibility:h})},[h,r,_]),"wp_block"===i)return null;const d=(0,c.jsx)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,c.jsx)(l.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 18.5A6.5 6.5 0 0 1 6.93 7.931l9.139 9.138A6.473 6.473 0 0 1 12 18.5Zm5.123-2.498a6.5 6.5 0 0 0-9.124-9.124l9.124 9.124ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Z"})}),y={verticalAlign:"middle",gap:"4px",justifyContent:"start",display:"inline-flex",alignItems:"center"},m=(t,e,i)=>(0,c.jsx)(n.Tooltip,{text:i,children:(0,c.jsxs)(n.__experimentalText,{style:y,children:[(0,c.jsx)(o,{icon:t}),e]})}),g=t.PluginDocumentSettingPanel||e.PluginDocumentSettingPanel;return(0,c.jsxs)(g,{name:"activitypub",className:"block-editor-block-inspector",title:(0,w.__)("Fediverse ⁂","activitypub"),children:[(0,c.jsx)(n.TextControl,{label:(0,w.__)("Content Warning","activitypub"),value:r?.activitypub_content_warning,onChange:t=>{_({...r,activitypub_content_warning:t})},placeholder:(0,w.__)("Optional content warning","activitypub"),help:(0,w.__)("Content warnings do not change the content on your site, only in the fediverse.","activitypub"),__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),(0,c.jsx)(n.RangeControl,{label:(0,w.__)("Maximum Image Attachments","activitypub"),value:r?.activitypub_max_image_attachments,onChange:t=>{_({...r,activitypub_max_image_attachments:t})},min:0,max:10,help:(0,w.__)("Maximum number of image attachments to include when sharing to the fediverse.","activitypub"),__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0}),(0,c.jsx)(n.RadioControl,{label:(0,w.__)("Visibility","activitypub"),help:(0,w.__)("This adjusts the visibility of a post in the fediverse, but note that it won't affect how the post appears on the blog.","activitypub"),selected:h,options:[{label:m(s,(0,w.__)("Public","activitypub"),(0,w.__)("Post will be visible to everyone and appear in public timelines.","activitypub")),value:"public"},{label:m(u,(0,w.__)("Quiet public","activitypub"),(0,w.__)("Post will be visible to everyone but will not appear in public timelines.","activitypub")),value:"quiet_public"},{label:m(d,(0,w.__)("Do not federate","activitypub"),(0,w.__)("Post will not be shared to the Fediverse.","activitypub")),value:"local"}],onChange:t=>{_({...r,activitypub_content_visibility:t})},className:"activitypub-visibility"}),(0,c.jsx)(n.SelectControl,{label:(0,w.__)("Who can quote this post?","activitypub"),help:(0,w.__)("Quoting allows others to cite your post while adding their own commentary.","activitypub"),value:r?.activitypub_interaction_policy_quote,options:[{label:(0,w.__)("Anyone","activitypub"),value:"anyone"},{label:(0,w.__)("Followers only","activitypub"),value:"followers"},{label:(0,w.__)("Just me","activitypub"),value:"me"}],onChange:t=>{_({...r,activitypub_interaction_policy_quote:t})},__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})]})}}),(0,i.registerPlugin)("activitypub-editor-preview",{render:()=>{const e=(0,p.useSelect)(e=>e(t.store).getCurrentPost().status,[]);return(0,c.jsx)(c.Fragment,{children:t.PluginPreviewMenuItem?(0,c.jsx)(t.PluginPreviewMenuItem,{onClick:()=>{const e=(0,p.select)(t.store).getEditedPostPreviewLink(),i=(0,_.addQueryArgs)(e,{activitypub:"true"});window.open(i,"_blank")},icon:r,disabled:"auto-draft"===e,children:(0,w.__)("Fediverse preview ⁂","activitypub")}):null})}})})(); \ No newline at end of file diff --git a/integration/class-classic-editor.php b/integration/class-classic-editor.php index 00d494c2a1..fcc31f72d8 100644 --- a/integration/class-classic-editor.php +++ b/integration/class-classic-editor.php @@ -153,15 +153,15 @@ public static function render_meta_box( $post ) {





diff --git a/src/editor-plugin/__tests__/plugin.test.js b/src/editor-plugin/__tests__/plugin.test.js index 1b16d4e2b5..938596c359 100644 --- a/src/editor-plugin/__tests__/plugin.test.js +++ b/src/editor-plugin/__tests__/plugin.test.js @@ -125,3 +125,107 @@ describe( 'EditorPlugin getDefaultVisibility', () => { expect( [ 'public', 'local' ] ).toContain( result ); } ); } ); + +/** + * Tests for the visibility sync logic. + * + * The useEffect in EditorPlugin syncs the computed default visibility to meta + * when there's no stored value and the default isn't 'public'. + * We test this logic by simulating the conditions the useEffect checks. + */ +describe( 'EditorPlugin visibility sync logic', () => { + /** + * Simulates the sync logic from the useEffect hook. + * + * @param {Object} meta The meta object. + * @param {string} postDate The post date. + * @param {Function} setMetaFn The setMeta function. + */ + const simulateSyncLogic = ( meta, postDate, setMetaFn ) => { + const defaultVisibility = getDefaultVisibility( meta, postDate ); + const storedVisibility = meta?.activitypub_content_visibility; + + // This mirrors the useEffect logic in plugin.js. + // WordPress may return '' (empty string) or undefined for unset meta. + // We skip 'public' since it's the implicit default. + if ( ! storedVisibility && defaultVisibility !== 'public' ) { + setMetaFn( { ...meta, activitypub_content_visibility: defaultVisibility } ); + } + }; + + test( 'syncs local visibility for old posts without stored value', () => { + const setMeta = jest.fn(); + const meta = {}; + const postDate = new Date( Date.now() - 60 * 24 * 60 * 60 * 1000 ); // 60 days ago. + + simulateSyncLogic( meta, postDate, setMeta ); + + expect( setMeta ).toHaveBeenCalledWith( { + activitypub_content_visibility: 'local', + } ); + } ); + + test( 'does not sync for new posts with public default', () => { + const setMeta = jest.fn(); + const meta = {}; + const postDate = new Date(); // Now. + + simulateSyncLogic( meta, postDate, setMeta ); + + // Public is the implicit default, no sync needed. + expect( setMeta ).not.toHaveBeenCalled(); + } ); + + test( 'does not sync when visibility is already stored', () => { + const setMeta = jest.fn(); + const meta = { activitypub_content_visibility: 'quiet_public' }; + const postDate = new Date( Date.now() - 60 * 24 * 60 * 60 * 1000 ); // 60 days ago. + + simulateSyncLogic( meta, postDate, setMeta ); + + expect( setMeta ).not.toHaveBeenCalled(); + } ); + + test( 'syncs when stored value is empty string and default is not public', () => { + const setMeta = jest.fn(); + // Empty string means unset - sync if default differs from public. + const meta = { activitypub_content_visibility: '' }; + const postDate = new Date( Date.now() - 60 * 24 * 60 * 60 * 1000 ); // 60 days ago. + + simulateSyncLogic( meta, postDate, setMeta ); + + // Old post defaults to local, so we sync. + expect( setMeta ).toHaveBeenCalledWith( { + activitypub_content_visibility: 'local', + } ); + } ); + + test( 'does not sync when stored value is empty string and default is public', () => { + const setMeta = jest.fn(); + // Empty string stored, default is public = no sync needed. + const meta = { activitypub_content_visibility: '' }; + const postDate = new Date(); // Now - defaults to public. + + simulateSyncLogic( meta, postDate, setMeta ); + + // Default is public, no sync needed. + expect( setMeta ).not.toHaveBeenCalled(); + } ); + + test( 'preserves existing meta fields when syncing', () => { + const setMeta = jest.fn(); + const meta = { + activitypub_content_warning: 'some warning', + activitypub_max_image_attachments: 5, + }; + const postDate = new Date( Date.now() - 60 * 24 * 60 * 60 * 1000 ); // 60 days ago. + + simulateSyncLogic( meta, postDate, setMeta ); + + expect( setMeta ).toHaveBeenCalledWith( { + activitypub_content_warning: 'some warning', + activitypub_max_image_attachments: 5, + activitypub_content_visibility: 'local', + } ); + } ); +} ); diff --git a/src/editor-plugin/plugin.js b/src/editor-plugin/plugin.js index 54be4d1142..8e2d35b553 100644 --- a/src/editor-plugin/plugin.js +++ b/src/editor-plugin/plugin.js @@ -12,6 +12,7 @@ import { import { Icon, globe, people, external } from '@wordpress/icons'; import { useSelect, select } from '@wordpress/data'; import { useEntityProp } from '@wordpress/core-data'; +import { useEffect } from '@wordpress/element'; import { addQueryArgs } from '@wordpress/url'; import { __ } from '@wordpress/i18n'; import { SVG, Path } from '@wordpress/primitives'; @@ -27,6 +28,22 @@ const EditorPlugin = () => { const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' ); const postDate = useSelect( ( selectFn ) => selectFn( editorStore ).getCurrentPost().date, [] ); + // Get the computed default visibility. + const defaultVisibility = getDefaultVisibility( meta, postDate ); + + // Sync computed default to meta when it differs from stored value. + // This ensures the default is persisted even if user doesn't change it. + useEffect( () => { + const storedVisibility = meta?.activitypub_content_visibility; + + // Only sync if visibility was never set and the default isn't 'public'. + // WordPress may return '' (empty string) or undefined for unset meta. + // We skip 'public' since it's the implicit default. + if ( ! storedVisibility && defaultVisibility !== 'public' ) { + setMeta( { ...meta, activitypub_content_visibility: defaultVisibility } ); + } + }, [ defaultVisibility, meta, setMeta ] ); + // Don't show when editing sync blocks. if ( 'wp_block' === postType ) { return null; @@ -124,7 +141,7 @@ const EditorPlugin = () => { "This adjusts the visibility of a post in the fediverse, but note that it won't affect how the post appears on the blog.", 'activitypub' ) } - selected={ getDefaultVisibility( meta, postDate ) } + selected={ defaultVisibility } options={ [ { label: enhancedLabel( diff --git a/src/editor-plugin/utils.js b/src/editor-plugin/utils.js index 078d5f31ed..d973b841af 100644 --- a/src/editor-plugin/utils.js +++ b/src/editor-plugin/utils.js @@ -1,6 +1,10 @@ /** * Calculates the default visibility for a post based on its metadata and age. * + * Note: JS uses 'public' as the value, while PHP uses '' (empty string). + * PHP's get_content_visibility() treats any value not in ['quiet_public', 'private', 'local'] + * as public, so 'public' works correctly. + * * Priority order: * 1. Explicitly set visibility value * 2. Federated posts default to public @@ -13,7 +17,7 @@ * @return {string} The default visibility value ('public', 'quiet_public', or 'local'). */ export const getDefaultVisibility = ( meta, postDate ) => { - // If already set, use that value. + // If already set, use that value (handles both 'public' and '' as public). if ( meta?.activitypub_content_visibility ) { return meta.activitypub_content_visibility; }