Skip to content

Commit

Permalink
Check if $blocks is an array for Rank Math
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoensing committed Apr 5, 2023
1 parent 2fc1419 commit f584538
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: SimpleTOC - Table of Contents Block
* Plugin URI: https://marc.tv/simpletoc-wordpress-inhaltsverzeichnis-plugin-gutenberg/
* Description: SEO-friendly Table of Contents Gutenberg block. No JavaScript and no CSS means faster loading.
* Version: 6.0.1
* Version: 6.0.2
* Author: Marc Tönsing
* Author URI: https://marc.tv
* Text Domain: simpletoc
Expand Down Expand Up @@ -248,6 +248,10 @@ function simpletoc_add_pagenumber($blocks, $headings)
{
$pages = 1;

if (!is_array($blocks)) {
return $headings;
}

foreach ($blocks as $block => $innerBlock) {
// count nextpage blocks
if (isset($blocks[$block]['blockName']) && $blocks[$block]['blockName'] === 'core/nextpage') {
Expand Down Expand Up @@ -275,6 +279,11 @@ function simpletoc_add_pagenumber($blocks, $headings)
function filter_headings_recursive($blocks)
{
$arr = [];

if (!is_array($blocks)) {
return $arr;
}

// allow developers to ignore specific blocks
$ignored_blocks = apply_filters('simpletoc_excluded_blocks', []);

Expand Down Expand Up @@ -684,7 +693,7 @@ function extract_id($headline)
function get_page_number_from_headline($headline)
{
$dom = new \DOMDocument();

@$dom->loadHTML('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $headline, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

$xpath = new \DOMXPath($dom);
Expand Down
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: Gutenberg, block, TOC, Table of Contents, AMP
Requires at least: 5.9
Donate link: https://marc.tv/out/donate
Tested up to: 6.2
Stable tag: 6.0.1
Stable tag: 6.0.2
Requires PHP: 7.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -50,8 +50,8 @@ SimpleTOC is open-source and developed on [GitHub Pages](https://github.com/mtoe

== Changelog ==

= 6.0.1 =
* Fix: "Update failed" with error 500 when Rank Math is installed.
= 6.0.2 =
* Fix: "Update failed" with error 500 when Rank Math is installed.

= 6.0.0 =
* Feature: Added SimpleTOC global settings to override individual block configuration.
Expand Down

0 comments on commit f584538

Please sign in to comment.