| @@ -208,11 +208,20 @@ | ||
| 208 | 208 | $this->blocks[] = $block; |
| 209 | 209 | return $this; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | + /** | |
| 213 | + * @since 3.15.0 returns the block collection if block does not exist. | |
| 214 | + * @since 3.0.0 | |
| 215 | + */ | |
| 212 | 216 | public function remove($blockName) { |
| 213 | 217 | $blockCollection = $this->findByNameRecursive($blockName, 0, 'parent'); |
| 214 | 218 | $innerBlocks = $blockCollection->blocks; |
| 219 | + | |
| 220 | + if(!$innerBlocks){ | |
| 221 | + return $this; | |
| 222 | + } | |
| 223 | + | |
| 215 | 224 | $blockIndex = array_search($blockName, array_column($innerBlocks, 'name')); |
| 216 | 225 | array_splice($innerBlocks, $blockIndex, 1); |
| 217 | 226 | $blockCollection->blocks = $innerBlocks; |
| 218 | 227 | return $this; |