Plugin Directory

Changeset 2871061


Ignore:
Timestamp:
02/25/2023 08:06:01 PM (3 years ago)
Author:
dyonic
Message:

Introduce excluded pages input

Location:
ryen-wp/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ryen-wp/trunk/README.txt

    r2869462 r2871061  
    66License: GPL 2.0
    77License URI: http://www.gnu.org/licenses/gpl-2.0.txt
    8 Stable Tag: 3.0.1
     8Stable Tag: 3.1.1
    99
    1010Build beautiful conversational forms
     
    2727
    2828== Changelog ==
     29= 3.1.1 =
     30* Fix excluded pages when empty
     31* Breaking change! You will need to import the new code snippet again.
     32* Fix wp admin crash
     33* Introduce excluded pages input
     34
    2935= 3.0.1 =
    3036* Fix flow not proceeding on unknown domains
  • ryen-wp/trunk/admin/class-ryen-admin.php

    r2869462 r2871061  
    2727  {
    2828    register_setting('ryen', 'init_snippet');
     29    register_setting('ryen', 'excluded_pages');
    2930  }
    3031}
  • ryen-wp/trunk/admin/partials/ryen-admin-display.php

    r2869462 r2871061  
    1212        <div style="display: flex; flex-direction: column">
    1313          <label>If embedding as <strong>Popup</strong> or <strong>Bubble</strong>, paste the initialization snippet here:</label>
    14           <textarea name="init_snippet" placeholder='Ryen.initPopup({ ryen: "https://ryen.org/my-ryen" });' style="min-height: 150px; padding: 0.5rem; margin-top: 1rem"><?php echo esc_attr(get_option('init_snippet')); ?></textarea>
     14          <textarea name="init_snippet" style="min-height: 150px; padding: 0.5rem; margin-top: 1rem"><?php echo esc_attr(get_option('init_snippet')); ?></textarea>
     15        </div>
     16
     17        <div style="display: flex; flex-direction: column; margin-top: 1rem">
     18          <label>Excluded pages (optionnal):</label>
     19          <p style="color: gray">Example: /app/*, /user/*, /admin/settings</p>
     20          <input name="excluded_pages" value="<?php echo esc_attr(get_option('excluded_pages')); ?>" style="padding: .5rem" />
    1521        </div>
    1622
  • ryen-wp/trunk/includes/class-ryen.php

    r2869462 r2871061  
    4343    {
    4444        $plugin_admin = new Ryen_Admin($this->get_version());
    45         $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
    4645        $this->loader->add_action('admin_menu', $plugin_admin, 'my_admin_menu');
    4746        $this->loader->add_action('admin_init', $plugin_admin, 'register_ryen_settings');
  • ryen-wp/trunk/public/class-ryen-public.php

    r2869462 r2871061  
    55  public function add_head_code()
    66  {
    7     function add_module_type($tag, $handle)
     7    function parse_wp_user()
    88    {
    9       if ('ryen' !== $handle) {
    10         return $tag;
     9      $wp_user = wp_get_current_user();
     10      echo '<script>
     11      if(typeof window.ryenWpUser === "undefined"){
     12      window.ryenWpUser = {
     13          wp_id:"' .
     14        $wp_user->ID .
     15        '",
     16          wp_username:"' .
     17        $wp_user->user_login .
     18        '",
     19          wp_email:"' .
     20        $wp_user->user_email .
     21        '",
     22          wp_first_name:"' .
     23        $wp_user->user_firstname .
     24        '",
     25          wp_last_name:"' .
     26        $wp_user->user_lastname .
     27        '",
     28        }
    1129      }
    12       $tag = str_replace(
    13         '<script',
    14         '<script type ="module"',
    15         $tag
    16       );
    17       return $tag;
     30      </script>';
    1831    }
    1932
    20     wp_enqueue_script('ryen', 'whatever.js');
    21     add_filter('script_loader_tag', 'add_module_type', 10, 2);
    22     wp_add_inline_script('ryen', $this->parse_wp_user());
    23     if (get_option('init_snippet') && get_option('init_snippet') !== '') {
    24       wp_add_inline_script('ryen', get_option('init_snippet'));
    25       wp_add_inline_script('ryen', 'Ryen.setPrefilledVariables({ ryenWpUser });');
     33    function ryen_script()
     34    {
     35      echo '<script type="module">
     36      import Ryen from "https://cdn.jsdelivr.net/npm/@ryen/js@0.0/dist/web.js";';
     37      if (
     38        get_option('excluded_pages') !== null &&
     39        get_option('excluded_pages') !== ''
     40      ) {
     41        $paths = explode(',', get_option('excluded_pages'));
     42        $arr_js = 'const ryenExcludePaths = [';
     43        foreach ($paths as $path) {
     44          $arr_js = $arr_js . '"' . $path . '",';
     45        }
     46        $arr_js = substr($arr_js, 0, -1) . '];';
     47        echo $arr_js;
     48      } else {
     49        echo 'const ryenExcludePaths = null;';
     50      }
     51      if (get_option('init_snippet') && get_option('init_snippet') !== '') {
     52
     53        echo 'if(!ryenExcludePaths || ryenExcludePaths.every((path) => {
     54          let excludePath = path.trim();
     55                    let windowPath = window.location.pathname;
     56                    if (excludePath.endsWith("*")) {
     57                        return !windowPath.startsWith(excludePath.slice(0, -1));
     58                    }
     59                    if (excludePath.endsWith("/")) {
     60                        excludePath = path.slice(0, -1);
     61                    }
     62                    if (windowPath.endsWith("/")) {
     63                        windowPath = windowPath.slice(0, -1);
     64                    }
     65                    return windowPath !== excludePath;
     66                })) {
     67          ' . get_option('init_snippet') . '
     68          Ryen.setPrefilledVariables({ ryenWpUser });
     69         
     70        }';
     71      }
     72      echo '</script>';
    2673    }
    27   }
    28 
    29   private function parse_wp_user()
    30   {
    31     $wp_user = wp_get_current_user();
    32     return 'if(typeof window.ryenWpUser === "undefined"){
    33       window.ryenWpUser = {
    34           wp_id:"' .
    35       $wp_user->ID .
    36       '",
    37           wp_username:"' .
    38       $wp_user->user_login .
    39       '",
    40           wp_email:"' .
    41       $wp_user->user_email .
    42       '",
    43           wp_first_name:"' .
    44       $wp_user->user_firstname .
    45       '",
    46           wp_last_name:"' .
    47       $wp_user->user_lastname .
    48       '",
    49         }
    50       }';
     74    add_action('wp_head', 'parse_wp_user');
     75    add_action('wp_footer', 'ryen_script');
    5176  }
    5277
    5378  public function add_ryen_container($attributes = [])
    5479  {
    55     $lib_url = "https://cdn.jsdelivr.net/npm/@ryen/js@0.0.14/dist/web.js";
     80    $lib_url = "https://cdn.jsdelivr.net/npm/@ryen/js@0.0/dist/web.js";
    5681    $width = '100%';
    5782    $height = '500px';
  • ryen-wp/trunk/ryen.php

    r2869462 r2871061  
    44 * Plugin Name:       Ryen WP
    55 * Description:       Convert more with conversational forms
    6  * Version:           3.0.1
     6 * Version:           3.1.1
    77 * Author:            Ryen
    88 * Author URI:        http://ryen.org/
     
    1717}
    1818
    19 define('RYEN_VERSION', '3.0.1');
     19define('RYEN_VERSION', '3.1.1');
    2020
    2121function activate_ryen()
Note: See TracChangeset for help on using the changeset viewer.