var _aweb = {"; $count = 0; foreach ($awebvoice_data["button"] as $key => $value) { $count++; echo $key.': "'. $value.'"'; if ($count < count($awebvoice_data["button"])) echo ","; } echo "}; (function() {var cms = document.createElement('script'); cms.type = 'text/javascript'; cms.async = true; cms.src = '".$awebvoice_data["button_src"]."'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cms, s);})();"; } add_action('init', 'awebvoice_assets'); function awebvoice_assets() { $awebvoice_data = unserialize(get_option("awebvoice_data")); if (function_exists('wp_footer')) { if (!is_admin()){ if (!$_POST['awebvoice_data']) { if (isset($awebvoice_data["form_id"]) && $awebvoice_data["sticky_button"] == "true") { add_action( 'wp_head', 'load_button_code' ); } } } } elseif (function_exists('wp_head')) { if (!is_admin()){ if (!$_POST['awebvoice_data']) { if (isset($awebvoice_data["form_id"]) && $awebvoice_data["sticky_button"] == "true") { add_action( 'wp_head', 'load_button_code' ); } } } } } // Adding Admin Menu add_action('admin_menu', 'awebvoice_plugin_menu'); function awebvoice_plugin_menu() { add_options_page('AWebVoice Settings', 'AWebVoice Form', 10, __FILE__, 'awebvoice_setup'); } function awebvoice_setup() { $awebvoice_data = unserialize(get_option("awebvoice_data")); if ($_POST) { $awebvoice_data = unserialize(stripslashes($_POST["awebvoice_data"])); $awebvoice_action = $awebvoice_data["action"]; unset($awebvoice_data["action"]); if ($awebvoice_action == "save_account") { // save initial email and set up contact page $old_data = unserialize(get_option('awebvoice_data')); if ($old_data["wp_page_id"]) wp_delete_post($old_data["wp_page_id"]); if ($awebvoice_data["publish_page"] == "true") { if (!get_post($awebvoice_data["wp_page_id"])) { $awebvoice_page_id = wp_insert_post(array( 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => $awebvoice_data["button"]["label"], 'post_title' => $awebvoice_data["button"]["label"], 'comment_status' => 'closed', 'post_content' => '' )); $awebvoice_data["wp_page_id"] = $awebvoice_page_id; } } update_option("awebvoice_data", serialize($awebvoice_data)); } elseif ($awebvoice_action == "save_settings") { // save just configuration settings if (get_option('awebvoice_data')) { $awebvoice_data = array_merge(unserialize(get_option('awebvoice_data')), $awebvoice_data); } if ($awebvoice_data["publish_page"] == "true") { if (!get_post($awebvoice_data["wp_page_id"])) { $awebvoice_page_id = wp_insert_post(array( 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => $awebvoice_data["button"]["label"], 'post_title' => $awebvoice_data["button"]["label"], 'comment_status' => 'closed', 'post_content' => '' )); $awebvoice_data["wp_page_id"] = $awebvoice_page_id; } else { $awebvoice_page_id = wp_update_post(array( 'ID' => $awebvoice_data["wp_page_id"], 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => $awebvoice_data["button"]["label"], 'post_title' => $awebvoice_data["button"]["label"], 'comment_status' => 'closed', 'post_content' => '' )); $awebvoice_data["wp_page_id"] = $awebvoice_page_id; } } else { wp_delete_post($awebvoice_data["wp_page_id"]); unset($awebvoice_data["wp_page_id"]); } update_option("awebvoice_data", serialize($awebvoice_data)); } } ?>