-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Advanced Panels: Add support for the 'Custom Fields' meta box #11084
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4098093
Advanced Panels: Add support for the 'Custom Fields' meta box
noisysocks 8e4bae5
Fix E2E tests
noisysocks d91cd88
Custom Fields: Remove unnecessary jQuery selector
noisysocks 391fbfc
Custom Fields: Use user meta field instead of site option
noisysocks cba7747
Custom Fields: Kill the process after redirecting
noisysocks 2491a18
Custom Fields: Use hidden <form> instead of redirect
noisysocks 2c11c00
Custom Fields: Rename isEnabled → isChecked
noisysocks a7d0a0c
Custom Fields: Move meta box options into their own component
noisysocks 6368b56
Custom Fields: Only show option if custom fields are supported
noisysocks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/edit-post/src/components/options-modal/meta-boxes-section.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Section from './section'; | ||
import { EnableCustomFieldsOption, EnablePanelOption } from './options'; | ||
|
||
function MetaBoxesSection( { hasCustomFieldsSupport, metaBoxes, ...sectionProps } ) { | ||
if ( ! hasCustomFieldsSupport && metaBoxes.length === 0 ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Section { ...sectionProps }> | ||
{ hasCustomFieldsSupport && ( | ||
<EnableCustomFieldsOption label={ __( 'Custom Fields' ) } /> | ||
) } | ||
{ map( | ||
metaBoxes, | ||
( { id, title } ) => | ||
// The 'Custom Fields' meta box is a special case handled above. | ||
id !== 'postcustom' && ( | ||
<EnablePanelOption key={ id } label={ title } panelName={ `meta-box-${ id }` } /> | ||
) | ||
) } | ||
</Section> | ||
); | ||
} | ||
|
||
export default withSelect( ( select ) => { | ||
const { getEditedPostAttribute } = select( 'core/editor' ); | ||
const { getPostType } = select( 'core' ); | ||
const { getAllMetaBoxes } = select( 'core/edit-post' ); | ||
|
||
const postType = getPostType( getEditedPostAttribute( 'type' ) ); | ||
return { | ||
hasCustomFieldsSupport: postType.supports[ 'custom-fields' ], | ||
metaBoxes: getAllMetaBoxes(), | ||
}; | ||
} )( MetaBoxesSection ); |
85 changes: 0 additions & 85 deletions
85
packages/edit-post/src/components/options-modal/options.js
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
packages/edit-post/src/components/options-modal/options/base.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { CheckboxControl } from '@wordpress/components'; | ||
|
||
function BaseOption( { label, isChecked, onChange } ) { | ||
return ( | ||
<CheckboxControl | ||
className="edit-post-options-modal__option" | ||
label={ label } | ||
checked={ isChecked } | ||
onChange={ onChange } | ||
/> | ||
); | ||
} | ||
|
||
export default BaseOption; |
36 changes: 36 additions & 0 deletions
36
packages/edit-post/src/components/options-modal/options/deferred.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BaseOption from './base'; | ||
|
||
class DeferredOption extends Component { | ||
constructor( { isChecked } ) { | ||
super( ...arguments ); | ||
this.state = { | ||
isChecked, | ||
}; | ||
} | ||
|
||
componentWillUnmount() { | ||
if ( this.state.isChecked !== this.props.isChecked ) { | ||
this.props.onChange( this.state.isChecked ); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<BaseOption | ||
label={ this.props.label } | ||
isChecked={ this.state.isChecked } | ||
onChange={ ( isChecked ) => this.setState( { isChecked } ) } | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default DeferredOption; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works!
Should I be seeing that error message though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw the error mentioned for other meta boxes elsewhere. I wonder if it's a more generic bug in 5.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you get this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bug in 5.0, fixed now.