PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 0.0.3
Gutenify – Visual Site Builder Blocks & Starter Templates v0.0.3
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / inc / blocks / google-maps / block.php

block.php in Gutenify – Visual Site Builder Blocks & Starter Templates 0.0.3, at inc/blocks/google-maps/block.php

85 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gutenify Google Map Block file.
4 *
5 * @package Gutenify
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class Gutenify_Block_Google_Maps {
14 public static function init(){
15 add_action( 'init', array( __CLASS__, 'register_block_type' ) );
16 add_action( 'enqueue_block_assets', array( __CLASS__, 'frontend_assets' ) );
17 }
18
19 public static function register_block_type(){
20 $deps = include_once( sprintf( '%s/assets/google-maps_admin.asset.php', GUTENIFY_ABSPATH ) );
21 $deps['dependencies'] = array_merge( $deps['dependencies'], array( 'gutenify-google-fonts' ) );
22 wp_register_script(
23 'gutenify-google-fonts',
24 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', array(), '1.6.26', true
25 );
26
27 wp_register_script(
28 'gutenify-google-maps-script',
29 plugins_url( 'assets/google-maps_admin.js', GUTENIFY_PLUGIN_FILE ), $deps['dependencies'], $deps['version'], true
30 );
31
32 wp_register_style(
33 'gutenify-google-maps-style',
34 plugins_url( 'assets/google-maps_admin.css', GUTENIFY_PLUGIN_FILE ),
35 array('gutenify-main-style'),
36 time()
37 );
38
39 $translation_array['google_fonts'] = Gutenify_Helpers::get_google_fonts();
40 wp_localize_script( 'gutenify-script', 'gutenify_data', $translation_array );
41
42 register_block_type( 'gutenify/google-maps', array(
43 'editor_script' => 'gutenify-google-maps-script',
44 'editor_style' => 'gutenify-google-maps-style',
45 'render_callback' => array( __CLASS__, 'frontend_dynamic_render_callback' )
46 ) );
47 }
48
49 public static function frontend_dynamic_render_callback($attributes) {
50 $defaults = include( sprintf( '%sinc/blocks/count-down/defaults.php', GUTENIFY_ABSPATH ) );
51 $attributes = wp_parse_args( $attributes, $defaults );
52 $wrapperClass = ! empty( $attributes['className'] ) ? $attributes['className'] . ' gutenify-google-maps-wrapper' : ' gutenify-google-maps-wrapper';
53 $blockId = !empty($attributes['blockClientId'])?$attributes['blockClientId']:'';
54 $blockId = str_replace('-','_', $blockId ) . '_' . md5( uniqid (rand (),true) );
55 // return print_r($attributes,true).'<div class="' . $wrapperClass . '" id="' . $blockId . '"></div>
56 return '<div class="' . $wrapperClass . '" id="' . $blockId . '"></div>
57 <script>
58 var '.$blockId.' = '.json_encode($attributes).';
59 </script>
60 ';
61 }
62
63 public static function frontend_assets() {
64 if( !is_admin() ) {
65 $deps = include_once( sprintf( '%s/assets/google-maps_frontend.asset.php', GUTENIFY_ABSPATH ) );
66 $deps['dependencies'] = array_merge( $deps['dependencies'], array( 'gutenify-google-fonts' ) );
67 wp_register_script(
68 'gutenify-google-fonts',
69 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', array(), '1.6.26', true
70 );
71 wp_enqueue_script(
72 'gutenify-google-maps-frontend-script',
73 plugins_url( 'assets/google-maps_frontend.js', GUTENIFY_PLUGIN_FILE ), $deps['dependencies'], $deps['version'], true
74 );
75 wp_enqueue_style(
76 'gutenify-google-maps-frontend-style',
77 plugins_url( 'assets/google-maps_frontend.css', GUTENIFY_PLUGIN_FILE ),
78 array(),
79 time()
80 );
81 }
82 }
83 }
84
85 Gutenify_Block_Google_Maps::init();