Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. function duke_blocks() {
  2.  
  3. wp_register_script(
  4. 'wb-blocks-js',
  5. get_template_directory_uri() . '/inc/meta-block.js',
  6. array( 'wp-blocks', 'wp-editor', 'wp-element','wp-components' )
  7. );
  8. register_block_type( 'dukeyin/audio-url', array(
  9. 'editor_script' => 'wb-blocks-js',
  10. ) );
  11.  
  12. }
  13. add_action( 'init', 'duke_blocks' );
  14.  
  15. function duke_register_block_meta() {
  16.  
  17. register_meta( 'post', 'audio-url', array(
  18. 'show_in_rest' => true,
  19. 'single' => true,
  20. 'type' => 'string',
  21. 'object_subtype' => 'audio',
  22. ) );
  23.  
  24. }
  25.  
  26. add_action( 'init', 'duke_register_block_meta' );
  27.  
  28. ( function( wp ) {
  29. var el = wp.element.createElement;
  30. var registerBlockType = wp.blocks.registerBlockType;
  31. var TextControl = wp.components.TextControl;
  32.  
  33. registerBlockType( 'dukeyin/audio-url', {
  34. title: 'Audio file URL',
  35. icon: 'media-audio',
  36. category: 'layout',
  37. attributes: {
  38. blockValue: {
  39. type: 'string',
  40. source: 'meta',
  41. meta: 'audio-url',
  42. }
  43. },
  44.  
  45. edit: function( props ) {
  46. var setAttributes = props.setAttributes;
  47.  
  48. function updateBlockValue( blockValue ) {
  49. setAttributes({ blockValue });
  50. }
  51.  
  52. return el(
  53. 'div',
  54. { className: "audio-url" },
  55. el( 'h5',{}, 'URL to audio file:'),
  56. el (TextControl,
  57. {
  58. onChange: updateBlockValue,
  59. value: props.attributes. blockValue,
  60. })
  61. );
  62. },
  63.  
  64. save: function( props ) {
  65. return null;
  66. },
  67. } );
  68. } )( window.wp );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement