2
0

🐛 (wordpress) Fix admin critical bug and better lib import

This commit is contained in:
Baptiste Arnaud
2023-02-25 17:13:26 +01:00
parent 2b2b1c3d6d
commit c889f302f6
18 changed files with 177 additions and 127 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wordpress",
"version": "2.1.11",
"version": "3.1.0",
"main": "index.js",
"repository": "https://github.com/baptisteArno/typebot.io",
"author": "baptisteArno",
@ -11,7 +11,7 @@
},
"scripts": {
"deploy": "pnpm copy && pnpm commit",
"copy": "svn copy ./trunk ./tags/3.0.1",
"commit": "svn ci -m 'Fix standard flow not proceeding'"
"copy": "svn copy ./trunk ./tags/3.1.0",
"commit": "svn ci -m 'Fix admin critical bug and introduce excluded pages'"
}
}

View File

@ -5,7 +5,7 @@ Requires at least: 5.0
Tested up to: 6.0
License: GPL 2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Stable Tag: 3.0.1
Stable Tag: 3.1.0
Build beautiful conversational forms
@ -26,6 +26,11 @@ This plugin relies on Typebot which is a tool that allows you to create conversa
3. Activate your Typebot with the "Typebot" admin button located in the sidebar
== Changelog ==
= 3.1.0 =
* Breaking change! You will need to import the new code snippet again.
* Fix wp admin crash
* Introduce excluded pages input
= 3.0.1 =
* Fix flow not proceeding on unknown domains

View File

@ -26,5 +26,6 @@ class Typebot_Admin
public function register_typebot_settings()
{
register_setting('typebot', 'init_snippet');
register_setting('typebot', 'excluded_pages');
}
}

View File

@ -11,7 +11,13 @@
?>
<div style="display: flex; flex-direction: column">
<label>If embedding as <strong>Popup</strong> or <strong>Bubble</strong>, paste the initialization snippet here:</label>
<textarea name="init_snippet" placeholder='Typebot.initPopup({ typebot: "https://typebot.io/my-typebot" });' style="min-height: 150px; padding: 0.5rem; margin-top: 1rem"><?php echo esc_attr(get_option('init_snippet')); ?></textarea>
<textarea name="init_snippet" style="min-height: 150px; padding: 0.5rem; margin-top: 1rem"><?php echo esc_attr(get_option('init_snippet')); ?></textarea>
</div>
<div style="display: flex; flex-direction: column; margin-top: 1rem">
<label>Excluded pages (optionnal):</label>
<p style="color: gray">Example: /app/*, /user/*, /admin/settings</p>
<input name="excluded_pages" value="<?php echo esc_attr(get_option('excluded_pages')); ?>" style="padding: .5rem" />
</div>
<div style="margin-top: 1rem">

View File

@ -42,7 +42,6 @@ class Typebot
private function define_admin_hooks()
{
$plugin_admin = new Typebot_Admin($this->get_version());
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
$this->loader->add_action('admin_menu', $plugin_admin, 'my_admin_menu');
$this->loader->add_action('admin_init', $plugin_admin, 'register_typebot_settings');
}

View File

@ -4,55 +4,78 @@ class Typebot_Public
{
public function add_head_code()
{
function add_module_type($tag, $handle)
function parse_wp_user()
{
if ('typebot' !== $handle) {
return $tag;
}
$tag = str_replace(
'<script',
'<script type ="module"',
$tag
);
return $tag;
}
wp_enqueue_script('typebot', 'whatever.js');
add_filter('script_loader_tag', 'add_module_type', 10, 2);
wp_add_inline_script('typebot', $this->parse_wp_user());
if (get_option('init_snippet') && get_option('init_snippet') !== '') {
wp_add_inline_script('typebot', get_option('init_snippet'));
wp_add_inline_script('typebot', 'Typebot.setPrefilledVariables({ typebotWpUser });');
}
}
private function parse_wp_user()
{
$wp_user = wp_get_current_user();
return 'if(typeof window.typebotWpUser === "undefined"){
$wp_user = wp_get_current_user();
echo '<script>
if(typeof window.typebotWpUser === "undefined"){
window.typebotWpUser = {
wp_id:"' .
$wp_user->ID .
'",
$wp_user->ID .
'",
wp_username:"' .
$wp_user->user_login .
'",
$wp_user->user_login .
'",
wp_email:"' .
$wp_user->user_email .
'",
$wp_user->user_email .
'",
wp_first_name:"' .
$wp_user->user_firstname .
'",
$wp_user->user_firstname .
'",
wp_last_name:"' .
$wp_user->user_lastname .
'",
$wp_user->user_lastname .
'",
}
}';
}
</script>';
}
function typebot_script()
{
echo '<script type="module">
import Typebot from "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0/dist/web.js";';
if (
get_option('excluded_pages') !== null &&
get_option('excluded_pages') !== ''
) {
$paths = explode(',', get_option('excluded_pages'));
$arr_js = 'const typebotExcludePaths = [';
foreach ($paths as $path) {
$arr_js = $arr_js . '"' . $path . '",';
}
$arr_js = substr($arr_js, 0, -1) . '];';
echo $arr_js;
}
if (get_option('init_snippet') && get_option('init_snippet') !== '') {
echo 'if(!typebotExcludePaths || typebotExcludePaths.every((path) => {
let excludePath = path.trim();
let windowPath = window.location.pathname;
if (excludePath.endsWith("*")) {
return !windowPath.startsWith(excludePath.slice(0, -1));
}
if (excludePath.endsWith("/")) {
excludePath = path.slice(0, -1);
}
if (windowPath.endsWith("/")) {
windowPath = windowPath.slice(0, -1);
}
return windowPath !== excludePath;
})) {
' . get_option('init_snippet') . '
Typebot.setPrefilledVariables({ typebotWpUser });
}';
}
echo '</script>';
}
add_action('wp_head', 'parse_wp_user');
add_action('wp_footer', 'typebot_script');
}
public function add_typebot_container($attributes = [])
{
$lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.14/dist/web.js";
$lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0/dist/web.js";
$width = '100%';
$height = '500px';
if (array_key_exists('width', $attributes)) {

View File

@ -3,7 +3,7 @@
/**
* Plugin Name: Typebot
* Description: Convert more with conversational forms
* Version: 3.0.1
* Version: 3.1.0
* Author: Typebot
* Author URI: http://typebot.io/
* License: GPL-2.0+
@ -16,7 +16,7 @@ if (!defined('WPINC')) {
die();
}
define('TYPEBOT_VERSION', '3.0.1');
define('TYPEBOT_VERSION', '3.1.0');
function activate_typebot()
{