Last active
September 22, 2019 14:04
-
-
Save vanaf1979/c2099252e1693356bd0bb309cbd9516d to your computer and use it in GitHub Desktop.
Gist for my tutorial: Building a Gutenberg sidebar plugin Part 4: Adding form components. https://vanaf1979.nl/building-a-gutenberg-sidebar-plugin-part-4-adding-form-components/
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
/** | |
* External dependencies. | |
*/ | |
import React from 'react' | |
/** | |
* WordPress dependencies. | |
*/ | |
const { __ } = wp.i18n; | |
const { compose } = wp.compose; | |
const { withDispatch, withSelect } = wp.data; | |
const { RadioControl } = wp.components; | |
/** | |
* Meta robots input component. | |
* | |
* @since 1.0.0 | |
*/ | |
class MetaRobotsField extends React.Component { | |
constructor() { | |
super() | |
} | |
render() { | |
return ( | |
<div className="metatags-browser-title-field"> | |
<RadioControl | |
label={__("Robots", "metatags")} | |
selected={ this.props.metaFieldValue ? this.props.metaFieldValue : 'index, follow' } | |
options={ [ | |
{ label: 'Index, Follow', value: 'index, follow' }, | |
{ label: 'Index, NoFollow', value: 'index, nofollow' }, | |
{ label: 'NoIndex, NoFollow', value: 'noindex, nofollow' }, | |
{ label: 'NoIndex, Follow', value: 'noindex, follow' }, | |
] } | |
onChange={this.props.setMetaFieldValue} | |
/> | |
</div> | |
) | |
} | |
} | |
export default compose([ | |
withDispatch(( dispatch , props ) => { | |
return { | |
setMetaFieldValue: function( value ) { | |
dispatch( 'core/editor' ).editPost( { meta: { metatags_robots_field: value } } ); | |
} | |
} | |
}), | |
withSelect(( select , props ) => { | |
return { | |
metaFieldValue: select( 'core/editor' ).getEditedPostAttribute( 'meta' )[ 'metatags_robots_field' ], | |
}; | |
}), | |
])( MetaRobotsField ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment