0) { add_action('init', 'install_AdminNotes'); } } // -------------------------------------------------------------------- // create and populate the database on installing the plugin // -------------------------------------------------------------------- function install_AdminNotes() { global $wpdb; global $table_name; $table_name = $wpdb->prefix . 'admin_notes'; if($wpdb->get_var("SHOW TABLES LIKE '" . $table_name ."'") != $table_name) { $sql = "CREATE TABLE $table_name ( task_id bigint(32) not null auto_increment, notes text not null default '', unique key id(task_id) );"; $results = $wpdb->query($sql); // Add initial data $sql = "INSERT INTO `$table_name` (notes) VALUES ('This is a sample note.')"; $results = $wpdb->query($sql); } } function load_js_admin_head() { wp_enqueue_script('js-adminnotes', '/wp-content/plugins/adminnotes/js-adminnotes.php', array('jquery'), '1.0'); } // -------------------------------------------------------------------- // Add actions // -------------------------------------------------------------------- add_action("admin_print_scripts", 'load_js_admin_head'); add_action('admin_notices', 'render_adminnotes_page'); add_action('wp-ajax_check_notes', 'check_notes', 10); add_action('wp_ajax_del_notes', 'del_notes', 10); add_action('wp_ajax_save_notes', 'save_notes', 10); add_action('wp_ajax_update_adminnotes_page', 'update_adminnotes_page', 10); add_action('wp_ajax_check_notes', 'check_notes', 10); // -------------------------------------------------------------------- // Render the Admin Notes page on all admin pages // -------------------------------------------------------------------- function render_adminnotes_page() { global $table_name; global $wpdb; global $notesarray; $table_name = $wpdb->prefix . 'admin_notes'; $notesarray = $wpdb->get_results("SELECT task_id, notes FROM $table_name ORDER BY `task_id` ASC"); include('html-adminnotes.php'); } //----------------------------------------------------------------------------- // update the admin notes page on adding a note - to show immediately in list. //----------------------------------------------------------------------------- function update_adminnotes_page() { global $wpdb; global $table_name; global $notesarray; $table_name = $wpdb->prefix . 'admin_notes'; usleep(500000); $notesarray = $wpdb->get_results("SELECT * FROM $table_name ORDER BY `task_id` ASC"); include('html-update_notes.php'); } //---------------------------------------------------------------------- // add the Save Function //-------------------------------------------------------------------- function save_notes() { global $wpdb; global $table_name; global $notesarray; $table_name = $wpdb->prefix . 'admin_notes'; $name = 'notes_input'; $value = $_POST['notes_input']; $sql = "INSERT INTO $table_name (notes) VALUES ('$value')"; $results = $wpdb->query($sql); } // -------------------------------------------------------------------- // Delete function //--------------------------------------------------------------------- function del_notes() { global $wpdb; global $table_name; $table_name = $wpdb->prefix . 'admin_notes'; $deletestring = $_POST['post_string']; $deleteid = explode('|',$deletestring); foreach($deleteid as $delid) { /////////// $sql = "DELETE FROM $table_name WHERE task_id = '$delid'"; $results = $wpdb->query($sql)or die(mysql_error()); //////////////// $notesarray = $wpdb->get_results("SELECT task_id, notes FROM $table_name"); if(!empty($notesarray)){ $havenotes = 'yes'; }else{ $havenotes = 'no'; } echo $havenotes; } //exit; } // -------------------------------------------------------------------- // Check function //--------------------------------------------------------------------- function check_notes() { global $wpdb; global $table_name; $table_name = $wpdb->prefix . 'admin_notes'; //////////////// $notesarray = $wpdb->get_results("SELECT task_id FROM $table_name"); if(!empty($notesarray)){ $havenotes = 'yes'; }else{ $havenotes = 'no'; } echo $havenotes; exit; } ?>