ActiveCampaign site tracking code in your pages. To get started, please activate the plugin and add your API credentials in the plugin settings. Author: ActiveCampaign Version: 8.1.21 Author URI: http://www.activecampaign.com */ # Changelog ## version 1: - initial release ## version 1.1: Verified this works with latest versions of WordPress and ActiveCampaign; Updated installation instructions ## version 2.0: Re-configured to work with ActiveCampaign version 5.4. Also improved some areas. ## version 2.1: Changed internal API requests to use only API URL and Key instead of Username and Password. Also provided option to remove style blocks, and converting `input type="button"` into `input type="submit"` ## version 3.0: Re-wrote widget backend to use most recent WordPress Widget structure. Improvements include streamlined code and API usage, ability to reset or refresh your forms, and better form width detection. ## version 3.5: You can now use a shortcode to display your subscription form. ## version 4.0: Added many additional settings to control how your form is displayed and submitted. ## version 4.5: Added ActiveCampaign to the Settings menu so you can use the shortcode independent of the widget. ## version 5.0: Added support for multiple forms. Removed widget entirely. ## version 5.1: Added button to TinyMCE toolbar to more easily choose and embed the form shortcode into the post body. ## version 5.2: Default form behavior is now "sync." This coincided with WordPress version 3.9 release. ## version 5.5: Added site tracking. ## version 5.6: Patched major security bug. ## version 5.7: Removed ability to add custom form "action" URL. ## version 5.8: Security fix. ## version 5.9: Use current user's email for site tracking. ## version 5.91: Updates to avoid conflicts with other plugins using the ActiveCampaign PHP API wrapper. ## version 5.92: Support for captcha validation when using the 'Submit form without refreshing page' (Ajax) option. Also added success or error CSS classes to the Ajax response div. ## version 5.93: Fix for issue with captcha verification when using the Ajax ("Submit form without refreshing page") form submission option. ## version 6.0: Added support for new form builder. ## version 6.1: Fix for issue with new forms not displaying properly. ## version 6.2: Fix for compatability issue with live composer plugin. ## version 6.25: Fix for SSL issue (when the page is loaded via HTTPS and the AC account uses a CNAME, forms would not show up). ## version 6.2.6: Fix for certain error messages not being displayed properly. ## version 6.2.7: Fix for 6.2.6 change missing another check. ## version 6.2.8: Fix for `Undefined index: css` error. ## version 6.2.9: Fix for "Keep original form CSS" checkbox not being respected. ## version 6.2.10: Limit amount of ActiveCampaign account data shown in JavaScript (for site tracking). ## version 6.2.11: Fix for when the "site_tracking" key is undefined. ## version 6.2.12: Fix for when the "form_id" key is undefined. ## version 6.3: Added site tracking options for GDPR ## version 7.0: Force upgrade prompt for users on 6.25 ## version 7.1: Update Site Tracking snippet to route through Prism. ## version 7.1.1: Include our own host header on requests. ## version 7.1.2: Update tracking code copy to be more specific to Site Tracking and Conversations. Fix old link to Forms page. Make install code toggle focusable. ## version 7.1.3: Updated readme ## version 7.1.4: Updated listing ## version 8.0.0: Update ActiveCampaign forms embed to be compatible with Gutenberg editor, Resolve account connection UI bug ## version 8.0.1: Removing php 7 feature usage ## version 8.0.2: Security fix to address CSRF vulnerability, general fix to address browser warning for invalid cookie attribute ## version 8.0.3: Pluggable bug fix ## version 8.1.0: Improvements to Gutenberg Editor experience, including live preview of Form embeds. Background color bug fix. Shortcode support for optional 'css' and 'static' attributes that default to plugin settings. Avoiding global namespace conflicts of on-demand chunks bug fix. ## version 8.1.1: Improved error handling on expired credentials and misconfigurations. Shortening Block widget name to 'AC Forms'. ## version 8.1.2: Simplifying plugin settings options. Dropping 'Global' CSS option for block, defaulting to 'Use ActiveCampaign CSS'. Converting to Dynamic Block pattern. ## version 8.1.3: Hotfix for Default CSS option deprecation. Moving from global assignment to block/shortcode assignment. Allowing fallback for existing blocks without CSS setting. ## version 8.1.4: Rolling back settings page form/css deprecations. We have improved testing workflows moving forward. ## version 8.1.5: Updating Readme with up to date screenshots and better descriptions. Updating Plugin Settings with clearer descriptions of form and shortcode use cases. Fixing block editor CSS class input on dynamic div output. Fixing display of Site Tracking settings without forms. Migrating Site Tracking JS to vgo() from pgo(). Fixing bug with Tracking ID fetch. Adding admin notice stack for future plugin updates. ## version 8.1.6: Improving credential check to fix permissions bug. Fixing non-inline form previews in block editor. Removing unnecessary Google Font loads on no-style embeds. Updating Plugin description. ## version 8.1.7: Updated listing ## version 8.1.8: Updated listing ## version 8.1.9: Updated authentication for internal API requests ## version 8.1.10: Verify 6.0 Compatibility. Updated listing ## version 8.1.11: Removing obsolete Javascript ## version 8.1.12: Security fix to address XSS vulnerability ## version 8.1.13: Verify 6.3.1 Compatibility. Updated listing ## version 8.1.14: Fixing shortcode CSS display in Form Preview ## version 8.1.15: Security fix to address SSRF vulnerability with API URL verification and wp_safe_remote_get. Removing unreachable deprecated curl code ## version 8.1.16: Verify 6.5 Compatibility. Updated listing ## version 8.1.17: Security fix to address XSS vulnerability with API URL and API Key verification ## version 8.1.18: Update readme.txt, address supported version of WordPress ## version 8.1.19: Update readme.txt, with newest activecampaign features ## version 8.1.20: Update readme.txt, with newest activecampaign features ## version 8.1.21: Update plugin branding define("ACTIVECAMPAIGN_URL", ""); define("ACTIVECAMPAIGN_API_KEY", ""); require_once(dirname(__FILE__) . "/activecampaign-api-php/ActiveCampaign.class.php"); require_once(dirname(__FILE__) . "/activecampaign-form-block/activecampaign-form-block.php"); /** * Get the source code for the form itself. * In the past we just returned the form HTML code (CSS + HTML), but the new version of forms just uses the JavaScript stuff (HTML JavaScript include). * * @param array settings The saved ActiveCampaign settings (from the WordPress admin section). * @param array form The individual form metadata (that we obtained from the forms/getforms API call). * @param boolean static Set to true so the "floating" forms don't float. Typically this is done for the admin section only. * @param boolean nostyles Manual override value for nostyles URL Param. Used in shortcode eval to bypass plugin setting. * @param boolean preview Manual value for preview URL Param. * @return string The raw source code that will render the form in the browser. */ function activecampaign_form_source($settings, $form, $static = false, $nostyles = null, $preview = false) { $script_src = activecampaign_form_script_src($settings, $form, $static, $nostyles, $preview); $source = ""; if (isset($form["version"]) && $form["version"] == 2 && isset($script_src)) { if ($form["layout"] == "inline-form") { $source .= "
"; } $source .= ""; } else { // Version 1 forms. } return $source; } /** * Get the script src attribute value for the form's embed. * This is used in shortcode rendering as well as block editor initialization. * * @param array settings The saved ActiveCampaign settings (from the WordPress admin section). * @param array form The individual form metadata (that we obtained from the forms/getforms API call). * @param boolean static Set to true so the "floating" forms don't float. Typically this is done for the admin section only. * @param boolean nostyles Manual override value for nostyles URL Param. Used in shortcode eval to bypass plugin setting. * @param boolean preview Manual value for preview URL Param. * @return string The URL-Encoded src for the rendered script tag */ function activecampaign_form_script_src($settings, $form, $static = false, $nostyles = null, $preview = false) { // Set to activehosted.com domain by default. $domain = (isset($settings["account_view"]) && isset($settings["account_view"]["account"]))? $settings["account_view"]["account"] : null; if(!isset($domain)){ return null; } $source = sprintf("https://%s/f/embed.php?", $domain); $css = (isset($settings["css"]) && isset($settings["css"][$form["id"]]))? $settings["css"][$form["id"]] : null; // Always passing params for JS eval in block editor $source .= ($static)? "static=1&" : "static=0&"; $source .= sprintf("id=%d&%s", $form["id"], strtoupper(uniqid())); $source .= ( (isset($nostyles) && $nostyles === true) || (!isset($nostyles) && (!isset($css) || !$css)) )? "&nostyles=1" : "&nostyles=0"; $source .= ($preview)? "&preview=1" : "&preview=0"; return $source; } function activecampaign_shortcodes($args) { // check for Settings options saved first. $settings = get_option("settings_activecampaign"); if ($settings) { if (isset($settings["forms"]) && $settings["forms"]) { if (isset($args) && isset($args["form"]) && isset($settings["forms"][$args["form"]])) { $form_id = $args["form"]; $form = $settings["forms"][$form_id]; $static = false; if (isset($args["static"]) && ($args["static"] === 1 || $args["static"] === '1' || $args["static"] === 'true')) { $static = true; } $preview = false; if (isset($args["preview"]) && ($args["preview"] === 1 || $args["preview"] === '1' || $args["preview"] === 'true')) { $preview = true; } // Use null default for undefined settings fallback $nostyles = null; if (isset($args["css"])) { if ($args["css"] === 1 || $args["css"] === '1' || $args["css"] === 'true') { $nostyles = false; } elseif ($args["css"] === 0 || $args["css"] === '0' || $args["css"] === 'false') { $nostyles = true; } } return activecampaign_form_source($settings, $form, $static, $nostyles, $preview); } } // Returning un-filtered tag for block editor eval return "[activecampaign]"; } else { // try widget options. $widget = get_option("widget_activecampaign_widget"); // it comes out as an array with other things in it, so loop through it if(!empty($widget)){ foreach ($widget as $k => $v) { // look for the one that appears to be the ActiveCampaign widget settings if (isset($v["api_url"]) && isset($v["api_key"]) && isset($v["form_html"])) { $widget_display = $v["form_html"]; return $widget_display; } } } } return ""; } function activecampaign_verify_api_host($api_host) { return (bool) preg_match('/^https:\/\/([a-zA-Z0-9_\-]+)\.(api\-us1|activehosted)\.com$/', $api_host); } /* * The ActiveCampaign settings page. */ function activecampaign_plugin_options() { if (!current_user_can("manage_options")) { wp_die(__("You do not have sufficient permissions to access this page.")); } $step = 1; $instance = array(); $connected = false; if ($_SERVER["REQUEST_METHOD"] == "POST") { // saving the settings page. $sanitizedApiUrl = sanitize_text_field($_POST["api_url"]); $sanitizedApiKey = sanitize_text_field($_POST["api_key"]); if ($sanitizedApiUrl && $sanitizedApiKey) { //Nonce check for preventing CSRF if (isset($_REQUEST["_wpnonce"])) { $nonce = $_REQUEST["_wpnonce"]; } else { $nonce = wp_create_nonce("invalid_nonce"); } if (! wp_verify_nonce($nonce, "activecampaign_save_settings")) { exit; } // Verify host against whitelist of known domains if(!activecampaign_verify_api_host($sanitizedApiUrl)){ $access_denied_string = "Access denied: Invalid API URL " . $sanitizedApiUrl . ". Please ensure the API URL uses https, and has no extra whitespace."; echo "

" . __($access_denied_string, "menu-activecampaign") . "

"; } else{ $ac = new ActiveCampaignWordPress($sanitizedApiUrl, $sanitizedApiKey); if (!(int)$ac->credentials_test()) { echo "

" . __("Access denied: Invalid credentials (URL and/or API key). \"{$sanitizedApiUrl}\"", "menu-activecampaign") . "

"; } else { $instance = $_POST; // first form submit (after entering API credentials). // get account details. $account = $ac->api("account/view"); $instance["account_view"] = get_object_vars($account); $instance["account"] = property_exists($account, 'account')? $account->account : null; $instance["tracking_actid"] = activecampaign_fetch_accountid($ac); // get forms. $instance = activecampaign_getforms($ac, $instance); $instance = activecampaign_form_html($ac, $instance); $connected = true; // If fetches didn't return domain or account, we can't display embeds, so fail out. This can happen with non-admin API credentials $domain = (isset($instance["account_view"]) && isset($instance["account_view"]["account"]))? $instance["account_view"]["account"] : null; if(!isset($instance["account"]) || !isset($domain)){ $connected = false; $instance = []; echo "

" . __("Access denied: You entered valid credentials, but the associated API User is not an ActiveCampaign Admin group member. Please use API credentials from a User within the Admin group.", "menu-activecampaign") . "

"; } } } } // else one or both of the credentials fields is empty. it will just disconnect below because $instance is empty. update_option("settings_activecampaign", $instance); } else { $instance = get_option("settings_activecampaign"); //dbg($instance); if ( isset($instance["api_url"], $instance["api_key"]) && $instance["api_url"] && $instance["api_key"] && activecampaign_verify_api_host($instance["api_url"]) ) { // instance saved already. $connected = true; } else { // settings not saved yet. // see if they set up our widget (maybe we can pull the API URL and Key from that). $widget = get_option("widget_activecampaign_widget"); if ($widget) { // if the ActiveCampaign widget is activated in a sidebar (dragged to a sidebar). $widget_info = current($widget); // take the first item. if ( isset($widget_info["api_url"], $widget_info["api_key"]) && $widget_info["api_url"] && $widget_info["api_key"] && activecampaign_verify_api_host($widget_info["api_url"]) ) { // if they already supplied an API URL and key in the widget. $instance["api_url"] = $widget_info["api_url"]; $instance["api_key"] = $widget_info["api_key"]; } } } } ?>

[activecampaign form=ID] shortcode in posts, pages, or a sidebar after setting up everything below. Questions or problems? Contact help@activecampaign.com.", "menu-activecampaign"); ?>


:
" style="width: 400px;" />

:
" style="width: 500px;" />

Developer section:", "menu-activecampaign"); ?>

/settings1.png" />


ActiveCampaign > Forms.

Users of the Gutenberg Block Editor will find all forms and CSS options are available within the AC Forms block.

Shortcodes can be used anywhere regardless of widgets in the following format: (where css=1 uses ActiveCampaign's suggested CSS and css=0 does not)
[activecampaign form=ID css=1] or [activecampaign form=ID css=0]

Users of the Classic Editor experience can check the checkbox next to forms they would like to enable in the classic widget, and also manage their form's global CSS setting below.", "menu-activecampaign"); ?>


" value="" onclick="toggle_form_options(this.value, this.checked);" /> (ID: ) - /app/forms/" target="_blank">Edit in ActiveCampaign - )">Copy Shortcode ">Copied!
" style="display: ; margin-left: 30px;">

]" id="activecampaign_form_swim_" value="swim" onchange="swim_toggle(, this.checked);" />
]" id="activecampaign_form_sync_" value="sync" onchange="sync_toggle(, this.checked);" />

]" id="activecampaign_form_ajax_" value="1" onchange="ajax_toggle(, this.checked);" />
]" id="activecampaign_form_css_" value="1" />
'; echo '

'.__("No forms were found", "menu-activecampaign").'

'; } // "Enable Site Tracking" toggle $settings_st_enabled = isset($instance["site_tracking"]) && (int)$instance["site_tracking"]; $settings_st_checked = $settings_st_enabled ? "checked=\"checked\"" : ""; // Site Tracking default option /* Default to "Track by default" option if any of these are true: 1. It's already been chosen and saved 2. Site tracking is just being enabled for the first time 3. Site tracking was already enabled but the new default options are not set yet */ $settings_st_default_on = ( ( isset($instance["activecampaign_site_tracking_default"]) && (int)$instance["activecampaign_site_tracking_default"] ) || ! isset($instance["site_tracking"]) || ! isset($instance["activecampaign_site_tracking_default"]) ); $settings_st_default_on_checked = $settings_st_default_on ? "checked=\"checked\"" : ""; $settings_st_default_off_checked = ! $settings_st_default_on_checked ? "checked=\"checked\"" : ""; ?>

Settings > Tracking page in your ActiveCampaign account.", "menu-activecampaign"); ?>

.

/>

/>

.

.


$form_metadata) { $form_source = activecampaign_form_source($instance, $form_metadata, true); echo $form_source; ?>

[activecampaign form= css=]


"; echo "Vartype: " . gettype($var) . "\n"; if (is_array($var)) { echo "Elements: " . count($var) . "\n\n"; } elseif (is_string($var)) { echo "Length: " . strlen($var) . "\n\n"; } print_r($var); echo ""; if (!$continue) { exit(); } } function activecampaign_fetch_accountid($ac){ /* It appears user/me doesn't always work, but for some reason that seems to be the only endpoint with param level access to account ID. As a fallback, let's fetch the script via API and extract the Account ID */ $user_me = $ac->api("user/me"); if(isset($user_me) && !empty($user_me->trackid)){ return $user_me->trackid; } // Try v3 code check $script = $ac->api3('siteTracking/code', [], false); //try regex to extract from script call. $matches = []; if(preg_match('/\'setAccount\', \'(\d*)\'\)/', $script, $matches) !== false && !empty($matches[1])){ return $matches[1]; } return ''; } function activecampaign_getforms($ac, $instance) { $forms = $ac->api("form/getforms"); if ((int)$forms->success) { $items = array(); $forms = get_object_vars($forms); foreach ($forms as $key => $value) { if (is_numeric($key)) { $items[$value->id] = get_object_vars($value); } } $instance["forms"] = $items; } else { if ($forms->error == "Failed: Nothing is returned") { $instance["error"] = "Nothing was returned. Do you have at least one form created in your ActiveCampaign account?"; } else { $instance["error"] = $forms->error; } } return $instance; } function activecampaign_form_html($ac, $instance) { if ($instance["forms"]) { foreach ($instance["forms"] as $form) { // $instance["form_id"] is an array of form ID's (since we allow multiple now). if (isset($instance["form_id"]) && in_array($form["id"], $instance["form_id"])) { if (isset($form["version"]) && $form["version"] == 2) { // Nothing to do here - we'll generate the form source code on page load. continue; } // Version 1 forms only should proceed here!! $domain = $instance["account"]; $protocol = "https:"; $form_embed_params = array( "id" => $form["id"], "ajax" => $instance["ajax"][$form["id"]], "css" => $instance["css"][$form["id"]], ); $sync = ($instance["syim"][$form["id"]] == "sync") ? 1 : 0; if ($instance["action"][$form["id"]]) { $form_embed_params["action"] = $instance["action"][$form["id"]]; } if ((int)$form_embed_params["ajax"] && !isset($form_embed_params["action"])) { // if they are using Ajax, but have not provided a custom action URL, we need to push it to a script where we can submit the form/process API request. // remove the "http(s)" portion, because it was conflicting with the Ajax request (I was getting 404's). $api_url_process = preg_replace("/https:\/\//", "", $instance["api_url"]); $form_embed_params["action"] = plugins_url("form_process.php?sync=" . $sync, __FILE__); } // prepare the params for the API call $api_params = array(); foreach ($form_embed_params as $var => $val) { $api_params[] = $var . "=" . urlencode($val); } // fetch the HTML source $html = $ac->api("form/embed?" . implode("&", $api_params)); if ((int)$form_embed_params["ajax"]) { // used for the result message that is displayed after submitting the form via Ajax $html = "
" . $html; } if ($html) { if ($instance["account"]) { // replace the API URL with the account URL (IE: https://account.api-us1.com is changed to http://account.activehosted.com). // (the form has to submit to the account URL.) if (!$instance["action"]) { $html = preg_replace("/action=['\"][^'\"]+['\"]/", "action='" . $protocol . "//" . $domain . "/proc.php'", $html); } } // replace the Submit button to be an actual submit type. //$html = preg_replace("/input type='button'/", "input type='submit'", $html); } if ((int)$form_embed_params["css"]) { // get the style content so we can prepend each rule with the form ID (IE: #_form_1341). // this is in case there are multiple forms on the same page - their styles need to be unique. preg_match_all("|]*>(.*)|iUs", $html, $style_blocks); if (isset($style_blocks[1]) && isset($style_blocks[1][0]) && $style_blocks[1][0]) { $css = $style_blocks[1][0]; // remove excess whitespace from within the string. $css = preg_replace("/\s+/", " ", $css); // remove whitespace from beginning and end of string. $css = trim($css); $css_rules = explode("}", $css); $css_rules_new = array(); foreach ($css_rules as $rule) { $rule_array = explode("{", $rule); $rule_array[0] = preg_replace("/\s+/", " ", $rule_array[0]); $rule_array[0] = trim($rule_array[0]); $rule_array[1] = preg_replace("/\s+/", " ", $rule_array[1]); $rule_array[1] = trim($rule_array[1]); if ($rule_array[1]) { // there could be comma-separated rules. $rule_array2 = explode(",", $rule_array[0]); foreach ($rule_array2 as $rule_) { $rule_ = "#_form_" . $form["id"] . " " . $rule_; $css_rules_new[] = $rule_ . " {" . $rule_array[1] . "}"; } } } }; $new_css = implode("\n\n", $css_rules_new); // remove existing styles. $html = preg_replace("/]*>(.*)<\/style>/s", "", $html); // replace with updated CSS string. $html = "" . $html; } // check for custom width. if ((int)$form["widthpx"]) { // if there is a custom width set // find the ._form CSS rule preg_match_all("/\._form {[^}]*}/", $html, $_form_css); if (isset($_form_css[0]) && $_form_css[0]) { foreach ($_form_css[0] as $_form) { // find "width:400px" preg_match("/width:[0-9]+px/", $_form, $width); if (isset($width[0]) && $width[0]) { // IE: replace "width:400px" with "width:200px" $html = preg_replace("/" . $width[0] . "/", "width:" . (int)$form["widthpx"] . "px", $html); } } } } $instance["form_html"][$form["id"]] = $html; } } } else { // no forms created in the AC account yet. echo "

" . __("Make sure you have at least one form created in ActiveCampaign.") . "

"; } return $instance; } function activecampaign_register_widgets() { register_widget("ActiveCampaign_Widget"); } function activecampaign_display($args) { extract($args); } function activecampaign_register_shortcodes() { add_shortcode("activecampaign", "activecampaign_shortcodes"); } function activecampaign_plugin_menu() { add_options_page(__("ActiveCampaign Settings", "menu-activecampaign"), __("ActiveCampaign", "menu-activecampaign"), "manage_options", "activecampaign", "activecampaign_plugin_options"); } function activecampaign_editor_buttons() { add_filter("mce_external_plugins", "activecampaign_add_buttons"); add_filter("mce_buttons", "activecampaign_register_buttons"); } function activecampaign_add_buttons($plugin_array) { $plugin_array["activecampaign_editor_buttons"] = plugins_url("editor_buttons.js", __FILE__); //we need to load the JS for this button as well //and we should load it on any page that has the button loaded, since some plugins allow editing pages from anywhere wp_enqueue_script("editor_pages", plugins_url("editor_pages.js", __FILE__), array(), false, true); // any data we need to access in JavaScript. $data = array( "site_url" => __(site_url()), "wp_version" => $GLOBALS["wp_version"], ); wp_localize_script("editor_pages", "php_data", $data); return $plugin_array; } function activecampaign_register_buttons($buttons) { array_push($buttons, "activecampaign_editor_forms"); return $buttons; } //add_action("widgets_init", "activecampaign_register_widgets"); add_action("init", "activecampaign_register_shortcodes"); add_action("init", "activecampaign_editor_buttons"); add_action("init", "activecampaign_form_block_init"); add_action("admin_menu", "activecampaign_plugin_menu"); add_filter("widget_text", "do_shortcode"); global $pagenow; add_action("wp_ajax_activecampaign_get_forms", "activecampaign_get_forms_callback"); add_action("wp_ajax_activecampaign_get_forms_html", "activecampaign_get_forms_html_callback"); add_action("admin_enqueue_scripts", "activecampaign_custom_wp_admin_style"); add_action("wp_enqueue_scripts", "activecampaign_frontend_scripts"); // get the raw forms data (array) for use in multiple spots. function activecampaign_get_forms_ajax() { // get forms that are cached after setting things up from the ActiveCampaign settings page. global $wpdb; // this is how you get access to the database $forms = array(); $settings = get_option("settings_activecampaign"); //ac_dbg($settings); if ($settings["form_id"]) { foreach ($settings["forms"] as $form) { if (in_array($form["id"], $settings["form_id"])) { $forms[$form["id"]] = $form["name"]; } } } return $forms; } // JSON output. function activecampaign_get_forms_callback() { $forms = activecampaign_get_forms_ajax(); $forms = json_encode($forms); echo $forms; die(); } // HTML output of forms (for the post dialog/window after you click the icon in the editor toolbar). // version 3.9 has this. function activecampaign_get_forms_html_callback() { $forms = activecampaign_get_forms_ajax(); echo "
"; echo "

" . __("Choose an integration form below to embed into your post or page body. Add or edit forms in ActiveCampaign and then refresh the forms on the Settings page.") . "

"; if ($forms) { echo "
"; } foreach ($forms as $formid => $formname) { echo "" . $formname . ""; } if ($forms) { echo "
"; } echo "
"; die(); } function activecampaign_custom_wp_admin_style() { wp_register_style("activecampaign-subscription-forms", "//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"); wp_enqueue_style("activecampaign-settings", plugins_url("admin_styles.css", __FILE__)); wp_enqueue_script("jquery-ui-dialog"); wp_enqueue_style("wp-jquery-ui-dialog"); } // scripts run only on the front-end. function activecampaign_frontend_scripts() { wp_enqueue_script("site_tracking", plugins_url("site_tracking.js", __FILE__), array(), false, true); $settings = get_option("settings_activecampaign"); unset($settings["api_url"]); unset($settings["api_key"]); $current_user = wp_get_current_user(); $user_email = ""; if (isset($current_user->data->user_email)) { $user_email = $current_user->data->user_email; } // any data we need to access in JavaScript. $data = array( "ac_settings" => array( "tracking_actid" => (!empty($settings["tracking_actid"]))? $settings["tracking_actid"]: null, "site_tracking_default" => 1, ), "user_email" => $user_email, ); if (isset($settings["site_tracking"]) && (int)$settings["site_tracking"]) { // This will only be set if the checkbox is checked on the ActiveCampaign settings page. $data["ac_settings"]["site_tracking"] = 1; if (isset($settings["activecampaign_site_tracking_default"])) { $data["ac_settings"]["site_tracking_default"] = (int)$settings["activecampaign_site_tracking_default"]; } } wp_localize_script("site_tracking", "php_data", $data); } // Adding a notification mechanism function activecampaign_admin_notice(){ $screen = get_current_screen(); if( !$screen || $screen->base !== 'settings_page_activecampaign'){ return; } $notices = [ 'v8.1.5 - We have updated the descriptions around form settings below. Please take a moment to read. Also note, if you are handling site tracking manually (GDPR), all JavaScript references to pgo() are now using the properly documented vgo() method.' ]; $index = (int) get_option("activecampaign_notice_index", 0); // Very first notice should get shown anyway since we have no count tracking yet if(count($notices) === 1 && empty($index)){ $index = 0; } // Default to notices count so we never show notices on fresh installs elseif(empty($index)){ $index = count($notices); } $initialIndex = $index; for($i = $index; $i < count($notices); $i++){ echo '

'.$notices[$i].'

'; $index++; } if($initialIndex !== $index){ update_option("activecampaign_notice_index", $index); } } add_action('admin_notices', 'activecampaign_admin_notice');