( function ( factory ) { if ( typeof module === 'object' && module.exports ) { module.exports = factory(); } else { factory().initialize( window.wp ); } } )( function () { 'use strict'; function getTranslator( wp ) { return wp.i18n && typeof wp.i18n.__ === 'function' ? wp.i18n.__ : function ( text ) { return text; }; } function updateMeta( editPost, currentMeta, key, value ) { if ( typeof editPost !== 'function' ) { return; } editPost( { meta: { ...( currentMeta || {} ), [ key ]: value } } ); } function hasRequiredGlobals( wp ) { return Boolean( wp && wp.components && wp.components.ToggleControl && wp.data && typeof wp.data.useDispatch === 'function' && typeof wp.data.useSelect === 'function' && wp.editPost && wp.editPost.PluginDocumentSettingPanel && wp.element && typeof wp.element.createElement === 'function' && wp.plugins && typeof wp.plugins.registerPlugin === 'function', ); } function initialize( wp ) { if ( ! hasRequiredGlobals( wp ) ) { return false; } const __ = getTranslator( wp ); function ProjectPanel() { const editorState = wp.data.useSelect( function ( select ) { if ( typeof select !== 'function' ) { return null; } const currentEditor = select( 'core/editor' ); const core = select( 'core' ); if ( ! currentEditor || typeof currentEditor.getCurrentPostType !== 'function' || typeof currentEditor.getEditedPostAttribute !== 'function' || ! core || typeof core.getEntityRecord !== 'function' ) { return null; } const topicIds = currentEditor.getEditedPostAttribute( 'topic' ); return { meta: currentEditor.getEditedPostAttribute( 'meta' ) || {}, postType: currentEditor.getCurrentPostType(), topic: Array.isArray( topicIds ) && topicIds.length === 1 ? core.getEntityRecord( 'taxonomy', 'chrnx_topic', topicIds[ 0 ] ) : null, }; }, [] ); const editorDispatch = wp.data.useDispatch( 'core/editor' ); if ( ! editorState || editorState.postType !== 'post' || ! editorDispatch?.editPost ) { return null; } if ( ! editorState.topic || editorState.topic.slug !== 'projects' ) { return null; } const meta = editorState.meta; return wp.element.createElement( wp.editPost.PluginDocumentSettingPanel, { name: 'chrnx-project', title: __( 'Project', 'chrnx' ) }, wp.element.createElement( wp.components.ToggleControl, { label: __( 'Show in Selected work', 'chrnx' ), help: __( 'Selected work lists these first, then fills the rest with the most recent projects.', 'chrnx', ), checked: Boolean( meta.chrnx_project_featured ), onChange( value ) { updateMeta( editorDispatch.editPost, meta, 'chrnx_project_featured', Boolean( value ) ); }, } ), ); } wp.plugins.registerPlugin( 'chrnx-project-meta', { render: ProjectPanel } ); return true; } return { initialize, updateMeta }; } );