'async', 'in_footer' => true, ) ); } // ...on the admin panel add_action( 'admin_enqueue_scripts', 'atcb_enqueue_script' ); // ...on the website $atcb_settings_options = get_option( 'atcb_global_settings' ); $unstyle = $atcb_settings_options && $atcb_settings_options['atcb_go_unstyle'] && ($atcb_settings_options['atcb_go_unstyle'] === 'true' || $atcb_settings_options['atcb_go_unstyle'] === true) ? true : false; add_action( 'wp_enqueue_scripts', function () use ($unstyle) { atcb_enqueue_script($unstyle); } ); // SHORTCODE function atcb_shortcode_func( $atts ) { global $allowedAttributes; $output = ' $value ) { if ( is_numeric($key) ) { // do not process any unknown attributes to prevent XSS if ( !in_array(strtolower($value), $allowedAttributes, true) ) { continue; } $output .= ' ' . esc_attr( $value ); } else { // do not process any unknown attributes to prevent XSS if ( !in_array(strtolower($key), $allowedAttributes, true) ) { continue; } $valueContent = esc_attr($value); // replace "{{sc_start}}", "{{sc_end}}" with "[" and "]" to allow for nested shortcodes $valueContent = str_replace('{sc_start}', '[', $valueContent); $valueContent = str_replace('{sc_end}', ']', $valueContent); $valueStr = do_shortcode($valueContent); $output .= ' ' . esc_attr( $key ) . '="' . esc_attr( $valueStr ) . '"'; } } $output .= '>'; return $output; } add_shortcode( 'add-to-calendar-button', 'atcb_shortcode_func' ); // GUTENBERG BLOCK function atcb_register_block() { global $allowedAttributes; // register the block script wp_register_script( 'atcb-block', plugins_url('build/block.js', __FILE__), array('wp-blocks', 'wp-block-editor', 'wp-element'), ATCB_PLUGIN_VERSION, true ); // register the actual block register_block_type( 'add-to-calendar/button', array('editor_script' => 'atcb-block') ); // add i18n load_plugin_textdomain( 'add-to-calendar-button', false, dirname(plugin_basename( __FILE__ )) . '/languages' ); $locale = get_Locale(); $language = explode( '_', $locale )[0]; wp_localize_script( 'atcb-block', 'atcbI18nObj', [ 'language' => $language, 'description' => __("Creates a button that adds an event to the user's calendar.", 'add-to-calendar-button'), 'keywords' => [ 'k1' => __("Calendar", 'add-to-calendar-button'), 'k2' => __("save", 'add-to-calendar-button'), 'k3' => __("Date", 'add-to-calendar-button'), 'k4' => __("Appointment", 'add-to-calendar-button') ], 'label_name' => __("Name", 'add-to-calendar-button'), 'label_options' => __("Calendar options", 'add-to-calendar-button'), 'label_others' => __("Other attributes", 'add-to-calendar-button'), 'label_override' => __("Overrides", 'add-to-calendar-button'), 'help' => __("Click here for documentation", 'add-to-calendar-button'), 'override_note' => __("With PRO active, only some attributes can be manipulated here. Check the docs for more details and try to adjust an event in the app first.", 'add-to-calendar-button'), 'note' => __("Mind that the interaction with the button is blocked in edit mode", 'add-to-calendar-button') ] ); // transmit further settings $tz = wp_timezone_string(); // if tz starts with +,-, or 0, we set it to "America/New_York" as default if ( preg_match('/^[+-0]/', $tz) ) { $tz = 'America/New_York'; } wp_localize_script( 'atcb-block', 'atcbSettings', [ 'allowedAttributes' => $allowedAttributes, 'defaultTimeZone' => $tz, 'defaultTitle' => __("My Event Title", 'add-to-calendar-button'), ] ); } add_action( 'init', 'atcb_register_block' ); ?>