Skip to content

Commit

Permalink
Updated top-10/popular-posts block to API version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaydsouza committed Jun 30, 2024
1 parent 56dcbc2 commit e543690
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 7 deletions.
78 changes: 78 additions & 0 deletions includes/frontend/blocks/build/popular-posts/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "top-10/popular-posts",
"version": "2.0.0",
"title": "Top 10 Popular Posts",
"category": "widgets",
"icon": "editor-ol",
"keywords": [
"top 10",
"popular posts",
"popular"
],
"description": "Display the Popular Posts",
"supports": {
"html": false
},
"attributes": {
"className": {
"type": "string",
"default": ""
},
"heading": {
"type": "boolean",
"default": true
},
"daily": {
"type": "boolean",
"default": false
},
"daily_range": {
"type": "string",
"default": 1
},
"hour_range": {
"type": "string",
"default": 0
},
"limit": {
"type": "string",
"default": 6
},
"offset": {
"type": "string",
"default": 0
},
"show_excerpt": {
"type": "boolean",
"default": false
},
"show_author": {
"type": "boolean",
"default": false
},
"show_date": {
"type": "boolean",
"default": false
},
"disp_list_count": {
"type": "boolean",
"default": false
},
"tptn_styles": {
"type": "string",
"default": "no_style"
},
"post_thumb_op": {
"type": "string",
"default": "text_only"
},
"other_attributes": {
"type": "string",
"default": ""
}
},
"textdomain": "top-10",
"editorScript": "file:./index.js"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-server-side-render'), 'version' => 'adff22f37f9d1ccaae4d');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-server-side-render'), 'version' => 'da3f23b1e50b8a6a8870');
1 change: 1 addition & 0 deletions includes/frontend/blocks/build/popular-posts/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions includes/frontend/blocks/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function __construct() {
*/
public function register_blocks() {
// Register Popular Posts block.
register_block_type_from_metadata(
TOP_TEN_PLUGIN_DIR . 'includes/frontend/blocks/popular-posts/',
register_block_type(
__DIR__ . '/build/popular-posts/',
array(
'render_callback' => array( __CLASS__, 'render_block' ),
)
Expand Down
1 change: 0 additions & 1 deletion includes/frontend/blocks/popular-posts/build/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"apiVersion": 3,
"name": "top-10/popular-posts",
"version": "2.0.0",
"title": "Top 10 Popular Posts",
Expand Down Expand Up @@ -70,5 +70,5 @@
}
},
"textdomain": "top-10",
"editorScript": "file:./build/index.js"
"editorScript": "file:./index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ import { registerBlockType } from '@wordpress/blocks';
*/
import Edit from './edit';

/**
* Import metadata
*/
import metadata from './block.json';

/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType( 'top-10/popular-posts', {
registerBlockType( metadata.name , {
/**
* @see ./edit.js
*/
Expand Down

0 comments on commit e543690

Please sign in to comment.