Skip to content

Commit

Permalink
Stopping Output of Row or Widget Filters
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGStapleton committed Nov 14, 2022
1 parent 8c16547 commit 49ad696
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions page-builder/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Page Builder Features and Actions](hooks/builder-features-actions.md)
- [Override Row Collapse Point](hooks/override-row-collapse-point.md)
- [Row Form](hooks/row-form.md)
- [Row & Widget Output Filters](hooks/stopping-output-of-row-widget.md)
- [Widget Form](hooks/widget-form.md)
- [Widget Instance](hooks/widget-instance.md)

Expand Down
1 change: 1 addition & 0 deletions page-builder/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
- [Filtering HTML Structure](hooks/html.md).
- [Overriding Row Collapse Point](hooks/override-row-collapse-point.md)
- [Filtering Row Form](hooks/row-form.md).
- [Row & Widget Output Filters](hooks/stopping-output-of-row-widget.md)
- [Filtering Widget Form](hooks/widget-form.md).
- [Filtering Widget Instance](hooks/widget-instance.md).
47 changes: 47 additions & 0 deletions page-builder/hooks/stopping-output-of-row-widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Stopping Output of Row or Widget
There are situations where you may wish to stop the output of a row or widget, and you can do this using the `siteorigin_panels_output_row` and `siteorigin_panels_output_widget` filters. While it's possible to remove them using other methods (such as filtering the panels_data array), those methods will require additional adjustments to account for Page Builder CSS to prevent ID mismatches.

### Filter: siteorigin_panels_output_row
This filter has the following arguments:

* `$output` controls whether to output the row. Default is true.
* `$row` is the current row instance.
* `$ri` is the Page Builder ID of the current row. Please note that this is a zero-based index. This means that instead of starting at 1, the first item ID is 0.
* `$post_id` the post ID of the current post.

The following snippet will prevent the output of a row when the Row Label is set to `test`.

```php
add_filter( 'siteorigin_panels_output_row', function( $output, $row, $ri, $panels_data, $post_id ) {
if ( ! empty( $row['label'] ) && $row['label'] == 'test' ) {
$output = false;
}

return $output;
}, 10, 5 );
```

### Filter: siteorigin_panels_output_widget
This filter has the following arguments:

* `$output` controls whether to output the row. Default is true.
* `$widget` is the current widget instance.
* `$ri` is the Page Builder ID of the current row.
* `$ci` is the Page Builder ID of the current cell.
* `$wi` is the Page Builder ID of the current widget.
* `$panels_data` the data of the currently rendering layout.
* `$post_id` the post ID of the current post.

Please note that Page Builder IDs have a zero-based index. This means that instead of starting at 1, the first item is already 0.

The following snippet will prevent the output of the Archive widget.

```php
add_filter( 'siteorigin_panels_output_widget', function( $output, $widget, $ri, $ci, $wi, $panels_data, $post_id ) {
if ( $widget['panels_info']['panels_info'] == 'WP_Widget_Archives' ) {
$output = false;
}

return $output;
}, 10, 7 );
```

0 comments on commit 49ad696

Please sign in to comment.