Plugin Directory

Changeset 3462109


Ignore:
Timestamp:
02/16/2026 12:34:50 AM (6 days ago)
Author:
fuseit
Message:

Release version v1.0.1

Location:
send2crm/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • send2crm/trunk/Admin/VersionManager.php

    r3434803 r3462109  
    5353
    5454    private string $minimumVersion;
    55 
    56     private array $releases;
    5755
    5856public function __construct(Settings $settings, string $version) {
     
    309307     *
    310308     * @since 1.0.0
    311      */
    312     public function insert_version_manager_scripts() {
    313        
     309     *
     310     * @param mixed $hook_suffix The admin page suffix to determin which page the function is running on.
     311     */
     312    public function insert_version_manager_scripts(mixed $hook_suffix) : void {
     313        if( $hook_suffix !== 'settings_page_' . $this->settings->pluginSlug ) {
     314            return;
     315        };
    314316        $versionManagerJSUrl = plugin_dir_url( __FILE__ ) . SEND2CRM_VERSION_MANAGER_FILENAME;
    315317        $versionManagerJsPath = plugin_dir_path( __FILE__ ) . SEND2CRM_VERSION_MANAGER_FILENAME;
     
    336338            'ajax_url' => admin_url('admin-ajax.php'),
    337339            'nonce' => wp_create_nonce('send2crm_releases_nonce'),
     340            //TODO: Remove hard coded element id and reference it from the field
    338341            'version_element_id' => "js_version",
    339342        ));
  • send2crm/trunk/Public/Snippet.php

    r3434803 r3462109  
    1212#region Constants
    1313define('SEND2CRM_JS_FOLDERNAME', 'js/');
     14define('SEND2CRM_SETTING_JS_FOLDERNAME', 'Admin/js/');
    1415define('SEND2CRM_SNIPPET_FILENAME', SEND2CRM_JS_FOLDERNAME . 'send2crm-setup.js');
    1516define('SEND2CRM_ADDITIONAL_SETTINGS_URL', 'https://fuseit.atlassian.net/wiki/x/E4Dogg');
    1617define('SEND2CRM_CLIENT_CONFIG_URL','https://fuseit.atlassian.net/wiki/x/FYBagw');
     18define('SEND2CRM_ADDITIONAL_SETTINGS_FILENAME', SEND2CRM_SETTING_JS_FOLDERNAME . 'additional-settings.js');
    1719#endregion
    1820/**
     
    4850        $this->version = $version;
    4951        $clientConfigUrl = SEND2CRM_CLIENT_CONFIG_URL;
     52        //TODO Move to initialize settings function
    5053        $additionalSettingsUrl = SEND2CRM_ADDITIONAL_SETTINGS_URL;
    5154        //Create the required settings as the default settings group, section.
     
    369372            'ip_lookup',
    370373            'IP Lookup Service URL',
    371             array($this, 'render_text_input'),
    372             'The URL of an external IP address lookup service. This service is queried when new sessions are created, and fields from the response are saved to the ipInfo property of the session. Must return JSON. Set the ipLookup setting to a falsey value (e.g. empty string) to disable IP lookup completely.',
     374            array($this, 'render_optional_url_input'),
     375            "<a href='https://ipinfo.io/glossary/ip-lookup' target='_blank'>What is this?</a><br/><strong>✓ Checked (Disable Lookup):</strong> Send2CRM will skip location lookups when a visitor starts a new session.<br/><strong>○ Unchecked (Perform Lookup):</strong> Send2CRM will look up visitor location information when a new session starts. You can enter a custom lookup service URL, or leave it blank to use the default service (https://ipinfo.io).",
    373376            'advanced',
    374377            $customizeTabName,
    375378            $customizeGroupName,
    376             type: 'url',
     379            type: 'optional_url',
    377380        );
    378381
     
    467470        // Render the input field
    468471        echo "<input type='text' id='" . esc_attr($fieldId) . "' name='" . esc_attr($settingName) . "' value='" . esc_attr($value) . "'>";
     472        if (empty($description)) {
     473            return;
     474        }
     475        echo "<p class='description'>" . wp_kses_post($description) ."</p>";
     476    }
     477
     478    /**
     479     * Callback for displaying an optional url input field on the settings page.
     480     * It includes a checkbox to disable the url input if the user wants to specifically remove the default.
     481     * This is created for settings like IpLookup where the default value is an empty string but the input value can be set to a false as a non default setting.
     482     *
     483     * @since   1.0.1
     484     * @param   array  $arguments The arguments passed to the callback by the settings API hook.
     485     */
     486    public function render_optional_url_input(array $arguments): void {
     487        $fieldId = $arguments['id'];
     488        $fieldDetails = $this->settings->get_field($fieldId);
     489        // Get the current saved value
     490        $optionGroup = $fieldDetails['option_group'];
     491        $value = $this->settings->get_setting($fieldId, $optionGroup);
     492        $settingName = $this->settings->get_setting_name($fieldId, $optionGroup);
     493        $description = $fieldDetails['description'];
     494       
     495        //Set input to hidden if value is false
     496        $type = $value === false? 'hidden' : 'text';
     497
     498       
     499        // Render checkbox to disable input field
     500        echo "<input type='checkbox' id='" . esc_attr($fieldId) . "-checkbox' value='1' " . checked($value === false, 1, false) . ">";
     501        echo "Disable IP Lookup Service</br>";
     502       
     503        //Set input value to 'false' if value is false
     504        $value = $value === false? 'false' : $value;
     505        // Render the input field
     506        echo "<p><input type='" . esc_attr($type) . "' id='" . esc_attr($fieldId) . "' name='" . esc_attr($settingName) . "' value='" . esc_attr($value) . "'></p>";
     507
    469508        if (empty($description)) {
    470509            return;
     
    526565     * @param   $isAdmin    Whether the current request is for an administrative interface page.
    527566    */
     567    //TODO: Check how this function is called from the plugin. Is is meant to be called from constructor or better to be called directly from plugin.
    528568    public function initialize_hooks(bool $isAdmin): void
    529569    {
    530570        if ($isAdmin) {
     571            //Hook on admin page to add javascript
     572            add_action('admin_enqueue_scripts', array($this, 'insert_additional_settings_scripts'));
    531573            return;
    532574        }
     
    543585        $apiKey = $this->settings->get_setting('api_key');
    544586        $apiDomain = $this->settings->get_setting('api_domain');
    545         $jsVersion = $this->settings->get_setting('js_version'); //TODO tidy this up so it is not directly calling the field by te key
     587        $jsVersion = $this->settings->get_setting('js_version');
    546588        $jsHash = $this->settings->get_setting('js_hash');
    547589        $useCDN = $this->settings->get_setting('use_cdn') ?? false;
     
    632674            'before',);
    633675    }
     676
     677    public function insert_additional_settings_scripts(mixed $hook_suffix) : void {
     678        if( $hook_suffix !== 'settings_page_' . $this->settings->pluginSlug ) {
     679            return;
     680        };
     681
     682        $additionalSettingsJSUrl = plugin_dir_url( __DIR__ ) . SEND2CRM_ADDITIONAL_SETTINGS_FILENAME;
     683        $additionalSettingsJsPath = plugin_dir_path( __DIR__ ) . SEND2CRM_ADDITIONAL_SETTINGS_FILENAME;
     684        $additionalSettingsJSId = "{$this->settings->pluginSlug}-additional-settings";
     685        $additionalSettingsJSVersion = file_exists($additionalSettingsJsPath) ? filemtime($additionalSettingsJsPath) : $this->version;
     686
     687        if (wp_register_script( $additionalSettingsJSId, $additionalSettingsJSUrl, array('jquery'), $additionalSettingsJSVersion, false ) === false) {
     688            add_settings_error( 'js_version', esc_attr('settings_updated'), "Unable to register Send2CRM additional settings script.", 'error' );
     689            return;
     690        }
     691
     692        wp_enqueue_script(
     693            $additionalSettingsJSId,
     694            $additionalSettingsJSUrl,
     695            array('jquery'),
     696            $this->version,
     697            false
     698        );
     699       
     700    }
     701
    634702    #endregion
    635703
     
    650718        return match ($type) {
    651719            'url'       => sanitize_url($value),
     720            'optional_url' => $this->sanitize_optional_url($value),
    652721            'email'     => sanitize_email($value),
    653722            'checkbox'  => rest_sanitize_boolean($value),
     
    660729
    661730    /**
     731     * Sanitizes an optional URL for cases like IpLookup where the default value is an empty string but the input value can be set to a false as a non default setting.
     732     *
     733     * @since   1.0.1
     734     * @param   mixed   $value  The input value of the setting sanitize.
     735     * @return  mixed   False if the input value is not empty and does not start with http:// or https://, otherwise the sanitized url is returned.
     736    */
     737    private function sanitize_optional_url(mixed $value) : mixed {
     738        if (
     739            str_starts_with($value, 'http://') === false &&
     740            str_starts_with($value, 'https://') === false &&
     741            empty($value) === false
     742        ) {
     743            return false;
     744        }
     745        return sanitize_url($value);
     746    }
     747
     748    /**
    662749     * Adds a setting to the settings array if it is not empty using the provided field data and input filter.
    663750     *
     
    666753     * @param   string  $key        The key to add the setting to.
    667754     * @param   string  $fieldId    The ID of the field to get the setting from.
    668      * @param   string  $filter     The input filter to apply to the setting value. This is on of the validation filter constants from 'https://www.php.net/manual/en/filter.constants.php'. For example 'FILTER_VALIDATE_BOOLEAN' applies a boolean filter to the setting.
    669      */
    670     private function add_setting_if_not_empty(array &$settings, string $key, string $fieldId, $filter = null) {
     755     * @param   int  $filter     The input filter to apply to the setting value. This is one of the validation filter constants from 'https://www.php.net/manual/en/filter.constants.php'. For example 'FILTER_VALIDATE_BOOLEAN' applies a boolean filter to the setting.
     756     */
     757    private function add_setting_if_not_empty(array &$settings, string $key, string $fieldId, int $filter = null) {
    671758        $value = $this->settings->get_setting($fieldId);
    672         if ($value !== array() && empty($value) === false) {
     759        if ($value !== array() && (empty($value) === false || $value === false)) {
    673760            if (isset($filter)) {
    674761                $value = filter_var($value, $filter);
  • send2crm/trunk/Public/js/send2crm-setup.js

    r3434803 r3462109  
     1
    12(function(s,e,n,d2,c,r,m){n[e]=n[e]||{};m=document.createElement('script');m.onload=function(){n[e].init(d2,c);};m.src=s;m.integrity='sha384-'+r;m.crossOrigin='anonymous';document.head.appendChild(m);})(snippetData.js_location, 'send2crm', window, snippetData.api_domain, snippetData.api_key, snippetData.hash);
    23
    34
    4 function additionalSetup() {
     5function additionalSetup(additionalSettings) {
    56    if ( (!additionalSettings || !Object.keys(additionalSettings).length)
    67        && ( (!servicePaths || !Object.keys(servicePaths).length)
     
    1516    }
    1617
    17     window.addEventListener('send2crmLoading', (evt) => {
     18    window.addEventListener('send2crmLoading', () => {
    1819        // All values are optional, defaults will be used if not present.
    1920        if (additionalSettings && Object.keys(additionalSettings).length > 0) {
     
    2930}
    3031
    31 additionalSetup();
     32additionalSetup(additionalSettings);
  • send2crm/trunk/readme.txt

    r3434803 r3462109  
    44Requires at least: 6.5
    55Tested up to: 6.9
    6 Stable tag: 1.0.0
     6Stable tag: 1.0.1
    77Requires PHP: 8.1
    88License: GPLv2 or later
     
    7272
    7373== Changelog ==
    74  
     74
     75= 1.0.1 =
     76* Fixed an issue where disabling the IP lookup service didn't work properly that resulted in errors when trying to turn off collection of ip information.
     77
    7578= 1.0.0 =
    7679* Initial Version
  • send2crm/trunk/send2crm.php

    r3434803 r3462109  
    1616 * Plugin URI:      https://github.com/FuseInfoTech/wordpress-send2crm-plugin/
    1717 * Description:     Easily integrate your WordPress site with your CRM through FuseIT’s official Send2CRM Wordpress plugin.
    18  * Version: 1.0.0
     18 * Version: 1.0.1
    1919 * Author: FuseIT
    2020 * Author URI: https://fuseit.com
     
    4949 * Rename this for your plugin and update it as you release new versions.
    5050 */
    51 define('SEND2CRM_VERSION', '1.0.0');
     51define('SEND2CRM_VERSION', '1.0.1');
    5252
    5353// The string used to uniquely identify this plugin.
     
    142142            $this->settings->initialize_hooks($isAdmin);
    143143            $this->versionManager->initialize_hooks($isAdmin);
    144         } else {
    145             $this->snippet->initialize_hooks($isAdmin);
    146144        }
     145        $this->snippet->initialize_hooks($isAdmin);
    147146        $this->isInitialized = true;
    148147    }
Note: See TracChangeset for help on using the changeset viewer.