'.__("Updates Saved!").'
'; } /** * * Runs the required SQL when the plugin is activated * * @param none * @return none */ function amq_install() { global $wpdb,$amq_db_version,$table_name; $table_name = $wpdb->prefix . "answer_my_question"; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, date_asked DATETIME NOT NULL, date_response DATETIME NOT NULL, user_name VARCHAR(60) NOT NULL, user_email VARCHAR(60) NOT NULL, url VARCHAR(60) DEFAULT '' NOT NULL, subject VARCHAR(60) NOT NULL, question TEXT NOT NULL, answer TEXT NOT NULL, answered tinyint(1) NOT NULL, notify_user tinyint(1) NOT NULL, show_on_site tinyint(1) NOT NULL DEFAULT '1', UNIQUE KEY id (id));"; dbDelta($sql); add_option("amq_db_version", $amq_db_version); //Update Database Schema $installed_ver = get_option("amq_db_version"); if($installed_ver != $amq_db_version) { $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, date_asked DATETIME NOT NULL, date_response DATETIME NOT NULL, user_name VARCHAR(60) NOT NULL, user_email VARCHAR(60) NOT NULL, url VARCHAR(60) DEFAULT '' NOT NULL, subject VARCHAR(60) NOT NULL, question TEXT NOT NULL, answer TEXT NOT NULL, answered tinyint(1) NOT NULL, notify_user tinyint(1) NOT NULL, show_on_site tinyint(1) NOT NULL DEFAULT '1', UNIQUE KEY id (id));"; dbDelta($sql); update_option("amq_db_version", $amq_db_version); } } /** * * Compares the current database version with the version recorded as installed in the users database. If they don't match, amq_install is run to update the schema * * @param none * @return none */ function amq_update_db_check() { global $amq_db_version; if (get_site_option('amq_db_version') != $amq_db_version) { amq_install(); } } /** * * Adds top level and sub level menu item for the plugin. Editor and above can use the plugin * * @param none * @return none */ function register_amq_menu_page() { add_menu_page("Answer My Question", "Answer My Question", "delete_pages", "answer-my-question", "answerMyQuestionView"); add_submenu_page("answer-my-question", "", "Settings", "delete_pages", "answer-my-question-settings", "answerMyQuestionSettings"); } /** * * Enqueues the plugin specific JavaScript and CSS to to the head for the main admin page * * @param none * @return none */ function loadMainScripts() { global $plugindir; wp_enqueue_script('', $plugindir . '/js/main.js'); echo "\n"; } /** * * Enqueues the plugin specific JavaScript and CSS to the public facing site * * @param none * @return none */ function loadClientAssets(){ echo "\n\n"; wp_enqueue_script('', plugins_url('js/answer_my_question_scripts.js', __FILE__), false, false, true); } /** * * Inserts the modal markup into the public facing site's footer * * @param none * @return none */ function insertModal() { global $wpdb; $table_name = $wpdb->prefix . "options"; //Get the plugin options $result = $wpdb->get_results("SELECT option_value FROM $table_name WHERE option_name = 'amq_option_item' LIMIT 1;"); if(count($result) > 0){ foreach($result as $row){ $modalDetails = unserialize($row->option_value); } } $modalTitle = (!empty($modalDetails['title']) ? sprintf( __('%s'), $modalDetails['title']) : __('Answer My Question')); $modalBody = (!empty($modalDetails['body']) ? str_replace("\n", "
'.$modalBody.'
Here you can administer all questions submitted by your site users.
'; if(count($result) > 0){ echo '
Hello,
This is an automated email from '.get_bloginfo("name").'.
Your quesiton titled: '.$subject.', has been answered on '.date("F j, Y", strtotime($responseDate)).'.
"'.$response.'"
'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers // NOTE: If multiple admins, you need to explode here and change $headers $headers .= 'To: '.$email.' <'.$email.'>' . "\r\n"; $headers .= 'From: '.get_bloginfo('admin_email').' <'.get_bloginfo('admin_email').'>' . "\r\n"; // Mail it if(mail($to, $emailSubject, $message, $headers)){ return true; }else{ return false; } } /** * * Settings options page * * @param none * @return none */ function answerMyQuestionSettings() { loadMainScripts(); if($_GET['settings-updated'] == true){ echo ''.__("Settings saved").'.