Created
April 14, 2022 12:44
-
-
Save Mamaduka/8c2c4f307b6ddfa59659c34f0c750c66 to your computer and use it in GitHub Desktop.
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
/** | |
* WordPress dependencies | |
*/ | |
import { registerPlugin } from '@wordpress/plugins'; | |
import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; | |
import { TextControl } from '@wordpress/components'; | |
import { useEntityProp } from '@wordpress/core-data'; | |
function SocialSettings() { | |
const [ links, setLinks ] = useEntityProp( 'root', 'site', 'social_links' ); | |
return ( | |
<PluginDocumentSettingPanel className="social-settings" title="Social"> | |
<TextControl | |
value={ links?.twitter ?? '' } | |
placeholder="Twitter" | |
onChange={ ( newValue ) => { | |
setLinks( { | |
...links, | |
twitter: newValue | |
} ); | |
} } | |
/> | |
<TextControl | |
value={ links?.github ?? '' } | |
placeholder="Github" | |
onChange={ ( newValue ) => { | |
setLinks( { | |
...links, | |
github: newValue | |
} ); | |
} } | |
/> | |
</PluginDocumentSettingPanel> | |
); | |
} | |
registerPlugin( 'social-settings-test', { render: SocialSettings } ); |
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
<?php | |
add_action( 'rest_api_init', function() { | |
register_setting( | |
'general', | |
'social_links', | |
array( | |
'type' => 'object', | |
'description' => 'Social Links', | |
'default' => array( | |
'twitter' => 'https://twitter.com', | |
'github' => 'https://github.com', | |
), | |
'show_in_rest' => array( | |
'schema' => array( | |
'type' => 'object', | |
'properties' => array( | |
'twitter' => array( | |
'type' => 'string', | |
), | |
'github' => array( | |
'type' => 'string', | |
), | |
), | |
), | |
), | |
) | |
); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment