Skip to content

Commit

Permalink
Merge pull request #435 from verdigado/fix-357
Browse files Browse the repository at this point in the history
Avoid iterate over undefined list
  • Loading branch information
albig committed Nov 10, 2023
2 parents 062382c + 075eda3 commit 54dc3ed
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/latest-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ToggleControl,
SelectControl
} from '@wordpress/components';

registerBlockType( 'sunflower/latest-posts', {
apiVersion: 2,
title: 'Neueste Beiträge (Sunflower)',
Expand All @@ -27,7 +27,7 @@ registerBlockType( 'sunflower/latest-posts', {
default: ''
},
},

edit: (props) => {
const blockProps = useBlockProps();

Expand All @@ -41,13 +41,13 @@ registerBlockType( 'sunflower/latest-posts', {

const get_wp_categories = ( input ) => {
let categories = new Array();
wp.data.select('core').getEntityRecords('taxonomy', 'category').forEach(element => {
wp.data.select('core').getEntityRecords('taxonomy', 'category')?.forEach(element => {
categories.push( element.slug );
});

return categories;
};

const onChangeCategories = ( input ) => {
props.setAttributes( { categories: input === undefined ? '' : input } );
};
Expand All @@ -67,12 +67,12 @@ registerBlockType( 'sunflower/latest-posts', {

return (
<div { ...blockProps }>
{
<span>
Zeige die neuesten Beiträge an. Titel, Kategorien und Anzahl kannst Du rechts einstellen.
Hier klicken für eine Liste aller Kategorien.
{
<span>
Zeige die neuesten Beiträge an. Titel, Kategorien und Anzahl kannst Du rechts einstellen.
Hier klicken für eine Liste aller Kategorien.
<ul>
{get_wp_categories().map((category, i) => {
{get_wp_categories().map((category, i) => {
return(<li>{category}</li>);
})}
</ul>
Expand Down Expand Up @@ -104,11 +104,11 @@ registerBlockType( 'sunflower/latest-posts', {
onChange={ onChangeCount }
/>
</PanelBody>

</InspectorControls>
}
</div>
)

},
} )

0 comments on commit 54dc3ed

Please sign in to comment.