Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoensing committed Feb 8, 2022
1 parent c75ebc8 commit 33f182a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 19 deletions.
8 changes: 4 additions & 4 deletions block.json → build/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/block.json",
"apiVersion": 2,
"name": "lastcommentedposts/list",
"version": "0.1.1",
"version": "1.9.0",
"title": "Last Commented Posts",
"category": "layout",
"keywords": [ "Last Commented", "Latest Comments", "Recent Comments" ],
Expand All @@ -18,7 +18,7 @@
"align": [ "wide" , "full"]
},
"textdomain": "lastcommentedposts",
"editorScript": "file:./build/index.js",
"style": "file:./build/style-index.css",
"editorStyle": "file:./build/index.css"
"editorScript": "file:index.js",
"style": "file:style-index.css",
"editorStyle": "file:index.css"
}
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-server-side-render'), 'version' => '9f59c03c79eb45e3ba383480f45ea2fc');
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-server-side-render'), 'version' => 'c45f7cf4d5180e3afccc5c6e9ac8fc94');
2 changes: 1 addition & 1 deletion build/index.js

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

14 changes: 7 additions & 7 deletions last-commented-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function init() {
*/

function register_block() {
register_block_type(plugin_dir_path(__FILE__), [
register_block_type(__DIR__ . '/build', [
'render_callback' => __NAMESPACE__ . '\\render_callback'
]);
}
Expand Down Expand Up @@ -116,16 +116,16 @@ function query_posts_with_recent_comments($limit)
function format_last_commented_list( $results , $attributes)
{

$align = $attributes['align'];
$icon = '<svg style="height: 0.75em; padding-right: 4px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect x="0" fill="none" width="20" height="20"/><g><path d="M10 9.25c-2.27 0-2.73-3.44-2.73-3.44C7 4.02 7.82 2 9.97 2c2.16 0 2.98 2.02 2.71 3.81 0 0-.41 3.44-2.68 3.44zm0 2.57L12.72 10c2.39 0 4.52 2.33 4.52 4.53v2.49s-3.65 1.13-7.24 1.13c-3.65 0-7.24-1.13-7.24-1.13v-2.49c0-2.25 1.94-4.48 4.47-4.48z"/></g></svg>';
$alignclass = '';
$is_backend = defined('REST_REQUEST') && true === REST_REQUEST && 'edit' === filter_input(INPUT_GET, 'context', FILTER_SANITIZE_STRING);


if ($align != '') {
if ( isset ($attributes['align']) ) {
$align = $attributes['align'];
$alignclass = 'align' . $align;
}

$icon = '<svg style="height: 0.75em; padding-right: 4px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect x="0" fill="none" width="20" height="20"/><g><path d="M10 9.25c-2.27 0-2.73-3.44-2.73-3.44C7 4.02 7.82 2 9.97 2c2.16 0 2.98 2.02 2.71 3.81 0 0-.41 3.44-2.68 3.44zm0 2.57L12.72 10c2.39 0 4.52 2.33 4.52 4.53v2.49s-3.65 1.13-7.24 1.13c-3.65 0-7.24-1.13-7.24-1.13v-2.49c0-2.25 1.94-4.48 4.47-4.48z"/></g></svg>';

$is_backend = defined('REST_REQUEST') && true === REST_REQUEST && 'edit' === filter_input(INPUT_GET, 'context', FILTER_SANITIZE_STRING);

$html = '<ol class="wp-block-last-commented-posts ' . $alignclass . ' ">';

foreach ($results as $result) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lastcommentposts",
"version": "1.0.0",
"version": "1.9.0",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: Gutenberg, block, comments,
Requires at least: 5.0
Donate link: https://marc.tv/out/donate
Tested up to: 5.8
Stable tag: 1.8
Stable tag: 1.9
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -23,7 +23,7 @@ In Gutenberg, add a block and search for "Last Commented Posts". Please save you

== Changelog ==

= 1.8 =
= 1.9 =
new coding standards
added aligment options
localisation
Expand Down
24 changes: 24 additions & 0 deletions src/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/block.json",
"apiVersion": 2,
"name": "lastcommentedposts/list",
"version": "1.9.0",
"title": "Last Commented Posts",
"category": "layout",
"keywords": [ "Last Commented", "Latest Comments", "Recent Comments" ],
"icon": "editor-ol",
"description": "Adds a block that lists the recent commented posts without duplicates.",
"attributes": {
"max_level": {
"type": "integer",
"default": 5
}
},
"supports": {
"align": [ "wide" , "full"]
},
"textdomain": "lastcommentedposts",
"editorScript": "file:index.js",
"style": "file:style-index.css",
"editorStyle": "file:index.css"
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import metadata from './block.json';

/**
* Internal dependencies
Expand All @@ -16,7 +16,7 @@ import { registerBlockType } from '@wordpress/blocks';
*/
import './style.scss';

registerBlockType('lastcommentedposts/list', {
registerBlockType(metadata, {
/**
* @see ./edit.js
*/
Expand Down
1 change: 0 additions & 1 deletion src/save.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { __ } from '@wordpress/i18n';

/**
* The save function defines the way in which the different attributes should
Expand Down

0 comments on commit 33f182a

Please sign in to comment.