Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
hacklab-blocks
Commits
5adb698d
Commit
5adb698d
authored
1 year ago
by
Filipe B. de Souza
Browse files
Options
Download
Email Patches
Plain Diff
create new block co-authores meta
parent
e25e1cf8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
220 additions
and
1 deletion
+220
-1
blocks/co-authors-meta/block.json
blocks/co-authors-meta/block.json
+22
-0
blocks/co-authors-meta/co-authors-meta.php
blocks/co-authors-meta/co-authors-meta.php
+52
-0
blocks/co-authors-meta/edit.js
blocks/co-authors-meta/edit.js
+67
-0
blocks/co-authors-meta/editor.scss
blocks/co-authors-meta/editor.scss
+9
-0
blocks/co-authors-meta/index.js
blocks/co-authors-meta/index.js
+40
-0
blocks/co-authors-meta/save.js
blocks/co-authors-meta/save.js
+23
-0
blocks/co-authors-meta/style.scss
blocks/co-authors-meta/style.scss
+3
-0
hacklab-blocks.php
hacklab-blocks.php
+4
-1
No files found.
blocks/co-authors-meta/block.json
0 → 100755
View file @
5adb698d
{
"$schema"
:
"https://schemas.wp.org/trunk/block.json"
,
"apiVersion"
:
2
,
"version"
:
"0.1.0"
,
"name"
:
"hacklab-blocks/co-authors-meta"
,
"title"
:
"Co-authors Meta"
,
"category"
:
"theme"
,
"icon"
:
"admin-post"
,
"description"
:
"Add metadata of the co-authors plugin."
,
"keywords"
:
[
"postlist"
,
"publicações"
],
"textdomain"
:
"hacklab-blocks"
,
"editorScript"
:
"file:../../build/js/co-authors-meta-index/co-authors-meta-index.js"
,
"attributes"
:
{
"prefix"
:
{
"type"
:
"string"
}
},
"usesContext"
:
[
"postId"
,
"postType"
],
"supports"
:
{
"html"
:
false
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/co-authors-meta/co-authors-meta.php
0 → 100644
View file @
5adb698d
<?php
namespace
hacklabBlocks
;
/**
* Server-side rendering of the `hacklab-blocks/post-meta` block.
*
* @package WordPress
*/
/**
* Renders the `hacklab-blocks/post-meta` block on the server.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
* @return string Returns the filtered post terms for the current post wrapped inside "a" tags.
*/
function
co_authors_meta_callback
(
$attributes
,
$content
,
$block
)
{
if
(
!
isset
(
$block
->
context
[
'postId'
]))
{
return
''
;
}
if
(
!
class_exists
(
'CoAuthors_Plus'
)
){
return
''
;
}
$post_id
=
$block
->
context
[
'postId'
];
$coauthors
=
get_coauthors
(
$post_id
);
$prefix
=
isset
(
$attributes
[
'prefix'
]
)
?
$attributes
[
'prefix'
]
:
''
;
$html
=
''
;
$html
.
=
'<span class="co-authors-meta-block">'
;
if
(
$prefix
){
$html
.
=
'<span class="prefix">'
;
$html
.
=
esc_html
(
$prefix
);
$html
.
=
'</span>'
;
}
foreach
(
$coauthors
as
$coauthor
){
$html
.
=
$coauthor
->
display_name
;
$html
.
=
' '
;
}
$html
.
=
'</span>'
;
return
$html
;
}
This diff is collapsed.
Click to expand it.
blocks/co-authors-meta/edit.js
0 → 100755
View file @
5adb698d
/**
* External dependencies
*/
import
classnames
from
'
classnames
'
;
import
{
unescape
}
from
'
lodash
'
;
import
ServerSideRender
from
'
@wordpress/server-side-render
'
;
/**
* WordPress dependencies
*/
import
{
InspectorControls
,
BlockControls
,
useBlockProps
,
}
from
'
@wordpress/block-editor
'
;
import
{
TextControl
,
Panel
,
PanelBody
,
FormTokenField
}
from
'
@wordpress/components
'
;
import
{
__
}
from
'
@wordpress/i18n
'
;
/**
* Internal dependencies
*/
export
default
function
Edit
(
props
)
{
const
attributes
=
props
.
attributes
;
const
context
=
props
.
context
;
const
setAttributes
=
props
.
setAttributes
;
const
{
prefix
}
=
attributes
;
const
{
postId
,
postType
}
=
context
;
const
hasPost
=
postId
&&
postType
;
const
blockProps
=
useBlockProps
({
className
:
classnames
({
}),
});
return
(
<
div
{
...
useBlockProps
()
}
>
<
InspectorControls
key
=
"
setting
"
>
<
Panel
>
<
PanelBody
title
=
{
__
(
'
Configurações do bloco
'
)}
>
<
TextControl
autoComplete
=
"
off
"
label
=
{
__
(
'
Prefixo
'
)}
value
=
{
prefix
||
''
}
onChange
=
{(
nextValue
)
=>
{
setAttributes
({
prefix
:
nextValue
});
}}
help
=
{
__
(
'
Adicione um prefixo antes dos autores.
'
)}
/
>
<
/PanelBody
>
<
/Panel
>
<
/InspectorControls
>
<
div
className
=
"
configBlock
"
>
<
header
><
p
>
CoAuthorsMeta
<
/p></
header
>
<
/div
>
<
/div
>
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/co-authors-meta/editor.scss
0 → 100755
View file @
5adb698d
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/
.wp-block-create-block-gutenpride
{
border
:
1px
dotted
#f00
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/co-authors-meta/index.js
0 → 100644
View file @
5adb698d
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
*/
import
{
registerBlockType
}
from
'
@wordpress/blocks
'
;
/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor. All other files
* get applied to the editor only.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import
'
./style.scss
'
;
import
'
./editor.scss
'
;
/**
* Internal dependencies
*/
import
Edit
from
'
./edit
'
;
import
save
from
'
./save
'
;
/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
*/
registerBlockType
(
'
hacklab-blocks/co-authors-meta
'
,
{
/**
* @see ./edit.js
*/
edit
:
Edit
,
/**
* @see ./save.js
*/
save
,
}
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/co-authors-meta/save.js
0 → 100755
View file @
5adb698d
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import
{
useBlockProps
}
from
'
@wordpress/block-editor
'
;
/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @param {Object} props Properties passed to the function.
* @param {Object} props.attributes Available block attributes.
* @return {WPElement} Element to render.
*/
export
default
function
save
(
{
attributes
}
)
{
const
blockProps
=
useBlockProps
.
save
();
return
<
div
{
...
blockProps
}
>
{
attributes
.
message
}
<
/div>
;
}
This diff is collapsed.
Click to expand it.
blocks/co-authors-meta/style.scss
0 → 100755
View file @
5adb698d
.wp-block-post-terms__separator
{
white-space
:
pre-wrap
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hacklab-blocks.php
View file @
5adb698d
...
...
@@ -62,6 +62,9 @@ function hacklab_blocks_init() {
'post-meta'
=>
array
(
'render_callback'
=>
'hacklabBlocks\\post_meta_callback'
,
),
'co-authors-meta'
=>
array
(
'render_callback'
=>
'hacklabBlocks\\co_authors_meta_callback'
,
),
'filter-by-taxonomy'
=>
array
(
'render_callback'
=>
'hacklabBlocks\\filter_by_taxonomy_callback'
,
),
...
...
@@ -78,7 +81,7 @@ function hacklab_blocks_init() {
foreach
(
$blocos_ativos
as
$block_name
=>
$block_args
)
{
$args
=
array
();
if
(
$block_args
){
include
$plugin_folder
.
'
/
blocks/'
.
$block_name
.
'/'
.
$block_name
.
'.php'
;
include
$plugin_folder
.
'blocks/'
.
$block_name
.
'/'
.
$block_name
.
'.php'
;
foreach
(
$block_args
as
$arg
=>
$value
)
{
$args
[
$arg
]
=
$value
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment