PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.0
Jetpack – WP Security, Backup, Speed, & Growth v16.0
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / extensions / blocks / tock / render.php

render.php in Jetpack – WP Security, Backup, Speed, & Growth 16.0, at extensions/blocks/tock/render.php

58 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Tock block render implementation.
4 *
5 * Loaded lazily from tock.php only when the block is rendered, to keep
6 * the render body out of the eager front-end PHP/opcache footprint.
7 *
8 * @package automattic/jetpack
9 */
10
11 namespace Automattic\Jetpack\Extensions\Tock;
12
13 use Automattic\Jetpack\Blocks;
14 use Jetpack_Gutenberg;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 0 );
18 }
19
20 /**
21 * Render the widget and associated JS
22 *
23 * @param array $attr The block attributes.
24 */
25 function render_block_implementation( $attr ) {
26 $content = '<div id="Tock_widget_container" data-tock-display-mode="Button" data-tock-color-mode="Blue" data-tock-locale="en-us" data-tock-timezone="America/New_York"></div>';
27 if ( empty( $attr['url'] ) ) {
28 if ( ! current_user_can( 'edit_posts' ) ) {
29 return;
30 }
31
32 return Jetpack_Gutenberg::notice(
33 __( 'The block will not be shown to your site visitors until a Tock business name is set.', 'jetpack' ),
34 'warning',
35 Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr )
36 );
37 }
38
39 wp_enqueue_script( 'tock-widget', 'https://www.exploretock.com/tock.js', array(), JETPACK__VERSION, true );
40
41 // Add CSS to hide direct link.
42 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
43
44 wp_add_inline_script(
45 'tock-widget',
46 "!function(t,o){if(!t.tock){var e=t.tock=function(){e.callMethod?
47 e.callMethod.apply(e,arguments):e.queue.push(arguments)};t._tock||(t._tock=e),
48 e.push=e,e.loaded=!0,e.version='1.0',e.queue=[];}}(window,document);
49 tock('init', " . wp_json_encode( $attr['url'], JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ');',
50 'before'
51 );
52 return sprintf(
53 '<div class="%1$s">%2$s</div>',
54 esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) ),
55 $content
56 );
57 }
58