Changeset 3462109
- Timestamp:
- 02/16/2026 12:34:50 AM (6 days ago)
- Location:
- send2crm/trunk
- Files:
-
- 1 added
- 5 edited
-
Admin/VersionManager.php (modified) (3 diffs)
-
Admin/js/additional-settings.js (added)
-
Public/Snippet.php (modified) (10 diffs)
-
Public/js/send2crm-setup.js (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
send2crm.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
send2crm/trunk/Admin/VersionManager.php
r3434803 r3462109 53 53 54 54 private string $minimumVersion; 55 56 private array $releases;57 55 58 56 public function __construct(Settings $settings, string $version) { … … 309 307 * 310 308 * @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 }; 314 316 $versionManagerJSUrl = plugin_dir_url( __FILE__ ) . SEND2CRM_VERSION_MANAGER_FILENAME; 315 317 $versionManagerJsPath = plugin_dir_path( __FILE__ ) . SEND2CRM_VERSION_MANAGER_FILENAME; … … 336 338 'ajax_url' => admin_url('admin-ajax.php'), 337 339 'nonce' => wp_create_nonce('send2crm_releases_nonce'), 340 //TODO: Remove hard coded element id and reference it from the field 338 341 'version_element_id' => "js_version", 339 342 )); -
send2crm/trunk/Public/Snippet.php
r3434803 r3462109 12 12 #region Constants 13 13 define('SEND2CRM_JS_FOLDERNAME', 'js/'); 14 define('SEND2CRM_SETTING_JS_FOLDERNAME', 'Admin/js/'); 14 15 define('SEND2CRM_SNIPPET_FILENAME', SEND2CRM_JS_FOLDERNAME . 'send2crm-setup.js'); 15 16 define('SEND2CRM_ADDITIONAL_SETTINGS_URL', 'https://fuseit.atlassian.net/wiki/x/E4Dogg'); 16 17 define('SEND2CRM_CLIENT_CONFIG_URL','https://fuseit.atlassian.net/wiki/x/FYBagw'); 18 define('SEND2CRM_ADDITIONAL_SETTINGS_FILENAME', SEND2CRM_SETTING_JS_FOLDERNAME . 'additional-settings.js'); 17 19 #endregion 18 20 /** … … 48 50 $this->version = $version; 49 51 $clientConfigUrl = SEND2CRM_CLIENT_CONFIG_URL; 52 //TODO Move to initialize settings function 50 53 $additionalSettingsUrl = SEND2CRM_ADDITIONAL_SETTINGS_URL; 51 54 //Create the required settings as the default settings group, section. … … 369 372 'ip_lookup', 370 373 '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).", 373 376 'advanced', 374 377 $customizeTabName, 375 378 $customizeGroupName, 376 type: ' url',379 type: 'optional_url', 377 380 ); 378 381 … … 467 470 // Render the input field 468 471 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 469 508 if (empty($description)) { 470 509 return; … … 526 565 * @param $isAdmin Whether the current request is for an administrative interface page. 527 566 */ 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. 528 568 public function initialize_hooks(bool $isAdmin): void 529 569 { 530 570 if ($isAdmin) { 571 //Hook on admin page to add javascript 572 add_action('admin_enqueue_scripts', array($this, 'insert_additional_settings_scripts')); 531 573 return; 532 574 } … … 543 585 $apiKey = $this->settings->get_setting('api_key'); 544 586 $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 key587 $jsVersion = $this->settings->get_setting('js_version'); 546 588 $jsHash = $this->settings->get_setting('js_hash'); 547 589 $useCDN = $this->settings->get_setting('use_cdn') ?? false; … … 632 674 'before',); 633 675 } 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 634 702 #endregion 635 703 … … 650 718 return match ($type) { 651 719 'url' => sanitize_url($value), 720 'optional_url' => $this->sanitize_optional_url($value), 652 721 'email' => sanitize_email($value), 653 722 'checkbox' => rest_sanitize_boolean($value), … … 660 729 661 730 /** 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 /** 662 749 * Adds a setting to the settings array if it is not empty using the provided field data and input filter. 663 750 * … … 666 753 * @param string $key The key to add the setting to. 667 754 * @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 onof 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) { 671 758 $value = $this->settings->get_setting($fieldId); 672 if ($value !== array() && empty($value) === false) {759 if ($value !== array() && (empty($value) === false || $value === false)) { 673 760 if (isset($filter)) { 674 761 $value = filter_var($value, $filter); -
send2crm/trunk/Public/js/send2crm-setup.js
r3434803 r3462109 1 1 2 (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); 2 3 3 4 4 function additionalSetup( ) {5 function additionalSetup(additionalSettings) { 5 6 if ( (!additionalSettings || !Object.keys(additionalSettings).length) 6 7 && ( (!servicePaths || !Object.keys(servicePaths).length) … … 15 16 } 16 17 17 window.addEventListener('send2crmLoading', ( evt) => {18 window.addEventListener('send2crmLoading', () => { 18 19 // All values are optional, defaults will be used if not present. 19 20 if (additionalSettings && Object.keys(additionalSettings).length > 0) { … … 29 30 } 30 31 31 additionalSetup( );32 additionalSetup(additionalSettings); -
send2crm/trunk/readme.txt
r3434803 r3462109 4 4 Requires at least: 6.5 5 5 Tested up to: 6.9 6 Stable tag: 1.0. 06 Stable tag: 1.0.1 7 7 Requires PHP: 8.1 8 8 License: GPLv2 or later … … 72 72 73 73 == 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 75 78 = 1.0.0 = 76 79 * Initial Version -
send2crm/trunk/send2crm.php
r3434803 r3462109 16 16 * Plugin URI: https://github.com/FuseInfoTech/wordpress-send2crm-plugin/ 17 17 * Description: Easily integrate your WordPress site with your CRM through FuseIT’s official Send2CRM Wordpress plugin. 18 * Version: 1.0. 018 * Version: 1.0.1 19 19 * Author: FuseIT 20 20 * Author URI: https://fuseit.com … … 49 49 * Rename this for your plugin and update it as you release new versions. 50 50 */ 51 define('SEND2CRM_VERSION', '1.0. 0');51 define('SEND2CRM_VERSION', '1.0.1'); 52 52 53 53 // The string used to uniquely identify this plugin. … … 142 142 $this->settings->initialize_hooks($isAdmin); 143 143 $this->versionManager->initialize_hooks($isAdmin); 144 } else {145 $this->snippet->initialize_hooks($isAdmin);146 144 } 145 $this->snippet->initialize_hooks($isAdmin); 147 146 $this->isInitialized = true; 148 147 }
Note: See TracChangeset
for help on using the changeset viewer.