Commit 91310327 authored by hayashiryota's avatar hayashiryota

init

parents
<?php
/**
* Plugin Name: My Note Plugin
* Version: 0.1
*/
add_action( 'init', function() {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
$dir = dirname( __FILE__ );
$index_js = 'note-block/index.js';
wp_register_script(
'note-block-block-editor',
plugins_url( $index_js, __FILE__ ),
array(
'wp-blocks',
'wp-element',
),
filemtime( "$dir/$index_js" )
);
$editor_css = 'note-block/editor.css';
wp_register_style(
'note-block-block-editor',
plugins_url( $editor_css, __FILE__ ),
array(),
filemtime( "$dir/$editor_css" )
);
$style_css = 'note-block/style.css';
wp_register_style(
'note-block-block',
plugins_url( $style_css, __FILE__ ),
array(),
filemtime( "$dir/$style_css" )
);
register_block_type( 'my-note-plugin/note-block', array(
'editor_script' => 'note-block-block-editor',
'editor_style' => 'note-block-block-editor',
'style' => 'note-block-block',
) );
} );
\ No newline at end of file
.edit-post-visual-editor .wp-block-my-note-plugin-note-block__heading {
color: white;
}
\ No newline at end of file
( function ( wp ) {
var el = wp.element.createElement;
var name = 'wp-block-my-note-plugin-note-block';
function createEditElement( props ) {
return el(
'div', {
className: name
}, [
el(
wp.editor.RichText, {
tagName: 'p',
className: name + '__heading',
value: props.attributes.heading,
onChange: function( heading ) {
props.setAttributes( { heading: heading } );
}
}
),
el(
wp.editor.RichText, {
tagName: 'div',
className: name + '__content',
value: props.attributes.content,
multiline: 'p',
onChange: function( content ) {
props.setAttributes( { content: content } );
}
}
)
]
);
}
function createSaveElement( props ) {
return el(
'div', {
}, [
el(
wp.editor.RichText.Content, {
tagName: 'p',
className: name + '__heading',
value: props.attributes.heading
}
),
el(
wp.editor.RichText.Content, {
tagName: 'div',
className: name + '__content',
value: props.attributes.content
}
)
]
);
}
wp.blocks.registerBlockType( 'my-note-plugin/note-block', {
title: '備考ブロック',
category: 'common',
attributes: {
heading: {
type: 'string',
source: 'children',
selector: 'p.' + name + '__heading',
default: 'Note'
},
content: {
type: 'array',
source: 'children',
selector: 'p.' + name + '__content'
}
},
edit: createEditElement,
save: createSaveElement
} );
} )( window.wp );
\ No newline at end of file
.wp-block-my-note-plugin-note-block {
background-color: #e8f2f9;
border: solid 1px #63a4d2;
border-radius: 3px;
font-size: 14px;
margin-bottom: 16px;
}
.wp-block-my-note-plugin-note-block__heading {
background-color: #63a4d2;
color: white;
font-weight: bold;
margin: 0;
padding: 3px 10px;
}
.wp-block-my-note-plugin-note-block__content {
padding: 8px 10px;
}
.wp-block-my-note-plugin-note-block__content p {
margin: 0 0 5px;
}
.wp-block-my-note-plugin-note-block__content p:last-child {
margin: 0;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment