Block.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\Dashboard\DashboardTab; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\BaseBlock; |
| 6 | |
| 7 | /** |
| 8 | * Checkout block |
| 9 | */ |
| 10 | class Block extends BaseBlock { |
| 11 | /** |
| 12 | * Render the block |
| 13 | * |
| 14 | * @param array $attributes Block attributes. |
| 15 | * @param string $content Post content. |
| 16 | * |
| 17 | * @return void |
| 18 | */ |
| 19 | public function render( $attributes, $content ) { |
| 20 | // we need a panel name. |
| 21 | if ( empty( $attributes['panel'] ) ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | // get the current page tab and possible id. |
| 26 | $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; |
| 27 | |
| 28 | return \SureCart::block()->render( |
| 29 | 'blocks/dashboard-tab', |
| 30 | [ |
| 31 | 'active' => $tab === $attributes['panel'] ? 'true' : 'false', |
| 32 | 'title' => $attributes['title'] ?? '', |
| 33 | 'icon' => $attributes['icon'] ?? 'home', |
| 34 | 'href' => esc_url( add_query_arg( [ 'tab' => sanitize_title( $attributes['panel'] ) ], remove_query_arg( array_keys( $_GET ) ) ) ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 35 | ] |
| 36 | ); |
| 37 | } |
| 38 | } |
| 39 |