PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 2.1.9
bBlocks – Essential Gutenberg Blocks & Patterns Collection v2.1.9
2.1.9 2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 All 109 releases
b-blocks / build / woo-product-grid / render.php

render.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 2.1.9, at build/woo-product-grid/render.php

75 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use BBlocks\Inc\Blocks\WooProductGrid;
4 use BBlocks\Inc\Sanitize;
5
6 if ( ! class_exists( WooProductGrid::class ) ) {
7 return;
8 }
9
10 $id = wp_unique_id( 'bBlocksWooProductGrid-' );
11
12 $currentId = get_the_ID();
13 if ( $currentId && 'product' === get_post_type( $currentId ) ) {
14 $attributes['query']['currentProductId'] = (int) $currentId;
15 }
16
17 if ( ! function_exists( 'wc_get_product' ) ) {
18 if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) ) {
19 return;
20 }
21
22 $installUrl = WooProductGrid::wooInstallUrl();
23
24 $linkOpen = $installUrl ? '<a href="' . esc_url( $installUrl ) . '" target="_blank" rel="noreferrer noopener">' : '<strong>';
25 $linkClose = $installUrl ? '</a>' : '</strong>';
26
27 $message = __( 'WooCommerce is not installed/activated on your site. Please install and activate <a>WooCommerce</a> first.', 'b-blocks' );
28 $message = str_replace( [ '<a>', '</a>' ], [ $linkOpen, $linkClose ], $message );
29 ?>
30 <div
31 <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped. ?>
32 <?php echo get_block_wrapper_attributes(); ?>
33 >
34 <p class='b-blocks-woo-product-grid-notice'>
35 <?php
36 echo wp_kses(
37 $message,
38 [
39 'a' => [ 'href' => [], 'target' => [], 'rel' => [] ],
40 'strong' => [],
41 ]
42 );
43 ?>
44 </p>
45 </div>
46 <?php
47 return;
48 }
49
50 $a = WooProductGrid::resolveAttributes( $attributes );
51
52 $attributes = Sanitize::attributes( WooProductGrid::viewAttributes( $attributes, $a ) );
53
54 if ( wp_script_is( 'wc-add-to-cart', 'registered' ) ) {
55 wp_enqueue_script( 'wc-add-to-cart' );
56 }
57
58 $firstData = WooProductGrid::getProducts( $a, 0, 1 );
59 $firstData['terms'] = WooProductGrid::filterTerms( $a );
60 $firstData['labels'] = WooProductGrid::labels();
61 $firstData = Sanitize::attributes( $firstData );
62
63 wp_reset_postdata();
64
65 ?>
66 <div
67 <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped. ?>
68 <?php echo get_block_wrapper_attributes(); ?>
69 id='<?php echo esc_attr( $id ); ?>'
70 data-attributes='<?php echo esc_attr( wp_json_encode( $attributes ) ); ?>'
71 data-nonce='<?php echo esc_attr( wp_json_encode( wp_create_nonce( 'wp_ajax' ) ) ); ?>'
72 data-ajax-url='<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>'
73 data-first-products='<?php echo esc_attr( wp_json_encode( $firstData ) ); ?>'
74 data-bblocks-advanced='<?php echo esc_attr( wp_json_encode( $attributes['advanced'] ?? [] ) ); ?>'
75 ></div>